[asterisk-commits] rmudgett: branch rmudgett/mwi r254929 - in /team/rmudgett/mwi: ./ channels/ c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 25 18:27:52 CDT 2010


Author: rmudgett
Date: Thu Mar 25 18:27:48 2010
New Revision: 254929

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=254929
Log:
Initial forward port of C.3-bier MWI implementation up to -r254821.

Next up is to test it to see if it still works.
Then on to converting it to use event subscriptions instead of polling.

Modified:
    team/rmudgett/mwi/CHANGES
    team/rmudgett/mwi/channels/chan_dahdi.c
    team/rmudgett/mwi/channels/sig_pri.h
    team/rmudgett/mwi/configs/chan_dahdi.conf.sample
    team/rmudgett/mwi/configure.ac

Modified: team/rmudgett/mwi/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mwi/CHANGES?view=diff&rev=254929&r1=254928&r2=254929
==============================================================================
--- team/rmudgett/mwi/CHANGES (original)
+++ team/rmudgett/mwi/CHANGES Thu Mar 25 18:27:48 2010
@@ -324,6 +324,7 @@
    dialing option.  Dial(DAHDI/g1/[extension]/K(<keypad_digits>))
    Access any received keypad digits in SETUP message by: ${CHANNEL(keypad_digits)}
    (requires latest LibPRI)
+ * Added Message Waiting Indication (MWI) support for ISDN PTMP endpoints (phones).
 
 Asterisk Manager Interface
 --------------------------

Modified: team/rmudgett/mwi/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mwi/channels/chan_dahdi.c?view=diff&rev=254929&r1=254928&r2=254929
==============================================================================
--- team/rmudgett/mwi/channels/chan_dahdi.c (original)
+++ team/rmudgett/mwi/channels/chan_dahdi.c Thu Mar 25 18:27:48 2010
@@ -10562,6 +10562,18 @@
 	char buf[1024];
 	struct pollfd *pfds=NULL;
 	int lastalloc = -1;
+#if defined(HAVE_PRI)
+#if defined(HAVE_PRI_MWI)
+	int span;
+	int idx;
+	int num_messages;
+	struct dahdi_pri *pri;
+	struct pri_party_id mailbox;
+
+	static int mbox_update_count;
+#endif	/* defined(HAVE_PRI_MWI) */
+#endif	/* defined(HAVE_PRI) */
+
 	/* This thread monitors all the frame relay interfaces which are not yet in use
 	   (and thus do not have a separate thread) indefinitely */
 	/* From here on out, we die whenever asked */
@@ -10823,6 +10835,51 @@
 			}
 		}
 		ast_mutex_unlock(&iflock);
+
+#if defined(HAVE_PRI)
+#if defined(HAVE_PRI_MWI)
+		/* Poll the voicemail mailboxes every 10 seconds or so. */
+		if (10 < ++mbox_update_count) {
+			mbox_update_count = 0;
+
+			/* Poll the voicemail mailboxes on each span. */
+			for (span = 0; span < NUM_SPANS; ++span) {
+				pri = pris + span;
+				if (!pri->pri.pri) {
+					/* Span not setup. */
+					continue;
+				}
+				/* Poll the voicemail mailboxes in this span. */
+				for (idx = 0; idx < SIG_PRI_MAX_MWI_MAILBOXES; ++idx) {
+					if (!pri->pri.mbox[idx].number) {
+						/* There are no more mailboxes on this span. */
+						break;
+					}
+					num_messages = ast_app_messagecount(pri->pri.mbox[idx].context,
+						pri->pri.mbox[idx].number, NULL);
+					if (num_messages == pri->pri.mbox[idx].last_message_count) {
+						/* The number of messages has not changed since last time. */
+						continue;
+					}
+					pri->pri.mbox[idx].last_message_count = num_messages;
+
+					/* The number of messages changed so send a MWI indication. */
+					memset(&mailbox, 0, sizeof(mailbox));
+					mailbox.number.valid = 1;
+					mailbox.number.presentation = PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
+					mailbox.number.plan = (PRI_TON_UNKNOWN << 4) | PRI_NPI_UNKNOWN;
+					ast_copy_string(mailbox.number.str, pri->pri.mbox[idx].number,
+						sizeof(mailbox.number.str));
+
+					ast_mutex_lock(&pri->pri.lock);
+					pri_mwi_indicate(pri->pri.pri, &mailbox, 1 /* speech */, num_messages,
+						NULL, NULL, -1, 0);
+					ast_mutex_unlock(&pri->pri.lock);
+				}
+			}
+		}
+#endif	/* defined(HAVE_PRI_MWI) */
+#endif	/* defined(HAVE_PRI) */
 	}
 	/* Never reached */
 	return NULL;
