Index: channels/sig_pri.h =================================================================== --- channels/sig_pri.h (revision 309251) +++ channels/sig_pri.h (working copy) @@ -139,6 +139,16 @@ void (* const open_media)(void *pvt); + /*! + * \brief Post an AMI B channel association event. + * + * \param pvt Private structure of the user of this module. + * \param chan Channel associated with the private pointer + * + * \return Nothing + */ + void (* const ami_channel_event)(void *pvt, struct ast_channel *chan); + /*! Reference the parent module. */ void (*module_ref)(void); /*! Unreference the parent module. */ Index: channels/chan_dahdi.c =================================================================== --- channels/chan_dahdi.c (revision 309251) +++ channels/chan_dahdi.c (working copy) @@ -2087,6 +2087,58 @@ DEADLOCK_AVOIDANCE(&p->lock); } +/*! + * \internal + * \brief Post an AMI DAHDI channel association event. + * \since 1.8 + * + * \param p DAHDI private pointer + * \param chan Channel associated with the private pointer + * + * \return Nothing + */ +static void dahdi_ami_channel_event(struct dahdi_pvt *p, struct ast_channel *chan) +{ + char ch_name[20]; + + if (p->channel < CHAN_PSEUDO) { + /* No B channel */ + snprintf(ch_name, sizeof(ch_name), "no-media (%d)", p->channel); + } else if (p->channel == CHAN_PSEUDO) { + /* Pseudo channel */ + strcpy(ch_name, "pseudo"); + } else { + /* Real channel */ + snprintf(ch_name, sizeof(ch_name), "%d", p->channel); + } + ast_manager_event(chan, EVENT_FLAG_CALL, "DAHDIChannel", + "Channel: %s\r\n" + "Uniqueid: %s\r\n" + "DAHDISpan: %d\r\n" + "DAHDIChannel: %s\r\n", + chan->name, + chan->uniqueid, + p->span, + ch_name); +} + +/*! + * \internal + * \brief Post an AMI DAHDI channel association event. + * \since 1.8 + * + * \param pvt DAHDI private pointer + * \param chan Channel associated with the private pointer + * + * \return Nothing + */ +static void my_ami_channel_event(void *pvt, struct ast_channel *chan) +{ + struct dahdi_pvt *p = pvt; + + dahdi_ami_channel_event(p, chan); +} + /* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on * returns the last value of the linear setting */ @@ -3272,6 +3324,7 @@ .module_ref = my_module_ref, .module_unref = my_module_unref, .open_media = my_pri_open_media, + .ami_channel_event = my_ami_channel_event, }; #endif /* defined(HAVE_PRI) */ @@ -9463,6 +9516,7 @@ ast_module_ref(ast_module_info->self); + dahdi_ami_channel_event(i, tmp); if (startpbx) { #ifdef HAVE_OPENR2 if (i->mfcr2call) { Index: channels/sig_pri.c =================================================================== --- channels/sig_pri.c (revision 309251) +++ channels/sig_pri.c (working copy) @@ -913,6 +913,24 @@ } } +/*! + * \internal + * \brief Post an AMI B channel association event. + * \since 1.8 + * + * \param p Channel private control structure. + * + * \note Assumes the private and owner are locked. + * + * \return Nothing + */ +static void sig_pri_ami_channel_event(struct sig_pri_chan *p) +{ + if (p->calls->ami_channel_event) { + p->calls->ami_channel_event(p->chan_pvt, p->owner); + } +} + struct ast_channel *sig_pri_request(struct sig_pri_chan *p, enum sig_pri_law law, const struct ast_channel *requestor, int transfercapability) { struct ast_channel *ast; @@ -1291,6 +1309,10 @@ sig_pri_open_media(new_chan); } + if (new_chan->owner) { + sig_pri_ami_channel_event(new_chan); + } + sig_pri_unlock_private(old_chan); if (new_chan->owner) { ast_channel_unlock(new_chan->owner); Index: UPGRADE.txt =================================================================== --- UPGRADE.txt (revision 309251) +++ UPGRADE.txt (working copy) @@ -65,6 +65,11 @@ app_set, pbx_realtime, and res_agi each to 1.4 in the [compat] section of asterisk.conf. +* Added AMI event DAHDIChannel to associate a DAHDI channel with an Asterisk + channel so AMI applications can passively determine the B channel currently + in use. Calls with "no-media" as the DAHDIChannel do not have an associated + B channel. No-media calls are either on hold or call-waiting. + * The PRI channels in chan_dahdi can no longer change the channel name if a different B channel is selected during call negotiation. To prevent using the channel name to infer what B channel a call is using and to avoid name