[Asterisk-code-review] sig_analog: Changes to improve electromechanical signalling compatibi... (asterisk[18])

Friendly Automation asteriskteam at digium.com
Fri Aug 20 22:54:21 CDT 2021


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16367 )

Change subject: sig_analog: Changes to improve electromechanical signalling compatibility
......................................................................

sig_analog: Changes to improve electromechanical signalling compatibility

This changeset is intended to address compatibility issues encountered
when interfacing Asterisk to electromechanical telephone switches that
implement ANI-B, ANI-C, or ANI-D.

In particular the behaviours that this impacts include:

 - FGC-CAMA did not work at all when using MF signaling. Modified the
   switch case block to send calls to the correct part of the
   signaling-handling state machine.

 - For FGC-CAMA operation, the delay between called number ST and
   second wink for ANI spill has been made configurable; previously
   all calls were made to wait for one full second.

 - After the ANI spill, previous behavior was to require a 'ST' tone
   to advance the call.  This has been changed to allow 'STP' 'ST2P'
   or 'ST3P' as well, for compatibility with ANI-D.

 - Store ANI2 (ANI INFO) digits in the CALLERID(ANI2) channel variable.

 - For calls with an ANI failure, No. 1 Crossbar switches will send
   forward a single-digit failure code, with no calling number digits
   and no ST pulse to terminate the spill.  I've made the ANI timeout
   configurable so to reduce dead air time on calls with ANI fail.

 - ANI info digits configurable.  Modern digital switches will send 2
   digits, but ANI-B sends only a single info digit.  This caused the
   ANI reported by Asterisk to be misaligned.

 - Changed a confusing log message to be more informative.

ASTERISK-29518

Change-Id: Ib7e27d987aee4ed9bc3663c57ef413e21b404256
---
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
5 files changed, 106 insertions(+), 10 deletions(-)

Approvals:
  N A: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 2c7b673..74c76f7 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -953,6 +953,10 @@
 			.parkinglot = "",
 			.transfertobusy = 1,
 
+			.ani_info_digits = 2,
+			.ani_wink_time = 1000,
+			.ani_timeout = 10000,
+
 			.cid_signalling = CID_SIG_BELL,
 			.cid_start = CID_START_RING,
 			.dahditrcallerid = 0,
@@ -12839,6 +12843,9 @@
 
 		tmp->polarityonanswerdelay = conf->chan.polarityonanswerdelay;
 		tmp->answeronpolarityswitch = conf->chan.answeronpolarityswitch;
+		tmp->ani_info_digits = conf->chan.ani_info_digits;
+		tmp->ani_wink_time = conf->chan.ani_wink_time;
+		tmp->ani_timeout = conf->chan.ani_timeout;
 		tmp->hanguponpolarityswitch = conf->chan.hanguponpolarityswitch;
 		tmp->sendcalleridafter = conf->chan.sendcalleridafter;
 		ast_cc_copy_config_params(tmp->cc_params, conf->chan.cc_params);
@@ -12944,6 +12951,9 @@
 				analog_p->channel = tmp->channel;
 				analog_p->polarityonanswerdelay = conf->chan.polarityonanswerdelay;
 				analog_p->answeronpolarityswitch = conf->chan.answeronpolarityswitch;
+				analog_p->ani_info_digits = conf->chan.ani_info_digits;
+				analog_p->ani_timeout = conf->chan.ani_timeout;
+				analog_p->ani_wink_time = conf->chan.ani_wink_time;
 				analog_p->hanguponpolarityswitch = conf->chan.hanguponpolarityswitch;
 				analog_p->permcallwaiting = conf->chan.callwaiting; /* permcallwaiting possibly modified in analog_config_complete */
 				analog_p->callreturn = conf->chan.callreturn;
