From d2585d6da2d30f116ef99339f79ce502f78697d4 Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Fri, 1 Jul 2016 13:07:17 -0500 Subject: [PATCH] q931.c: Lucent switch implementation bug workaround. A bug in a Lucent switch implementation sets the Connected Number information element octet 3 extension bit. When set that means octet 3 is complete and thus there is no optional octet 3a. However, the buggy switch still sends octet 3a. The unexpected octet 3a is interpreted as the first octet 4 and thus the first character in the connected line number is a garbage character. * Work around the switch bug by checking octet 3 and the potential octet 3a extension bits. If they are both set then assume that octet 3a is actually present for the buggy switch types. PRI-183 #close Reported by: Richard Mudgett Change-Id: I378af37bfd852737a0bfe6263ef3473ea6acfbad --- q931.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/q931.c b/q931.c index b25e951..98d6596 100644 --- a/q931.c +++ b/q931.c @@ -2351,7 +2351,30 @@ static int receive_connected_number(int full_ie, struct pri *ctrl, q931_call *ca switch (i) { case 0: call->remote_id.number.plan = ie->data[i] & 0x7f; - break; + + /* + * Work around a bug in a Lucent switch implementation that + * sets the extension bit in octet 3 even though octet 3a + * is present. + */ + if (ie->data[i] & 0x80) { + /* Octet 3 extension bit is set */ + if (ctrl->switchtype != PRI_SWITCH_LUCENT5E + && ctrl->switchtype != PRI_SWITCH_ATT4ESS) { + /* Not a potentially buggy switch type. */ + break; + } + if (!(ie->data[i + 1] & 0x80)) { + /* + * The possible octet 3a doesn't have the extension + * bit set. It is likely not the erroneous octet 3a. + */ + break; + } + } + /* Octet 3a is present */ + ++i; + /* Fall through */ case 1: /* Keep only the presentation and screening fields */ call->remote_id.number.presentation = @@ -2393,7 +2416,35 @@ static void dump_connected_number(int full_ie, struct pri *ctrl, q931_ie *ie, in prefix, ie2str(full_ie), len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f); - break; + + /* + * Work around a bug in a Lucent switch implementation that + * sets the extension bit in octet 3 even though octet 3a + * is present. + */ + if (ie->data[i] & 0x80) { + /* Octet 3 extension bit is set */ + if (ctrl->switchtype != PRI_SWITCH_LUCENT5E + && ctrl->switchtype != PRI_SWITCH_ATT4ESS) { + /* Not a potentially buggy switch type. */ + break; + } + if (!(ie->data[i + 1] & 0x80)) { + /* + * The possible octet 3a doesn't have the extension + * bit set. It is likely not the erroneous octet 3a. + */ + break; + } + pri_message(ctrl, "\n"); + pri_message(ctrl, "%c Switch bug workaround.\n", + prefix); + pri_message(ctrl, "%c Assuming octet 3a is present.", + prefix); + } + /* Octet 3a is present */ + ++i; + /* Fall through */ case 1: /* Octet 3a */ pri_message(ctrl, "\n"); pri_message(ctrl, "%c Ext: %d Presentation: %s (%d)",