[libpri-commits] tilghman: branch group/issue10217 r934 - /team/group/issue10217/

SVN commits to the libpri project libpri-commits at lists.digium.com
Thu Jul 2 12:13:19 CDT 2009


Author: tilghman
Date: Thu Jul  2 12:13:15 2009
New Revision: 934

URL: http://svn.asterisk.org/svn-view/libpri?view=rev&rev=934
Log:
Merged revisions 907,914,919-921 via svnmerge from 
https://origsvn.digium.com/svn/libpri/branches/1.4

........
  r907 | seanbright | 2009-06-25 13:53:38 -0500 (Thu, 25 Jun 2009) | 17 lines
  
  Add support for sending Reverse Charging Indication IE on ISDN PRI.
  
  Add the ability to transmit a Reverse Charging Indication IE during a SETUP
  message.  In passing, re-work some of the receive logic to be forwards
  compatible with new RCI values that may be added in the future.  Also removed
  the PRI_REVERSECHARGE_SUPPORT define that I added on the last commit since we
  can just check for PRI_REVERSECHARGE_NONE or _REQUESTED on the Asterisk side to
  determine support for this.
  
  Special thanks to rmudgett who could have written this in half the time he spent
  reviewing it, but instead talked me through it.  Much appreciated!
  
  (issue #13760)
  Reported by: mrgabu
  
  Review: https://reviewboard.asterisk.org/r/292/
........
  r914 | rmudgett | 2009-06-26 13:37:15 -0500 (Fri, 26 Jun 2009) | 1 line
  
  Added printf format attribute to pri_message() and pri_error() and fixed some detected errors.
........
  r919 | rmudgett | 2009-06-26 14:41:56 -0500 (Fri, 26 Jun 2009) | 1 line
  
  Doxygenify the timer comments.
........
  r920 | rmudgett | 2009-06-26 14:43:13 -0500 (Fri, 26 Jun 2009) | 1 line
  
  Eliminate local version of PRI_MAX_TIMERS.
........
  r921 | rmudgett | 2009-06-26 14:50:19 -0500 (Fri, 26 Jun 2009) | 6 lines
  
  Fix potential buffer overflow in pri_dump_info_str().
  
  *  Created pri_snprintf() to prevent buffer overflow in pri_dump_info_str().
  *  Extracted timer name to timer number table from pri_timer2idx() so
  pri_dump_info_str() can use it.
........

Modified:
    team/group/issue10217/   (props changed)
    team/group/issue10217/libpri.h
    team/group/issue10217/pri.c
    team/group/issue10217/pri_internal.h
    team/group/issue10217/q931.c

Propchange: team/group/issue10217/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/issue10217/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Jul  2 12:13:15 2009
@@ -1,1 +1,1 @@
-/branches/1.4:1-901
+/branches/1.4:1-933

Modified: team/group/issue10217/libpri.h
URL: http://svn.asterisk.org/svn-view/libpri/team/group/issue10217/libpri.h?view=diff&rev=934&r1=933&r2=934
==============================================================================
--- team/group/issue10217/libpri.h (original)
+++ team/group/issue10217/libpri.h Thu Jul  2 12:13:15 2009
@@ -182,6 +182,10 @@
 
 #define PRES_NUMBER_NOT_AVAILABLE \
 	(PRI_PRES_UNAVAILABLE | PRI_PRES_NETWORK_NUMBER)
+
+/* Reverse Charging Indication */
+#define PRI_REVERSECHARGE_NONE      -1
+#define PRI_REVERSECHARGE_REQUESTED  1
 
 /* Causes for disconnection */
 #define PRI_CAUSE_UNALLOCATED					1
@@ -770,6 +774,7 @@
 #define PRI_USER_USER_TX
 /* Set the user user field.  Warning!  don't send binary data accross this field */
 void pri_sr_set_useruser(struct pri_sr *sr, const char *userchars);
+void pri_sr_set_reversecharge(struct pri_sr *sr, int requested);
 
 void pri_call_set_useruser(q931_call *sr, const char *userchars);
 
@@ -836,7 +841,6 @@
 #define PRI_REDIRECTING_REASON
 #define PRI_AOC_UNITS
 #define PRI_ANI
-#define PRI_REVERSECHARGE_SUPPORT
 
 /* Send notification */
 int pri_notify(struct pri *pri, q931_call *c, int channel, int info);
@@ -849,32 +853,32 @@
 int pri_get_timer(struct pri *pri, int timer);
 int pri_timer2idx(const char *timer_name);
 
-/* New configurable timers and counters must be added to the end of the list */
+/*! New configurable timers and counters must be added to the end of the list */
 enum PRI_TIMERS_AND_COUNTERS {
-	PRI_TIMER_N200,	/* Maximum numer of Q.921 retransmissions */
-	PRI_TIMER_N201,	/* Maximum numer of octets in an information field */
-	PRI_TIMER_N202,	/* Maximum numer of transmissions of the TEI identity request message */
-	PRI_TIMER_K,	/* Maximum number of outstanding I-frames */
-
-	PRI_TIMER_T200,	/* Time between SABME's */
-	PRI_TIMER_T201,	/* Minimum time between retransmissions of the TEI Identity check messages */
-	PRI_TIMER_T202,	/* Minimum time between transmission of TEI Identity request messages */
-	PRI_TIMER_T203,	/* Maximum time without exchanging packets */
+	PRI_TIMER_N200,	/*!< Maximum numer of Q.921 retransmissions */
+	PRI_TIMER_N201,	/*!< Maximum numer of octets in an information field */
+	PRI_TIMER_N202,	/*!< Maximum numer of transmissions of the TEI identity request message */
+	PRI_TIMER_K,	/*!< Maximum number of outstanding I-frames */
+
+	PRI_TIMER_T200,	/*!< Time between SABME's */
+	PRI_TIMER_T201,	/*!< Minimum time between retransmissions of the TEI Identity check messages */
+	PRI_TIMER_T202,	/*!< Minimum time between transmission of TEI Identity request messages */
+	PRI_TIMER_T203,	/*!< Maximum time without exchanging packets */
 
 	PRI_TIMER_T300,
-	PRI_TIMER_T301,	/* Maximum time to respond to an ALERT */
+	PRI_TIMER_T301,	/*!< Maximum time to respond to an ALERT */
 	PRI_TIMER_T302,
-	PRI_TIMER_T303,	/* Maximum time to wait after sending a SETUP without a response */
+	PRI_TIMER_T303,	/*!< Maximum time to wait after sending a SETUP without a response */
 	PRI_TIMER_T304,
-	PRI_TIMER_T305,	/* Wait for DISCONNECT acknowledge */
+	PRI_TIMER_T305,	/*!< Wait for DISCONNECT acknowledge */
 	PRI_TIMER_T306,
 	PRI_TIMER_T307,
-	PRI_TIMER_T308,	/* Wait for RELEASE acknowledge */
-	PRI_TIMER_T309,	/* Time active calls can tollerate data link layer being down before clearing. */
-	PRI_TIMER_T310,	/* Maximum time between receiving a CALL_PROCEEDING and receiving a ALERT/CONNECT/DISCONNECT/PROGRESS */
-	PRI_TIMER_T313,	/* Wait for CONNECT acknowledge, CPE side only */
+	PRI_TIMER_T308,	/*!< Wait for RELEASE acknowledge */
+	PRI_TIMER_T309,	/*!< Time active calls can tollerate data link layer being down before clearing. */
+	PRI_TIMER_T310,	/*!< Maximum time between receiving a CALL_PROCEEDING and receiving a ALERT/CONNECT/DISCONNECT/PROGRESS */
+	PRI_TIMER_T313,	/*!< Wait for CONNECT acknowledge, CPE side only */
 	PRI_TIMER_T314,
-	PRI_TIMER_T316,	/* Maximum time between transmitting a RESTART and receiving a RESTART ACK */
+	PRI_TIMER_T316,	/*!< Maximum time between transmitting a RESTART and receiving a RESTART ACK */
 	PRI_TIMER_T317,
 	PRI_TIMER_T318,
 	PRI_TIMER_T319,
@@ -882,8 +886,8 @@
 	PRI_TIMER_T321,
 	PRI_TIMER_T322,
 
-	PRI_TIMER_TM20,	/* Maximum time awaiting XID response */
-	PRI_TIMER_NM20,	/* Number of XID retransmits */
+	PRI_TIMER_TM20,	/*!< Maximum time awaiting XID response */
+	PRI_TIMER_NM20,	/*!< Number of XID retransmits */
 
 	/* Must be last in the enum list */
 	_PRI_MAX_TIMERS,

Modified: team/group/issue10217/pri.c
URL: http://svn.asterisk.org/svn-view/libpri/team/group/issue10217/pri.c?view=diff&rev=934&r1=933&r2=934
==============================================================================
--- team/group/issue10217/pri.c (original)
+++ team/group/issue10217/pri.c Thu Jul  2 12:13:15 2009
@@ -42,6 +42,52 @@
 #include "pri_facility.h"
 #include "pri_q921.h"
 #include "pri_q931.h"
+
+#define PRI_BIT(a_bit)		(1UL << (a_bit))
+#define PRI_ALL_SWITCHES	0xFFFFFFFF
+
+struct pri_timer_table {
+	const char *name;
+	enum PRI_TIMERS_AND_COUNTERS number;
+	unsigned long used_by;
+};
+
+/*!
+ * \note Sort the timer table entries in the order of the timer name so
+ * pri_dump_info_str() can display them in a consitent order.
+ */
+static const struct pri_timer_table pri_timer[] = {
+/* *INDENT-OFF* */
+	/* timer name       timer number                used by switches */
+	{ "N200",           PRI_TIMER_N200,             PRI_ALL_SWITCHES },
+	{ "N201",           PRI_TIMER_N201,             PRI_ALL_SWITCHES },
+	{ "N202",           PRI_TIMER_N202,             PRI_ALL_SWITCHES },
+	{ "K",              PRI_TIMER_K,                PRI_ALL_SWITCHES },
+	{ "T200",           PRI_TIMER_T200,             PRI_ALL_SWITCHES },
+	{ "T202",           PRI_TIMER_T202,             PRI_ALL_SWITCHES },
+	{ "T203",           PRI_TIMER_T203,             PRI_ALL_SWITCHES },
+	{ "T300",           PRI_TIMER_T300,             PRI_ALL_SWITCHES },
+	{ "T301",           PRI_TIMER_T301,             PRI_ALL_SWITCHES },
+	{ "T302",           PRI_TIMER_T302,             PRI_ALL_SWITCHES },
+	{ "T303",           PRI_TIMER_T303,             PRI_ALL_SWITCHES },
+	{ "T304",           PRI_TIMER_T304,             PRI_ALL_SWITCHES },
+	{ "T305",           PRI_TIMER_T305,             PRI_ALL_SWITCHES },
+	{ "T306",           PRI_TIMER_T306,             PRI_ALL_SWITCHES },
+	{ "T307",           PRI_TIMER_T307,             PRI_ALL_SWITCHES },
+	{ "T308",           PRI_TIMER_T308,             PRI_ALL_SWITCHES },
+	{ "T309",           PRI_TIMER_T309,             PRI_ALL_SWITCHES },
+	{ "T310",           PRI_TIMER_T310,             PRI_ALL_SWITCHES },
+	{ "T313",           PRI_TIMER_T313,             PRI_ALL_SWITCHES },
+	{ "T314",           PRI_TIMER_T314,             PRI_ALL_SWITCHES },
+	{ "T316",           PRI_TIMER_T316,             PRI_ALL_SWITCHES },
+	{ "T317",           PRI_TIMER_T317,             PRI_ALL_SWITCHES },
+	{ "T318",           PRI_TIMER_T318,             PRI_ALL_SWITCHES },
+	{ "T319",           PRI_TIMER_T319,             PRI_ALL_SWITCHES },
+	{ "T320",           PRI_TIMER_T320,             PRI_ALL_SWITCHES },
+	{ "T321",           PRI_TIMER_T321,             PRI_ALL_SWITCHES },
+	{ "T322",           PRI_TIMER_T322,             PRI_ALL_SWITCHES },
+/* *INDENT-ON* */
+};
 
 char *pri_node2str(int node)
 {
@@ -93,17 +139,17 @@
 	}
 
 	/* Set timer values to standard defaults.  Time is in ms. */
-	ctrl->timers[PRI_TIMER_N200] = 3;		/* Max numer of Q.921 retransmissions */
-	ctrl->timers[PRI_TIMER_N202] = 3;		/* Max numer of transmissions of the TEI identity request message */
-	ctrl->timers[PRI_TIMER_K] = 7;			/* Max number of outstanding I-frames */
-	ctrl->timers[PRI_TIMER_T200] = 1000;	/* Time between SABME's */
-	ctrl->timers[PRI_TIMER_T202] = 10000;	/* Min time between transmission of TEI Identity request messages */
-	ctrl->timers[PRI_TIMER_T203] = 10000;	/* Max time without exchanging packets */
-	ctrl->timers[PRI_TIMER_T305] = 30000;	/* Wait for DISCONNECT acknowledge */
-	ctrl->timers[PRI_TIMER_T308] = 4000;	/* Wait for RELEASE acknowledge */
-	ctrl->timers[PRI_TIMER_T313] = 4000;	/* Wait for CONNECT acknowledge, CPE side only */
-	ctrl->timers[PRI_TIMER_TM20] = 2500;	/* Max time awaiting XID response - Q.921 Appendix IV */
-	ctrl->timers[PRI_TIMER_NM20] = 3;		/* Number of XID retransmits - Q.921 Appendix IV */
+	ctrl->timers[PRI_TIMER_N200] = 3;			/* Max numer of Q.921 retransmissions */
+	ctrl->timers[PRI_TIMER_N202] = 3;			/* Max numer of transmissions of the TEI identity request message */
+	ctrl->timers[PRI_TIMER_K] = 7;				/* Max number of outstanding I-frames */
+	ctrl->timers[PRI_TIMER_T200] = 1000;		/* Time between SABME's */
+	ctrl->timers[PRI_TIMER_T202] = 10 * 1000;	/* Min time between transmission of TEI Identity request messages */
+	ctrl->timers[PRI_TIMER_T203] = 10 * 1000;	/* Max time without exchanging packets */
+	ctrl->timers[PRI_TIMER_T305] = 30 * 1000;	/* Wait for DISCONNECT acknowledge */
+	ctrl->timers[PRI_TIMER_T308] = 4 * 1000;	/* Wait for RELEASE acknowledge */
+	ctrl->timers[PRI_TIMER_T313] = 4 * 1000;	/* Wait for CONNECT acknowledge, CPE side only */
+	ctrl->timers[PRI_TIMER_TM20] = 2500;		/* Max time awaiting XID response - Q.921 Appendix IV */
+	ctrl->timers[PRI_TIMER_NM20] = 3;			/* Number of XID retransmits - Q.921 Appendix IV */
 
 	/* Set any switch specific override default values */
 	switch (switchtype) {
@@ -139,48 +185,13 @@
 
 int pri_timer2idx(const char *timer_name)
 {
-	static const struct {
-		const char *name;
-		int number;
-	} timer[] = {
-/* *INDENT-OFF* */
-		{ "N200", PRI_TIMER_N200 },
-		{ "N201", PRI_TIMER_N201 },
-		{ "N202", PRI_TIMER_N202 },
-		{ "K",    PRI_TIMER_K },
-		{ "T200", PRI_TIMER_T200 },
-		{ "T202", PRI_TIMER_T202 },
-		{ "T203", PRI_TIMER_T203 },
-		{ "T300", PRI_TIMER_T300 },
-		{ "T301", PRI_TIMER_T301 },
-		{ "T302", PRI_TIMER_T302 },
-		{ "T303", PRI_TIMER_T303 },
-		{ "T304", PRI_TIMER_T304 },
-		{ "T305", PRI_TIMER_T305 },
-		{ "T306", PRI_TIMER_T306 },
-		{ "T307", PRI_TIMER_T307 },
-		{ "T308", PRI_TIMER_T308 },
-		{ "T309", PRI_TIMER_T309 },
-		{ "T310", PRI_TIMER_T310 },
-		{ "T313", PRI_TIMER_T313 },
-		{ "T314", PRI_TIMER_T314 },
-		{ "T316", PRI_TIMER_T316 },
-		{ "T317", PRI_TIMER_T317 },
-		{ "T318", PRI_TIMER_T318 },
-		{ "T319", PRI_TIMER_T319 },
-		{ "T320", PRI_TIMER_T320 },
-		{ "T321", PRI_TIMER_T321 },
-		{ "T322", PRI_TIMER_T322 },
-/* *INDENT-ON* */
-	};
-
 	unsigned idx;
-	int timer_number;
+	enum PRI_TIMERS_AND_COUNTERS timer_number;
 
 	timer_number = -1;
-	for (idx = 0; idx < ARRAY_LEN(timer); ++idx) {
-		if (!strcasecmp(timer_name, timer[idx].name)) {
-			timer_number = timer[idx].number;
+	for (idx = 0; idx < ARRAY_LEN(pri_timer); ++idx) {
+		if (!strcasecmp(timer_name, pri_timer[idx].name)) {
+			timer_number = pri_timer[idx].number;
 			break;
 		}
 	}
@@ -692,7 +703,7 @@
 static void pri_sr_init(struct pri_sr *req)
 {
 	memset(req, 0, sizeof(struct pri_sr));
-	
+	req->reversecharge = PRI_REVERSECHARGE_NONE;
 }
 
 int pri_sr_set_connection_call_independent(struct pri_sr *req)
@@ -846,49 +857,102 @@
 	return pri->fd;
 }
 
-char *pri_dump_info_str(struct pri *pri)
-{
-	char buf[4096];
-	int len = 0;
+/*!
+ * \internal
+ * \brief Append snprintf output to the given buffer.
+ *
+ * \param buf Buffer currently filling.
+ * \param buf_used Offset into buffer where to put new stuff.
+ * \param buf_size Actual buffer size of buf.
+ * \param format printf format string.
+ *
+ * \return Total buffer space used.
+ */
+static size_t pri_snprintf(char *buf, size_t buf_used, size_t buf_size, const char *format, ...) __attribute__((format(printf, 4, 5)));
+static size_t pri_snprintf(char *buf, size_t buf_used, size_t buf_size, const char *format, ...)
+{
+	va_list args;
+
+	if (buf_used < buf_size) {
+		va_start(args, format);
+		buf_used += vsnprintf(buf + buf_used, buf_size - buf_used, format, args);
+		va_end(args);
+	}
+	if (buf_size < buf_used) {
+		buf_used = buf_size + 1;
+	}
+	return buf_used;
+}
+
+char *pri_dump_info_str(struct pri *ctrl)
+{
+	char *buf;
+	size_t buf_size;
+	size_t used;
 #ifdef LIBPRI_COUNTERS
 	struct q921_frame *f;
-	int q921outstanding = 0;
+	unsigned q921outstanding;
 #endif
-	if (!pri)
+	unsigned idx;
+	unsigned long switch_bit;
+
+	if (!ctrl) {
 		return NULL;
+	}
+
+	buf_size = 4096;	/* This should be bigger than we will ever need. */
+	buf = malloc(buf_size);
+	if (!buf) {
+		return NULL;
+	}
 
 	/* Might be nice to format these a little better */
-	len += sprintf(buf + len, "Switchtype: %s\n", pri_switch2str(pri->switchtype));
-	len += sprintf(buf + len, "Type: %s\n", pri_node2str(pri->localtype));
+	used = 0;
+	used = pri_snprintf(buf, used, buf_size, "Switchtype: %s\n",
+		pri_switch2str(ctrl->switchtype));
+	used = pri_snprintf(buf, used, buf_size, "Type: %s\n", pri_node2str(ctrl->localtype));
 #ifdef LIBPRI_COUNTERS
 	/* Remember that Q921 Counters include Q931 packets (and any retransmissions) */
-	len += sprintf(buf + len, "Q931 RX: %d\n", pri->q931_rxcount);
-	len += sprintf(buf + len, "Q931 TX: %d\n", pri->q931_txcount);
-	len += sprintf(buf + len, "Q921 RX: %d\n", pri->q921_rxcount);
-	len += sprintf(buf + len, "Q921 TX: %d\n", pri->q921_txcount);
-	f = pri->txqueue;
+	used = pri_snprintf(buf, used, buf_size, "Q931 RX: %d\n", ctrl->q931_rxcount);
+	used = pri_snprintf(buf, used, buf_size, "Q931 TX: %d\n", ctrl->q931_txcount);
+	used = pri_snprintf(buf, used, buf_size, "Q921 RX: %d\n", ctrl->q921_rxcount);
+	used = pri_snprintf(buf, used, buf_size, "Q921 TX: %d\n", ctrl->q921_txcount);
+	q921outstanding = 0;
+	f = ctrl->txqueue;
 	while (f) {
 		q921outstanding++;
 		f = f->next;
 	}
-	len += sprintf(buf + len, "Q921 Outstanding: %d\n", q921outstanding);
+	used = pri_snprintf(buf, used, buf_size, "Q921 Outstanding: %u\n", q921outstanding);
 #endif
-	len += sprintf(buf + len, "Window Length: %d/%d\n", pri->windowlen, pri->window);
-	len += sprintf(buf + len, "Sentrej: %d\n", pri->sentrej);
-	len += sprintf(buf + len, "SolicitFbit: %d\n", pri->solicitfbit);
-	len += sprintf(buf + len, "Retrans: %d\n", pri->retrans);
-	len += sprintf(buf + len, "Busy: %d\n", pri->busy);
-	len += sprintf(buf + len, "Overlap Dial: %d\n", pri->overlapdial);
-	len += sprintf(buf + len, "Logical Channel Mapping: %d\n", pri->chan_mapping_logical);
-	len += sprintf(buf + len, "T200 Timer: %d\n", pri->timers[PRI_TIMER_T200]);
-	len += sprintf(buf + len, "T203 Timer: %d\n", pri->timers[PRI_TIMER_T203]);
-	len += sprintf(buf + len, "T305 Timer: %d\n", pri->timers[PRI_TIMER_T305]);
-	len += sprintf(buf + len, "T308 Timer: %d\n", pri->timers[PRI_TIMER_T308]);
-	len += sprintf(buf + len, "T309 Timer: %d\n", pri->timers[PRI_TIMER_T309]);
-	len += sprintf(buf + len, "T313 Timer: %d\n", pri->timers[PRI_TIMER_T313]);
-	len += sprintf(buf + len, "N200 Counter: %d\n", pri->timers[PRI_TIMER_N200]);
-
-	return strdup(buf);
+	used = pri_snprintf(buf, used, buf_size, "Window Length: %d/%d\n", ctrl->windowlen,
+		ctrl->window);
+	used = pri_snprintf(buf, used, buf_size, "Sentrej: %d\n", ctrl->sentrej);
+	used = pri_snprintf(buf, used, buf_size, "SolicitFbit: %d\n", ctrl->solicitfbit);
+	used = pri_snprintf(buf, used, buf_size, "Retrans: %d\n", ctrl->retrans);
+	used = pri_snprintf(buf, used, buf_size, "Busy: %d\n", ctrl->busy);
+	used = pri_snprintf(buf, used, buf_size, "Overlap Dial: %d\n", ctrl->overlapdial);
+	used = pri_snprintf(buf, used, buf_size, "Logical Channel Mapping: %d\n",
+		ctrl->chan_mapping_logical);
+	used = pri_snprintf(buf, used, buf_size, "Timer and counter settings:\n");
+	switch_bit = PRI_BIT(ctrl->switchtype);
+	for (idx = 0; idx < ARRAY_LEN(pri_timer); ++idx) {
+		if (pri_timer[idx].used_by & switch_bit) {
+			enum PRI_TIMERS_AND_COUNTERS tmr;
+
+			tmr = pri_timer[idx].number;
+			if (0 <= ctrl->timers[tmr] || tmr == PRI_TIMER_T309) {
+				used = pri_snprintf(buf, used, buf_size, "  %s: %d\n",
+					pri_timer[idx].name, ctrl->timers[tmr]);
+			}
+		}
+	}
+
+	if (buf_size < used) {
+		pri_message(ctrl,
+			"pri_dump_info_str(): Produced output exceeded buffer capacity. (Truncated)\n");
+	}
+	return buf;
 }
 
 int pri_get_crv(struct pri *pri, q931_call *call, int *callmode)
@@ -972,3 +1036,8 @@
 	sr->redirectingreason = reason;
 	return 0;
 }
+
+void pri_sr_set_reversecharge(struct pri_sr *sr, int requested)
+{
+	sr->reversecharge = requested;
+}

Modified: team/group/issue10217/pri_internal.h
URL: http://svn.asterisk.org/svn-view/libpri/team/group/issue10217/pri_internal.h?view=diff&rev=934&r1=933&r2=934
==============================================================================
--- team/group/issue10217/pri_internal.h (original)
+++ team/group/issue10217/pri_internal.h Thu Jul  2 12:13:15 2009
@@ -48,10 +48,8 @@
 enum q931_state;
 enum q931_mode;
 
-/* No more than 128 scheduled events */
+/*! Maximum number of scheduled events active at the same time. */
 #define MAX_SCHED 128
-
-#define MAX_TIMERS 32
 
 /*! \brief D channel controller structure */
 struct pri {
@@ -100,7 +98,7 @@
 	int ri;
 	int t200_timer;		/* T-200 retransmission timer */
 	/* All ISDN Timer values */
-	int timers[MAX_TIMERS];
+	int timers[PRI_MAX_TIMERS];
 
 	/* Used by scheduler */
 	struct timeval tv;
@@ -156,6 +154,7 @@
 	int justsignalling;
 	const char *useruserinfo;
 	int transferable;
+	int reversecharge;
 	struct pri_lowlayercompat llc[4];
 };
 
@@ -280,7 +279,10 @@
 	q931_call *bridged_call;        /* Pointer to other leg of bridged call (Used by Q.SIG when eliminating tromboned calls) */
 
 	int changestatus;		/* SERVICE message changestatus */
-	int reversecharge;		/* Reverse charging indication */
+	int reversecharge;		/* Reverse charging indication:
+							   -1 - No reverse charging
+							    1 - Reverse charging
+							0,2-7 - Reserved for future use */
 };
 
 extern int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), void *data);
@@ -291,9 +293,8 @@
 
 extern pri_event *pri_mkerror(struct pri *pri, char *errstr);
 
-extern void pri_message(struct pri *pri, char *fmt, ...);
-
-extern void pri_error(struct pri *pri, char *fmt, ...);
+void pri_message(struct pri *ctrl, char *fmt, ...) __attribute__((format(printf, 2, 3)));
+void pri_error(struct pri *ctrl, char *fmt, ...) __attribute__((format(printf, 2, 3)));
 
 void libpri_copy_string(char *dst, const char *src, size_t size);
 

Modified: team/group/issue10217/q931.c
URL: http://svn.asterisk.org/svn-view/libpri/team/group/issue10217/q931.c?view=diff&rev=934&r1=933&r2=934
==============================================================================
--- team/group/issue10217/q931.c (original)
+++ team/group/issue10217/q931.c Thu Jul  2 12:13:15 2009
@@ -1029,7 +1029,8 @@
 					(data & 0x04)?1:0,
 					(data & 0x02)?1:0);
 			} else {
-				pri_message(ctrl, "%c                                Unknown octet 5b: 0x%x\n", data );
+				pri_message(ctrl, "%c                                Unknown octet 5b: 0x%x\n",
+					prefix, data);
 			}
 			pos++;
 		}
