Merge pull request #130 from diizzyy/patch-2
authorJiri Slachta <jiri.slachta@gmail.com>
Fri, 5 May 2017 11:37:35 +0000 (13:37 +0200)
committerGitHub <noreply@github.com>
Fri, 5 May 2017 11:37:35 +0000 (13:37 +0200)
net/baresip: Update to 0.5.0

29 files changed:
libs/libpri/Makefile
libs/re/Makefile
net/asterisk-11.x/Makefile
net/asterisk-11.x/patches/051-musl-includes.patch [deleted file]
net/asterisk-11.x/src-lantiq/channels/chan_lantiq.c [new file with mode: 0644]
net/asterisk-11.x/src-lantiq/configs/lantiq.conf.sample [new file with mode: 0644]
net/asterisk-13.x/Makefile
net/asterisk-13.x/patches/001-disable-semaphores-check.patch
net/asterisk-13.x/patches/002-undef-res-ninit.patch
net/asterisk-13.x/patches/004-ifdef-missing-execinfo.patch
net/asterisk-13.x/patches/040-fix-config-options.patch [deleted file]
net/asterisk-13.x/patches/051-musl-includes.patch [deleted file]
net/asterisk-13.x/patches/052-musl-libcap.patch
net/asterisk-13.x/src-lantiq/channels/chan_lantiq.c [new file with mode: 0644]
net/asterisk-13.x/src-lantiq/configs/samples/lantiq.conf.sample [new file with mode: 0644]
net/freeswitch-stable-sounds/Makefile [new file with mode: 0644]
net/freeswitch-stable/Config.in [new file with mode: 0644]
net/freeswitch-stable/Makefile [new file with mode: 0644]
net/freeswitch-stable/files/freeswitch.default [new file with mode: 0644]
net/freeswitch-stable/files/freeswitch.hotplug [new file with mode: 0644]
net/freeswitch-stable/files/freeswitch.init [new file with mode: 0644]
net/freeswitch-stable/patches/010-fix-zrtp-cflags.patch [new file with mode: 0644]
net/freeswitch-stable/patches/030-fix-configure-ac.patch [new file with mode: 0644]
net/freeswitch-stable/patches/110-apr-add-cache-for-strerror_r.patch [new file with mode: 0644]
net/freeswitch-stable/patches/120-fix-copts.diff [new file with mode: 0644]
net/freeswitch-stable/patches/130-fix-iksemel-copts.diff [new file with mode: 0644]
net/kamailio-4.x/Makefile
net/kamailio-4.x/patches/050-fix-kamailio-utils.patch
net/yate/Makefile

index c516a6bcc810ca51632ae2e7e005ad1d6758a6ab..01fe368f7859cc62c2ed4c4271a9e336a1fef329 100644 (file)
@@ -8,12 +8,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=libpri
-PKG_VERSION:=1.5.0
+PKG_VERSION:=1.6.0
 PKG_RELEASE:=1
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://downloads.asterisk.org/pub/telephony/libpri/releases
-PKG_MD5SUM:=d32bf834861d3b0d24f26b0ffb52e971
+PKG_HASH:=7225ea7ec334a115f9dc08e71f55589c38cb4e00b13964cd2f08cc4e6123e3f6
 PKG_MAINTAINER:=Daniel Golle <daniel@makrotopia.org>
 
 PKG_INSTALL:=1
index 175a23c87b49151592aa136e9c2607986eb23197..af173f9f168e7ed474d7027d4f5f2fa6602ff734 100644 (file)
@@ -26,7 +26,7 @@ define Package/libre
   SUBMENU:=Telephony
   SECTION:=libs
   CATEGORY:=Libraries
-  DEPENDS:=+libopenssl +libpthread
+  DEPENDS:=+libopenssl +libpthread +zlib
   TITLE:=Generic library for real-time communications with async IO support
   URL:=http://www.creytiv.com/
 endef
index 064a47ab614cbbde87e28d43ab2f387df2fe1145..e86865b90503d683bcafdd9145a224e23bebe07b 100644 (file)
@@ -9,12 +9,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=asterisk11
-PKG_VERSION:=11.22.0
-PKG_RELEASE:=2
+PKG_VERSION:=11.25.1
+PKG_RELEASE:=1
 
 PKG_SOURCE:=asterisk-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://downloads.asterisk.org/pub/telephony/asterisk/releases/
-PKG_MD5SUM:=35870c34fadbd2bcb284bd8521c6e689
+PKG_HASH:=dc9c282ca1142b286e5a5c391647d6be73f35524c8def37718de866e8384a57c
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/asterisk-$(PKG_VERSION)
 PKG_BUILD_DEPENDS:=libxml2/host
@@ -210,6 +210,14 @@ else
        --without-postgres
 endif
 
+ifneq ($(SDK)$(CONFIG_PACKAGE_asterisk11-res-fax-spandsp),)
+  CONFIGURE_ARGS+= \
+       --with-spandsp="$(STAGING_DIR)/usr"
+else
+  CONFIGURE_ARGS+= \
+       --without-spandsp
+endif
+
 ifneq ($(SDK)$(CONFIG_PACKAGE_asterisk11-res-srtp),)
   CONFIGURE_ARGS+= \
        --with-srtp="$(STAGING_DIR)/usr"
@@ -255,7 +263,6 @@ CONFIGURE_ARGS+= \
        --without-pwlib \
        --without-radius \
        --without-sdl \
-       --without-spandsp \
        --without-sqlite \
        --with-sqlite3="$(STAGING_DIR)/usr" \
        --without-suppserv \
@@ -278,6 +285,13 @@ AST_MENUSELECT_OPTS = \
        --with-ncurses="$(STAGING_DIR)/host/usr" \
        --with-libxml2="$(STAGING_DIR)/host/usr"
 
