callerid.c: Parse previously ignored Caller ID parameters.

Commit f2f397c1a8 previously
made it possible to send Caller ID parameters to FXS stations
which, prior to that, could not be sent.

This change is complementary in that we now handle receiving
all these parameters on FXO lines and provide these up to
the dialplan, via chan_dahdi. In particular:

* If a redirecting reason is provided, the channel's redirecting
  reason is set. No redirecting number is set, since there is
  no parameter for this in the Caller ID protocol, but the reason
  can be checked to determine if and why a call was forwarded.
* If the Call Qualifier parameter is received, the Call Qualifier
  variable is set.
* Some comments have been added to explain why some of the code
  is the way it is, to assist other people looking at it.

With this change, Asterisk's Caller ID implementation is now
reasonably complete for both FXS and FXO operation.

Resolves: #681
(cherry picked from commit 6bd0b67081)
This commit is contained in:
Naveen Albert
2024-04-01 17:16:29 -04:00
committed by Asterisk Development Team
parent 6e8678d8ac
commit a2579ec402
4 changed files with 144 additions and 17 deletions

View File

@@ -1436,6 +1436,7 @@ static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_e
int res;
unsigned char buf[256];
int flags;
int redirecting;
poller.fd = p->subs[SUB_REAL].dfd;
poller.events = POLLPRI | POLLIN;
@@ -1482,7 +1483,8 @@ static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_e
}
if (res == 1) {
callerid_get(p->cs, &name, &num, &flags);
struct ast_channel *chan = analog_p->ss_astchan;
callerid_get_with_redirecting(p->cs, &name, &num, &flags, &redirecting);
if (name)
ast_copy_string(namebuf, name, ANALOG_MAX_CID);
if (num)
@@ -1490,7 +1492,6 @@ static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_e
if (flags & (CID_PRIVATE_NUMBER | CID_UNKNOWN_NUMBER)) {
/* If we got a presentation, we must set it on the channel */
struct ast_channel *chan = analog_p->ss_astchan;
struct ast_party_caller caller;
ast_party_caller_set_init(&caller, ast_channel_caller(chan));
@@ -1499,8 +1500,19 @@ static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_e
ast_party_caller_set(ast_channel_caller(chan), &caller, NULL);
ast_party_caller_free(&caller);
}
if (redirecting) {
/* There is a redirecting reason available in the Caller*ID received.
* No idea what the redirecting number is, since the Caller*ID protocol
* has no parameter for that, but at least we know WHY it was redirected. */
ast_channel_redirecting(chan)->reason.code = redirecting;
}
ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", num, name, flags);
if (flags & CID_QUALIFIER) {
/* This is the inverse of how the qualifier is set in sig_analog */
pbx_builtin_setvar_helper(chan, "CALL_QUALIFIER", "1");
}
ast_debug(1, "CallerID number: %s, name: %s, flags=%d, redirecting=%s\n", num, name, flags, ast_redirecting_reason_name(&ast_channel_redirecting(chan)->reason));
return 0;
}
}