chan_dahdi: set CHANNEL(hangupsource) when a PRI channel hangs up
authorFrederic LE FOLL <frederic.lefoll@c-s.fr>
Thu, 5 Sep 2019 15:52:13 +0000 (17:52 +0200)
committerFrederic LE FOLL <frederic.lefoll@c-s.fr>
Tue, 10 Sep 2019 15:59:26 +0000 (10:59 -0500)
When the remote ISDN party ends an ISDN call on a PRI link
(DISCONNECT), CHANNEL(hangupsource) information is not available.

chan_dahdi already contains an ast_set_hangupsource() in
__dahdi_exception() function but it seems that ISDN message processing
does not use this part of code.

Two other channel modules associate ast_queue_hangup() and
ast_set_hangupsource() functions calls:
- chan_pjsip in chan_pjsip_session_end() function,
- chan_sip in sip_queue_hangup_cause() function.
chan_iax2 separates them, in iax2_queue_hangup()/iax2_destroy() and
set_hangup_source_and_cause().

Thus, I propose to add ast_set_hangupsource() beside
ast_queue_hangup() in sig_pri_queue_hangup(), like chan_pjsip and
chan_sip already do.

ASTERISK-28525

Change-Id: I0f588a4bcf15ccd0648fd69830d1b801c3f21b7c

channels/sig_pri.c

index a8c042f..82048b3 100644 (file)
@@ -1391,14 +1391,25 @@ static void pri_queue_control(struct sig_pri_span *pri, int chanpos, int subclas
  */
 static void sig_pri_queue_hangup(struct sig_pri_span *pri, int chanpos)
 {
+       struct ast_channel *owner;
+
        if (sig_pri_callbacks.queue_control) {
                sig_pri_callbacks.queue_control(pri->pvts[chanpos]->chan_pvt, AST_CONTROL_HANGUP);
        }
 
        sig_pri_lock_owner(pri, chanpos);
-       if (pri->pvts[chanpos]->owner) {
-               ast_queue_hangup(pri->pvts[chanpos]->owner);
-               ast_channel_unlock(pri->pvts[chanpos]->owner);
+       owner = pri->pvts[chanpos]->owner;
+       if (owner) {
+               ao2_ref(owner, +1);
+               ast_queue_hangup(owner);
+               ast_channel_unlock(owner);
+
+               /* Tell the CDR this DAHDI channel hung up */
+               sig_pri_unlock_private(pri->pvts[chanpos]);
+               ast_set_hangupsource(owner, ast_channel_name(owner), 0);
+               sig_pri_lock_private(pri->pvts[chanpos]);
+
+               ao2_ref(owner, -1);
        }
 }