+define Build/Prepare
+       $(call Build/Prepare/Default)
+ifneq ($(CONFIG_TARGET_lantiq),)
+       $(CP) ./src-lantiq/* $(PKG_BUILD_DIR)/
+endif
+endef
+
 define Build/Configure
        (cd $(PKG_BUILD_DIR); \
                ./bootstrap.sh; \
@@ -366,6 +380,7 @@ $(eval $(call BuildAsterisk11Module,app-record,Record sound file,to record a sou
 $(eval $(call BuildAsterisk11Module,app-sayunixtime,Say Unix time,an application to say Unix time,,,,app_sayunixtime,))
 $(eval $(call BuildAsterisk11Module,app-senddtmf,Send DTMF digits,Sends arbitrary DTMF digits,,,,app_senddtmf,))
 $(eval $(call BuildAsterisk11Module,app-sms,SMS,SMS support (ETSI ES 201 912 protocol 1),+libpopt +libstdcpp,,,app_sms,,smsq))
+$(eval $(call BuildAsterisk11Module,app-speech,Dialplan Speech,Dialplan Speech Applications,+asterisk11-res-speech,,,app_speech_utils,))
 $(eval $(call BuildAsterisk11Module,app-stack,Stack applications,Stack applications Gosub Return etc.,+asterisk11-res-agi,,,app_stack,))
 $(eval $(call BuildAsterisk11Module,app-system,System exec,support for executing system commands,,,,app_system,))
 $(eval $(call BuildAsterisk11Module,app-talkdetect,File playback with audio detect,for file playback with audio detect,,,,app_talkdetect,))
@@ -379,6 +394,7 @@ $(eval $(call BuildAsterisk11Module,chan-alsa,ALSA channel,the channel chan_alsa
 $(eval $(call BuildAsterisk11Module,chan-agent,Agents proxy channel,an implementation of agents proxy channel,,,,chan_agent,))
 $(eval $(call BuildAsterisk11Module,chan-dahdi,DAHDI channel,DAHDI channel support,+dahdi-tools-libtonezone +kmod-dahdi +libpri,/etc/asterisk/chan_dahdi.conf,chan_dahdi.conf,chan_dahdi,))
 $(eval $(call BuildAsterisk11Module,chan-iax2,IAX2 channel,IAX support,+asterisk11-res-timing-timerfd,/etc/asterisk/iax.conf /etc/asterisk/iaxprov.conf,iax.conf iaxprov.conf,chan_iax2,))
+$(eval $(call BuildAsterisk11Module,chan-lantiq,Lantiq TAPI channel,An implementation of Lantiq TAPI channel,@TARGET_lantiq +kmod-ltq-vmmc,/etc/asterisk/lantiq.conf,lantiq.conf,chan_lantiq,))
 $(eval $(call BuildAsterisk11Module,chan-mgcp,MGCP channel,the channel chan_mgcp,,/etc/asterisk/mgcp.conf,mgcp.conf,chan_mgcp,))
 $(eval $(call BuildAsterisk11Module,chan-motif,Jingle channel,Motif Jingle Channel Driver,+asterisk11-res-xmpp,/etc/asterisk/motif.conf /etc/asterisk/jingle.conf,motif.conf jingle.conf,chan_motif,))
 $(eval $(call BuildAsterisk11Module,chan-ooh323,ooH323 channel,the channel chan_ooh323,,/etc/asterisk/ooh323.conf,ooh323.conf,chan_ooh323,))
@@ -434,15 +450,19 @@ $(eval $(call BuildAsterisk11Module,pbx-realtime,Realtime Switch,realtime switch
 $(eval $(call BuildAsterisk11Module,pgsql,PostgreSQL,PostgreSQL support,+libpq,/etc/asterisk/cel_pgsql.conf /etc/asterisk/cdr_pgsql.conf /etc/asterisk/res_pgsql.conf,cel_pgsql.conf cdr_pgsql.conf res_pgsql.conf,cel_pgsql cdr_pgsql res_config_pgsql,))
 $(eval $(call BuildAsterisk11Module,res-adsi,Provide ADSI,Analog Display Services Interface capability,,,,res_adsi,))
 $(eval $(call BuildAsterisk11Module,res-ael-share,Shareable AEL code,support for shareable AEL code mainly between internal and external modules,,,,res_ael_share,))
-$(eval $(call BuildAsterisk11Module,res-agi,Asterisk Gateway Interface,Support for the Asterisk Gateway Interface extension,,,,res_agi,))
+$(eval $(call BuildAsterisk11Module,res-agi,Asterisk Gateway Interface,Support for the Asterisk Gateway Interface extension,+asterisk11-res-speech,,,res_agi,))
 $(eval $(call BuildAsterisk11Module,res-calendar,Calendaring API,Calendaring support (ICal and Google Calendar),,/etc/asterisk/calendar.conf,calendar.conf,res_calendar,,))
 $(eval $(call BuildAsterisk11Module,res-clioriginate,Calls via CLI,Originate calls via the CLI,,,,res_clioriginate,))
+$(eval $(call BuildAsterisk11Module,res-fax-spandsp,Spandsp T.38 and G.711,Spandsp T.38 and G.711 FAX Resource,+asterisk11-res-fax +libspandsp +libtiff,,,res_fax_spandsp,))
+$(eval $(call BuildAsterisk11Module,res-fax,FAX modules,Generic FAX resource for FAX technology resource modules,+asterisk11-res-timing-pthread,/etc/asterisk/res_fax.conf,res_fax.conf,res_fax,))
 $(eval $(call BuildAsterisk11Module,res-monitor,Provide Monitor,Cryptographic Signature capability,,,,res_monitor,))
 $(eval $(call BuildAsterisk11Module,res-musiconhold,MOH,Music On Hold support,,/etc/asterisk/musiconhold.conf,musiconhold.conf,res_musiconhold,))
 $(eval $(call BuildAsterisk11Module,res-phoneprov,Phone Provisioning,Phone provisioning application for the asterisk internal http server,,/etc/asterisk/phoneprov.conf,phoneprov.conf,res_phoneprov,))
 $(eval $(call BuildAsterisk11Module,res-pktccops,Provide PacketCable COPS,simple client/server model for supporting policy control over QoS signaling protocols,,/etc/asterisk/res_pktccops.conf,res_pktccops.conf,res_pktccops,))
 $(eval $(call BuildAsterisk11Module,res-smdi,Provide SMDI,Simple Message Desk Interface capability,,/etc/asterisk/smdi.conf,smdi.conf,res_smdi,))
+$(eval $(call BuildAsterisk11Module,res-speech,Speech Recognition API,Support for the Asterisk Generic Speech Recognition API,,,,res_speech,))
 $(eval $(call BuildAsterisk11Module,res-srtp,SRTP,Secure RTP,+libsrtp,,,res_srtp,))
+$(eval $(call BuildAsterisk11Module,res-stun-monitor,STUN monitoring,resource STUN Monitor,,/etc/asterisk/res_stun_monitor.conf,res_stun_monitor.conf,res_stun_monitor,))
 $(eval $(call BuildAsterisk11Module,res-timing-dahdi,DAHDI Timing Interface,,+asterisk11-chan-dahdi,,,res_timing_dahdi,))
 $(eval $(call BuildAsterisk11Module,res-timing-pthread,pthread Timing Interface,,,,,res_timing_pthread,))
 $(eval $(call BuildAsterisk11Module,res-timing-timerfd,Timerfd Timing Interface,,,,,res_timing_timerfd,))
diff --git a/net/asterisk-11.x/patches/051-musl-includes.patch b/net/asterisk-11.x/patches/051-musl-includes.patch
deleted file mode 100644 (file)
index 6bee31c..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
---- a/include/asterisk/compat.h
-+++ b/include/asterisk/compat.h
-@@ -68,7 +68,7 @@
- #endif
- #ifndef AST_POLL_COMPAT
--#include <sys/poll.h>
-+#include <poll.h>
- #else
- #include "asterisk/poll-compat.h"
- #endif
---- a/include/asterisk/poll-compat.h
-+++ b/include/asterisk/poll-compat.h
-@@ -83,7 +83,7 @@
- #ifndef AST_POLL_COMPAT
--#include <sys/poll.h>
-+#include <poll.h>
- #define ast_poll(a, b, c) poll(a, b, c)
---- a/main/ast_expr2.c
-+++ b/main/ast_expr2.c
-@@ -93,6 +93,7 @@
- #include "asterisk.h"
-+#include <sys/cdefs.h>
- #include <sys/types.h>
- #include <stdio.h>
---- a/main/ast_expr2.y
-+++ b/main/ast_expr2.y
-@@ -14,6 +14,7 @@
- #include "asterisk.h"
-+#include <sys/cdefs.h>
- #include <sys/types.h>
- #include <stdio.h>
diff --git a/net/asterisk-11.x/src-lantiq/channels/chan_lantiq.c b/net/asterisk-11.x/src-lantiq/channels/chan_lantiq.c
new file mode 100644 (file)
index 0000000..cfe3d00
--- /dev/null
@@ -0,0 +1,2302 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Luka Perkov
+ * Copyright (C) 2012, John Crispin
+ * Copyright (C) 2012, Andrej Vlašić
+ * Copyright (C) 2012, Kaspar Schleiser for T-Labs
+ *                     (Deutsche Telekom Innovation Laboratories)
+ * Copyright (C) 2012, Mirko Vogt for T-Labs
+ *                     (Deutsche Telekom Innovation Laboratories)
+ * Copyright (c) 2015, Antonio Eugenio Burriel
+ * Copyright (C) 2017, Stefan Koch
+ *
+ * Luka Perkov <openwrt@lukaperkov.net>
+ * John Crispin <blogic@openwrt.org>
+ * Andrej Vlašić <andrej.vlasic0@gmail.com>
+ * Kaspar Schleiser <kaspar@schleiser.de>
+ * Mirko Vogt <mirko@openwrt.org>
+ * Antonio Eugenio Burriel <aeburriel@gmail.com>
+ * Stefan Koch <stefan.koch10@gmail.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Asterisk channel line driver for Lantiq based TAPI boards
+ *
+ * \author Luka Perkov <openwrt@lukaperkov.net>
+ * \author John Crispin <blogic@openwrt.org>
+ * \author Andrej Vlašić <andrej.vlasic0@gmail.com>
+ * \author Kaspar Schleiser <kaspar@schleiser.de>
+ * \author Mirko Vogt <mirko@openwrt.org>
+ * \author Antonio Eugenio Burriel <aeburriel@gmail.com>
+ * \author Stefan Koch <stefan.koch10@gmail.com>
+ *
+ * \ingroup channel_drivers
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision: xxx $")
+
+#include <ctype.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <stdio.h>
+#ifdef HAVE_LINUX_COMPILER_H
+#include <linux/compiler.h>
+#endif
+#include <linux/telephony.h>
+
+#include <asterisk/lock.h>
+#include <asterisk/channel.h>
+#include <asterisk/config.h>
+#include <asterisk/module.h>
+#include <asterisk/pbx.h>
+#include <asterisk/utils.h>
+#include <asterisk/callerid.h>
+#include <asterisk/causes.h>
+#include <asterisk/indications.h>
+#include <asterisk/stringfields.h>
+#include <asterisk/musiconhold.h>
+#include <asterisk/sched.h>
+#include <asterisk/cli.h>
+#include <asterisk/devicestate.h>
+
+/* Lantiq TAPI includes */
+#include <drv_tapi/drv_tapi_io.h>
+#include <drv_vmmc/vmmc_io.h>
+
+#define TAPI_AUDIO_PORT_NUM_MAX                 2
+
+/* Tapi predefined tones 0 to 31 */
+#define TAPI_TONE_LOCALE_NONE                  0
+//#define TAPI_TONE_LOCALE_DIAL_CODE           25
+//#define TAPI_TONE_LOCALE_RINGING_CODE                26
+//#define TAPI_TONE_LOCALE_BUSY_CODE           27
+//#define TAPI_TONE_LOCALE_CONGESTION_CODE     27
+
+/* Tapi custom tones 32 to 256 */
+#define TAPI_TONE_LOCALE_DIAL_CODE             32
+#define TAPI_TONE_LOCALE_RINGING_CODE          33
+#define TAPI_TONE_LOCALE_BUSY_CODE             34
+#define TAPI_TONE_LOCALE_CONGESTION_CODE       35
+
+#define LANTIQ_CONTEXT_PREFIX "lantiq"
+#define DEFAULT_INTERDIGIT_TIMEOUT 4000
+#define G723_HIGH_RATE 1
+#define LED_NAME_LENGTH 32
+
+static const char config[] = "lantiq.conf";
+
+static char firmware_filename[PATH_MAX] = "/lib/firmware/ifx_firmware.bin";
+static char bbd_filename[PATH_MAX] = "/lib/firmware/ifx_bbd_fxs.bin";
+static char base_path[PATH_MAX] = "/dev/vmmc";
+static int per_channel_context = 0;
+
+/* tone generator types */
+enum tone_generator_t {
+       TONE_INTEGRATED, /* tapi tone generator */
+       TONE_ASTERISK, /* asterisk tone generator where possible */
+       TONE_MEDIA /* media tone where possible */
+};
+
+/* tone generator (default is integraded) */
+static enum tone_generator_t tone_generator = TONE_INTEGRATED;
+
+/* tone zones for dial, ring, busy and congestion */
+struct ast_tone_zone_sound *ts_dial;
+struct ast_tone_zone_sound *ts_ring;
+struct ast_tone_zone_sound *ts_busy;
+struct ast_tone_zone_sound *ts_congestion;
+
+/*
+ * The private structures of the Phone Jack channels are linked for selecting
+ * outgoing channels.
+ */
+enum channel_state {
+       ONHOOK,
+       OFFHOOK,
+       DIALING,
+       INCALL,
+       CALL_ENDED,
+       RINGING,
+       UNKNOWN
+};
+
+static struct lantiq_pvt {
+       struct ast_channel *owner;       /* Channel we belong to, possibly NULL   */
+       int port_id;                     /* Port number of this object, 0..n      */
+       int channel_state;
+       char context[AST_MAX_CONTEXT];   /* this port's dialplan context          */
+       int dial_timer;                  /* timer handle for autodial timeout     */
+       char dtmfbuf[AST_MAX_EXTENSION]; /* buffer holding dialed digits          */
+       int dtmfbuf_len;                 /* lenght of dtmfbuf                     */
+       int rtp_timestamp;               /* timestamp for RTP packets             */
+       int ptime;                       /* Codec base ptime                      */
+       uint16_t rtp_seqno;              /* Sequence nr for RTP packets           */
+       uint32_t call_setup_start;       /* Start of dialling in ms               */
+       uint32_t call_setup_delay;       /* time between ^ and 1st ring in ms     */
+       uint32_t call_start;             /* time we started dialling / answered   */
+       uint32_t call_answer;            /* time the callee answered our call     */
+       uint16_t jb_size;                /* Jitter buffer size                    */
+       uint32_t jb_underflow;           /* Jitter buffer injected samples        */
+       uint32_t jb_overflow;            /* Jitter buffer dropped samples         */
+       uint16_t jb_delay;               /* Jitter buffer: playout delay          */
+       uint16_t jb_invalid;             /* Jitter buffer: Nr. of invalid packets */
+} *iflist = NULL;
+
+static struct lantiq_ctx {
+               int dev_fd;
+               int channels;
+               int ch_fd[TAPI_AUDIO_PORT_NUM_MAX];
+               char voip_led[LED_NAME_LENGTH]; /* VOIP LED name */
+               char ch_led[TAPI_AUDIO_PORT_NUM_MAX][LED_NAME_LENGTH]; /* FXS LED names */
+               int interdigit_timeout; /* Timeout in ms between dialed digits */
+} dev_ctx;
+
+static int ast_digit_begin(struct ast_channel *ast, char digit);
+static int ast_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
+static int ast_lantiq_call(struct ast_channel *ast, const char *dest, int timeout);
+static int ast_lantiq_hangup(struct ast_channel *ast);
+static int ast_lantiq_answer(struct ast_channel *ast);
+static struct ast_frame *ast_lantiq_read(struct ast_channel *ast);
+static int ast_lantiq_write(struct ast_channel *ast, struct ast_frame *frame);
+static struct ast_frame *ast_lantiq_exception(struct ast_channel *ast);
+static int ast_lantiq_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
+static int ast_lantiq_fixup(struct ast_channel *old, struct ast_channel *new);
+static struct ast_channel *ast_lantiq_requester(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause);
+static int ast_lantiq_devicestate(const char *data);
+static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *args, char *buf, size_t buflen);
+static void lantiq_jb_get_stats(int c);
+static struct ast_format lantiq_map_rtptype_to_format(uint8_t rtptype);
+static uint8_t lantiq_map_format_to_rtptype(const struct ast_format *format);
+static int lantiq_conf_enc(int c, const struct ast_format *format);
+static void lantiq_reset_dtmfbuf(struct lantiq_pvt *pvt);
+
+static struct ast_channel_tech lantiq_tech = {
+       .type = "TAPI",
+       .description = "Lantiq TAPI Telephony API Driver",
+       .send_digit_begin = ast_digit_begin,
+       .send_digit_end = ast_digit_end,
+       .call = ast_lantiq_call,
+       .hangup = ast_lantiq_hangup,
+       .answer = ast_lantiq_answer,
+       .read = ast_lantiq_read,
+       .write = ast_lantiq_write,
+       .exception = ast_lantiq_exception,
+       .indicate = ast_lantiq_indicate,
+       .fixup = ast_lantiq_fixup,
+       .requester = ast_lantiq_requester,
+       .devicestate = ast_lantiq_devicestate,
+       .func_channel_read = acf_channel_read
+};
+
+/* Protect the interface list (of lantiq_pvt's) */
+AST_MUTEX_DEFINE_STATIC(iflock);
+
+/*
+ * Protect the monitoring thread, so only one process can kill or start it, and
+ * not when it's doing something critical.
+ */
+AST_MUTEX_DEFINE_STATIC(monlock);
+
+/* The scheduling context */
+struct ast_sched_context *sched;
+
+/*
+ * This is the thread for the monitor which checks for input on the channels
+ * which are not currently in use.
+ */
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
+
+
+#define WORDS_BIGENDIAN
+/* struct taken from some GPLed code by  Mike Borella */
+typedef struct rtp_header
+{
+#if defined(WORDS_BIGENDIAN)
+  uint8_t version:2, padding:1, extension:1, csrc_count:4;
+  uint8_t marker:1, payload_type:7;
+#else
+  uint8_t csrc_count:4, extension:1, padding:1, version:2;
+  uint8_t payload_type:7, marker:1;
+#endif
+  uint16_t seqno;
+  uint32_t timestamp;
+  uint32_t ssrc;
+} rtp_header_t;
+#define RTP_HEADER_LEN 12
+#define RTP_BUFFER_LEN 512
+/* Internal RTP payload types - standard */
+#define RTP_PCMU       0
+#define RTP_G723_63    4
+#define RTP_PCMA       8
+#define RTP_G722       9
+#define RTP_CN         13
+#define RTP_G729       18
+/* Internal RTP payload types - custom   */
+#define RTP_G7221      100
+#define RTP_G726       101
+#define RTP_ILBC       102
+#define RTP_SLIN8      103
+#define RTP_SLIN16     104
+#define RTP_SIREN7     105
+#define RTP_G723_53    106
+
+
+/* LED Control. Taken with modifications from SVD by Luca Olivetti <olivluca@gmail.com> */
+#define LED_SLOW_BLINK 1000
+#define LED_FAST_BLINK 100
+static FILE *led_open(const char *led, char* sub)
+{
+       char fname[100];
+
+       if (snprintf(fname, sizeof(fname), "/sys/class/leds/%s/%s", led, sub) >= sizeof(fname))
+               return NULL;
+       return fopen(fname, "r+");
+}
+
+static FILE *led_trigger(const char *led)
+{
+       return led_open(led, "trigger");
+}
+
+static void led_delay(const char *led, int onoff, int msec)
+{
+       FILE *fp = led_open(led, onoff ? "delay_on" : "delay_off");
+       if (fp) {
+               fprintf(fp,"%d\n",msec);
+               fclose(fp);
+       }
+}
+
+static void led_on(const char *led)
+{
+       FILE *fp;
+
+       fp = led_trigger(led);
+       if (fp) {
+               fprintf(fp,"default-on\n");
+               fclose(fp);
+       }
+}
+
+static void led_off(const char *led)
+{
+       FILE *fp;
+
+       fp = led_trigger(led);
+       if (fp) {
+               fprintf(fp,"none\n");
+               fclose(fp);
+       }
+}
+
+static void led_blink(const char *led, int period)
+{
+       FILE *fp;
+
+       fp = led_trigger(led);
+       if (fp) {
+               fprintf(fp, "timer\n");
+               fclose(fp);
+               led_delay(led, 1, period/2);
+               led_delay(led, 0, period/2);
+       }
+}
+
+static uint32_t now(void) {
+       struct timespec ts;
+       clock_gettime(CLOCK_MONOTONIC, &ts);
+
+       uint64_t tmp = ts.tv_sec*1000 + (ts.tv_nsec/1000000);
+       return (uint32_t) tmp;
+}
+
+static uint32_t epoch(void) {
+       struct timeval tv;
+       gettimeofday(&tv, NULL);
+
+       return tv.tv_sec;
+}
+
+static int lantiq_dev_open(const char *dev_path, const int32_t ch_num)
+{
+       char dev_name[PATH_MAX];
+       memset(dev_name, 0, sizeof(dev_name));
+       snprintf(dev_name, PATH_MAX, "%s%u%u", dev_path, 1, ch_num);
+       return open((const char*)dev_name, O_RDWR, 0644);
+}
+
+static void lantiq_ring(int c, int r, const char *cid, const char *name)
+{
+       uint8_t status;
+
+       if (r) {
+               led_blink(dev_ctx.ch_led[c], LED_FAST_BLINK);
+               if (!cid) {
+                       status = (uint8_t) ioctl(dev_ctx.ch_fd[c], IFX_TAPI_RING_START, 0);
+               } else {
+                       IFX_TAPI_CID_MSG_t msg;
+                       IFX_TAPI_CID_MSG_ELEMENT_t elements[3];
+                       int count = 0;
+                       time_t timestamp;
+                       struct tm *tm;
+
+                       elements[count].string.elementType = IFX_TAPI_CID_ST_CLI;
+                       elements[count].string.len = strlen(cid);
+                       if (elements[count].string.len > IFX_TAPI_CID_MSG_LEN_MAX) {
+                               elements[count].string.len = IFX_TAPI_CID_MSG_LEN_MAX;
+                       }
+                       strncpy((char *)elements[count].string.element, cid, IFX_TAPI_CID_MSG_LEN_MAX);
+                       elements[count].string.element[IFX_TAPI_CID_MSG_LEN_MAX-1] = '\0';
+                       count++;
+
+                       if (name) {
+                               elements[count].string.elementType = IFX_TAPI_CID_ST_NAME;
+                               elements[count].string.len = strlen(name);
+                               if (elements[count].string.len > IFX_TAPI_CID_MSG_LEN_MAX) {
+                                       elements[count].string.len = IFX_TAPI_CID_MSG_LEN_MAX;
+                               }
+                               strncpy((char *)elements[count].string.element, name, IFX_TAPI_CID_MSG_LEN_MAX);
+                               elements[count].string.element[IFX_TAPI_CID_MSG_LEN_MAX-1] = '\0';
+                               count++;
+                       }
+
+                       if ((time(&timestamp) != -1) && ((tm=localtime(&timestamp)) != NULL)) {
+                               elements[count].date.elementType = IFX_TAPI_CID_ST_DATE;
+                               elements[count].date.day = tm->tm_mday;
+                               elements[count].date.month = tm->tm_mon + 1;
+                               elements[count].date.hour = tm->tm_hour;
+                               elements[count].date.mn = tm->tm_min;
+                               count++;
+                       }
+
+                       msg.txMode = IFX_TAPI_CID_HM_ONHOOK;
+                       msg.messageType = IFX_TAPI_CID_MT_CSUP;
+                       msg.message = elements;
+                       msg.nMsgElements = count;
+
+                       status = (uint8_t) ioctl(dev_ctx.ch_fd[c], IFX_TAPI_CID_TX_SEQ_START, (IFX_int32_t) &msg);
+               }
+       } else {
+               status = (uint8_t) ioctl(dev_ctx.ch_fd[c], IFX_TAPI_RING_STOP, 0);
+               led_off(dev_ctx.ch_led[c]);
+       }
+
+       if (status) {
+               ast_log(LOG_ERROR, "%s ioctl failed\n",
+                       (r ? "IFX_TAPI_RING_START" : "IFX_TAPI_RING_STOP"));
+       }
+}
+
+/* add a frequency to TAPE tone structure */
+/* returns the TAPI frequency ID */
+static int tapitone_add_freq (IFX_TAPI_TONE_t *tone, IFX_uint32_t freq) {
+       const int n=4; /* TAPI tone structure supports up to 4 frequencies */
+       int error=0;
+       int ret;
+       int i;
+
+       /* pointer array for freq's A, B, C, D */
+       IFX_uint32_t *freqarr[] = { &(tone->simple.freqA), &(tone->simple.freqB), &(tone->simple.freqC), &(tone->simple.freqD) };
+
+       /* pointer array for level's A, B, C, D */
+       IFX_int32_t *lvlarr[] = { &(tone->simple.levelA), &(tone->simple.levelB), &(tone->simple.levelC), &(tone->simple.levelD) };
+
+       /* array for freq IDs */
+       IFX_uint32_t retarr[] = { IFX_TAPI_TONE_FREQA, IFX_TAPI_TONE_FREQB, IFX_TAPI_TONE_FREQC, IFX_TAPI_TONE_FREQD };
+
+       /* determine if freq already set */
+       for (i = 0; i < n; i++) {
+               if(*freqarr[i] == freq) /* freq found */
+                       break;
+               else if (i == n-1) /* last iteration */
+                       error=1; /* not found */
+       }
+
+       /* write frequency if not already set */
+       if(error) {
+               error=0; /* reset error flag */
+               /* since freq is not set, write it into first free place */
+               for (i = 0; i < n; i++) {
+                       if(!*freqarr[i]) { /* free place */
+                               *freqarr[i] = freq; /* set freq */
+                               *lvlarr[i] = -150; /* set volume level */
+                               break;
+                       } else if (i == n-1) /* last iteration */
+                               error=1; /* no free place becaus maximum count of freq's is set */
+               }
+       }
+
+       /* set freq ID return value */
+       if (!freq || error)
+               ret = IFX_TAPI_TONE_FREQNONE;
+       else
+               ret = retarr[i];
+
+       return ret; /* freq ID */
+}
+
+/* convert asterisk playlist string to tapi tone structure */
+/* based on ast_playtones_start() from indications.c of asterisk 13 */
+static void playlist_to_tapitone (const char *playlst, IFX_uint32_t index, IFX_TAPI_TONE_t *tone)
+{
+       char *s, *data = ast_strdupa(playlst);
+       char *stringp;
+       char *separator;
+       int i;
+
+       /* initialize tapi tone structure */
+       memset(tone, 0, sizeof(IFX_TAPI_TONE_t));
+       tone->simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+       tone->simple.index = index;
+
+       stringp = data;
+
+       /* check if the data is separated with '|' or with ',' by default */
+       if (strchr(stringp,'|')) {
+               separator = "|";
+       } else {
+               separator = ",";
+       }
+
+       for ( i = 0; (s = strsep(&stringp, separator)) && !ast_strlen_zero(s) && i < IFX_TAPI_TONE_STEPS_MAX; i++) {
+               struct ast_tone_zone_part tone_data = {
+                       .time = 0,
+               };
+
+               s = ast_strip(s);
+               if (s[0]=='!') {
+                       s++;
+               }
+
+               if (ast_tone_zone_part_parse(s, &tone_data)) {
+                       ast_log(LOG_ERROR, "Failed to parse tone part '%s'\n", s);
+                       continue;
+               }
+
+               /* first tone must hava a cadence */
+               if (i==0 && !tone_data.time)
+                       tone->simple.cadence[i] = 1000;
+               else
+                       tone->simple.cadence[i] = tone_data.time;
+
+               /* check for modulation */
+               if (tone_data.modulate) {
+                       tone->simple.modulation[i] = IFX_TAPI_TONE_MODULATION_ON;
+                       tone->simple.modulation_factor = IFX_TAPI_TONE_MODULATION_FACTOR_90;
+               }
+
+               /* copy freq's to tapi tone structure */
+               /* a freq will implicitly skipped if it is zero  */
+               tone->simple.frequencies[i] |= tapitone_add_freq(tone, tone_data.freq1);
+               tone->simple.frequencies[i] |= tapitone_add_freq(tone, tone_data.freq2);
+       }
+}
+
+static int lantiq_play_tone(int c, int t)
+{
+       /* stop currently playing tone before starting new one */
+       ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_LOCAL_PLAY, TAPI_TONE_LOCALE_NONE);
+
+       /* do not handle stop tone twice */
+       if (t != TAPI_TONE_LOCALE_NONE) {
+               /* start new tone */
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_LOCAL_PLAY, t)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_LOCAL_PLAY ioctl failed\n");
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+static enum channel_state lantiq_get_hookstatus(int port)
+{
+       uint8_t status;
+
+       if (ioctl(dev_ctx.ch_fd[port], IFX_TAPI_LINE_HOOK_STATUS_GET, &status)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_LINE_HOOK_STATUS_GET ioctl failed\n");
+               return UNKNOWN;
+       }
+
+       if (status) {
+               return OFFHOOK;
+       } else {
+               return ONHOOK;
+       }
+}
+
+static int
+lantiq_dev_binary_buffer_create(const char *path, uint8_t **ppBuf, uint32_t *pBufSz)
+{
+       FILE *fd;
+       struct stat file_stat;
+       int status = -1;
+
+       fd = fopen(path, "rb");
+       if (fd == NULL) {
+               ast_log(LOG_ERROR, "binary file %s open failed\n", path);
+               goto on_exit;
+       }
+
+       if (stat(path, &file_stat)) {
+               ast_log(LOG_ERROR, "file %s statistics get failed\n", path);
+               goto on_exit;
+       }
+
+       *ppBuf = malloc(file_stat.st_size);
+       if (*ppBuf == NULL) {
+               ast_log(LOG_ERROR, "binary file %s memory allocation failed\n", path);
+               goto on_exit;
+       }
+
+       if (fread (*ppBuf, sizeof(uint8_t), file_stat.st_size, fd) != file_stat.st_size) {
+               ast_log(LOG_ERROR, "file %s read failed\n", path);
+               status = -1;
+               goto on_exit;
+       }
+
+       *pBufSz = file_stat.st_size;
+       status = 0;
+
+on_exit:
+       if (fd != NULL)
+               fclose(fd);
+
+       if (*ppBuf != NULL && status)
+               free(*ppBuf);
+
+       return status;
+}
+
+static int32_t lantiq_dev_firmware_download(int32_t fd, const char *path)
+{
+       uint8_t *firmware = NULL;
+       uint32_t size = 0;
+       VMMC_IO_INIT vmmc_io_init;
+
+       ast_log(LOG_DEBUG, "loading firmware: \"%s\".\n", path);
+
+       if (lantiq_dev_binary_buffer_create(path, &firmware, &size))
+               return -1;
+
+       memset(&vmmc_io_init, 0, sizeof(VMMC_IO_INIT));
+       vmmc_io_init.pPRAMfw = firmware;
+       vmmc_io_init.pram_size = size;
+
+       if (ioctl(fd, FIO_FW_DOWNLOAD, &vmmc_io_init)) {
+               ast_log(LOG_ERROR, "FIO_FW_DOWNLOAD ioctl failed\n");
+               return -1;
+       }
+
+       if (firmware != NULL)
+               free(firmware);
+
+       return 0;
+}
+
+static const char *state_string(enum channel_state s)
+{
+       switch (s) {
+               case ONHOOK: return "ONHOOK";
+               case OFFHOOK: return "OFFHOOK";
+               case DIALING: return "DIALING";
+               case INCALL: return "INCALL";
+               case CALL_ENDED: return "CALL_ENDED";
+               case RINGING: return "RINGING";
+               default: return "UNKNOWN";
+       }
+}
+
+static const char *control_string(int c)
+{
+       switch (c) {
+               case AST_CONTROL_HANGUP: return "Other end has hungup";
+               case AST_CONTROL_RING: return "Local ring";
+               case AST_CONTROL_RINGING: return "Remote end is ringing";
+               case AST_CONTROL_ANSWER: return "Remote end has answered";
+               case AST_CONTROL_BUSY: return "Remote end is busy";
+               case AST_CONTROL_TAKEOFFHOOK: return "Make it go off hook";
+               case AST_CONTROL_OFFHOOK: return "Line is off hook";
+               case AST_CONTROL_CONGESTION: return "Congestion (circuits busy)";
+               case AST_CONTROL_FLASH: return "Flash hook";
+               case AST_CONTROL_WINK: return "Wink";
+               case AST_CONTROL_OPTION: return "Set a low-level option";
+               case AST_CONTROL_RADIO_KEY: return "Key Radio";
+               case AST_CONTROL_RADIO_UNKEY: return "Un-Key Radio";
+               case AST_CONTROL_PROGRESS: return "Remote end is making Progress";
+               case AST_CONTROL_PROCEEDING: return "Remote end is proceeding";
+               case AST_CONTROL_HOLD: return "Hold";
+               case AST_CONTROL_UNHOLD: return "Unhold";
+               case AST_CONTROL_SRCUPDATE: return "Media Source Update";
+               case AST_CONTROL_CONNECTED_LINE: return "Connected Line";
+               case AST_CONTROL_REDIRECTING: return "Redirecting";
+               case AST_CONTROL_INCOMPLETE: return "Incomplete";
+               case -1: return "Stop tone";
+               default: return "Unknown";
+       }
+}
+
+static int ast_lantiq_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen)
+{
+       struct lantiq_pvt *pvt = ast_channel_tech_pvt(chan);
+
+       ast_verb(3, "phone indication \"%s\"\n", control_string(condition));
+
+       switch (condition) {
+               case -1:
+                       {
+                               lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_NONE);
+                               return 0;
+                       }
+               case AST_CONTROL_CONGESTION:
+                       {
+                               if (tone_generator == TONE_INTEGRATED)
+                                       lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_CONGESTION_CODE);
+                               else
+                                       ast_playtones_start(chan, 0, ts_congestion->data, 1);
+
+                               return 0;
+                       }
+               case AST_CONTROL_BUSY:
+                       {
+                               if (tone_generator == TONE_INTEGRATED)
+                                       lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_BUSY_CODE);
+                               else
+                                       ast_playtones_start(chan, 0, ts_busy->data, 1);
+
+                               return 0;
+                       }
+               case AST_CONTROL_RINGING:
+               case AST_CONTROL_PROGRESS:
+                       {
+                               pvt->call_setup_delay = now() - pvt->call_setup_start;
+
+                               if (tone_generator == TONE_INTEGRATED)
+                                       lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_RINGING_CODE);
+                               else if (tone_generator == TONE_ASTERISK) /* do nothing if TONE_MEDIA is set */
+                                       ast_playtones_start(chan, 0, ts_ring->data, 1);
+
+                               return 0;
+                       }
+               default:
+                       {
+                               /* -1 lets asterisk generate the tone */
+                               return -1;
+                       }
+       }
+}
+
+static int ast_lantiq_fixup(struct ast_channel *old, struct ast_channel *new)
+{
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return 0;
+}
+
+static int ast_digit_begin(struct ast_channel *chan, char digit)
+{
+       /* TODO: Modify this callback to let Asterisk support controlling the length of DTMF */
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return 0;
+}
+
+static int ast_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
+{
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return 0;
+}
+
+static int ast_lantiq_call(struct ast_channel *ast, const char *dest, int timeout)
+{
+       int res = 0;
+       struct lantiq_pvt *pvt;
+
+       /* lock to prevent simultaneous access with do_monitor thread processing */
+       ast_mutex_lock(&iflock);
+
+       pvt = ast_channel_tech_pvt(ast);
+       ast_log(LOG_DEBUG, "state: %s\n", state_string(pvt->channel_state));
+
+       if (pvt->channel_state == ONHOOK) {
+               struct ast_party_id connected_id = ast_channel_connected_effective_id(ast);
+               const char *cid = connected_id.number.valid ? connected_id.number.str : NULL;
+               const char *name = connected_id.name.valid ? connected_id.name.str : NULL;
+
+               ast_log(LOG_DEBUG, "port %i is ringing\n", pvt->port_id);
+               ast_log(LOG_DEBUG, "port %i CID: %s\n", pvt->port_id, cid ? cid : "none");
+               ast_log(LOG_DEBUG, "port %i NAME: %s\n", pvt->port_id, name ? name : "none");
+
+               lantiq_ring(pvt->port_id, 1, cid, name);
+               pvt->channel_state = RINGING;
+
+               ast_setstate(ast, AST_STATE_RINGING);
+               ast_queue_control(ast, AST_CONTROL_RINGING);
+       } else {
+               ast_log(LOG_DEBUG, "port %i is busy\n", pvt->port_id);
+               ast_setstate(ast, AST_STATE_BUSY);
+               ast_queue_control(ast, AST_CONTROL_BUSY);
+               res = -1;
+       }
+
+       ast_mutex_unlock(&iflock);
+
+       return res;
+}
+
+static int ast_lantiq_hangup(struct ast_channel *ast)
+{
+       struct lantiq_pvt *pvt;
+
+       /* lock to prevent simultaneous access with do_monitor thread processing */
+       ast_mutex_lock(&iflock);
+
+       pvt = ast_channel_tech_pvt(ast);
+       ast_log(LOG_DEBUG, "state: %s\n", state_string(pvt->channel_state));
+
+       if (ast_channel_state(ast) == AST_STATE_RINGING) {
+               ast_debug(1, "channel state is RINGING\n");
+       }
+
+       switch (pvt->channel_state) {
+               case RINGING:
+               case ONHOOK:
+                       lantiq_ring(pvt->port_id, 0, NULL, NULL);
+                       pvt->channel_state = ONHOOK;
+                       break;
+               default:
+                       ast_log(LOG_DEBUG, "we were hung up, play busy tone\n");
+                       pvt->channel_state = CALL_ENDED;
+                       lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_BUSY_CODE);
+       }
+
+       lantiq_jb_get_stats(pvt->port_id);
+
+       ast_setstate(ast, AST_STATE_DOWN);
+       ast_module_unref(ast_module_info->self);
+       ast_channel_tech_pvt_set(ast, NULL);
+       pvt->owner = NULL;
+
+       ast_mutex_unlock(&iflock);
+
+       return 0;
+}
+
+static int ast_lantiq_answer(struct ast_channel *ast)
+{
+       struct lantiq_pvt *pvt = ast_channel_tech_pvt(ast);
+
+       ast_log(LOG_DEBUG, "Remote end has answered call.\n");
+
+       if (lantiq_conf_enc(pvt->port_id, ast_channel_writeformat(ast)))
+               return -1;
+
+       pvt->call_answer = epoch();
+
+       return 0;
+}
+
+static struct ast_frame * ast_lantiq_read(struct ast_channel *ast)
+{
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return NULL;
+}
+
+/* create asterisk format from rtp payload type */
+static struct ast_format lantiq_map_rtptype_to_format(uint8_t rtptype)
+{
+       struct ast_format format = {0};
+
+       switch (rtptype) {
+               case RTP_PCMU: ast_format_set(&format, AST_FORMAT_ULAW, 0); break;
+               case RTP_PCMA: ast_format_set(&format, AST_FORMAT_ALAW, 0); break;
+               case RTP_G722: ast_format_set(&format, AST_FORMAT_G722, 0); break;
+               case RTP_G726: ast_format_set(&format, AST_FORMAT_G726, 0); break;
+               case RTP_SLIN8: ast_format_set(&format, AST_FORMAT_SLINEAR, 0); break;
+               case RTP_SLIN16: ast_format_set(&format, AST_FORMAT_SLINEAR16, 0); break;
+               case RTP_ILBC: ast_format_set(&format, AST_FORMAT_ILBC, 0); break;
+               case RTP_SIREN7: ast_format_set(&format, AST_FORMAT_SIREN7, 0); break;
+               case RTP_G723_63: ast_format_set(&format, AST_FORMAT_G723_1, 0); break;
+               case RTP_G723_53: ast_format_set(&format, AST_FORMAT_G723_1, 0); break;
+               case RTP_G729: ast_format_set(&format, AST_FORMAT_G729A, 0); break;
+               default:
+               {
+                       ast_log(LOG_ERROR, "unsupported rtptype received is 0x%x, forcing ulaw\n", (unsigned) rtptype);
+                       ast_format_set(&format, AST_FORMAT_ULAW, 0);
+               }
+       }
+
+       return format;
+}
+
+/* create rtp payload type from asterisk format */
+static uint8_t lantiq_map_format_to_rtptype(const struct ast_format *format)
+{
+       uint8_t rtptype = 0;
+       enum ast_format_id formatid = format ? format->id : 0;
+
+       switch (formatid) {
+               case AST_FORMAT_ULAW: rtptype = RTP_PCMU; break;
+               case AST_FORMAT_ALAW: rtptype = RTP_PCMA; break;
+               case AST_FORMAT_G722: rtptype = RTP_G722; break;
+               case AST_FORMAT_G726: rtptype = RTP_G726; break;
+               case AST_FORMAT_SLINEAR: rtptype = RTP_SLIN8; break;
+               case AST_FORMAT_SLINEAR16: rtptype = RTP_SLIN16; break;
+               case AST_FORMAT_ILBC: rtptype = RTP_ILBC; break;
+               case AST_FORMAT_SIREN7: rtptype = RTP_SIREN7; break;
+#if defined G723_HIGH_RATE
+               case AST_FORMAT_G723_1: rtptype = RTP_G723_63; break;
+#else
+               case AST_FORMAT_G723_1: rtptype = RTP_G723_53; break;
+#endif
+               case AST_FORMAT_G729A: rtptype = RTP_G729; break;
+               default:
+               {
+                       ast_log(LOG_ERROR, "unsupported format %s (0x%x), forcing ulaw\n", ast_getformatname(format), (int) formatid);
+                       rtptype = RTP_PCMU;
+               }
+       }
+
+       return rtptype;
+}
+
+static int lantiq_conf_enc(int c, const struct ast_format *format)
+{
+       /* Configure encoder before starting RTP session */
+       IFX_TAPI_ENC_CFG_t enc_cfg;
+       enum ast_format_id formatid = format ? format->id : 0;
+
+       memset(&enc_cfg, 0, sizeof(IFX_TAPI_ENC_CFG_t));
+       switch (formatid) {
+               case AST_FORMAT_ULAW:
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_MLAW;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+                       iflist[c].ptime = 10;
+                       break;
+               case AST_FORMAT_ALAW:
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_ALAW;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+                       iflist[c].ptime = 10;
+                       break;
+               case AST_FORMAT_G722:
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G722_64;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+                       iflist[c].ptime = 20;
+                       break;
+               case AST_FORMAT_G726:
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G726_32;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+                       iflist[c].ptime = 10;
+                       break;
+               case AST_FORMAT_SLINEAR:
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_LIN16_8;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+                       iflist[c].ptime = 10;
+                       break;
+               case AST_FORMAT_SLINEAR16:
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_LIN16_16;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_10;
+                       iflist[c].ptime = 10;
+                       break;
+               case AST_FORMAT_ILBC:
+                       /* iLBC 15.2kbps is currently unsupported by Asterisk */
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_ILBC_133;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_30;
+                       iflist[c].ptime = 30;
+                       break;
+               case AST_FORMAT_SIREN7:
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G7221_32;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+                       iflist[c].ptime = 20;
+                       break;
+               case AST_FORMAT_G723_1:
+#if defined G723_HIGH_RATE
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G723_63;
+#else
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G723_53;
+#endif
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_30;
+                       iflist[c].ptime = 30;
+                       break;
+               case AST_FORMAT_G729A:
+                        enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G729;
+                        enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+                        iflist[c].ptime = 10;
+                        break;
+               default:
+                       ast_log(LOG_ERROR, "unsupported format %s (0x%x)\n", ast_getformatname(format), (int) formatid);
+                       enc_cfg.nEncType = IFX_TAPI_COD_TYPE_MLAW;
+                       enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+                       iflist[c].ptime = 10;
+       }
+
+       ast_log(LOG_DEBUG, "Configuring encoder to use TAPI codec type %d (%s) on channel %i\n", enc_cfg.nEncType, ast_getformatname(format), c);
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_CFG_SET, &enc_cfg)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_ENC_CFG_SET %d failed\n", c);
+       }
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_START, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_ENC_START ioctl failed\n");
+       }
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_DEC_START, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_DEC_START ioctl failed\n");
+       }
+
+       return 0;
+}
+
+static int ast_lantiq_write(struct ast_channel *ast, struct ast_frame *frame)
+{
+       char buf[RTP_BUFFER_LEN];
+       rtp_header_t *rtp_header = (rtp_header_t *) buf;
+       struct lantiq_pvt *pvt = ast_channel_tech_pvt(ast);
+       int ret;
+       uint8_t rtptype;
+       int subframes, subframes_rtp, length, samples;
+       char *head, *tail;
+
+       if(frame->frametype != AST_FRAME_VOICE) {
+               ast_log(LOG_DEBUG, "unhandled frame type\n");
+               return 0;
+       }
+
+       if (frame->datalen == 0) {
+               ast_log(LOG_DEBUG, "we've been prodded\n");
+               return 0;
+       }
+
+       /* get rtp payload type */
+       rtptype = lantiq_map_format_to_rtptype(&frame->subclass.format);
+
+       rtp_header->version      = 2;
+       rtp_header->padding      = 0;
+       rtp_header->extension    = 0;
+       rtp_header->csrc_count   = 0;
+       rtp_header->marker       = 0;
+       rtp_header->ssrc         = 0;
+       rtp_header->payload_type = rtptype;
+
+       subframes = (iflist[pvt->port_id].ptime + frame->len - 1) / iflist[pvt->port_id].ptime; /* number of subframes in AST frame */
+       if (subframes == 0)
+               subframes = 1;
+
+       subframes_rtp = (RTP_BUFFER_LEN - RTP_HEADER_LEN) * subframes / frame->datalen; /* how many frames fit in a single RTP packet */
+
+       /* By default stick to the maximum multiple of native frame length */
+       length = subframes_rtp * frame->datalen / subframes;
+       samples = length * frame->samples / frame->datalen;
+
+       head = frame->data.ptr;
+       tail = frame->data.ptr + frame->datalen;
+       while (head < tail) {
+               rtp_header->seqno        = pvt->rtp_seqno++;
+               rtp_header->timestamp    = pvt->rtp_timestamp;
+
+               if ((tail - head) < (RTP_BUFFER_LEN - RTP_HEADER_LEN)) {
+                       length = tail - head;
+                       samples = length * frame->samples / frame->datalen;
+               }
+
+               if ( frame->datalen <= (sizeof(buf) - RTP_HEADER_LEN) )
+                       memcpy(buf + RTP_HEADER_LEN, head, length);
+               else {
+                       ast_log(LOG_WARNING, "buffer is too small\n");
+                       return -1;
+               }
+
+               head += length;
+               pvt->rtp_timestamp += (rtp_header->payload_type == RTP_G722) ? samples / 2 : samples; /* per RFC3551 */
+
+               ret = write(dev_ctx.ch_fd[pvt->port_id], buf, RTP_HEADER_LEN + length);
+               if (ret < 0) {
+                       ast_debug(1, "TAPI: ast_lantiq_write(): error writing.\n");
+                       return -1;
+               }
+               if (ret != (RTP_HEADER_LEN + length)) {
+                       ast_log(LOG_WARNING, "Short TAPI write of %d bytes, expected %d bytes\n", ret, RTP_HEADER_LEN + length);
+                       continue;
+               }
+       }
+
+       return 0;
+}
+
+static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *args, char *buf, size_t buflen)
+{
+       struct lantiq_pvt *pvt;
+       int res = 0;
+
+       if (!chan || ast_channel_tech(chan) != &lantiq_tech) {
+               ast_log(LOG_ERROR, "This function requires a valid Lantiq TAPI channel\n");
+               return -1;
+       }
+
+       ast_mutex_lock(&iflock);
+
+       pvt = (struct lantiq_pvt*) ast_channel_tech_pvt(chan);
+
+       if (!strcasecmp(args, "csd")) {
+               snprintf(buf, buflen, "%lu", (unsigned long int) pvt->call_setup_delay);
+       } else if (!strcasecmp(args, "jitter_stats")){
+               lantiq_jb_get_stats(pvt->port_id);
+               snprintf(buf, buflen, "jbBufSize=%u,jbUnderflow=%u,jbOverflow=%u,jbDelay=%u,jbInvalid=%u",
+                               (uint32_t) pvt->jb_size,
+                               (uint32_t) pvt->jb_underflow,
+                               (uint32_t) pvt->jb_overflow,
+                               (uint32_t) pvt->jb_delay,
+                               (uint32_t) pvt->jb_invalid);
+       } else if (!strcasecmp(args, "jbBufSize")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_size);
+       } else if (!strcasecmp(args, "jbUnderflow")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_underflow);
+       } else if (!strcasecmp(args, "jbOverflow")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_overflow);
+       } else if (!strcasecmp(args, "jbDelay")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_delay);
+       } else if (!strcasecmp(args, "jbInvalid")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_invalid);
+       } else if (!strcasecmp(args, "start")) {
+               struct tm *tm = gmtime((const time_t*)&pvt->call_start);
+               strftime(buf, buflen, "%F %T", tm);
+       } else if (!strcasecmp(args, "answer")) {
+               struct tm *tm = gmtime((const time_t*)&pvt->call_answer);
+               strftime(buf, buflen, "%F %T", tm);
+       } else {
+               res = -1;
+       }
+
+       ast_mutex_unlock(&iflock);
+
+       return res;
+}
+
+static struct ast_frame * ast_lantiq_exception(struct ast_channel *ast)
+{
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return NULL;
+}
+
+static void lantiq_jb_get_stats(int c) {
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       IFX_TAPI_JB_STATISTICS_t param;
+       memset (&param, 0, sizeof (param));
+       if (ioctl (dev_ctx.ch_fd[c], IFX_TAPI_JB_STATISTICS_GET, (IFX_int32_t) &param) != IFX_SUCCESS) {
+               ast_debug(1, "Error getting jitter buffer  stats.\n");
+       } else {
+#if !defined (TAPI_VERSION3) && defined (TAPI_VERSION4)
+               ast_debug(1, "Jitter buffer stats:  dev=%u, ch=%u, nType=%u, nBufSize=%u, nIsUnderflow=%u, nDsOverflow=%u, nPODelay=%u, nInvalid=%u\n",
+                               (uint32_t) param.dev,
+                               (uint32_t) param.ch,
+#else
+               ast_debug(1, "Jitter buffer stats:  nType=%u, nBufSize=%u, nIsUnderflow=%u, nDsOverflow=%u, nPODelay=%u, nInvalid=%u\n",
+#endif
+                               (uint32_t) param.nType,
+                               (uint32_t) param.nBufSize,
+                               (uint32_t) param.nIsUnderflow,
+                               (uint32_t) param.nDsOverflow,
+                               (uint32_t) param.nPODelay,
+                               (uint32_t) param.nInvalid);
+
+               pvt->jb_size = param.nBufSize;
+               pvt->jb_underflow = param.nIsUnderflow;
+               pvt->jb_overflow = param.nDsOverflow;
+               pvt->jb_invalid = param.nInvalid;
+               pvt->jb_delay = param.nPODelay;
+       }
+}
+
+
+static int lantiq_standby(int c)
+{
+       ast_debug(1, "Stopping line feed for channel %i\n", c);
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_FEED_SET, IFX_TAPI_LINE_FEED_STANDBY)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_LINE_FEED_SET ioctl failed\n");
+               return -1;
+       }
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_STOP, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_ENC_STOP ioctl failed\n");
+               return -1;
+       }
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_DEC_STOP, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_DEC_STOP ioctl failed\n");
+               return -1;
+       }
+
+       return lantiq_play_tone(c, TAPI_TONE_LOCALE_NONE);
+}
+
+static int lantiq_end_dialing(int c)
+{
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       ast_log(LOG_DEBUG, "end of dialing\n");
+
+       if (pvt->dial_timer != -1) {
+               AST_SCHED_DEL(sched, pvt->dial_timer);
+               pvt->dial_timer = -1;
+       }
+
+       if(pvt->owner) {
+               ast_hangup(pvt->owner);
+       }
+       lantiq_reset_dtmfbuf(pvt);
+
+       return 0;
+}
+
+static int lantiq_end_call(int c)
+{
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       ast_log(LOG_DEBUG, "end of call\n");
+
+       if(pvt->owner) {
+               lantiq_jb_get_stats(c);
+               ast_queue_hangup(pvt->owner);
+       }
+
+       return 0;
+}
+
+static struct ast_channel *lantiq_channel(int state, int c, char *ext, char *ctx, struct ast_format_cap *cap)
+{
+       struct ast_channel *chan = NULL;
+       struct lantiq_pvt *pvt = &iflist[c];
+       struct ast_format format = {0};
+       struct ast_format_cap *newcap = ast_format_cap_alloc();
+
+       if (!newcap) {
+               ast_log(LOG_DEBUG, "Cannot allocate format capabilities!\n");
+               return NULL;
+       }
+
+       chan = ast_channel_alloc(1, state, NULL, NULL, "", ext, ctx, 0, c, "TAPI/%d", (c + 1));
+       if (!chan) {
+               ast_log(LOG_DEBUG, "Cannot allocate channel!\n");
+               ast_format_cap_destroy(newcap);
+               return NULL;
+       }
+
+       ast_channel_tech_set(chan, &lantiq_tech);
+       ast_channel_tech_pvt_set(chan, pvt);
+       pvt->owner = chan;
+
+       if (cap && ast_format_cap_has_joint(cap, lantiq_tech.capabilities)) { /* compatible format capabilities given */
+               ast_format_cap_joint_copy(lantiq_tech.capabilities, cap, newcap);
+               ast_best_codec(newcap, &format); /* choose format */
+       } else { /* no or unsupported format capabilities given */
+               ast_best_codec(lantiq_tech.capabilities, &format); /* choose format from capabilities */
+       }
+
+       /* set choosed format */
+       ast_format_cap_set(ast_channel_nativeformats(chan), &format);
+       ast_format_copy(ast_channel_readformat(chan), &format);
+       ast_format_copy(ast_channel_writeformat(chan), &format);
+       ast_format_copy(ast_channel_rawreadformat(chan), &format);
+       ast_format_copy(ast_channel_rawwriteformat(chan), &format);
+
+       ast_format_cap_destroy(newcap);
+
+       /* configuring encoder */
+       if (format.id != 0)
+               if (lantiq_conf_enc(c, &format) < 0)
+                       return NULL;
+
+       return chan;
+}
+
+static struct ast_channel *ast_lantiq_requester(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause)
+{
+       char buf[BUFSIZ];
+       struct ast_channel *chan = NULL;
+       int port_id = -1;
+
+       ast_mutex_lock(&iflock);
+
+       ast_debug(1, "Asked to create a TAPI channel with formats: %s\n", ast_getformatname_multiple(buf, sizeof(buf), cap));
+
+       /* check for correct data argument */
+       if (ast_strlen_zero(data)) {
+               ast_log(LOG_ERROR, "Unable to create channel with empty destination.\n");
+               *cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
+               goto bailout;
+       }
+
+       /* get our port number */
+       port_id = atoi((char*) data);
+       if (port_id < 1 || port_id > dev_ctx.channels) {
+               ast_log(LOG_ERROR, "Unknown channel ID: \"%s\"\n", data);
+               *cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
+               goto bailout;
+       }
+
+       /* on asterisk user's side, we're using port 1-2.
+        * Here in non normal human's world, we begin
+        * counting at 0.
+        */
+       port_id -= 1;
+
+
+       /* Bail out if channel is already in use */
+       struct lantiq_pvt *pvt = &iflist[port_id];
+       if (! pvt->channel_state == ONHOOK) {
+               ast_debug(1, "TAPI channel %i alread in use.\n", port_id+1);
+       } else {
+               chan = lantiq_channel(AST_STATE_DOWN, port_id, NULL, NULL, cap);
+               ast_channel_unlock(chan);
+       }
+
+bailout:
+       ast_mutex_unlock(&iflock);
+       return chan;
+}
+
+static int ast_lantiq_devicestate(const char *data)
+{
+       int port = atoi(data) - 1;
+       if ((port < 1) || (port > dev_ctx.channels)) {
+               return AST_DEVICE_INVALID;
+       }
+
+       switch (iflist[port].channel_state) {
+               case ONHOOK:
+                       return AST_DEVICE_NOT_INUSE;
+               case OFFHOOK:
+               case DIALING:
+               case INCALL:
+               case CALL_ENDED:
+                       return AST_DEVICE_INUSE;
+               case RINGING:
+                       return AST_DEVICE_RINGING;
+               case UNKNOWN:
+               default:
+                       return AST_DEVICE_UNKNOWN;
+       }
+}
+
+static int lantiq_dev_data_handler(int c)
+{
+       char buf[BUFSIZ];
+       struct ast_frame frame = {0};
+       struct ast_format format = {0};
+
+       int res = read(dev_ctx.ch_fd[c], buf, sizeof(buf));
+       if (res <= 0) {
+               ast_log(LOG_ERROR, "we got read error %i\n", res);
+               return -1;
+       } else if (res < RTP_HEADER_LEN) {
+               ast_log(LOG_ERROR, "we got data smaller than header size\n");
+               return -1;
+       }
+
+       rtp_header_t *rtp = (rtp_header_t*) buf;
+       struct lantiq_pvt *pvt = (struct lantiq_pvt *) &iflist[c];
+       if ((!pvt->owner) || (ast_channel_state(pvt->owner) != AST_STATE_UP)) {
+               return 0;
+       }
+
+       if (rtp->payload_type == RTP_CN) {
+               /* TODO: Handle Comfort Noise frames */
+               ast_debug(1, "Dropping Comfort Noise frame\n");
+       }
+
+       format = lantiq_map_rtptype_to_format(rtp->payload_type);
+       frame.src = "TAPI";
+       frame.frametype = AST_FRAME_VOICE;
+       ast_format_copy(&frame.subclass.format, &format);
+       frame.datalen = res - RTP_HEADER_LEN;
+       frame.data.ptr = buf + RTP_HEADER_LEN;
+       frame.samples = ast_codec_get_samples(&frame);
+
+       if(!ast_channel_trylock(pvt->owner)) {
+               ast_queue_frame(pvt->owner, &frame);
+               ast_channel_unlock(pvt->owner);
+       }
+
+       return 0;
+}
+
+static int accept_call(int c)
+{
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       ast_log(LOG_DEBUG, "accept call\n");
+
+       if (pvt->owner) {
+               struct ast_channel *chan = pvt->owner;
+
+               switch (ast_channel_state(chan)) {
+                       case AST_STATE_RINGING:
+                               lantiq_play_tone(c, TAPI_TONE_LOCALE_NONE);
+                               ast_queue_control(pvt->owner, AST_CONTROL_ANSWER);
+                               pvt->channel_state = INCALL;
+                               pvt->call_start = epoch();
+                               pvt->call_answer = pvt->call_start;
+                               break;
+                       default:
+                               ast_log(LOG_WARNING, "entered unhandled state %s\n", ast_state2str(ast_channel_state(chan)));
+               }
+       }
+
+       return 0;
+}
+
+static int lantiq_dev_event_hook(int c, int state)
+{
+       ast_mutex_lock(&iflock);
+
+       ast_log(LOG_DEBUG, "on port %i detected event %s hook\n", c, state ? "on" : "off");
+
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       int ret = -1;
+       if (state) { /* going onhook */
+               switch (iflist[c].channel_state) {
+                       case DIALING:
+                               ret = lantiq_end_dialing(c);
+                               break;
+                       case INCALL:
+                               ret = lantiq_end_call(c);
+                               break;
+               }
+
+               iflist[c].channel_state = ONHOOK;
+
+               /* stop DSP data feed */
+               lantiq_standby(c);
+               led_off(dev_ctx.ch_led[c]);
+
+       } else { /* going offhook */
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_FEED_SET, IFX_TAPI_LINE_FEED_ACTIVE)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_LINE_FEED_SET ioctl failed\n");
+                       goto out;
+               }
+
+               switch (iflist[c].channel_state) {
+                       case RINGING:
+                               ret = accept_call(c);
+                               led_blink(dev_ctx.ch_led[c], LED_SLOW_BLINK);
+                               break;
+                       default:
+                               iflist[c].channel_state = OFFHOOK;
+                               lantiq_play_tone(c, TAPI_TONE_LOCALE_DIAL_CODE);
+                               lantiq_reset_dtmfbuf(pvt);
+                               ret = 0;
+                               led_on(dev_ctx.ch_led[c]);
+                               break;
+               }
+
+       }
+
+out:
+       ast_mutex_unlock(&iflock);
+
+       return ret;
+}
+
+static void lantiq_reset_dtmfbuf(struct lantiq_pvt *pvt)
+{
+       pvt->dtmfbuf[0] = '\0';
+       pvt->dtmfbuf_len = 0;
+}
+
+static void lantiq_dial(struct lantiq_pvt *pvt)
+{
+       struct ast_channel *chan = NULL;
+
+       ast_mutex_lock(&iflock);
+       ast_log(LOG_DEBUG, "user want's to dial %s.\n", pvt->dtmfbuf);
+
+       if (ast_exists_extension(NULL, pvt->context, pvt->dtmfbuf, 1, NULL)) {
+               ast_debug(1, "found extension %s, dialing\n", pvt->dtmfbuf);
+
+               ast_verbose(VERBOSE_PREFIX_3 " extension exists, starting PBX %s\n", pvt->dtmfbuf);
+
+               chan = lantiq_channel(AST_STATE_UP, pvt->port_id, pvt->dtmfbuf, pvt->context, NULL);
+               if (!chan) {
+                       ast_log(LOG_ERROR, "couldn't create channel\n");
+                       goto bailout;
+               }
+               ast_channel_tech_pvt_set(chan, pvt);
+               pvt->owner = chan;
+
+               ast_setstate(chan, AST_STATE_RING);
+               pvt->channel_state = INCALL;
+
+               pvt->call_setup_start = now();
+               pvt->call_start = epoch();
+
+               if (ast_pbx_start(chan)) {
+                       ast_log(LOG_WARNING, " unable to start PBX on %s\n", ast_channel_name(chan));
+                       ast_hangup(chan);
+               }
+
+               ast_channel_unlock(chan);
+       } else {
+               ast_log(LOG_DEBUG, "no extension found\n");
+               lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_CONGESTION_CODE);
+               pvt->channel_state = CALL_ENDED;
+       }
+
+       lantiq_reset_dtmfbuf(pvt);
+bailout:
+       ast_mutex_unlock(&iflock);
+}
+
+static int lantiq_event_dial_timeout(const void* data)
+{
+       ast_debug(1, "TAPI: lantiq_event_dial_timeout()\n");
+
+       struct lantiq_pvt *pvt = (struct lantiq_pvt *) data;
+       pvt->dial_timer = -1;
+
+       if (! pvt->channel_state == ONHOOK) {
+               lantiq_dial(pvt);
+       } else {
+               ast_debug(1, "TAPI: lantiq_event_dial_timeout(): dial timeout in state ONHOOK.\n");
+       }
+
+       return 0;
+}
+
+static int lantiq_send_digit(int c, char digit)
+{
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       struct ast_frame f = { .frametype = AST_FRAME_DTMF, .subclass.integer = digit };
+
+       if (pvt->owner) {
+               ast_log(LOG_DEBUG, "Port %i transmitting digit \"%c\"\n", c, digit);
+               return ast_queue_frame(pvt->owner, &f);
+       } else {
+               ast_debug(1, "Warning: lantiq_send_digit() without owner!\n");
+               return -1;
+       }
+}
+
+static void lantiq_dev_event_digit(int c, char digit)
+{
+       ast_mutex_lock(&iflock);
+
+       ast_log(LOG_DEBUG, "on port %i detected digit \"%c\"\n", c, digit);
+
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       switch (pvt->channel_state) {
+               case INCALL:
+                       lantiq_send_digit(c, digit);
+                       break;
+               case OFFHOOK:
+                       pvt->channel_state = DIALING;
+
+                       lantiq_play_tone(c, TAPI_TONE_LOCALE_NONE);
+                       led_blink(dev_ctx.ch_led[c], LED_SLOW_BLINK);
+
+                       /* fall through */
+               case DIALING:
+                       if (pvt->dtmfbuf_len < AST_MAX_EXTENSION - 1) {
+                               pvt->dtmfbuf[pvt->dtmfbuf_len] = digit;
+                               pvt->dtmfbuf[++pvt->dtmfbuf_len] = '\0';
+                       } else {
+                               /* No more room for another digit */
+                               lantiq_end_dialing(c);
+                               lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_BUSY_CODE);
+                               pvt->channel_state = CALL_ENDED;
+                               break;
+                       }
+
+                       /* setup autodial timer */
+                       if (pvt->dial_timer == -1) {
+                               ast_log(LOG_DEBUG, "setting new timer\n");
+                               pvt->dial_timer = ast_sched_add(sched, dev_ctx.interdigit_timeout, lantiq_event_dial_timeout, (const void*) pvt);
+                       } else {
+                               ast_log(LOG_DEBUG, "replacing timer\n");
+                               AST_SCHED_REPLACE(pvt->dial_timer, sched, dev_ctx.interdigit_timeout, lantiq_event_dial_timeout, (const void*) pvt);
+                       }
+                       break;
+               default:
+                       ast_log(LOG_ERROR, "don't know what to do in unhandled state\n");
+                       break;
+       }
+
+       ast_mutex_unlock(&iflock);
+       return;
+}
+
+static void lantiq_dev_event_handler(void)
+{
+       IFX_TAPI_EVENT_t event;
+       unsigned int i;
+
+       for (i = 0; i < dev_ctx.channels ; i++) {
+               ast_mutex_lock(&iflock);
+
+               memset (&event, 0, sizeof(event));
+               event.ch = i;
+               if (ioctl(dev_ctx.dev_fd, IFX_TAPI_EVENT_GET, &event)) {
+                       ast_mutex_unlock(&iflock);
+                       continue;
+               }
+               if (event.id == IFX_TAPI_EVENT_NONE) {
+                       ast_mutex_unlock(&iflock);
+                       continue;
+               }
+
+               ast_mutex_unlock(&iflock);
+
+               switch(event.id) {
+                       case IFX_TAPI_EVENT_FXS_ONHOOK:
+                               lantiq_dev_event_hook(i, 1);
+                               break;
+                       case IFX_TAPI_EVENT_FXS_OFFHOOK:
+                               lantiq_dev_event_hook(i, 0);
+                               break;
+                       case IFX_TAPI_EVENT_DTMF_DIGIT:
+                               lantiq_dev_event_digit(i, (char)event.data.dtmf.ascii);
+                               break;
+                       case IFX_TAPI_EVENT_PULSE_DIGIT:
+                               if (event.data.pulse.digit == 0xB) {
+                                       lantiq_dev_event_digit(i, '0');
+                               } else {
+                                       lantiq_dev_event_digit(i, '0' + (char)event.data.pulse.digit);
+                               }
+                               break;
+                       case IFX_TAPI_EVENT_COD_DEC_CHG:
+                       case IFX_TAPI_EVENT_TONE_GEN_END:
+                       case IFX_TAPI_EVENT_CID_TX_SEQ_END:
+                               break;
+                       default:
+                               ast_log(LOG_ERROR, "Unknown TAPI event %08X. Restarting Asterisk...\n", event.id);
+                               sleep(1);
+                               ast_cli_command(-1, "core restart now");
+                               break;
+               }
+       }
+}
+
+static void * lantiq_events_monitor(void *data)
+{
+       ast_verbose("TAPI thread started\n");
+
+       struct pollfd fds[TAPI_AUDIO_PORT_NUM_MAX + 1];
+       int c;
+
+       fds[0].fd = dev_ctx.dev_fd;
+       fds[0].events = POLLIN;
+       for (c = 0; c < dev_ctx.channels; c++) {
+               fds[c + 1].fd = dev_ctx.ch_fd[c];
+               fds[c + 1].events = POLLIN;
+       }
+
+       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+       for (;;) {
+               if (poll(fds, dev_ctx.channels + 1, 2000) <= 0) {
+                       continue;
+               }
+
+               ast_mutex_lock(&monlock);
+               if (fds[0].revents & POLLIN) {
+                       lantiq_dev_event_handler();
+               }
+
+               for (c = 0; c < dev_ctx.channels; c++) {
+                       if ((fds[c + 1].revents & POLLIN) && (lantiq_dev_data_handler(c))) {
+                               ast_log(LOG_ERROR, "data handler %d failed\n", c);
+                               break;
+                       }
+               }
+               ast_mutex_unlock(&monlock);
+       }
+
+       return NULL;
+}
+
+static int restart_monitor(void)
+{
+       /* If we're supposed to be stopped -- stay stopped */
+       if (monitor_thread == AST_PTHREADT_STOP)
+               return 0;
+
+       ast_mutex_lock(&monlock);
+
+       if (monitor_thread == pthread_self()) {
+               ast_mutex_unlock(&monlock);
+               ast_log(LOG_WARNING, "Cannot kill myself\n");
+               return -1;
+       }
+
+       if (monitor_thread != AST_PTHREADT_NULL) {
+               /* Wake up the thread */
+               pthread_kill(monitor_thread, SIGURG);
+       } else {
+               /* Start a new monitor */
+               if (ast_pthread_create_background(&monitor_thread, NULL, lantiq_events_monitor, NULL) < 0) {
+                       ast_mutex_unlock(&monlock);
+                       ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
+                       return -1;
+               }
+       }
+       ast_mutex_unlock(&monlock);
+
+       return 0;
+}
+
+static void lantiq_cleanup(void)
+{
+       int c;
+
+       if (dev_ctx.dev_fd < 0) {
+               return;
+       }
+
+       for (c = 0; c < dev_ctx.channels ; c++) {
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_FEED_SET, IFX_TAPI_LINE_FEED_STANDBY)) {
+                       ast_log(LOG_WARNING, "IFX_TAPI_LINE_FEED_SET ioctl failed\n");
+               }
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_STOP, 0)) {
+                       ast_log(LOG_WARNING, "IFX_TAPI_ENC_STOP ioctl failed\n");
+               }
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_DEC_STOP, 0)) {
+                       ast_log(LOG_WARNING, "IFX_TAPI_DEC_STOP ioctl failed\n");
+               }
+               led_off(dev_ctx.ch_led[c]);
+       }
+
+       if (ioctl(dev_ctx.dev_fd, IFX_TAPI_DEV_STOP, 0)) {
+               ast_log(LOG_WARNING, "IFX_TAPI_DEV_STOP ioctl failed\n");
+       }
+
+       close(dev_ctx.dev_fd);
+       dev_ctx.dev_fd = -1;
+       led_off(dev_ctx.voip_led);
+}
+
+static int unload_module(void)
+{
+       int c;
+
+       ast_channel_unregister(&lantiq_tech);
+
+       if (ast_mutex_lock(&iflock)) {
+               ast_log(LOG_WARNING, "Unable to lock the interface list\n");
+               return -1;
+       }
+       for (c = 0; c < dev_ctx.channels ; c++) {
+               if (iflist[c].owner)
+                       ast_softhangup(iflist[c].owner, AST_SOFTHANGUP_APPUNLOAD);
+       }
+       ast_mutex_unlock(&iflock);
+
+       if (ast_mutex_lock(&monlock)) {
+               ast_log(LOG_WARNING, "Unable to lock the monitor\n");
+               return -1;
+       }
+       if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
+               pthread_t th = monitor_thread;
+               monitor_thread = AST_PTHREADT_STOP;
+               pthread_cancel(th);
+               pthread_kill(th, SIGURG);
+               ast_mutex_unlock(&monlock);
+               pthread_join(th, NULL);
+       } else {
+               monitor_thread = AST_PTHREADT_STOP;
+               ast_mutex_unlock(&monlock);
+       }
+
+       ast_sched_context_destroy(sched);
+       ast_mutex_destroy(&iflock);
+       ast_mutex_destroy(&monlock);
+
+       lantiq_cleanup();
+       ast_free(iflist);
+
+       return 0;
+}
+
+static struct lantiq_pvt *lantiq_init_pvt(struct lantiq_pvt *pvt)
+{
+       if (pvt) {
+               pvt->owner = NULL;
+               pvt->port_id = -1;
+               pvt->channel_state = UNKNOWN;
+               pvt->context[0] = '\0';
+               pvt->dial_timer = -1;
+               pvt->dtmfbuf[0] = '\0';
+               pvt->dtmfbuf_len = 0;
+               pvt->call_setup_start = 0;
+               pvt->call_setup_delay = 0;
+               pvt->call_answer = 0;
+               pvt->jb_size = 0;
+               pvt->jb_underflow = 0;
+               pvt->jb_overflow = 0;
+               pvt->jb_delay = 0;
+               pvt->jb_invalid = 0;
+       } else {
+               ast_log(LOG_ERROR, "unable to clear pvt structure\n");
+       }
+
+       return pvt;
+}
+
+static int lantiq_create_pvts(void)
+{
+       int i;
+
+       iflist = ast_calloc(1, sizeof(struct lantiq_pvt) * dev_ctx.channels);
+
+       if (!iflist) {
+               ast_log(LOG_ERROR, "unable to allocate memory\n");
+               return -1;
+       }
+
+       for (i = 0; i < dev_ctx.channels; i++) {
+               lantiq_init_pvt(&iflist[i]);
+               iflist[i].port_id = i;
+               if (per_channel_context) {
+                       snprintf(iflist[i].context, AST_MAX_CONTEXT, "%s%i", LANTIQ_CONTEXT_PREFIX, i + 1);
+                       ast_debug(1, "Context for channel %i: %s\n", i, iflist[i].context);
+               } else {
+                       snprintf(iflist[i].context, AST_MAX_CONTEXT, "default");
+               }
+       }
+       return 0;
+}
+
+static int lantiq_setup_rtp(int c)
+{
+       /* Configure RTP payload type tables */
+       IFX_TAPI_PKT_RTP_PT_CFG_t rtpPTConf;
+
+       memset((char*)&rtpPTConf, '\0', sizeof(rtpPTConf));
+
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G723_63] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G723_63] = RTP_G723_63;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G723_53] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G723_53] = RTP_G723_53;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G729] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G729] = RTP_G729;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_MLAW] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_MLAW] = RTP_PCMU;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_ALAW] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_ALAW] = RTP_PCMA;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G726_32] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G726_32] = RTP_G726;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_ILBC_152] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_ILBC_152] = RTP_ILBC;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_LIN16_8] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_LIN16_8] = RTP_SLIN8;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_LIN16_16] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_LIN16_16] = RTP_SLIN16;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G722_64] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G722_64] = RTP_G722;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G7221_32] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G7221_32] = RTP_G7221;
+
+       int ret;
+       if ((ret = ioctl(dev_ctx.ch_fd[c], IFX_TAPI_PKT_RTP_PT_CFG_SET, (IFX_int32_t) &rtpPTConf))) {
+               ast_log(LOG_ERROR, "IFX_TAPI_PKT_RTP_PT_CFG_SET failed: ret=%i\n", ret);
+               return -1;
+       }
+
+       return 0;
+}
+
+static int load_module(void)
+{
+       struct ast_config *cfg;
+       struct ast_variable *v;
+       int txgain = 0;
+       int rxgain = 0;
+       int wlec_type = 0;
+       int wlec_nlp = 0;
+       int wlec_nbfe = 0;
+       int wlec_nbne = 0;
+       int wlec_wbne = 0;
+       int jb_type = IFX_TAPI_JB_TYPE_ADAPTIVE;
+       int jb_pckadpt = IFX_TAPI_JB_PKT_ADAPT_VOICE;
+       int jb_localadpt = IFX_TAPI_JB_LOCAL_ADAPT_DEFAULT;
+       int jb_scaling = 0x10;
+       int jb_initialsize = 0x2d0;
+       int jb_minsize = 0x50;
+       int jb_maxsize = 0x5a0;
+       int cid_type = IFX_TAPI_CID_STD_TELCORDIA;
+       int vad_type = IFX_TAPI_ENC_VAD_NOVAD;
+       dev_ctx.dev_fd = -1;
+       dev_ctx.channels = TAPI_AUDIO_PORT_NUM_MAX;
+       dev_ctx.interdigit_timeout = DEFAULT_INTERDIGIT_TIMEOUT;
+       struct ast_tone_zone *tz;
+       struct ast_flags config_flags = { 0 };
+       int c;
+       struct ast_format format;
+
+       if(!(lantiq_tech.capabilities = ast_format_cap_alloc())) {
+         ast_log(LOG_ERROR, "Unable to allocate format capabilities.\n");
+         return AST_MODULE_LOAD_DECLINE;
+       }
+
+       /* channel format capabilities */
+       ast_format_cap_add(lantiq_tech.capabilities, ast_format_set(&format, AST_FORMAT_ULAW, 0));
+       ast_format_cap_add(lantiq_tech.capabilities, ast_format_set(&format, AST_FORMAT_ALAW, 0));
+       ast_format_cap_add(lantiq_tech.capabilities, ast_format_set(&format, AST_FORMAT_G722, 0));
+       ast_format_cap_add(lantiq_tech.capabilities, ast_format_set(&format, AST_FORMAT_G726, 0));
+       ast_format_cap_add(lantiq_tech.capabilities, ast_format_set(&format, AST_FORMAT_SLINEAR, 0));
+
+       /* Turn off the LEDs, just in case */
+       led_off(dev_ctx.voip_led);
+       for(c = 0; c < TAPI_AUDIO_PORT_NUM_MAX; c++)
+               led_off(dev_ctx.ch_led[c]);
+
+       if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+               ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+               return AST_MODULE_LOAD_DECLINE;
+       }
+
+       /* We *must* have a config file otherwise stop immediately */
+       if (!cfg) {
+               ast_log(LOG_ERROR, "Unable to load config %s\n", config);
+               return AST_MODULE_LOAD_DECLINE;
+       }
+
+       if (ast_mutex_lock(&iflock)) {
+               ast_log(LOG_ERROR, "Unable to lock interface list.\n");
+               goto cfg_error;
+       }
+
+       for (v = ast_variable_browse(cfg, "interfaces"); v; v = v->next) {
+               if (!strcasecmp(v->name, "channels")) {
+                       dev_ctx.channels = atoi(v->value);
+                       if (!dev_ctx.channels) {
+                               ast_log(LOG_ERROR, "Invalid value for channels in config %s\n", config);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "firmwarefilename")) {
+                       ast_copy_string(firmware_filename, v->value, sizeof(firmware_filename));
+               } else if (!strcasecmp(v->name, "bbdfilename")) {
+                       ast_copy_string(bbd_filename, v->value, sizeof(bbd_filename));
+               } else if (!strcasecmp(v->name, "basepath")) {
+                       ast_copy_string(base_path, v->value, sizeof(base_path));
+               } else if (!strcasecmp(v->name, "per_channel_context")) {
+                       if (!strcasecmp(v->value, "on")) {
+                               per_channel_context = 1;
+                       } else if (!strcasecmp(v->value, "off")) {
+                               per_channel_context = 0;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown per_channel_context value '%s'. Try 'on' or 'off'.\n", v->value);
+                               goto cfg_error_il;
+                       }
+               }
+       }
+
+       for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
+               if (!strcasecmp(v->name, "rxgain")) {
+                       rxgain = atoi(v->value);
+                       if (!rxgain) {
+                               rxgain = 0;
+                               ast_log(LOG_WARNING, "Invalid rxgain: %s, using default.\n", v->value);
+                       }
+               } else if (!strcasecmp(v->name, "txgain")) {
+                       txgain = atoi(v->value);
+                       if (!txgain) {
+                               txgain = 0;
+                               ast_log(LOG_WARNING, "Invalid txgain: %s, using default.\n", v->value);
+                       }
+               } else if (!strcasecmp(v->name, "echocancel")) {
+                       if (!strcasecmp(v->value, "off")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_OFF;
+                       } else if (!strcasecmp(v->value, "nlec")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_NE;
+                               if (!strcasecmp(v->name, "echocancelfixedwindowsize")) {
+                                       wlec_nbne = atoi(v->value);
+                               }
+                       } else if (!strcasecmp(v->value, "wlec")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_NFE;
+                               if (!strcasecmp(v->name, "echocancelnfemovingwindowsize")) {
+                                       wlec_nbfe = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "echocancelfixedwindowsize")) {
+                                       wlec_nbne = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "echocancelwidefixedwindowsize")) {
+                                       wlec_wbne = atoi(v->value);
+                               }
+                       } else if (!strcasecmp(v->value, "nees")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_NE_ES;
+                       } else if (!strcasecmp(v->value, "nfees")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_NFE_ES;
+                       } else if (!strcasecmp(v->value, "es")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_ES;
+                       } else {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_OFF;
+                               ast_log(LOG_ERROR, "Unknown echo cancellation type '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "echocancelnlp")) {
+                       if (!strcasecmp(v->value, "on")) {
+                               wlec_nlp = IFX_TAPI_WLEC_NLP_ON;
+                       } else if (!strcasecmp(v->value, "off")) {
+                               wlec_nlp = IFX_TAPI_WLEC_NLP_OFF;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown echo cancellation nlp '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "jitterbuffertype")) {
+                       if (!strcasecmp(v->value, "fixed")) {
+                               jb_type = IFX_TAPI_JB_TYPE_FIXED;
+                       } else if (!strcasecmp(v->value, "adaptive")) {
+                               jb_type = IFX_TAPI_JB_TYPE_ADAPTIVE;
+                               jb_localadpt = IFX_TAPI_JB_LOCAL_ADAPT_DEFAULT;
+                               if (!strcasecmp(v->name, "jitterbufferadaptation")) {
+                                       if (!strcasecmp(v->value, "on")) {
+                                               jb_localadpt = IFX_TAPI_JB_LOCAL_ADAPT_ON;
+                                       } else if (!strcasecmp(v->value, "off")) {
+                                               jb_localadpt = IFX_TAPI_JB_LOCAL_ADAPT_OFF;
+                                       }
+                               } else if (!strcasecmp(v->name, "jitterbufferscalling")) {
+                                       jb_scaling = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "jitterbufferinitialsize")) {
+                                       jb_initialsize = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "jitterbufferminsize")) {
+                                       jb_minsize = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "jitterbuffermaxsize")) {
+                                       jb_maxsize = atoi(v->value);
+                               }
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown jitter buffer type '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "jitterbufferpackettype")) {
+                       if (!strcasecmp(v->value, "voice")) {
+                               jb_pckadpt = IFX_TAPI_JB_PKT_ADAPT_VOICE;
+                       } else if (!strcasecmp(v->value, "data")) {
+                               jb_pckadpt = IFX_TAPI_JB_PKT_ADAPT_DATA;
+                       } else if (!strcasecmp(v->value, "datanorep")) {
+                               jb_pckadpt = IFX_TAPI_JB_PKT_ADAPT_DATA_NO_REP;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown jitter buffer packet adaptation type '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "calleridtype")) {
+                       ast_log(LOG_DEBUG, "Setting CID type to %s.\n", v->value);
+                       if (!strcasecmp(v->value, "telecordia")) {
+                               cid_type = IFX_TAPI_CID_STD_TELCORDIA;
+                       } else if (!strcasecmp(v->value, "etsifsk")) {
+                               cid_type = IFX_TAPI_CID_STD_ETSI_FSK;
+                       } else if (!strcasecmp(v->value, "etsidtmf")) {
+                               cid_type = IFX_TAPI_CID_STD_ETSI_DTMF;
+                       } else if (!strcasecmp(v->value, "sin")) {
+                               cid_type = IFX_TAPI_CID_STD_SIN;
+                       } else if (!strcasecmp(v->value, "ntt")) {
+                               cid_type = IFX_TAPI_CID_STD_NTT;
+                       } else if (!strcasecmp(v->value, "kpndtmf")) {
+                               cid_type = IFX_TAPI_CID_STD_KPN_DTMF;
+                       } else if (!strcasecmp(v->value, "kpndtmffsk")) {
+                               cid_type = IFX_TAPI_CID_STD_KPN_DTMF_FSK;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown caller id type '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "voiceactivitydetection")) {
+                       if (!strcasecmp(v->value, "on")) {
+                               vad_type = IFX_TAPI_ENC_VAD_ON;
+                       } else if (!strcasecmp(v->value, "g711")) {
+                               vad_type = IFX_TAPI_ENC_VAD_G711;
+                       } else if (!strcasecmp(v->value, "cng")) {
+                               vad_type = IFX_TAPI_ENC_VAD_CNG_ONLY;
+                       } else if (!strcasecmp(v->value, "sc")) {
+                               vad_type = IFX_TAPI_ENC_VAD_SC_ONLY;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown voice activity detection value '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "interdigit")) {
+                       dev_ctx.interdigit_timeout = atoi(v->value);
+                       ast_log(LOG_DEBUG, "Setting interdigit timeout to %s.\n", v->value);
+                       if (!dev_ctx.interdigit_timeout) {
+                               dev_ctx.interdigit_timeout = DEFAULT_INTERDIGIT_TIMEOUT;
+                               ast_log(LOG_WARNING, "Invalid interdigit timeout: %s, using default.\n", v->value);
+                       }
+               } else if (!strcasecmp(v->name, "tone_generator")) {
+                       if (!strcasecmp(v->value, "integrated")) {
+                               tone_generator = TONE_INTEGRATED;
+                       } else if (!strcasecmp(v->value, "asterisk")) {
+                               tone_generator = TONE_ASTERISK;
+                       } else if (!strcasecmp(v->value, "media")) {
+                               tone_generator = TONE_MEDIA;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown tone_generator value '%s'. Try 'integrated', 'asterisk' or 'media'.\n", v->value);
+                               goto cfg_error_il;
+                       }
+               }
+       }
+
+       lantiq_create_pvts();
+
+       ast_mutex_unlock(&iflock);
+       ast_config_destroy(cfg);
+
+       if (!(sched = ast_sched_context_create())) {
+               ast_log(LOG_ERROR, "Unable to create scheduler context\n");
+               goto load_error;
+       }
+
+       if (ast_sched_start_thread(sched)) {
+               ast_log(LOG_ERROR, "Unable to create scheduler context thread\n");
+               goto load_error_st;
+       }
+
+       if (ast_channel_register(&lantiq_tech)) {
+               ast_log(LOG_ERROR, "Unable to register channel class 'Phone'\n");
+               goto load_error_st;
+       }
+
+       /* tapi */
+       IFX_TAPI_TONE_t tone;
+       IFX_TAPI_DEV_START_CFG_t dev_start;
+       IFX_TAPI_MAP_DATA_t map_data;
+       IFX_TAPI_LINE_TYPE_CFG_t line_type;
+       IFX_TAPI_LINE_VOLUME_t line_vol;
+       IFX_TAPI_WLEC_CFG_t wlec_cfg;
+       IFX_TAPI_JB_CFG_t jb_cfg;
+       IFX_TAPI_CID_CFG_t cid_cfg;
+
+       /* open device */
+       dev_ctx.dev_fd = lantiq_dev_open(base_path, 0);
+
+       if (dev_ctx.dev_fd < 0) {
+               ast_log(LOG_ERROR, "lantiq TAPI device open function failed\n");
+               goto load_error_st;
+       }
+
+       snprintf(dev_ctx.voip_led, LED_NAME_LENGTH, "voice");
+       for (c = 0; c < dev_ctx.channels ; c++) {
+               dev_ctx.ch_fd[c] = lantiq_dev_open(base_path, c + 1);
+
+               if (dev_ctx.ch_fd[c] < 0) {
+                       ast_log(LOG_ERROR, "lantiq TAPI channel %d open function failed\n", c);
+                       goto load_error_st;
+               }
+               snprintf(dev_ctx.ch_led[c], LED_NAME_LENGTH, "fxs%d", c + 1);
+       }
+
+       if (lantiq_dev_firmware_download(dev_ctx.dev_fd, firmware_filename)) {
+               ast_log(LOG_ERROR, "voice firmware download failed\n");
+               goto load_error_st;
+       }
+
+       if (ioctl(dev_ctx.dev_fd, IFX_TAPI_DEV_STOP, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_DEV_STOP ioctl failed\n");
+               goto load_error_st;
+       }
+
+       memset(&dev_start, 0x0, sizeof(IFX_TAPI_DEV_START_CFG_t));
+       dev_start.nMode = IFX_TAPI_INIT_MODE_VOICE_CODER;
+
+       /* Start TAPI */
+       if (ioctl(dev_ctx.dev_fd, IFX_TAPI_DEV_START, &dev_start)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_DEV_START ioctl failed\n");
+               goto load_error_st;
+       }
+
+       tz = ast_get_indication_zone(NULL);
+
+       if (!tz) {
+               ast_log(LOG_ERROR, "Unable to alloc tone zone\n");
+               goto load_error_st;
+       }
+
+       ts_dial = ast_get_indication_tone(tz, "dial");
+       ts_ring = ast_get_indication_tone(tz, "ring");
+       ts_busy = ast_get_indication_tone(tz, "busy");
+       ts_congestion = ast_get_indication_tone(tz, "congestion");
+
+       if (!ts_dial || !ts_dial->data || !ts_ring || !ts_ring->data || !ts_busy || !ts_busy->data || !ts_congestion || !ts_congestion->data) {
+               ast_log(LOG_ERROR, "Unable to get indication tones\n");
+               goto load_error_st;
+       }
+
+       for (c = 0; c < dev_ctx.channels ; c++) {
+               /* We're a FXS and want to switch between narrow & wide band automatically */
+               memset(&line_type, 0, sizeof(IFX_TAPI_LINE_TYPE_CFG_t));
+               line_type.lineType = IFX_TAPI_LINE_TYPE_FXS_AUTO;
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_TYPE_SET, &line_type)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_LINE_TYPE_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* tones */
+               memset(&tone, 0, sizeof(IFX_TAPI_TONE_t));
+               tone.simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+               playlist_to_tapitone(ts_dial->data, TAPI_TONE_LOCALE_DIAL_CODE, &tone);
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_TABLE_CFG_SET, &tone)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_TABLE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               memset(&tone, 0, sizeof(IFX_TAPI_TONE_t));
+               tone.simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+               playlist_to_tapitone(ts_ring->data, TAPI_TONE_LOCALE_RINGING_CODE, &tone);
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_TABLE_CFG_SET, &tone)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_TABLE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               memset(&tone, 0, sizeof(IFX_TAPI_TONE_t));
+               tone.simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+               playlist_to_tapitone(ts_busy->data, TAPI_TONE_LOCALE_BUSY_CODE, &tone);
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_TABLE_CFG_SET, &tone)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_TABLE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               memset(&tone, 0, sizeof(IFX_TAPI_TONE_t));
+               tone.simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+               playlist_to_tapitone(ts_congestion->data, TAPI_TONE_LOCALE_CONGESTION_CODE, &tone);
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_TABLE_CFG_SET, &tone)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_TABLE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* ringing type */
+               IFX_TAPI_RING_CFG_t ringingType;
+               memset(&ringingType, 0, sizeof(IFX_TAPI_RING_CFG_t));
+               ringingType.nMode = IFX_TAPI_RING_CFG_MODE_INTERNAL_BALANCED;
+               ringingType.nSubmode = IFX_TAPI_RING_CFG_SUBMODE_DC_RNG_TRIP_FAST;
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_RING_CFG_SET, (IFX_int32_t) &ringingType)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_RING_CFG_SET failed\n");
+                       goto load_error_st;
+               }
+
+               /* ring cadence */
+               IFX_char_t data[15] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+                                       0x00, 0x00, 0x00, 0x00, 0x00,
+                                       0x00, 0x00, 0x00, 0x00, 0x00 };
+
+               IFX_TAPI_RING_CADENCE_t ringCadence;
+               memset(&ringCadence, 0, sizeof(IFX_TAPI_RING_CADENCE_t));
+               memcpy(&ringCadence.data, data, sizeof(data));
+               ringCadence.nr = sizeof(data) * 8;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_RING_CADENCE_HR_SET, &ringCadence)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_RING_CADENCE_HR_SET failed\n");
+                       goto load_error_st;
+               }
+
+               /* perform mapping */
+               memset(&map_data, 0x0, sizeof(IFX_TAPI_MAP_DATA_t));
+               map_data.nDstCh = c;
+               map_data.nChType = IFX_TAPI_MAP_TYPE_PHONE;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_MAP_DATA_ADD, &map_data)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_MAP_DATA_ADD %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* set line feed */
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_FEED_SET, IFX_TAPI_LINE_FEED_STANDBY)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_LINE_FEED_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* set volume */
+               memset(&line_vol, 0, sizeof(line_vol));
+               line_vol.nGainRx = rxgain;
+               line_vol.nGainTx = txgain;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_PHONE_VOLUME_SET, &line_vol)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_PHONE_VOLUME_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Configure line echo canceller */
+               memset(&wlec_cfg, 0, sizeof(wlec_cfg));
+               wlec_cfg.nType = wlec_type;
+               wlec_cfg.bNlp = wlec_nlp;
+               wlec_cfg.nNBFEwindow = wlec_nbfe;
+               wlec_cfg.nNBNEwindow = wlec_nbne;
+               wlec_cfg.nWBNEwindow = wlec_wbne;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_WLEC_PHONE_CFG_SET, &wlec_cfg)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_WLEC_PHONE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Configure jitter buffer */
+               memset(&jb_cfg, 0, sizeof(jb_cfg));
+               jb_cfg.nJbType = jb_type;
+               jb_cfg.nPckAdpt = jb_pckadpt;
+               jb_cfg.nLocalAdpt = jb_localadpt;
+               jb_cfg.nScaling = jb_scaling;
+               jb_cfg.nInitialSize = jb_initialsize;
+               jb_cfg.nMinSize = jb_minsize;
+               jb_cfg.nMaxSize = jb_maxsize;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_JB_CFG_SET, &jb_cfg)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_JB_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Configure Caller ID type */
+               memset(&cid_cfg, 0, sizeof(cid_cfg));
+               cid_cfg.nStandard = cid_type;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_CID_CFG_SET, &cid_cfg)) {
+                       ast_log(LOG_ERROR, "IIFX_TAPI_CID_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Configure voice activity detection */
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_VAD_CFG_SET, vad_type)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_ENC_VAD_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Setup TAPI <-> internal RTP codec type mapping */
+               if (lantiq_setup_rtp(c)) {
+                       goto load_error_st;
+               }
+
+               /* Set initial hook status */
+               iflist[c].channel_state = lantiq_get_hookstatus(c);
+
+               if (iflist[c].channel_state == UNKNOWN) {
+                       goto load_error_st;
+               }
+       }
+
+       /* make sure our device will be closed properly */
+       ast_register_atexit(lantiq_cleanup);
+
+       restart_monitor();
+       led_on(dev_ctx.voip_led);
+       return AST_MODULE_LOAD_SUCCESS;
+
+cfg_error_il:
+       ast_mutex_unlock(&iflock);
+cfg_error:
+       ast_config_destroy(cfg);
+       return AST_MODULE_LOAD_DECLINE;
+
+load_error_st:
+       ast_sched_context_destroy(sched);
+load_error:
+       unload_module();
+       ast_free(iflist);
+       return AST_MODULE_LOAD_FAILURE;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Lantiq TAPI Telephony API Support",
+       .load = load_module,
+       .unload = unload_module,
+       .load_pri = AST_MODPRI_CHANNEL_DRIVER
+);
diff --git a/net/asterisk-11.x/src-lantiq/configs/lantiq.conf.sample b/net/asterisk-11.x/src-lantiq/configs/lantiq.conf.sample
new file mode 100644 (file)
index 0000000..74c6f3f
--- /dev/null
@@ -0,0 +1,153 @@
+;
+; TAPI Telephony Interface
+;
+; Configuration file
+
+[interfaces]
+;
+; Number of FXS ports (default: 2)
+channels = 2
+;
+; Create contexts per channel (default: off)
+;per_channel_context = off
+;
+; Set tapi firmware file path
+;firmwarefilename = /lib/firmware/danube_firmware.bin
+;
+; Set tapi bbd file path
+;bbdfilename = /lib/firmware/danube_bbd_fxs.bin
+;
+; Set vmmc device path
+;basepath = /dev/vmmc
+;
+[general]
+;
+; Gain setting for the receive and transmit path.
+; The value is given in dB within the range (-24dB to +12dB), in 1 dB steps.
+;
+;rxgain = 1
+;txgain = 1
+;
+;
+;
+; Line echo cancller valid types:
+;
+; off          LEC and echo suppressor turned off.
+; nlec         LEC using fixed window; no echo suppressor.
+; wlec         LEC using fixed and moving window; no echo suppressor.
+; nees         LEC using fixed window and echo suppressor.
+; nfees                LEC using fixed and moving window and echo suppressor.
+; es           Echo suppressor
+;
+;echocancel = off
+;
+; If nlec or wlec is selected than size of the fixed window in narrowband (8 kHz) sampling mode
+; can be defined with:
+; A value of 0 defaults to: 16 ms if type is nlec or 8 ms if type is wlec:
+;
+;echocancelfixedwindowsize = 0
+;
+; If wlec is selected than size of the moving window in narrowband (8 kHz) sampling mode
+; can be defined with:
+; A value of 0 defaults to 8 ms.
+;
+;echocancelnfemovingwindowsize = 0
+;
+; If wlec is selected than size of the moving window in wideband (16 kHz) sampling mode
+; can be defined with:
+; A value of 0 defaults to 8 ms.
+;
+;echocancelwidefixedwindowsize = 0
+;
+; Activate or deactivate line echo cancller NLP (Non Linear Processor) if the LEC is active,
+; valid is on or off:
+;
+;echocancelnlp = off
+;
+;
+;
+; Jitter buffer valid types:
+;
+; fixed                Fixed jitter buffer.
+; adaptive     Adaptive jitter buffer.
+;
+;jitterbuffertype = fixed
+;
+; Jitter buffer packet adaptation valid types:
+;
+; voice                Jitter buffer optimized for voice.
+; data         Jitter buffer optimized for data.
+; datanorep    Jitter buffer optimized for data but without doing packet repetition.
+;
+;jitterbufferpackettype = voice
+;
+;      Following jitter buffer values can only be used with jitter buffer adaptive type:
+; Turns on or off jitter buffer adaptation:
+;
+;jitterbufferadaptation = off
+;
+; Scaling factor multiplied by 16; in adaptive jitter buffer mode, the target average playout delay is
+; equal to the estimated jitter multiplied by the scaling factor. The default value for the scaling factor
+; is about 1.4 (scaling=22), meaning that the target average playout delay is equal to the estimated
+; jitter. If less packets should be dropped because of jitter, the scaling factor has to be increased. An
+; increase in the scaling factor will eventually lead to an increased playout delay.
+; The supported range is 1 to 16 (16 up to 256).
+;
+;jitterbufferscalling = 1
+;
+; Initial size of the jitter buffer in time stamps of 125 us:
+;
+;jitterbufferinitialsize = 125
+;
+; Minimum size of the jitter buffer in time stamps of 125 us
+;
+;jitterbufferminsize = 125
+;
+; Maximum size of the jitter buffer in time stamps of 125 us
+;
+;jitterbuffermaxsize = 125
+;
+;
+;
+; Caller id valid standards:
+;
+; telecordia    Bellcore/Telcordia GR-30-CORE; use Bell202 FSK coding of CID information. (default)
+; etsifsk       ETSI 300-659-1/2/3 V1.3.1; use V.23 FSK coding to transmit CID information.
+; etsidtmf      ETSI 300-659-1/2/3 V1.3.1; use DTMF transmission of CID information.
+; sin           SIN 227 Issue 3.4; use V.23 FSK coding of CID information.
+; ntt           NTT standard: TELEPHONE SERVICE INTERFACES, edition 5; use a modified V.23 FSK coding of
+;               CID information.
+; kpndtmf       KPN; use DTMF transmission of CID information.
+; kpndtmffsk    KPN; use DTMF and FSK transmission of CID information.
+;
+;calleridtype = telecordia
+;
+;
+;
+; Voice activity detection:
+;
+; on           Voice activity detection on; in this case also comfort noise and spectral
+;              information (nicer noise) is switched on.
+; g711         Voice activity detection on with comfort noise generation,
+;              but without spectral information.
+; cng          Voice activity detection on with comfort noise generation, but without silence compression
+; sc           Voice activity detection on with silence compression,
+;              but without comfort noise generation.
+;
+;voiceactivitydetection = on
+;
+;
+;
+; Timeout between dialed digits, in milliseconds, before placing the call.
+;
+;interdigit = 4000
+;
+;
+;
+; Tone generator type (default: integrated)
+; integrated   Use tapi tone generator
+; asterisk     Use asterisk tone generator where possible
+; media                Use media tone where possible
+;
+;tone_generator = integrated
+;
index 5cf80cf6f227dedea1b132d6561358a7dd704e35..4514b52ba69eb8e44879efa77d6ef0defeada22a 100644 (file)
@@ -9,12 +9,12 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=asterisk13
-PKG_VERSION:=13.9.1
+PKG_VERSION:=13.15.0
 PKG_RELEASE:=1
 
 PKG_SOURCE:=asterisk-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://downloads.asterisk.org/pub/telephony/asterisk/releases/
