From 3072c540bb2a4d128e97ef94d070696bf1348b5d Mon Sep 17 00:00:00 2001 From: Naveen Albert Date: Wed, 18 Aug 2021 19:44:17 +0000 Subject: [PATCH] chan_iax2: Add ANI2/OLI information element Adds an information element for ANI2 so that Originating Line Information can be transmitted over IAX2 channels. ASTERISK-29605 #close Change-Id: Iaeacdf6ccde18eaff7f776a0f49fee87dcb549d2 --- channels/chan_iax2.c | 5 +++++ channels/iax2/include/iax2.h | 2 ++ channels/iax2/include/parser.h | 1 + channels/iax2/parser.c | 10 ++++++++++ doc/CHANGES-staging/chan_iax2_ani2.txt | 4 ++++ 5 files changed, 22 insertions(+) create mode 100644 doc/CHANGES-staging/chan_iax2_ani2.txt diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index c57434bf202..e16577eecd2 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -865,6 +865,7 @@ struct chan_iax2_pvt { int calling_ton; int calling_tns; int calling_pres; + int calling_ani2; int amaflags; AST_LIST_HEAD_NOLOCK(, iax2_dpcache) dpentries; /*! variables inherited from the user definition */ @@ -5181,6 +5182,7 @@ static int iax2_call(struct ast_channel *c, const char *dest, int timeout) iax_ie_append_byte(&ied, IAX_IE_CALLINGTON, ast_channel_connected(c)->id.number.plan); iax_ie_append_short(&ied, IAX_IE_CALLINGTNS, ast_channel_dialed(c)->transit_network_select); + iax_ie_append_int(&ied, IAX_IE_CALLINGANI2, ast_channel_connected(c)->ani2); if (n) iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, n); @@ -5941,6 +5943,7 @@ static struct ast_channel *ast_iax2_new(int callno, int state, iax2_format capab ast_channel_redirecting(tmp)->from.number.valid = 1; ast_channel_redirecting(tmp)->from.number.str = ast_strdup(i->rdnis); } + ast_channel_caller(tmp)->ani2 = i->calling_ani2; ast_channel_caller(tmp)->id.name.presentation = i->calling_pres; ast_channel_caller(tmp)->id.number.presentation = i->calling_pres; ast_channel_caller(tmp)->id.number.plan = i->calling_ton; @@ -7831,6 +7834,8 @@ static int check_access(int callno, struct ast_sockaddr *addr, struct iax_ies *i iaxs[callno]->calling_tns = ies->calling_tns; if (ies->calling_pres > -1) iaxs[callno]->calling_pres = ies->calling_pres; + if (ies->calling_ani2 > -1) + iaxs[callno]->calling_ani2 = ies->calling_ani2; if (ies->format) iaxs[callno]->peerformat = ies->format; if (ies->adsicpe) diff --git a/channels/iax2/include/iax2.h b/channels/iax2/include/iax2.h index 3deb5dbcd8d..a661858d2e2 100644 --- a/channels/iax2/include/iax2.h +++ b/channels/iax2/include/iax2.h @@ -187,6 +187,8 @@ enum iax_frame_subclass { #define IAX_IE_CAPABILITY2 55 /*!< Actual codec capability - u8 version + integer array */ #define IAX_IE_FORMAT2 56 /*!< Desired codec format - u8 version + integer array */ +#define IAX_IE_CALLINGANI2 57 /*!< Calling Originating Line Information (ANI2) digits */ + #define IAX_MAX_OSPBLOCK_SIZE 254 /*!< Max OSP token block size, 255 bytes - 1 byte OSP token block index */ #define IAX_MAX_OSPBLOCK_NUM 4 #define IAX_MAX_OSPTOKEN_SIZE (IAX_MAX_OSPBLOCK_SIZE * IAX_MAX_OSPBLOCK_NUM) diff --git a/channels/iax2/include/parser.h b/channels/iax2/include/parser.h index d8edc4b2aa3..cd64f35e2e3 100644 --- a/channels/iax2/include/parser.h +++ b/channels/iax2/include/parser.h @@ -32,6 +32,7 @@ struct iax_ies { int calling_ton; int calling_tns; int calling_pres; + int calling_ani2; char *called_context; char *username; char *password; diff --git a/channels/iax2/parser.c b/channels/iax2/parser.c index 86839388b13..8a36f172183 100644 --- a/channels/iax2/parser.c +++ b/channels/iax2/parser.c @@ -313,6 +313,7 @@ static struct iax2_ie infoelts[] = { { IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte }, { IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte }, { IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short }, + { IAX_IE_CALLINGANI2, "CALLING ANI2", dump_int }, { IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate }, { IAX_IE_CAUSECODE, "CAUSE CODE", dump_byte }, { IAX_IE_ENCRYPTION, "ENCRYPTION", dump_short }, @@ -805,6 +806,7 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) ies->calling_ton = -1; ies->calling_tns = -1; ies->calling_pres = -1; + ies->calling_ani2 = -1; ies->samprate = IAX_RATE_8KHZ; while(datalen >= 2) { ie = data[0]; @@ -1057,6 +1059,14 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen) errorf(tmp); } break; + case IAX_IE_CALLINGANI2: + if (len == (int)sizeof(unsigned int)) { + ies->calling_ani2 = ntohl(get_unaligned_uint32(data + 2)); + } else { + snprintf(tmp, (int)sizeof(tmp), "callingani2 was %d long: %s\n", len, data + 2); + errorf(tmp); + } + break; case IAX_IE_CALLINGTNS: if (len != (int)sizeof(unsigned short)) { snprintf(tmp, (int)sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len); diff --git a/doc/CHANGES-staging/chan_iax2_ani2.txt b/doc/CHANGES-staging/chan_iax2_ani2.txt new file mode 100644 index 00000000000..37c6fa6cf6c --- /dev/null +++ b/doc/CHANGES-staging/chan_iax2_ani2.txt @@ -0,0 +1,4 @@ +Subject: chan_iax2 + +ANI2 (OLI) is now transmitted over IAX2 calls +as an information element.