@@ -18241,6 +18251,12 @@
 			confp->chan.polarityonanswerdelay = atoi(v->value);
 		} else if (!strcasecmp(v->name, "answeronpolarityswitch")) {
 			confp->chan.answeronpolarityswitch = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "ani_info_digits")) {
+			confp->chan.ani_info_digits = atoi(v->value);
+		} else if (!strcasecmp(v->name, "ani_wink_time")) {
+			confp->chan.ani_wink_time = atoi(v->value);
+		} else if (!strcasecmp(v->name, "ani_timeout")) {
+			confp->chan.ani_timeout = atoi(v->value);
 		} else if (!strcasecmp(v->name, "hanguponpolarityswitch")) {
 			confp->chan.hanguponpolarityswitch = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "sendcalleridafter")) {
diff --git a/channels/chan_dahdi.h b/channels/chan_dahdi.h
index f98ebdc..de813f2 100644
--- a/channels/chan_dahdi.h
+++ b/channels/chan_dahdi.h
@@ -182,6 +182,22 @@
 	 */
 	unsigned int answeronpolarityswitch:1;
 	/*!
+	 * \brief INTEGER, number of ANI INFO digits on a CAMA trunk.
+	 * older switches use 1 INFO digit, newer switches use 2 INFO digits
+	 * \note Set from the "ani_info_digits" value read in from chan_dahdi.conf
+	 */
+	unsigned int ani_info_digits:8;
+	/*!
+	 * \brief INTEGER, length of ANI failure timeout in ms.
+	 * \note Set from the "ani_timeout" value read in from chan_dahdi.conf
+	 */
+	unsigned int ani_timeout:16;
+	/*!
+	 * \brief INTEGER, length of time to wait before sending ANI wink in ms.
+	 * \note Set from the "ani_wink_time" value read in from chan_dahdi.conf
+	 */
+	unsigned int ani_wink_time:16;
+	/*!
 	 * \brief TRUE if busy detection is enabled.
 	 * (Listens for the beep-beep busy pattern.)
 	 * \note Set from the "busydetect" value read in from chan_dahdi.conf
diff --git a/channels/sig_analog.c b/channels/sig_analog.c
index 4356e02..5bb5649 100644
--- a/channels/sig_analog.c
+++ b/channels/sig_analog.c
@@ -1864,7 +1864,6 @@
 					if (p->sig == ANALOG_SIG_E911) {
 						analog_off_hook(p);
 					}
-					res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000);
 				}
 				if (res < 1) {
 					analog_dsp_reset_and_flush_digits(p);
@@ -1927,21 +1926,64 @@
 			goto quit;
 		}
 
-		if (p->sig == ANALOG_SIG_FGC_CAMA) {
-			char anibuf[100];
+		if (p->sig == ANALOG_SIG_FGC_CAMA || p->sig == ANALOG_SIG_FGC_CAMAMF) {
+			/* This if block is where we process ANI for CAMA */
 
-			if (ast_safe_sleep(chan,1000) == -1) {
+			char anibuf[100];
+			struct ast_party_caller *caller;
+
+			/* cnoffset is the point at which we pull the calling number out
+			 * of anibuf. Must be the number of ani_info_digits + 1 to account
+			 * for the KP, which is considered a digit.  */
+
+			/* The 1XB with ANI-B will send a full 10 digits
+			*  or 2 digits in case of ANI failure.
+			* (CD-95811-01 Section II, page 10)
+			* 10 digit string example:  *08320123#
+			* 2 digit string example:   *2
+			* KP (*) and ST (#) are considered to be digits */
+
+			int cnoffset = p->ani_info_digits + 1;
+			ast_debug(1, "cnoffset: %d\n", cnoffset);
+
+			/* This is how long to wait before the wink to start ANI spill
+			 * Pulled from chan_dahdi.conf, default is 1000ms */
+			if (ast_safe_sleep(chan,p->ani_wink_time) == -1) {
 				ast_hangup(chan);
 				goto quit;
 			}
 			analog_off_hook(p);
+			ast_debug(1, "Sent wink to signal ANI start\n");
 			analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_MF);
-			res = analog_my_getsigstr(chan, anibuf, "#", 10000);
-			if ((res > 0) && (strlen(anibuf) > 2)) {
-				if (anibuf[strlen(anibuf) - 1] == '#') {
+
+			/* ani_timeout is configured in chan_dahdi.conf. default is 10000ms.
+			 * ST, STP, ST2P, ST3P can all signal transmission complete, regardless of timeout */
+			res = analog_my_getsigstr(chan, anibuf, "#ABC", p->ani_timeout);
+
+			/* so we can work with the ani buffer */
+			pbx_builtin_setvar_helper(chan, "ANIBUF", anibuf);
+
+			/* as long as we get a terminating pulse OR the length of ANI buffer is at least >=2, we can treat
+			 * this as a complete spill for the purposes of setting anistart */
+			if ((res > 0) || (strlen(anibuf) >= 2)) {
+				char anistart[2] = "X";
+				char f[10] = {0};
+				if (strchr("#ABC", anibuf[strlen(anibuf) - 1])) {
+					anistart[0] = anibuf[strlen(anibuf) - 1];
 					anibuf[strlen(anibuf) - 1] = 0;
 				}
-				ast_set_callerid(chan, anibuf + 2, NULL, anibuf + 2);
+				ast_set_callerid(chan, anibuf + cnoffset, NULL, anibuf + cnoffset);
+
+				caller = ast_channel_caller(chan);
+				strncpy(f, &(anibuf[1]), MIN((int)(p->ani_info_digits), sizeof(f)-1));
+				caller->ani2 = atoi(f);
+
+				anibuf[cnoffset] = 0;
+
+				/* so we can work with the different start pulses as used in ANI-D */
+				pbx_builtin_setvar_helper(chan, "ANISTART", anistart);
+				/* so we can use our ANI INFO digits in our dialplan */
+				pbx_builtin_setvar_helper(chan, "ANI2", anibuf + 1);
 			}
 			analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_DTMF);
 		}
@@ -2023,7 +2065,7 @@
 					ast_copy_string(exten, "911", sizeof(exten));
 				}
 			} else {
-				ast_log(LOG_WARNING, "Got a non-E911/FGC CAMA input on channel %d.  Assuming E&M Wink instead\n", p->channel);
+				ast_log(LOG_WARNING, "A KP was expected to start signaling for Feature Group C CAMA-MF, but we got something else. Received: %s on channel %d\n", exten, p->channel);
 			}
 		}
 		if (p->sig == ANALOG_SIG_FEATB) {
@@ -2035,7 +2077,7 @@
 				s1 = strsep(&stringp, "#");
 				ast_copy_string(exten, exten2 + 1, sizeof(exten));
 			} else {
-				ast_log(LOG_WARNING, "Got a non-Feature Group B input on channel %d.  Assuming E&M Wink instead\n", p->channel);
+				ast_log(LOG_WARNING, "A KP was expected to start signaling for Feature Group B, but we got something else. Received: %s on channel %d\n", exten, p->channel);
 			}
 		}
 		if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