-PKG_MD5SUM:=76c42992a79f41ec467ed20500e8b249
+PKG_HASH:=8b8a55557d9c882f9b68f61b62f5f8af5c9ad68b6da6a1aa3506fa1894fb5844
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/asterisk-$(PKG_VERSION)
 PKG_BUILD_DEPENDS:=libxml2/host
@@ -207,7 +207,7 @@ CONFIGURE_ARGS+= \
        --with-popt="$(STAGING_DIR)/usr" \
        --without-pwlib \
        --without-radius \
-       --without-spandsp \
+       $(if $(CONFIG_PACKAGE_$(PKG_NAME)-res-fax-spandsp),--with-spandsp="$(STAGING_DIR)/usr",--without-spandsp) \
        $(if $(CONFIG_PACKAGE_$(PKG_NAME)-res-xmpp),--with-iksemel="$(STAGING_DIR)/usr",--without-iksemel) \
        --without-sdl \
        --without-sqlite \
@@ -233,6 +233,13 @@ AST_MENUSELECT_OPTS = \
        --with-ncurses="$(STAGING_DIR_HOST)/usr" \
        --with-libxml2="$(STAGING_DIR_HOST)/usr"
 
+define Build/Prepare
+       $(call Build/Prepare/Default)
+ifneq ($(CONFIG_TARGET_lantiq),)
+       $(CP) ./src-lantiq/* $(PKG_BUILD_DIR)/
+endif
+endef
+
 define Build/Configure
        (cd $(PKG_BUILD_DIR); \
                ./bootstrap.sh; \
@@ -313,6 +320,7 @@ $(eval $(call BuildAsterisk13Module,app-record,Record sound file,to record a sou
 $(eval $(call BuildAsterisk13Module,app-sayunixtime,Say Unix time,an application to say Unix time,,,app_sayunixtime,,))
 $(eval $(call BuildAsterisk13Module,app-senddtmf,Send DTMF digits,Sends arbitrary DTMF digits,,,app_senddtmf,,))
 $(eval $(call BuildAsterisk13Module,app-sms,SMS,SMS support (ETSI ES 201 912 protocol 1),+libpopt +libstdcpp,,app_sms,,))
+$(eval $(call BuildAsterisk13Module,app-speech,Dialplan Speech,Dialplan Speech Applications,+asterisk13-res-speech,,app_speech_utils,,))
 $(eval $(call BuildAsterisk13Module,app-stack,Stack applications,Stack applications Gosub Return etc.,+asterisk13-res-agi,,app_stack,,))
 $(eval $(call BuildAsterisk13Module,app-system,System exec,support for executing system commands,,,app_system,,))
 $(eval $(call BuildAsterisk13Module,app-talkdetect,File playback with audio detect,for file playback with audio detect,,,app_talkdetect,,))
@@ -331,6 +339,7 @@ $(eval $(call BuildAsterisk13Module,cdr-sqlite3,Provides CDR SQLITE3,Call Detail
 $(eval $(call BuildAsterisk13Module,chan-alsa,ALSA channel,the channel chan_alsa,+alsa-lib,alsa.conf,chan_alsa,,))
 $(eval $(call BuildAsterisk13Module,chan-dahdi,DAHDI channel,DAHDI channel support,+dahdi-tools-libtonezone +kmod-dahdi +libpri,chan_dahdi.conf,chan_dahdi,,))
 $(eval $(call BuildAsterisk13Module,chan-iax2,IAX2 channel,IAX support,+asterisk13-res-timing-timerfd,iax.conf iaxprov.conf,chan_iax2,,))
+$(eval $(call BuildAsterisk13Module,chan-lantiq,Lantiq TAPI channel,An implementation of Lantiq TAPI channel,@TARGET_lantiq +kmod-ltq-vmmc,lantiq.conf,chan_lantiq,,))
 $(eval $(call BuildAsterisk13Module,chan-oss,OSS channel,the channel chan_oss,,oss.conf,chan_oss,,))
 $(eval $(call BuildAsterisk13Module,chan-sip,SIP channel,the channel chan_sip,+asterisk13-app-confbridge,sip.conf sip_notify.conf,chan_sip,,))
 $(eval $(call BuildAsterisk13Module,chan-skinny,Skinny channel,the channel chan_skinny,,skinny.conf,chan_skinny,,))
@@ -371,6 +380,7 @@ $(eval $(call BuildAsterisk13Module,func-global,Global variable,global variable
 $(eval $(call BuildAsterisk13Module,func-groupcount,Group count,for counting number of channels in the specified group,,,func_groupcount,,))
 $(eval $(call BuildAsterisk13Module,func-math,Math functions,Math functions,,,func_math,))
 $(eval $(call BuildAsterisk13Module,func-module,Simple module check function,Simple module check function,,,func_module,))
+$(eval $(call BuildAsterisk13Module,func-periodic-hook,Periodic dialplan hooks,Execute a periodic dialplan hook into the audio of a call,,,func_periodic_hook,,))
 $(eval $(call BuildAsterisk13Module,func-presencestate,Hinted presence state,Gets or sets a presence state in the dialplan,,,func_presencestate,,))
 $(eval $(call BuildAsterisk13Module,func-realtime,realtime,the realtime dialplan function,,,func_realtime,,))
 $(eval $(call BuildAsterisk13Module,func-shell,Shell,support for shell execution,,,func_shell,,))
@@ -385,12 +395,14 @@ $(eval $(call BuildAsterisk13Module,pgsql,PostgreSQL,PostgreSQL support,+libpq,c
 $(eval $(call BuildAsterisk13Module,pjsip,pjsip channel,the channel pjsip,+asterisk13-res-sorcery +libpjsip +libpjmedia +libpjnath +libpjsip-simple +libpjsip-ua +libpjsua +libpjsua2,pjsip.conf pjsip_notify.conf,func_pjsip_endpoint chan_pjsip res_pjsip_acl res_pjsip_authenticator_digest res_pjsip_caller_id res_pjsip_dialog_info_body_generator res_pjsip_diversion res_pjsip_dtmf_info res_pjsip_endpoint_identifier_anonymous res_pjsip_endpoint_identifier_ip res_pjsip_endpoint_identifier_user res_pjsip_exten_state res_pjsip_header_funcs res_pjsip_log_forwarder res_pjsip_logger res_pjsip_messaging res_pjsip_multihomed res_pjsip_mwi_body_generator res_pjsip_mwi res_pjsip_nat res_pjsip_notify res_pjsip_one_touch_record_info res_pjsip_outbound_authenticator_digest res_pjsip_outbound_publish res_pjsip_outbound_registration res_pjsip_path res_pjsip_pidf_body_generator res_pjsip_pidf_digium_body_supplement res_pjsip_pidf_eyebeam_body_supplement res_pjsip_publish_asterisk res_pjsip_pubsub res_pjsip_refer res_pjsip_registrar_expire res_pjsip_registrar res_pjsip_rfc3326 res_pjsip_sdp_rtp res_pjsip_send_to_voicemail res_pjsip_session res_pjsip res_pjsip_transport_websocket res_pjsip_t38 res_pjsip_xpidf_body_generator,,))
 $(eval $(call BuildAsterisk13Module,res-adsi,Provide ADSI,Analog Display Services Interface capability,,,res_adsi,,))
 $(eval $(call BuildAsterisk13Module,res-ael-share,Shareable AEL code,support for shareable AEL code mainly between internal and external modules,,,res_ael_share,,))
-$(eval $(call BuildAsterisk13Module,res-agi,Asterisk Gateway Interface,Support for the Asterisk Gateway Interface extension,,,res_agi,,))
+$(eval $(call BuildAsterisk13Module,res-agi,Asterisk Gateway Interface,Support for the Asterisk Gateway Interface extension,+asterisk13-res-speech,,res_agi,,))
 $(eval $(call BuildAsterisk13Module,res-calendar,Calendaring API,Calendaring support (ICal and Google Calendar),,calendar.conf,res_calendar,,))
 $(eval $(call BuildAsterisk13Module,res-clioriginate,Calls via CLI,Originate calls via the CLI,,,res_clioriginate,,))
 $(eval $(call BuildAsterisk13Module,res-hep,HEPv3 API,,,,res_hep,,))
 $(eval $(call BuildAsterisk13Module,res-hep-pjsip,PJSIP HEPv3 Logger,,+asterisk13-res-hep +asterisk13-pjsip,,res_hep,,))
 $(eval $(call BuildAsterisk13Module,res-hep-rtcp,RTCP HEPv3 Logger,,+asterisk13-res-hep,,res_hep,,))
+$(eval $(call BuildAsterisk13Module,res-fax-spandsp,Spandsp T.38 and G.711,Spandsp T.38 and G.711 FAX Resource,+asterisk13-res-fax +libspandsp +libtiff,,res_fax_spandsp,,))
+$(eval $(call BuildAsterisk13Module,res-fax,FAX modules,Generic FAX resource for FAX technology resource modules,+asterisk13-res-timing-pthread,res_fax.conf,res_fax,,))
 $(eval $(call BuildAsterisk13Module,res-http-websocket,HTTP websocket support,,,,res_http_websocket,,))
 $(eval $(call BuildAsterisk13Module,res-monitor,Provide Monitor,Cryptographic Signature capability,,,res_monitor,,))
 $(eval $(call BuildAsterisk13Module,res-musiconhold,MOH,Music On Hold support,,musiconhold.conf,res_musiconhold,,))
@@ -401,9 +413,10 @@ $(eval $(call BuildAsterisk13Module,res-rtp-asterisk,RTP stack,,+libpjsip +libpj
 $(eval $(call BuildAsterisk13Module,res-rtp-multicast,RTP multicast engine,,,,res_rtp_multicast,,))
 $(eval $(call BuildAsterisk13Module,res-smdi,Provide SMDI,Simple Message Desk Interface capability,,smdi.conf,res_smdi,,))
 $(eval $(call BuildAsterisk13Module,res-sorcery,Sorcery data layer,,,,res_sorcery_astdb res_sorcery_config res_sorcery_memory res_sorcery_realtime,,))
+$(eval $(call BuildAsterisk13Module,res-speech,Speech Recognition API,Support for the Asterisk Generic Speech Recognition API,,,res_speech,,))
 $(eval $(call BuildAsterisk13Module,res-srtp,SRTP Support,Secure RTP connection,+libsrtp,,res_srtp,,))
+$(eval $(call BuildAsterisk13Module,res-stun-monitor,STUN monitoring,resource STUN Monitor,,res_stun_monitor.conf,res_stun_monitor,,))
 $(eval $(call BuildAsterisk13Module,res-timing-dahdi,DAHDI Timing Interface,,+asterisk13-chan-dahdi,,res_timing_dahdi,,))
 $(eval $(call BuildAsterisk13Module,res-timing-pthread,pthread Timing Interface,,,,res_timing_pthread,,))
 $(eval $(call BuildAsterisk13Module,res-timing-timerfd,Timerfd Timing Interface,,,,res_timing_timerfd,,))
 $(eval $(call BuildAsterisk13Module,voicemail,Voicemail,voicemail related modules,+asterisk13-res-adsi +asterisk13-res-smdi,voicemail.conf,app_voicemail,vm-*,))
-
index 6256fd8c575f67e86f30abc82208016acc5f2e9a..873cfbe331ce644061e79b7a58d260438cc64e7b 100644 (file)
@@ -1,6 +1,6 @@
 --- a/configure.ac
 +++ b/configure.ac
-@@ -927,19 +927,6 @@ AC_LINK_IFELSE(
+@@ -960,19 +960,6 @@ AC_LINK_IFELSE(
    ]
  )
  
index 1d01bb8297d310fe15ff776a138e2da3641066d5..110c07e6425355a331e54014f7b102ae18d6a488 100644 (file)
@@ -1,6 +1,6 @@
 --- a/configure.ac
 +++ b/configure.ac
-@@ -1261,7 +1261,6 @@ AC_LINK_IFELSE(
+@@ -1290,7 +1290,6 @@ AC_LINK_IFELSE(
                        #include <resolv.h>],
                        [int foo = res_ninit(NULL);])],
        AC_MSG_RESULT(yes)
index 264eb41a7b406c380c19cb76b28b39b2491c9406..0a03b3874551ab31543c2a6c16395c895f080045 100644 (file)
@@ -31,7 +31,7 @@
 @@ -114,9 +120,11 @@ struct ast_lock_track {
        int reentrancy;
        const char *func[AST_MAX_REENTRANCY];
-       pthread_t thread[AST_MAX_REENTRANCY];
+       pthread_t thread_id[AST_MAX_REENTRANCY];
 +#ifndef __UCLIBC__
  #ifdef HAVE_BKTR
        struct ast_bt backtrace[AST_MAX_REENTRANCY];
diff --git a/net/asterisk-13.x/patches/040-fix-config-options.patch b/net/asterisk-13.x/patches/040-fix-config-options.patch
deleted file mode 100644 (file)
index e3ed33a..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
---- a/main/config_options.c
-+++ b/main/config_options.c
-@@ -198,8 +198,8 @@ static int link_option_to_types(struct a
- #ifdef AST_DEVMODE
-                       opt->doc_unavailable = 1;
- #endif
--#endif
-               }
-+#endif
-       }
-       /* The container(s) should hold the only ref to opt */
-       ao2_ref(opt, -1);
diff --git a/net/asterisk-13.x/patches/051-musl-includes.patch b/net/asterisk-13.x/patches/051-musl-includes.patch
deleted file mode 100644 (file)
index 6bee31c..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
---- a/include/asterisk/compat.h
-+++ b/include/asterisk/compat.h
-@@ -68,7 +68,7 @@
- #endif
- #ifndef AST_POLL_COMPAT
--#include <sys/poll.h>
-+#include <poll.h>
- #else
- #include "asterisk/poll-compat.h"
- #endif
---- a/include/asterisk/poll-compat.h
-+++ b/include/asterisk/poll-compat.h
-@@ -83,7 +83,7 @@
- #ifndef AST_POLL_COMPAT
--#include <sys/poll.h>
-+#include <poll.h>
- #define ast_poll(a, b, c) poll(a, b, c)
---- a/main/ast_expr2.c
-+++ b/main/ast_expr2.c
-@@ -93,6 +93,7 @@
- #include "asterisk.h"
-+#include <sys/cdefs.h>
- #include <sys/types.h>
- #include <stdio.h>
---- a/main/ast_expr2.y
-+++ b/main/ast_expr2.y
-@@ -14,6 +14,7 @@
- #include "asterisk.h"
-+#include <sys/cdefs.h>
- #include <sys/types.h>
- #include <stdio.h>
index 41981ca17fc655b352b1641b46066e67e2a3ac6d..4df7f0c6d3cf449965cb06da1cada877aeb55892 100644 (file)
@@ -1,7 +1,7 @@
 --- a/configure.ac
 +++ b/configure.ac
 @@ -181,6 +181,9 @@ case "${host_os}" in
