[libpri-commits] rmudgett: branch rmudgett/mwi r1571 - /team/rmudgett/mwi/

SVN commits to the libpri project libpri-commits at lists.digium.com
Tue Mar 23 18:34:24 CDT 2010


Author: rmudgett
Date: Tue Mar 23 18:34:20 2010
New Revision: 1571

URL: http://svnview.digium.com/svn/libpri?view=rev&rev=1571
Log:
Implement MWI indicate API call.

Modified:
    team/rmudgett/mwi/libpri.h
    team/rmudgett/mwi/pri.c
    team/rmudgett/mwi/pri_facility.c
    team/rmudgett/mwi/pri_internal.h

Modified: team/rmudgett/mwi/libpri.h
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/mwi/libpri.h?view=diff&rev=1571&r1=1570&r2=1571
==============================================================================
--- team/rmudgett/mwi/libpri.h (original)
+++ team/rmudgett/mwi/libpri.h Tue Mar 23 18:34:20 2010
@@ -1490,6 +1490,25 @@
 /* Send an MWI deactivate request to a remote location */
 int pri_mwi_deactivate(struct pri *pri, q931_call *c, char *caller, int callerplan, char *callername, int callerpres, char *called, int calledplan);
 
+/*!
+ * \brief Send a MWI indication on the specified D channel.
+ *
+ * \param ctrl D channel controller.
+ * \param mailbox Controlling party number (NULL if not present).
+ * \param basic_service Basic service enum (-1 if not present).
+ * \param num_messages NumberOfMessages (-1 if not present).
+ * \param caller_id Controlling party privided number (NULL if not present).
+ * \param timestamp Generalized Time format (NULL if not present).
+ * \param message_reference Message reference number (-1 if not present).
+ * \param message_status Message status: added(0), removed(1).
+ *
+ * \retval 0 on success.
+ * \retval -1 on error.
+ */
+int pri_mwi_indicate(struct pri *ctrl, const struct pri_party_id *mailbox,
+	int basic_service, int num_messages, const struct pri_party_id *caller_id,
+	const char *timestamp, int message_reference, int message_status);
+
 /* Set service message support flag */
 int pri_set_service_message_support(struct pri *pri, int supportflag);
 

Modified: team/rmudgett/mwi/pri.c
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/mwi/pri.c?view=diff&rev=1571&r1=1570&r2=1571
==============================================================================
--- team/rmudgett/mwi/pri.c (original)
+++ team/rmudgett/mwi/pri.c Tue Mar 23 18:34:20 2010
@@ -711,7 +711,6 @@
 }
 
 /*!
- * \internal
  * \brief Copy the PRI party name to the Q.931 party name structure.
  *
  * \param q931_name Q.931 party name structure
@@ -719,7 +718,7 @@
  *
  * \return Nothing
  */
