From af07dc888306930320cc5c77e5e9233a530eefca Mon Sep 17 00:00:00 2001 From: Matthew Fredrickson Date: Fri, 10 Feb 2006 21:50:56 +0000 Subject: Add smdi support for asterisk (see doc/smdi.txt for config info) (#5945) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@9423 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_zap.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 8 deletions(-) (limited to 'channels/chan_zap.c') diff --git a/channels/chan_zap.c b/channels/chan_zap.c index 1eca4706e..a078c63fa 100644 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -101,6 +101,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" #include "asterisk/transcap.h" #include "asterisk/stringfields.h" +#ifdef WITH_SMDI +#include "asterisk/smdi.h" +#include "asterisk/astobj.h" +#define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */ +#endif #ifndef ZT_SIG_HARDHDLC #error "Your zaptel is too old. please update" @@ -279,7 +284,10 @@ static char mailbox[AST_MAX_EXTENSION]; static int amaflags = 0; static int adsi = 0; - +#ifdef WITH_SMDI +static int use_smdi = 0; +static char smdi_port[SMDI_MAX_FILENAME_LEN] = "/dev/ttyS0"; +#endif static int numbufs = 4; static int cur_prewink = -1; @@ -605,6 +613,10 @@ static struct zt_pvt { unsigned int r2blocked:1; unsigned int sigchecked:1; #endif +#ifdef WITH_SMDI + unsigned int use_smdi:1; /* Whether to use SMDI on this channel */ + struct ast_smdi_interface *smdi_iface; /* The serial port to listen for SMDI data on */ +#endif struct zt_distRings drings; @@ -2165,6 +2177,10 @@ static void destroy_zt_pvt(struct zt_pvt **pvt) p->prev->next = p->next; if(p->next) p->next->prev = p->prev; +#ifdef WITH_SMDI + if(p->use_smdi) + ASTOBJ_UNREF(p->smdi_iface, ast_smdi_interface_destroy); +#endif ast_mutex_destroy(&p->lock); free(p); *pvt = NULL; @@ -5274,7 +5290,7 @@ static void *ss_thread(void *data) unsigned char buf[256]; char dtmfcid[300]; char dtmfbuf[300]; - struct callerid_state *cs; + struct callerid_state *cs=NULL; char *name=NULL, *number=NULL; int distMatches; int curRingData[3]; @@ -5282,7 +5298,9 @@ static void *ss_thread(void *data) int counter1; int counter; int samples = 0; - +#ifdef WITH_SMDI + struct ast_smdi_md_message *smdi_msg = NULL; +#endif int flags; int i; int timeout; @@ -5928,10 +5946,35 @@ lax); } } #endif +#ifdef WITH_SMDI + /* check for SMDI messages */ + if(p->use_smdi && p->smdi_iface) { + smdi_msg = ast_smdi_md_message_wait(p->smdi_iface, SMDI_MD_WAIT_TIMEOUT); + + if(smdi_msg != NULL) { + ast_copy_string(chan->exten, smdi_msg->fwd_st, sizeof(chan->exten)); + + if (smdi_msg->type == 'B') + pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b"); + else if (smdi_msg->type == 'N') + pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u"); + + ast_log(LOG_DEBUG, "Recieved SMDI message on %s\n", chan->name); + } else { + ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n"); + } + } + + if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) { + number = smdi_msg->calling_st; + /* If we want caller id, we're in a prering state due to a polarity reversal * and we're set to use a polarity reversal to trigger the start of caller id, * grab the caller id and wait for ringing to start... */ + } else if (p->use_callerid && (chan->_state == AST_STATE_PRERING && p->cid_start == CID_START_POLARITY)) { +#else if (p->use_callerid && (chan->_state == AST_STATE_PRERING && p->cid_start == CID_START_POLARITY)) { +#endif /* If set to use DTMF CID signalling, listen for DTMF */ if (p->cid_signalling == CID_SIG_DTMF) { int i = 0; @@ -6297,7 +6340,10 @@ lax); ast_shrink_phone_number(number); ast_set_callerid(chan, number, name, number); - +#ifdef WITH_SMDI + if (smdi_msg) + ASTOBJ_UNREF(smdi_msg, ast_smdi_md_message_destroy); +#endif if (cs) callerid_free(cs); ast_setstate(chan, AST_STATE_RING); @@ -7274,6 +7320,9 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p tmp->callwaitingcallerid = callwaitingcallerid; tmp->threewaycalling = threewaycalling; tmp->adsi = adsi; +#ifdef WITH_SMDI + tmp->use_smdi = use_smdi; +#endif tmp->permhidecallerid = hidecallerid; tmp->callreturn = callreturn; tmp->echocancel = echocancel; @@ -7306,6 +7355,22 @@ static struct zt_pvt *mkintf(int channel, int signalling, int radio, struct zt_p } } +#ifdef WITH_SMDI + if (tmp->cid_signalling == CID_SIG_SMDI) { + if (!tmp->use_smdi) { + ast_log(LOG_WARNING, "SMDI callerid requires SMDI to be enabled, enabling...\n"); + tmp->use_smdi = 1; + } + } + if (tmp->use_smdi) { + tmp->smdi_iface = ast_smdi_interface_find(smdi_port); + if (!(tmp->smdi_iface)) { + ast_log(LOG_ERROR, "Invalid SMDI port specfied, disabling SMDI support\n"); + tmp->use_smdi = 0; + } + } +#endif + ast_copy_string(tmp->accountcode, accountcode, sizeof(tmp->accountcode)); tmp->amaflags = amaflags; if (!here) { @@ -10479,12 +10544,12 @@ static int setup_zap(int reload) cid_signalling = CID_SIG_V23; else if (!strcasecmp(v->value, "dtmf")) cid_signalling = CID_SIG_DTMF; +#ifdef WITH_SMDI + else if (!strcasecmp(v->value, "smdi")) + cid_signalling = CID_SIG_SMDI; +#endif else if (!strcasecmp(v->value, "v23_jp")) -#ifdef ZT_EVENT_RINGBEGIN cid_signalling = CID_SIG_V23_JP; -#else - ast_log(LOG_WARNING, "Asterisk compiled aginst Zaptel version too old to support japanese CallerID!\n"); -#endif else if (ast_true(v->value)) cid_signalling = CID_SIG_BELL; } else if (!strcasecmp(v->name, "cidstart")) { @@ -10507,6 +10572,12 @@ static int setup_zap(int reload) ast_copy_string(mailbox, v->value, sizeof(mailbox)); } else if (!strcasecmp(v->name, "adsi")) { adsi = ast_true(v->value); +#ifdef WITH_SMDI + } else if (!strcasecmp(v->name, "usesmdi")) { + use_smdi = ast_true(v->value); + } else if (!strcasecmp(v->name, "smdiport")) { + ast_copy_string(smdi_port, v->value, sizeof(smdi_port)); +#endif } else if (!strcasecmp(v->name, "transfer")) { transfer = ast_true(v->value); } else if (!strcasecmp(v->name, "canpark")) { -- cgit v1.2.3