-      linux-gnueabi* |  linux-gnuspe)
+      linux-gnu*)
       OSARCH=linux-gnu
       ;;
 +     linux-musl*)
@@ -10,7 +10,7 @@
       kfreebsd*-gnu)
       OSARCH=kfreebsd-gnu
       ;;
-@@ -1373,9 +1376,11 @@ if test "${PBX_BFD}" = "0"; then
+@@ -1402,9 +1405,11 @@ if test "${PBX_BFD}" = "0"; then
    AST_EXT_LIB_CHECK([BFD], [bfd], [bfd_check_format], [bfd.h], [-ldl -liberty -lz])
  fi
  
@@ -26,9 +26,9 @@
  AST_C_DEFINE_CHECK([DAHDI], [DAHDI_DEFAULT_MTU_MRU], [dahdi/user.h], [220])
 --- a/main/Makefile
 +++ b/main/Makefile
-@@ -45,7 +45,7 @@ AST_LIBS+=$(UUID_LIB)
- AST_LIBS+=$(CRYPT_LIB)
- AST_LIBS+=$(AST_CLANG_BLOCKS_LIBS)
+@@ -47,7 +47,7 @@ AST_LIBS+=$(UUID_LIB)
+ AST_LIBS+=$(RT_LIB)
+ AST_LIBS+=$(SYSTEMD_LIB)
  
 -ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc kfreebsd-gnu),)
 +ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc linux-musl kfreebsd-gnu),)