-static void pri_copy_party_name_to_q931(struct q931_party_name *q931_name, const struct pri_party_name *pri_name)
+void pri_copy_party_name_to_q931(struct q931_party_name *q931_name, const struct pri_party_name *pri_name)
 {
 	q931_party_name_init(q931_name);
 	if (pri_name->valid) {
@@ -731,7 +730,6 @@
 }
 
 /*!
- * \internal
  * \brief Copy the PRI party number to the Q.931 party number structure.
  *
  * \param q931_number Q.931 party number structure
@@ -739,7 +737,7 @@
  *
  * \return Nothing
  */
-static void pri_copy_party_number_to_q931(struct q931_party_number *q931_number, const struct pri_party_number *pri_number)
+void pri_copy_party_number_to_q931(struct q931_party_number *q931_number, const struct pri_party_number *pri_number)
 {
 	q931_party_number_init(q931_number);
 	if (pri_number->valid) {
@@ -751,7 +749,6 @@
 }
 
 /*!
- * \internal
  * \brief Copy the PRI party subaddress to the Q.931 party subaddress structure.
  *
  * \param q931_subaddress Q.931 party subaddress structure
@@ -759,7 +756,7 @@
  *
  * \return Nothing
  */
-static void pri_copy_party_subaddress_to_q931(struct q931_party_subaddress *q931_subaddress, const struct pri_party_subaddress *pri_subaddress)
+void pri_copy_party_subaddress_to_q931(struct q931_party_subaddress *q931_subaddress, const struct pri_party_subaddress *pri_subaddress)
 {
 	int length;
 	int maxlen = sizeof(q931_subaddress->data) - 1;
@@ -785,7 +782,6 @@
 }
 
 /*!
- * \internal
  * \brief Copy the PRI party id to the Q.931 party id structure.
  *
  * \param q931_id Q.931 party id structure
@@ -793,7 +789,7 @@
  *
  * \return Nothing
  */
-static void pri_copy_party_id_to_q931(struct q931_party_id *q931_id, const struct pri_party_id *pri_id)
+void pri_copy_party_id_to_q931(struct q931_party_id *q931_id, const struct pri_party_id *pri_id)
 {
 	pri_copy_party_name_to_q931(&q931_id->name, &pri_id->name);
 	pri_copy_party_number_to_q931(&q931_id->number, &pri_id->number);

Modified: team/rmudgett/mwi/pri_facility.c
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/mwi/pri_facility.c?view=diff&rev=1571&r1=1570&r2=1571
==============================================================================
--- team/rmudgett/mwi/pri_facility.c (original)
+++ team/rmudgett/mwi/pri_facility.c Tue Mar 23 18:34:20 2010
@@ -1737,6 +1737,146 @@
 	}
 
 	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer, NULL);
+}
+
+/*!
+ * \internal
+ * \brief Encode a MWI indication.
+ *
+ * \param ctrl D channel controller for diagnostic messages or global options.
+ * \param pos Starting position to encode the facility ie contents.
+ * \param end End of facility ie contents encoding data buffer.
+ * \param mailbox Controlling party number (NULL if not present).
+ * \param basic_service Basic service enum (-1 if not present).
+ * \param num_messages NumberOfMessages (-1 if not present).
+ * \param caller_id Controlling party privided number (NULL if not present).
+ * \param timestamp Generalized Time format (NULL if not present).
+ * \param message_reference Message reference number (-1 if not present).
+ * \param message_status Message status: added(0), removed(1).
+ *
+ * \retval Start of the next ASN.1 component to encode on success.
+ * \retval NULL on error.
+ */
+static unsigned char *enc_etsi_mwi_indicate_message(struct pri *ctrl, unsigned char *pos,
+	unsigned char *end, const struct pri_party_id *mailbox, int basic_service,
+	int num_messages, const struct pri_party_id *caller_id, const char *timestamp,
+	int message_reference, int message_status)
+{
+	struct rose_msg_invoke msg;
+	struct q931_party_number number;
+
+	pos = facility_encode_header(ctrl, pos, end, NULL);
+	if (!pos) {
+		return NULL;
+	}
+
+	memset(&msg, 0, sizeof(msg));
+	msg.operation = ROSE_ETSI_MWIIndicate;
+	msg.invoke_id = get_invokeid(ctrl);
+
+	if (mailbox && mailbox->number.valid) {
+		pri_copy_party_number_to_q931(&number, &mailbox->number);
+		q931_copy_number_to_rose(ctrl, &msg.args.etsi.MWIIndicate.controlling_user_number,
+			&number);
+	}
+	if (-1 < basic_service) {
+		msg.args.etsi.MWIIndicate.basic_service_present = 1;
+		msg.args.etsi.MWIIndicate.basic_service = basic_service;
+	}
+	if (-1 < num_messages) {
+		msg.args.etsi.MWIIndicate.number_of_messages_present = 1;
+		msg.args.etsi.MWIIndicate.number_of_messages = num_messages;
+	}
+	if (caller_id && caller_id->number.valid) {
+		pri_copy_party_number_to_q931(&number, &caller_id->number);
+		q931_copy_number_to_rose(ctrl,
+			&msg.args.etsi.MWIIndicate.controlling_user_provided_number, &number);
+	}
+	if (timestamp && timestamp[0]) {
+		msg.args.etsi.MWIIndicate.time_present = 1;
+		libpri_copy_string((char *) msg.args.etsi.MWIIndicate.time.str, timestamp,
+			sizeof(msg.args.etsi.MWIIndicate.time.str));
+	}
+	if (-1 < message_reference) {
+		msg.args.etsi.MWIIndicate.message_id_present = 1;
+		msg.args.etsi.MWIIndicate.message_id.reference_number = message_reference;
+		msg.args.etsi.MWIIndicate.message_id.status = message_status;
+	}
+
+	pos = rose_encode_invoke(ctrl, pos, end, &msg);
+
+	return pos;
+}
+
+/*!
+ * \internal
+ * \brief Encode and queue a MWI indication.
+ *
+ * \param ctrl D channel controller.
+ * \param call Call leg to queue message.
+ * \param mailbox Controlling party number (NULL if not present).
+ * \param basic_service Basic service enum (-1 if not present).
+ * \param num_messages NumberOfMessages (-1 if not present).
+ * \param caller_id Controlling party privided number (NULL if not present).
+ * \param timestamp Generalized Time format (NULL if not present).
+ * \param message_reference Message reference number (-1 if not present).
+ * \param message_status Message status: added(0), removed(1).
+ *
+ * \retval 0 on success.
+ * \retval -1 on error.
+ */
+static int rose_mwi_indicate_encode(struct pri *ctrl, struct q931_call *call,
+	const struct pri_party_id *mailbox, int basic_service, int num_messages,
+	const struct pri_party_id *caller_id, const char *timestamp, int message_reference,
+	int message_status)
+{
+	unsigned char buffer[255];
+	unsigned char *end;
+
+	end = enc_etsi_mwi_indicate_message(ctrl, buffer, buffer + sizeof(buffer), mailbox,
+		basic_service, num_messages, caller_id, timestamp, message_reference,
+		message_status);
+	if (!end) {
+		return -1;
+	}
+
+	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer, NULL);
+}
+
+int pri_mwi_indicate(struct pri *ctrl, const struct pri_party_id *mailbox,
+	int basic_service, int num_messages, const struct pri_party_id *caller_id,
+	const char *timestamp, int message_reference, int message_status)
+{
+	struct q931_call *call;
+
+	if (!ctrl) {
+		return -1;
+	}
+
+	switch (ctrl->switchtype) {
+	case PRI_SWITCH_EUROISDN_E1:
+	case PRI_SWITCH_EUROISDN_T1:
+		if (!BRI_NT_PTMP(ctrl)) {
+			return -1;
+		}
+		call = PRI_MASTER(ctrl)->dummy_call;
+		if (!call) {
+			return -1;
+		}
+		break;
+	default:
+		return -1;
+	}
+
+	if (rose_mwi_indicate_encode(ctrl, call, mailbox, basic_service, num_messages,
+		caller_id, timestamp, message_reference, message_status)
+		|| q931_facility(ctrl, call)) {
+		pri_message(ctrl,
+			"Could not schedule facility message for MWI indicate message.\n");
+		return -1;
+	}
+
+	return 0;
 }
 /* End MWI */
 
