[svn-commits] mattf: branch mattf/libpri-1.4-ntptmp r941 - /team/mattf/libpri-1.4-ntptmp/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jul 17 16:49:05 CDT 2009


Author: mattf
Date: Fri Jul 17 16:49:00 2009
New Revision: 941

URL: http://svn.asterisk.org/svn-view/libpri?view=rev&rev=941
Log:
Add support for checking mode validity when receiving TEI management messages

Modified:
    team/mattf/libpri-1.4-ntptmp/pri.c
    team/mattf/libpri-1.4-ntptmp/pri_internal.h
    team/mattf/libpri-1.4-ntptmp/q921.c
    team/mattf/libpri-1.4-ntptmp/q931.c

Modified: team/mattf/libpri-1.4-ntptmp/pri.c
URL: http://svn.asterisk.org/svn-view/libpri/team/mattf/libpri-1.4-ntptmp/pri.c?view=diff&rev=941&r1=940&r2=941
==============================================================================
--- team/mattf/libpri-1.4-ntptmp/pri.c (original)
+++ team/mattf/libpri-1.4-ntptmp/pri.c Fri Jul 17 16:49:00 2009
@@ -223,7 +223,7 @@
 /* Pass in the master for this function */
 void __pri_free_tei(struct pri * p)
 {
-	free (p);
+	free(p);
 }
 
 struct pri *__pri_new_tei(int fd, int node, int switchtype, struct pri *master, pri_io_cb rd, pri_io_cb wr, void *userdata, int tei, int bri)

Modified: team/mattf/libpri-1.4-ntptmp/pri_internal.h
URL: http://svn.asterisk.org/svn-view/libpri/team/mattf/libpri-1.4-ntptmp/pri_internal.h?view=diff&rev=941&r1=940&r2=941
==============================================================================
--- team/mattf/libpri-1.4-ntptmp/pri_internal.h (original)
+++ team/mattf/libpri-1.4-ntptmp/pri_internal.h Fri Jul 17 16:49:00 2009
@@ -32,6 +32,7 @@
 
 #include <stddef.h>
 #include <sys/time.h>
+#include "pri_q921.h"
 
 #define ARRAY_LEN(arr)	(sizeof(arr) / sizeof((arr)[0]))
 
@@ -294,4 +295,21 @@
 
 void __pri_free_tei(struct pri *p);
 
+static inline int BRI_NT_PTMP(struct pri *ctrl)
+{
+	while (ctrl->master)
+		ctrl = ctrl->master;
+
+	return ctrl->bri && (((ctrl)->localtype == PRI_NETWORK) && ((ctrl)->tei == Q921_TEI_GROUP));
+}
+
+static inline int BRI_TE_PTMP(struct pri *ctrl)
+{
+	while (ctrl->master)
+		ctrl = ctrl->master;
+
+	return ctrl->bri && (((ctrl)->localtype == PRI_CPE) && ((ctrl)->tei == Q921_TEI_GROUP));
+}
+
+
 #endif

Modified: team/mattf/libpri-1.4-ntptmp/q921.c
URL: http://svn.asterisk.org/svn-view/libpri/team/mattf/libpri-1.4-ntptmp/q921.c?view=diff&rev=941&r1=940&r2=941
==============================================================================
--- team/mattf/libpri-1.4-ntptmp/q921.c (original)
+++ team/mattf/libpri-1.4-ntptmp/q921.c Fri Jul 17 16:49:00 2009
@@ -912,6 +912,12 @@
 	int ri;
 	struct pri *sub;
 	int tei;
