Asterisk - The Open Source Telephony Project GIT-master-a63eec2
|
Central Station Alarm receiver for Ademco Contact ID. More...
#include "asterisk.h"
#include <math.h>
#include <sys/wait.h>
#include <sys/time.h>
#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"
#include "asterisk/utils.h"
#include "asterisk/indications.h"
#include "asterisk/format_cache.h"
Go to the source code of this file.
Data Structures | |
struct | event_node |
Macros | |
#define | ADEMCO_AUDIO_CALL_NEXT "606" |
#define | ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID" |
#define | ADEMCO_EXPRESS_4_1 "ADEMCO_EXPRESS_4_1" |
#define | ADEMCO_EXPRESS_4_2 "ADEMCO_EXPRESS_4_2" |
#define | ADEMCO_HIGH_SPEED "ADEMCO_HIGH_SPEED" |
#define | ADEMCO_MSG_TYPE_1 "18" |
#define | ADEMCO_MSG_TYPE_2 "98" |
#define | ADEMCO_MSG_TYPE_3 "17" |
#define | ADEMCO_MSG_TYPE_4 "27" |
#define | ADEMCO_MSG_TYPE_5 "55" |
#define | ADEMCO_MSG_TYPE_6 "56" |
#define | ADEMCO_SUPER_FAST "ADEMCO_SUPER_FAST" |
#define | ALMRCV_CONFIG "alarmreceiver.conf" |
#define | UNKNOWN_FORMAT "UNKNOWN_FORMAT" |
Typedefs | |
typedef struct event_node | event_node_t |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | ademco_check_valid (char *signalling_type, char *event) |
Check if the message is in known and valid Ademco format. | |
static int | ademco_detect_format (char *signalling_type, char *event, int *no_checksum) |
Detect the message format of an event. | |
static int | ademco_verify_checksum (char *event, int expected) |
Verify Ademco checksum. | |
static int | alarmreceiver_exec (struct ast_channel *chan, const char *data) |
This is the main function called by Asterisk Core whenever the App is invoked in the extension logic. | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static void | database_increment (char *key) |
Attempt to access a database variable and increment it. | |
static int | load_config (int reload) |
Load the configuration from the configuration file. | |
static int | load_module (void) |
Load the module. | |
static int | log_events (struct ast_channel *chan, char *signalling_type, event_node_t *event, int no_checksum) |
Log events if configuration key logindividualevents is enabled or on exit. | |
static int | receive_ademco_event (struct ast_channel *chan, event_node_t **ehead, char *signalling_type, int *no_checksum) |
Receive Ademco ContactID or other format Data String. | |
static int | receive_dtmf_digits (struct ast_channel *chan, char *digit_string, int buf_size, int expected, int *received) |
Receive a fixed length DTMF string. | |
static int | reload (void) |
static int | send_tone_burst (struct ast_channel *chan, const char *tone_freq, int tone_duration, int delay) |
Send a single tone burst for a specified duration and frequency. | |
static int | unload_module (void) |
Unregister Alarm Receiver App. | |
static int | write_event (FILE *logfile, event_node_t *event) |
Log a single event. | |
static int | write_metadata (FILE *logfile, char *signalling_type, struct ast_channel *chan, int no_checksum) |
Write metadata to log file. | |
Variables | ||
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Alarm Receiver for Asterisk" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, } | |
static int | answait = 1250 | |
static const char | app [] = "AlarmReceiver" | |
static const struct ast_module_info * | ast_module_info = &__mod_info | |
struct timeval | call_start_time | |
static char | db_family [128] = {'\0'} | |
struct { | ||
char digit | ||
char weight | ||
} | digits_mapping [] | |
static char | event_app [128] = {'\0'} | |
static char | event_file [14] = "/event-XXXXXX" | |
static char | event_spool_dir [128] = {'\0'} | |
static int | fdtimeout = 2000 | |
static int | log_individual_events = 0 | |
static int | no_group_meta = 0 | |
static int | sdtimeout = 200 | |
static char | time_stamp_format [128] = {"%a %b %d, %Y @ %H:%M:%S %Z"} | |
static int | toneloudness = 4096 | |
Central Station Alarm receiver for Ademco Contact ID.
*** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
Use at your own risk. Please consult the GNU GPL license document included with Asterisk. *
*** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
Definition in file app_alarmreceiver.c.
#define ADEMCO_AUDIO_CALL_NEXT "606" |
Definition at line 128 of file app_alarmreceiver.c.
#define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID" |
Definition at line 71 of file app_alarmreceiver.c.
#define ADEMCO_EXPRESS_4_1 "ADEMCO_EXPRESS_4_1" |
Definition at line 80 of file app_alarmreceiver.c.
#define ADEMCO_EXPRESS_4_2 "ADEMCO_EXPRESS_4_2" |
Definition at line 87 of file app_alarmreceiver.c.
#define ADEMCO_HIGH_SPEED "ADEMCO_HIGH_SPEED" |
Definition at line 94 of file app_alarmreceiver.c.
#define ADEMCO_MSG_TYPE_1 "18" |
Definition at line 121 of file app_alarmreceiver.c.
#define ADEMCO_MSG_TYPE_2 "98" |
Definition at line 122 of file app_alarmreceiver.c.
#define ADEMCO_MSG_TYPE_3 "17" |
Definition at line 123 of file app_alarmreceiver.c.
#define ADEMCO_MSG_TYPE_4 "27" |
Definition at line 124 of file app_alarmreceiver.c.
#define ADEMCO_MSG_TYPE_5 "55" |
Definition at line 125 of file app_alarmreceiver.c.
#define ADEMCO_MSG_TYPE_6 "56" |
Definition at line 126 of file app_alarmreceiver.c.
#define ADEMCO_SUPER_FAST "ADEMCO_SUPER_FAST" |
Definition at line 115 of file app_alarmreceiver.c.
#define ALMRCV_CONFIG "alarmreceiver.conf" |
Definition at line 68 of file app_alarmreceiver.c.
#define UNKNOWN_FORMAT "UNKNOWN_FORMAT" |
Definition at line 69 of file app_alarmreceiver.c.
typedef struct event_node event_node_t |
Definition at line 142 of file app_alarmreceiver.c.
|
static |
Definition at line 1002 of file app_alarmreceiver.c.
|
static |
Definition at line 1002 of file app_alarmreceiver.c.
|
static |
Check if the message is in known and valid Ademco format.
signalling_type | Expected signalling type for the message |
event | event received |
0 | The event is valid |
-1 | The event is not valid |
Definition at line 525 of file app_alarmreceiver.c.
References ADEMCO_CONTACT_ID, ADEMCO_EXPRESS_4_1, ADEMCO_EXPRESS_4_2, ADEMCO_HIGH_SPEED, ADEMCO_MSG_TYPE_1, ADEMCO_MSG_TYPE_2, ADEMCO_MSG_TYPE_3, ADEMCO_MSG_TYPE_4, ADEMCO_MSG_TYPE_5, ADEMCO_MSG_TYPE_6, ADEMCO_SUPER_FAST, and UNKNOWN_FORMAT.
Referenced by receive_ademco_event().
|
static |
Detect the message format of an event.
signalling_type | Expected signalling type for the message |
event | event received |
no_checksum | Should we calculate checksum for the message |
Definition at line 565 of file app_alarmreceiver.c.
References ADEMCO_CONTACT_ID, ADEMCO_EXPRESS_4_1, ADEMCO_EXPRESS_4_2, ADEMCO_HIGH_SPEED, ADEMCO_MSG_TYPE_1, ADEMCO_MSG_TYPE_2, ADEMCO_MSG_TYPE_3, ADEMCO_MSG_TYPE_4, ADEMCO_MSG_TYPE_5, ADEMCO_MSG_TYPE_6, ADEMCO_SUPER_FAST, ast_debug, ast_verb, and UNKNOWN_FORMAT.
Referenced by receive_ademco_event().
|
static |
Verify Ademco checksum.
event | Received DTMF String |
expected | Number of Digits expected |
0 | success |
-1 | failure |
Definition at line 458 of file app_alarmreceiver.c.
References ARRAY_LEN, ast_verb, digit, and digits_mapping.
Referenced by receive_ademco_event().
|
static |
This is the main function called by Asterisk Core whenever the App is invoked in the extension logic.
chan | Asterisk Channel |
data | Application data |
0 | success |
-1 | failure |
Definition at line 794 of file app_alarmreceiver.c.
References answait, ast_answer(), ast_channel_name(), ast_channel_readformat(), ast_channel_writeformat(), ast_copy_string(), ast_debug, ast_format_alaw, ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_ulaw, ast_free, ast_log, ast_safe_sleep(), ast_safe_system(), ast_set_read_format(), ast_set_write_format(), AST_STATE_UP, ast_strlen_zero(), ast_tvnow(), ast_verb, call_start_time, event_app, log_events(), log_individual_events, LOG_WARNING, event_node::next, NULL, receive_ademco_event(), and UNKNOWN_FORMAT.
Referenced by load_module().
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1002 of file app_alarmreceiver.c.
|
static |
Attempt to access a database variable and increment it.
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.
key | A database key to increment |
Definition at line 210 of file app_alarmreceiver.c.
References ast_db_get(), ast_db_put(), ast_strlen_zero(), ast_verb, db_family, and value.
Referenced by receive_ademco_event().
|
static |
Load the configuration from the configuration file.
reload | True on reload |
1 | success |
0 | failure |
Definition at line 870 of file app_alarmreceiver.c.
References ALMRCV_CONFIG, answait, ast_config_destroy(), ast_config_load, ast_copy_string(), ast_log, ast_true(), ast_variable_retrieve(), ast_verb, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, db_family, event_app, event_spool_dir, fdtimeout, LOG_ERROR, log_individual_events, no_group_meta, NULL, reload(), sdtimeout, time_stamp_format, toneloudness, and value.
|
static |
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 tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
Definition at line 976 of file app_alarmreceiver.c.
References alarmreceiver_exec(), app, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, and load_config().
|
static |
Log events if configuration key logindividualevents is enabled or on exit.
chan | Asterisk Channel |
signalling_type | Signaling Type |
event | Event Structure |
no_checksum | Expecting messages without checksum |
0 | success |
-1 | failure |
Definition at line 404 of file app_alarmreceiver.c.
References ast_copy_string(), ast_debug, ast_strlen_zero(), ast_verb, event_file, event_spool_dir, event_node::next, NULL, write_event(), and write_metadata().
Referenced by alarmreceiver_exec(), and receive_ademco_event().
|
static |
Receive Ademco ContactID or other format Data String.
chan | Asterisk Channel |
ehead | Pointer to events list |
signalling_type | Expected signalling type for the message |
no_checksum | Should we calculate checksum for the message |
0 | success |
-1 | failure |
Definition at line 613 of file app_alarmreceiver.c.
References ADEMCO_AUDIO_CALL_NEXT, ademco_check_valid(), ADEMCO_CONTACT_ID, ademco_detect_format(), ADEMCO_EXPRESS_4_1, ADEMCO_EXPRESS_4_2, ademco_verify_checksum(), ast_calloc, ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_debug, ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, call_start_time, event_node::data, database_increment(), log_events(), log_individual_events, event_node::next, NULL, pbx_builtin_getvar_helper(), receive_dtmf_digits(), send_tone_burst(), and UNKNOWN_FORMAT.
Referenced by alarmreceiver_exec().
|
static |
Receive a fixed length DTMF string.
chan | Asterisk Channel |
digit_string | Digits String |
buf_size | The size of the Digits String buffer |
expected | Digits expected for this message type |
received | Pointer to number of digits received so far |
0 | if all digits were successfully received |
1 | if a timeout occurred |
-1 | if the caller hung up or on channel errors |
Definition at line 255 of file app_alarmreceiver.c.
References ast_channel_hangupcause_set(), ast_channel_name(), AST_CONTROL_HANGUP, ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_frfree, ast_read(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, ast_waitfor(), ast_frame::data, fdtimeout, ast_frame::frametype, ast_frame_subclass::integer, NULL, sdtimeout, ast_frame::subclass, and ast_frame::uint32.
Referenced by receive_ademco_event().
|
static |
Definition at line 988 of file app_alarmreceiver.c.
References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and load_config().
Referenced by load_config().
|
static |
Send a single tone burst for a specified duration and frequency.
chan | Asterisk Channel |
tone_freq | Frequency of the tone to send |
tone_duration | Tone duration in ms |
delay | Delay before sending the tone |
0 | success |
-1 | failure |
Definition at line 498 of file app_alarmreceiver.c.
References ast_playtones_start(), ast_playtones_stop(), ast_safe_sleep(), and toneloudness.
Referenced by receive_ademco_event().
|
static |
Unregister Alarm Receiver App.
0 | success |
-1 | failure |
Definition at line 961 of file app_alarmreceiver.c.
References app, and ast_unregister_application().
|
static |
Log a single event.
logfile | Log File Pointer |
event | Event Structure |
0 | success |
-1 | failure |
Definition at line 384 of file app_alarmreceiver.c.
References no_group_meta.
Referenced by log_events().
|
static |
Write metadata to log file.
logfile | Log File Pointer |
signalling_type | Signaling Type |
chan | Asterisk Channel |
no_checksum | Expecting messages without checksum |
0 | success |
-1 | failure |
Definition at line 323 of file app_alarmreceiver.c.
References ast_channel_caller(), ast_copy_string(), ast_debug, ast_localtime(), ast_shrink_phone_number(), ast_strftime(), ast_strlen_zero(), ast_tvnow(), ast_verb, name, no_group_meta, NULL, S_COR, and time_stamp_format.
Referenced by log_events().
|
static |
Definition at line 1002 of file app_alarmreceiver.c.
|
static |
Definition at line 187 of file app_alarmreceiver.c.
Referenced by alarmreceiver_exec(), and load_config().
|
static |
Definition at line 146 of file app_alarmreceiver.c.
Referenced by load_module(), and unload_module().
|
static |
Definition at line 1002 of file app_alarmreceiver.c.
struct timeval call_start_time |
Definition at line 144 of file app_alarmreceiver.c.
Referenced by alarmreceiver_exec(), and receive_ademco_event().
|
static |
Definition at line 193 of file app_alarmreceiver.c.
Referenced by database_increment(), and load_config().
char digit |
Definition at line 131 of file app_alarmreceiver.c.
Referenced by __ast_pbx_run(), __ast_read(), action_atxfer(), action_cancel_atxfer(), action_playback_and_continue(), ademco_verify_checksum(), agent_alert(), ast_bridge_channel_feature_digit(), ast_bridge_channel_feature_digit_add(), ast_channel_end_dtmf(), ast_dsp_process(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_end(), ast_rtp_dtmf_end_with_duration(), ast_rtp_instance_dtmf_begin(), ast_rtp_instance_dtmf_end(), ast_rtp_instance_dtmf_end_with_duration(), ast_senddigit(), ast_senddigit_begin(), ast_senddigit_end(), ast_senddigit_external(), ast_senddigit_mf(), ast_senddigit_mf_begin(), ast_translate_number_ka(), ast_unreal_digit_begin(), ast_unreal_digit_end(), attended_transfer_exec(), audiosocket_send_dtmf(), bridge_channel_feature_digit_add(), chan_pjsip_digit_begin(), chan_pjsip_digit_end(), chan_pjsip_indicate(), change_spy_mode(), channel_dtmf_begin_cb(), channel_dtmf_end_cb(), collect_digits(), compare(), console_digit_begin(), console_digit_end(), controlplayback_exec(), dahdi_digit_begin(), dahdi_digit_end(), dial_exec_full(), dictate_exec(), digit_to_dtmfindex(), directory_exec(), do_directory(), dtmf_end_to_json(), dtmf_stream(), get_mohbydigit(), handle_incoming_request(), hfp_send_dtmf(), iax2_digit_begin(), iax2_digit_end(), info_dtmf_data_alloc(), jingle_digit_begin(), jingle_digit_end(), manager_play_dtmf(), manager_play_mf(), mbl_digit_end(), moh_digit_match(), moh_handle_digit(), morsecode_exec(), ooh323_digit_begin(), ooh323_digit_end(), ooh323_onReceivedDigit(), play_file(), send_dtmf_begin_event(), send_dtmf_end_event(), send_dtmf_tone(), store_digit(), try_calling(), unistim_do_senddigit(), unistim_senddigit_begin(), unistim_senddigit_end(), valid_exit(), wait_for_answer(), and webchan_send_dtmf_text().
struct { ... } digits_mapping[] |
Referenced by ademco_verify_checksum().
|
static |
Definition at line 192 of file app_alarmreceiver.c.
Referenced by alarmreceiver_exec(), and load_config().
|
static |
Definition at line 197 of file app_alarmreceiver.c.
Referenced by log_events().
|
static |
Definition at line 191 of file app_alarmreceiver.c.
Referenced by load_config(), and log_events().
|
static |
Definition at line 185 of file app_alarmreceiver.c.
Referenced by acf_faxopt_write(), load_config(), and receive_dtmf_digits().
|
static |
Definition at line 189 of file app_alarmreceiver.c.
Referenced by alarmreceiver_exec(), load_config(), and receive_ademco_event().
|
static |
Definition at line 190 of file app_alarmreceiver.c.
Referenced by load_config(), write_event(), and write_metadata().
|
static |
Definition at line 186 of file app_alarmreceiver.c.
Referenced by load_config(), and receive_dtmf_digits().
Definition at line 194 of file app_alarmreceiver.c.
Referenced by load_config(), and write_metadata().
|
static |
Definition at line 188 of file app_alarmreceiver.c.
Referenced by load_config(), and send_tone_burst().
char weight |
Definition at line 132 of file app_alarmreceiver.c.
Referenced by ast_srv_get_nth_record(), cache_lookup_internal(), dns_srv_alloc(), dns_srv_sort(), dundi_ie_append_answer(), dundi_lookup_thread(), dundi_show_cache(), dundi_show_mappings(), generate_srv_record(), nominal_test(), parse_srv(), precache_trans(), and srv_result_read().