@@ -2335,12 +2336,13 @@
 	type = ie->data[0] & 0x1F;
 	pri_message(ctrl, "%c Generic Digits (len=%02d): Encoding %s  Type %s\n", prefix, len, gdencoding2str(encoding), gdtype2str(type));
 	if (encoding == 3) {	/* Binary */
-		pri_message(ctrl, "%c                            Don't know how to handle binary encoding\n");
+		pri_message(ctrl, "%c                            Don't know how to handle binary encoding\n",
+			prefix);
 		return;
 	}
 	if (len == 3)	/* No number information */
 		return;
-	pri_message(ctrl, "%c                            Digits: ");
+	pri_message(ctrl, "%c                            Digits: ", prefix);
 	value = 0;
 	for(idx = 3; idx < len; ++idx) {
 		switch(encoding) {
@@ -2519,6 +2521,15 @@
 	return 0;
 }
 
+static int transmit_reverse_charging_indication(int full_ie, struct pri *ctrl, q931_call *call, int msgtype, q931_ie *ie, int len, int order)
+{
+	if (call->reversecharge != PRI_REVERSECHARGE_NONE) {
+		ie->data[0] = 0x80 | (call->reversecharge & 0x7);
+		return 3;
+	}
+	return 0;
+}
+
 static struct ie ies[] = {
 	/* Codeset 0 - Common */
 	{ 1, NATIONAL_CHANGE_STATUS, "Change Status", dump_change_status, receive_change_status, transmit_change_status },
@@ -2535,7 +2546,7 @@
 	{ 1, Q931_BINARY_PARAMETERS, "Packet-layer Binary Parameters" },
 	{ 1, Q931_WINDOW_SIZE, "Packet-layer Window Size" },
 	{ 1, Q931_CLOSED_USER_GROUP, "Closed User Group" },
-	{ 1, Q931_REVERSE_CHARGE_INDIC, "Reverse Charging Indication", dump_reverse_charging_indication, receive_reverse_charging_indication },
+	{ 1, Q931_REVERSE_CHARGE_INDIC, "Reverse Charging Indication", dump_reverse_charging_indication, receive_reverse_charging_indication, transmit_reverse_charging_indication },
 	{ 0, Q931_REPEAT_INDIC, "Repeat Indicator", dump_repeat_indicator, receive_repeat_indicator, transmit_repeat_indicator },
 	{ 1, Q931_CALLING_PARTY_NUMBER, "Calling Party Number", dump_calling_party_number, receive_calling_party_number, transmit_calling_party_number },
 	{ 1, Q931_CALLING_PARTY_SUBADDR, "Calling Party Subaddress", dump_calling_party_subaddr, receive_calling_party_subaddr },
@@ -3484,8 +3495,8 @@
 }
 
 static int setup_ies[] = { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT, Q931_IE_FACILITY, Q931_PROGRESS_INDICATOR, Q931_NETWORK_SPEC_FAC, Q931_DISPLAY,
-	Q931_CALLING_PARTY_NUMBER, Q931_CALLED_PARTY_NUMBER, Q931_REDIRECTING_NUMBER, Q931_IE_USER_USER, Q931_SENDING_COMPLETE,
-	Q931_IE_ORIGINATING_LINE_INFO, Q931_IE_GENERIC_DIGITS, -1 };
+	Q931_REVERSE_CHARGE_INDIC, Q931_CALLING_PARTY_NUMBER, Q931_CALLED_PARTY_NUMBER, Q931_REDIRECTING_NUMBER, Q931_IE_USER_USER,
+	Q931_SENDING_COMPLETE, Q931_IE_ORIGINATING_LINE_INFO, Q931_IE_GENERIC_DIGITS, -1 };
 
 static int llc_setup_ies[] = { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT, Q931_IE_FACILITY, Q931_PROGRESS_INDICATOR, Q931_NETWORK_SPEC_FAC, Q931_DISPLAY,
 	Q931_CALLING_PARTY_NUMBER, Q931_CALLED_PARTY_NUMBER, Q931_REDIRECTING_NUMBER, Q931_IE_USER_USER, Q931_REPEAT_INDIC, Q931_LOW_LAYER_COMPAT, Q931_SENDING_COMPLETE,
@@ -3586,6 +3597,8 @@
 		c->progressmask = PRI_PROG_CALLER_NOT_ISDN;
 	else
 		c->progressmask = 0;
+
+	c->reversecharge = req->reversecharge;
 
 	pri_call_add_standard_apdus(ctrl, c);
 
@@ -3830,6 +3843,7 @@
 		c->complete = 0;
 		c->nonisdn = 0;
 		c->aoc_units = -1;
+		c->reversecharge = -1;
 		/* Fall through */
 	case Q931_CONNECT:
 	case Q931_ALERTING:




More information about the libpri-commits mailing list