@@ -11430,6 +11487,11 @@
 #endif	/* defined(HAVE_PRI_CALL_HOLD) */
 						pris[span].pri.facilityenable = conf->pri.pri.facilityenable;
 						ast_copy_string(pris[span].pri.msn_list, conf->pri.pri.msn_list, sizeof(pris[span].pri.msn_list));
+#if defined(HAVE_PRI_MWI)
+						ast_copy_string(pris[span].pri.mwi_mailboxes,
+							conf->pri.pri.mwi_mailboxes,
+							sizeof(pris[span].pri.mwi_mailboxes));
+#endif	/* defined(HAVE_PRI_MWI) */
 						ast_copy_string(pris[span].pri.idledial, conf->pri.pri.idledial, sizeof(pris[span].pri.idledial));
 						ast_copy_string(pris[span].pri.idleext, conf->pri.pri.idleext, sizeof(pris[span].pri.idleext));
 						ast_copy_string(pris[span].pri.internationalprefix, conf->pri.pri.internationalprefix, sizeof(pris[span].pri.internationalprefix));
@@ -13318,8 +13380,50 @@
 	struct dahdi_params p;
 	struct dahdi_bufferinfo bi;
 	struct dahdi_spaninfo si;
+#if defined(HAVE_PRI_MWI)
+	char *saveptr;
+	char *mbox_number;
+	char *mbox_context;
+#endif	/* defined(HAVE_PRI_MWI) */
 
 	pri->pri.calls = &dahdi_pri_callbacks;