diff --git a/net/asterisk-13.x/src-lantiq/channels/chan_lantiq.c b/net/asterisk-13.x/src-lantiq/channels/chan_lantiq.c
new file mode 100644 (file)
index 0000000..19d422e
--- /dev/null
@@ -0,0 +1,2301 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Luka Perkov
+ * Copyright (C) 2012, John Crispin
+ * Copyright (C) 2012, Andrej Vlašić
+ * Copyright (C) 2012, Kaspar Schleiser for T-Labs
+ *                     (Deutsche Telekom Innovation Laboratories)
+ * Copyright (C) 2012, Mirko Vogt for T-Labs
+ *                     (Deutsche Telekom Innovation Laboratories)
+ * Copyright (c) 2015, Antonio Eugenio Burriel
+ * Copyright (C) 2017, Stefan Koch
+ *
+ * Luka Perkov <openwrt@lukaperkov.net>
+ * John Crispin <blogic@openwrt.org>
+ * Andrej Vlašić <andrej.vlasic0@gmail.com>
+ * Kaspar Schleiser <kaspar@schleiser.de>
+ * Mirko Vogt <mirko@openwrt.org>
+ * Antonio Eugenio Burriel <aeburriel@gmail.com>
+ * Stefan Koch <stefan.koch10@gmail.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Asterisk channel line driver for Lantiq based TAPI boards
+ *
+ * \author Luka Perkov <openwrt@lukaperkov.net>
+ * \author John Crispin <blogic@openwrt.org>
+ * \author Andrej Vlašić <andrej.vlasic0@gmail.com>
+ * \author Kaspar Schleiser <kaspar@schleiser.de>
+ * \author Mirko Vogt <mirko@openwrt.org>
+ * \author Antonio Eugenio Burriel <aeburriel@gmail.com>
+ * \author Stefan Koch <stefan.koch10@gmail.com>
+ *
+ * \ingroup channel_drivers
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision: xxx $")
+
+#include <ctype.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <stdio.h>
+#ifdef HAVE_LINUX_COMPILER_H
+#include <linux/compiler.h>
+#endif
+#include <linux/telephony.h>
+
+#include <asterisk/lock.h>
+#include <asterisk/channel.h>
+#include <asterisk/config.h>
+#include <asterisk/module.h>
+#include <asterisk/pbx.h>
+#include <asterisk/utils.h>
+#include <asterisk/callerid.h>
+#include <asterisk/causes.h>
+#include <asterisk/indications.h>
+#include <asterisk/stringfields.h>
+#include <asterisk/musiconhold.h>
+#include <asterisk/sched.h>
+#include <asterisk/cli.h>
+#include <asterisk/devicestate.h>
+#include <asterisk/format_cache.h>
+
+/* Lantiq TAPI includes */
+#include <drv_tapi/drv_tapi_io.h>
+#include <drv_vmmc/vmmc_io.h>
+
+#define TAPI_AUDIO_PORT_NUM_MAX                 2
+
+/* Tapi predefined tones 0 to 31 */
+#define TAPI_TONE_LOCALE_NONE                  0
+//#define TAPI_TONE_LOCALE_DIAL_CODE           25
+//#define TAPI_TONE_LOCALE_RINGING_CODE                26
+//#define TAPI_TONE_LOCALE_BUSY_CODE           27
+//#define TAPI_TONE_LOCALE_CONGESTION_CODE     27
+
+/* Tapi custom tones 32 to 256 */
+#define TAPI_TONE_LOCALE_DIAL_CODE             32
+#define TAPI_TONE_LOCALE_RINGING_CODE          33
+#define TAPI_TONE_LOCALE_BUSY_CODE             34
+#define TAPI_TONE_LOCALE_CONGESTION_CODE       35
+
+#define LANTIQ_CONTEXT_PREFIX "lantiq"
+#define DEFAULT_INTERDIGIT_TIMEOUT 4000
+#define G723_HIGH_RATE 1
+#define LED_NAME_LENGTH 32
+
+static const char config[] = "lantiq.conf";
+
+static char firmware_filename[PATH_MAX] = "/lib/firmware/ifx_firmware.bin";
+static char bbd_filename[PATH_MAX] = "/lib/firmware/ifx_bbd_fxs.bin";
+static char base_path[PATH_MAX] = "/dev/vmmc";
+static int per_channel_context = 0;
+
+/* tone generator types */
+enum tone_generator_t {
+       TONE_INTEGRATED, /* tapi tone generator */
+       TONE_ASTERISK, /* asterisk tone generator where possible */
+       TONE_MEDIA /* media tone where possible */
+};
+
+/* tone generator (default is integraded) */
+static enum tone_generator_t tone_generator = TONE_INTEGRATED;
+
+/* tone zones for dial, ring, busy and congestion */
+struct ast_tone_zone_sound *ts_dial;
+struct ast_tone_zone_sound *ts_ring;
+struct ast_tone_zone_sound *ts_busy;
+struct ast_tone_zone_sound *ts_congestion;
+
+/*
+ * The private structures of the Phone Jack channels are linked for selecting
+ * outgoing channels.
+ */
+enum channel_state {
+       ONHOOK,
+       OFFHOOK,
+       DIALING,
+       INCALL,
+       CALL_ENDED,
+       RINGING,
+       UNKNOWN
+};
+
+static struct lantiq_pvt {
+       struct ast_channel *owner;       /* Channel we belong to, possibly NULL   */
+       int port_id;                     /* Port number of this object, 0..n      */
+       int channel_state;
+       char context[AST_MAX_CONTEXT];   /* this port's dialplan context          */
+       int dial_timer;                  /* timer handle for autodial timeout     */
+       char dtmfbuf[AST_MAX_EXTENSION]; /* buffer holding dialed digits          */
+       int dtmfbuf_len;                 /* lenght of dtmfbuf                     */
+       int rtp_timestamp;               /* timestamp for RTP packets             */
+       int ptime;                       /* Codec base ptime                      */
+       uint16_t rtp_seqno;              /* Sequence nr for RTP packets           */
+       uint32_t call_setup_start;       /* Start of dialling in ms               */
+       uint32_t call_setup_delay;       /* time between ^ and 1st ring in ms     */
+       uint32_t call_start;             /* time we started dialling / answered   */
+       uint32_t call_answer;            /* time the callee answered our call     */
+       uint16_t jb_size;                /* Jitter buffer size                    */
+       uint32_t jb_underflow;           /* Jitter buffer injected samples        */
+       uint32_t jb_overflow;            /* Jitter buffer dropped samples         */
+       uint16_t jb_delay;               /* Jitter buffer: playout delay          */
+       uint16_t jb_invalid;             /* Jitter buffer: Nr. of invalid packets */
+} *iflist = NULL;
+
+static struct lantiq_ctx {
+               int dev_fd;
+               int channels;
+               int ch_fd[TAPI_AUDIO_PORT_NUM_MAX];
+               char voip_led[LED_NAME_LENGTH]; /* VOIP LED name */
+               char ch_led[TAPI_AUDIO_PORT_NUM_MAX][LED_NAME_LENGTH]; /* FXS LED names */
+               int interdigit_timeout; /* Timeout in ms between dialed digits */
+} dev_ctx;
+
+static int ast_digit_begin(struct ast_channel *ast, char digit);
+static int ast_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
+static int ast_lantiq_call(struct ast_channel *ast, const char *dest, int timeout);
+static int ast_lantiq_hangup(struct ast_channel *ast);
+static int ast_lantiq_answer(struct ast_channel *ast);
+static struct ast_frame *ast_lantiq_read(struct ast_channel *ast);
+static int ast_lantiq_write(struct ast_channel *ast, struct ast_frame *frame);
+static struct ast_frame *ast_lantiq_exception(struct ast_channel *ast);
+static int ast_lantiq_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
+static int ast_lantiq_fixup(struct ast_channel *old, struct ast_channel *new);
+static struct ast_channel *ast_lantiq_requester(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assigned_ids, const struct ast_channel *requestor, const char *data, int *cause);
+static int ast_lantiq_devicestate(const char *data);
+static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *args, char *buf, size_t buflen);
+static void lantiq_jb_get_stats(int c);
+static struct ast_format *lantiq_map_rtptype_to_format(uint8_t rtptype);
+static uint8_t lantiq_map_format_to_rtptype(const struct ast_format *format);
+static int lantiq_conf_enc(int c, const struct ast_format *format);
+static void lantiq_reset_dtmfbuf(struct lantiq_pvt *pvt);
+
+static struct ast_channel_tech lantiq_tech = {
+       .type = "TAPI",
+       .description = "Lantiq TAPI Telephony API Driver",
+       .send_digit_begin = ast_digit_begin,
+       .send_digit_end = ast_digit_end,
+       .call = ast_lantiq_call,
+       .hangup = ast_lantiq_hangup,
+       .answer = ast_lantiq_answer,
+       .read = ast_lantiq_read,
+       .write = ast_lantiq_write,
+       .exception = ast_lantiq_exception,
+       .indicate = ast_lantiq_indicate,
+       .fixup = ast_lantiq_fixup,
+       .requester = ast_lantiq_requester,
+       .devicestate = ast_lantiq_devicestate,
+       .func_channel_read = acf_channel_read
+};
+
+/* Protect the interface list (of lantiq_pvt's) */
+AST_MUTEX_DEFINE_STATIC(iflock);
+
+/*
+ * Protect the monitoring thread, so only one process can kill or start it, and
+ * not when it's doing something critical.
+ */
+AST_MUTEX_DEFINE_STATIC(monlock);
+
+/* The scheduling context */
+struct ast_sched_context *sched;
+
+/*
+ * This is the thread for the monitor which checks for input on the channels
+ * which are not currently in use.
+ */
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
+
+
+#define WORDS_BIGENDIAN
+/* struct taken from some GPLed code by  Mike Borella */
+typedef struct rtp_header
+{
+#if defined(WORDS_BIGENDIAN)
+  uint8_t version:2, padding:1, extension:1, csrc_count:4;
+  uint8_t marker:1, payload_type:7;
+#else
+  uint8_t csrc_count:4, extension:1, padding:1, version:2;
+  uint8_t payload_type:7, marker:1;
+#endif
+  uint16_t seqno;
+  uint32_t timestamp;
+  uint32_t ssrc;
+} rtp_header_t;
+#define RTP_HEADER_LEN 12
+#define RTP_BUFFER_LEN 512
+/* Internal RTP payload types - standard */
+#define RTP_PCMU       0
+#define RTP_G723_63    4
+#define RTP_PCMA       8
+#define RTP_G722       9
+#define RTP_CN         13
+#define RTP_G729       18
+/* Internal RTP payload types - custom   */
+#define RTP_G7221      100
+#define RTP_G726       101
+#define RTP_ILBC       102
+#define RTP_SLIN8      103
+#define RTP_SLIN16     104
+#define RTP_SIREN7     105
+#define RTP_G723_53    106
+
+
+/* LED Control. Taken with modifications from SVD by Luca Olivetti <olivluca@gmail.com> */
+#define LED_SLOW_BLINK 1000
+#define LED_FAST_BLINK 100
+static FILE *led_open(const char *led, char* sub)
+{
+       char fname[100];
+
+       if (snprintf(fname, sizeof(fname), "/sys/class/leds/%s/%s", led, sub) >= sizeof(fname))
+               return NULL;
+       return fopen(fname, "r+");
+}
+
+static FILE *led_trigger(const char *led)
+{
+       return led_open(led, "trigger");
+}
+
+static void led_delay(const char *led, int onoff, int msec)
+{
+       FILE *fp = led_open(led, onoff ? "delay_on" : "delay_off");
+       if (fp) {
+               fprintf(fp,"%d\n",msec);
+               fclose(fp);
+       }
+}
+
+static void led_on(const char *led)
+{
+       FILE *fp;
+
+       fp = led_trigger(led);
+       if (fp) {
+               fprintf(fp,"default-on\n");
+               fclose(fp);
+       }
+}
+
+static void led_off(const char *led)
+{
+       FILE *fp;
+
+       fp = led_trigger(led);
+       if (fp) {
+               fprintf(fp,"none\n");
+               fclose(fp);
+       }
+}
+
+static void led_blink(const char *led, int period)
+{
+       FILE *fp;
+
+       fp = led_trigger(led);
+       if (fp) {
+               fprintf(fp, "timer\n");
+               fclose(fp);
+               led_delay(led, 1, period/2);
+               led_delay(led, 0, period/2);
+       }
+}
+
+static uint32_t now(void) {
+       struct timespec ts;
+       clock_gettime(CLOCK_MONOTONIC, &ts);
+
+       uint64_t tmp = ts.tv_sec*1000 + (ts.tv_nsec/1000000);
+       return (uint32_t) tmp;
+}
+
+static uint32_t epoch(void) {
+       struct timeval tv;
+       gettimeofday(&tv, NULL);
+
+       return tv.tv_sec;
+}
+
+static int lantiq_dev_open(const char *dev_path, const int32_t ch_num)
+{
+       char dev_name[PATH_MAX];
+       memset(dev_name, 0, sizeof(dev_name));
+       snprintf(dev_name, PATH_MAX, "%s%u%u", dev_path, 1, ch_num);
+       return open((const char*)dev_name, O_RDWR, 0644);
+}
+
+static void lantiq_ring(int c, int r, const char *cid, const char *name)
+{
+       uint8_t status;
+
+       if (r) {
+               led_blink(dev_ctx.ch_led[c], LED_FAST_BLINK);
+               if (!cid) {
+                       status = (uint8_t) ioctl(dev_ctx.ch_fd[c], IFX_TAPI_RING_START, 0);
+               } else {
+                       IFX_TAPI_CID_MSG_t msg;
+                       IFX_TAPI_CID_MSG_ELEMENT_t elements[3];
+                       int count = 0;
+                       time_t timestamp;
+                       struct tm *tm;
+
+                       elements[count].string.elementType = IFX_TAPI_CID_ST_CLI;
+                       elements[count].string.len = strlen(cid);
+                       if (elements[count].string.len > IFX_TAPI_CID_MSG_LEN_MAX) {
+                               elements[count].string.len = IFX_TAPI_CID_MSG_LEN_MAX;
+                       }
+                       strncpy((char *)elements[count].string.element, cid, IFX_TAPI_CID_MSG_LEN_MAX);
+                       elements[count].string.element[IFX_TAPI_CID_MSG_LEN_MAX-1] = '\0';
+                       count++;
+
+                       if (name) {
+                               elements[count].string.elementType = IFX_TAPI_CID_ST_NAME;
+                               elements[count].string.len = strlen(name);
+                               if (elements[count].string.len > IFX_TAPI_CID_MSG_LEN_MAX) {
+                                       elements[count].string.len = IFX_TAPI_CID_MSG_LEN_MAX;
+                               }
+                               strncpy((char *)elements[count].string.element, name, IFX_TAPI_CID_MSG_LEN_MAX);
+                               elements[count].string.element[IFX_TAPI_CID_MSG_LEN_MAX-1] = '\0';
+                               count++;
+                       }
+
+                       if ((time(&timestamp) != -1) && ((tm=localtime(&timestamp)) != NULL)) {
+                               elements[count].date.elementType = IFX_TAPI_CID_ST_DATE;
+                               elements[count].date.day = tm->tm_mday;
+                               elements[count].date.month = tm->tm_mon + 1;
+                               elements[count].date.hour = tm->tm_hour;
+                               elements[count].date.mn = tm->tm_min;
+                               count++;
+                       }
+
+                       msg.txMode = IFX_TAPI_CID_HM_ONHOOK;
+                       msg.messageType = IFX_TAPI_CID_MT_CSUP;
+                       msg.message = elements;
+                       msg.nMsgElements = count;
+
+                       status = (uint8_t) ioctl(dev_ctx.ch_fd[c], IFX_TAPI_CID_TX_SEQ_START, (IFX_int32_t) &msg);
+               }
+       } else {
+               status = (uint8_t) ioctl(dev_ctx.ch_fd[c], IFX_TAPI_RING_STOP, 0);
+               led_off(dev_ctx.ch_led[c]);
+       }
+
+       if (status) {
+               ast_log(LOG_ERROR, "%s ioctl failed\n",
+                       (r ? "IFX_TAPI_RING_START" : "IFX_TAPI_RING_STOP"));
+       }
+}
+
+/* add a frequency to TAPE tone structure */
+/* returns the TAPI frequency ID */
+static int tapitone_add_freq (IFX_TAPI_TONE_t *tone, IFX_uint32_t freq) {
+       const int n=4; /* TAPI tone structure supports up to 4 frequencies */
+       int error=0;
+       int ret;
+       int i;
+
+       /* pointer array for freq's A, B, C, D */
+       IFX_uint32_t *freqarr[] = { &(tone->simple.freqA), &(tone->simple.freqB), &(tone->simple.freqC), &(tone->simple.freqD) };
+
+       /* pointer array for level's A, B, C, D */
+       IFX_int32_t *lvlarr[] = { &(tone->simple.levelA), &(tone->simple.levelB), &(tone->simple.levelC), &(tone->simple.levelD) };
+
+       /* array for freq IDs */
+       IFX_uint32_t retarr[] = { IFX_TAPI_TONE_FREQA, IFX_TAPI_TONE_FREQB, IFX_TAPI_TONE_FREQC, IFX_TAPI_TONE_FREQD };
+
+       /* determine if freq already set */
+       for (i = 0; i < n; i++) {
+               if(*freqarr[i] == freq) /* freq found */
+                       break;
+               else if (i == n-1) /* last iteration */
+                       error=1; /* not found */
+       }
+
+       /* write frequency if not already set */
+       if(error) {
+               error=0; /* reset error flag */
+               /* since freq is not set, write it into first free place */
+               for (i = 0; i < n; i++) {
+                       if(!*freqarr[i]) { /* free place */
+                               *freqarr[i] = freq; /* set freq */
+                               *lvlarr[i] = -150; /* set volume level */
+                               break;
+                       } else if (i == n-1) /* last iteration */
+                               error=1; /* no free place becaus maximum count of freq's is set */
+               }
+       }
+
+       /* set freq ID return value */
+       if (!freq || error)
+               ret = IFX_TAPI_TONE_FREQNONE;
+       else
+               ret = retarr[i];
+
+       return ret; /* freq ID */
+}
+
+/* convert asterisk playlist string to tapi tone structure */
+/* based on ast_playtones_start() from indications.c of asterisk 13 */
+static void playlist_to_tapitone (const char *playlst, IFX_uint32_t index, IFX_TAPI_TONE_t *tone)
+{
+       char *s, *data = ast_strdupa(playlst);
+       char *stringp;
+       char *separator;
+       int i;
+
+       /* initialize tapi tone structure */
+       memset(tone, 0, sizeof(IFX_TAPI_TONE_t));
+       tone->simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+       tone->simple.index = index;
+
+       stringp = data;
+
+       /* check if the data is separated with '|' or with ',' by default */
+       if (strchr(stringp,'|')) {
+               separator = "|";
+       } else {
+               separator = ",";
+       }
+
+       for ( i = 0; (s = strsep(&stringp, separator)) && !ast_strlen_zero(s) && i < IFX_TAPI_TONE_STEPS_MAX; i++) {
+               struct ast_tone_zone_part tone_data = {
+                       .time = 0,
+               };
+
+               s = ast_strip(s);
+               if (s[0]=='!') {
+                       s++;
+               }
+
+               if (ast_tone_zone_part_parse(s, &tone_data)) {
+                       ast_log(LOG_ERROR, "Failed to parse tone part '%s'\n", s);
+                       continue;
+               }
+
+               /* first tone must hava a cadence */
+               if (i==0 && !tone_data.time)
+                       tone->simple.cadence[i] = 1000;
+               else
+                       tone->simple.cadence[i] = tone_data.time;
+
+               /* check for modulation */
+               if (tone_data.modulate) {
+                       tone->simple.modulation[i] = IFX_TAPI_TONE_MODULATION_ON;
+                       tone->simple.modulation_factor = IFX_TAPI_TONE_MODULATION_FACTOR_90;
+               }
+
+               /* copy freq's to tapi tone structure */
+               /* a freq will implicitly skipped if it is zero  */
+               tone->simple.frequencies[i] |= tapitone_add_freq(tone, tone_data.freq1);
+               tone->simple.frequencies[i] |= tapitone_add_freq(tone, tone_data.freq2);
+       }
+}
+
+static int lantiq_play_tone(int c, int t)
+{
+       /* stop currently playing tone before starting new one */
+       ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_LOCAL_PLAY, TAPI_TONE_LOCALE_NONE);
+
+       /* do not handle stop tone twice */
+       if (t != TAPI_TONE_LOCALE_NONE) {
+               /* start new tone */
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_LOCAL_PLAY, t)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_LOCAL_PLAY ioctl failed\n");
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+static enum channel_state lantiq_get_hookstatus(int port)
+{
+       uint8_t status;
+
+       if (ioctl(dev_ctx.ch_fd[port], IFX_TAPI_LINE_HOOK_STATUS_GET, &status)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_LINE_HOOK_STATUS_GET ioctl failed\n");
+               return UNKNOWN;
+       }
+
+       if (status) {
+               return OFFHOOK;
+       } else {
+               return ONHOOK;
+       }
+}
+
+static int
+lantiq_dev_binary_buffer_create(const char *path, uint8_t **ppBuf, uint32_t *pBufSz)
+{
+       FILE *fd;
+       struct stat file_stat;
+       int status = -1;
+
+       fd = fopen(path, "rb");
+       if (fd == NULL) {
+               ast_log(LOG_ERROR, "binary file %s open failed\n", path);
+               goto on_exit;
+       }
+
+       if (stat(path, &file_stat)) {
+               ast_log(LOG_ERROR, "file %s statistics get failed\n", path);
+               goto on_exit;
+       }
+
+       *ppBuf = malloc(file_stat.st_size);
+       if (*ppBuf == NULL) {
+               ast_log(LOG_ERROR, "binary file %s memory allocation failed\n", path);
+               goto on_exit;
+       }
+
+       if (fread (*ppBuf, sizeof(uint8_t), file_stat.st_size, fd) != file_stat.st_size) {
+               ast_log(LOG_ERROR, "file %s read failed\n", path);
+               status = -1;
+               goto on_exit;
+       }
+
+       *pBufSz = file_stat.st_size;
+       status = 0;
+
+on_exit:
+       if (fd != NULL)
+               fclose(fd);
+
+       if (*ppBuf != NULL && status)
+               free(*ppBuf);
+
+       return status;
+}
+
+static int32_t lantiq_dev_firmware_download(int32_t fd, const char *path)
+{
+       uint8_t *firmware = NULL;
+       uint32_t size = 0;
+       VMMC_IO_INIT vmmc_io_init;
+
+       ast_log(LOG_DEBUG, "loading firmware: \"%s\".\n", path);
+
+       if (lantiq_dev_binary_buffer_create(path, &firmware, &size))
+               return -1;
+
+       memset(&vmmc_io_init, 0, sizeof(VMMC_IO_INIT));
+       vmmc_io_init.pPRAMfw = firmware;
+       vmmc_io_init.pram_size = size;
+
+       if (ioctl(fd, FIO_FW_DOWNLOAD, &vmmc_io_init)) {
+               ast_log(LOG_ERROR, "FIO_FW_DOWNLOAD ioctl failed\n");
+               return -1;
+       }
+
+       if (firmware != NULL)
+               free(firmware);
+
+       return 0;
+}
+
+static const char *state_string(enum channel_state s)
+{
+       switch (s) {
+               case ONHOOK: return "ONHOOK";
+               case OFFHOOK: return "OFFHOOK";
+               case DIALING: return "DIALING";
+               case INCALL: return "INCALL";
+               case CALL_ENDED: return "CALL_ENDED";
+               case RINGING: return "RINGING";
+               default: return "UNKNOWN";
+       }
+}
+
+static const char *control_string(int c)
+{
+       switch (c) {
+               case AST_CONTROL_HANGUP: return "Other end has hungup";
+               case AST_CONTROL_RING: return "Local ring";
+               case AST_CONTROL_RINGING: return "Remote end is ringing";
+               case AST_CONTROL_ANSWER: return "Remote end has answered";
+               case AST_CONTROL_BUSY: return "Remote end is busy";
+               case AST_CONTROL_TAKEOFFHOOK: return "Make it go off hook";
+               case AST_CONTROL_OFFHOOK: return "Line is off hook";
+               case AST_CONTROL_CONGESTION: return "Congestion (circuits busy)";
+               case AST_CONTROL_FLASH: return "Flash hook";
+               case AST_CONTROL_WINK: return "Wink";
+               case AST_CONTROL_OPTION: return "Set a low-level option";
+               case AST_CONTROL_RADIO_KEY: return "Key Radio";
+               case AST_CONTROL_RADIO_UNKEY: return "Un-Key Radio";
+               case AST_CONTROL_PROGRESS: return "Remote end is making Progress";
+               case AST_CONTROL_PROCEEDING: return "Remote end is proceeding";
+               case AST_CONTROL_HOLD: return "Hold";
+               case AST_CONTROL_UNHOLD: return "Unhold";
+               case AST_CONTROL_SRCUPDATE: return "Media Source Update";
+               case AST_CONTROL_CONNECTED_LINE: return "Connected Line";
+               case AST_CONTROL_REDIRECTING: return "Redirecting";
+               case AST_CONTROL_INCOMPLETE: return "Incomplete";
+               case -1: return "Stop tone";
+               default: return "Unknown";
+       }
+}
+
+static int ast_lantiq_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen)
+{
+       struct lantiq_pvt *pvt = ast_channel_tech_pvt(chan);
+
+       ast_verb(3, "phone indication \"%s\"\n", control_string(condition));
+
+       switch (condition) {
+               case -1:
+                       {
+                               lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_NONE);
+                               return 0;
+                       }
+               case AST_CONTROL_CONGESTION:
+                       {
+                               if (tone_generator == TONE_INTEGRATED)
+                                       lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_CONGESTION_CODE);
+                               else
+                                       ast_playtones_start(chan, 0, ts_congestion->data, 1);
+
+                               return 0;
+                       }
+               case AST_CONTROL_BUSY:
+                       {
+                               if (tone_generator == TONE_INTEGRATED)
+                                       lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_BUSY_CODE);
+                               else
+                                       ast_playtones_start(chan, 0, ts_busy->data, 1);
+
+                               return 0;
+                       }
+               case AST_CONTROL_RINGING:
+               case AST_CONTROL_PROGRESS:
+                       {
+                               pvt->call_setup_delay = now() - pvt->call_setup_start;
+
+                               if (tone_generator == TONE_INTEGRATED)
+                                       lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_RINGING_CODE);
+                               else if (tone_generator == TONE_ASTERISK) /* do nothing if TONE_MEDIA is set */
+                                       ast_playtones_start(chan, 0, ts_ring->data, 1);
+
+                               return 0;
+                       }
+               default:
+                       {
+                               /* -1 lets asterisk generate the tone */
+                               return -1;
+                       }
+       }
+}
+
+static int ast_lantiq_fixup(struct ast_channel *old, struct ast_channel *new)
+{
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return 0;
+}
+
+static int ast_digit_begin(struct ast_channel *chan, char digit)
+{
+       /* TODO: Modify this callback to let Asterisk support controlling the length of DTMF */
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return 0;
+}
+
+static int ast_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
+{
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return 0;
+}
+
+static int ast_lantiq_call(struct ast_channel *ast, const char *dest, int timeout)
+{
+       int res = 0;
+       struct lantiq_pvt *pvt;
+
+       /* lock to prevent simultaneous access with do_monitor thread processing */
+       ast_mutex_lock(&iflock);
+
+       pvt = ast_channel_tech_pvt(ast);
+       ast_log(LOG_DEBUG, "state: %s\n", state_string(pvt->channel_state));
+
+       if (pvt->channel_state == ONHOOK) {
+               struct ast_party_id connected_id = ast_channel_connected_effective_id(ast);
+               const char *cid = connected_id.number.valid ? connected_id.number.str : NULL;
+               const char *name = connected_id.name.valid ? connected_id.name.str : NULL;
+
+               ast_log(LOG_DEBUG, "port %i is ringing\n", pvt->port_id);
+               ast_log(LOG_DEBUG, "port %i CID: %s\n", pvt->port_id, cid ? cid : "none");
+               ast_log(LOG_DEBUG, "port %i NAME: %s\n", pvt->port_id, name ? name : "none");
+
+               lantiq_ring(pvt->port_id, 1, cid, name);
+               pvt->channel_state = RINGING;
+
+               ast_setstate(ast, AST_STATE_RINGING);
+               ast_queue_control(ast, AST_CONTROL_RINGING);
+       } else {
+               ast_log(LOG_DEBUG, "port %i is busy\n", pvt->port_id);
+               ast_setstate(ast, AST_STATE_BUSY);
+               ast_queue_control(ast, AST_CONTROL_BUSY);
+               res = -1;
+       }
+
+       ast_mutex_unlock(&iflock);
+
+       return res;
+}
+
+static int ast_lantiq_hangup(struct ast_channel *ast)
+{
+       struct lantiq_pvt *pvt;
+
+       /* lock to prevent simultaneous access with do_monitor thread processing */
+       ast_mutex_lock(&iflock);
+
+       pvt = ast_channel_tech_pvt(ast);
+       ast_log(LOG_DEBUG, "state: %s\n", state_string(pvt->channel_state));
+
+       if (ast_channel_state(ast) == AST_STATE_RINGING) {
+               ast_debug(1, "channel state is RINGING\n");
+       }
+
+       switch (pvt->channel_state) {
+               case RINGING:
+               case ONHOOK:
+                       lantiq_ring(pvt->port_id, 0, NULL, NULL);
+                       pvt->channel_state = ONHOOK;
+                       break;
+               default:
+                       ast_log(LOG_DEBUG, "we were hung up, play busy tone\n");
+                       pvt->channel_state = CALL_ENDED;
+                       lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_BUSY_CODE);
+       }
+
+       lantiq_jb_get_stats(pvt->port_id);
+
+       ast_setstate(ast, AST_STATE_DOWN);
+       ast_module_unref(ast_module_info->self);
+       ast_channel_tech_pvt_set(ast, NULL);
+       pvt->owner = NULL;
+
+       ast_mutex_unlock(&iflock);
+
+       return 0;
+}
+
+static int ast_lantiq_answer(struct ast_channel *ast)
+{
+       struct lantiq_pvt *pvt = ast_channel_tech_pvt(ast);
+
+       ast_log(LOG_DEBUG, "Remote end has answered call.\n");
+
+       if (lantiq_conf_enc(pvt->port_id, ast_channel_writeformat(ast)))
+               return -1;
+
+       pvt->call_answer = epoch();
+
+       return 0;
+}
+
+static struct ast_frame * ast_lantiq_read(struct ast_channel *ast)
+{
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return NULL;
+}
+
+/* create asterisk format from rtp payload type */
+static struct ast_format *lantiq_map_rtptype_to_format(uint8_t rtptype)
+{
+       struct ast_format *format = NULL;
+
+       switch (rtptype) {
+               case RTP_PCMU: format = ast_format_ulaw; break;
+               case RTP_PCMA: format = ast_format_alaw; break;
+               case RTP_G722: format = ast_format_g722; break;
+               case RTP_G726: format = ast_format_g726; break;
+               case RTP_SLIN8: format = ast_format_slin; break;
+               case RTP_SLIN16: format = ast_format_slin16; break;
+               case RTP_ILBC: format = ast_format_ilbc; break;
+               case RTP_SIREN7: format = ast_format_siren7; break;
+               case RTP_G723_63: format = ast_format_g723; break;
+               case RTP_G723_53: format = ast_format_g723; break;
+               case RTP_G729: format = ast_format_g729; break;
+               default:
+               {
+                       ast_log(LOG_ERROR, "unsupported rtptype received is 0x%x, forcing ulaw\n", (unsigned) rtptype);
+                       format = ast_format_ulaw;
+               }
+       }
+
+       return format;
+}
+
+/* create rtp payload type from asterisk format */
+static uint8_t lantiq_map_format_to_rtptype(const struct ast_format *format)
+{
+       uint8_t rtptype = 0;
+
+       if (ast_format_cmp(format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_PCMU;
+       else if (ast_format_cmp(format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_PCMA;
+       else if (ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_G722;
+       else if (ast_format_cmp(format, ast_format_g726) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_G726;
+       else if (ast_format_cmp(format, ast_format_slin) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_SLIN8;
+       else if (ast_format_cmp(format, ast_format_slin16) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_SLIN16;
+       else if (ast_format_cmp(format, ast_format_ilbc) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_ILBC;
+       else if (ast_format_cmp(format, ast_format_siren7) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_SIREN7;
+       else if (ast_format_cmp(format, ast_format_g723) == AST_FORMAT_CMP_EQUAL)
+#if defined G723_HIGH_RATE
+               rtptype = RTP_G723_63;
+#else
+               rtptype = RTP_G723_53;
+#endif
+       else if (ast_format_cmp(format, ast_format_g729) == AST_FORMAT_CMP_EQUAL)
+               rtptype = RTP_G729;
+       else {
+               ast_log(LOG_ERROR, "unsupported format %s, forcing ulaw\n", ast_format_get_name(format));
+               rtptype = RTP_PCMU;
+       }
+
+       return rtptype;
+}
+
+static int lantiq_conf_enc(int c, const struct ast_format *format)
+{
+       /* Configure encoder before starting RTP session */
+       IFX_TAPI_ENC_CFG_t enc_cfg;
+
+       memset(&enc_cfg, 0, sizeof(IFX_TAPI_ENC_CFG_t));
+
+       if (ast_format_cmp(format, ast_format_ulaw) == AST_FORMAT_CMP_EQUAL) {
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_MLAW;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+               iflist[c].ptime = 10;
+       } else if (ast_format_cmp(format, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) {
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_ALAW;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+               iflist[c].ptime = 10;
+       } else if (ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) {
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G722_64;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+               iflist[c].ptime = 20;
+       } else if (ast_format_cmp(format, ast_format_g726) == AST_FORMAT_CMP_EQUAL) {
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G726_32;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+               iflist[c].ptime = 10;
+       } else if (ast_format_cmp(format, ast_format_slin) == AST_FORMAT_CMP_EQUAL) {
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_LIN16_8;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+               iflist[c].ptime = 10;
+       } else if (ast_format_cmp(format, ast_format_slin16) == AST_FORMAT_CMP_EQUAL) {
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_LIN16_16;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_10;
+               iflist[c].ptime = 10;
+       } else if (ast_format_cmp(format, ast_format_ilbc) == AST_FORMAT_CMP_EQUAL) {
+               /* iLBC 15.2kbps is currently unsupported by Asterisk */
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_ILBC_133;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_30;
+               iflist[c].ptime = 30;
+       } else if (ast_format_cmp(format, ast_format_siren7) == AST_FORMAT_CMP_EQUAL) {
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G7221_32;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+               iflist[c].ptime = 20;
+       } else if (ast_format_cmp(format, ast_format_g723) == AST_FORMAT_CMP_EQUAL) {
+#if defined G723_HIGH_RATE
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G723_63;
+#else
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G723_53;
+#endif
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_30;
+               iflist[c].ptime = 30;
+       } else if (ast_format_cmp(format, ast_format_g729) == AST_FORMAT_CMP_EQUAL) {
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_G729;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+               iflist[c].ptime = 10;
+       } else {
+               ast_log(LOG_ERROR, "unsupported format %s, forcing ulaw\n", ast_format_get_name(format));
+               enc_cfg.nEncType = IFX_TAPI_COD_TYPE_MLAW;
+               enc_cfg.nFrameLen = IFX_TAPI_COD_LENGTH_20;
+               iflist[c].ptime = 10;
+       }
+
+       ast_log(LOG_DEBUG, "Configuring encoder to use TAPI codec type %d (%s) on channel %i\n", enc_cfg.nEncType, ast_format_get_name(format), c);
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_CFG_SET, &enc_cfg)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_ENC_CFG_SET %d failed\n", c);
+       }
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_START, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_ENC_START ioctl failed\n");
+       }
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_DEC_START, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_DEC_START ioctl failed\n");
+       }
+
+       return 0;
+}
+
+static int ast_lantiq_write(struct ast_channel *ast, struct ast_frame *frame)
+{
+       char buf[RTP_BUFFER_LEN];
+       rtp_header_t *rtp_header = (rtp_header_t *) buf;
+       struct lantiq_pvt *pvt = ast_channel_tech_pvt(ast);
+       int ret;
+       uint8_t rtptype;
+       int subframes, subframes_rtp, length, samples;
+       char *head, *tail;
+
+       if(frame->frametype != AST_FRAME_VOICE) {
+               ast_log(LOG_DEBUG, "unhandled frame type\n");
+               return 0;
+       }
+
+       if (frame->datalen == 0) {
+               ast_log(LOG_DEBUG, "we've been prodded\n");
+               return 0;
+       }
+
+       /* get rtp payload type */
+       rtptype = lantiq_map_format_to_rtptype(frame->subclass.format);
+
+       rtp_header->version      = 2;
+       rtp_header->padding      = 0;
+       rtp_header->extension    = 0;
+       rtp_header->csrc_count   = 0;
+       rtp_header->marker       = 0;
+       rtp_header->ssrc         = 0;
+       rtp_header->payload_type = rtptype;
+
+       subframes = (iflist[pvt->port_id].ptime + frame->len - 1) / iflist[pvt->port_id].ptime; /* number of subframes in AST frame */
+       if (subframes == 0)
+               subframes = 1;
+
+       subframes_rtp = (RTP_BUFFER_LEN - RTP_HEADER_LEN) * subframes / frame->datalen; /* how many frames fit in a single RTP packet */
+
+       /* By default stick to the maximum multiple of native frame length */
+       length = subframes_rtp * frame->datalen / subframes;
+       samples = length * frame->samples / frame->datalen;
+
+       head = frame->data.ptr;
+       tail = frame->data.ptr + frame->datalen;
+       while (head < tail) {
+               rtp_header->seqno        = pvt->rtp_seqno++;
+               rtp_header->timestamp    = pvt->rtp_timestamp;
+
+               if ((tail - head) < (RTP_BUFFER_LEN - RTP_HEADER_LEN)) {
+                       length = tail - head;
+                       samples = length * frame->samples / frame->datalen;
+               }
+
+               if ( frame->datalen <= (sizeof(buf) - RTP_HEADER_LEN) )
+                       memcpy(buf + RTP_HEADER_LEN, head, length);
+               else {
+                       ast_log(LOG_WARNING, "buffer is too small\n");
+                       return -1;
+               }
+
+               head += length;
+               pvt->rtp_timestamp += (rtp_header->payload_type == RTP_G722) ? samples / 2 : samples; /* per RFC3551 */
+
+               ret = write(dev_ctx.ch_fd[pvt->port_id], buf, RTP_HEADER_LEN + length);
+               if (ret < 0) {
+                       ast_debug(1, "TAPI: ast_lantiq_write(): error writing.\n");
+                       return -1;
+               }
+               if (ret != (RTP_HEADER_LEN + length)) {
+                       ast_log(LOG_WARNING, "Short TAPI write of %d bytes, expected %d bytes\n", ret, RTP_HEADER_LEN + length);
+                       continue;
+               }
+       }
+
+       return 0;
+}
+
+static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *args, char *buf, size_t buflen)
+{
+       struct lantiq_pvt *pvt;
+       int res = 0;
+
+       if (!chan || ast_channel_tech(chan) != &lantiq_tech) {
+               ast_log(LOG_ERROR, "This function requires a valid Lantiq TAPI channel\n");
+               return -1;
+       }
+
+       ast_mutex_lock(&iflock);
+
+       pvt = (struct lantiq_pvt*) ast_channel_tech_pvt(chan);
+
+       if (!strcasecmp(args, "csd")) {
+               snprintf(buf, buflen, "%lu", (unsigned long int) pvt->call_setup_delay);
+       } else if (!strcasecmp(args, "jitter_stats")){
+               lantiq_jb_get_stats(pvt->port_id);
+               snprintf(buf, buflen, "jbBufSize=%u,jbUnderflow=%u,jbOverflow=%u,jbDelay=%u,jbInvalid=%u",
+                               (uint32_t) pvt->jb_size,
+                               (uint32_t) pvt->jb_underflow,
+                               (uint32_t) pvt->jb_overflow,
+                               (uint32_t) pvt->jb_delay,
+                               (uint32_t) pvt->jb_invalid);
+       } else if (!strcasecmp(args, "jbBufSize")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_size);
+       } else if (!strcasecmp(args, "jbUnderflow")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_underflow);
+       } else if (!strcasecmp(args, "jbOverflow")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_overflow);
+       } else if (!strcasecmp(args, "jbDelay")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_delay);
+       } else if (!strcasecmp(args, "jbInvalid")) {
+               snprintf(buf, buflen, "%u", (uint32_t) pvt->jb_invalid);
+       } else if (!strcasecmp(args, "start")) {
+               struct tm *tm = gmtime((const time_t*)&pvt->call_start);
+               strftime(buf, buflen, "%F %T", tm);
+       } else if (!strcasecmp(args, "answer")) {
+               struct tm *tm = gmtime((const time_t*)&pvt->call_answer);
+               strftime(buf, buflen, "%F %T", tm);
+       } else {
+               res = -1;
+       }
+
+       ast_mutex_unlock(&iflock);
+
+       return res;
+}
+
+static struct ast_frame * ast_lantiq_exception(struct ast_channel *ast)
+{
+       ast_log(LOG_DEBUG, "entering... no code here...\n");
+       return NULL;
+}
+
+static void lantiq_jb_get_stats(int c) {
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       IFX_TAPI_JB_STATISTICS_t param;
+       memset (&param, 0, sizeof (param));
+       if (ioctl (dev_ctx.ch_fd[c], IFX_TAPI_JB_STATISTICS_GET, (IFX_int32_t) &param) != IFX_SUCCESS) {
+               ast_debug(1, "Error getting jitter buffer  stats.\n");
+       } else {
+#if !defined (TAPI_VERSION3) && defined (TAPI_VERSION4)
+               ast_debug(1, "Jitter buffer stats:  dev=%u, ch=%u, nType=%u, nBufSize=%u, nIsUnderflow=%u, nDsOverflow=%u, nPODelay=%u, nInvalid=%u\n",
+                               (uint32_t) param.dev,
+                               (uint32_t) param.ch,
+#else
+               ast_debug(1, "Jitter buffer stats:  nType=%u, nBufSize=%u, nIsUnderflow=%u, nDsOverflow=%u, nPODelay=%u, nInvalid=%u\n",
+#endif
+                               (uint32_t) param.nType,
+                               (uint32_t) param.nBufSize,
+                               (uint32_t) param.nIsUnderflow,
+                               (uint32_t) param.nDsOverflow,
+                               (uint32_t) param.nPODelay,
+                               (uint32_t) param.nInvalid);
+
+               pvt->jb_size = param.nBufSize;
+               pvt->jb_underflow = param.nIsUnderflow;
+               pvt->jb_overflow = param.nDsOverflow;
+               pvt->jb_invalid = param.nInvalid;
+               pvt->jb_delay = param.nPODelay;
+       }
+}
+
+
+static int lantiq_standby(int c)
+{
+       ast_debug(1, "Stopping line feed for channel %i\n", c);
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_FEED_SET, IFX_TAPI_LINE_FEED_STANDBY)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_LINE_FEED_SET ioctl failed\n");
+               return -1;
+       }
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_STOP, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_ENC_STOP ioctl failed\n");
+               return -1;
+       }
+
+       if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_DEC_STOP, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_DEC_STOP ioctl failed\n");
+               return -1;
+       }
+
+       return lantiq_play_tone(c, TAPI_TONE_LOCALE_NONE);
+}
+
+static int lantiq_end_dialing(int c)
+{
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       ast_log(LOG_DEBUG, "end of dialing\n");
+
+       if (pvt->dial_timer != -1) {
+               AST_SCHED_DEL(sched, pvt->dial_timer);
+               pvt->dial_timer = -1;
+       }
+
+       if(pvt->owner) {
+               ast_hangup(pvt->owner);
+       }
+       lantiq_reset_dtmfbuf(pvt);
+
+       return 0;
+}
+
+static int lantiq_end_call(int c)
+{
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       ast_log(LOG_DEBUG, "end of call\n");
+
+       if(pvt->owner) {
+               lantiq_jb_get_stats(c);
+               ast_queue_hangup(pvt->owner);
+       }
+
+       return 0;
+}
+
+static struct ast_channel *lantiq_channel(int state, int c, char *ext, char *ctx, struct ast_format_cap *cap, const struct ast_assigned_ids *assigned_ids, const struct ast_channel *requestor)
+{
+       struct ast_channel *chan = NULL;
+       struct lantiq_pvt *pvt = &iflist[c];
+       struct ast_format *format = NULL;
+       struct ast_format_cap *newcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+       struct ast_format_cap *formatcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+
+       if (!newcap || !formatcap) {
+               ast_log(LOG_DEBUG, "Cannot allocate format capabilities!\n");
+               return NULL;
+       }
+
+       chan = ast_channel_alloc(1, state, NULL, NULL, "", ext, ctx, assigned_ids, requestor, c, "TAPI/%d", (c + 1));
+       if (!chan) {
+               ast_log(LOG_DEBUG, "Cannot allocate channel!\n");
+               ao2_ref(newcap, -1);
+               ao2_ref(formatcap, -1);
+               return NULL;
+       }
+
+       ast_channel_tech_set(chan, &lantiq_tech);
+       ast_channel_tech_pvt_set(chan, pvt);
+       pvt->owner = chan;
+
+       if (cap && ast_format_cap_iscompatible(cap, lantiq_tech.capabilities)) { /* compatible format capabilities given */
+               ast_format_cap_get_compatible(lantiq_tech.capabilities, cap, newcap);
+               format = ast_format_cap_get_format(newcap, 0); /* choose format */
+       } else { /* no or unsupported format capabilities given */
+               format = ast_format_cap_get_format(lantiq_tech.capabilities, 0); /* choose format from capabilities */
+       }
+
+       /* set choosed format */
+       ast_format_cap_append(formatcap, format, 0);
+       ast_channel_nativeformats_set(chan, formatcap);
+       ast_channel_set_readformat(chan, format);
+       ast_channel_set_writeformat(chan, format);
+       ast_channel_set_rawreadformat(chan, format);
+       ast_channel_set_rawwriteformat(chan, format);
+
+       ao2_ref(newcap, -1);
+       ao2_ref(formatcap, -1);
+
+       /* configuring encoder */
+       if (format != 0)
+               if (lantiq_conf_enc(c, format) < 0)
+                       return NULL;
+
+       return chan;
+}
+
+static struct ast_channel *ast_lantiq_requester(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assigned_ids, const struct ast_channel *requestor, const char *data, int *cause)
+{
+       struct ast_str *buf = ast_str_alloca(64);
+       struct ast_channel *chan = NULL;
+       int port_id = -1;
+
+       ast_mutex_lock(&iflock);
+
+       ast_debug(1, "Asked to create a TAPI channel with formats: %s\n", ast_format_cap_get_names(cap, &buf));
+
+       /* check for correct data argument */
+       if (ast_strlen_zero(data)) {
+               ast_log(LOG_ERROR, "Unable to create channel with empty destination.\n");
+               *cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
+               goto bailout;
+       }
+
+       /* get our port number */
+       port_id = atoi((char*) data);
+       if (port_id < 1 || port_id > dev_ctx.channels) {
+               ast_log(LOG_ERROR, "Unknown channel ID: \"%s\"\n", data);
+               *cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
+               goto bailout;
+       }
+
+       /* on asterisk user's side, we're using port 1-2.
+        * Here in non normal human's world, we begin
+        * counting at 0.
+        */
+       port_id -= 1;
+
+
+       /* Bail out if channel is already in use */
+       struct lantiq_pvt *pvt = &iflist[port_id];
+       if (! pvt->channel_state == ONHOOK) {
+               ast_debug(1, "TAPI channel %i alread in use.\n", port_id+1);
+       } else {
+               chan = lantiq_channel(AST_STATE_DOWN, port_id, NULL, NULL, cap, assigned_ids, requestor);
+               ast_channel_unlock(chan);  /* it's essential to unlock channel */
+       }
+
+bailout:
+       ast_mutex_unlock(&iflock);
+       return chan;
+}
+
+static int ast_lantiq_devicestate(const char *data)
+{
+       int port = atoi(data) - 1;
+       if ((port < 1) || (port > dev_ctx.channels)) {
+               return AST_DEVICE_INVALID;
+       }
+
+       switch (iflist[port].channel_state) {
+               case ONHOOK:
+                       return AST_DEVICE_NOT_INUSE;
+               case OFFHOOK:
+               case DIALING:
+               case INCALL:
+               case CALL_ENDED:
+                       return AST_DEVICE_INUSE;
+               case RINGING:
+                       return AST_DEVICE_RINGING;
+               case UNKNOWN:
+               default:
+                       return AST_DEVICE_UNKNOWN;
+       }
+}
+
+static int lantiq_dev_data_handler(int c)
+{
+       char buf[BUFSIZ];
+       struct ast_frame frame = {0};
+       struct ast_format *format = NULL;
+
+       int res = read(dev_ctx.ch_fd[c], buf, sizeof(buf));
+       if (res <= 0) {
+               ast_log(LOG_ERROR, "we got read error %i\n", res);
+               return -1;
+       } else if (res < RTP_HEADER_LEN) {
+               ast_log(LOG_ERROR, "we got data smaller than header size\n");
+               return -1;
+       }
+
+       rtp_header_t *rtp = (rtp_header_t*) buf;
+       struct lantiq_pvt *pvt = (struct lantiq_pvt *) &iflist[c];
+       if ((!pvt->owner) || (ast_channel_state(pvt->owner) != AST_STATE_UP)) {
+               return 0;
+       }
+
+       if (rtp->payload_type == RTP_CN) {
+               /* TODO: Handle Comfort Noise frames */
+               ast_debug(1, "Dropping Comfort Noise frame\n");
+       }
+
+       format = lantiq_map_rtptype_to_format(rtp->payload_type);
+       frame.src = "TAPI";
+       frame.frametype = AST_FRAME_VOICE;
+       frame.subclass.format = format;
+       frame.datalen = res - RTP_HEADER_LEN;
+       frame.data.ptr = buf + RTP_HEADER_LEN;
+       frame.samples = ast_codec_samples_count(&frame);
+
+       if(!ast_channel_trylock(pvt->owner)) {
+               ast_queue_frame(pvt->owner, &frame);
+               ast_channel_unlock(pvt->owner);
+       }
+
+       return 0;
+}
+
+static int accept_call(int c)
+{
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       ast_log(LOG_DEBUG, "accept call\n");
+
+       if (pvt->owner) {
+               struct ast_channel *chan = pvt->owner;
+
+               switch (ast_channel_state(chan)) {
+                       case AST_STATE_RINGING:
+                               lantiq_play_tone(c, TAPI_TONE_LOCALE_NONE);
+                               ast_queue_control(pvt->owner, AST_CONTROL_ANSWER);
+                               pvt->channel_state = INCALL;
+                               pvt->call_start = epoch();
+                               pvt->call_answer = pvt->call_start;
+                               break;
+                       default:
+                               ast_log(LOG_WARNING, "entered unhandled state %s\n", ast_state2str(ast_channel_state(chan)));
+               }
+       }
+
+       return 0;
+}
+
+static int lantiq_dev_event_hook(int c, int state)
+{
+       ast_mutex_lock(&iflock);
+
+       ast_log(LOG_DEBUG, "on port %i detected event %s hook\n", c, state ? "on" : "off");
+
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       int ret = -1;
+       if (state) { /* going onhook */
+               switch (iflist[c].channel_state) {
+                       case DIALING:
+                               ret = lantiq_end_dialing(c);
+                               break;
+                       case INCALL:
+                               ret = lantiq_end_call(c);
+                               break;
+               }
+
+               iflist[c].channel_state = ONHOOK;
+
+               /* stop DSP data feed */
+               lantiq_standby(c);
+               led_off(dev_ctx.ch_led[c]);
+
+       } else { /* going offhook */
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_FEED_SET, IFX_TAPI_LINE_FEED_ACTIVE)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_LINE_FEED_SET ioctl failed\n");
+                       goto out;
+               }
+
+               switch (iflist[c].channel_state) {
+                       case RINGING:
+                               ret = accept_call(c);
+                               led_blink(dev_ctx.ch_led[c], LED_SLOW_BLINK);
+                               break;
+                       default:
+                               iflist[c].channel_state = OFFHOOK;
+                               lantiq_play_tone(c, TAPI_TONE_LOCALE_DIAL_CODE);
+                               lantiq_reset_dtmfbuf(pvt);
+                               ret = 0;
+                               led_on(dev_ctx.ch_led[c]);
+                               break;
+               }
+
+       }
+
+out:
+       ast_mutex_unlock(&iflock);
+
+       return ret;
+}
+
+static void lantiq_reset_dtmfbuf(struct lantiq_pvt *pvt)
+{
+       pvt->dtmfbuf[0] = '\0';
+       pvt->dtmfbuf_len = 0;
+}
+
+static void lantiq_dial(struct lantiq_pvt *pvt)
+{
+       struct ast_channel *chan = NULL;
+
+       ast_mutex_lock(&iflock);
+       ast_log(LOG_DEBUG, "user want's to dial %s.\n", pvt->dtmfbuf);
+
+       if (ast_exists_extension(NULL, pvt->context, pvt->dtmfbuf, 1, NULL)) {
+               ast_debug(1, "found extension %s, dialing\n", pvt->dtmfbuf);
+
+               ast_verbose(VERBOSE_PREFIX_3 " extension exists, starting PBX %s\n", pvt->dtmfbuf);
+
+               chan = lantiq_channel(AST_STATE_UP, pvt->port_id, pvt->dtmfbuf, pvt->context, NULL, 0, NULL);
+               if (!chan) {
+                       ast_log(LOG_ERROR, "couldn't create channel\n");
+                       goto bailout;
+               }
+               ast_channel_tech_pvt_set(chan, pvt);
+               pvt->owner = chan;
+
+               ast_setstate(chan, AST_STATE_RING);
+               pvt->channel_state = INCALL;
+
+               pvt->call_setup_start = now();
+               pvt->call_start = epoch();
+
+               if (ast_pbx_start(chan)) {
+                       ast_log(LOG_WARNING, " unable to start PBX on %s\n", ast_channel_name(chan));
+                       ast_hangup(chan);
+               }
+
+               ast_channel_unlock(chan); /* it's essential to unlock channel */
+       } else {
+               ast_log(LOG_DEBUG, "no extension found\n");
+               lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_CONGESTION_CODE);
+               pvt->channel_state = CALL_ENDED;
+       }
+
+       lantiq_reset_dtmfbuf(pvt);
+bailout:
+       ast_mutex_unlock(&iflock);
+}
+
+static int lantiq_event_dial_timeout(const void* data)
+{
+       ast_debug(1, "TAPI: lantiq_event_dial_timeout()\n");
+
+       struct lantiq_pvt *pvt = (struct lantiq_pvt *) data;
+       pvt->dial_timer = -1;
+
+       if (! pvt->channel_state == ONHOOK) {
+               lantiq_dial(pvt);
+       } else {
+               ast_debug(1, "TAPI: lantiq_event_dial_timeout(): dial timeout in state ONHOOK.\n");
+       }
+
+       return 0;
+}
+
+static int lantiq_send_digit(int c, char digit)
+{
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       struct ast_frame f = { .frametype = AST_FRAME_DTMF, .subclass.integer = digit };
+
+       if (pvt->owner) {
+               ast_log(LOG_DEBUG, "Port %i transmitting digit \"%c\"\n", c, digit);
+               return ast_queue_frame(pvt->owner, &f);
+       } else {
+               ast_debug(1, "Warning: lantiq_send_digit() without owner!\n");
+               return -1;
+       }
+}
+
+static void lantiq_dev_event_digit(int c, char digit)
+{
+       ast_mutex_lock(&iflock);
+
+       ast_log(LOG_DEBUG, "on port %i detected digit \"%c\"\n", c, digit);
+
+       struct lantiq_pvt *pvt = &iflist[c];
+
+       switch (pvt->channel_state) {
+               case INCALL:
+                       lantiq_send_digit(c, digit);
+                       break;
+               case OFFHOOK:
+                       pvt->channel_state = DIALING;
+
+                       lantiq_play_tone(c, TAPI_TONE_LOCALE_NONE);
+                       led_blink(dev_ctx.ch_led[c], LED_SLOW_BLINK);
+
+                       /* fall through */
+               case DIALING:
+                       if (pvt->dtmfbuf_len < AST_MAX_EXTENSION - 1) {
+                               pvt->dtmfbuf[pvt->dtmfbuf_len] = digit;
+                               pvt->dtmfbuf[++pvt->dtmfbuf_len] = '\0';
+                       } else {
+                               /* No more room for another digit */
+                               lantiq_end_dialing(c);
+                               lantiq_play_tone(pvt->port_id, TAPI_TONE_LOCALE_BUSY_CODE);
+                               pvt->channel_state = CALL_ENDED;
+                               break;
+                       }
+
+                       /* setup autodial timer */
+                       if (pvt->dial_timer == -1) {
+                               ast_log(LOG_DEBUG, "setting new timer\n");
+                               pvt->dial_timer = ast_sched_add(sched, dev_ctx.interdigit_timeout, lantiq_event_dial_timeout, (const void*) pvt);
+                       } else {
+                               ast_log(LOG_DEBUG, "replacing timer\n");
+                               AST_SCHED_REPLACE(pvt->dial_timer, sched, dev_ctx.interdigit_timeout, lantiq_event_dial_timeout, (const void*) pvt);
+                       }
+                       break;
+               default:
+                       ast_log(LOG_ERROR, "don't know what to do in unhandled state\n");
+                       break;
+       }
+
+       ast_mutex_unlock(&iflock);
+       return;
+}
+
+static void lantiq_dev_event_handler(void)
+{
+       IFX_TAPI_EVENT_t event;
+       unsigned int i;
+
+       for (i = 0; i < dev_ctx.channels ; i++) {
+               ast_mutex_lock(&iflock);
+
+               memset (&event, 0, sizeof(event));
+               event.ch = i;
+               if (ioctl(dev_ctx.dev_fd, IFX_TAPI_EVENT_GET, &event)) {
+                       ast_mutex_unlock(&iflock);
+                       continue;
+               }
+               if (event.id == IFX_TAPI_EVENT_NONE) {
+                       ast_mutex_unlock(&iflock);
+                       continue;
+               }
+
+               ast_mutex_unlock(&iflock);
+
+               switch(event.id) {
+                       case IFX_TAPI_EVENT_FXS_ONHOOK:
+                               lantiq_dev_event_hook(i, 1);
+                               break;
+                       case IFX_TAPI_EVENT_FXS_OFFHOOK:
+                               lantiq_dev_event_hook(i, 0);
+                               break;
+                       case IFX_TAPI_EVENT_DTMF_DIGIT:
+                               lantiq_dev_event_digit(i, (char)event.data.dtmf.ascii);
+                               break;
+                       case IFX_TAPI_EVENT_PULSE_DIGIT:
+                               if (event.data.pulse.digit == 0xB) {
+                                       lantiq_dev_event_digit(i, '0');
+                               } else {
+                                       lantiq_dev_event_digit(i, '0' + (char)event.data.pulse.digit);
+                               }
+                               break;
+                       case IFX_TAPI_EVENT_COD_DEC_CHG:
+                       case IFX_TAPI_EVENT_TONE_GEN_END:
+                       case IFX_TAPI_EVENT_CID_TX_SEQ_END:
+                               break;
+                       default:
+                               ast_log(LOG_ERROR, "Unknown TAPI event %08X. Restarting Asterisk...\n", event.id);
+                               sleep(1);
+                               ast_cli_command(-1, "core restart now");
+                               break;
+               }
+       }
+}
+
+static void * lantiq_events_monitor(void *data)
+{
+       ast_verbose("TAPI thread started\n");
+
+       struct pollfd fds[TAPI_AUDIO_PORT_NUM_MAX + 1];
+       int c;
+
+       fds[0].fd = dev_ctx.dev_fd;
+       fds[0].events = POLLIN;
+       for (c = 0; c < dev_ctx.channels; c++) {
+               fds[c + 1].fd = dev_ctx.ch_fd[c];
+               fds[c + 1].events = POLLIN;
+       }
+
+       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+       for (;;) {
+               if (poll(fds, dev_ctx.channels + 1, 2000) <= 0) {
+                       continue;
+               }
+
+               ast_mutex_lock(&monlock);
+               if (fds[0].revents & POLLIN) {
+                       lantiq_dev_event_handler();
+               }
+
+               for (c = 0; c < dev_ctx.channels; c++) {
+                       if ((fds[c + 1].revents & POLLIN) && (lantiq_dev_data_handler(c))) {
+                               ast_log(LOG_ERROR, "data handler %d failed\n", c);
+                               break;
+                       }
+               }
+               ast_mutex_unlock(&monlock);
+       }
+
+       return NULL;
+}
+
+static int restart_monitor(void)
+{
+       /* If we're supposed to be stopped -- stay stopped */
+       if (monitor_thread == AST_PTHREADT_STOP)
+               return 0;
+
+       ast_mutex_lock(&monlock);
+
+       if (monitor_thread == pthread_self()) {
+               ast_mutex_unlock(&monlock);
+               ast_log(LOG_WARNING, "Cannot kill myself\n");
+               return -1;
+       }
+
+       if (monitor_thread != AST_PTHREADT_NULL) {
+               /* Wake up the thread */
+               pthread_kill(monitor_thread, SIGURG);
+       } else {
+               /* Start a new monitor */
+               if (ast_pthread_create_background(&monitor_thread, NULL, lantiq_events_monitor, NULL) < 0) {
+                       ast_mutex_unlock(&monlock);
+                       ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
+                       return -1;
+               }
+       }
+       ast_mutex_unlock(&monlock);
+
+       return 0;
+}
+
+static void lantiq_cleanup(void)
+{
+       int c;
+
+       if (dev_ctx.dev_fd < 0) {
+               return;
+       }
+
+       for (c = 0; c < dev_ctx.channels ; c++) {
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_FEED_SET, IFX_TAPI_LINE_FEED_STANDBY)) {
+                       ast_log(LOG_WARNING, "IFX_TAPI_LINE_FEED_SET ioctl failed\n");
+               }
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_STOP, 0)) {
+                       ast_log(LOG_WARNING, "IFX_TAPI_ENC_STOP ioctl failed\n");
+               }
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_DEC_STOP, 0)) {
+                       ast_log(LOG_WARNING, "IFX_TAPI_DEC_STOP ioctl failed\n");
+               }
+               led_off(dev_ctx.ch_led[c]);
+       }
+
+       if (ioctl(dev_ctx.dev_fd, IFX_TAPI_DEV_STOP, 0)) {
+               ast_log(LOG_WARNING, "IFX_TAPI_DEV_STOP ioctl failed\n");
+       }
+
+       close(dev_ctx.dev_fd);
+       dev_ctx.dev_fd = -1;
+       led_off(dev_ctx.voip_led);
+}
+
+static int unload_module(void)
+{
+       int c;
+
+       ast_channel_unregister(&lantiq_tech);
+
+       if (ast_mutex_lock(&iflock)) {
+               ast_log(LOG_WARNING, "Unable to lock the interface list\n");
+               return -1;
+       }
+       for (c = 0; c < dev_ctx.channels ; c++) {
+               if (iflist[c].owner)
+                       ast_softhangup(iflist[c].owner, AST_SOFTHANGUP_APPUNLOAD);
+       }
+       ast_mutex_unlock(&iflock);
+
+       if (ast_mutex_lock(&monlock)) {
+               ast_log(LOG_WARNING, "Unable to lock the monitor\n");
+               return -1;
+       }
+       if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
+               pthread_t th = monitor_thread;
+               monitor_thread = AST_PTHREADT_STOP;
+               pthread_cancel(th);
+               pthread_kill(th, SIGURG);
+               ast_mutex_unlock(&monlock);
+               pthread_join(th, NULL);
+       } else {
+               monitor_thread = AST_PTHREADT_STOP;
+               ast_mutex_unlock(&monlock);
+       }
+
+       ast_sched_context_destroy(sched);
+       ast_mutex_destroy(&iflock);
+       ast_mutex_destroy(&monlock);
+
+       lantiq_cleanup();
+       ast_free(iflist);
+
+       return 0;
+}
+
+static struct lantiq_pvt *lantiq_init_pvt(struct lantiq_pvt *pvt)
+{
+       if (pvt) {
+               pvt->owner = NULL;
+               pvt->port_id = -1;
+               pvt->channel_state = UNKNOWN;
+               pvt->context[0] = '\0';
+               pvt->dial_timer = -1;
+               pvt->dtmfbuf[0] = '\0';
+               pvt->dtmfbuf_len = 0;
+               pvt->call_setup_start = 0;
+               pvt->call_setup_delay = 0;
+               pvt->call_answer = 0;
+               pvt->jb_size = 0;
+               pvt->jb_underflow = 0;
+               pvt->jb_overflow = 0;
+               pvt->jb_delay = 0;
+               pvt->jb_invalid = 0;
+       } else {
+               ast_log(LOG_ERROR, "unable to clear pvt structure\n");
+       }
+
+       return pvt;
+}
+
+static int lantiq_create_pvts(void)
+{
+       int i;
+
+       iflist = ast_calloc(1, sizeof(struct lantiq_pvt) * dev_ctx.channels);
+
+       if (!iflist) {
+               ast_log(LOG_ERROR, "unable to allocate memory\n");
+               return -1;
+       }
+
+       for (i = 0; i < dev_ctx.channels; i++) {
+               lantiq_init_pvt(&iflist[i]);
+               iflist[i].port_id = i;
+               if (per_channel_context) {
+                       snprintf(iflist[i].context, AST_MAX_CONTEXT, "%s%i", LANTIQ_CONTEXT_PREFIX, i + 1);
+                       ast_debug(1, "Context for channel %i: %s\n", i, iflist[i].context);
+               } else {
+                       snprintf(iflist[i].context, AST_MAX_CONTEXT, "default");
+               }
+       }
+       return 0;
+}
+
+static int lantiq_setup_rtp(int c)
+{
+       /* Configure RTP payload type tables */
+       IFX_TAPI_PKT_RTP_PT_CFG_t rtpPTConf;
+
+       memset((char*)&rtpPTConf, '\0', sizeof(rtpPTConf));
+
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G723_63] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G723_63] = RTP_G723_63;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G723_53] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G723_53] = RTP_G723_53;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G729] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G729] = RTP_G729;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_MLAW] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_MLAW] = RTP_PCMU;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_ALAW] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_ALAW] = RTP_PCMA;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G726_32] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G726_32] = RTP_G726;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_ILBC_152] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_ILBC_152] = RTP_ILBC;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_LIN16_8] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_LIN16_8] = RTP_SLIN8;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_LIN16_16] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_LIN16_16] = RTP_SLIN16;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G722_64] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G722_64] = RTP_G722;
+       rtpPTConf.nPTup[IFX_TAPI_COD_TYPE_G7221_32] = rtpPTConf.nPTdown[IFX_TAPI_COD_TYPE_G7221_32] = RTP_G7221;
+
+       int ret;
+       if ((ret = ioctl(dev_ctx.ch_fd[c], IFX_TAPI_PKT_RTP_PT_CFG_SET, (IFX_int32_t) &rtpPTConf))) {
+               ast_log(LOG_ERROR, "IFX_TAPI_PKT_RTP_PT_CFG_SET failed: ret=%i\n", ret);
+               return -1;
+       }
+
+       return 0;
+}
+
+static int load_module(void)
+{
+       struct ast_config *cfg;
+       struct ast_variable *v;
+       int txgain = 0;
+       int rxgain = 0;
+       int wlec_type = 0;
+       int wlec_nlp = 0;
+       int wlec_nbfe = 0;
+       int wlec_nbne = 0;
+       int wlec_wbne = 0;
+       int jb_type = IFX_TAPI_JB_TYPE_ADAPTIVE;
+       int jb_pckadpt = IFX_TAPI_JB_PKT_ADAPT_VOICE;
+       int jb_localadpt = IFX_TAPI_JB_LOCAL_ADAPT_DEFAULT;
+       int jb_scaling = 0x10;
+       int jb_initialsize = 0x2d0;
+       int jb_minsize = 0x50;
+       int jb_maxsize = 0x5a0;
+       int cid_type = IFX_TAPI_CID_STD_TELCORDIA;
+       int vad_type = IFX_TAPI_ENC_VAD_NOVAD;
+       dev_ctx.dev_fd = -1;
+       dev_ctx.channels = TAPI_AUDIO_PORT_NUM_MAX;
+       dev_ctx.interdigit_timeout = DEFAULT_INTERDIGIT_TIMEOUT;
+       struct ast_tone_zone *tz;
+       struct ast_flags config_flags = { 0 };
+       int c;
+
+       if(!(lantiq_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
+         ast_log(LOG_ERROR, "Unable to allocate format capabilities.\n");
+         return AST_MODULE_LOAD_DECLINE;
+       }
+
+       /* channel format capabilities */
+       ast_format_cap_append(lantiq_tech.capabilities, ast_format_ulaw, 0);
+       ast_format_cap_append(lantiq_tech.capabilities, ast_format_alaw, 0);
+       ast_format_cap_append(lantiq_tech.capabilities, ast_format_g722, 0);
+       ast_format_cap_append(lantiq_tech.capabilities, ast_format_g726, 0);
+       ast_format_cap_append(lantiq_tech.capabilities, ast_format_slin, 0);
+
+       /* Turn off the LEDs, just in case */
+       led_off(dev_ctx.voip_led);
+       for(c = 0; c < TAPI_AUDIO_PORT_NUM_MAX; c++)
+               led_off(dev_ctx.ch_led[c]);
+
+       if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
+               ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
+               return AST_MODULE_LOAD_DECLINE;
+       }
+
+       /* We *must* have a config file otherwise stop immediately */
+       if (!cfg) {
+               ast_log(LOG_ERROR, "Unable to load config %s\n", config);
+               return AST_MODULE_LOAD_DECLINE;
+       }
+
+       if (ast_mutex_lock(&iflock)) {
+               ast_log(LOG_ERROR, "Unable to lock interface list.\n");
+               goto cfg_error;
+       }
+
+       for (v = ast_variable_browse(cfg, "interfaces"); v; v = v->next) {
+               if (!strcasecmp(v->name, "channels")) {
+                       dev_ctx.channels = atoi(v->value);
+                       if (!dev_ctx.channels) {
+                               ast_log(LOG_ERROR, "Invalid value for channels in config %s\n", config);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "firmwarefilename")) {
+                       ast_copy_string(firmware_filename, v->value, sizeof(firmware_filename));
+               } else if (!strcasecmp(v->name, "bbdfilename")) {
+                       ast_copy_string(bbd_filename, v->value, sizeof(bbd_filename));
+               } else if (!strcasecmp(v->name, "basepath")) {
+                       ast_copy_string(base_path, v->value, sizeof(base_path));
+               } else if (!strcasecmp(v->name, "per_channel_context")) {
+                       if (!strcasecmp(v->value, "on")) {
+                               per_channel_context = 1;
+                       } else if (!strcasecmp(v->value, "off")) {
+                               per_channel_context = 0;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown per_channel_context value '%s'. Try 'on' or 'off'.\n", v->value);
+                               goto cfg_error_il;
+                       }
+               }
+       }
+
+       for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
+               if (!strcasecmp(v->name, "rxgain")) {
+                       rxgain = atoi(v->value);
+                       if (!rxgain) {
+                               rxgain = 0;
+                               ast_log(LOG_WARNING, "Invalid rxgain: %s, using default.\n", v->value);
+                       }
+               } else if (!strcasecmp(v->name, "txgain")) {
+                       txgain = atoi(v->value);
+                       if (!txgain) {
+                               txgain = 0;
+                               ast_log(LOG_WARNING, "Invalid txgain: %s, using default.\n", v->value);
+                       }
+               } else if (!strcasecmp(v->name, "echocancel")) {
+                       if (!strcasecmp(v->value, "off")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_OFF;
+                       } else if (!strcasecmp(v->value, "nlec")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_NE;
+                               if (!strcasecmp(v->name, "echocancelfixedwindowsize")) {
+                                       wlec_nbne = atoi(v->value);
+                               }
+                       } else if (!strcasecmp(v->value, "wlec")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_NFE;
+                               if (!strcasecmp(v->name, "echocancelnfemovingwindowsize")) {
+                                       wlec_nbfe = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "echocancelfixedwindowsize")) {
+                                       wlec_nbne = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "echocancelwidefixedwindowsize")) {
+                                       wlec_wbne = atoi(v->value);
+                               }
+                       } else if (!strcasecmp(v->value, "nees")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_NE_ES;
+                       } else if (!strcasecmp(v->value, "nfees")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_NFE_ES;
+                       } else if (!strcasecmp(v->value, "es")) {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_ES;
+                       } else {
+                               wlec_type = IFX_TAPI_WLEC_TYPE_OFF;
+                               ast_log(LOG_ERROR, "Unknown echo cancellation type '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "echocancelnlp")) {
+                       if (!strcasecmp(v->value, "on")) {
+                               wlec_nlp = IFX_TAPI_WLEC_NLP_ON;
+                       } else if (!strcasecmp(v->value, "off")) {
+                               wlec_nlp = IFX_TAPI_WLEC_NLP_OFF;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown echo cancellation nlp '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "jitterbuffertype")) {
+                       if (!strcasecmp(v->value, "fixed")) {
+                               jb_type = IFX_TAPI_JB_TYPE_FIXED;
+                       } else if (!strcasecmp(v->value, "adaptive")) {
+                               jb_type = IFX_TAPI_JB_TYPE_ADAPTIVE;
+                               jb_localadpt = IFX_TAPI_JB_LOCAL_ADAPT_DEFAULT;
+                               if (!strcasecmp(v->name, "jitterbufferadaptation")) {
+                                       if (!strcasecmp(v->value, "on")) {
+                                               jb_localadpt = IFX_TAPI_JB_LOCAL_ADAPT_ON;
+                                       } else if (!strcasecmp(v->value, "off")) {
+                                               jb_localadpt = IFX_TAPI_JB_LOCAL_ADAPT_OFF;
+                                       }
+                               } else if (!strcasecmp(v->name, "jitterbufferscalling")) {
+                                       jb_scaling = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "jitterbufferinitialsize")) {
+                                       jb_initialsize = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "jitterbufferminsize")) {
+                                       jb_minsize = atoi(v->value);
+                               } else if (!strcasecmp(v->name, "jitterbuffermaxsize")) {
+                                       jb_maxsize = atoi(v->value);
+                               }
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown jitter buffer type '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "jitterbufferpackettype")) {
+                       if (!strcasecmp(v->value, "voice")) {
+                               jb_pckadpt = IFX_TAPI_JB_PKT_ADAPT_VOICE;
+                       } else if (!strcasecmp(v->value, "data")) {
+                               jb_pckadpt = IFX_TAPI_JB_PKT_ADAPT_DATA;
+                       } else if (!strcasecmp(v->value, "datanorep")) {
+                               jb_pckadpt = IFX_TAPI_JB_PKT_ADAPT_DATA_NO_REP;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown jitter buffer packet adaptation type '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "calleridtype")) {
+                       ast_log(LOG_DEBUG, "Setting CID type to %s.\n", v->value);
+                       if (!strcasecmp(v->value, "telecordia")) {
+                               cid_type = IFX_TAPI_CID_STD_TELCORDIA;
+                       } else if (!strcasecmp(v->value, "etsifsk")) {
+                               cid_type = IFX_TAPI_CID_STD_ETSI_FSK;
+                       } else if (!strcasecmp(v->value, "etsidtmf")) {
+                               cid_type = IFX_TAPI_CID_STD_ETSI_DTMF;
+                       } else if (!strcasecmp(v->value, "sin")) {
+                               cid_type = IFX_TAPI_CID_STD_SIN;
+                       } else if (!strcasecmp(v->value, "ntt")) {
+                               cid_type = IFX_TAPI_CID_STD_NTT;
+                       } else if (!strcasecmp(v->value, "kpndtmf")) {
+                               cid_type = IFX_TAPI_CID_STD_KPN_DTMF;
+                       } else if (!strcasecmp(v->value, "kpndtmffsk")) {
+                               cid_type = IFX_TAPI_CID_STD_KPN_DTMF_FSK;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown caller id type '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "voiceactivitydetection")) {
+                       if (!strcasecmp(v->value, "on")) {
+                               vad_type = IFX_TAPI_ENC_VAD_ON;
+                       } else if (!strcasecmp(v->value, "g711")) {
+                               vad_type = IFX_TAPI_ENC_VAD_G711;
+                       } else if (!strcasecmp(v->value, "cng")) {
+                               vad_type = IFX_TAPI_ENC_VAD_CNG_ONLY;
+                       } else if (!strcasecmp(v->value, "sc")) {
+                               vad_type = IFX_TAPI_ENC_VAD_SC_ONLY;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown voice activity detection value '%s'\n", v->value);
+                               goto cfg_error_il;
+                       }
+               } else if (!strcasecmp(v->name, "interdigit")) {
+                       dev_ctx.interdigit_timeout = atoi(v->value);
+                       ast_log(LOG_DEBUG, "Setting interdigit timeout to %s.\n", v->value);
+                       if (!dev_ctx.interdigit_timeout) {
+                               dev_ctx.interdigit_timeout = DEFAULT_INTERDIGIT_TIMEOUT;
+                               ast_log(LOG_WARNING, "Invalid interdigit timeout: %s, using default.\n", v->value);
+                       }
+               } else if (!strcasecmp(v->name, "tone_generator")) {
+                       if (!strcasecmp(v->value, "integrated")) {
+                               tone_generator = TONE_INTEGRATED;
+                       } else if (!strcasecmp(v->value, "asterisk")) {
+                               tone_generator = TONE_ASTERISK;
+                       } else if (!strcasecmp(v->value, "media")) {
+                               tone_generator = TONE_MEDIA;
+                       } else {
+                               ast_log(LOG_ERROR, "Unknown tone_generator value '%s'. Try 'integrated', 'asterisk' or 'media'.\n", v->value);
+                               goto cfg_error_il;
+                       }
+               }
+       }
+
+       lantiq_create_pvts();
+
+       ast_mutex_unlock(&iflock);
+       ast_config_destroy(cfg);
+
+       if (!(sched = ast_sched_context_create())) {
+               ast_log(LOG_ERROR, "Unable to create scheduler context\n");
+               goto load_error;
+       }
+
+       if (ast_sched_start_thread(sched)) {
+               ast_log(LOG_ERROR, "Unable to create scheduler context thread\n");
+               goto load_error_st;
+       }
+
+       if (ast_channel_register(&lantiq_tech)) {
+               ast_log(LOG_ERROR, "Unable to register channel class 'Phone'\n");
+               goto load_error_st;
+       }
+
+       /* tapi */
+       IFX_TAPI_TONE_t tone;
+       IFX_TAPI_DEV_START_CFG_t dev_start;
+       IFX_TAPI_MAP_DATA_t map_data;
+       IFX_TAPI_LINE_TYPE_CFG_t line_type;
+       IFX_TAPI_LINE_VOLUME_t line_vol;
+       IFX_TAPI_WLEC_CFG_t wlec_cfg;
+       IFX_TAPI_JB_CFG_t jb_cfg;
+       IFX_TAPI_CID_CFG_t cid_cfg;
+
+       /* open device */
+       dev_ctx.dev_fd = lantiq_dev_open(base_path, 0);
+
+       if (dev_ctx.dev_fd < 0) {
+               ast_log(LOG_ERROR, "lantiq TAPI device open function failed\n");
+               goto load_error_st;
+       }
+
+       snprintf(dev_ctx.voip_led, LED_NAME_LENGTH, "voice");
+       for (c = 0; c < dev_ctx.channels ; c++) {
+               dev_ctx.ch_fd[c] = lantiq_dev_open(base_path, c + 1);
+
+               if (dev_ctx.ch_fd[c] < 0) {
+                       ast_log(LOG_ERROR, "lantiq TAPI channel %d open function failed\n", c);
+                       goto load_error_st;
+               }
+               snprintf(dev_ctx.ch_led[c], LED_NAME_LENGTH, "fxs%d", c + 1);
+       }
+
+       if (lantiq_dev_firmware_download(dev_ctx.dev_fd, firmware_filename)) {
+               ast_log(LOG_ERROR, "voice firmware download failed\n");
+               goto load_error_st;
+       }
+
+       if (ioctl(dev_ctx.dev_fd, IFX_TAPI_DEV_STOP, 0)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_DEV_STOP ioctl failed\n");
+               goto load_error_st;
+       }
+
+       memset(&dev_start, 0x0, sizeof(IFX_TAPI_DEV_START_CFG_t));
+       dev_start.nMode = IFX_TAPI_INIT_MODE_VOICE_CODER;
+
+       /* Start TAPI */
+       if (ioctl(dev_ctx.dev_fd, IFX_TAPI_DEV_START, &dev_start)) {
+               ast_log(LOG_ERROR, "IFX_TAPI_DEV_START ioctl failed\n");
+               goto load_error_st;
+       }
+
+       tz = ast_get_indication_zone(NULL);
+
+       if (!tz) {
+               ast_log(LOG_ERROR, "Unable to alloc tone zone\n");
+               goto load_error_st;
+       }
+
+       ts_dial = ast_get_indication_tone(tz, "dial");
+       ts_ring = ast_get_indication_tone(tz, "ring");
+       ts_busy = ast_get_indication_tone(tz, "busy");
+       ts_congestion = ast_get_indication_tone(tz, "congestion");
+
+       if (!ts_dial || !ts_dial->data || !ts_ring || !ts_ring->data || !ts_busy || !ts_busy->data || !ts_congestion || !ts_congestion->data) {
+               ast_log(LOG_ERROR, "Unable to get indication tones\n");
+               goto load_error_st;
+       }
+
+       for (c = 0; c < dev_ctx.channels ; c++) {
+               /* We're a FXS and want to switch between narrow & wide band automatically */
+               memset(&line_type, 0, sizeof(IFX_TAPI_LINE_TYPE_CFG_t));
+               line_type.lineType = IFX_TAPI_LINE_TYPE_FXS_AUTO;
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_TYPE_SET, &line_type)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_LINE_TYPE_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* tones */
+               memset(&tone, 0, sizeof(IFX_TAPI_TONE_t));
+               tone.simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+               playlist_to_tapitone(ts_dial->data, TAPI_TONE_LOCALE_DIAL_CODE, &tone);
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_TABLE_CFG_SET, &tone)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_TABLE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               memset(&tone, 0, sizeof(IFX_TAPI_TONE_t));
+               tone.simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+               playlist_to_tapitone(ts_ring->data, TAPI_TONE_LOCALE_RINGING_CODE, &tone);
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_TABLE_CFG_SET, &tone)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_TABLE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               memset(&tone, 0, sizeof(IFX_TAPI_TONE_t));
+               tone.simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+               playlist_to_tapitone(ts_busy->data, TAPI_TONE_LOCALE_BUSY_CODE, &tone);
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_TABLE_CFG_SET, &tone)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_TABLE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               memset(&tone, 0, sizeof(IFX_TAPI_TONE_t));
+               tone.simple.format = IFX_TAPI_TONE_TYPE_SIMPLE;
+               playlist_to_tapitone(ts_congestion->data, TAPI_TONE_LOCALE_CONGESTION_CODE, &tone);
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_TONE_TABLE_CFG_SET, &tone)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_TONE_TABLE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* ringing type */
+               IFX_TAPI_RING_CFG_t ringingType;
+               memset(&ringingType, 0, sizeof(IFX_TAPI_RING_CFG_t));
+               ringingType.nMode = IFX_TAPI_RING_CFG_MODE_INTERNAL_BALANCED;
+               ringingType.nSubmode = IFX_TAPI_RING_CFG_SUBMODE_DC_RNG_TRIP_FAST;
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_RING_CFG_SET, (IFX_int32_t) &ringingType)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_RING_CFG_SET failed\n");
+                       goto load_error_st;
+               }
+
+               /* ring cadence */
+               IFX_char_t data[15] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+                                       0x00, 0x00, 0x00, 0x00, 0x00,
+                                       0x00, 0x00, 0x00, 0x00, 0x00 };
+
+               IFX_TAPI_RING_CADENCE_t ringCadence;
+               memset(&ringCadence, 0, sizeof(IFX_TAPI_RING_CADENCE_t));
+               memcpy(&ringCadence.data, data, sizeof(data));
+               ringCadence.nr = sizeof(data) * 8;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_RING_CADENCE_HR_SET, &ringCadence)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_RING_CADENCE_HR_SET failed\n");
+                       goto load_error_st;
+               }
+
+               /* perform mapping */
+               memset(&map_data, 0x0, sizeof(IFX_TAPI_MAP_DATA_t));
+               map_data.nDstCh = c;
+               map_data.nChType = IFX_TAPI_MAP_TYPE_PHONE;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_MAP_DATA_ADD, &map_data)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_MAP_DATA_ADD %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* set line feed */
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_LINE_FEED_SET, IFX_TAPI_LINE_FEED_STANDBY)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_LINE_FEED_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* set volume */
+               memset(&line_vol, 0, sizeof(line_vol));
+               line_vol.nGainRx = rxgain;
+               line_vol.nGainTx = txgain;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_PHONE_VOLUME_SET, &line_vol)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_PHONE_VOLUME_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Configure line echo canceller */
+               memset(&wlec_cfg, 0, sizeof(wlec_cfg));
+               wlec_cfg.nType = wlec_type;
+               wlec_cfg.bNlp = wlec_nlp;
+               wlec_cfg.nNBFEwindow = wlec_nbfe;
+               wlec_cfg.nNBNEwindow = wlec_nbne;
+               wlec_cfg.nWBNEwindow = wlec_wbne;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_WLEC_PHONE_CFG_SET, &wlec_cfg)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_WLEC_PHONE_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Configure jitter buffer */
+               memset(&jb_cfg, 0, sizeof(jb_cfg));
+               jb_cfg.nJbType = jb_type;
+               jb_cfg.nPckAdpt = jb_pckadpt;
+               jb_cfg.nLocalAdpt = jb_localadpt;
+               jb_cfg.nScaling = jb_scaling;
+               jb_cfg.nInitialSize = jb_initialsize;
+               jb_cfg.nMinSize = jb_minsize;
+               jb_cfg.nMaxSize = jb_maxsize;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_JB_CFG_SET, &jb_cfg)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_JB_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Configure Caller ID type */
+               memset(&cid_cfg, 0, sizeof(cid_cfg));
+               cid_cfg.nStandard = cid_type;
+
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_CID_CFG_SET, &cid_cfg)) {
+                       ast_log(LOG_ERROR, "IIFX_TAPI_CID_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Configure voice activity detection */
+               if (ioctl(dev_ctx.ch_fd[c], IFX_TAPI_ENC_VAD_CFG_SET, vad_type)) {
+                       ast_log(LOG_ERROR, "IFX_TAPI_ENC_VAD_CFG_SET %d failed\n", c);
+                       goto load_error_st;
+               }
+
+               /* Setup TAPI <-> internal RTP codec type mapping */
+               if (lantiq_setup_rtp(c)) {
+                       goto load_error_st;
+               }
+
+               /* Set initial hook status */
+               iflist[c].channel_state = lantiq_get_hookstatus(c);
+
+               if (iflist[c].channel_state == UNKNOWN) {
+                       goto load_error_st;
+               }
+       }
+
+       /* make sure our device will be closed properly */
+       ast_register_atexit(lantiq_cleanup);
+
+       restart_monitor();
+       led_on(dev_ctx.voip_led);
+       return AST_MODULE_LOAD_SUCCESS;
+
+cfg_error_il:
+       ast_mutex_unlock(&iflock);
+cfg_error:
+       ast_config_destroy(cfg);
+       return AST_MODULE_LOAD_DECLINE;
+
+load_error_st:
+       ast_sched_context_destroy(sched);
+load_error:
+       unload_module();
+       ast_free(iflist);
+       return AST_MODULE_LOAD_FAILURE;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Lantiq TAPI Telephony API Support",
+       .load = load_module,
+       .unload = unload_module,
+       .load_pri = AST_MODPRI_CHANNEL_DRIVER
+);
diff --git a/net/asterisk-13.x/src-lantiq/configs/samples/lantiq.conf.sample b/net/asterisk-13.x/src-lantiq/configs/samples/lantiq.conf.sample
new file mode 100644 (file)
index 0000000..74c6f3f
--- /dev/null
@@ -0,0 +1,153 @@
+;
+; TAPI Telephony Interface
+;
+; Configuration file
+
+[interfaces]
+;
+; Number of FXS ports (default: 2)
+channels = 2
+;
+; Create contexts per channel (default: off)
+;per_channel_context = off
+;
+; Set tapi firmware file path
+;firmwarefilename = /lib/firmware/danube_firmware.bin
+;
+; Set tapi bbd file path
+;bbdfilename = /lib/firmware/danube_bbd_fxs.bin
+;
+; Set vmmc device path
+;basepath = /dev/vmmc
+;
+[general]
+;
+; Gain setting for the receive and transmit path.
+; The value is given in dB within the range (-24dB to +12dB), in 1 dB steps.
+;
+;rxgain = 1
+;txgain = 1
+;
+;
+;
+; Line echo cancller valid types:
+;
+; off          LEC and echo suppressor turned off.
+; nlec         LEC using fixed window; no echo suppressor.
+; wlec         LEC using fixed and moving window; no echo suppressor.
+; nees         LEC using fixed window and echo suppressor.
+; nfees                LEC using fixed and moving window and echo suppressor.
+; es           Echo suppressor
+;
+;echocancel = off
+;
+; If nlec or wlec is selected than size of the fixed window in narrowband (8 kHz) sampling mode
+; can be defined with:
+; A value of 0 defaults to: 16 ms if type is nlec or 8 ms if type is wlec:
+;
+;echocancelfixedwindowsize = 0
+;
+; If wlec is selected than size of the moving window in narrowband (8 kHz) sampling mode
+; can be defined with:
+; A value of 0 defaults to 8 ms.
+;
+;echocancelnfemovingwindowsize = 0
+;
+; If wlec is selected than size of the moving window in wideband (16 kHz) sampling mode
+; can be defined with:
+; A value of 0 defaults to 8 ms.
+;
+;echocancelwidefixedwindowsize = 0
+;
+; Activate or deactivate line echo cancller NLP (Non Linear Processor) if the LEC is active,
+; valid is on or off:
+;
+;echocancelnlp = off
+;
+;
+;
+; Jitter buffer valid types:
+;
+; fixed                Fixed jitter buffer.
+; adaptive     Adaptive jitter buffer.
+;
+;jitterbuffertype = fixed
+;
+; Jitter buffer packet adaptation valid types:
+;
+; voice                Jitter buffer optimized for voice.
+; data         Jitter buffer optimized for data.
+; datanorep    Jitter buffer optimized for data but without doing packet repetition.
+;
+;jitterbufferpackettype = voice
+;
+;      Following jitter buffer values can only be used with jitter buffer adaptive type:
+; Turns on or off jitter buffer adaptation:
+;
+;jitterbufferadaptation = off
+;
+; Scaling factor multiplied by 16; in adaptive jitter buffer mode, the target average playout delay is
+; equal to the estimated jitter multiplied by the scaling factor. The default value for the scaling factor
+; is about 1.4 (scaling=22), meaning that the target average playout delay is equal to the estimated
+; jitter. If less packets should be dropped because of jitter, the scaling factor has to be increased. An
+; increase in the scaling factor will eventually lead to an increased playout delay.
+; The supported range is 1 to 16 (16 up to 256).
+;
+;jitterbufferscalling = 1
+;
+; Initial size of the jitter buffer in time stamps of 125 us:
+;
+;jitterbufferinitialsize = 125
+;
+; Minimum size of the jitter buffer in time stamps of 125 us
+;
+;jitterbufferminsize = 125
+;
+; Maximum size of the jitter buffer in time stamps of 125 us
+;
+;jitterbuffermaxsize = 125
+;
+;
+;
+; Caller id valid standards:
+;
+; telecordia    Bellcore/Telcordia GR-30-CORE; use Bell202 FSK coding of CID information. (default)
+; etsifsk       ETSI 300-659-1/2/3 V1.3.1; use V.23 FSK coding to transmit CID information.
+; etsidtmf      ETSI 300-659-1/2/3 V1.3.1; use DTMF transmission of CID information.
+; sin           SIN 227 Issue 3.4; use V.23 FSK coding of CID information.
+; ntt           NTT standard: TELEPHONE SERVICE INTERFACES, edition 5; use a modified V.23 FSK coding of
+;               CID information.
+; kpndtmf       KPN; use DTMF transmission of CID information.
+; kpndtmffsk    KPN; use DTMF and FSK transmission of CID information.
+;
+;calleridtype = telecordia
+;
+;
+;
+; Voice activity detection:
+;
+; on           Voice activity detection on; in this case also comfort noise and spectral
+;              information (nicer noise) is switched on.
+; g711         Voice activity detection on with comfort noise generation,
+;              but without spectral information.
+; cng          Voice activity detection on with comfort noise generation, but without silence compression
+; sc           Voice activity detection on with silence compression,
+;              but without comfort noise generation.
+;
+;voiceactivitydetection = on
+;
+;
+;
+; Timeout between dialed digits, in milliseconds, before placing the call.
+;
+;interdigit = 4000
+;
+;
+;
+; Tone generator type (default: integrated)
+; integrated   Use tapi tone generator
+; asterisk     Use asterisk tone generator where possible
+; media                Use media tone where possible
+;
+;tone_generator = integrated
+;
diff --git a/net/freeswitch-stable-sounds/Makefile b/net/freeswitch-stable-sounds/Makefile
new file mode 100644 (file)
index 0000000..3c545b5
--- /dev/null
@@ -0,0 +1,112 @@
+#
+# Copyright (C) 2017 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=freeswitch-stable-sounds
+PKG_VERSION:=1.0.52
+PKG_RELEASE:=1
+PKG_MAINTAINER:=Sebastian Kemper <sebastian_ml@gmx.net>
+
+PKG_LICENSE:=MPL-1.1
+
+PRG_URL:=https://files.freeswitch.org/releases/sounds
+
+include $(INCLUDE_DIR)/package.mk
+
+SOUNDS_DIR:=/usr/share/freeswitch/sounds
+
+define Package/$(PKG_NAME)/Default
+  SUBMENU:=Telephony
+  SECTION:=net
+  CATEGORY:=Network
+  URL:=https://www.freeswitch.org
+  DEPENDS:=freeswitch-stable
+  PKGARCH:=all
+endef
+
+define Package/$(PKG_NAME)/Sounds
+define Package/$(PKG_NAME)-$(1)
+$(call Package/$(PKG_NAME)/Default)
+  TITLE:=$(2)
+endef
+define Download/$(PKG_NAME)-$(1)
+  FILE:=freeswitch-sounds-$(1)-$(4).tar.gz
+  URL:=$(PRG_URL)
+  MD5SUM:=$(5)
+endef
+define Package/$(PKG_NAME)-$(1)/description
+$(3)
+endef
+define Package/$(PKG_NAME)-$(1)/install
+       $(INSTALL_DIR) $$(1)$(SOUNDS_DIR)
+       $(TAR) --extract --no-same-owner --no-same-permissions --gzip \
+               --file=$(DL_DIR)/freeswitch-sounds-$(1)-$(4).tar.gz \
+               --directory=$$(1)$(SOUNDS_DIR)
+       $(FIND) $$(1)$(SOUNDS_DIR) -type d -exec chmod 755 {} \;
+       $(FIND) $$(1)$(SOUNDS_DIR) -type f -exec chmod 644 {} \;
+endef
+ifneq ($(CONFIG_PACKAGE_$(PKG_NAME)-$(1)),)
+$$(eval $$(call Download,$(PKG_NAME)-$(1)))
+endif
+$$(eval $$(call BuildPackage,$(PKG_NAME)-$(1)))
+endef
+
+define Build/Prepare
+endef
+
+define Build/Compile
+endef
+
+################################
+# FreeSWITCH sound packs
+# Params:
+# 1 - Package subname
+# 2 - Package title
+# 3 - Package description
+# 4 - Source version
+# 5 - Source SHA256SUM
+################################
+
+$(eval $(call Package/$(PKG_NAME)/Sounds,en-ca-june-8000,Sound prompts,Speaker: June - Language: en-CA - Sample Rate: 8kHz,1.0.51,9aaa9d73cfecfdab7a1fa2d63d65b922b86a405ebb9a31b09b15e58a2af9260a))
+$(eval $(call Package/$(PKG_NAME)/Sounds,en-ca-june-16000,Sound prompts,Speaker: June - Language: en-CA - Sample Rate: 16kHz,1.0.51,8d0091a2c98e5e06afea6bdd9f6cf2942e937786016037207b85757218b0f7a7))
+$(eval $(call Package/$(PKG_NAME)/Sounds,en-ca-june-32000,Sound prompts,Speaker: June - Language: en-CA - Sample Rate: 32kHz,1.0.51,8720b363995724792ff4723e1c8218ef95b27cb36208b7258f93bdda72123387))
+$(eval $(call Package/$(PKG_NAME)/Sounds,en-ca-june-48000,Sound prompts,Speaker: June - Language: en-CA - Sample Rate: 48kHz,1.0.51,d2fce478a95b8d9500a544a00253c81d7e9f639e21980bd689910fac87f30871))
+$(eval $(call Package/$(PKG_NAME)/Sounds,en-us-callie-8000,Sound prompts,Speaker: Callie - Language: en-US - Sample Rate: 8kHz,1.0.51,e48a63bd69e6253d294ce43a941d603b02467feb5d92ee57a536ccc5f849a4a8))
+$(eval $(call Package/$(PKG_NAME)/Sounds,en-us-callie-16000,Sound prompts,Speaker: Callie - Language: en-US - Sample Rate: 16kHz,1.0.51,324b1ab5ab754db5697963e9bf6a2f9c7aeb1463755e86bbb6dc4d6a77329da2))
+$(eval $(call Package/$(PKG_NAME)/Sounds,en-us-callie-32000,Sound prompts,Speaker: Callie - Language: en-US - Sample Rate: 32kHz,1.0.51,06fd6b8aec937556bf5303ab19a212c60daf00546d395cf269dfe324ac9c6838))
+$(eval $(call Package/$(PKG_NAME)/Sounds,en-us-callie-48000,Sound prompts,Speaker: Callie - Language: en-US - Sample Rate: 48kHz,1.0.51,cfc50f1d9b5d43cb87a9a2c0ce136c37ee85ac3b0e5be930d8dc2c913c4495aa))
+$(eval $(call Package/$(PKG_NAME)/Sounds,fr-ca-june-8000,Sound prompts,Speaker: June - Language: fr-CA - Sample Rate: 8kHz,1.0.51,eada67c61bd62ec420eb017df7524d10de286fba0c2da4800516b9f62c00e78c))
+$(eval $(call Package/$(PKG_NAME)/Sounds,fr-ca-june-16000,Sound prompts,Speaker: June - Language: fr-CA - Sample Rate: 16kHz,1.0.51,f942980ad359951ef3f69a324a3299ef86cdb4f8d2c62adaf73a1b95fb39fcc6))
+$(eval $(call Package/$(PKG_NAME)/Sounds,fr-ca-june-32000,Sound prompts,Speaker: June - Language: fr-CA - Sample Rate: 32kHz,1.0.51,8966a0c4daf666018cca6d8ba0f7708e251bed952b015d0ca6a0792341fe531b))
+$(eval $(call Package/$(PKG_NAME)/Sounds,fr-ca-june-48000,Sound prompts,Speaker: June - Language: fr-CA - Sample Rate: 48kHz,1.0.51,abaea558fb5485abdd01d0b1186e03cf508f96ac90492814cc7ed4475e99a1e0))
+$(eval $(call Package/$(PKG_NAME)/Sounds,music-8000,Music on Hold,Music on Hold - Sample Rate: 8kHz,1.0.52,2491dcb92a69c629b03ea070d2483908a52e2c530dd77791f49a45a4d70aaa07))
+$(eval $(call Package/$(PKG_NAME)/Sounds,music-16000,Music on Hold,Music on Hold - Sample Rate: 16kHz,1.0.52,93e0bf31797f4847dc19a94605c039ad4f0763616b6d819f5bddbfb6dd09718a))
+$(eval $(call Package/$(PKG_NAME)/Sounds,music-32000,Music on Hold,Music on Hold - Sample Rate: 32kHz,1.0.52,4129788a638b77c5f85ff35abfcd69793d8aeb9d7833a75c74ec77355b2657a9))
+$(eval $(call Package/$(PKG_NAME)/Sounds,music-48000,Music on Hold,Music on Hold - Sample Rate: 48kHz,1.0.52,cc31cdb5b1bd653850bf6e054d963314bcf7c1706a9bf05f5a69bcbd00858d2a))
+$(eval $(call Package/$(PKG_NAME)/Sounds,pl-pl-espeak-8000,Sound prompts,Speaker: espeak - Language: pl-PL - Sample Rate: 8kHz,0.1.0,4bc7a772edde56d76f618fe4b33d71e47314cf36fc632c94a22d34dd581cbfc0))
+$(eval $(call Package/$(PKG_NAME)/Sounds,pl-pl-espeak-16000,Sound prompts,Speaker: espeak - Language: pl-PL - Sample Rate: 16kHz,0.1.0,824f28092913e3be8a042347b20bf0c425c7889de54cfa0740767c1431e66a93))
+$(eval $(call Package/$(PKG_NAME)/Sounds,pt-BR-karina-8000,Sound prompts,Speaker: Karina - Language: pr-BR - Sample Rate: 8kHz,1.0.51,ba9b5d7f97675c560823a6f94804a6716dac66efe203dd1779952518c3944a77))
+$(eval $(call Package/$(PKG_NAME)/Sounds,pt-BR-karina-16000,Sound prompts,Speaker: Karina - Language: pr-BR - Sample Rate: 16kHz,1.0.51,80432c1027f57e464cd899ed92216936cf48a3993dc1c168b1be2545b8f97aed))
+$(eval $(call Package/$(PKG_NAME)/Sounds,pt-BR-karina-32000,Sound prompts,Speaker: Karina - Language: pr-BR - Sample Rate: 32kHz,1.0.51,e80a8653585cf9a4fe9cf1c0004279602542d15894ba13f2104d990cefdee567))
+$(eval $(call Package/$(PKG_NAME)/Sounds,pt-BR-karina-48000,Sound prompts,Speaker: Karina - Language: pr-BR - Sample Rate: 48kHz,1.0.51,51ef9cac2dc4dd70d81c18f8e65bfd11de44207e8fac9961a68aa0d50d539870))
+$(eval $(call Package/$(PKG_NAME)/Sounds,ru-RU-elena-8000,Sound prompts,Speaker: Elena - Language: ru-RU - Sample Rate: 8kHz,1.0.51,d2679503eb1f4dc1716df5f8c4b5a7b721f087b17e96a02b1a92480311074c66))
+$(eval $(call Package/$(PKG_NAME)/Sounds,ru-RU-elena-16000,Sound prompts,Speaker: Elena - Language: ru-RU - Sample Rate: 16kHz,1.0.51,d2679503eb1f4dc1716df5f8c4b5a7b721f087b17e96a02b1a92480311074c66))
+$(eval $(call Package/$(PKG_NAME)/Sounds,ru-RU-elena-32000,Sound prompts,Speaker: Elena - Language: ru-RU - Sample Rate: 32kHz,1.0.51,d2679503eb1f4dc1716df5f8c4b5a7b721f087b17e96a02b1a92480311074c66))
+$(eval $(call Package/$(PKG_NAME)/Sounds,ru-RU-elena-48000,Sound prompts,Speaker: Elena - Language: ru-RU - Sample Rate: 48kHz,1.0.51,d2679503eb1f4dc1716df5f8c4b5a7b721f087b17e96a02b1a92480311074c66))
+$(eval $(call Package/$(PKG_NAME)/Sounds,sv-se-jakob-8000,Sound prompts,Speaker: Jakob - Language: sv-SE - Sample Rate: 8kHz,1.0.50,aa81c97b2954b36d5625d556d2c6764ee79d0c925284ba5ff4c60cb479936b48))
+$(eval $(call Package/$(PKG_NAME)/Sounds,sv-se-jakob-16000,Sound prompts,Speaker: Jakob - Language: sv-SE - Sample Rate: 16kHz,1.0.50,52da670c651ff598815aed655644b44b891ee158f4c67d048da90056a36ddcf6))
+$(eval $(call Package/$(PKG_NAME)/Sounds,sv-se-jakob-32000,Sound prompts,Speaker: Jakob - Language: sv-SE - Sample Rate: 32kHz,1.0.50,160de01069afa827c830595e521b53d95de4b415b48061fb843a1c4025fa17f2))
+$(eval $(call Package/$(PKG_NAME)/Sounds,sv-se-jakob-48000,Sound prompts,Speaker: Jakob - Language: sv-SE - Sample Rate: 48kHz,1.0.50,059889d75926b8e1f39e8d2c33f0e8f744a43c094bbe213a1caa9f26ae9a2799))
+$(eval $(call Package/$(PKG_NAME)/Sounds,zh-cn-sinmei-8000,Sound prompts,Speaker: Sinmei - Language: zh-CN - Sample Rate: 8kHz,1.0.51,764985f39313426ef4a0ea4dd848f05faaced37b91b2c9a22f17d3f77235fae3))
+$(eval $(call Package/$(PKG_NAME)/Sounds,zh-cn-sinmei-16000,Sound prompts,Speaker: Sinmei - Language: zh-CN - Sample Rate: 16kHz,1.0.51,d849a5818ac6630d7c572d728dcd48176a6877defd8c239cb12011528e95c2cd))
+$(eval $(call Package/$(PKG_NAME)/Sounds,zh-cn-sinmei-32000,Sound prompts,Speaker: Sinmei - Language: zh-CN - Sample Rate: 32kHz,1.0.51,903fda016d2ac053ffe6bc2d4eaf816a66c8043ddc3383d48b7b14335d9ea98e))
+$(eval $(call Package/$(PKG_NAME)/Sounds,zh-cn-sinmei-48000,Sound prompts,Speaker: Sinmei - Language: zh-CN - Sample Rate: 48kHz,1.0.51,95b9064acec13a0a32b15ea0b44dc408094b4d9dee84b183c5d9150a77e9bb23))
+$(eval $(call Package/$(PKG_NAME)/Sounds,zh-hk-sinmei-8000,Sound prompts,Speaker: Sinmei - Language: zh-HK - Sample Rate: 8kHz,1.0.51,917d08c80969bdaf30f2a63a3b69f542b143614d42c6241503ac655d13864eb0))
+$(eval $(call Package/$(PKG_NAME)/Sounds,zh-hk-sinmei-16000,Sound prompts,Speaker: Sinmei - Language: zh-HK - Sample Rate: 16kHz,1.0.51,0950e1d971b4f2ba4decd949406ccd0198fe9c686f246e175c70aafdf9783f30))
+$(eval $(call Package/$(PKG_NAME)/Sounds,zh-hk-sinmei-32000,Sound prompts,Speaker: Sinmei - Language: zh-HK - Sample Rate: 32kHz,1.0.51,97d846ab06b5c84d2c46bec64560556acbfc88eb2080bd325b2c5259a5ae80d0))
+$(eval $(call Package/$(PKG_NAME)/Sounds,zh-hk-sinmei-48000,Sound prompts,Speaker: Sinmei - Language: zh-HK - Sample Rate: 48kHz,1.0.51,bd605be7e536e11f8f67229a95513ef3f177263587c5bca75ccae647f43962a1))
diff --git a/net/freeswitch-stable/Config.in b/net/freeswitch-stable/Config.in
new file mode 100644 (file)
index 0000000..f12a62a
--- /dev/null
@@ -0,0 +1,45 @@
+menu "Advanced configuration"
+       depends on PACKAGE_freeswitch-stable
+
+config FS_STABLE_WITH_DEBUG
+       bool "Compile with debug information"
+       default n
+       help
+         Enable extra debug codepaths, like asserts and extra output. If you
+         want to get meaningful backtraces see
+         https://wiki.openwrt.org/doc/devel/debugging for starting points.
+
+config FS_STABLE_WITH_LIBEDIT
+       bool "Compile with libedit support"
+       default y
+       help
+         Compile with libedit support to enable command-line history editing
+         and curses functionality. Of course this feels nicer when interacting
+         with FreeSWITCH (without it it doesn't feel very interactive at all),
+         but it adds additional dependencies (libedit, libncursesw, terminfo).
+
+config FS_STABLE_WITH_ODBC
+       bool "Compile with ODBC support"
+       default n
+       help
+         Enable ODBC support.
+
+config FS_STABLE_WITH_PGSQL
+       bool "Compile with PGSQL support"
+       default n
+       help
+         Enable PostgreSQL support.
+
+config FS_STABLE_WITH_SRTP
+       bool "Enable SRTP"
+       default y
+       help
+         Compile with SRTP support.
+
+config FS_STABLE_WITH_ZRTP
+       bool "Enable ZRTP"
+       default n
+       help
+         Compile with ZRTP support.
+
+endmenu
diff --git a/net/freeswitch-stable/Makefile b/net/freeswitch-stable/Makefile
new file mode 100644 (file)
index 0000000..2fb12a9
--- /dev/null
@@ -0,0 +1,640 @@
+#
+# Copyright (C) 2017 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+# TODO
+#
+# - try to use system xmlrpc-c once it compiles again :-)
+# - include fs_ivrd?
+
+# NOTES
+#
+# - --disable-cpp sounds like we could get rid of the dep on libstdcpp, but it
+#   only results in switch_cpp.cpp not being compiled and there is other stuff
+#   that depends on libstdcpp.
+# - I have patched configure.ac to be able to say no to libpng and freetype. If
+#   there are errors in the future due to missing depends we'll need to poke
+#   around some more.
+
+include $(TOPDIR)/rules.mk
+
+PRG_NAME:=freeswitch
+PKG_NAME:=$(PRG_NAME)-stable
+PKG_VERSION:=1.6.17
+PKG_RELEASE:=1
+PKG_MAINTAINER:=Sebastian Kemper <sebastian_ml@gmx.net>
+
+PKG_SOURCE:=$(PRG_NAME)-$(PKG_VERSION).tar.xz
+PKG_SOURCE_URL:=https://files.$(PRG_NAME).org/releases/$(PRG_NAME)
+PKG_MD5SUM:=709b3e43362d86b9682a7db14eb344b74362493d68244dfc4e6f40218089d4e1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PRG_NAME)-$(PKG_VERSION)
+
+# configure fails without libjpeg, but it's only needed for mod_spandsp
+PKG_BUILD_DEPENDS:=libjpeg
+
+PKG_BUILD_PARALLEL:=1
+PKG_INSTALL:=1
+
+PKG_LICENSE:= \
+       AGPL-3.0 \
+       Apache-2.0 \
+       BSD-2-Clause \
+       BSD-3-Clause \
+       BSD-4-Clause \
+       BSD-like \
+       Beerware \
+       GPL-1.0+ \
+       GPL-2.0 \
+       GPL-2.0+ \
+       GPL-3.0 \
+       ISC \
+       LGPL-2.0+ \
+       LGPL-2.1 \
+       LGPL-2.1+ \
+       MIT/X11 (BSD like) \
+       MPL-1.1 \
+       OpenLDAP \
+       RSA-MD \
+       zlib-acknowledgement
+
+PKG_LICENSE_FILES:=debian/copyright
+
+FS_STABLE_DEPS_BASE:= \
+       +FS_STABLE_WITH_PGSQL:libpq \
+       +libopenssl \
+       +libuuid
+
+FS_STABLE_DEPS:= \
+       $(FS_STABLE_DEPS_BASE) \
+       +FS_STABLE_WITH_LIBEDIT:libedit \
+       +FS_STABLE_WITH_ODBC:unixodbc \
+       +libcurl \
+       +libpcre \
+       +libpthread \
+       +librt \
+       +libspeex \
+       +libspeexdsp \
+       +libstdcpp \
+       +libsqlite3 \
+       +zlib
+
+FS_STABLE_MOD_AVAILABLE:= \
+       abstraction \
+       alsa \
+       avmd \
+       blacklist \
+       callcenter \
+       cdr_csv \
+       cdr_sqlite \
+       cidlookup \
+       commands \
+       conference \
+       console \
+       curl \
+       db \
+       dialplan_asterisk \
+       dialplan_xml \
+       dingaling \
+       directory \
+       distributor \
+       dptools \
+       easyroute \
+       enum \
+       esf \
+       esl \
+       event_multicast \
+       event_socket \
+       expr \
+       fifo \
+       format_cdr \
+       fsk \
+       g723_1 \
+       g729 \
+       hash \
+       hiredis \
+       httapi \
+       http_cache \
+       json_cdr \
+       lcr \
+       local_stream \
+       logfile \
+       loopback \
+       lua \
+       native_file \
+       odbc_cdr \
+       redis \
+       rtc \
+       rtmp \
+       say_de \
+       say_en \
+       say_es \
+       say_es_ar \
+       say_fa \
+       say_fr \
+       say_he \
+       say_hr \
+       say_hu \
+       say_it \
+       say_ja \
+       say_nl \
+       say_pl \
+       say_pt \
+       say_ru \
+       say_sv \
+       say_th \
+       say_zh \
+       sndfile \
+       snom \
+       sofia \
+       spandsp \
+       spy \
+       syslog \
+       tone_stream \
+       translate \
+       valet_parking \
+       verto \
+       voicemail \
+       xml_cdr \
+       xml_rpc \
+       xml_scgi
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/$(PKG_NAME)/install/bin
+       $(INSTALL_DIR) $(1)/usr/bin
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/$(2) $(1)/usr/bin
+endef
+
+define Package/$(PKG_NAME)/install/dir
+       for dir in $$$$(shell cd $(2); find -type d -print | sed 's|^./\?||'); \
+       do \
+               $(INSTALL_DIR) $(1)/$$$$$$$$dir; \
+       done
+       for file in $$$$(shell cd $(2); find -type f -print | sed 's|^./||'); \
+       do \
+               $(INSTALL_DATA) $(2)/$$$$$$$$file $(1)/$$$$$$$$file; \
+       done
+endef
+
+define Package/$(PKG_NAME)/install/lib
+       $(INSTALL_DIR) $(1)/usr/lib
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/$(2).so* $(1)/usr/lib
+endef
+
+define Package/$(PKG_NAME)/install/mod
+       $(INSTALL_DIR) $(1)/usr/lib/$(PRG_NAME)/mod
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/$(PRG_NAME)/mod/mod_$(2).so \
+                                               $(1)/usr/lib/$(PRG_NAME)/mod
+endef
+
+define Package/$(PKG_NAME)/config
+       source "$(SOURCE)/Config.in"
+endef
+
+define Package/$(PKG_NAME)/Default
+  SUBMENU:=Telephony
+  SECTION:=net
+  CATEGORY:=Network
+  URL:=https://www.$(PRG_NAME).org
+endef
+
+define Package/$(PKG_NAME)
+$(call Package/$(PKG_NAME)/Default)
+  TITLE:=Open source telephony platform, v$(PKG_VERSION)
+  MENU:=1
+  USERID:=$(PRG_NAME)=372:$(PRG_NAME)=372
+  DEPENDS:=$(FS_STABLE_DEPS)
+  CONFLICTS:=$(PRG_NAME)
+endef
+
+define Package/$(PKG_NAME)/description
+FreeSWITCH is a scalable open source cross-platform telephony platform
+designed to route and interconnect popular communication protocols
+using audio, video, text or any other form of media.
+endef
+
+define Package/$(PKG_NAME)/conffiles
+/etc/$(PRG_NAME)
+/etc/default/$(PRG_NAME)
+/etc/init.d/$(PRG_NAME)
+endef
+
+define Package/$(PKG_NAME)/install
+$(call Package/$(PKG_NAME)/install/bin,$(1),$(PRG_NAME))
+$(call Package/$(PKG_NAME)/install/lib,$(1),lib$(PRG_NAME))
+       $(INSTALL_DIR) $(1)/etc/$(PRG_NAME)/tls
+       $(INSTALL_DIR) $(1)/usr/share/$(PRG_NAME)/fonts
+       $(INSTALL_DIR) $(1)/usr/share/$(PRG_NAME)/grammar
+       $(INSTALL_DIR) $(1)/usr/share/$(PRG_NAME)/htdocs
+       $(INSTALL_DIR) $(1)/usr/share/$(PRG_NAME)/images
+       $(INSTALL_DIR) $(1)/usr/share/$(PRG_NAME)/scripts
+       $(INSTALL_DIR) $(1)/usr/share/$(PRG_NAME)/sounds
+       $(INSTALL_DIR) $(1)/etc/default
+       $(INSTALL_CONF) ./files/$(PRG_NAME).default $(1)/etc/default/$(PRG_NAME)
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/$(PRG_NAME).init $(1)/etc/init.d/$(PRG_NAME)
+ifeq ($(CONFIG_FS_STABLE_WITH_LIBEDIT),)
+       $(SED) '/^  #procd_append_param command -nc -nf$$$$/s/#//' \
+                                               $(1)/etc/init.d/$(PRG_NAME)
+endif
+endef
+
+define Package/$(PKG_NAME)/postinst
+#!/bin/sh
+if [ -z "$${IPKG_INSTROOT}" ]; then
+  # Prevent autostart of $(PRG_NAME)
+  touch /etc/$(PRG_NAME)_disabled
+
+  echo
+  echo "o-------------------------------------------------------------------o"
+  echo "| FreeSWITCH note                                                   |"
+  echo "o-------------------------------------------------------------------o"
+  echo "| Edit /etc/default/freeswitch to change basic init configuration.  |"
+  echo "o-------------------------------------------------------------=^_^=-o"
+  echo
+fi
+exit 0
+endef
+
+define Package/$(PKG_NAME)-hotplug
+$(call Package/$(PKG_NAME)/Default)
+  TITLE:=Hotplug script
+  DEPENDS:=$(PKG_NAME)
+  PKGARCH:=all
+endef
+
+define Package/$(PKG_NAME)-hotplug/description
+This package includes a hotplug script for FreeSWITCH.
+endef
+
+define Package/$(PKG_NAME)-hotplug/install
+       $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
+       $(INSTALL_BIN) ./files/$(PRG_NAME).hotplug \
+                                       $(1)/etc/hotplug.d/iface/99-$(PRG_NAME)
+endef
+
+define Package/$(PKG_NAME)-hotplug/postinst
+#!/bin/sh
+if [ -z "$${IPKG_INSTROOT}" ]; then
+  echo
+  echo "o-------------------------------------------------------------------o"
+  echo "| FreeSWITCH hotplug note                                           |"
+  echo "o-------------------------------------------------------------------o"
+  echo "| See /etc/default/freeswitch for hotplug hints.                    |"
+  echo "o-------------------------------------------------------------=^_^=-o"
+  echo
+fi
+exit 0
+endef
+
+define Package/$(PKG_NAME)-timezones
+$(call Package/$(PKG_NAME)/Default)
+  TITLE:=Timezones file
+  DEPENDS:=$(PKG_NAME)
+  PKGARCH:=all
+endef
+
+define Package/$(PKG_NAME)-timezones/description
+This package includes a timezones file for FreeSWITCH.
+endef
+
+define Package/$(PKG_NAME)-timezones/install
+       $(INSTALL_DIR) $(1)/usr/share/$(PRG_NAME)/tz
+       $(INSTALL_DATA) \
+       $(PKG_BUILD_DIR)/conf/vanilla/autoload_configs/timezones.conf.xml \
+                                               $(1)/usr/share/$(PRG_NAME)/tz
+endef
+
+define Package/$(PKG_NAME)/Example
+define Package/$(PKG_NAME)-example-$(1)
+$(call Package/$(PKG_NAME)/Default)
+  TITLE:=Example configuration
+  DEPENDS:=$(PKG_NAME)
+  PKGARCH:=all
+endef
+define Package/$(PKG_NAME)-example-$(1)/description
+This package does not install any configuration for FreeSWITCH into
+/etc/freeswitch. The system administrator is completely responsible
+for that directory. If you install one of the example configuration
+packages, it will install the corresponding sample configuration to
+/usr/share/freeswitch/conf where you can take a look at it.
+endef
+define Package/$(PKG_NAME)-example-$(1)/install
+$(call Package/$(PKG_NAME)/install/dir,$$(1)/usr/share/$(PRG_NAME)/conf/$(1),$(PKG_BUILD_DIR)/conf/$(1))
+endef
+$$(eval $$(call BuildPackage,$(PKG_NAME)-example-$(1)))
+endef
+
+define Package/$(PKG_NAME)/Language
+define Package/$(PKG_NAME)-lang-$(1)
+$(call Package/$(PKG_NAME)/Default)
+  TITLE:=$(2) language files
+  DEPENDS:=$(PKG_NAME)
+  PKGARCH:=all
+endef
+define Package/$(PKG_NAME)-lang-$(1)/description
+This package includes the $(2) language files for FreeSWITCH.
+endef
+define Package/$(PKG_NAME)-lang-$(1)/install
+$(call Package/$(PKG_NAME)/install/dir,$$(1)/usr/share/$(PRG_NAME)/lang/$(1),$(PKG_BUILD_DIR)/conf/vanilla/lang/$(1))
+endef
+$$(eval $$(call BuildPackage,$(PKG_NAME)-lang-$(1)))
+endef
+
+define Package/$(PKG_NAME)/Module
+define Package/$(PKG_NAME)-mod-$(1)
+$(call Package/$(PKG_NAME)/Default)
+  TITLE:=$(2) module
+  DEPENDS:=$(PKG_NAME) $(4)
+endef
+define Package/$(PKG_NAME)-mod-$(1)/description
+$(subst \n,$(newline),$(3))
+endef
+define Package/$(PKG_NAME)-mod-$(1)/install
+$(call Package/$(PKG_NAME)/install/mod,$$(1),$(1))
+endef
+$$(eval $$(call BuildPackage,$(PKG_NAME)-mod-$(1)))
+endef
+
+define Package/$(PKG_NAME)/Util
+define Package/$(PKG_NAME)-util-$(1)
+$(call Package/$(PKG_NAME)/Default)
+  TITLE:=$(2) utility
+  DEPENDS:=$(PKG_NAME) $(4)
+  ifeq ($(5),y)
+  PKGARCH:=all
+  endif
+endef
+define Package/$(PKG_NAME)-util-$(1)/description
+$(subst \n,$(newline),$(3))
+endef
+define Package/$(PKG_NAME)-util-$(1)/install
+$(call Package/$(PKG_NAME)/install/bin,$$(1),$(1))
+endef
+ifeq ($(1)$(CONFIG_FS_STABLE_WITH_LIBEDIT),fs_cli)
+define Package/$(PKG_NAME)-util-$(1)/postinst
+#!/bin/sh
+if [ -z "$${IPKG_INSTROOT}" ]; then
+  echo
+  echo "o-------------------------------------------------------------------o"
+  echo "| fs_cli note                                                       |"
+  echo "o-------------------------------------------------------------------o"
+  echo "| Your FreeSWITCH was compiled without libedit support. Due to an   |"
+  echo "| interop issue it's possible that when you try to exit fs_cli with |"
+  echo "| Ctrl-D, you'll see messages flashing by and have to kill fs_cli   |"
+  echo "| manually. To avoid this you can either use Ctrl-C instead (fs_cli |"
+  echo "| needs to be started with '-i' for this to work; you could create  |"
+  echo "| an appropriate alias in /etc/profile) or type /exit, /quit or     |"
+  echo "| /bye.                                                             |"
+  echo "o-------------------------------------------------------------=^_^=-o"
+  echo
+fi
+exit 0
+endef
+endif
+$$(eval $$(call BuildPackage,$(PKG_NAME)-util-$(1)))
+endef
+
+# we neither need host-perl nor host-php
+CONFIGURE_VARS+= \
+       ac_cv_prog_PERL=false \
+       ac_cv_have_perl=no \
+       ac_cv_prog_PHP=false \
+       ac_cv_have_php=no \
+       ac_cv_prog_PHP_CONFIG=false \
+       ac_cv_have_php_config=no
+
+# The autoconf variables in this block are OK for both musl and glibc
+CONFIGURE_VARS+= \
+       ac_cv_file__dev_ptmx=yes \
+       ac_cv_file__dev_urandom=yes \
+       ac_cv_file_dbd_apr_dbd_mysql_c=no \
+       ac_cv_free_null=yes \
+       ac_cv_func_mmap_fixed_mapped=yes \
+       ac_cv_func_pthread_rwlock_init=yes \
+       ac_cv_func_sem_open=yes \
+       ac_cv_have_working_memmove=yes \
+       ac_cv_negative_eai=yes \
+       ac_cv_o_nonblock_inherited=no \
+       ac_cv_struct_rlimit=yes \
+       apr_cv_epoll=yes \
+       apr_cv_gai_addrconfig=yes \
+       apr_cv_mutex_recursive=yes \
+       apr_cv_process_shared_works=yes \
+       apr_cv_pthreads_lib=-lpthread \
+       apr_cv_tcp_nodelay_with_cork=yes \
+       apr_cv_type_rwlock_t=yes
+
+# Regarding apr_cv_mutex_robust_shared=no see
+# http://www.openwall.com/lists/musl/2016/11/26/1
+# _Don't_ remove quotes below!
+ifeq ($(CONFIG_LIBC),"musl")
+CONFIGURE_VARS+= \
+       apr_cv_mutex_robust_shared=no \
+       ac_cv_strerror_r_rc_int=yes
+else
+CONFIGURE_VARS+= \
+       apr_cv_mutex_robust_shared=yes
+endif
+
+# fs_cli
+CONFIGURE_VARS+= \
+       disable_cc=yes
+
+CONFIGURE_ARGS+= \
+       --build=$(GNU_HOST_NAME) \
+       --host=$(GNU_TARGET_NAME) \
+       --target=$(GNU_TARGET_NAME) \
+       --prefix=/usr/share/$(PRG_NAME) \
+       --bindir=/usr/bin \
+       --libdir=/usr/lib \
+       --srcdir=$(PKG_BUILD_DIR) \
+       --sysconfdir=/etc \
+       --disable-dependency-tracking \
+       --disable-libvpx \
+       --disable-libyuv \
+       --disable-static \
+       --disable-system-xmlrpc-c \
+       --enable-fhs \
+       --with-cachedir=/tmp/$(PRG_NAME)/cache \
+       --with-certsdir=/etc/$(PRG_NAME)/tls \
+       --with-dbdir=/tmp/$(PRG_NAME)/db \
+       --with-fontsdir=/usr/share/$(PRG_NAME)/fonts \
+       --with-grammardir=/usr/share/$(PRG_NAME)/grammar \
+       --with-htdocsdir=/usr/share/$(PRG_NAME)/htdocs \
+       --with-imagesdir=/usr/share/$(PRG_NAME)/images \
+       --with-logfiledir=/tmp/$(PRG_NAME)/log \
+       --with-modinstdir=/usr/lib/$(PRG_NAME)/mod \
+       --with-recordingsdir=/tmp/$(PRG_NAME)/recordings \
+       --with-rundir=/var/run/$(PRG_NAME) \
+       --with-scriptdir=/usr/share/$(PRG_NAME)/scripts \
+       --with-soundsdir=/usr/share/$(PRG_NAME)/sounds \
+       --with-storagedir=/tmp/$(PRG_NAME)/storage \
+       --without-erlang \
+       --without-freetype \
+       --without-png \
+       --without-python \
+       $(call autoconf_bool,CONFIG_FS_STABLE_WITH_LIBEDIT,core-libedit-support) \
+       $(call autoconf_bool,CONFIG_FS_STABLE_WITH_ODBC,core-odbc-support) \
+       $(call autoconf_bool,CONFIG_FS_STABLE_WITH_SRTP,srtp) \
+       $(call autoconf_bool,CONFIG_FS_STABLE_WITH_ZRTP,zrtp) \
+       $(if $(CONFIG_FS_STABLE_WITH_DEBUG),,--disable-debug) \
+       $(if $(CONFIG_FS_STABLE_WITH_ODBC),--with-odbc-lib="$(STAGING_DIR)/usr/lib") \
+       $(if $(CONFIG_FS_STABLE_WITH_ODBC),--with-odbc="$(STAGING_DIR)/usr") \
+       $(if $(CONFIG_FS_STABLE_WITH_PGSQL),--enable-core-pgsql-support,--without-pgsql)
+
+define Build/Prepare
+       $(call Build/Prepare/Default)
+       $(SED) '/^#/!s/^/#/' $(PKG_BUILD_DIR)/modules.conf
+       $(foreach m,$(FS_STABLE_MOD_AVAILABLE),
+               $(if $(CONFIG_PACKAGE_$(PKG_NAME)-mod-$(m)),
+               $(SED) '/mod_$(m)/s/^#//' $(PKG_BUILD_DIR)/modules.conf))
+endef
+
+define Build/Configure
+       find $(PKG_BUILD_DIR) -name missing -type f -exec rm {} \;
+       cd $(PKG_BUILD_DIR); $(AM_TOOL_PATHS) ./rebootstrap.sh
+       $(call Build/Configure/Default)
+endef
+
+$(eval $(call BuildPackage,$(PKG_NAME)))
+$(eval $(call BuildPackage,$(PKG_NAME)-hotplug))
+$(eval $(call BuildPackage,$(PKG_NAME)-timezones))
+
+################################
+# FreeSWITCH example configs
+# Params:
+# 1 - Package subname
+################################
+
+$(eval $(call Package/$(PKG_NAME)/Example,curl))
+$(eval $(call Package/$(PKG_NAME)/Example,insideout))
+$(eval $(call Package/$(PKG_NAME)/Example,minimal))
+$(eval $(call Package/$(PKG_NAME)/Example,rayo))
+$(eval $(call Package/$(PKG_NAME)/Example,sbc))
+$(eval $(call Package/$(PKG_NAME)/Example,softphone))
+$(eval $(call Package/$(PKG_NAME)/Example,testing))
+$(eval $(call Package/$(PKG_NAME)/Example,vanilla))
+
+################################
+# FreeSWITCH language files
+# Params:
+# 1 - Language code
+# 2 - Language
+################################
+
+$(eval $(call Package/$(PKG_NAME)/Language,de,German))
+$(eval $(call Package/$(PKG_NAME)/Language,en,English))
+$(eval $(call Package/$(PKG_NAME)/Language,es,Spanish))
+$(eval $(call Package/$(PKG_NAME)/Language,fr,French))
+$(eval $(call Package/$(PKG_NAME)/Language,he,Hebrew))
+$(eval $(call Package/$(PKG_NAME)/Language,pt,Portuguese))
+$(eval $(call Package/$(PKG_NAME)/Language,ru,Russian))
+$(eval $(call Package/$(PKG_NAME)/Language,sv,Swedish))
+
+################################
+# FreeSWITCH modules
+# Params:
+# 1 - Package subname
+# 2 - Package title
+# 3 - Module description
+# 4 - Module dependencies
+################################
+
+$(eval $(call Package/$(PKG_NAME)/Module,abstraction,API abstraction,This module provides a way to create new API functions via regex\nrewriting.,))
+$(eval $(call Package/$(PKG_NAME)/Module,alsa,ALSA endpoint,ALSA endpoint module.,+alsa-lib))
+$(eval $(call Package/$(PKG_NAME)/Module,avmd,Voicemail detection,This module attempts to determine when a voicemail system has answered\nthe call.,))
+$(eval $(call Package/$(PKG_NAME)/Module,blacklist,Blacklist helper,This module provides tools to blacklist callers.,))
+$(eval $(call Package/$(PKG_NAME)/Module,callcenter,Call center,This module implements Automated Call Distribution queues.,))
+$(eval $(call Package/$(PKG_NAME)/Module,cdr_csv,CSV CDR,CSV Call Detail Record handler.,))
+$(eval $(call Package/$(PKG_NAME)/Module,cdr_sqlite,SQLite CDR,SQLite Call Detail Record handler.,))
+$(eval $(call Package/$(PKG_NAME)/Module,cidlookup,Caller ID lookup,This module provides an API for querying caller ID name and location\ndata.,))
+$(eval $(call Package/$(PKG_NAME)/Module,commands,Commands,This module provides miscellaneous API commands.,))
+$(eval $(call Package/$(PKG_NAME)/Module,conference,Conference,This module provides multi-party conferencing.,))
+$(eval $(call Package/$(PKG_NAME)/Module,console,Console logger,Allows control over what messages get logged to the console. When\nFreeSWITCH is compiled without libedit support - this is not the\ndefault - mod_console has no effect because the init script starts\nFreeSWITCH with the console disabled to work around an\ninteroperability issue that causes high CPU load.,))
+$(eval $(call Package/$(PKG_NAME)/Module,curl,cURL,This module provides an API for making HTTP requests with cURL.,))
+$(eval $(call Package/$(PKG_NAME)/Module,db,DB,This module implements a simple db API with group support. Also can be\nused as a limit db backend.,+libdb47))
+$(eval $(call Package/$(PKG_NAME)/Module,dialplan_asterisk,Asterisk dialplan,Asterisk extensions.conf style dialplan parser.,))
+$(eval $(call Package/$(PKG_NAME)/Module,dialplan_xml,XML dialplan,Standard FreeSWITCH XML dialplan support.,))
+$(eval $(call Package/$(PKG_NAME)/Module,dingaling,Generic XMPP,Allows FreeSWITCH to be used as a client for XMPP Servers.,))
+$(eval $(call Package/$(PKG_NAME)/Module,directory,Dial-by-name directory,This module implements a dial-by-name directory IVR.,))
+$(eval $(call Package/$(PKG_NAME)/Module,distributor,Load distributor,This module implements a mechanism for performing load balancing.,))
+$(eval $(call Package/$(PKG_NAME)/Module,dptools,Dialplan tools,This module implements basic dialplan tools.,))
+$(eval $(call Package/$(PKG_NAME)/Module,easyroute,DID routing,This module does destination lookup based on DID.,))
+$(eval $(call Package/$(PKG_NAME)/Module,enum,ENUM routing,This module implements ENUM support.,+libldns))
+$(eval $(call Package/$(PKG_NAME)/Module,esf,Multicast,This module adds multi-cast support.,))
+$(eval $(call Package/$(PKG_NAME)/Module,esl,Single ESL,This module adds an API for generating one-off ESL requests.,))
+$(eval $(call Package/$(PKG_NAME)/Module,event_multicast,Multicast Event,Multicast Event System for FreeSWITCH.,))
+$(eval $(call Package/$(PKG_NAME)/Module,event_socket,Event socket,Sends events via a single socket. Needed for fs_cli.,))
+$(eval $(call Package/$(PKG_NAME)/Module,expr,Expr,This module adds expr support for expression evaluation.,))
+$(eval $(call Package/$(PKG_NAME)/Module,fifo,FIFO,This module adds a first-in first-out queue system.,))
+$(eval $(call Package/$(PKG_NAME)/Module,format_cdr,Multiformat CDR,A superset of mod_json_cdr and mod_xml_cdr.,))
+$(eval $(call Package/$(PKG_NAME)/Module,fsk,FSK,This module adds frequency-shift keying support which can be used to\nsend and receive caller ID.,))
+$(eval $(call Package/$(PKG_NAME)/Module,g723_1,G.723.1 passthrough,G.723.1 codec passthrough.,))
+$(eval $(call Package/$(PKG_NAME)/Module,g729,G.729 passthrough,G.729 codec passthrough.,))
+$(eval $(call Package/$(PKG_NAME)/Module,hash,Hash,This module provides a key-value in-memory datastore. Usable as a\nlimit backend.,))
+$(eval $(call Package/$(PKG_NAME)/Module,hiredis,Redis client,This module provides a mechanism to use Redis as a datastore.,libhiredis))
+$(eval $(call Package/$(PKG_NAME)/Module,httapi,HT-TAPI,This module provides an API for controlling the switch by responding\nto HTTP requests.,))
+$(eval $(call Package/$(PKG_NAME)/Module,http_cache,HTTP GET with caching,This module provides an API for making HTTP GET requests where the\nresult is cached.,))
+$(eval $(call Package/$(PKG_NAME)/Module,json_cdr,JSON CDR,JSON-based Call Detail Record handler.,))
+$(eval $(call Package/$(PKG_NAME)/Module,lcr,LCR,This module adds a facility for least-cost routing.,))
+$(eval $(call Package/$(PKG_NAME)/Module,local_stream,Local stream,Connects multiple channels to a looped stream.,))
+$(eval $(call Package/$(PKG_NAME)/Module,logfile,File logger,Logs FreeSWITCH output to a file.,))
+$(eval $(call Package/$(PKG_NAME)/Module,loopback,Loopback,A loopback channel driver.,))
+$(eval $(call Package/$(PKG_NAME)/Module,lua,Lua,Lua language interface for FreeSWITCH.,+liblua))
+$(eval $(call Package/$(PKG_NAME)/Module,native_file,Native file,Plays files that are already encoded in the right format.,))
+$(eval $(call Package/$(PKG_NAME)/Module,odbc_cdr,ODBC CDR,ODBC Call Detail Record handler.,))
+$(eval $(call Package/$(PKG_NAME)/Module,redis,Redis limit backend,This module provides a mechanism to use Redis as a limit backend data\nstore.,))
+$(eval $(call Package/$(PKG_NAME)/Module,rtc,Media streaming,Media streaming as used by WebRTC and mod_verto.,))
+$(eval $(call Package/$(PKG_NAME)/Module,rtmp,RTMP endpoint,RTMP endpoint support. Allows FreeSWITCH to be used from RTMP clients.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_de,German Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_en,English Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_es,Spanish Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_es_ar,Argentinian Spanish Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_fa,Persian Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_fr,French Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_he,Hebrew Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_hr,Croatian Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_hu,Hungarian Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_it,Italian Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_ja,Japanese Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_nl,Dutch Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_pl,Polish Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_pt,Portuguese Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_ru,Russian Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_sv,Swedish Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_th,Thai Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,say_zh,Chinese Say,Uses prerecorded sounds to read or say various things.,))
+$(eval $(call Package/$(PKG_NAME)/Module,sndfile,Soundfile,Adds sound format support via libsndfile.,+libsndfile))
+$(eval $(call Package/$(PKG_NAME)/Module,snom,SNOM,This module implements features specific to SNOM phones.,))
+$(eval $(call Package/$(PKG_NAME)/Module,sofia,Sofia SIP,SIP module.,))
+$(eval $(call Package/$(PKG_NAME)/Module,spandsp,SpanDSP,This module implements SpanDSP fax. It includes DSP and codec\nfunctionality.,+libjpeg +liblzma))
+$(eval $(call Package/$(PKG_NAME)/Module,spy,User Spy,This module adds the ability to monitor the audio of a channel.,))
+$(eval $(call Package/$(PKG_NAME)/Module,syslog,Syslog logger,Logs FreeSWITCH output to the syslog.,))
+$(eval $(call Package/$(PKG_NAME)/Module,tone_stream,Tone stream,Tone generation stream.,))
+$(eval $(call Package/$(PKG_NAME)/Module,translate,Number translation,This module implements number translation.,))
+$(eval $(call Package/$(PKG_NAME)/Module,valet_parking,Valet parking,This module implements the valet call parking strategy.,))
+$(eval $(call Package/$(PKG_NAME)/Module,verto,Verto,Verto signaling protocol.,))
+$(eval $(call Package/$(PKG_NAME)/Module,voicemail,Voicemail,This module provides a voicemail system.,))
+$(eval $(call Package/$(PKG_NAME)/Module,xml_cdr,XML CDR,XML Call Detail Record handler.,))
+$(eval $(call Package/$(PKG_NAME)/Module,xml_rpc,XML RPC,Allows using the webapi to control FreeSWITCH.,))
+$(eval $(call Package/$(PKG_NAME)/Module,xml_scgi,XML SCGI,SCGI XML Gateway.,))
+
+################################
+# FreeSWITCH utilities
+# Params:
+# 1 - Package subname
+# 2 - Package title
+# 3 - Utility description
+# 4 - Utility dependencies
+# 5 - Utility is a script (y/n)
+################################
+
+$(eval $(call Package/$(PKG_NAME)/Util,fs_cli,CLI,The fs_cli program is a Command-Line Interface that allows a user to\nconnect to a FreeSWITCH instance running on the local or a remote\nsystem.,$(FS_STABLE_DEPS_BASE) +FS_STABLE_WITH_LIBEDIT:libedit,n))
+$(eval $(call Package/$(PKG_NAME)/Util,fs_encode,Sound file conversion,Format conversion of sound files so the result can be used by\nmod_native_file.,$(FS_STABLE_DEPS) +$(PKG_NAME)-mod-native_file +$(PKG_NAME)-mod-sndfile +$(PKG_NAME)-mod-spandsp,n))
+$(eval $(call Package/$(PKG_NAME)/Util,gentls_cert,TLS certificate,Can be used to create TLS certificates and setup CAs.,+openssl-util,y))
+$(eval $(call Package/$(PKG_NAME)/Util,tone2wav,Sound file generation,Generates a sound file from a teletone script. The output can be in\nany format that is supported by libsndfile.,$(FS_STABLE_DEPS) +$(PKG_NAME)-mod-sndfile,n))
diff --git a/net/freeswitch-stable/files/freeswitch.default b/net/freeswitch-stable/files/freeswitch.default
new file mode 100644 (file)
index 0000000..32effa2
--- /dev/null
@@ -0,0 +1,40 @@
+### FreeSWITCH configuration ###
+
+#FS_USER=freeswitch
+#FS_GROUP=freeswitch
+
+#FS_DIR_CACHE="/tmp/freeswitch/cache"
+
+# Don't point FS_DIR_DB toward a flash drive, e.g. the flash drive of your
+# router. FreeSWITCH will be writing constantly to its databases, which would
+# degrade the flash over time. Point it to a tmpfs destination like /dev/shm or
+# /tmp instead in order for the writes to go to RAM.
+#FS_DIR_DB="/tmp/freeswitch/db"
+
+#FS_DIR_LOG="/tmp/freeswitch/log"
+#FS_DIR_RECORDINGS="/tmp/freeswitch/recordings"
+#FS_DIR_STORAGE="/tmp/freeswitch/storage"
+#FS_DIR_TEMP="/tmp/freeswitch/temp"
+
+# The following is appended to the command line when starting FreeSWITCH:
+OPTIONS="-np -nonat"
+
+### Hotplug configuration ###
+
+# Only used by the FreeSWITCH hotplug script (available in a seperate package).
+
+# Provide the interface that needs to change its state to "up" (if unset the
+# hotplug script does nothing):
+#FS_HOTPLUG_INTERFACE="wan"
+
+# You can add conditions which need to be met before FreeSWITCH is started.
+
+# Uncomment to check if something is mounted here:
+#FS_HOTPLUG_MOUNTPOINT="/mnt/usb"
+
+# Uncomment to check if ntpd is running and has set the system time:
+#FS_HOTPLUG_NTPD="check"
+
+# Uncomment to change the default timeout of 60 seconds that the hotplug script
+# waits for a condition to turn from false to true:
+#FS_HOTPLUG_TIMEOUT="20"
diff --git a/net/freeswitch-stable/files/freeswitch.hotplug b/net/freeswitch-stable/files/freeswitch.hotplug
new file mode 100644 (file)
index 0000000..4a6a2c1
--- /dev/null
@@ -0,0 +1,147 @@
+#!/bin/sh
+
+FS=freeswitch
+DEFAULT=/etc/default/$FS
+LOGGER="/usr/bin/logger -t ${FS}-hotplug"
+LOG_ERR="$LOGGER -p user.err --"
+LOG_NOTICE="$LOGGER -p user.notice --"
+LOG_WARN="$LOGGER -p user.warn --"
+
+[ "$ACTION" = ifup ] || exit 0
+
+[ -f $DEFAULT ] && . $DEFAULT
+
+[ -n "$FS_HOTPLUG_INTERFACE" ] || exit 0
+
+[ "$INTERFACE" = "$FS_HOTPLUG_INTERFACE" ] || exit 0
+
+pgrep $FS &> /dev/null
+if [ $? -eq 0 ]; then
+  $LOG_NOTICE Stopping $FS
+  /etc/init.d/$FS stop &> /dev/null
+  pgrep $FS &> /dev/null
+  if [ $? -eq 0 ]; then
+    $LOG_ERR Failed to stop $FS
+    exit 1
+  else
+    $LOG_NOTICE $FS stopped
+  fi
+fi
+
+[ "$FS_HOTPLUG_TIMEOUT" -gt 0 ] 2> /dev/null || unset FS_HOTPLUG_TIMEOUT
+TIMEOUT="${FS_HOTPLUG_TIMEOUT:-60}"
+
+# Mount condition, idea lifted from OpenWrt wiki
+[ -n "$FS_HOTPLUG_MOUNTPOINT" ] && {
+
+  if ! [ -d "$FS_HOTPLUG_MOUNTPOINT" ]; then
+    $LOG_ERR "$FS_HOTPLUG_MOUNTPOINT" not a valid mount point
+    exit 1
+  fi
+
+  mnt="$FS_HOTPLUG_MOUNTPOINT"
+  notReady=start
+  timeout=$TIMEOUT
+
+  while [ -n "$notReady" -a $timeout -gt 0 ]; do
+    if [ "$notReady" != start ]; then
+      $LOG_NOTICE "$mnt" not yet mounted, timeout in $timeout s
+      sleep 5
+      timeout=$(($timeout-5))
+    fi
+
+    notReady=
+
+    result=$(cat /proc/mounts | awk '{print $2}' | grep "^$mnt\$")
+    if [ -z "$result" ]; then
+      notReady="$mnt not ready yet"
+    fi
+  done
+
+  if [ -n "$notReady" ]; then
+    $LOG_ERR "$mnt" still not mounted
+    $LOG_ERR Not starting $FS
+    exit 1
+  else
+    $LOG_NOTICE "$mnt" mounted
+  fi
+
+}
+
+# ntpd condition
+[ -n "$FS_HOTPLUG_NTPD" ] && {
+
+  type ntpq &> /dev/null
+  [ $? -eq 0 ] || {
+    $LOG_ERR ntpq utility not found
+    exit 1
+  }
+
+  pgrep ntpd &> /dev/null || {
+    $LOG_ERR ntpd not running
+    exit 1
+  }
+
+  notReady=start
+  timeout=$TIMEOUT
+
+  result=$(uci get 'system.ntp.enabled' 2> /dev/null)
+  [ "$result" -eq 1 ] 2> /dev/null && {
+    $LOG_WARN BusyBox NTP client _and_ ntpd running
+  }
+
+  while [ -n "$notReady" -a $timeout -gt 0 ]; do
+    if [ "$notReady" != start ]; then
+      $LOG_NOTICE System time not in sync yet, timeout in $timeout s
+      sleep 5
+      timeout=$(($timeout-5))
+    fi
+
+    notReady=
+
+    result=$(ntpq -c 'timeout 300' -c 'rv 0 stratum' 2> /dev/null | \
+                    awk -F '=' '{print $2}' | grep -o -E '^[0-9]+')
+    if [ -z $result ]; then
+      $LOG_WARN Failed to extract stratum from ntpd
+      notReady="unable to extract stratum"
+    else
+      $LOG_NOTICE ntpd stratum $result
+      if [ $result -lt 16 ] 2> /dev/null; then
+        result=$(ntpq -c 'timeout 300' -c 'rv 0 offset' 2> /dev/null \
+                 | awk -F '=' '{print $2}' | grep -o -E '^-?[0-9]+')
+        if [ -z $result ]; then
+          $LOG_WARN Failed to extract offset from ntpd
+          notReady="unable to extract offset"
+        else
+          # "-0" looks stupid, so remove "-"
+          result=$(echo $result | grep -o '[0-9]*')
+          $LOG_NOTICE ntpd to system time offset \+\/\- $result ms
+          # If offset < 100 ms consider system time in sync
+          [ $result -lt 100 ] || notReady="system time not in sync yet"
+        fi
+      else
+        notReady="ntpd not in sync yet"
+      fi
+    fi
+  done
+
+  if [ -n "$notReady" ]; then
+    $LOG_ERR System time still not in sync
+    $LOG_ERR Not starting $FS
+    exit 1
+  else
+    $LOG_NOTICE System time in sync
+  fi
+
+}
+
+/etc/init.d/$FS start &> /dev/null
+# Wait a bit in order for pgrep to be able to find the new process
+sleep 1
+pgrep $FS &>/dev/null
+if [ $? -eq 0 ]; then
+  $LOG_NOTICE Started $FS due to \"ifup "$INTERFACE"\" event
+else
+  $LOG_ERR Start of $FS due to \"ifup "$INTERFACE"\" event failed
+  exit 1
+fi
diff --git a/net/freeswitch-stable/files/freeswitch.init b/net/freeswitch-stable/files/freeswitch.init
new file mode 100644 (file)
index 0000000..d55f810
--- /dev/null
@@ -0,0 +1,126 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2017 OpenWrt.org
+
+START=90
+
+USE_PROCD=1
+
+#PROCD_DEBUG=1
+
+FS=freeswitch
+DEFAULT=/etc/default/$FS
+LOGGER="/usr/bin/logger -p user.err -s -t $FS"
+OPTIONS=
+TIMEOUT=30
+
+[ -f $DEFAULT ] && . $DEFAULT
+
+fs_user="${FS_USER:-$FS}"
+fs_group="${FS_GROUP:-$FS}"
+
+fs_dir_etc="/etc/$FS"
+fs_dir_localstate="/var/lib/$FS"
+fs_dir_run="/var/run/$FS"
+
+fs_dir_cache="${FS_DIR_CACHE:-/tmp/$FS/cache}"
+fs_dir_db="${FS_DIR_DB:-/tmp/$FS/db}"
+fs_dir_log="${FS_DIR_LOG:-/tmp/$FS/log}"
+fs_dir_recordings="${FS_DIR_RECORDINGS:-/tmp/$FS/recordings}"
+fs_dir_storage="${FS_DIR_STORAGE:-/tmp/$FS/storage}"
+fs_dir_temp="${FS_DIR_TEMP:-/tmp/$FS/temp}"
+
+start_service() {
+  local dir=
+
+  if [ -f "/etc/${FS}_disabled" ]; then
+    $LOGGER File \"/etc/${FS}_disabled\" exists
+    $LOGGER Remove it once your configuration is set up
+    exit 1
+  fi
+
+  for dir in "$fs_dir_cache" "$fs_dir_db" "$fs_dir_localstate" \
+    "$fs_dir_log" "$fs_dir_recordings" "$fs_dir_run" "$fs_dir_storage" \
+    "$fs_dir_temp"
+  do
+    [ -n "$dir" ] && {
+      mkdir -p "$dir"
+      chown "$fs_user":"$fs_group" "$dir"
+      chmod 750 "$dir"
+    }
+  done
+
+  #[ -d "$fs_dir_etc" ] && {
+  #  find "$fs_dir_etc" -type f -exec chown root:"$fs_group" {} \;
+  #  find "$fs_dir_etc" -type f -exec chmod 640 {} \;
+  #}
+
+  procd_open_instance
+  # starting with full path seems cleaner judging by 'ps' output
+  procd_set_param command /usr/bin/$FS
+  # need to specify all or none of -conf, -log, and -db
+  procd_append_param command -cache "$fs_dir_cache" -conf \
+    "$fs_dir_etc" -db "$fs_dir_db" -log "$fs_dir_log" -recordings \
+    "$fs_dir_recordings" -run "$fs_dir_run" -storage "$fs_dir_storage" \
+    -temp "$fs_dir_temp"
+  procd_append_param command -c
+  # -nc -nf: workaround for interop issue (which causes high load)
+  #procd_append_param command -nc -nf
+  procd_append_param command $OPTIONS
+  procd_set_param user "$fs_user"
+  # forward stdout of the command to logd
+  #procd_set_param stdout 1
+  # same for stderr
+  procd_set_param stderr 1
+  procd_close_instance
+}
+
+stop_service() {
+  local retval=
+  local mypid=
+  local timeout=$TIMEOUT
+
+  pgrep $FS &> /dev/null
+  [ $? -ne 0 ] && exit 0
+
+  [ -f "$fs_dir_run"/${FS}.pid ]
+  retval=$?
+
+  # init script could find itself in a scenario where FS was started
+  # very recently, so make it wait a while for a pid file to appear
+  while [ $retval -ne 0 -a $timeout -gt 0 ]; do
+    sleep 1
+    [ -f "$fs_dir_run"/${FS}.pid ]
+    retval=$?
+    timeout=$(($timeout-1))
+  done
+
+  [ $retval -eq 0 ] || {
+    $LOGGER PID file does not exist
+    exit 1
+  }
+
+  mypid=$(cat "$fs_dir_run"/${FS}.pid)
+
+  [ "$mypid" -gt 1 ] 2> /dev/null || {
+    $LOGGER PID file contains garbage
+    exit 1
+  }
+
+  timeout=$TIMEOUT
+  kill $mypid
+  pgrep $FS | grep -w $mypid &>/dev/null
+  retval=$?
+
+  while [ $retval -eq 0 -a $timeout -gt 0 ]; do
+    sleep 10
+    pgrep $FS | grep -w $mypid &>/dev/null
+    retval=$?
+    [ $retval -eq 0 ] && kill $mypid 2>/dev/null
+    timeout=$(($timeout-10))
+  done
+
+  [ $retval -ne 1 ] && {
+    $LOGGER Failed to stop $FS
+    exit 1
+  }
+}
diff --git a/net/freeswitch-stable/patches/010-fix-zrtp-cflags.patch b/net/freeswitch-stable/patches/010-fix-zrtp-cflags.patch
new file mode 100644 (file)
index 0000000..00b959f
--- /dev/null
@@ -0,0 +1,11 @@
+--- a/libs/libzrtp/configure.ac
++++ b/libs/libzrtp/configure.ac
+@@ -34,7 +34,7 @@ esac
+ AM_INIT_AUTOMAKE
+ AX_PREFIX_CONFIG_H(include/zrtp_config_unix.h,ZRTP,config/config.h)
+-CFLAGS="$CFLAGS -std=c99 -O2 -g3 -Wall -Wextra -Wno-unused-parameter -fno-strict-aliasing -fPIC -DZRTP_AUTOMAKE=1"
++CFLAGS="$CFLAGS -std=c99 -Wall -Wextra -Wno-unused-parameter -fno-strict-aliasing -fPIC -DZRTP_AUTOMAKE=1"
+ # Configuring external libraries
+ echo "========================= configuring bnlib =============================="
diff --git a/net/freeswitch-stable/patches/030-fix-configure-ac.patch b/net/freeswitch-stable/patches/030-fix-configure-ac.patch
new file mode 100644 (file)
index 0000000..4e73092
--- /dev/null
@@ -0,0 +1,42 @@
+--- a/configure.ac
++++ b/configure.ac
+@@ -256,30 +256,6 @@ AX_COMPILER_VENDOR
+ # Set CC_FOR_BUILD
+ if test "x${cross_compiling}" = "xyes"; then
+     CC_FOR_BUILD=${CC_FOR_BUILD-gcc}
+-    case "$host" in
+-       arm*-linux-gnueabi*|arm*-*-linux-gnueabi*)
+-              # spandsp modem
+-              ac_cv_file__dev_ptmx=yes
+-              # libjs
+-              export ac_cv_va_copy=yes
+-              # srtp
+-              export ac_cv_file__dev_urandom=yes
+-              # rpl_malloc
+-              export ac_cv_func_realloc_0_nonnull=yes
+-              export ac_cv_func_malloc_0_nonnull=yes
+-              # apr
+-              export ac_cv_func_setpgrp_void=yes
+-              export ac_cv_file__dev_zero=yes
+-              export apr_cv_tcp_nodelay_with_cork=yes
+-              export ac_cv_file_dbd_apr_dbd_mysql_c=no
+-              export ac_cv_sizeof_ssize_t=4
+-              export apr_cv_mutex_recursive=yes
+-              export ac_cv_func_pthread_rwlock_init=yes
+-              export apr_cv_type_rwlock_t=yes
+-              export apr_cv_process_shared_works=yes
+-              export apr_cv_mutex_robust_shared=yes
+-       ;;
+-    esac
+ else
+     CC_FOR_BUILD='$(CC)'
+ fi
+@@ -667,7 +643,7 @@ AC_ARG_ENABLE(core-pgsql-pkgconfig,
+       [AS_HELP_STRING([--disable-core-pgsql-pkgconfig], [Use pg_config to get PGQSL build options])],[enable_core_pgsql_pkgconfig="$enableval"],[enable_core_pgsql_pkgconfig="yes"])
+ if test x"$enable_core_pgsql_support" = x"yes" ; then
+-  AC_PATH_PROG([PG_CONFIG], [pg_config], [no])
++  AC_PATH_PROG([PG_CONFIG], [pg_config], [no], ["${STAGING_DIR}"/usr/bin])
+   AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no])
+     if test "$PKG_CONFIG" = "no" \
+        || test x"$enable_core_pgsql_pkgconfig" = x"no" \
diff --git a/net/freeswitch-stable/patches/110-apr-add-cache-for-strerror_r.patch b/net/freeswitch-stable/patches/110-apr-add-cache-for-strerror_r.patch
new file mode 100644 (file)
index 0000000..a753697
--- /dev/null
@@ -0,0 +1,90 @@
+--- a/libs/apr-util/build/apr_common.m4
++++ b/libs/apr-util/build/apr_common.m4
+@@ -514,8 +514,9 @@ dnl  string.
+ dnl
+ dnl
+ AC_DEFUN([APR_CHECK_STRERROR_R_RC],[
+-AC_MSG_CHECKING(for type of return code from strerror_r)
+-AC_TRY_RUN([
++AC_CACHE_CHECK([whether return code from strerror_r has type int],
++[ac_cv_strerror_r_rc_int],
++[AC_TRY_RUN([
+ #include <errno.h>
+ #include <string.h>
+ #include <stdio.h>
+@@ -531,14 +532,10 @@ int main(void)
+ }], [
+     ac_cv_strerror_r_rc_int=yes ], [
+     ac_cv_strerror_r_rc_int=no ], [
+-    ac_cv_strerror_r_rc_int=no ] )
++    ac_cv_strerror_r_rc_int=no ] ) ] )
+ if test "x$ac_cv_strerror_r_rc_int" = xyes; then
+   AC_DEFINE(STRERROR_R_RC_INT, 1, [Define if strerror returns int])
+-  msg="int"
+-else
+-  msg="pointer"
+ fi
+-AC_MSG_RESULT([$msg])
+ ] )
+ dnl
+--- a/libs/apr/build/apr_common.m4
++++ b/libs/apr/build/apr_common.m4
+@@ -514,8 +514,9 @@ dnl  string.
+ dnl
+ dnl
+ AC_DEFUN([APR_CHECK_STRERROR_R_RC],[
+-AC_MSG_CHECKING(for type of return code from strerror_r)
+-AC_TRY_RUN([
++AC_CACHE_CHECK([whether return code from strerror_r has type int],
++[ac_cv_strerror_r_rc_int],
++[AC_TRY_RUN([
+ #include <errno.h>
+ #include <string.h>
+ #include <stdio.h>
+@@ -531,14 +532,10 @@ int main(void)
+ }], [
+     ac_cv_strerror_r_rc_int=yes ], [
+     ac_cv_strerror_r_rc_int=no ], [
+-    ac_cv_strerror_r_rc_int=no ] )
++    ac_cv_strerror_r_rc_int=no ] ) ] )
+ if test "x$ac_cv_strerror_r_rc_int" = xyes; then
+   AC_DEFINE(STRERROR_R_RC_INT, 1, [Define if strerror returns int])
+-  msg="int"
+-else
+-  msg="pointer"
+ fi
+-AC_MSG_RESULT([$msg])
+ ] )
+ dnl
+--- a/libs/unimrcp/build/acmacros/apr_common.m4
++++ b/libs/unimrcp/build/acmacros/apr_common.m4
+@@ -526,8 +526,9 @@ dnl  string.
+ dnl
+ dnl
+ AC_DEFUN([APR_CHECK_STRERROR_R_RC], [
+-AC_MSG_CHECKING(for type of return code from strerror_r)
+-AC_TRY_RUN([
++AC_CACHE_CHECK([whether return code from strerror_r has type int],
++[ac_cv_strerror_r_rc_int],
++[AC_TRY_RUN([
+ #include <errno.h>
+ #include <string.h>
+ #include <stdio.h>
+@@ -543,14 +544,10 @@ main()
+ }], [
+     ac_cv_strerror_r_rc_int=yes ], [
+     ac_cv_strerror_r_rc_int=no ], [
+-    ac_cv_strerror_r_rc_int=no ] )
++    ac_cv_strerror_r_rc_int=no ] ) ] )
+ if test "x$ac_cv_strerror_r_rc_int" = xyes; then
+   AC_DEFINE(STRERROR_R_RC_INT, 1, [Define if strerror returns int])
+-  msg="int"
+-else
+-  msg="pointer"
+ fi
+-AC_MSG_RESULT([$msg])
+ ] )
+ dnl
diff --git a/net/freeswitch-stable/patches/120-fix-copts.diff b/net/freeswitch-stable/patches/120-fix-copts.diff
new file mode 100644 (file)
index 0000000..a8ca5d0
--- /dev/null
@@ -0,0 +1,226 @@
+--- a/configure.ac
++++ b/configure.ac
+@@ -1959,7 +1959,13 @@ AC_SUBST(OUR_DISABLED_INSTALL_MODS)
+ AC_SUBST(OUR_DISABLED_UNINSTALL_MODS)
+ AC_SUBST(AM_MAKEFLAGS)
+-ac_configure_args="$ac_configure_args --with-modinstdir=${modulesdir} CONFIGURE_CFLAGS='$CFLAGS $CPPFLAGS' CONFIGURE_CXXFLAGS='$CXXFLAGS $CPPFLAGS' CONFIGURE_LDFLAGS='$LDFLAGS' "
++ac_configure_args="$ac_configure_args --with-modinstdir=${modulesdir}"
++
++case $host in
++   *-darwin*)
++        ac_configure_args="$ac_configure_args CONFIGURE_CFLAGS='$CFLAGS $CPPFLAGS' CONFIGURE_CXXFLAGS='$CXXFLAGS $CPPFLAGS' CONFIGURE_LDFLAGS='$LDFLAGS' "
++       ;;
++esac
+ #     --prefix='$prefix' --exec_prefix='$exec_prefix' --libdir='$libdir' --libexecdir='$libexecdir' --bindir='$bindir' --sbindir='$sbindir' \
+ #     --localstatedir='$localstatedir' --datadir='$datadir'"
+--- a/libs/apr-util/configure.ac
++++ b/libs/apr-util/configure.ac
+@@ -20,9 +20,13 @@ dnl Generate ./config.nice for reproduci
+ dnl 
+ APR_CONFIG_NICE(config.nice)
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ dnl # Some initial steps for configuration.  We setup the default directory
+ dnl # and which files are to be configured.
+--- a/libs/apr/configure.ac
++++ b/libs/apr/configure.ac
+@@ -20,9 +20,13 @@ sinclude(build/apr_hints.m4)
+ sinclude(build/libtool.m4)
+ sinclude(build/ltsugar.m4)
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ dnl Hard-coded inclusion at the tail end of apr_private.h:
+ AH_BOTTOM([
+--- a/libs/broadvoice/configure.ac
++++ b/libs/broadvoice/configure.ac
+@@ -22,9 +22,13 @@
+ AC_INIT([broadvoice],[0.1.0])
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ m4_include(config/ax_compiler_vendor.m4)
+ m4_include(config/ax_check_real_file.m4)
+--- a/libs/iksemel/configure.ac
++++ b/libs/iksemel/configure.ac
+@@ -6,9 +6,13 @@ AC_CONFIG_SRCDIR([configure.ac])
+ AM_INIT_AUTOMAKE
+ AC_CONFIG_HEADERS(include/config.h)
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ AC_CANONICAL_HOST
+--- a/libs/ilbc/configure.ac
++++ b/libs/ilbc/configure.ac
+@@ -22,9 +22,13 @@
+ AC_INIT([ilbc], [0.0.1])
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ AC_DEFUN([AX_COMPILER_VENDOR],
+ [
+--- a/libs/libdingaling/configure.ac
++++ b/libs/libdingaling/configure.ac
+@@ -8,9 +8,13 @@ AM_INIT_AUTOMAKE
+ AC_CONFIG_SRCDIR([src])
+ AC_CONFIG_HEADERS([src/config.h])
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ #Set default language
+ AC_LANG_C
+--- a/libs/libsndfile/configure.ac
++++ b/libs/libsndfile/configure.ac
+@@ -15,9 +15,13 @@ AC_CANONICAL_TARGET([])
+ AC_CONFIG_MACRO_DIR([M4])
+ AC_CONFIG_HEADERS([src/config.h])
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ AM_INIT_AUTOMAKE
+ AC_SUBST(ACLOCAL_AMFLAGS, "-I M4")
+--- a/libs/sofia-sip/configure.ac
++++ b/libs/sofia-sip/configure.ac
+@@ -13,9 +13,13 @@ dnl ---------------------------
+ dnl update both the version for AC_INIT and the LIBSOFIA_SIP_UA_MAJOR_MINOR
+ AC_INIT([sofia-sip], [1.12.10devel])
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ AC_CONFIG_SRCDIR([libsofia-sip-ua/sip/sofia-sip/sip.h])
+ AC_CONFIG_MACRO_DIR([m4])
+--- a/libs/spandsp/configure.ac
++++ b/libs/spandsp/configure.ac
+@@ -21,9 +21,13 @@
+ AC_PREREQ([2.59])
+ AC_INIT([spandsp], [1.99.0])
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ SPANDSP_LT_CURRENT=3
+ SPANDSP_LT_REVISION=0
+--- a/libs/srtp/configure.ac
++++ b/libs/srtp/configure.ac
+@@ -3,9 +3,13 @@ AC_INIT(srtp, 1.4.2, mcgrew@cisco.com)
+ AC_CONFIG_AUX_DIR(build)
+ AM_INIT_AUTOMAKE
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ #Set default language
+ AC_LANG_C
+--- a/libs/tiff-4.0.2/configure.ac
++++ b/libs/tiff-4.0.2/configure.ac
+@@ -32,9 +32,13 @@ AC_LANG(C)
+ AC_PROG_LIBTOOL
+ m4_include(m4/acinclude.m4)
+-CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
+-CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
+-LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++case $host in
++   *-darwin*)
++        CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
++        CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
++        LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
++       ;;
++esac
+ dnl Compute the canonical host (run-time) system type variable
+ AC_CANONICAL_HOST
diff --git a/net/freeswitch-stable/patches/130-fix-iksemel-copts.diff b/net/freeswitch-stable/patches/130-fix-iksemel-copts.diff
new file mode 100644 (file)
index 0000000..005b7a4
--- /dev/null
@@ -0,0 +1,9 @@
+--- a/libs/iksemel/src/Makefile.am
++++ b/libs/iksemel/src/Makefile.am
+@@ -25,5 +25,5 @@ libiksemel_la_SOURCES = \
+       base64.c
+ libiksemel_la_LDFLAGS = -version-info 4:0:1 -no-undefined
+-libiksemel_la_CFLAGS = $(CFLAGS) $(LIBGNUTLS_CFLAGS)  
++libiksemel_la_CFLAGS = $(LIBGNUTLS_CFLAGS)  
+ libiksemel_la_LIBADD = $(LIBGNUTLS_LIBS)  
index 56af9ec4e9fcb81d0c70f31612b09a5ff4ca463c..60b8c59d14d1966ca1375bf738fc14da72cec3ec 100644 (file)
@@ -1,6 +1,7 @@
 #
-# Copyright (C) 2016 OpenWrt.org
+# Copyright (C) 2006-2017 OpenWrt.org
 # Copyright (C) 2013-2016 CESNET,z.s.p.o.
+# Copyright (C) 2017 Jiri Slachta
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=kamailio4
-PKG_VERSION:=4.4.0
+PKG_VERSION:=4.4.5
 PKG_RELEASE:=1
 
 PKG_SOURCE_URL:=http://www.kamailio.org/pub/kamailio/$(PKG_VERSION)/src/
 PKG_SOURCE:=kamailio-$(PKG_VERSION)$(PKG_VARIANT)_src.tar.gz
-PKG_MD5SUM:=e9fa206f67346a6b01c015d76ec2db9d
+PKG_HASH:=fd7ced2268b4fbc7763b415341a05034eaff68a666cbf7507c707ac9199c3012
 PKG_USE_MIPS16:=0
 
 PKG_LICENSE:=GPL-2.0+
index 2ea697af205e144def1c3ba474cd890b6aa33771..c19761db67b7a8d279325eca212ab7817b28096f 100644 (file)
@@ -8,7 +8,7 @@
  #
 --- a/utils/kamctl/kamctlrc
 +++ b/utils/kamctl/kamctlrc
-@@ -147,3 +147,6 @@
+@@ -145,3 +145,6 @@
  ## Extra start options - default is: not set
  # example: start Kamailio with 64MB share memory: STARTOPTIONS="-m 64"
  # STARTOPTIONS=
index 111b2c35995d5a289174eb42bc13b8b7c6521b3e..bfca8b9f46017ab686f8fd287f48f79782014d99 100644 (file)
@@ -12,7 +12,7 @@ RELEASEVER:=5.5.0
 
 PKG_NAME:=yate
 PKG_VERSION:=$(RELEASEVER)-1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://yate.null.ro/tarballs/yate5/
@@ -111,7 +111,6 @@ CONFIGURE_ARGS+= \
        --with-mysql="$(STAGING_DIR)/usr" \
        --without-wphwec \
        --without-libgsm \
-       --with-libspeex="$(STAGING_DIR)/usr/include" \
        --without-amrnb \
        --with-spandsp="$(STAGING_DIR)/usr/include" \
        --without-pwlib \
@@ -262,7 +261,6 @@ $(eval $(call BuildPlugin,rmanager,,Yate Remote Management,))
 $(eval $(call BuildPlugin,sigtransport,server,SIGTRAN (SS7 over IP) connection provider,))
 $(eval $(call BuildPlugin,sip_cnam_lnp,sip,Query CNAM and LNP databases using SIP INVITE,))
 $(eval $(call BuildPlugin,sipfeatures,server,SIP Features (SUBSCRIBE/NOTIFY),))
-$(eval $(call BuildPlugin,speexcodec,,Speex Codec,+libspeex))
 $(eval $(call BuildPlugin,subscription,server,Subcription handler and presence notifier,))
 $(eval $(call BuildPlugin,tdmcard,server,TDM Cards Signalling and Data Driver,@BROKEN)) # Missing TDM libraries
 $(eval $(call BuildPlugin,tonedetect,,Detectors for Various Tones,))