[asterisk-r2] handle a removed DAHDI device

Tzafrir Cohen tzafrir.cohen at xorcom.com
Thu Jun 15 12:10:09 CDT 2017


Hi all,

DAHDI devices nowadays may be not only assigned but also unassinged:

  dahdi_span_assignment remove

This practically removes all DAHDI spans, although the devices
themselves remain and may be re-assigned later on.

The Asterisk MFC/R2 code does not handle this well. It results in an
endless stream of messages:

[2017-06-15 20:03:18] ERROR[23002]: chan_dahdi.c:3690 dahdi_r2_on_os_error: OS error on chan 73: No such device
[2017-06-15 20:03:18] ERROR[22968]: chan_dahdi.c:3935 dahdi_r2_write_log: Chan 38 - Failed to get I/O events

There should be two ways to detect this:
1. Upon disconnect DAHDI sends an event (DAHDI_EVENT_REMOVED, similar to
DAHDI_EVENT_ALARM).

2. Any I/O with DAHDI should result in -ENODEV. This error from a device
that clearly existed earlier is a good indication that it was removed.

For (1):

--- a/src/openr2/r2hwcompat.h
+++ b/src/openr2/r2hwcompat.h
@@ -50,6 +50,7 @@ typedef struct dahdi_params OR2_HW_PARAMS;
        #define OR2_HW_EVENT_BITS_CHANGED DAHDI_EVENT_BITSCHANGED
        #define OR2_HW_EVENT_ALARM DAHDI_EVENT_ALARM
        #define OR2_HW_EVENT_NO_ALARM DAHDI_EVENT_NOALARM
+       #define OR2_HW_EVENT_REMOVED DAHDI_EVENT_REMOVED
 
        #define OR2_HW_OP_CHANNO DAHDI_CHANNO
        #define OR2_HW_OP_GET_PARAMS DAHDI_GET_PARAMS
@@ -88,6 +89,7 @@ typedef ZT_PARAMS OR2_HW_PARAMS;
        #define OR2_HW_EVENT_BITS_CHANGED ZT_EVENT_BITSCHANGED
        #define OR2_HW_EVENT_ALARM ZT_EVENT_ALARM
        #define OR2_HW_EVENT_NO_ALARM ZT_EVENT_NOALARM
+       #define OR2_HW_EVENT_REMOVED ZT_EVENT_REMOVED
 
        #define OR2_HW_OP_CHANNO ZT_CHANNO
        #define OR2_HW_OP_GET_PARAMS ZT_GET_PARAMS
diff --git a/src/r2chan.c b/src/r2chan.c
index a0ffc7c..fecf9d1 100755
--- a/src/r2chan.c
+++ b/src/r2chan.c
@@ -281,6 +281,10 @@ static int openr2_chan_handle_zap_event(openr2_chan_t *r2chan
                r2chan->inalarm = (event == OR2_HW_EVENT_ALARM) ? 1 : 0;
                EMI(r2chan)->on_hardware_alarm(r2chan, r2chan->inalarm);
                break;
+       case OR2_HW_EVENT_REMOVED:
+               openr2_log(r2chan, OR2_LOG_DEBUG, "Channel removed\n");
+               /* FIXME: remove span */
+               break;
        default:
                openr2_log(r2chan, OR2_LOG_DEBUG, "Unhandled hardware event %d\n",
                break;

But I suspect it should the fix should be done in Asterisk. Any hint on
how to proceed?

-- 
               Tzafrir Cohen
+972-50-7952406           mailto:tzafrir.cohen at xorcom.com
http://www.xorcom.com



More information about the asterisk-r2 mailing list