[asterisk-commits] mattf: branch mattf/asterisk-ss7cluster r242028 - /team/mattf/asterisk-ss7clu...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 21 11:54:34 CST 2010


Author: mattf
Date: Thu Jan 21 11:54:30 2010
New Revision: 242028

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=242028
Log:
Commit new libss7 cluster interface changes for chan_dahdi

Modified:
    team/mattf/asterisk-ss7cluster/channels/chan_dahdi.c

Modified: team/mattf/asterisk-ss7cluster/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/mattf/asterisk-ss7cluster/channels/chan_dahdi.c?view=diff&rev=242028&r1=242027&r2=242028
==============================================================================
--- team/mattf/asterisk-ss7cluster/channels/chan_dahdi.c (original)
+++ team/mattf/asterisk-ss7cluster/channels/chan_dahdi.c Thu Jan 21 11:54:30 2010
@@ -455,6 +455,7 @@
 static int cur_adjpointcode = -1;
 static int cur_networkindicator = -1;
 static int cur_defaultdpc = -1;
+static int cur_slc = -1;
 #endif /* HAVE_SS7 */
 
 #ifdef HAVE_OPENR2
@@ -609,6 +610,8 @@
 	short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
 	struct ast_frame f;		/*!< One frame for each channel.  How did this ever work before? */
 	unsigned int needringing:1;
+	unsigned int needproceeding:1;
+	unsigned int needprogress:1;
 	unsigned int needbusy:1;
 	unsigned int needcongestion:1;
 	unsigned int needcallerid:1;
@@ -1447,14 +1450,41 @@
 #if defined(HAVE_SS7)
 static inline void ss7_rel(struct dahdi_ss7 *ss7)
 {
+	return;
 	ast_mutex_unlock(&ss7->lock);
 }
 #endif	/* defined(HAVE_SS7) */
 
 #if defined(HAVE_SS7)
