[asterisk-commits] mattf: branch mattf/1.6.0-chan_ccs r270833 - /team/mattf/1.6.0-chan_ccs/chann...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 16 10:50:41 CDT 2010


Author: mattf
Date: Wed Jun 16 10:50:37 2010
New Revision: 270833

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=270833
Log:
Convert chan_ccs bearers into ao2 objects, and convert channel list into hash table

Modified:
    team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c
    team/mattf/1.6.0-chan_ccs/channels/chan_mgcp.c

Modified: team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c
URL: http://svnview.digium.com/svn/asterisk/team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c?view=diff&rev=270833&r1=270832&r2=270833
==============================================================================
--- team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c (original)
+++ team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c Wed Jun 16 10:50:37 2010
@@ -55,6 +55,7 @@
 #include "asterisk/stringfields.h"
 #include "asterisk/abstract_jb.h"
 #include "asterisk/event.h"
+#include "asterisk/astobj2.h"
 
 static const char config[] = "ccs.conf";
 
@@ -195,7 +196,9 @@
 	unsigned int pointcode;
 	unsigned int networkindicator;
 	struct ss7 *ss7;
-	struct ccs_chan *pvts[CCS_MAX_CHANNELS];				/*!< Member channel pvt structs */
+	struct ccs_chan *oldpvts[CCS_MAX_CHANNELS];				/*!< Member channel pvt structs */
+	struct ao2_container *pvts;
+
 	int flags;							/*!< Linkset flags */
 };
 
@@ -328,6 +331,8 @@
 			ast_mutex_unlock(&p->lock);
 		}
 
+		res = -1;
+
 		break;
 	case AST_CONTROL_PROCEEDING:
 		ast_debug(1,"Received AST_CONTROL_PROCEEDING on %s\n",chan->name);
@@ -363,7 +368,7 @@
 		ast_log(LOG_ERROR, "Got indication! %d\n", ind);
 	}
 
-	return 0;
+	return res;
 }
 
 static enum ast_rtp_get_result ccs_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