@@ -4559,6 +4699,14 @@
 			break;
 		}
 		break;
+#if 0	/* Not handled yet */
+	case ROSE_ETSI_MWIActivate:
+		break;
+	case ROSE_ETSI_MWIDeactivate:
+		break;
+	case ROSE_ETSI_MWIIndicate:
+		break;
+#endif	/* Not handled yet */
 	case ROSE_QSIG_CallingName:
 		/* CallingName is put in remote_id.name */
 		rose_copy_name_to_q931(ctrl, &call->remote_id.name,

Modified: team/rmudgett/mwi/pri_internal.h
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/mwi/pri_internal.h?view=diff&rev=1571&r1=1570&r2=1571
==============================================================================
--- team/rmudgett/mwi/pri_internal.h (original)
+++ team/rmudgett/mwi/pri_internal.h Tue Mar 23 18:34:20 2010
@@ -932,6 +932,11 @@
 void q931_party_id_copy_to_pri(struct pri_party_id *pri_id, const struct q931_party_id *q931_id);
 void q931_party_redirecting_copy_to_pri(struct pri_party_redirecting *pri_redirecting, const struct q931_party_redirecting *q931_redirecting);
 
+void pri_copy_party_name_to_q931(struct q931_party_name *q931_name, const struct pri_party_name *pri_name);
+void pri_copy_party_number_to_q931(struct q931_party_number *q931_number, const struct pri_party_number *pri_number);
+void pri_copy_party_subaddress_to_q931(struct q931_party_subaddress *q931_subaddress, const struct pri_party_subaddress *pri_subaddress);
+void pri_copy_party_id_to_q931(struct q931_party_id *q931_id, const struct pri_party_id *pri_id);
+
 void q931_party_id_fixup(const struct pri *ctrl, struct q931_party_id *id);
 int q931_party_id_presentation(const struct q931_party_id *id);
 




More information about the libpri-commits mailing list