+static struct dahdi_ss7 * ss7_resolve_linkset(int linkset);
+
+static void ss7_add_slave_to_server(const char *addr)
+{
+	struct dahdi_ss7 *ss7 = ss7_resolve_linkset(cur_linkset);
+	int startcic, endcic;
+	int from_ni1, from_dpc1, to_ni1, to_dpc1, to_opc1;
+	int from_ni2, from_dpc2, to_ni2, to_dpc2, to_opc2;
+
+	if (sscanf(addr, "%d-%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", 
+				&startcic, &endcic,
+				&from_ni1, &from_dpc1, &to_ni1, &to_dpc1, &to_opc1,
+				&from_ni2, &from_dpc2, &to_ni2, &to_dpc2, &to_opc2) != 12) {
+
+		ast_log(LOG_ERROR, "Improperly setup masquerade route %s\n", addr);
+		return;
+	}
+
+
+	isup_masquerade_add_cic_route(ss7->ss7, startcic, endcic, from_ni1, from_dpc1, to_ni1, to_dpc1, to_opc1,
+			from_ni2, from_dpc2, to_ni2, to_dpc2, to_opc2);
+
+	return;
+}
+
 static inline int ss7_grab(struct dahdi_pvt *pvt, struct dahdi_ss7 *pri)
 {
 	int res;
+	return 0;
 	/* Grab the lock first */
 	do {
 		res = ast_mutex_trylock(&pri->lock);
@@ -4364,6 +4394,8 @@
 		p->subs[idx].needanswer = 0;
 		p->subs[idx].needflash = 0;
 		p->subs[idx].needringing = 0;
+		p->subs[idx].needprogress = 0;
+		p->subs[idx].needproceeding = 0;
 		p->subs[idx].needbusy = 0;
 		p->subs[idx].needcongestion = 0;
 		p->subs[idx].linear = 0;
@@ -6786,12 +6818,30 @@
 	}
 #endif
 
+	if (p->subs[idx].needproceeding) {
+		/* Send ringing frame if requested */
+		p->subs[idx].needproceeding = 0;
+		p->subs[idx].f.frametype = AST_FRAME_CONTROL;
+		p->subs[idx].f.subclass = AST_CONTROL_PROCEEDING;
+		ast_mutex_unlock(&p->lock);
+		return &p->subs[idx].f;
+	}
+
 	if (p->subs[idx].needringing) {
 		/* Send ringing frame if requested */
 		p->subs[idx].needringing = 0;
 		p->subs[idx].f.frametype = AST_FRAME_CONTROL;
 		p->subs[idx].f.subclass = AST_CONTROL_RINGING;
 		ast_setstate(ast, AST_STATE_RINGING);
+		ast_mutex_unlock(&p->lock);
+		return &p->subs[idx].f;
+	}
+
+	if (p->subs[idx].needprogress) {
+		/* Send ringing frame if requested */
+		p->subs[idx].needprogress = 0;
+		p->subs[idx].f.frametype = AST_FRAME_CONTROL;
+		p->subs[idx].f.subclass = AST_CONTROL_PROGRESS;
 		ast_mutex_unlock(&p->lock);
 		return &p->subs[idx].f;
 	}
@@ -11356,103 +11406,20 @@
 #if defined(HAVE_SS7)
 static void *ss7_linkset(void *data)
 {
-	int res, i;
-	struct timeval *next = NULL, tv;
+	int i;
 	struct dahdi_ss7 *linkset = (struct dahdi_ss7 *) data;
 	struct ss7 *ss7 = linkset->ss7;
-	ss7_event *e = NULL;
+	ss7_event *e = NULL, ev;
 	struct dahdi_pvt *p;
 	int chanpos;
-	struct pollfd pollers[NUM_DCHANS];
 	int cic;
 	unsigned int dpc;
-	int nextms = 0;
 
 	ss7_start(ss7);
 
 	while(1) {
-		ast_mutex_lock(&linkset->lock);
-		if ((next = ss7_schedule_next(ss7))) {
-			tv = ast_tvnow();
-			tv.tv_sec = next->tv_sec - tv.tv_sec;
-			tv.tv_usec = next->tv_usec - tv.tv_usec;
-			if (tv.tv_usec < 0) {
-				tv.tv_usec += 1000000;
-				tv.tv_sec -= 1;
-			}
-			if (tv.tv_sec < 0) {
-				tv.tv_sec = 0;
-				tv.tv_usec = 0;
-			}
-			nextms = tv.tv_sec * 1000;
-			nextms += tv.tv_usec / 1000;
-		}
-		ast_mutex_unlock(&linkset->lock);
-
-		for (i = 0; i < linkset->numsigchans; i++) {
-			pollers[i].fd = linkset->fds[i];
-			pollers[i].events = ss7_pollflags(ss7, linkset->fds[i]);
-			pollers[i].revents = 0;
-		}
-
-		res = poll(pollers, linkset->numsigchans, nextms);
-		if ((res < 0) && (errno != EINTR)) {
-			ast_log(LOG_ERROR, "poll(%s)\n", strerror(errno));
-		} else if (!res) {
-			ast_mutex_lock(&linkset->lock);
-			ss7_schedule_run(ss7);
-			ast_mutex_unlock(&linkset->lock);
-			continue;
-		}
-
-		ast_mutex_lock(&linkset->lock);
-		for (i = 0; i < linkset->numsigchans; i++) {
-			if (pollers[i].revents & POLLPRI) {
-				int x;
-				if (ioctl(pollers[i].fd, DAHDI_GETEVENT, &x)) {
-					ast_log(LOG_ERROR, "Error in exception retrieval!\n");
-				}
-				switch (x) {
-				case DAHDI_EVENT_OVERRUN:
-					ast_debug(1, "Overrun detected!\n");
-					break;
-				case DAHDI_EVENT_BADFCS:
-					ast_debug(1, "Bad FCS\n");
-					break;
-				case DAHDI_EVENT_ABORT:
-					ast_debug(1, "HDLC Abort\n");
-					break;
-				case DAHDI_EVENT_ALARM:
-					ast_log(LOG_ERROR, "Alarm on link!\n");
-					linkset->linkstate[i] |= (LINKSTATE_DOWN | LINKSTATE_INALARM);
-					linkset->linkstate[i] &= ~LINKSTATE_UP;
-					ss7_link_alarm(ss7, pollers[i].fd);
-					break;
-				case DAHDI_EVENT_NOALARM:
-					ast_log(LOG_ERROR, "Alarm cleared on link\n");
-					linkset->linkstate[i] &= ~(LINKSTATE_INALARM | LINKSTATE_DOWN);
-					linkset->linkstate[i] |= LINKSTATE_STARTING;
-					ss7_link_noalarm(ss7, pollers[i].fd);
-					break;
-				default:
-					ast_log(LOG_ERROR, "Got exception %d!\n", x);
-					break;
-				}
-			}
-
-			if (pollers[i].revents & POLLIN) {
-				res = ss7_read(ss7, pollers[i].fd);
-			}
-
-			if (pollers[i].revents & POLLOUT) {
-				res = ss7_write(ss7, pollers[i].fd);
-				if (res < 0) {
-					ast_debug(1, "Error in write %s\n", strerror(errno));
-				}
-			}
-		}
-
-		while ((e = ss7_check_event(ss7))) {
+		while (ss7_check_event(ss7, &ev)) {
+			e = &ev;
 			switch (e->e) {
 			case SS7_EVENT_UP:
 				if (linkset->state != LINKSET_STATE_UP) {
@@ -11491,16 +11458,13 @@
 					break;
 				case CPG_EVENT_PROGRESS:
 				case CPG_EVENT_INBANDINFO:
-					{
-						struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROGRESS, };
-						ast_debug(1, "Queuing frame PROGRESS on CIC %d\n", p->cic);
-						dahdi_queue_frame(p, &f, linkset);
-						p->progress = 1;
-						p->dialing = 0;
-						if (p->dsp && p->dsp_features) {
-							ast_dsp_set_features(p->dsp, p->dsp_features);
-							p->dsp_features = 0;
-						}
+					p->subs[SUB_REAL].needprogress = 1;
+					ast_debug(1, "Queuing frame PROGRESS on CIC %d\n", p->cic);
+					p->progress = 1;
+					p->dialing = 0;
+					if (p->dsp && p->dsp_features) {
+						ast_dsp_set_features(p->dsp, p->dsp_features);
+						p->dsp_features = 0;
 					}
 					break;
 				default:
@@ -11714,8 +11678,6 @@
 					isup_rel(ss7, e->acm.call, -1);
 					break;
 				} else {
-					struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_PROCEEDING, };
-
 					p = linkset->pvts[chanpos];
 
 					ast_debug(1, "Queueing frame from SS7_EVENT_ACM on CIC %d\n", p->cic);
@@ -11725,8 +11687,8 @@
 					}
 
 					ast_mutex_lock(&p->lock);
-					dahdi_queue_frame(p, &f, linkset);
 					p->proceeding = 1;
+					p->subs[SUB_REAL].needproceeding = 1;
 					p->dialing = 0;
 					/* Send alerting if subscriber is free */
 					if (e->acm.called_party_status_ind == 1) {
@@ -11879,7 +11841,6 @@
 				break;
 			}
 		}
-		ast_mutex_unlock(&linkset->lock);
 	}
 
 	return 0;
@@ -15372,6 +15333,76 @@
 }
 
 #if defined(HAVE_SS7)
+static int linkset_addsigchan(const char *sigchanstr)
+{
+	struct dahdi_ss7 *link;
+	char mysigstr[128];
+	char *addr;
+
+	ast_copy_string(mysigstr, sigchanstr, sizeof(mysigstr));
+
+	addr = mysigstr;
+
+	link = ss7_resolve_linkset(cur_linkset);
+	if (!link) {
+		ast_log(LOG_ERROR, "Invalid linkset number.  Must be between 1 and %d\n", NUM_SPANS + 1);
+		return -1;
+	}
+
+	if (cur_ss7type < 0) {
+		ast_log(LOG_ERROR, "Unspecified or invalid ss7type\n");
+		return -1;
+	}
+
+	if (!link->ss7) {
+		link->ss7 = ss7_new(cur_ss7type);
+	}
+
+	if (!link->ss7) {
+		ast_log(LOG_ERROR, "Can't create new SS7!\n");
+		return -1;
+	}
+
+	link->type = cur_ss7type;
+
+	if (cur_pointcode < 0) {
+		ast_log(LOG_ERROR, "Unspecified pointcode!\n");
+		return -1;
+	}
+
+	if (cur_slc < 0) {
+		ast_log(LOG_ERROR, "Unspecified SLC!\n");
+		return -1;
+	}
+
+	if (ast_strlen_zero(addr)) {
+		ast_log(LOG_ERROR, "Invalid sigchan!\n");
+		return -1;
+	} else {
+		if (ss7_add_link(link->ss7, addr, cur_slc, cur_networkindicator, cur_pointcode, cur_adjpointcode)) {
+			ast_log(LOG_ERROR, "Failed to add link with tech '%s'\n", addr);
+			return -1;
+		} else {
+			ast_log(LOG_ERROR, "Successfully added link with tech '%s'\n", addr);
+		}
+		ss7_set_isup_pc(link->ss7, cur_pointcode);
+	}
+
+	if (cur_defaultdpc < 0) {
+		ast_log(LOG_ERROR, "Unspecified defaultdpc!\n");
+		return -1;
+	}
+
+	if (cur_networkindicator < 0) {
+		ast_log(LOG_ERROR, "Invalid networkindicator!\n");
+		return -1;
+	} else
+		ss7_set_network_ind(link->ss7, cur_networkindicator);
+
+	return 0;
+}
+
+#if 0
 static int linkset_addsigchan(int sigchan)
 {
 	struct dahdi_ss7 *link;
@@ -15492,6 +15523,7 @@
 
 	return 0;
 }
+#endif
 #endif	/* defined(HAVE_SS7) */
 
 #if defined(HAVE_SS7)
@@ -16773,6 +16805,8 @@
 				ast_copy_string(confp->ss7.subscriberprefix, v->value, sizeof(confp->ss7.subscriberprefix));
 			} else if (!strcasecmp(v->name, "ss7_unknownprefix")) {
 				ast_copy_string(confp->ss7.unknownprefix, v->value, sizeof(confp->ss7.unknownprefix));
+			} else if (!strcasecmp(v->name, "ss7_isup_masquerade_route")) {
+  				ss7_add_slave_to_server(v->value);
 			} else if (!strcasecmp(v->name, "ss7_called_nai")) {
 				if (!strcasecmp(v->value, "national")) {
 					confp->ss7.called_nai = SS7_NAI_NATIONAL;
@@ -16798,12 +16832,13 @@
 					ast_log(LOG_WARNING, "Unknown SS7 calling_nai '%s' at line %d.\n", v->value, v->lineno);
 				}
 			} else if (!strcasecmp(v->name, "sigchan")) {
-				int sigchan, res;
-				sigchan = atoi(v->value);
-				res = linkset_addsigchan(sigchan);
+				int res;
+				res = linkset_addsigchan(v->value);
 				if (res < 0)
 					return -1;
 
+			} else if (!strcasecmp(v->name, "slc")) {
+				cur_slc = atoi(v->value);
 			} else if (!strcasecmp(v->name, "ss7_explicitacm")) {
 				struct dahdi_ss7 *link;
 				link = ss7_resolve_linkset(cur_linkset);




More information about the asterisk-commits mailing list