@@ -769,20 +774,22 @@
 static struct ast_channel * ccs_ss7_new(struct ccs_chan *c, struct ccs_ss7 *ss7, int state, char *called_num)
 {
 	struct ast_channel *ast;
-	int i;
-
 	if (!c) {
-		for (i = 0; i < ss7->numchans; i++) {
-			if (ss7->pvts[i]) {
-				ast_mutex_lock(&ss7->pvts[i]->lock);
-				if (ss7_available(ss7->pvts[i])) {
-					c = ss7->pvts[i];
-					c->owner = &inuse;
-					ast_mutex_unlock(&ss7->pvts[i]->lock);
-					break;
-				}
-				ast_mutex_unlock(&ss7->pvts[i]->lock);
+		struct ao2_iterator i;
+		struct ccs_chan *p = NULL;
+
+		i = ao2_iterator_init(ss7->pvts, 0);
+
+		while ((p = ao2_iterator_next(&i))) {
+			ast_mutex_lock(&p->lock);
+			if (ss7_available(p)) {
+				c = p;
+				c->owner = &inuse;
+				ast_mutex_unlock(&p->lock);
+				break;
 			}
+			ast_mutex_unlock(&p->lock);
+			ao2_ref(p, -1);
 		}
 	}
 
@@ -931,16 +938,16 @@
 	ast_log(LOG_NOTICE, "Code %s\n", __FUNCTION__);
 }
 
-static int ss7_find_cic(struct ccs_ss7 *linkset, int cic, unsigned int dpc)
-{
-	int i;
-	int winner = -1;
-	for (i = 0; i < linkset->numchans; i++) {
-		if (linkset->pvts[i] && ((linkset->pvts[i]->sig.ss7.dpc == dpc) && (linkset->pvts[i]->sig.ss7.cic == cic))) {
-			winner = i;
-			break;
-		}
-	}
+static struct ccs_chan * ss7_find_cic(struct ccs_ss7 *linkset, int cic, unsigned int dpc)
+{
+	struct ccs_chan tmp_chan = {
+		.sig.ss7.dpc = dpc,
+		.sig.ss7.cic = cic,
+	};
+	struct ccs_chan *winner;
+	winner = ao2_find(linkset->pvts, &tmp_chan, OBJ_POINTER);
+	if (winner)
+		ao2_ref(winner, -1);
 	return winner;
 }
 
@@ -948,11 +955,13 @@
 {
 	unsigned char status[32];
 	struct ccs_chan *p = NULL;
-	int i, offset;
-
-	for (i = 0; i < linkset->numchans; i++) {
-		if (linkset->pvts[i] && (linkset->pvts[i]->sig.ss7.dpc == dpc && ((linkset->pvts[i]->sig.ss7.cic >= startcic) && (linkset->pvts[i]->sig.ss7.cic <= endcic)))) {
-			p = linkset->pvts[i];
+	struct ao2_iterator i;
+	int offset;
+
+	i = ao2_iterator_init(linkset->pvts, 0);
+
+	while ((p = ao2_iterator_next(&i))) {
+		if ((p->sig.ss7.dpc == dpc && ((p->sig.ss7.cic >= startcic) && (p->sig.ss7.cic <= endcic)))) {
 			offset = p->sig.ss7.cic - startcic;
 			status[offset] = 0;
 			if (p->locallyblocked)
@@ -967,6 +976,7 @@
 			} else
 				status[offset] |= 0x3 << 2;
 		}
+		ao2_ref(p, -1);
 	}
 
 	if (p)
@@ -978,55 +988,80 @@
 
 static inline void ss7_block_cics(struct ccs_ss7 *linkset, int startcic, int endcic, unsigned int dpc, unsigned char state[], int block)
 {
-	int i;
-
-	for (i = 0; i < linkset->numchans; i++) {
-		if (linkset->pvts[i] && (linkset->pvts[i]->sig.ss7.dpc == dpc && ((linkset->pvts[i]->sig.ss7.cic >= startcic) && (linkset->pvts[i]->sig.ss7.cic <= endcic)))) {
+	int offset = 0;
+	struct ao2_iterator i;
+	struct ccs_chan *p;
+
+	i = ao2_iterator_init(linkset->pvts, 0);
+
+	while ((p = ao2_iterator_next(&i))) {
+		if ((p->sig.ss7.dpc == dpc && ((p->sig.ss7.cic >= startcic) && (p->sig.ss7.cic <= endcic)))) {
 			if (state) {
-				if (state[i])
-					linkset->pvts[i]->remotelyblocked = block;
+				if (state[offset])
+					p->remotelyblocked = block;
 			} else
-				linkset->pvts[i]->remotelyblocked = block;
+				p->remotelyblocked = block;
+			offset++;
 		}
+		ao2_ref(p, -1);
 	}
 }
 
 static void ss7_inservice(struct ccs_ss7 *linkset, int startcic, int endcic, unsigned int dpc)
 {
-	int i;
-
-	for (i = 0; i < linkset->numchans; i++) {
-		if (linkset->pvts[i] && (linkset->pvts[i]->sig.ss7.dpc == dpc && ((linkset->pvts[i]->sig.ss7.cic >= startcic) && (linkset->pvts[i]->sig.ss7.cic <= endcic))))
-			linkset->pvts[i]->inservice = 1;
+	struct ao2_iterator i;
+	struct ccs_chan *p;
+
+	i = ao2_iterator_init(linkset->pvts, 0);
+
+	while ((p = ao2_iterator_next(&i))) {
+		if ((p->sig.ss7.dpc == dpc && ((p->sig.ss7.cic >= startcic) && (p->sig.ss7.cic <= endcic))))
+			p->inservice = 1;
+		ao2_ref(p, -1);
 	}
 }
 
 static void ss7_reset_linkset(struct ccs_ss7 *linkset)
 {
-	int i, startcic = -1, endcic, dpc;
+#if 0
+	struct ao2_iterator i;
+	struct ccs_chan *p;
+#endif
 
 	if (linkset->numchans <= 0)
 		return;
 
-	startcic = linkset->pvts[0]->sig.ss7.cic;
+#if 0
+	i = ao2_iterator_init(linkset->pvts, 0);
+
+	while ((p = ao2_iterator_next(&i))) {
+		isup_rsc(p->sig.ss7.ss7->ss7, p->sig.ss7.cic, p->sig.ss7.dpc);
+		ao2_ref(p, -1);
+	}
+#endif
+
+#if 1
+	int i, startcic = -1, endcic, dpc;
+	startcic = linkset->oldpvts[0]->sig.ss7.cic;
 	/* DB: CIC's DPC fix */
-	dpc = linkset->pvts[0]->sig.ss7.dpc;
+	dpc = linkset->oldpvts[0]->sig.ss7.dpc;
 
 	for (i = 0; i < linkset->numchans; i++) {
-		if (linkset->pvts[i+1] && linkset->pvts[i+1]->sig.ss7.dpc == dpc && ((linkset->pvts[i+1]->sig.ss7.cic - linkset->pvts[i]->sig.ss7.cic) == 1) && (linkset->pvts[i]->sig.ss7.cic - startcic < 31)) {
+		if (linkset->oldpvts[i+1] && linkset->oldpvts[i+1]->sig.ss7.dpc == dpc && ((linkset->oldpvts[i+1]->sig.ss7.cic - linkset->oldpvts[i]->sig.ss7.cic) == 1) && (linkset->oldpvts[i]->sig.ss7.cic - startcic < 31)) {
 			continue;
 		} else {
-			endcic = linkset->pvts[i]->sig.ss7.cic;
+			endcic = linkset->oldpvts[i]->sig.ss7.cic;
 			ast_verbose("Resetting CICs %d to %d\n", startcic, endcic);
 			isup_grs(linkset->ss7, startcic, endcic, dpc);
 
 			/* DB: CIC's DPC fix */
-			if (linkset->pvts[i+1]) {
-				startcic = linkset->pvts[i+1]->sig.ss7.cic;
-				dpc = linkset->pvts[i+1]->sig.ss7.dpc;
+			if (linkset->oldpvts[i+1]) {
+				startcic = linkset->oldpvts[i+1]->sig.ss7.cic;
+				dpc = linkset->oldpvts[i+1]->sig.ss7.dpc;
 			}
 		}
 	}
+#endif
 }
 
 static void ccs_loopback(struct ccs_chan *p, int enable)
@@ -1191,15 +1226,15 @@
 
 static void *ss7_linkset(void *data)
 {
-	int i;
+	//int i;
 	struct ccs_ss7 *linkset = (struct ccs_ss7 *) data;
 	struct ss7 *ss7 = linkset->ss7;
 	ss7_event *e = NULL;
 	ss7_event ev;
 	struct ccs_chan *p;
-	int chanpos;
 	int cic;
 	unsigned int dpc;
+	struct ao2_iterator i;
 
 	ss7_start(ss7);
 
@@ -1216,11 +1251,12 @@
 				break;
 			case SS7_EVENT_DOWN:
 				ast_verbose("--- SS7 Down ---\n");
+
 				linkset->state = LINKSET_STATE_DOWN;
-				for (i = 0; i < linkset->numchans; i++) {
-					struct ccs_chan *p = linkset->pvts[i];
-					if (p)
-						p->inalarm = 1;
+
+				i = ao2_iterator_init(linkset->pvts, 0);
+				while ((p = ao2_iterator_next(&i))) {
+					p->inalarm = 1;
 				}
 				break;
 			case MTP2_LINK_UP:
@@ -1230,12 +1266,11 @@
 				ast_log(LOG_WARNING, "MTP2 link down (SLC %d)\n", e->gen.data);
 				break;
 			case ISUP_EVENT_CPG:
-				chanpos = ss7_find_cic(linkset, e->cpg.cic, e->cpg.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->cpg.cic, e->cpg.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "CPG on unconfigured CIC %d\n", e->cpg.cic);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 				switch (e->cpg.event) {
 				case CPG_EVENT_ALERTING:
 					{
@@ -1271,12 +1306,11 @@
 				break;
 			case ISUP_EVENT_RSC:
 				ast_verbose("Resetting CIC %d\n", e->rsc.cic);
-				chanpos = ss7_find_cic(linkset, e->rsc.cic, e->rsc.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->rsc.cic, e->rsc.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "RSC on unconfigured CIC %d\n", e->rsc.cic);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 				ast_mutex_lock(&p->lock);
 
 				p->inservice = 1;
@@ -1294,12 +1328,11 @@
 				break;
 			case ISUP_EVENT_GRS:
 				ast_debug(1, "Got Reset for CICs %d to %d: Acknowledging\n", e->grs.startcic, e->grs.endcic);
-				chanpos = ss7_find_cic(linkset, e->grs.startcic, e->grs.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->grs.startcic, e->grs.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "GRS on unconfigured CIC %d\n", e->grs.startcic);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 				isup_gra(ss7, e->grs.startcic, e->grs.endcic, e->grs.opc);
 				ss7_block_cics(linkset, e->grs.startcic, e->grs.endcic, e->grs.opc, NULL, 0);
 				break;
@@ -1314,13 +1347,12 @@
 				break;
 			case ISUP_EVENT_IAM:
  				ast_debug(1, "Got IAM for CIC %d and called number %s, calling number %s\n", e->iam.cic, e->iam.called_party_num, e->iam.calling_party_num);
-				chanpos = ss7_find_cic(linkset, e->iam.cic, e->iam.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->iam.cic, e->iam.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "IAM on unconfigured CIC %d\n", e->iam.cic);
 					isup_rel(ss7, e->iam.call, -1);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 				ast_mutex_lock(&p->lock);
 				if (!ss7_available(p)) {
 					if (p->sig.ss7.call == e->iam.call) {
@@ -1407,13 +1439,12 @@
 				}
 				break;
 			case ISUP_EVENT_COT:
-				chanpos = ss7_find_cic(linkset, e->cot.cic, e->cot.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->cot.cic, e->cot.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "COT on unconfigured CIC %d\n", e->cot.cic);
 					isup_rel(ss7, e->cot.call, -1);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 
 				ccs_loopback(p, 0);
 
@@ -1422,13 +1453,11 @@
 				break;
 			case ISUP_EVENT_CCR:
 				ast_debug(1, "Got CCR request on CIC %d\n", e->ccr.cic);
-				chanpos = ss7_find_cic(linkset, e->ccr.cic, e->ccr.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->ccr.cic, e->ccr.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "CCR on unconfigured CIC %d\n", e->ccr.cic);
 					break;
 				}
-
-				p = linkset->pvts[chanpos];
 
 				ast_mutex_lock(&p->lock);
 				ccs_loopback(p, 1);
@@ -1438,13 +1467,11 @@
 				break;
 			case ISUP_EVENT_CVT:
 				ast_debug(1, "Got CVT request on CIC %d\n", e->cvt.cic);
-				chanpos = ss7_find_cic(linkset, e->cvt.cic, e->cvt.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->cvt.cic, e->cvt.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "CVT on unconfigured CIC %d\n", e->cvt.cic);
 					break;
 				}
-				
-				p = linkset->pvts[chanpos];
 				
 				ast_mutex_lock(&p->lock);
 				ccs_loopback(p, 1);
@@ -1456,15 +1483,13 @@
 			{
 				struct ast_channel *owner;
 
-				chanpos = ss7_find_cic(linkset, e->rel.cic, e->rel.opc);
-
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->rel.cic, e->rel.opc);
+
+				if (!p) {
 					ast_log(LOG_WARNING, "REL on unconfigured CIC %d\n", e->rel.cic);
 					break;
 				}
 
-				p = linkset->pvts[chanpos];
-
 				ast_mutex_lock(&p->lock);
 
 				owner = p->owner;
@@ -1490,16 +1515,14 @@
 				break;
 			}
 			case ISUP_EVENT_ACM:
-				chanpos = ss7_find_cic(linkset, e->acm.cic, e->acm.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->acm.cic, e->acm.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "ACM on unconfigured CIC %d\n", e->acm.cic);
 					isup_rel(ss7, e->acm.call, -1);
 					break;
 				} else {
 					struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROCEEDING, };
 					struct ast_frame af = { AST_FRAME_CONTROL, AST_CONTROL_RINGING, };
-
-					p = linkset->pvts[chanpos];
 
 					ast_debug(1, "Queueing frame from SS7_EVENT_ACM on CIC %d\n", p->sig.ss7.cic);
 					
@@ -1519,32 +1542,29 @@
 				}
 				break;
 			case ISUP_EVENT_CGB:
- 				chanpos = ss7_find_cic(linkset, e->cgb.startcic, e->cgb.opc);
- 				if (chanpos < 0) {
+ 				p = ss7_find_cic(linkset, e->cgb.startcic, e->cgb.opc);
+ 				if (!p) {
  					ast_log(LOG_WARNING, "CGB on unconfigured CIC %d\n", e->cgb.startcic);
  					break;
  				}
- 				p = linkset->pvts[chanpos];
 				ss7_block_cics(linkset, e->cgb.startcic, e->cgb.endcic, e->cgb.opc, e->cgb.status, 1);
  				isup_cgba(linkset->ss7, e->cgb.startcic, e->cgb.endcic, e->cgb.opc, e->cgb.status, e->cgb.type);
 				break;
 			case ISUP_EVENT_CGU:
- 				chanpos = ss7_find_cic(linkset, e->cgu.startcic, e->cgu.opc);
- 				if (chanpos < 0) {
+ 				p = ss7_find_cic(linkset, e->cgu.startcic, e->cgu.opc);
+ 				if (!p) {
  					ast_log(LOG_WARNING, "CGU on unconfigured CIC %d\n", e->cgu.startcic);
  					break;
  				}
- 				p = linkset->pvts[chanpos];
 				ss7_block_cics(linkset, e->cgu.startcic, e->cgu.endcic, e->cgu.opc, e->cgu.status, 0);
  				isup_cgua(linkset->ss7, e->cgu.startcic, e->cgu.endcic, e->cgu.opc, e->cgu.status, e->cgu.type);
 				break;
 			case ISUP_EVENT_UCIC:
-				chanpos = ss7_find_cic(linkset, e->ucic.cic, e->ucic.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->ucic.cic, e->ucic.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "UCIC on unconfigured CIC %d\n", e->ucic.cic);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 				ast_debug(1, "Unequiped Circuit Id Code on CIC %d\n", e->ucic.cic);
 				ast_mutex_lock(&p->lock);
 				p->remotelyblocked = 1;
@@ -1552,12 +1572,11 @@
 				ast_mutex_unlock(&p->lock);			//doesn't require a SS7 acknowledgement
 				break;
 			case ISUP_EVENT_BLO:
-				chanpos = ss7_find_cic(linkset, e->blo.cic, e->blo.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->blo.cic, e->blo.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "BLO on unconfigured CIC %d\n", e->blo.cic);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 				ast_debug(1, "Blocking CIC %d\n", e->blo.cic);
 				ast_mutex_lock(&p->lock);
 				p->remotelyblocked = 1;
@@ -1565,24 +1584,22 @@
 				isup_bla(linkset->ss7, e->blo.cic, p->sig.ss7.dpc);
 				break;
 			case ISUP_EVENT_BLA:
-				chanpos = ss7_find_cic(linkset, e->bla.cic, e->bla.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->bla.cic, e->bla.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "BLA on unconfigured CIC %d\n", e->bla.cic);
 					break;
 				}
 				ast_debug(1, "Blocking CIC %d\n", e->bla.cic);
-				p = linkset->pvts[chanpos];
 				ast_mutex_lock(&p->lock);
 				p->locallyblocked = 1;
 				ast_mutex_unlock(&p->lock);
 				break;
 			case ISUP_EVENT_UBL:
-				chanpos = ss7_find_cic(linkset, e->ubl.cic, e->ubl.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->ubl.cic, e->ubl.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "UBL on unconfigured CIC %d\n", e->ubl.cic);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 				ast_debug(1, "Unblocking CIC %d\n", e->ubl.cic);
 				ast_mutex_lock(&p->lock);
 				p->remotelyblocked = 0;
@@ -1590,12 +1607,11 @@
 				isup_uba(linkset->ss7, e->ubl.cic, p->sig.ss7.dpc);
 				break;
 			case ISUP_EVENT_UBA:
-				chanpos = ss7_find_cic(linkset, e->uba.cic, e->uba.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->uba.cic, e->uba.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "UBA on unconfigured CIC %d\n", e->uba.cic);
 					break;
 				}
-				p = linkset->pvts[chanpos];
 				ast_debug(1, "Unblocking CIC %d\n", e->uba.cic);
 				ast_mutex_lock(&p->lock);
 				p->locallyblocked = 0;
@@ -1608,15 +1624,14 @@
 				else
 					cic = e->anm.cic;
 
-				chanpos = ss7_find_cic(linkset, cic, (e->e == ISUP_EVENT_ANM) ? e->anm.opc : e->con.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, cic, (e->e == ISUP_EVENT_ANM) ? e->anm.opc : e->con.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "ANM/CON on unconfigured CIC %d\n", cic);
 					isup_rel(ss7, (e->e == ISUP_EVENT_ANM) ? e->anm.call : e->con.call, -1);
 					break;
 				} else {
 					struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER, };
 
-					p = linkset->pvts[chanpos];
 					ast_mutex_lock(&p->lock);
 					ccs_queue_frame(p, &f);
 					ast_mutex_unlock(&p->lock);
@@ -1624,13 +1639,12 @@
 				}
 				break;
 			case ISUP_EVENT_RLC:
-				chanpos = ss7_find_cic(linkset, e->rlc.cic, e->rlc.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->rlc.cic, e->rlc.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "RLC on unconfigured CIC %d:%d\n", e->rlc.cic, e->rlc.opc);
 					break;
 				} else {
 					struct ast_channel *bearer;
-					p = linkset->pvts[chanpos];
 					ast_mutex_lock(&p->lock);
 					if (p->alreadyhungup) {
 						p->sig.ss7.call = NULL;
@@ -1652,12 +1666,11 @@
 				}
 				break;
 			case ISUP_EVENT_FAA:
-				chanpos = ss7_find_cic(linkset, e->faa.cic, e->faa.opc);
-				if (chanpos < 0) {
+				p = ss7_find_cic(linkset, e->faa.cic, e->faa.opc);
+				if (!p) {
 					ast_log(LOG_WARNING, "FAA on unconfigured CIC %d\n", e->faa.cic);
 					break;
 				} else {
-					p = linkset->pvts[chanpos];
 					ast_debug(1, "FAA received on CIC %d\n", e->faa.cic);
 					ast_mutex_lock(&p->lock);
 					if (p->alreadyhungup){
@@ -1772,7 +1785,7 @@
 		return -1;
 	}
 
-	chan = ast_calloc(1, sizeof(*chan));
+	chan = ao2_alloc(sizeof(*chan), NULL);
 
 	if (!chan)
 		return -1;
@@ -1784,7 +1797,7 @@
 	chan->sig.ss7.dpc = dpc;
 	chan->sig.ss7.cic = cic;
 
-	ss7->pvts[ss7->numchans++] = chan;
+	ss7->oldpvts[ss7->numchans++] = chan;
 	chan->sig.ss7.ss7 = ss7;
 
 	chan->sigtype = CCS_SIG_SS7;
@@ -1792,7 +1805,9 @@
 
 	ast_mutex_init(&chan->lock);
 
-	ast_verb(3, "Adding SS7 CIC %d:%d (%s %s) to linkset \'%s\'\n", cic, dpc, tech, dialstr, ss7->name);
+	ao2_link(ss7->pvts, chan);
+
+	ast_verb(3, "Added SS7 CIC %d:%d (%s %s) to linkset \'%s\'\n", cic, dpc, tech, dialstr, ss7->name);
 
 	return 0;
 }
@@ -1851,6 +1866,19 @@
 	return ccs_add_ss7_channel(ss7, defaultdpc, cic, techstr, dialstr, context);
 }
 
+static int linkset_pvts_hash_cb(const void *obj, const int flags)
+{
+	const struct ccs_chan *p = obj;
+
+	return p->sig.ss7.cic;
+}
+
+static int linkset_pvts_cmp_cb(void *obj, void *arg, int flags)
+{
+	const struct ccs_chan *p1 = obj, *p2 = arg;
+
+	return ((p1->sig.ss7.cic == p2->sig.ss7.cic) && (p1->sig.ss7.dpc == p2->sig.ss7.dpc)) ? 1 : 0;
+}
 
 static struct ccs_ss7 * build_linkset(char *name, struct ast_variable *v)
 {
@@ -1871,6 +1899,10 @@
 	ss7->master = AST_PTHREADT_NULL;
 
 	ast_copy_string(ss7->name, name, sizeof(ss7->name));
+
+	ss7->pvts = ao2_container_alloc(CCS_MAX_CHANNELS, linkset_pvts_hash_cb, linkset_pvts_cmp_cb);
+	if (!ss7->pvts)
+		goto failed_out;
 
 	for (; v; v = v->next) {
 		if (!strcasecmp(v->name, "ss7type")) {
@@ -2078,7 +2110,7 @@
 		if (strcasecmp(cat, "general")) {
 			if (signalling_is_ss7(ast_variable_browse(cfg, cat))) {
 
-				ast_log(LOG_VERBOSE, "Found SS7 signalled group %s\n", cat);
+				ast_log(LOG_VERBOSE, "Found SS7 linkset %s\n", cat);
 				for (i = 0; i < CCS_MAX_LINKSETS; i++) {
 					if (!linksets[i]) {
 						break;

Modified: team/mattf/1.6.0-chan_ccs/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/mattf/1.6.0-chan_ccs/channels/chan_mgcp.c?view=diff&rev=270833&r1=270832&r2=270833
==============================================================================
--- team/mattf/1.6.0-chan_ccs/channels/chan_mgcp.c (original)
+++ team/mattf/1.6.0-chan_ccs/channels/chan_mgcp.c Wed Jun 16 10:50:37 2010
@@ -1487,7 +1487,7 @@
 			ind, control2str(ind), ast->name);
 	}
 	ast_mutex_lock(&sub->lock);
-	if (p->type != TYPE_LINE)
+	if (p->type != TYPE_LINE && ind != AST_CONTROL_SRCUPDATE)
 		goto out;
 	switch(ind) {
 	case AST_CONTROL_RINGING:




More information about the asterisk-commits mailing list