+
+	if (!BRI_NT_PTMP(pri) && !BRI_TE_PTMP(pri)) {
+		pri_error(pri, "Received MDL/TEI managemement message, but configured for mode other than PTMP!\n");
+		return NULL;
+	}
+
 	if (pri->debug & PRI_DEBUG_Q921_STATE)
 		pri_message(pri, "Received MDL message\n");
 	if (h->data[0] != 0x0f) {
@@ -926,17 +932,19 @@
 	tei = (h->data[4] >> 1);
 	switch(h->data[3]) {
 	case Q921_TEI_IDENTITY_REQUEST:
+		if (!BRI_NT_PTMP(pri)) {
+			return NULL;
+		}
+
 		if (tei != 127) {
 			pri_error(pri, "Received TEI identity request with invalid TEI %d\n", tei);
 			q921_send_tei(pri, Q921_TEI_IDENTITY_DENIED, ri, tei, 1);
 		}
-		/* Go to master */
-		for (sub = pri; sub->master; sub = sub->master);
 		tei = 64;
-/*! \todo XXX Error:  The following loop never terminates! */
-		while(sub->subchannel) {
-			if(sub->subchannel->tei == tei)
+		while (sub->subchannel) {
+			if (sub->subchannel->tei == tei)
 				++tei;
+			sub = sub->subchannel;
 		}
 		sub->subchannel = __pri_new_tei(-1, pri->localtype, pri->switchtype, pri, NULL, NULL, NULL, tei, 1);
 		if (!sub->subchannel) {
@@ -946,6 +954,9 @@
 		q921_send_tei(pri, Q921_TEI_IDENTITY_ASSIGNED, ri, tei, 1);
 		break;
 	case Q921_TEI_IDENTITY_ASSIGNED:
+		if (!BRI_TE_PTMP(pri))
+			return NULL;
+
 		if (ri != pri->ri) {
 			pri_message(pri, "TEI assignment received for invalid Ri %02x (our is %02x)\n", ri, pri->ri);
 			return NULL;
@@ -969,6 +980,8 @@
 		pri->q921_state = Q921_TEI_ASSIGNED;
 		break;
 	case Q921_TEI_IDENTITY_CHECK_REQUEST:
+		if (!BRI_TE_PTMP(pri))
+			return NULL;
 		/* We're assuming one TEI per PRI in TE PTMP mode */
 
 		/* If no subchannel (TEI) ignore */
@@ -981,6 +994,8 @@
 
 		break;
 	case Q921_TEI_IDENTITY_REMOVE:
+		if (!BRI_TE_PTMP(pri))
+			return NULL;
 		/* XXX: Assuming multiframe mode has been disconnected already */
 		if (!pri->subchannel)
 			return NULL;
@@ -1243,6 +1258,28 @@
 	return NULL;
 }
 
+#if 0
+static pri_event *q921_handle_unmatched_frame(struct pri *pri, q921_h *h, int len)
+{
+	pri_error(pri, "Could not find candidate subchannel for received frame with SAPI/TEI of %d/%d.\n", h->h.sapi, h->h.tei);
+	if (h->h.tei < 64) {
+		pri_error(pri, "Do not support manual TEI range. Discarding\n");
+		return NULL;
+	}
+
+	if (h->h.sapi != Q921_CALL_CTRL) {
+		pri_error(pri, "Message with SAPI other than CALL CTRL is discarded\n");
+		return NULL;
+	}
+
+	pri_message(pri, "Sending TEI release, in order to re-establish TEI state\n");
+
+	/* TODO: Send TEI release message here */
+
+	return NULL;
+}
+#endif
+
 static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len)
 {
 	pri_event *ev;
@@ -1268,7 +1305,17 @@
 		if (pri->subchannel)
 			return q921_receive(pri->subchannel, h, len + 2);
 		else {
+			/* This means we couldn't find a candidate subchannel for it...
+			 * Time for some corrective action */
+
+#if 0
+			if (pri->master)
+				return q921_handle_unmatched_frame(pri->master, h, len);
+			else
+				return NULL;
+#else
 			return NULL;
+#endif
 		}
 
 	}

Modified: team/mattf/libpri-1.4-ntptmp/q931.c
URL: http://svn.asterisk.org/svn-view/libpri/team/mattf/libpri-1.4-ntptmp/q931.c?view=diff&rev=941&r1=940&r2=941
==============================================================================
--- team/mattf/libpri-1.4-ntptmp/q931.c (original)
+++ team/mattf/libpri-1.4-ntptmp/q931.c Fri Jul 17 16:49:00 2009
@@ -2675,11 +2675,6 @@
 	*mhb = mh;
 }
 
-static int inline PRI_NT_PTMP(struct pri *ctrl)
-{
-	return (((ctrl)->localtype == PRI_NETWORK) && ((ctrl)->tei == Q921_TEI_GROUP));
-}
-
 static int q931_xmit(struct pri *ctrl, q931_h *h, int len, int cr)
 {
 	/* 
@@ -2690,7 +2685,7 @@
 	 * If those are true, we need to send the SETUP in a UI frame
 	 * instead of an I-frame.
 	 */
-	if (PRI_NT_PTMP(ctrl))
+	if (BRI_NT_PTMP(ctrl))
 		q921_transmit_uiframe(ctrl, h, len);
 	else
 		q921_transmit_iframe(ctrl, h, len, cr);




More information about the svn-commits mailing list