2004-06-21 19:28:34 +00:00
|
|
|
/*
|
2005-09-15 15:44:26 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2004-06-21 19:28:34 +00:00
|
|
|
*
|
2005-01-21 07:06:25 +00:00
|
|
|
* Copyright (C) 2004 - 2005 Steve Rodgers
|
2004-06-21 19:28:34 +00:00
|
|
|
*
|
|
|
|
* Steve Rodgers <hwstar@rodgers.sdcoxmail.com>
|
|
|
|
*
|
2005-09-15 15:44:26 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2004-06-21 19:28:34 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-15 15:44:26 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2012-09-05 15:56:33 +00:00
|
|
|
*
|
2008-02-07 20:42:59 +00:00
|
|
|
* \brief Central Station Alarm receiver for Ademco Contact ID
|
2005-11-06 15:09:47 +00:00
|
|
|
* \author Steve Rodgers <hwstar@rodgers.sdcoxmail.com>
|
2008-02-07 20:42:59 +00:00
|
|
|
*
|
|
|
|
* *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
|
2004-06-21 19:28:34 +00:00
|
|
|
*
|
2006-06-07 18:54:56 +00:00
|
|
|
* Use at your own risk. Please consult the GNU GPL license document included with Asterisk. *
|
2004-06-21 19:28:34 +00:00
|
|
|
*
|
|
|
|
* *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
|
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2008-02-07 20:42:59 +00:00
|
|
|
*/
|
|
|
|
|
2012-10-14 21:45:16 +00:00
|
|
|
/*! \li \ref app_alarmreceiver.c uses the configuration file \ref alarmreceiver.conf
|
2012-10-01 23:22:50 +00:00
|
|
|
* \addtogroup configuration_file Configuration Files
|
|
|
|
*/
|
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
/*!
|
2012-10-01 23:22:50 +00:00
|
|
|
* \page alarmreceiver.conf alarmreceiver.conf
|
|
|
|
* \verbinclude alarmreceiver.conf.sample
|
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>extended</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/translate.h"
|
|
|
|
#include "asterisk/app.h"
|
|
|
|
#include "asterisk/dsp.h"
|
|
|
|
#include "asterisk/config.h"
|
|
|
|
#include "asterisk/localtime.h"
|
|
|
|
#include "asterisk/callerid.h"
|
|
|
|
#include "asterisk/astdb.h"
|
2006-01-11 22:41:34 +00:00
|
|
|
#include "asterisk/utils.h"
|
2012-09-05 15:56:33 +00:00
|
|
|
#include "asterisk/indications.h"
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
#include "asterisk/format_cache.h"
|
2004-06-21 19:28:34 +00:00
|
|
|
|
|
|
|
#define ALMRCV_CONFIG "alarmreceiver.conf"
|
2012-10-17 19:02:46 +00:00
|
|
|
#define UNKNOWN_FORMAT "UNKNOWN_FORMAT"
|
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
#define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID"
|
2012-10-17 19:02:46 +00:00
|
|
|
/*
|
|
|
|
AAAA _ID_ P CCC XX ZZZ S
|
|
|
|
|
|
|
|
where AAAA is the account number, _ID_ is 18 or 98, P is the pin status (alarm or restore), CCC
|
|
|
|
is the alarm code which is pre-defined by Ademco (but you may be able to reprogram it in the panel), XX
|
|
|
|
is the dialer group, partition or area number, ZZZ is the zone or user number and S is the checksum
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ADEMCO_EXPRESS_4_1 "ADEMCO_EXPRESS_4_1"
|
|
|
|
/*
|
|
|
|
AAAA _ID_ C S
|
|
|
|
|
|
|
|
where AAAA is the account number, _ID_ is 17, C is the alarm code and S is the checksum.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ADEMCO_EXPRESS_4_2 "ADEMCO_EXPRESS_4_2"
|
|
|
|
/*
|
|
|
|
AAAA _ID_ C Z S
|
|
|
|
|
|
|
|
where AAAA is the account number, _ID_ is 27, C is the alarm code, Z is the zone or user number and S is the checksum.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ADEMCO_HIGH_SPEED "ADEMCO_HIGH_SPEED"
|
|
|
|
/*
|
|
|
|
AAAA _ID_ PPPP PPPP X S
|
|
|
|
|
|
|
|
where AAAA is the account number, _ID_ is 55, PPPP PPPP is the status of each zone, X
|
|
|
|
is a special digit which describes the type of information in the PPPP PPPP fields and S is checksum.
|
|
|
|
Each P field contains one of the following values:
|
|
|
|
1 new alarm 3 new restore 5 normal
|
|
|
|
2 new opening 4 new closing 6 outstanding
|
|
|
|
The X field contains one of the following values:
|
|
|
|
0 AlarmNet messages
|
|
|
|
1 ambush or duress
|
|
|
|
2 opening by user (the first P field contains the user number)
|
|
|
|
3 bypass (the P fields indicate which zones are bypassed)
|
|
|
|
4 closing by user (the first P field contain the user number)
|
|
|
|
5 trouble (the P fields contain which zones are in trouble)
|
|
|
|
6 system trouble
|
|
|
|
7 normal message (the P fields indicate zone status)
|
|
|
|
8 low battery (the P fields indicate zone status)
|
|
|
|
9 test (the P fields indicate zone status)
|
|
|
|
*/
|
|
|
|
#define ADEMCO_SUPER_FAST "ADEMCO_SUPER_FAST"
|
|
|
|
/*
|
|
|
|
AAAA _ID_ PPPP PPPP X
|
|
|
|
where AAA is the account number, _ID_ is 56
|
|
|
|
*/
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
#define ADEMCO_MSG_TYPE_1 "18"
|
|
|
|
#define ADEMCO_MSG_TYPE_2 "98"
|
2012-10-17 19:02:46 +00:00
|
|
|
#define ADEMCO_MSG_TYPE_3 "17"
|
|
|
|
#define ADEMCO_MSG_TYPE_4 "27"
|
|
|
|
#define ADEMCO_MSG_TYPE_5 "55"
|
|
|
|
#define ADEMCO_MSG_TYPE_6 "56"
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
#define ADEMCO_AUDIO_CALL_NEXT "606"
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char digit;
|
|
|
|
char weight;
|
|
|
|
} digits_mapping[] = { {'0', 10}, {'1', 1} , {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5},
|
|
|
|
{'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'*', 11}, {'#', 12},
|
|
|
|
{'A', 13}, {'B', 14}, {'C', 15} };
|
2004-06-21 19:28:34 +00:00
|
|
|
|
|
|
|
struct event_node{
|
|
|
|
char data[17];
|
|
|
|
struct event_node *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct event_node event_node_t;
|
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
struct timeval call_start_time;
|
|
|
|
|
2009-06-07 14:55:51 +00:00
|
|
|
static const char app[] = "AlarmReceiver";
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<application name="AlarmReceiver" language="en_US">
|
|
|
|
<synopsis>
|
2008-11-05 14:37:07 +00:00
|
|
|
Provide support for receiving alarm reports from a burglar or fire alarm panel.
|
2008-11-01 21:10:07 +00:00
|
|
|
</synopsis>
|
|
|
|
<syntax />
|
|
|
|
<description>
|
|
|
|
<para>This application should be called whenever there is an alarm panel calling in to dump its events.
|
2008-11-05 14:37:07 +00:00
|
|
|
The application will handshake with the alarm panel, and receive events, validate them, handshake them,
|
|
|
|
and store them until the panel hangs up. Once the panel hangs up, the application will run the system
|
|
|
|
command specified by the eventcmd setting in <filename>alarmreceiver.conf</filename> and pipe the
|
|
|
|
events to the standard input of the application.
|
|
|
|
The configuration file also contains settings for DTMF timing, and for the loudness of the
|
|
|
|
acknowledgement tones.</para>
|
2012-10-17 19:02:46 +00:00
|
|
|
<note><para>Few Ademco DTMF signalling formats are detected automaticaly: Contact ID, Express 4+1,
|
|
|
|
Express 4+2, High Speed and Super Fast.</para></note>
|
2012-10-18 20:31:05 +00:00
|
|
|
<para>The application is affected by the following variables:</para>
|
|
|
|
<variablelist>
|
|
|
|
<variable name="ALARMRECEIVER_CALL_LIMIT">
|
|
|
|
<para>Maximum call time, in milliseconds.</para>
|
|
|
|
<para>If set, this variable causes application to exit after the specified time.</para>
|
|
|
|
</variable>
|
|
|
|
<variable name="ALARMRECEIVER_RETRIES_LIMIT">
|
|
|
|
<para>Maximum number of retries per call.</para>
|
|
|
|
<para>If set, this variable causes application to exit after the specified number of messages.</para>
|
|
|
|
</variable>
|
|
|
|
</variablelist>
|
2008-11-01 21:10:07 +00:00
|
|
|
</description>
|
2008-11-05 14:37:07 +00:00
|
|
|
<see-also>
|
|
|
|
<ref type="filename">alarmreceiver.conf</ref>
|
|
|
|
</see-also>
|
2008-11-01 21:10:07 +00:00
|
|
|
</application>
|
|
|
|
***/
|
2004-06-21 19:28:34 +00:00
|
|
|
|
|
|
|
/* Config Variables */
|
|
|
|
static int fdtimeout = 2000;
|
2008-02-07 20:42:59 +00:00
|
|
|
static int sdtimeout = 200;
|
2012-10-17 19:02:46 +00:00
|
|
|
static int answait = 1250;
|
2004-06-21 19:28:34 +00:00
|
|
|
static int toneloudness = 4096;
|
|
|
|
static int log_individual_events = 0;
|
2012-10-17 19:02:46 +00:00
|
|
|
static int no_group_meta = 0;
|
2004-06-21 19:28:34 +00:00
|
|
|
static char event_spool_dir[128] = {'\0'};
|
|
|
|
static char event_app[128] = {'\0'};
|
|
|
|
static char db_family[128] = {'\0'};
|
|
|
|
static char time_stamp_format[128] = {"%a %b %d, %Y @ %H:%M:%S %Z"};
|
|
|
|
|
|
|
|
/* Misc variables */
|
|
|
|
static char event_file[14] = "/event-XXXXXX";
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief Attempt to access a database variable and increment it
|
|
|
|
*
|
|
|
|
* \note Only if the user defined db-family in alarmreceiver.conf
|
|
|
|
*
|
|
|
|
* The alarmreceiver app will write statistics to a few variables
|
|
|
|
* in this family if it is defined. If the new key doesn't exist in the
|
|
|
|
* family, then create it and set its value to 1.
|
|
|
|
*
|
|
|
|
* \param key A database key to increment
|
|
|
|
* \return Nothing
|
|
|
|
*/
|
|
|
|
static void database_increment(char *key)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
|
|
|
unsigned v;
|
|
|
|
char value[16];
|
2012-09-05 15:56:33 +00:00
|
|
|
|
|
|
|
if (ast_strlen_zero(db_family)) {
|
|
|
|
return; /* If not defined, don't do anything */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_db_get(db_family, key, value, sizeof(value) - 1)) {
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: Creating database entry %s and setting to 1\n", key);
|
2004-06-21 19:28:34 +00:00
|
|
|
/* Guess we have to create it */
|
2012-09-05 15:56:33 +00:00
|
|
|
ast_db_put(db_family, key, "1");
|
2004-06-21 19:28:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-05 15:56:33 +00:00
|
|
|
|
2009-08-10 19:20:57 +00:00
|
|
|
sscanf(value, "%30u", &v);
|
2004-06-21 19:28:34 +00:00
|
|
|
v++;
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2008-02-05 23:00:15 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: New value for %s: %u\n", key, v);
|
2004-07-14 07:22:30 +00:00
|
|
|
snprintf(value, sizeof(value), "%u", v);
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if (ast_db_put(db_family, key, value)) {
|
2008-02-05 23:00:15 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: database_increment write error\n");
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief Receive a fixed length DTMF string.
|
|
|
|
*
|
|
|
|
* \note Doesn't give preferential treatment to any digit,
|
|
|
|
* \note allow different timeout values for the first and all subsequent digits
|
|
|
|
*
|
|
|
|
* \param chan Asterisk Channel
|
|
|
|
* \param digit_string Digits String
|
2012-10-16 19:26:20 +00:00
|
|
|
* \param buf_size The size of the Digits String buffer
|
2012-10-17 19:02:46 +00:00
|
|
|
* \param expected Digits expected for this message type
|
|
|
|
* \param received Pointer to number of digits received so far
|
2012-09-05 15:56:33 +00:00
|
|
|
*
|
|
|
|
* \retval 0 if all digits were successfully received
|
|
|
|
* \retval 1 if a timeout occurred
|
|
|
|
* \retval -1 if the caller hung up or on channel errors
|
|
|
|
*/
|
2012-10-17 19:02:46 +00:00
|
|
|
static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int buf_size, int expected, int *received)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
2012-09-05 15:56:33 +00:00
|
|
|
int rtn = 0;
|
2004-06-21 19:28:34 +00:00
|
|
|
int r;
|
|
|
|
struct ast_frame *f;
|
2005-07-15 23:00:47 +00:00
|
|
|
struct timeval lastdigittime;
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2005-07-15 23:00:47 +00:00
|
|
|
lastdigittime = ast_tvnow();
|
2012-10-17 19:02:46 +00:00
|
|
|
while (*received < expected && *received < buf_size - 1) {
|
2012-09-05 15:56:33 +00:00
|
|
|
/* If timed out, leave */
|
2012-10-17 19:02:46 +00:00
|
|
|
if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) > ((*received > 0) ? sdtimeout : fdtimeout)) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: DTMF Digit Timeout on %s\n", ast_channel_name(chan));
|
2012-09-05 15:56:33 +00:00
|
|
|
ast_debug(1, "AlarmReceiver: DTMF timeout on chan %s\n", ast_channel_name(chan));
|
|
|
|
rtn = 1;
|
2004-06-21 19:28:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-02-08 20:49:48 +00:00
|
|
|
if ((r = ast_waitfor(chan, -1)) < 0) {
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "Waitfor returned %d\n", r);
|
2004-06-21 19:28:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if ((f = ast_read(chan)) == NULL) {
|
|
|
|
rtn = -1;
|
2004-06-21 19:28:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
/* If they hung up, leave */
|
2012-09-05 15:56:33 +00:00
|
|
|
if ((f->frametype == AST_FRAME_CONTROL)
|
|
|
|
&& (f->subclass.integer == AST_CONTROL_HANGUP)) {
|
2008-05-22 16:29:54 +00:00
|
|
|
if (f->data.uint32) {
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_hangupcause_set(chan, f->data.uint32);
|
2008-04-24 22:16:48 +00:00
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
ast_frfree(f);
|
2012-09-05 15:56:33 +00:00
|
|
|
rtn = -1;
|
2004-06-21 19:28:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/* If not DTMF, just do it again */
|
2008-02-07 20:42:59 +00:00
|
|
|
if (f->frametype != AST_FRAME_DTMF) {
|
2004-06-21 19:28:34 +00:00
|
|
|
ast_frfree(f);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/* Save digit */
|
2012-10-17 19:02:46 +00:00
|
|
|
digit_string[(*received)++] = f->subclass.integer;
|
2004-06-21 19:28:34 +00:00
|
|
|
ast_frfree(f);
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2005-07-15 23:00:47 +00:00
|
|
|
lastdigittime = ast_tvnow();
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
/* Null terminate the end of the digit_string */
|
|
|
|
digit_string[*received] = '\0';
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
return rtn;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief Write metadata to log file
|
|
|
|
*
|
|
|
|
* \param logfile Log File Pointer
|
|
|
|
* \param signalling_type Signaling Type
|
|
|
|
* \param chan Asterisk Channel
|
2012-10-17 19:02:46 +00:00
|
|
|
* \param no_checksum Expecting messages without checksum
|
2012-09-05 15:56:33 +00:00
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
2012-10-17 19:02:46 +00:00
|
|
|
static int write_metadata(FILE *logfile, char *signalling_type, struct ast_channel *chan, int no_checksum)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
2007-07-18 19:47:20 +00:00
|
|
|
struct timeval t;
|
|
|
|
struct ast_tm now;
|
2010-07-14 15:48:36 +00:00
|
|
|
char *cl;
|
|
|
|
char *cn;
|
2004-06-21 19:28:34 +00:00
|
|
|
char workstring[80];
|
|
|
|
char timestamp[80];
|
2012-09-05 15:56:33 +00:00
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
/* Extract the caller ID location */
|
2010-07-14 15:48:36 +00:00
|
|
|
ast_copy_string(workstring,
|
2012-09-05 15:56:33 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.number.valid,
|
|
|
|
ast_channel_caller(chan)->id.number.str, ""), sizeof(workstring));
|
2010-07-14 15:48:36 +00:00
|
|
|
ast_shrink_phone_number(workstring);
|
|
|
|
if (ast_strlen_zero(workstring)) {
|
|
|
|
cl = "<unknown>";
|
|
|
|
} else {
|
|
|
|
cl = workstring;
|
|
|
|
}
|
2012-09-05 15:56:33 +00:00
|
|
|
cn = S_COR(ast_channel_caller(chan)->id.name.valid,
|
|
|
|
ast_channel_caller(chan)->id.name.str, "<unknown>");
|
2004-06-21 19:28:34 +00:00
|
|
|
|
|
|
|
/* Get the current time */
|
2007-07-18 19:47:20 +00:00
|
|
|
t = ast_tvnow();
|
2004-06-21 19:28:34 +00:00
|
|
|
ast_localtime(&t, &now, NULL);
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
/* Format the time */
|
2008-02-07 20:42:59 +00:00
|
|
|
ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
if (no_group_meta && fprintf(logfile, "PROTOCOL=%s\n"
|
|
|
|
"CHECKSUM=%s\n"
|
|
|
|
"CALLINGFROM=%s\n"
|
|
|
|
"CALLERNAME=%s\n"
|
|
|
|
"TIMESTAMP=%s\n\n",
|
|
|
|
signalling_type, (!no_checksum) ? "yes" : "no", cl, cn, timestamp) > -1) {
|
|
|
|
return 0;
|
|
|
|
} else if (fprintf(logfile, "\n\n[metadata]\n\n"
|
2012-09-05 15:56:33 +00:00
|
|
|
"PROTOCOL=%s\n"
|
2012-10-17 19:02:46 +00:00
|
|
|
"CHECKSUM=%s\n"
|
2012-09-05 15:56:33 +00:00
|
|
|
"CALLINGFROM=%s\n"
|
|
|
|
"CALLERNAME=%s\n"
|
|
|
|
"TIMESTAMP=%s\n\n"
|
2012-10-17 19:02:46 +00:00
|
|
|
"[events]\n\n",
|
|
|
|
signalling_type, (!no_checksum) ? "yes" : "no", cl, cn, timestamp) > -1) {
|
|
|
|
return 0;
|
2010-07-14 15:48:36 +00:00
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_verb(3, "AlarmReceiver: can't write metadata\n");
|
|
|
|
ast_debug(1, "AlarmReceiver: can't write metadata\n");
|
|
|
|
return -1;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief Log a single event
|
|
|
|
*
|
|
|
|
* \param logfile Log File Pointer
|
|
|
|
* \param event Event Structure
|
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
|
|
|
static int write_event(FILE *logfile, event_node_t *event)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
2012-10-17 19:02:46 +00:00
|
|
|
if (fprintf(logfile, "%s%s\n", no_group_meta ? "event=" : "", event->data) < 0) {
|
2012-09-05 15:56:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-10-17 19:02:46 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
return 0;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
2012-10-17 19:02:46 +00:00
|
|
|
* \brief Log events if configuration key logindividualevents is enabled or on exit
|
2012-09-05 15:56:33 +00:00
|
|
|
*
|
|
|
|
* \param chan Asterisk Channel
|
|
|
|
* \param signalling_type Signaling Type
|
|
|
|
* \param event Event Structure
|
2012-10-17 19:02:46 +00:00
|
|
|
* \param no_checksum Expecting messages without checksum
|
2012-09-05 15:56:33 +00:00
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
2012-10-17 19:02:46 +00:00
|
|
|
static int log_events(struct ast_channel *chan, char *signalling_type, event_node_t *event, int no_checksum)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
2012-09-05 15:56:33 +00:00
|
|
|
char workstring[sizeof(event_spool_dir) + sizeof(event_file)] = "";
|
2004-06-21 19:28:34 +00:00
|
|
|
int fd;
|
|
|
|
FILE *logfile;
|
|
|
|
event_node_t *elp = event;
|
2012-09-05 15:56:33 +00:00
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (!ast_strlen_zero(event_spool_dir)) {
|
2012-09-05 15:56:33 +00:00
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
/* Make a template */
|
2005-07-10 23:12:25 +00:00
|
|
|
ast_copy_string(workstring, event_spool_dir, sizeof(workstring));
|
2004-07-14 07:22:30 +00:00
|
|
|
strncat(workstring, event_file, sizeof(workstring) - strlen(workstring) - 1);
|
2012-09-05 15:56:33 +00:00
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
/* Make the temporary file */
|
|
|
|
fd = mkstemp(workstring);
|
2012-09-05 15:56:33 +00:00
|
|
|
|
2008-02-07 20:42:59 +00:00
|
|
|
if (fd == -1) {
|
|
|
|
ast_verb(3, "AlarmReceiver: can't make temporary file\n");
|
2012-09-05 15:56:33 +00:00
|
|
|
ast_debug(1, "AlarmReceiver: can't make temporary file\n");
|
|
|
|
return -1;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if ((logfile = fdopen(fd, "w")) == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the file */
|
2012-10-17 19:02:46 +00:00
|
|
|
if (write_metadata(logfile, signalling_type, chan, no_checksum)) {
|
2012-09-05 15:56:33 +00:00
|
|
|
fflush(logfile);
|
|
|
|
fclose(logfile);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
while ((elp != NULL) && (write_event(logfile, elp) == 0)) {
|
2012-09-05 15:56:33 +00:00
|
|
|
elp = elp->next;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2012-09-05 15:56:33 +00:00
|
|
|
|
|
|
|
fflush(logfile);
|
|
|
|
fclose(logfile);
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
return 0;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief Verify Ademco checksum
|
|
|
|
* \since 11.0
|
|
|
|
*
|
|
|
|
* \param event Received DTMF String
|
|
|
|
* \param expected Number of Digits expected
|
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
|
|
|
static int ademco_verify_checksum(char *event, int expected)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
2012-09-05 15:56:33 +00:00
|
|
|
int checksum = 0;
|
2008-02-07 20:42:59 +00:00
|
|
|
int i, j;
|
2012-09-05 15:56:33 +00:00
|
|
|
|
|
|
|
for (j = 0; j < expected; j++) {
|
|
|
|
for (i = 0; i < ARRAY_LEN(digits_mapping); i++) {
|
|
|
|
if (digits_mapping[i].digit == event[j]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= ARRAY_LEN(digits_mapping)) {
|
|
|
|
ast_verb(2, "AlarmReceiver: Bad DTMF character %c, trying again\n", event[j]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
checksum += digits_mapping[i].weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checksum is mod(15) of the total */
|
|
|
|
if (!(checksum % 15)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2015-01-23 15:13:08 +00:00
|
|
|
* \brief Send a single tone burst for a specified duration and frequency.
|
2012-09-05 15:56:33 +00:00
|
|
|
* \since 11.0
|
|
|
|
*
|
|
|
|
* \param chan Asterisk Channel
|
|
|
|
* \param tone_freq Frequency of the tone to send
|
|
|
|
* \param tone_duration Tone duration in ms
|
|
|
|
* \param delay Delay before sending the tone
|
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
2012-10-17 19:02:46 +00:00
|
|
|
static int send_tone_burst(struct ast_channel *chan, const char *tone_freq, int tone_duration, int delay)
|
2012-09-05 15:56:33 +00:00
|
|
|
{
|
|
|
|
if (delay && ast_safe_sleep(chan, delay)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
if (ast_playtones_start(chan, toneloudness, tone_freq, 0)) {
|
2012-09-05 15:56:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_safe_sleep(chan, tone_duration)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_playtones_stop(chan);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2012-10-17 19:02:46 +00:00
|
|
|
* \brief Check if the message is in known and valid Ademco format
|
|
|
|
*
|
|
|
|
* \param signalling_type Expected signalling type for the message
|
|
|
|
* \param event event received
|
|
|
|
*
|
|
|
|
* \retval 0 The event is valid
|
|
|
|
* \retval -1 The event is not valid
|
|
|
|
*/
|
|
|
|
static int ademco_check_valid(char *signalling_type, char *event)
|
|
|
|
{
|
|
|
|
if (!strcmp(signalling_type, UNKNOWN_FORMAT)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(signalling_type, ADEMCO_CONTACT_ID)
|
|
|
|
&& strncmp(event + 4, ADEMCO_MSG_TYPE_1, 2)
|
|
|
|
&& strncmp(event + 4, ADEMCO_MSG_TYPE_2, 2)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(signalling_type, ADEMCO_EXPRESS_4_1) && strncmp(event + 4, ADEMCO_MSG_TYPE_3, 2)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(signalling_type, ADEMCO_EXPRESS_4_2) && strncmp(event + 4, ADEMCO_MSG_TYPE_4, 2)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(signalling_type, ADEMCO_HIGH_SPEED) && strncmp(event + 4, ADEMCO_MSG_TYPE_5, 2)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(signalling_type, ADEMCO_SUPER_FAST) && strncmp(event + 4, ADEMCO_MSG_TYPE_6, 2)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Detect the message format of an event
|
|
|
|
*
|
|
|
|
* \param signalling_type Expected signalling type for the message
|
|
|
|
* \param event event received
|
|
|
|
* \param no_checksum Should we calculate checksum for the message
|
|
|
|
*
|
|
|
|
* \returns The expected digits for the detected event type
|
|
|
|
*/
|
|
|
|
static int ademco_detect_format(char *signalling_type, char *event, int *no_checksum)
|
|
|
|
{
|
|
|
|
int res = 16;
|
|
|
|
|
|
|
|
if (!strncmp(event + 4, ADEMCO_MSG_TYPE_1, 2)
|
|
|
|
|| !strncmp(event + 4, ADEMCO_MSG_TYPE_2, 2)) {
|
|
|
|
sprintf(signalling_type, "%s", ADEMCO_CONTACT_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strncmp(event + 4, ADEMCO_MSG_TYPE_3, 2)) {
|
|
|
|
sprintf(signalling_type, "%s", ADEMCO_EXPRESS_4_1);
|
|
|
|
res = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strncmp(event + 4, ADEMCO_MSG_TYPE_4, 2)) {
|
|
|
|
sprintf(signalling_type, "%s", ADEMCO_EXPRESS_4_2);
|
|
|
|
res = 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strncmp(event + 4, ADEMCO_MSG_TYPE_5, 2)) {
|
|
|
|
sprintf(signalling_type, "%s", ADEMCO_HIGH_SPEED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strncmp(event + 4, ADEMCO_MSG_TYPE_6, 2)) {
|
|
|
|
sprintf(signalling_type, "%s", ADEMCO_SUPER_FAST);
|
|
|
|
*no_checksum = 1;
|
|
|
|
res = 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(signalling_type, UNKNOWN_FORMAT)) {
|
|
|
|
ast_verb(4, "AlarmMonitoring: Detected format %s.\n", signalling_type);
|
|
|
|
ast_debug(1, "AlarmMonitoring: Autodetected format %s.\n", signalling_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Receive Ademco ContactID or other format Data String
|
2012-09-05 15:56:33 +00:00
|
|
|
*
|
|
|
|
* \param chan Asterisk Channel
|
|
|
|
* \param ehead Pointer to events list
|
2012-10-17 19:02:46 +00:00
|
|
|
* \param signalling_type Expected signalling type for the message
|
|
|
|
* \param no_checksum Should we calculate checksum for the message
|
2012-09-05 15:56:33 +00:00
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
2012-10-17 19:02:46 +00:00
|
|
|
static int receive_ademco_event(struct ast_channel *chan, event_node_t **ehead, char *signalling_type, int *no_checksum)
|
2012-09-05 15:56:33 +00:00
|
|
|
{
|
2004-06-21 19:28:34 +00:00
|
|
|
int res = 0;
|
2012-10-17 19:02:46 +00:00
|
|
|
const char *limit;
|
2004-06-21 19:28:34 +00:00
|
|
|
char event[17];
|
|
|
|
event_node_t *enew, *elp;
|
|
|
|
int got_some_digits = 0;
|
|
|
|
int events_received = 0;
|
|
|
|
int ack_retries = 0;
|
2012-10-17 19:02:46 +00:00
|
|
|
int limit_retries = 0;
|
|
|
|
int expected_length = sizeof(event) - 1;
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
database_increment("calls-received");
|
|
|
|
|
|
|
|
/* Wait for first event */
|
2012-09-05 15:56:33 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: Waiting for first event from panel...\n");
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2008-02-07 20:42:59 +00:00
|
|
|
while (res >= 0) {
|
2012-10-17 19:02:46 +00:00
|
|
|
int digits_received = 0;
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
res = 0;
|
2012-10-17 19:02:46 +00:00
|
|
|
|
|
|
|
if (log_individual_events) {
|
|
|
|
sprintf(signalling_type, "%s", UNKNOWN_FORMAT);
|
|
|
|
expected_length = 16;
|
|
|
|
*no_checksum = 0;
|
|
|
|
}
|
|
|
|
|
2008-02-07 20:42:59 +00:00
|
|
|
if (got_some_digits == 0) {
|
|
|
|
/* Send ACK tone sequence */
|
|
|
|
ast_verb(4, "AlarmReceiver: Sending 1400Hz 100ms burst (ACK)\n");
|
2012-10-17 19:02:46 +00:00
|
|
|
res = send_tone_burst(chan, "1400", 100, 0);
|
2008-02-07 20:42:59 +00:00
|
|
|
if (!res) {
|
|
|
|
ast_verb(4, "AlarmReceiver: Sending 2300Hz 100ms burst (ACK)\n");
|
2012-10-17 19:02:46 +00:00
|
|
|
res = send_tone_burst(chan, "2300", 100, 100);
|
2008-02-07 20:42:59 +00:00
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2012-09-05 15:56:33 +00:00
|
|
|
if (res) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
res = receive_dtmf_digits(chan, event, sizeof(event), expected_length, &digits_received);
|
2008-02-07 20:42:59 +00:00
|
|
|
if (res < 0) {
|
|
|
|
if (events_received == 0) {
|
2004-06-21 19:28:34 +00:00
|
|
|
/* Hangup with no events received should be logged in the DB */
|
|
|
|
database_increment("no-events-received");
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: No events received!\n");
|
2008-02-07 20:42:59 +00:00
|
|
|
} else {
|
|
|
|
if (ack_retries) {
|
2004-06-21 19:28:34 +00:00
|
|
|
database_increment("ack-retries");
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: ACK retries during this call: %d\n", ack_retries);
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-05 23:00:15 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: App exiting...\n");
|
2004-06-21 19:28:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
if (!strcmp(signalling_type, UNKNOWN_FORMAT) && digits_received > 5) {
|
|
|
|
expected_length = ademco_detect_format(signalling_type, event, no_checksum);
|
|
|
|
|
|
|
|
if (res > 0) {
|
|
|
|
if (digits_received == expected_length) {
|
|
|
|
res = limit_retries = 0;
|
|
|
|
} else if (digits_received == expected_length - 1
|
|
|
|
&& (!strcmp(signalling_type, ADEMCO_EXPRESS_4_2)
|
|
|
|
|| !strcmp(signalling_type, ADEMCO_EXPRESS_4_1))) {
|
|
|
|
/* ADEMCO EXPRESS without checksum */
|
|
|
|
res = limit_retries = 0;
|
|
|
|
expected_length--;
|
|
|
|
*no_checksum = 1;
|
|
|
|
ast_verb(4, "AlarmMonitoring: Skipping checksum for format %s.\n", signalling_type);
|
|
|
|
ast_debug(1, "AlarmMonitoring: Skipping checksum for format %s.\n", signalling_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
limit = pbx_builtin_getvar_helper(chan, "ALARMRECEIVER_CALL_LIMIT");
|
|
|
|
if (!ast_strlen_zero(limit)) {
|
|
|
|
if (ast_tvdiff_ms(ast_tvnow(), call_start_time) > atoi(limit)) {
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
limit = pbx_builtin_getvar_helper(chan, "ALARMRECEIVER_RETRIES_LIMIT");
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
if (!ast_strlen_zero(limit)) {
|
|
|
|
if (limit_retries + 1 >= atoi(limit)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if (res) {
|
2008-02-07 20:42:59 +00:00
|
|
|
/* Didn't get all of the digits */
|
2008-02-05 23:00:15 +00:00
|
|
|
ast_verb(2, "AlarmReceiver: Incomplete string: %s, trying again...\n", event);
|
2012-10-17 19:02:46 +00:00
|
|
|
limit_retries++;
|
|
|
|
|
|
|
|
if (!events_received && strcmp(signalling_type, UNKNOWN_FORMAT))
|
|
|
|
{
|
|
|
|
sprintf(signalling_type, "%s", UNKNOWN_FORMAT);
|
|
|
|
expected_length = sizeof(event) - 1;
|
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2008-02-07 20:42:59 +00:00
|
|
|
if (!got_some_digits) {
|
2005-10-26 19:48:14 +00:00
|
|
|
got_some_digits = (!ast_strlen_zero(event)) ? 1 : 0;
|
2004-06-21 19:28:34 +00:00
|
|
|
ack_retries++;
|
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
got_some_digits = 1;
|
|
|
|
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(2, "AlarmReceiver: Received Event %s\n", event);
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "AlarmReceiver: Received event: %s\n", event);
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
/* Calculate checksum */
|
2012-10-17 19:02:46 +00:00
|
|
|
if (!(*no_checksum) && ademco_verify_checksum(event, expected_length)) {
|
2004-06-21 19:28:34 +00:00
|
|
|
database_increment("checksum-errors");
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(2, "AlarmReceiver: Nonzero checksum\n");
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "AlarmReceiver: Nonzero checksum\n");
|
2004-06-21 19:28:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the message type for correctness */
|
2012-10-17 19:02:46 +00:00
|
|
|
if (ademco_check_valid(signalling_type, event)) {
|
|
|
|
database_increment("format-errors");
|
|
|
|
ast_verb(2, "AlarmReceiver: Wrong message type\n");
|
|
|
|
ast_debug(1, "AlarmReceiver: Wrong message type\n");
|
2004-06-21 19:28:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
events_received++;
|
2008-02-07 20:42:59 +00:00
|
|
|
|
|
|
|
/* Queue the Event */
|
2006-01-11 22:41:34 +00:00
|
|
|
if (!(enew = ast_calloc(1, sizeof(*enew)))) {
|
2012-09-05 15:56:33 +00:00
|
|
|
return -1;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2004-06-21 19:28:34 +00:00
|
|
|
enew->next = NULL;
|
2005-07-10 23:12:25 +00:00
|
|
|
ast_copy_string(enew->data, event, sizeof(enew->data));
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/* Insert event onto end of list */
|
|
|
|
if (*ehead == NULL) {
|
2004-06-21 19:28:34 +00:00
|
|
|
*ehead = enew;
|
2012-09-05 15:56:33 +00:00
|
|
|
} else {
|
|
|
|
for (elp = *ehead; elp->next != NULL; elp = elp->next) {
|
|
|
|
;
|
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
elp->next = enew;
|
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
|
|
|
/* Let the user have the option of logging the single event before sending the kissoff tone */
|
2012-10-17 19:02:46 +00:00
|
|
|
if (log_individual_events && log_events(chan, signalling_type, enew, *no_checksum)) {
|
|
|
|
return -1;
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/* Send the kissoff tone (1400 Hz, 900 ms, after 200ms delay) */
|
2012-10-17 19:02:46 +00:00
|
|
|
if (send_tone_burst(chan, "1400", 900, 200)) {
|
2012-09-05 15:56:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-10-17 19:02:46 +00:00
|
|
|
|
|
|
|
/* If audio call follows, exit alarm receiver app */
|
|
|
|
if (!strcmp(signalling_type, ADEMCO_CONTACT_ID)
|
|
|
|
&& !strncmp(event + 7, ADEMCO_AUDIO_CALL_NEXT, 3)) {
|
|
|
|
ast_verb(4, "AlarmReceiver: App exiting... Audio call next!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief This is the main function called by Asterisk Core whenever the App is invoked in the extension logic.
|
|
|
|
*
|
|
|
|
* \param chan Asterisk Channel
|
|
|
|
* \param data Application data
|
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
2009-05-21 21:13:09 +00:00
|
|
|
static int alarmreceiver_exec(struct ast_channel *chan, const char *data)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
|
|
|
int res = 0;
|
2012-10-17 19:02:46 +00:00
|
|
|
int no_checksum = 0;
|
2004-06-21 19:28:34 +00:00
|
|
|
event_node_t *elp, *efree;
|
2004-07-14 07:22:30 +00:00
|
|
|
char signalling_type[64] = "";
|
2004-06-21 19:28:34 +00:00
|
|
|
event_node_t *event_head = NULL;
|
|
|
|
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
if ((ast_format_cmp(ast_channel_writeformat(chan), ast_format_ulaw) == AST_FORMAT_CMP_NOT_EQUAL) &&
|
|
|
|
(ast_format_cmp(ast_channel_writeformat(chan), ast_format_alaw) == AST_FORMAT_CMP_NOT_EQUAL)) {
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: Setting write format to Mu-law\n");
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
if (ast_set_write_format(chan, ast_format_ulaw)) {
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_log(LOG_WARNING, "AlarmReceiver: Unable to set write format to Mu-law on %s\n",ast_channel_name(chan));
|
|
|
|
return -1;
|
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
if ((ast_format_cmp(ast_channel_readformat(chan), ast_format_ulaw) == AST_FORMAT_CMP_NOT_EQUAL) &&
|
|
|
|
(ast_format_cmp(ast_channel_readformat(chan), ast_format_alaw) == AST_FORMAT_CMP_NOT_EQUAL)) {
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: Setting read format to Mu-law\n");
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
if (ast_set_read_format(chan, ast_format_ulaw)) {
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_log(LOG_WARNING, "AlarmReceiver: Unable to set read format to Mu-law on %s\n",ast_channel_name(chan));
|
|
|
|
return -1;
|
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2006-10-26 17:52:15 +00:00
|
|
|
/* Set default values for this invocation of the application */
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_copy_string(signalling_type, UNKNOWN_FORMAT, sizeof(signalling_type));
|
|
|
|
call_start_time = ast_tvnow();
|
2004-06-21 19:28:34 +00:00
|
|
|
|
|
|
|
/* Answer the channel if it is not already */
|
2012-02-20 23:43:27 +00:00
|
|
|
if (ast_channel_state(chan) != AST_STATE_UP) {
|
2012-10-17 19:02:46 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: Answering channel\n");
|
|
|
|
if (ast_answer(chan)) {
|
2004-06-21 19:28:34 +00:00
|
|
|
return -1;
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for the connection to settle post-answer */
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: Waiting for connection to stabilize\n");
|
2012-10-17 19:02:46 +00:00
|
|
|
if (ast_safe_sleep(chan, answait)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
|
|
|
|
/* Attempt to receive the events */
|
2012-10-17 19:02:46 +00:00
|
|
|
receive_ademco_event(chan, &event_head, signalling_type, &no_checksum);
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2008-02-07 20:42:59 +00:00
|
|
|
/* Events queued by receiver, write them all out here if so configured */
|
2012-10-17 19:02:46 +00:00
|
|
|
if (!log_individual_events) {
|
|
|
|
res = log_events(chan, signalling_type, event_head, no_checksum);
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/* Do we exec a command line at the end? */
|
2008-02-07 20:42:59 +00:00
|
|
|
if ((!res) && (!ast_strlen_zero(event_app)) && (event_head)) {
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1,"Alarmreceiver: executing: %s\n", event_app);
|
2004-06-21 19:28:34 +00:00
|
|
|
ast_safe_system(event_app);
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/* Free up the data allocated in our linked list */
|
2008-02-07 20:42:59 +00:00
|
|
|
for (elp = event_head; (elp != NULL);) {
|
2004-06-21 19:28:34 +00:00
|
|
|
efree = elp;
|
|
|
|
elp = elp->next;
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(efree);
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief Load the configuration from the configuration file
|
|
|
|
*
|
2012-10-17 19:02:46 +00:00
|
|
|
* \param reload True on reload
|
|
|
|
*
|
2012-09-05 15:56:33 +00:00
|
|
|
* \retval 1 success
|
|
|
|
* \retval 0 failure
|
|
|
|
*/
|
2012-10-17 19:02:46 +00:00
|
|
|
static int load_config(int reload)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
|
|
|
struct ast_config *cfg;
|
2012-09-05 15:56:33 +00:00
|
|
|
const char *value;
|
2012-10-17 19:02:46 +00:00
|
|
|
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
|
2004-06-21 19:28:34 +00:00
|
|
|
|
|
|
|
/* Read in the config file */
|
2007-08-16 21:09:46 +00:00
|
|
|
cfg = ast_config_load(ALMRCV_CONFIG, config_flags);
|
2008-02-07 20:42:59 +00:00
|
|
|
|
|
|
|
if (!cfg) {
|
2008-02-05 23:00:15 +00:00
|
|
|
ast_verb(4, "AlarmReceiver: No config file\n");
|
2006-08-31 21:00:20 +00:00
|
|
|
return 0;
|
2012-10-17 19:02:46 +00:00
|
|
|
} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
|
|
|
|
return 1;
|
2008-09-12 23:30:03 +00:00
|
|
|
} else if (cfg == CONFIG_STATUS_FILEINVALID) {
|
2012-09-05 15:56:33 +00:00
|
|
|
ast_log(LOG_ERROR, "Config file %s is in an invalid format. Aborting.\n",
|
|
|
|
ALMRCV_CONFIG);
|
2008-09-12 23:30:03 +00:00
|
|
|
return 0;
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "eventcmd")) != NULL) {
|
|
|
|
ast_copy_string(event_app, value, sizeof(event_app));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "loudness")) != NULL) {
|
|
|
|
toneloudness = atoi(value);
|
|
|
|
if (toneloudness < 100) {
|
|
|
|
toneloudness = 100;
|
|
|
|
} else if (toneloudness > 8192) {
|
|
|
|
toneloudness = 8192;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "fdtimeout")) != NULL) {
|
|
|
|
fdtimeout = atoi(value);
|
|
|
|
if (fdtimeout < 1000) {
|
|
|
|
fdtimeout = 1000;
|
|
|
|
} else if (fdtimeout > 10000) {
|
|
|
|
fdtimeout = 10000;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "sdtimeout")) != NULL) {
|
|
|
|
sdtimeout = atoi(value);
|
|
|
|
if (sdtimeout < 110) {
|
|
|
|
sdtimeout = 110;
|
|
|
|
} else if (sdtimeout > 4000) {
|
|
|
|
sdtimeout = 4000;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "answait")) != NULL) {
|
|
|
|
answait = atoi(value);
|
|
|
|
if (answait < 500) {
|
|
|
|
answait = 500;
|
|
|
|
} else if (answait > 10000) {
|
|
|
|
answait = 10000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "no_group_meta")) != NULL) {
|
|
|
|
no_group_meta = ast_true(value);
|
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "logindividualevents")) != NULL) {
|
|
|
|
log_individual_events = ast_true(value);
|
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "eventspooldir")) != NULL) {
|
|
|
|
ast_copy_string(event_spool_dir, value, sizeof(event_spool_dir));
|
|
|
|
}
|
2008-02-07 20:42:59 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "timestampformat")) != NULL) {
|
|
|
|
ast_copy_string(time_stamp_format, value, sizeof(time_stamp_format));
|
|
|
|
}
|
2004-06-21 19:28:34 +00:00
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
if ((value = ast_variable_retrieve(cfg, "general", "db-family")) != NULL) {
|
|
|
|
ast_copy_string(db_family, value, sizeof(db_family));
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
2012-09-05 15:56:33 +00:00
|
|
|
|
|
|
|
ast_config_destroy(cfg);
|
|
|
|
|
2006-08-31 21:00:20 +00:00
|
|
|
return 1;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-05 15:56:33 +00:00
|
|
|
/*!
|
|
|
|
* \brief Unregister Alarm Receiver App
|
|
|
|
*
|
|
|
|
* \retval 0 success
|
|
|
|
* \retval -1 failure
|
|
|
|
*/
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
2007-07-16 13:35:20 +00:00
|
|
|
return ast_unregister_application(app);
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-10-01 23:22:50 +00:00
|
|
|
/*!
|
|
|
|
* \brief Load the module
|
|
|
|
*
|
|
|
|
* Module loading including tests for configuration or dependencies.
|
|
|
|
* This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
|
|
|
|
* or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
|
2012-10-17 19:02:46 +00:00
|
|
|
* tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
|
|
|
|
* configuration file or other non-critical problem return
|
2012-10-01 23:22:50 +00:00
|
|
|
* AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
|
2012-09-05 15:56:33 +00:00
|
|
|
*/
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2004-06-21 19:28:34 +00:00
|
|
|
{
|
2012-10-17 19:02:46 +00:00
|
|
|
if (load_config(0)) {
|
2012-09-05 15:56:33 +00:00
|
|
|
if (ast_register_application_xml(app, alarmreceiver_exec)) {
|
2017-04-11 16:07:39 +00:00
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
2007-12-26 20:02:27 +00:00
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
2012-09-05 15:56:33 +00:00
|
|
|
}
|
2012-10-17 19:02:46 +00:00
|
|
|
|
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int reload(void)
|
|
|
|
{
|
|
|
|
if (load_config(1)) {
|
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
2004-06-21 19:28:34 +00:00
|
|
|
}
|
|
|
|
|
2012-10-17 19:02:46 +00:00
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Alarm Receiver for Asterisk",
|
2015-05-06 00:49:04 +00:00
|
|
|
.support_level = AST_MODULE_SUPPORT_EXTENDED,
|
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
.reload = reload,
|
2012-10-17 19:02:46 +00:00
|
|
|
);
|