diff --git a/channels/sig_analog.h b/channels/sig_analog.h
index 3b9dcf5..488be36 100644
--- a/channels/sig_analog.h
+++ b/channels/sig_analog.h
@@ -277,6 +277,10 @@
 	int msgstate;
 
 	/* XXX: Option Variables - Set by allocator of private structure */
+	unsigned int ani_info_digits:8;			/* Older switches use 1 INFO digit, newer switches use 2 */
+	unsigned int ani_timeout:16;			/* Time in ms before we give up waiting for ANI spill */
+	unsigned int ani_wink_time:16;			/* Safe wait time before we wink to start ANI spill */
+
 	unsigned int answeronpolarityswitch:1;
 	unsigned int callreturn:1;
 	unsigned int cancallforward:1;
diff --git a/configs/samples/chan_dahdi.conf.sample b/configs/samples/chan_dahdi.conf.sample
index d24c22b..5c1d2ee 100644
--- a/configs/samples/chan_dahdi.conf.sample
+++ b/configs/samples/chan_dahdi.conf.sample
@@ -1098,6 +1098,24 @@
 ; The default is -1: not to set anything.
 ;tonezone = 0 ; 0 is US
 ;
+; The number of ANI info digits to expect before the main ANI spill.
+; Switches using ANI-B, -C, and -D will usually send 1 digit. Modern digital
+; systems will send 2, following NANPA ANI II requirements.
+;
+;ani_info_digits=2
+;
+; Time in ms to wait before asterisk sends wink to start ANI spill. Can be
+; shortened if your switch supports it.
+;
+;ani_wink_time=1000
+;
+; Time in ms to wait for each digit in the spill including the ST pulse.
+; This value can affect how long it takes to recognize ANI failures that do
+; not send a ST pulse. If ANI failures take too long to recognize, you can
+; lower this value.
+;
+;ani_timeout=10000
+;
 ; FXO (FXS signalled) devices must have a timeout to determine if there was a
 ; hangup before the line was answered.  This value can be tweaked to shorten
 ; how long it takes before DAHDI considers a non-ringing line to have hungup.

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16367
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: Ib7e27d987aee4ed9bc3663c57ef413e21b404256
Gerrit-Change-Number: 16367
Gerrit-PatchSet: 2
Gerrit-Owner: Sarah Autumn <sarah at endlesstemple.org>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210820/ede36890/attachment-0001.html>


More information about the asterisk-code-review mailing list