[Asterisk-code-review] chan dahdi: Configurable dialed digit timeouts (asterisk[master])
Tzafrir Cohen
asteriskteam at digium.com
Thu Mar 22 12:32:14 CDT 2018
Tzafrir Cohen has uploaded this change for review. ( https://gerrit.asterisk.org/8637
Change subject: chan_dahdi: Configurable dialed digit timeouts
......................................................................
chan_dahdi: Configurable dialed digit timeouts
Analog phones dial overlap dialing and it is chan_dahdi's job to read
the numbers. It has three timeout constants, that this commit convert to
channel-level configuration options.
* firstdigit_timeout: delay before the first digit is dialed
* gendigit_timeout: the delay after a digit has been dialed, if current
digit does not match an extension in the current dialplan context.
* matchdigit_timeout: the delay after a digit has been dialed, if current
digit matches an extension in the current dialplan context.
Change-Id: Ib728fa900a4f6ae56d1ed810aba61b6593fb7213
---
M UPGRADE.txt
M channels/chan_dahdi.c
M channels/chan_dahdi.h
M channels/sig_analog.c
M channels/sig_analog.h
M configs/samples/chan_dahdi.conf.sample
6 files changed, 105 insertions(+), 29 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/37/8637/1
diff --git a/UPGRADE.txt b/UPGRADE.txt
index 108c10a..a604af9 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -50,6 +50,10 @@
MALLOC_DEBUG and vice versa. Third-party pre-compiled modules no longer
need to have a special build with it enabled.
+chan_dahdi:
+ - Timeouts for reading digits from analog phones are now configurable in
+ chan_dahdi.conf: firstdigit_timeout, gendigit_timeout, matchdigit_timeout.
+
cdr_syslog:
- The cdr_syslog module is now deprecated and by default it is no longer
built.
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 37e2774..e39184b 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -554,6 +554,10 @@
#define CALLPROGRESS_FAX_INCOMING 4
#define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
+#define DEFAULT_FIRST_DIGIT_TIMEOUT 16000
+#define DEFAULT_GEN_DIGIT_TIMEOUT 8000
+#define DEFAULT_MATCH_DIGIT_TIMEOUT 3000
+
#define NUM_CADENCE_MAX 25
static int num_cadence = 4;
static int user_has_defined_cadences = 0;
@@ -614,15 +618,6 @@
static int pridebugfd = -1;
static char pridebugfilename[1024] = "";
#endif
-
-/*! \brief Wait up to 16 seconds for first digit (FXO logic) */
-static int firstdigittimeout = 16000;
-
-/*! \brief How long to wait for following digits (FXO logic) */
-static int gendigittimeout = 8000;
-
-/*! \brief How long to wait for an extra digit, if there is an ambiguous match */
-static int matchdigittimeout = 3000;
/*! \brief Protect the interface list (of dahdi_pvt's) */
AST_MUTEX_DEFINE_STATIC(iflock);
@@ -977,6 +972,9 @@
.buf_no = numbufs,
.usefaxbuffers = 0,
.cc_params = ast_cc_config_params_init(),
+ .firstdigit_timeout = DEFAULT_FIRST_DIGIT_TIMEOUT,
+ .gendigit_timeout = DEFAULT_GEN_DIGIT_TIMEOUT,
+ .matchdigit_timeout = DEFAULT_MATCH_DIGIT_TIMEOUT,
},
.timing = {
.prewinktime = -1,
@@ -3326,6 +3324,22 @@
}
}
+#define get_pvt_field_callback(type, field, def_value) \
+ static type my_get_##field(void *pvt) \
+ { \
+ struct dahdi_pvt *p = pvt; \
+ if (!p) { \
+ return def_value; \
+ } \
+ return p->field; \
+ }
+
+get_pvt_field_callback(int, firstdigit_timeout, 0);
+get_pvt_field_callback(int, matchdigit_timeout, 0);
+get_pvt_field_callback(int, gendigit_timeout, 0);
+
+#undef get_pvt_field_callback
+
struct analog_callback analog_callbacks =
{
.play_tone = my_play_tone,
@@ -3394,6 +3408,9 @@
.answer_polarityswitch = my_answer_polarityswitch,
.hangup_polarityswitch = my_hangup_polarityswitch,
.have_progressdetect = my_have_progressdetect,
+ .get_firstdigit_timeout = my_get_firstdigit_timeout,
+ .get_matchdigit_timeout = my_get_matchdigit_timeout,
+ .get_gendigit_timeout = my_get_gendigit_timeout,
};
/*! Round robin search locations. */
@@ -9555,9 +9572,9 @@
dtmfbuf[len] = '\0';
while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
- timeout = matchdigittimeout;
+ timeout = p->matchdigit_timeout;
} else {
- timeout = gendigittimeout;
+ timeout = p->gendigit_timeout;
}
res = ast_waitfordigit(chan, timeout);
if (res < 0) {
@@ -9725,7 +9742,7 @@
case SIG_FXOGS:
case SIG_FXOKS:
/* Read the first digit */
- timeout = firstdigittimeout;
+ timeout = p->firstdigit_timeout;
/* If starting a threeway call, never timeout on the first digit so someone
can use flash-hook as a "hold" feature */
if (p->subs[SUB_THREEWAY].owner)
@@ -9800,8 +9817,8 @@
}
} else {
/* It's a match, but they just typed a digit, and there is an ambiguous match,
- so just set the timeout to matchdigittimeout and wait some more */
- timeout = matchdigittimeout;
+ so just set the timeout to matchdigit_timeout and wait some more */
+ timeout = p->matchdigit_timeout;
}
} else if (res == 0) {
ast_debug(1, "not enough digits (and no ambiguous match)...\n");
@@ -9821,7 +9838,7 @@
len = 0;
ioctl(p->subs[idx].dfd,DAHDI_CONFDIAG,&len);
memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
+ timeout = p->firstdigit_timeout;
} else if (!strcmp(exten, pickupexten)) {
/* Scan all channels and see if there are any
@@ -9866,7 +9883,7 @@
}
len = 0;
memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
+ timeout = p->firstdigit_timeout;
} else if (p->callreturn && !strcmp(exten, "*69")) {
res = tone_zone_play_tone(p->subs[idx].dfd, DAHDI_TONE_DIALRECALL);
break;
@@ -9938,7 +9955,7 @@
}
len = 0;
memset(exten, 0, sizeof(exten));
- timeout = firstdigittimeout;
+ timeout = p->firstdigit_timeout;
} else if (!strcmp(exten, "*0")) {
struct ast_channel *nbridge =
p->subs[SUB_THREEWAY].owner;
@@ -9986,7 +10003,7 @@
break;
}
if (!timeout)
- timeout = gendigittimeout;
+ timeout = p->gendigit_timeout;
if (len && !ast_ignore_pattern(ast_channel_context(chan), exten))
tone_zone_play_tone(p->subs[idx].dfd, -1);
}
@@ -12501,6 +12518,9 @@
tmp->waitfordialtone = conf->chan.waitfordialtone;
tmp->dialtone_detect = conf->chan.dialtone_detect;
tmp->faxdetect_timeout = conf->chan.faxdetect_timeout;
+ tmp->firstdigit_timeout = conf->chan.firstdigit_timeout;
+ tmp->gendigit_timeout = conf->chan.gendigit_timeout;
+ tmp->matchdigit_timeout = conf->chan.matchdigit_timeout;
tmp->cancallforward = conf->chan.cancallforward;
tmp->dtmfrelax = conf->chan.dtmfrelax;
tmp->callwaiting = tmp->permcallwaiting;
@@ -17713,6 +17733,18 @@
if (sscanf(v->value, "%30u", &confp->chan.faxdetect_timeout) != 1) {
confp->chan.faxdetect_timeout = 0;
}
+ } else if (!strcasecmp(v->name, "firstdigit_timeout")) {
+ if (sscanf(v->value, "%30u", &confp->chan.firstdigit_timeout) != 1) {
+ confp->chan.firstdigit_timeout = DEFAULT_FIRST_DIGIT_TIMEOUT;
+ }
+ } else if (!strcasecmp(v->name, "gendigit_timeout")) {
+ if (sscanf(v->value, "%30u", &confp->chan.gendigit_timeout) != 1) {
+ confp->chan.gendigit_timeout = DEFAULT_GEN_DIGIT_TIMEOUT;
+ }
+ } else if (!strcasecmp(v->name, "matchdigit_timeout")) {
+ if (sscanf(v->value, "%30u", &confp->chan.matchdigit_timeout) != 1) {
+ confp->chan.matchdigit_timeout = DEFAULT_MATCH_DIGIT_TIMEOUT;
+ }
} else if (!strcasecmp(v->name, "echocancel")) {
process_echocancel(confp, v->value, v->lineno);
} else if (!strcasecmp(v->name, "echotraining")) {
diff --git a/channels/chan_dahdi.h b/channels/chan_dahdi.h
index ab5c1eb..40e2e78 100644
--- a/channels/chan_dahdi.h
+++ b/channels/chan_dahdi.h
@@ -617,6 +617,20 @@
* \note Set from the "faxdetect_timeout" value read in from chan_dahdi.conf
*/
unsigned int faxdetect_timeout;
+ /*! \brief Time (ms) to wait for first digit in an analog phone
+ * \note Set from the "firstdigit_timeout" value read in from chan_dahdi.conf
+ */
+ int firstdigit_timeout;
+
+ /*! \brief Time (ms) to wait for following digits in an analog phone
+ * \note Set from the "gendigit_timeout" value read in from chan_dahdi.conf
+ */
+ int gendigit_timeout;
+
+ /*! \brief Time (ms) to wait for an extra digit, if there is an ambiguous match
+ * \note Set from the "matchdigit_timeout" value read in from chan_dahdi.conf
+ */
+ int matchdigit_timeout;
struct timeval waitingfordt; /*!< Time we started waiting for dialtone */
struct timeval flashtime; /*!< Last flash-hook time */
/*! \brief Opaque DSP configuration structure. */
diff --git a/channels/sig_analog.c b/channels/sig_analog.c
index 110942c..76b623e 100644
--- a/channels/sig_analog.c
+++ b/channels/sig_analog.c
@@ -62,9 +62,6 @@
#define POLARITY_IDLE 0
#define POLARITY_REV 1
#define MIN_MS_SINCE_FLASH ( (2000) ) /*!< 2000 ms */
-static int analog_matchdigittimeout = 3000;
-static int analog_gendigittimeout = 8000;
-static int analog_firstdigittimeout = 16000;
static char analog_defaultcic[64] = "";
static char analog_defaultozz[64] = "";
@@ -218,6 +215,18 @@
/* Don't have progress detection. */
return 0;
}
+
+#define analog_get_field_callback(type, callback_name, def_value) \
+ static type analog_get_##callback_name(struct analog_pvt *p) \
+ { \
+ if (!analog_callbacks.get_##callback_name) { \
+ return def_value; \
+ } \
+ return analog_callbacks.get_##callback_name(p->chan_pvt); \
+ }
+analog_get_field_callback(int, firstdigit_timeout, 0);
+analog_get_field_callback(int, matchdigit_timeout, 0);
+analog_get_field_callback(int, gendigit_timeout, 0);
enum analog_cid_start analog_str_to_cidstart(const char *value)
{
@@ -1886,9 +1895,9 @@
dtmfbuf[len] = '\0';
while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
- timeout = analog_matchdigittimeout;
+ timeout = analog_get_matchdigit_timeout(p);
} else {
- timeout = analog_gendigittimeout;
+ timeout = analog_get_gendigit_timeout(p);
}
res = ast_waitfordigit(chan, timeout);
if (res < 0) {
@@ -2074,7 +2083,7 @@
case ANALOG_SIG_FXOGS:
case ANALOG_SIG_FXOKS:
/* Read the first digit */
- timeout = analog_firstdigittimeout;
+ timeout = analog_get_firstdigit_timeout(p);
/* If starting a threeway call, never timeout on the first digit so someone
can use flash-hook as a "hold" feature */
if (p->subs[ANALOG_SUB_THREEWAY].owner) {
@@ -2155,7 +2164,7 @@
} else {
/* It's a match, but they just typed a digit, and there is an ambiguous match,
so just set the timeout to analog_matchdigittimeout and wait some more */
- timeout = analog_matchdigittimeout;
+ timeout = analog_get_matchdigit_timeout(p);
}
} else if (res == 0) {
ast_debug(1, "not enough digits (and no ambiguous match)...\n");
@@ -2174,7 +2183,7 @@
}
len = 0;
memset(exten, 0, sizeof(exten));
- timeout = analog_firstdigittimeout;
+ timeout = analog_get_firstdigit_timeout(p);
} else if (!strcmp(exten, pickupexten)) {
/* Scan all channels and see if there are any
@@ -2219,7 +2228,7 @@
}
len = 0;
memset(exten, 0, sizeof(exten));
- timeout = analog_firstdigittimeout;
+ timeout = analog_get_firstdigit_timeout(p);
} else if (p->callreturn && !strcmp(exten, "*69")) {
res = 0;
if (!ast_strlen_zero(p->lastcid_num)) {
@@ -2305,7 +2314,7 @@
}
len = 0;
memset(exten, 0, sizeof(exten));
- timeout = analog_firstdigittimeout;
+ timeout = analog_get_firstdigit_timeout(p);
} else if (!strcmp(exten, "*0")) {
struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner;
struct analog_pvt *pbridge = NULL;
@@ -2348,7 +2357,7 @@
break;
}
if (!timeout) {
- timeout = analog_gendigittimeout;
+ timeout = analog_get_gendigit_timeout(p);
}
if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) {
analog_play_tone(p, idx, -1);
diff --git a/channels/sig_analog.h b/channels/sig_analog.h
index 42e00c0..8557039 100644
--- a/channels/sig_analog.h
+++ b/channels/sig_analog.h
@@ -237,6 +237,9 @@
const char *(* const get_orig_dialstring)(void *pvt);
int (* const have_progressdetect)(void *pvt);
+ int (* const get_firstdigit_timeout)(void *pvt);
+ int (* const get_matchdigit_timeout)(void *pvt);
+ int (* const get_gendigit_timeout)(void *pvt);
};
/*! Global analog callbacks to the upper layer. */
diff --git a/configs/samples/chan_dahdi.conf.sample b/configs/samples/chan_dahdi.conf.sample
index 3c5e18d..6d2e5eb 100644
--- a/configs/samples/chan_dahdi.conf.sample
+++ b/configs/samples/chan_dahdi.conf.sample
@@ -1137,6 +1137,20 @@
;
;faxbuffers=>6,full
;
+; When FXO signalling (FXS device, e.g. analog phone) is used, overlap dialing
+; is typically used. Asterisk has several configurable (per-channel) timeouts
+; to know how long to wait for the next digit. All the values are in
+; milliseconds.
+; * firstdigit_timeout: a longer timeout before any digit is dialed.
+; By default: 16 seconds.
+; * gendigit_timeout: timeout for next digits, if the current number dialed
+; does not match a number in the current context. Default: 8 seconds.
+; * matchdigit_timeout: timeout for next digits, if the current number dialed
+; matches a number in the current context. Default: 3 seconds.
+;firstdigit_timeout=16000
+;gendigit_timeout=8000
+;matchdigit_timeout=3000
+;
; Configure the default number of DAHDI buffers and the transmit policy to use.
; This can be used to eliminate data drops when scheduling jitter prevents
; Asterisk from writing to a DAHDI channel regularly. Most users will probably
--
To view, visit https://gerrit.asterisk.org/8637
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib728fa900a4f6ae56d1ed810aba61b6593fb7213
Gerrit-Change-Number: 8637
Gerrit-PatchSet: 1
Gerrit-Owner: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180322/6f1482f8/attachment-0001.html>
More information about the asterisk-code-review
mailing list