+
+#if defined(HAVE_PRI_MWI)
+	/* Prepare the mbox[] for use. */
+	memset(pri->pri.mbox, 0, sizeof(pri->pri.mbox));
+	for (i = 0; i < SIG_PRI_MAX_MWI_MAILBOXES; ++i) {
+		pri->pri.mbox[i].last_message_count = -1;
+	}
+
+	/*
+	 * Split the mwi_mailboxes configuration string into the mbox[]:
+	 * mailbox_number[@context]{,mailbox_number[@context]}
+	 */
+	i = 0;
+	saveptr = NULL;/* So compiler will not complain about uninitialized variable. */
+	for (mbox_number = strtok_r(pri->pri.mwi_mailboxes, ",", &saveptr);
+		mbox_number && i < SIG_PRI_MAX_MWI_MAILBOXES;
+		mbox_number = strtok_r(NULL, ",", &saveptr)) {
+		/* Split the mailbox_number and context */
+		mbox_context = strchr(mbox_number, '@');
+		if (mbox_context) {
+			*mbox_context++ = '\0';
+			mbox_context = ast_strip(mbox_context);
+		}
+		mbox_number = ast_strip(mbox_number);
+		if (ast_strlen_zero(mbox_number)) {
+			/* There is no mailbox number.  Skip it. */
+			continue;
+		}
+
+		/* Fill the mbox[] element. */
+		pri->pri.mbox[i].number = mbox_number;
+		if (!ast_strlen_zero(mbox_context)) {
+			pri->pri.mbox[i].context = mbox_context;
+		}
+		++i;
+	}
+#endif	/* defined(HAVE_PRI_MWI) */
 
 	for (i = 0; i < NUM_DCHANS; i++) {
 		if (!pri->dchannels[i])
@@ -16472,6 +16576,11 @@
 			} else if (!strcasecmp(v->name, "hold_disconnect_transfer")) {
 				confp->pri.pri.hold_disconnect_transfer = ast_true(v->value);
 #endif	/* defined(HAVE_PRI_CALL_HOLD) */
+#if defined(HAVE_PRI_MWI)
+			} else if (!strcasecmp(v->name, "mwi_mailboxes")) {
+				ast_copy_string(confp->pri.pri.mwi_mailboxes, v->value,
+					sizeof(confp->pri.pri.mwi_mailboxes));
+#endif	/* defined(HAVE_PRI_MWI) */
 #endif /* HAVE_PRI */
 #ifdef HAVE_SS7
 			} else if (!strcasecmp(v->name, "ss7type")) {

Modified: team/rmudgett/mwi/channels/sig_pri.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mwi/channels/sig_pri.h?view=diff&rev=254929&r1=254928&r2=254929
==============================================================================
--- team/rmudgett/mwi/channels/sig_pri.h (original)
+++ team/rmudgett/mwi/channels/sig_pri.h Thu Mar 25 18:27:48 2010
@@ -29,6 +29,10 @@
 #include "asterisk/frame.h"
 #include <libpri.h>
 #include <dahdi/user.h>
+#if defined(PRI_SUBCMD_MCID_REQ)
+/* BUGBUG the HAVE_PRI_MWI line is to be removed when the mwi branch is merged to trunk and the configure script is updated. */
+#define HAVE_PRI_MWI 1
+#endif	/* defined(PRI_SUBCMD_MCID_REQ) */
 
 enum sig_pri_tone {
 	SIG_PRI_TONE_RINGTONE = 0,
@@ -191,6 +195,26 @@
 	int reverse_charging_indication;
 #endif
 };
+
+#if defined(HAVE_PRI_MWI)
+/*! Maximum number of mailboxes per span. */
+#define SIG_PRI_MAX_MWI_MAILBOXES		8
+
+struct sig_pri_mbox {
+	/*!
+	 * \brief Mailbox number
+	 * \note NULL if mailbox not configured.
+	 */
+	const char *number;
+	/*!
+	 * \brief Mailbox context.
+	 * \note NULL if default.
+	 */
+	const char *context;
+	/*! \brief Number of messages in mailbox from last poll. */
+	int last_message_count;
+};
+#endif	/* defined(HAVE_PRI_MWI) */
 
 struct sig_pri_pri {
 	/* Should be set by user */
@@ -219,6 +243,17 @@
 	char privateprefix[20];					/*!< for private dialplans */
 	char unknownprefix[20];					/*!< for unknown dialplans */
 	long resetinterval;						/*!< Interval (in seconds) for resetting unused channels */
+#if defined(HAVE_PRI_MWI)
+	/*! \brief Active MWI mailboxes */
+	struct sig_pri_mbox mbox[SIG_PRI_MAX_MWI_MAILBOXES];
+	/*!
+	 * \brief Comma separated list of mailboxes to indicate MWI.
+	 * \note Empty if disabled.
+	 * \note Format: mailbox_number[@context]{,mailbox_number[@context]}
+	 * \note String is split apart when span is started.
+	 */
+	char mwi_mailboxes[2 * AST_MAX_EXTENSION];
+#endif	/* defined(HAVE_PRI_MWI) */
 	char msn_list[AST_MAX_EXTENSION];		/*!< Comma separated list of MSNs to handle.  Empty if disabled. */
 	char idleext[AST_MAX_EXTENSION];		/*!< Where to idle extra calls */
 	char idlecontext[AST_MAX_CONTEXT];		/*!< What context to use for idle */

Modified: team/rmudgett/mwi/configs/chan_dahdi.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mwi/configs/chan_dahdi.conf.sample?view=diff&rev=254929&r1=254928&r2=254929
==============================================================================
--- team/rmudgett/mwi/configs/chan_dahdi.conf.sample (original)
+++ team/rmudgett/mwi/configs/chan_dahdi.conf.sample Thu Mar 25 18:27:48 2010
@@ -449,6 +449,12 @@
 ;
 callwaiting=yes
 ;
+; Configure the ISDN span to indicate MWI for the list of mailboxes.
+; You can give a comma separated list of up to 8 mailboxes per span.
+; An empty list disables MWI.
+; The default is an empty list.
+;mwi_mailboxes=mailbox_number[@context]{,mailbox_number[@context]}
+;
 ; Whether or not restrict outgoing caller ID (will be sent as ANI only, not
 ; available for the user)
 ; Mostly use with FXS ports

Modified: team/rmudgett/mwi/configure.ac
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/mwi/configure.ac?view=diff&rev=254929&r1=254928&r2=254929
==============================================================================
--- team/rmudgett/mwi/configure.ac (original)
+++ team/rmudgett/mwi/configure.ac Thu Mar 25 18:27:48 2010
@@ -335,6 +335,7 @@
 AST_EXT_LIB_SETUP([POPT], [popt], [popt])
 AST_EXT_LIB_SETUP([PORTAUDIO], [PortAudio], [portaudio])
 AST_EXT_LIB_SETUP([PRI], [ISDN PRI], [pri])
+AST_EXT_LIB_SETUP_DEPENDENT([PRI_MWI], [ISDN PRI Message Waiting Indication], [PRI], [pri])
 AST_EXT_LIB_SETUP_DEPENDENT([PRI_SUBADDR], [ISDN PRI subaddressing], [PRI], [pri])
 AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_HOLD], [ISDN PRI call hold], [PRI], [pri])
 AST_EXT_LIB_SETUP_DEPENDENT([PRI_CALL_REROUTING], [ISDN PRI call rerouting and call deflection], [PRI], [pri])
@@ -1529,6 +1530,7 @@
 AST_EXT_LIB_CHECK([PORTAUDIO], [portaudio], [Pa_GetDeviceCount], [portaudio.h])
 
 AST_EXT_LIB_CHECK([PRI], [pri], [pri_connected_line_update], [libpri.h])
+AST_EXT_LIB_CHECK([PRI_MWI], [pri], [pri_mwi_indicate], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_SUBADDR], [pri], [pri_sr_set_called_subaddress], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_CALL_HOLD], [pri], [pri_hold_enable], [libpri.h])
 AST_EXT_LIB_CHECK([PRI_CALL_REROUTING], [pri], [pri_reroute_enable], [libpri.h])




More information about the asterisk-commits mailing list