[svn-commits] rmudgett: branch rmudgett/link_q931 r1992 - /team/rmudgett/link_q931/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Sep 13 17:01:08 CDT 2010


Author: rmudgett
Date: Mon Sep 13 17:01:03 2010
New Revision: 1992

URL: http://svnview.digium.com/svn/libpri?view=rev&rev=1992
Log:
Initial TEI link association restructuring. Untested.

Modified:
    team/rmudgett/link_q931/pri.c
    team/rmudgett/link_q931/pri_facility.c
    team/rmudgett/link_q931/pri_internal.h
    team/rmudgett/link_q931/pri_q921.h
    team/rmudgett/link_q931/pri_q931.h
    team/rmudgett/link_q931/q921.c
    team/rmudgett/link_q931/q931.c

Modified: team/rmudgett/link_q931/pri.c
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/link_q931/pri.c?view=diff&rev=1992&r1=1991&r2=1992
==============================================================================
--- team/rmudgett/link_q931/pri.c (original)
+++ team/rmudgett/link_q931/pri.c Mon Sep 13 17:01:03 2010
@@ -402,7 +402,8 @@
 		break;
 	}
 
-	if (p->tei == Q921_TEI_GROUP && p->sapi == Q921_SAPI_LAYER2_MANAGEMENT && p->localtype == PRI_CPE) {
+	if (p->tei == Q921_TEI_GROUP && p->sapi == Q921_SAPI_LAYER2_MANAGEMENT
+		&& p->localtype == PRI_CPE) {
 		p->subchannel = __pri_new_tei(-1, p->localtype, p->switchtype, p, NULL, NULL, NULL, Q921_TEI_PRI, 1);
 		if (!p->subchannel) {
 			free(p);

Modified: team/rmudgett/link_q931/pri_facility.c
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/link_q931/pri_facility.c?view=diff&rev=1992&r1=1991&r2=1992
==============================================================================
--- team/rmudgett/link_q931/pri_facility.c (original)
+++ team/rmudgett/link_q931/pri_facility.c Mon Sep 13 17:01:03 2010
@@ -2556,6 +2556,7 @@
 
 	switch (reason) {
 	case APDU_CALLBACK_REASON_MSG_RESULT:
+/* BUGBUG need a link here */
 		call_2 = q931_find_call(ctrl, apdu->response.user.value);
 		if (!call_2) {
 			break;

Modified: team/rmudgett/link_q931/pri_internal.h
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/link_q931/pri_internal.h?view=diff&rev=1992&r1=1991&r2=1992
==============================================================================
--- team/rmudgett/link_q931/pri_internal.h (original)
+++ team/rmudgett/link_q931/pri_internal.h Mon Sep 13 17:01:03 2010
@@ -448,9 +448,10 @@
 
 /* q931_call datastructure */
 struct q931_call {
-	struct pri *pri;	/* PRI */
+	struct pri *pri;	/* D channel controller (master) */
+	struct pri *link;	/* Q.921 link associated with this call. */
+	q931_call *next;
 	int cr;				/* Call Reference */
-	q931_call *next;
 	/* Slotmap specified (bitmap of channels 31/24-1) (Channel Identifier IE) (-1 means not specified) */
 	int slotmap;
 	/* An explicit channel (Channel Identifier IE) (-1 means not specified) */
@@ -899,7 +900,7 @@
 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);
 void __pri_free_tei(struct pri *p);
 
-void q931_init_call_record(struct pri *ctrl, struct q931_call *call, int cr);
+void q931_init_call_record(struct pri *link, struct q931_call *call, int cr);
 
 void pri_sr_init(struct pri_sr *req);
 

Modified: team/rmudgett/link_q931/pri_q921.h
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/link_q931/pri_q921.h?view=diff&rev=1992&r1=1991&r2=1992
==============================================================================
--- team/rmudgett/link_q931/pri_q921.h (original)
+++ team/rmudgett/link_q931/pri_q921.h Mon Sep 13 17:01:03 2010
@@ -195,7 +195,7 @@
 
 extern pri_event *q921_receive(struct pri *pri, q921_h *h, int len);
 
-extern int q921_transmit_iframe(struct pri *pri, int tei, void *buf, int len, int cr);
+int q921_transmit_iframe(struct pri *link, void *buf, int len, int cr);
 
 int q921_transmit_uiframe(struct pri *link, void *buf, int len);
 

Modified: team/rmudgett/link_q931/pri_q931.h
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/link_q931/pri_q931.h?view=diff&rev=1992&r1=1991&r2=1992
==============================================================================
--- team/rmudgett/link_q931/pri_q931.h (original)
+++ team/rmudgett/link_q931/pri_q931.h Mon Sep 13 17:01:03 2010
@@ -456,7 +456,7 @@
 /* Q.SIG specific */
 #define QSIG_IE_TRANSIT_COUNT		0x31
 
-extern int q931_receive(struct pri *pri, int tei, q931_h *h, int len);
+int q931_receive(struct pri *link, q931_h *h, int len);
 
 extern int q931_alerting(struct pri *pri, q931_call *call, int channel, int info);
 
@@ -491,8 +491,8 @@
 
 extern int q931_call_setcrv(struct pri *pri, q931_call *call, int crv, int callmode);
 
-struct q931_call *q931_find_call(struct pri *ctrl, int cr);
-struct q931_call *q931_new_call(struct pri *pri);
+struct q931_call *q931_find_call(struct pri *link, int cr);
+struct q931_call *q931_new_call(struct pri *ctrl);
 
 extern int q931_setup(struct pri *pri, q931_call *c, struct pri_sr *req);
 

Modified: team/rmudgett/link_q931/q921.c
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/link_q931/q921.c?view=diff&rev=1992&r1=1991&r2=1992
==============================================================================
--- team/rmudgett/link_q931/q921.c (original)
+++ team/rmudgett/link_q931/q921.c Mon Sep 13 17:01:03 2010
@@ -797,41 +797,33 @@
 }
 
 /* This is the equivalent of a DL-DATA request, as well as the I-frame queued up outcome */
-int q921_transmit_iframe(struct pri *link, int tei, void *buf, int len, int cr)
+int q921_transmit_iframe(struct pri *link, void *buf, int len, int cr)
 {
 	q921_frame *f, *prev=NULL;
 	struct pri *ctrl;
 
 	ctrl = PRI_MASTER(link);
 
-	if (BRI_NT_PTMP(ctrl)) {
-		if (tei == Q921_TEI_GROUP) {
-			pri_error(ctrl, "Huh?! For NT-PTMP, we shouldn't be sending I-frames out the group TEI\n");
+	if (PTMP_MODE(ctrl)) {
+		if (link->tei == Q921_TEI_GROUP) {
+			pri_error(ctrl, "Huh?! For PTMP, we shouldn't be sending I-frames out the group TEI\n");
 			return 0;
 		}
-
-		link = pri_find_tei(ctrl, Q921_SAPI_CALL_CTRL, tei);
-		if (!link) {
-			pri_error(ctrl, "Huh?! Unable to locate PRI associated with TEI %d.  Did we have to ditch it due to error conditions?\n", tei);
-			return 0;
-		}
-	} else if (BRI_TE_PTMP(ctrl)) {
-		/* We don't care what the tei is, since we only support one sub and one TEI */
-		link = ctrl->subchannel;
-
-		switch (link->q921_state) {
-		case Q921_TEI_UNASSIGNED:
-			q921_setstate(link, Q921_ESTABLISH_AWAITING_TEI);
-			q921_tei_request(link);
-			break;
-		case Q921_ASSIGN_AWAITING_TEI:
-			q921_setstate(link, Q921_ESTABLISH_AWAITING_TEI);
-			break;
-		default:
-			break;
+		if (BRI_TE_PTMP(ctrl)) {
+			switch (link->q921_state) {
+			case Q921_TEI_UNASSIGNED:
+				q921_setstate(link, Q921_ESTABLISH_AWAITING_TEI);
+				q921_tei_request(link);
+				break;
+			case Q921_ASSIGN_AWAITING_TEI:
+				q921_setstate(link, Q921_ESTABLISH_AWAITING_TEI);
+				break;
+			default:
+				break;
+			}
 		}
 	} else {
-		/* Should just be PTP modes, which shouldn't have subs */
+		/* PTP modes, which shouldn't have subs */
 	}
 
 	/* Figure B.7/Q.921 Page 70 */
@@ -2266,9 +2258,9 @@
 		}
 		if (delay_q931_receive) {
 			/* Q.921 has finished processing the frame so we can give it to Q.931 now. */
-			res = q931_receive(link, link->tei, (q931_h *) h->i.data, len - 4);
+			res = q931_receive(link, (q931_h *) h->i.data, len - 4);
 			if (res != -1 && (res & Q931_RES_HAVEEVENT)) {
-				eres = &link->ev;
+				eres = &ctrl->ev;
 			}
 		}
 		break;
@@ -2515,9 +2507,9 @@
 			if (ctrl->debug & PRI_DEBUG_Q931_DUMP) {
 				q931_dump(ctrl, link->tei, (q931_h *) h->u.data, len - 3, 0);
 			}
-			res = q931_receive(link, link->tei, (q931_h *) h->u.data, len - 3);
+			res = q931_receive(link, (q931_h *) h->u.data, len - 3);
 			if (res != -1 && (res & Q931_RES_HAVEEVENT)) {
-				ev = &link->ev;
+				ev = &ctrl->ev;
 			}
 			break;
 		case 0x08:

Modified: team/rmudgett/link_q931/q931.c
URL: http://svnview.digium.com/svn/libpri/team/rmudgett/link_q931/q931.c?view=diff&rev=1992&r1=1991&r2=1992
==============================================================================
--- team/rmudgett/link_q931/q931.c (original)
+++ team/rmudgett/link_q931/q931.c Mon Sep 13 17:01:03 2010
@@ -3690,7 +3690,7 @@
 /*!
  * \brief Initialize the call record.
  *
- * \param ctrl D channel controller.
+ * \param link Q.921 link associated with the call.
  * \param call Q.931 call leg.
  * \param cr Call Reference identifier.
  *
@@ -3698,7 +3698,7 @@
  *
  * \return Nothing
  */
-void q931_init_call_record(struct pri *ctrl, struct q931_call *call, int cr)
+void q931_init_call_record(struct pri *link, struct q931_call *call, int cr)
 {
 	call->cr = cr;
 	call->slotmap = -1;
@@ -3734,33 +3734,29 @@
 	q931_party_number_init(&call->ani);
 	q931_party_redirecting_init(&call->redirecting);
 
-	/* PRI is set to whoever called us */
-	if (BRI_TE_PTMP(ctrl)) {
-		/*
-		 * Point to the master to avoid stale pointer problems if
-		 * the TEI is removed later.
-		 */
-		call->pri = PRI_MASTER(ctrl);
-	} else {
-		call->pri = ctrl;
-	}
+	/* The call is now attached to whoever called us */
+	call->pri = PRI_MASTER(link);
+	call->link = link;
 }
 
 /*!
  * \internal
  * \brief Create a new call record.
  *
- * \param ctrl D channel controller.
+ * \param link Q.921 link associated with the call.
  * \param cr Call Reference identifier.
  *
  * \retval record on success.
  * \retval NULL on error.
  */
-static struct q931_call *q931_create_call_record(struct pri *ctrl, int cr)
+static struct q931_call *q931_create_call_record(struct pri *link, int cr)
 {
 	struct q931_call *call;
 	struct q931_call *prev;
-	struct pri *master;
+	struct pri *ctrl;
+
+	/* Find the master - He has the call pool */
+	ctrl = PRI_MASTER(link);
 
 	if (ctrl->debug & PRI_DEBUG_Q931_STATE) {
 		pri_message(ctrl, "-- Making new call for cref %d\n", cr);
@@ -3772,20 +3768,17 @@
 	}
 
 	/* Initialize call structure. */
-	q931_init_call_record(ctrl, call, cr);
-
-	/* Find the master - He has the call pool */
-	master = PRI_MASTER(ctrl);
+	q931_init_call_record(link, call, cr);
 
 	/* Append to the list end */
-	if (*master->callpool) {
+	if (*ctrl->callpool) {
 		/* Find the list end. */
-		for (prev = *master->callpool; prev->next; prev = prev->next) {
+		for (prev = *ctrl->callpool; prev->next; prev = prev->next) {
 		}
 		prev->next = call;
 	} else {
 		/* List was empty. */
-		*master->callpool = call;
+		*ctrl->callpool = call;
 	}
 
 	return call;
@@ -3794,40 +3787,40 @@
 /*!
  * \brief Find a call in the active call pool.
  *
- * \param ctrl D channel controller.
+ * \param link Q.921 link associated with the call.
  * \param cr Call Reference identifier.
  *
  * \retval call if found.
  * \retval NULL if not found.
  */
-struct q931_call *q931_find_call(struct pri *ctrl, int cr)
+struct q931_call *q931_find_call(struct pri *link, int cr)
 {
 	struct q931_call *cur;
-	struct pri *master;
+	struct pri *ctrl;
 
 	if (cr == Q931_DUMMY_CALL_REFERENCE) {
-		return ctrl->dummy_call;
+		return link->dummy_call;
 	}
 
 	/* Find the master - He has the call pool */
-	master = PRI_MASTER(ctrl);
+	ctrl = PRI_MASTER(link);
 
 	if (BRI_NT_PTMP(ctrl) && !(cr & Q931_CALL_REFERENCE_FLAG)) {
-		if (ctrl->tei == Q921_TEI_GROUP) {
-			/* Broadcast TEI.  This is bad.  We are using the wrong ctrl structure. */
+		if (link->tei == Q921_TEI_GROUP) {
+			/* Broadcast TEI.  This is bad.  We are using the wrong link structure. */
 			pri_error(ctrl, "Looking for cref %d when using broadcast TEI.\n", cr);
 			return NULL;
 		}
 
 		/* We are looking for a call reference value that the other side allocated. */
-		for (cur = *master->callpool; cur; cur = cur->next) {
-			if (cur->cr == cr && cur->pri == ctrl) {
-				/* Found existing call.  The call reference and TEI matched. */
+		for (cur = *ctrl->callpool; cur; cur = cur->next) {
+			if (cur->cr == cr && cur->link == link) {
+				/* Found existing call.  The call reference and link matched. */
 				break;
 			}
 		}
 	} else {
-		for (cur = *master->callpool; cur; cur = cur->next) {
+		for (cur = *ctrl->callpool; cur; cur = cur->next) {
 			if (cur->cr == cr) {
 				/* Found existing call. */
 				switch (ctrl->switchtype) {
@@ -3838,8 +3831,9 @@
 					break;
 				default:
 					if (!ctrl->bri) {
-						/* PRI is set to whoever called us */
+						/* The call is now attached to whoever called us */
 						cur->pri = ctrl;
+						cur->link = link;
 					}
 					break;
 				}
@@ -3850,51 +3844,57 @@
 	return cur;
 }
 
-static struct q931_call *q931_getcall(struct pri *ctrl, int cr)
+static struct q931_call *q931_getcall(struct pri *link, int cr)
 {
 	struct q931_call *cur;
 
-	cur = q931_find_call(ctrl, cr);
+	cur = q931_find_call(link, cr);
 	if (cur) {
 		return cur;
 	}
 
 	/* No call record exists, make a new one */
-	return q931_create_call_record(ctrl, cr);
+	return q931_create_call_record(link, cr);
 }
 
 struct q931_call *q931_new_call(struct pri *ctrl)
 {
 	struct q931_call *cur;
-	struct pri *master;
+	struct pri *link;
 	int first_cref;
 	int cref;
 
 	/* Find the master - He has the call pool */
-	master = PRI_MASTER(ctrl);
+	ctrl = PRI_MASTER(ctrl);
+
+	if (BRI_TE_PTMP(ctrl)) {
+		link = ctrl->subchannel;
+	} else {
+		link = ctrl;
+	}
 
 	/* Find a new call reference value. */
-	first_cref = master->cref;
+	first_cref = ctrl->cref;
 	do {
-		cref = Q931_CALL_REFERENCE_FLAG | master->cref;
+		cref = Q931_CALL_REFERENCE_FLAG | ctrl->cref;
 
 		/* Next call reference. */
-		++master->cref;
-		if (!master->bri) {
-			if (master->cref > 32767) {
-				master->cref = 1;
+		++ctrl->cref;
+		if (!ctrl->bri) {
+			if (ctrl->cref > 32767) {
+				ctrl->cref = 1;
 			}
 		} else {
-			if (master->cref > 127) {
-				master->cref = 1;
+			if (ctrl->cref > 127) {
+				ctrl->cref = 1;
 			}
 		}
 
 		/* Is the call reference value in use? */
-		for (cur = *master->callpool; cur; cur = cur->next) {
+		for (cur = *ctrl->callpool; cur; cur = cur->next) {
 			if (cur->cr == cref) {
 				/* Yes it is in use. */
-				if (first_cref == master->cref) {
+				if (first_cref == ctrl->cref) {
 					/* All call reference values are in use! */
 					return NULL;
 				}
@@ -3903,7 +3903,7 @@
 		}
 	} while (cur);
 
-	return q931_create_call_record(ctrl, cref);
+	return q931_create_call_record(link, cref);
 }
 
 static void stop_t303(struct q931_call *call);
@@ -4387,20 +4387,23 @@
 	*mhb = mh;
 }
 
-static int q931_xmit(struct pri *ctrl, int tei, q931_h *h, int len, int cr, int uiframe)
-{
+static int q931_xmit(struct pri *link, q931_h *h, int len, int cr, int uiframe)
+{
+	struct pri *ctrl;
+
+	ctrl = PRI_MASTER(link);
 #ifdef LIBPRI_COUNTERS
 	ctrl->q931_txcount++;
 #endif
 	if (uiframe) {
-		q921_transmit_uiframe(ctrl, h, len);
+		q921_transmit_uiframe(link, h, len);
 		if (ctrl->debug & PRI_DEBUG_Q931_DUMP) {
 			/*
 			 * The transmit operation might dump the Q.921 header, so logging
 			 * the Q.931 message body after the transmit puts the sections of
 			 * the message in the right order in the log,
 			 */
-			q931_dump(ctrl, tei, h, len, 1);
+			q931_dump(ctrl, link->tei, h, len, 1);
 		}
 	} else {
 		/*
@@ -4411,9 +4414,9 @@
 		 * Q.931 message as appropriate at that time.
 		 */
 		if (ctrl->debug & PRI_DEBUG_Q931_DUMP) {
-			q931_to_q921_passing_dump(ctrl, tei, h, len);
-		}
-		q921_transmit_iframe(ctrl, tei, h, len, cr);
+			q931_to_q921_passing_dump(ctrl, link->tei, h, len);
+		}
+		q921_transmit_iframe(link, h, len, cr);
 	}
 	return 0;
 }
@@ -4444,12 +4447,18 @@
 	int x;
 	int codeset;
 	int uiframe;
-	int tei;
 
 	if (call->outboundbroadcast && call->master_call == call && msgtype != Q931_SETUP) {
 		pri_error(ctrl,
 			"Attempting to use master call record to send %s on BRI PTMP NT %p\n",
 			msg2str(msgtype), ctrl);
+		return -1;
+	}
+
+	if (!call->link) {
+		pri_error(ctrl,
+			"Call w/ cref:%d is not associated with a link.  TEI removed due to error conditions?\n",
+			call->cr);
 		return -1;
 	}
 
@@ -4473,7 +4482,6 @@
 	/* Invert the logic */
 	len = sizeof(buf) - len;
 
-	tei = call->pri->tei;
 	uiframe = 0;
 	if (BRI_NT_PTMP(ctrl)) {
 		/* NT PTMP is the only mode that can broadcast Q.931 messages. */
@@ -4490,7 +4498,7 @@
 			uiframe = 1;
 			break;
 		case Q931_FACILITY:
-			if (tei == Q921_TEI_GROUP) {
+			if (call->link->tei == Q921_TEI_GROUP) {
 				/* Broadcast TEI. */
 				if (q931_is_dummy_call(call)) {
 					/*
@@ -4512,17 +4520,11 @@
 		if (ctrl->debug & PRI_DEBUG_Q931_STATE) {
 			/* This message is only interesting for NT PTMP mode. */
 			pri_message(ctrl,
-				"Sending message for call %p on call->pri: %p with TEI/SAPI %d/%d\n",
-				call, call->pri, call->pri->tei, call->pri->sapi);
-		}
-	} else if (call->pri->subchannel && BRI_TE_PTMP(ctrl)) {
-		/*
-		 * Get the best available TEI value for the debug dump display.
-		 * We may not actually have a TEI assigned at the moment.
-		 */
-		tei = call->pri->subchannel->tei;
-	}
-	q931_xmit(call->pri, tei, h, len, 1, uiframe);
+				"Sending message for call %p on call->link: %p with TEI/SAPI %d/%d\n",
+				call, call->link, call->link->tei, call->link->sapi);
+		}
+	}
+	q931_xmit(call->link, h, len, 1, uiframe);
 	call->acked = 1;
 	return 0;
 }
@@ -5864,9 +5866,6 @@
 
 static void pri_create_fake_clearing(struct q931_call *c, struct pri *master)
 {
-	/* Point to the master so the timeout event can come out. */
-	c->pri = master;
-
 	pri_schedule_del(master, c->retranstimer);
 	c->retranstimer = pri_schedule_event(master, 0, pri_fake_clearing, c);
 }
@@ -6356,16 +6355,19 @@
 	}
 }
 
-static struct q931_call *q931_get_subcall(struct pri *ctrl, struct q931_call *master_call)
+static struct q931_call *q931_get_subcall(struct pri *link, struct q931_call *master_call)
 {
 	int i;
 	struct q931_call *cur;
+	struct pri *ctrl;
 	int firstfree = -1;
+
+	ctrl = PRI_MASTER(link);
 
 	/* First try to locate our subcall */
 	for (i = 0; i < ARRAY_LEN(master_call->subcalls); ++i) {
 		if (master_call->subcalls[i]) {
-			if (master_call->subcalls[i]->pri == ctrl) {
+			if (master_call->subcalls[i]->link == link) {
 				return master_call->subcalls[i];
 			}
 		} else if (firstfree == -1) {
@@ -6385,7 +6387,8 @@
 		return NULL;
 	}
 	*cur = *master_call;
-	cur->pri = ctrl;
+	//cur->pri = ctrl;/* We get this assignment for free. */
+	cur->link = link;
 	cur->next = NULL;
 	cur->apdus = NULL;
 	cur->bridged_call = NULL;
@@ -6405,16 +6408,17 @@
 
 	if (ctrl->debug & PRI_DEBUG_Q931_STATE) {
 		pri_message(ctrl, "Adding subcall %p for TEI %d to call %p at position %d\n",
-			cur, ctrl->tei, master_call, firstfree);
+			cur, link->tei, master_call, firstfree);
 	}
 	/* Should only get here if the TEI is not found */
 	return cur;
 }
 
-int q931_receive(struct pri *ctrl, int tei, q931_h *h, int len)
+int q931_receive(struct pri *link, q931_h *h, int len)
 {
 	q931_mh *mh;
 	struct q931_call *c;
+	struct pri *ctrl;
 	q931_ie *ie;
 	unsigned int x;
 	int y;
@@ -6428,6 +6432,7 @@
 	int allow_event;
 	int allow_posthandle;
 
+	ctrl = PRI_MASTER(link);
 	memset(last_ie, 0, sizeof(last_ie));
 #ifdef LIBPRI_COUNTERS
 	ctrl->q931_rxcount++;
@@ -6447,7 +6452,7 @@
 			   KLUDGE this by changing byte 4 from a 0xf (SERVICE)
 			   to a 0x7 (SERVICE ACKNOWLEDGE) */
 			h->raw[h->crlen + 2] -= 0x8;
-			q931_xmit(ctrl, ctrl->tei, h, len, 1, 0);
+			q931_xmit(link, h, len, 1, 0);
 			return 0;
 		}
 		break;
@@ -6462,13 +6467,13 @@
 	}
 
 	cref = q931_cr(h);
-	c = q931_getcall(ctrl, cref);
+	c = q931_getcall(link, cref);
 	if (!c) {
 		pri_error(ctrl, "Unable to locate call %d\n", cref);
 		return -1;
 	}
-	if (c->master_call->outboundbroadcast && ctrl != PRI_MASTER(ctrl)) {
-		c = q931_get_subcall(ctrl, c->master_call);
+	if (c->master_call->outboundbroadcast && link != ctrl) {
+		c = q931_get_subcall(link, c->master_call);
 		if (!c) {
 			pri_error(ctrl, "Unable to locate subcall for %d\n", cref);
 			return -1;
@@ -6477,10 +6482,8 @@
 
 	if (ctrl->debug & PRI_DEBUG_Q931_STATE) {
 		pri_message(ctrl,
-			"Received message for call %p on %p TEI/SAPI %d/%d, call->pri is %p TEI/SAPI %d/%d\n",
-			c,
-			ctrl, ctrl->tei, ctrl->sapi,
-			c->pri, c->pri->tei, c->pri->sapi);
+			"Received message for call %p on %p TEI/SAPI %d/%d\n",
+			c, link, link->tei, link->sapi);
 	}
 
 	/* Preliminary handling */
@@ -8346,10 +8349,6 @@
 	struct q931_call *c = data;
 	struct pri *ctrl = c->pri;
 
-	/* Point to the master so the timeout event can come out. */
-	ctrl = PRI_MASTER(ctrl);
-	c->pri = ctrl;
-
 	if (ctrl->debug & PRI_DEBUG_Q931_STATE)
 		pri_message(ctrl, "T309 timed out waiting for data link re-establishment\n");
 
@@ -8365,10 +8364,6 @@
 	struct q931_call *c = data;
 	struct pri *ctrl = c->pri;
 
-	/* Point to the master so the timeout event can come out. */
-	ctrl = PRI_MASTER(ctrl);
-	c->pri = ctrl;
-
 	if (ctrl->debug & PRI_DEBUG_Q931_STATE)
 		pri_message(ctrl, "Cancel call after data link failure\n");
 
@@ -8418,7 +8413,7 @@
 			/* Does this master call have a subcall on the link that went down? */
 			call = NULL;
 			for (idx = 0; idx < ARRAY_LEN(cur->subcalls); ++idx) {
-				if (cur->subcalls[idx] && cur->subcalls[idx]->pri == link) {
+				if (cur->subcalls[idx] && cur->subcalls[idx]->link == link) {
 					/* This subcall is on the link that went down. */
 					call = cur->subcalls[idx];
 					break;
@@ -8428,7 +8423,7 @@
 				/* No subcall is on the link that went down. */
 				continue;
 			}
-		} else if (cur->pri != link) {
+		} else if (cur->link != link) {
 			/* This call is not on the link that went down. */
 			continue;
 		} else {
@@ -8446,7 +8441,7 @@
 				call->cr, call->channelno, call->ourcallstate,
 				q931_call_state_str(call->ourcallstate));
 		}
-		call->pri = ctrl;/* Point to a safer place until the call is destroyed. */
+		call->link = NULL;
 		pri_schedule_del(ctrl, call->retranstimer);
 		call->retranstimer = pri_schedule_event(ctrl, 0, pri_dl_down_cancelcall, call);
 	}
@@ -8467,11 +8462,6 @@
 	/* Find the master - He has the call pool */
 	ctrl = PRI_MASTER(link);
 
-	if (BRI_TE_PTMP(ctrl)) {
-		/* The link is always the master */
-		link = ctrl;
-	}
-
 	switch (event) {
 	case PRI_EVENT_DCHAN_DOWN:
 		if (ctrl->debug & PRI_DEBUG_Q931_STATE) {
@@ -8486,7 +8476,7 @@
 				/* Does this master call have a subcall on the link that went down? */
 				call = NULL;
 				for (idx = 0; idx < ARRAY_LEN(cur->subcalls); ++idx) {
-					if (cur->subcalls[idx] && cur->subcalls[idx]->pri == link) {
+					if (cur->subcalls[idx] && cur->subcalls[idx]->link == link) {
 						/* This subcall is on the link that went down. */
 						call = cur->subcalls[idx];
 						break;
@@ -8496,7 +8486,7 @@
 					/* No subcall is on the link that went down. */
 					continue;
 				}
-			} else if (cur->pri != link) {
+			} else if (cur->link != link) {
 				/* This call is not on the link that went down. */
 				continue;
 			} else {
@@ -8570,7 +8560,7 @@
 				/* Does this master call have a subcall on the link that came up? */
 				call = NULL;
 				for (idx = 0; idx < ARRAY_LEN(cur->subcalls); ++idx) {
-					if (cur->subcalls[idx] && cur->subcalls[idx]->pri == link) {
+					if (cur->subcalls[idx] && cur->subcalls[idx]->link == link) {
 						/* This subcall is on the link that came up. */
 						call = cur->subcalls[idx];
 						break;
@@ -8580,7 +8570,7 @@
 					/* No subcall is on the link that came up. */
 					continue;
 				}
-			} else if (cur->pri != link) {
+			} else if (cur->link != link) {
 				/* This call is not on the link that came up. */
 				continue;
 			} else {




More information about the svn-commits mailing list