Asterisk - The Open Source Telephony Project
18.5.0
|
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. More... | |
static int | ademco_detect_format (char *signalling_type, char *event, int *no_checksum) |
Detect the message format of an event. More... | |
static int | ademco_verify_checksum (char *event, int expected) |
Verify Ademco checksum. More... | |
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. More... | |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static void | database_increment (char *key) |
Attempt to access a database variable and increment it. More... | |
static int | load_config (int reload) |
Load the configuration from the configuration file. More... | |
static int | load_module (void) |
Load the module. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
static int | unload_module (void) |
Unregister Alarm Receiver App. More... | |
static int | write_event (FILE *logfile, event_node_t *event) |
Log a single event. More... | |
static int | write_metadata (FILE *logfile, char *signalling_type, struct ast_channel *chan, int no_checksum) |
Write metadata to log file. More... | |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Alarm Receiver for Asterisk" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .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.
Referenced by receive_ademco_event().
#define ADEMCO_CONTACT_ID "ADEMCO_CONTACT_ID" |
Definition at line 71 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), ademco_detect_format(), and receive_ademco_event().
#define ADEMCO_EXPRESS_4_1 "ADEMCO_EXPRESS_4_1" |
Definition at line 80 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), ademco_detect_format(), and receive_ademco_event().
#define ADEMCO_EXPRESS_4_2 "ADEMCO_EXPRESS_4_2" |
Definition at line 87 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), ademco_detect_format(), and receive_ademco_event().
#define ADEMCO_HIGH_SPEED "ADEMCO_HIGH_SPEED" |
Definition at line 94 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), and ademco_detect_format().
#define ADEMCO_MSG_TYPE_1 "18" |
Definition at line 121 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), and ademco_detect_format().
#define ADEMCO_MSG_TYPE_2 "98" |
Definition at line 122 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), and ademco_detect_format().
#define ADEMCO_MSG_TYPE_3 "17" |
Definition at line 123 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), and ademco_detect_format().
#define ADEMCO_MSG_TYPE_4 "27" |
Definition at line 124 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), and ademco_detect_format().
#define ADEMCO_MSG_TYPE_5 "55" |
Definition at line 125 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), and ademco_detect_format().
#define ADEMCO_MSG_TYPE_6 "56" |
Definition at line 126 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), and ademco_detect_format().
#define ADEMCO_SUPER_FAST "ADEMCO_SUPER_FAST" |
Definition at line 115 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), and ademco_detect_format().
#define ALMRCV_CONFIG "alarmreceiver.conf" |
Definition at line 68 of file app_alarmreceiver.c.
Referenced by load_config().
#define UNKNOWN_FORMAT "UNKNOWN_FORMAT" |
Definition at line 69 of file app_alarmreceiver.c.
Referenced by ademco_check_valid(), ademco_detect_format(), alarmreceiver_exec(), and receive_ademco_event().
typedef struct event_node event_node_t |
Definition at line 142 of file app_alarmreceiver.c.
|
static |
Definition at line 1000 of file app_alarmreceiver.c.
|
static |
Definition at line 1000 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 523 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 563 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 456 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 792 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 1000 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 208 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 868 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, sdtimeout, time_stamp_format, toneloudness, and value.
Referenced by load_module(), and reload().
|
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 974 of file app_alarmreceiver.c.
References alarmreceiver_exec(), app, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, and load_config().
Referenced by reload().
|
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 402 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 611 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 253 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 986 of file app_alarmreceiver.c.
References AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_EXTENDED, ASTERISK_GPL_KEY, load_config(), load_module(), and unload_module().
|
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 496 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 959 of file app_alarmreceiver.c.
References app, and ast_unregister_application().
Referenced by reload().
|
static |
Log a single event.
logfile | Log File Pointer |
event | Event Structure |
0 | success |
-1 | failure |
Definition at line 382 of file app_alarmreceiver.c.
References event_node::data, and 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 321 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, ast_bridge::name, no_group_meta, NULL, S_COR, and time_stamp_format.
Referenced by log_events().
|
static |
Definition at line 1000 of file app_alarmreceiver.c.
|
static |
Definition at line 184 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 1000 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 190 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_dsp_process(), ast_rtp_dtmf_begin(), ast_translate_number_ka(), ast_unreal_digit_begin(), ast_unreal_digit_end(), attended_transfer_exec(), bridge_channel_feature_digit_add(), chan_pjsip_pvt_dtor(), channel_dtmf_begin_cb(), channel_dtmf_end_cb(), collect_digits(), compare(), controlplayback_exec(), dahdi_chan_conf_default(), dahdi_digit_begin(), dial_exec_full(), dictate_exec(), directory_exec(), do_directory(), dtmf_end_to_json(), dtmf_stream(), handle_clear_alarms(), handle_incoming_request(), handle_keypad_button_message(), info_dtmf_data_alloc(), jb_debug_output(), keypad_cfg_read(), manager_play_dtmf(), manager_play_mf(), mgcp_senddigit_end(), misdn_digit_end(), moh_digit_match(), morsecode_exec(), ooh323_digit_begin(), phone_call(), phone_check_exception(), phone_exception(), play_file(), send_dtmf_begin_event(), send_dtmf_end_event(), store_digit(), test_dtmf_amplitude_sweep(), test_dtmf_twist_sweep(), try_calling(), unistim_do_senddigit(), and valid_exit().
struct { ... } digits_mapping[] |
Referenced by ademco_verify_checksum().
|
static |
Definition at line 189 of file app_alarmreceiver.c.
Referenced by alarmreceiver_exec(), and load_config().
|
static |
Definition at line 194 of file app_alarmreceiver.c.
Referenced by log_events().
|
static |
Definition at line 188 of file app_alarmreceiver.c.
Referenced by load_config(), and log_events().
|
static |
Definition at line 182 of file app_alarmreceiver.c.
Referenced by acf_faxopt_write(), load_config(), and receive_dtmf_digits().
|
static |
Definition at line 186 of file app_alarmreceiver.c.
Referenced by alarmreceiver_exec(), load_config(), and receive_ademco_event().
|
static |
Definition at line 187 of file app_alarmreceiver.c.
Referenced by load_config(), write_event(), and write_metadata().
|
static |
Definition at line 183 of file app_alarmreceiver.c.
Referenced by load_config(), and receive_dtmf_digits().
Definition at line 191 of file app_alarmreceiver.c.
Referenced by load_config(), and write_metadata().
|
static |
Definition at line 185 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 cache_lookup_internal(), dns_srv_alloc(), dns_srv_sort(), dundi_lookup_thread(), dundi_show_cache(), dundi_show_mappings(), precache_trans(), and srv_result_read().