[svn-commits] jpeeler: branch jpeeler/dahdi-restart r134982 - /team/jpeeler/dahdi-restart/c...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 31 17:00:14 CDT 2008


Author: jpeeler
Date: Thu Jul 31 17:00:13 2008
New Revision: 134982

URL: http://svn.digium.com/view/asterisk?view=rev&rev=134982
Log:
fix module loading/unloading while using SS7

Modified:
    team/jpeeler/dahdi-restart/channels/chan_dahdi.c

Modified: team/jpeeler/dahdi-restart/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/dahdi-restart/channels/chan_dahdi.c?view=diff&rev=134982&r1=134981&r2=134982
==============================================================================
--- team/jpeeler/dahdi-restart/channels/chan_dahdi.c (original)
+++ team/jpeeler/dahdi-restart/channels/chan_dahdi.c Thu Jul 31 17:00:13 2008
@@ -11975,6 +11975,10 @@
     }
 	#endif /* HAVE_PRI */
 
+	#if defined(HAVE_SS7)
+
+	#endif /* HAVE_SS7 */
+
 	restart_pending = 1;
 
     ast_mutex_lock(&monlock);
@@ -12980,6 +12984,458 @@
 	return 0;
 }
 
+#ifdef HAVE_SS7
+static int linkset_addsigchan(int sigchan)
+{
+	struct dahdi_ss7 *link;
+	int res;
+	int curfd;
+	struct dahdi_params p;
+	struct dahdi_bufferinfo bi;
+	struct dahdi_spaninfo si;
+
+
+	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;
+	} else
+		ss7_set_pc(link->ss7, cur_pointcode);
+
+	if (sigchan < 0) {
+		ast_log(LOG_ERROR, "Invalid sigchan!\n");
+		return -1;
+	} else {
+		if (link->numsigchans >= NUM_DCHANS) {
+			ast_log(LOG_ERROR, "Too many sigchans on linkset %d\n", cur_linkset);
+			return -1;
+		}
+		curfd = link->numsigchans;
+
+		link->fds[curfd] = open("/dev/dahdi/channel", O_RDWR, 0600);
+		if ((link->fds[curfd] < 0) || (ioctl(link->fds[curfd],DAHDI_SPECIFY,&sigchan) == -1)) {
+			ast_log(LOG_ERROR, "Unable to open SS7 sigchan %d (%s)\n", sigchan, strerror(errno));
+			return -1;
+		}
+		res = ioctl(link->fds[curfd], DAHDI_GET_PARAMS, &p);
+		if (res) {
+			dahdi_close(link->fds[curfd]);
+			link->fds[curfd] = -1;
+			ast_log(LOG_ERROR, "Unable to get parameters for sigchan %d (%s)\n", sigchan, strerror(errno));
+			return -1;
+		}
+		if ((p.sigtype != DAHDI_SIG_HDLCFCS) && (p.sigtype != DAHDI_SIG_HARDHDLC) && (p.sigtype != DAHDI_SIG_MTP2)) {
+			dahdi_close(link->fds[curfd]);
+			link->fds[curfd] = -1;
+			ast_log(LOG_ERROR, "sigchan %d is not in HDLC/FCS mode.\n", sigchan);
+			return -1;
+		}
+
+		bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
+		bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
+		bi.numbufs = 32;
+		bi.bufsize = 512;
+
+		if (ioctl(link->fds[curfd], DAHDI_SET_BUFINFO, &bi)) {
+			ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d: %s\n", sigchan, strerror(errno));
+			dahdi_close(link->fds[curfd]);
+			link->fds[curfd] = -1;
+			return -1;
+		}
+
+		if (p.sigtype == DAHDI_SIG_MTP2)
+			ss7_add_link(link->ss7, SS7_TRANSPORT_DAHDIMTP2, link->fds[curfd]);
+		else
+			ss7_add_link(link->ss7, SS7_TRANSPORT_DAHDIDCHAN, link->fds[curfd]);
+
+		link->numsigchans++;
+
+		memset(&si, 0, sizeof(si));
+		res = ioctl(link->fds[curfd], DAHDI_SPANSTAT, &si);
+		if (res) {
+			dahdi_close(link->fds[curfd]);
+			link->fds[curfd] = -1;
+			ast_log(LOG_ERROR, "Unable to get span state for sigchan %d (%s)\n", sigchan, strerror(errno));
+		}
+
+		if (!si.alarms) {
+			link->linkstate[curfd] = LINKSTATE_DOWN;
+			ss7_link_noalarm(link->ss7, link->fds[curfd]);
+		} else {
+			link->linkstate[curfd] = LINKSTATE_DOWN | LINKSTATE_INALARM;
+			ss7_link_alarm(link->ss7, link->fds[curfd]);
+		}
+	}
+
+	if (cur_adjpointcode < 0) {
+		ast_log(LOG_ERROR, "Unspecified adjpointcode!\n");
+		return -1;
+	} else {
+		ss7_set_adjpc(link->ss7, link->fds[curfd], cur_adjpointcode);
+	}
+
+	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;
+}
+
+static char *handle_ss7_no_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int span;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "ss7 no debug linkset";
+		e->usage = 
+			"Usage: ss7 no debug linkset <span>\n"
+			"       Disables debugging on a given SS7 linkset\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+	if (a->argc < 5)
+		return CLI_SHOWUSAGE;
+	span = atoi(a->argv[4]);
+	if ((span < 1) || (span > NUM_SPANS)) {
+		ast_cli(a->fd, "Invalid linkset %s.  Should be a number from %d to %d\n", a->argv[4], 1, NUM_SPANS);
+		return CLI_SUCCESS;
+	}
+	if (!linksets[span-1].ss7) {
+		ast_cli(a->fd, "No SS7 running on linkset %d\n", span);
+		return CLI_SUCCESS;
+	}
+	if (linksets[span-1].ss7)
+		ss7_set_debug(linksets[span-1].ss7, 0);
+
+	ast_cli(a->fd, "Disabled debugging on linkset %d\n", span);
+	return CLI_SUCCESS;
+}
+
+static char *handle_ss7_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int span;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "ss7 debug linkset";
+		e->usage = 
+			"Usage: ss7 debug linkset <linkset>\n"
+			"       Enables debugging on a given SS7 linkset\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+	if (a->argc < 4)
+		return CLI_SHOWUSAGE;
+	span = atoi(a->argv[3]);
+	if ((span < 1) || (span > NUM_SPANS)) {
+		ast_cli(a->fd, "Invalid linkset %s.  Should be a number from %d to %d\n", a->argv[3], 1, NUM_SPANS);
+		return CLI_SUCCESS;
+	}
+	if (!linksets[span-1].ss7) {
+		ast_cli(a->fd, "No SS7 running on linkset %d\n", span);
+		return CLI_SUCCESS;
+	}
+	if (linksets[span-1].ss7)
+		ss7_set_debug(linksets[span-1].ss7, SS7_DEBUG_MTP2 | SS7_DEBUG_MTP3 | SS7_DEBUG_ISUP);
+
+	ast_cli(a->fd, "Enabled debugging on linkset %d\n", span);
+	return CLI_SUCCESS;
+}
+
+static char *handle_ss7_block_cic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int linkset, cic;
+	int blocked = -1, i;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "ss7 block cic";
+		e->usage = 
+			"Usage: ss7 block cic <linkset> <CIC>\n"
+			"       Sends a remote blocking request for the given CIC on the specified linkset\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+	if (a->argc == 5)
+		linkset = atoi(a->argv[3]);
+	else
+		return CLI_SHOWUSAGE;
+
+	if ((linkset < 1) || (linkset > NUM_SPANS)) {
+		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+		return CLI_SUCCESS;
+	}
+
+	if (!linksets[linkset-1].ss7) {
+		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
+		return CLI_SUCCESS;
+	}
+
+	cic = atoi(a->argv[4]);
+
+	if (cic < 1) {
+		ast_cli(a->fd, "Invalid CIC specified!\n");
+		return CLI_SUCCESS;
+	}
+
+	for (i = 0; i < linksets[linkset-1].numchans; i++) {
+		if (linksets[linkset-1].pvts[i]->cic == cic) {
+			blocked = linksets[linkset-1].pvts[i]->locallyblocked;
+			if (!blocked) {
+				ast_mutex_lock(&linksets[linkset-1].lock);
+				isup_blo(linksets[linkset-1].ss7, cic, linksets[linkset-1].pvts[i]->dpc);
+				ast_mutex_unlock(&linksets[linkset-1].lock);
+			}
+		}
+	}
+
+	if (blocked < 0) {
+		ast_cli(a->fd, "Invalid CIC specified!\n");
+		return CLI_SUCCESS;
+	}
+
+	if (!blocked)
+		ast_cli(a->fd, "Sent blocking request for linkset %d on CIC %d\n", linkset, cic);
+	else
+		ast_cli(a->fd, "CIC %d already locally blocked\n", cic);
+
+	/* Break poll on the linkset so it sends our messages */
+	pthread_kill(linksets[linkset-1].master, SIGURG);
+
+	return CLI_SUCCESS;
+}
+
+static char *handle_ss7_block_linkset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int linkset;
+	int i;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "ss7 block linkset";
+		e->usage = 
+			"Usage: ss7 block linkset <linkset number>\n"
+			"       Sends a remote blocking request for all CICs on the given linkset\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+	if (a->argc == 4)
+		linkset = atoi(a->argv[3]);
+	else
+		return CLI_SHOWUSAGE;
+
+	if ((linkset < 1) || (linkset > NUM_SPANS)) {
+		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+		return CLI_SUCCESS;
+	}
+
+	if (!linksets[linkset-1].ss7) {
+		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
+		return CLI_SUCCESS;
+	}
+
+	for (i = 0; i < linksets[linkset-1].numchans; i++) {
+		ast_cli(a->fd, "Sending remote blocking request on CIC %d\n", linksets[linkset-1].pvts[i]->cic);
+		ast_mutex_lock(&linksets[linkset-1].lock);
+		isup_blo(linksets[linkset-1].ss7, linksets[linkset-1].pvts[i]->cic, linksets[linkset-1].pvts[i]->dpc);
+		ast_mutex_unlock(&linksets[linkset-1].lock);
+	}
+
+	/* Break poll on the linkset so it sends our messages */
+	pthread_kill(linksets[linkset-1].master, SIGURG);
+
+	return CLI_SUCCESS;
+}
+
+static char *handle_ss7_unblock_cic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int linkset, cic;
+	int i, blocked = -1;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "ss7 unblock cic";
+		e->usage = 
+			"Usage: ss7 unblock cic <linkset> <CIC>\n"
+			"       Sends a remote unblocking request for the given CIC on the specified linkset\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc == 5)
+		linkset = atoi(a->argv[3]);
+	else
+		return CLI_SHOWUSAGE;
+
+	if ((linkset < 1) || (linkset > NUM_SPANS)) {
+		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+		return CLI_SUCCESS;
+	}
+
+	if (!linksets[linkset-1].ss7) {
+		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
+		return CLI_SUCCESS;
+	}
+
+	cic = atoi(a->argv[4]);
+
+	if (cic < 1) {
+		ast_cli(a->fd, "Invalid CIC specified!\n");
+		return CLI_SUCCESS;
+	}
+
+	for (i = 0; i < linksets[linkset-1].numchans; i++) {
+		if (linksets[linkset-1].pvts[i]->cic == cic) {
+			blocked = linksets[linkset-1].pvts[i]->locallyblocked;
+			if (blocked) {
+				ast_mutex_lock(&linksets[linkset-1].lock);
+				isup_ubl(linksets[linkset-1].ss7, cic, linksets[linkset-1].pvts[i]->dpc);
+				ast_mutex_unlock(&linksets[linkset-1].lock);
+			}
+		}
+	}
+
+	if (blocked > 0)
+		ast_cli(a->fd, "Sent unblocking request for linkset %d on CIC %d\n", linkset, cic);
+
+	/* Break poll on the linkset so it sends our messages */
+	pthread_kill(linksets[linkset-1].master, SIGURG);
+
+	return CLI_SUCCESS;
+}
+
+static char *handle_ss7_unblock_linkset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int linkset;
+	int i;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "ss7 unblock linkset";
+		e->usage = 
+			"Usage: ss7 unblock linkset <linkset number>\n"
+			"       Sends a remote unblocking request for all CICs on the specified linkset\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc == 4)
+		linkset = atoi(a->argv[3]);
+	else
+		return CLI_SHOWUSAGE;
+
+	if ((linkset < 1) || (linkset > NUM_SPANS)) {
+		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+		return CLI_SUCCESS;
+	}
+
+	if (!linksets[linkset-1].ss7) {
+		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
+		return CLI_SUCCESS;
+	}
+
+	for (i = 0; i < linksets[linkset-1].numchans; i++) {
+		ast_cli(a->fd, "Sending remote unblock request on CIC %d\n", linksets[linkset-1].pvts[i]->cic);
+		ast_mutex_lock(&linksets[linkset-1].lock);
+		isup_ubl(linksets[linkset-1].ss7, linksets[linkset-1].pvts[i]->cic, linksets[linkset-1].pvts[i]->dpc);
+		ast_mutex_unlock(&linksets[linkset-1].lock);
+	}
+
+	/* Break poll on the linkset so it sends our messages */
+	pthread_kill(linksets[linkset-1].master, SIGURG);
+
+	return CLI_SUCCESS;
+}
+
+static char *handle_ss7_show_linkset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int linkset;
+	struct dahdi_ss7 *ss7;
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "ss7 show linkset";
+		e->usage = 
+			"Usage: ss7 show linkset <span>\n"
+			"       Shows the status of an SS7 linkset.\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc < 4)
+		return CLI_SHOWUSAGE;
+	linkset = atoi(a->argv[3]);
+	if ((linkset < 1) || (linkset > NUM_SPANS)) {
+		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
+		return CLI_SUCCESS;
+	}
+	if (!linksets[linkset-1].ss7) {
+		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
+		return CLI_SUCCESS;
+	}
+	if (linksets[linkset-1].ss7)
+		ss7 = &linksets[linkset-1];
+
+	ast_cli(a->fd, "SS7 linkset %d status: %s\n", linkset, (ss7->state == LINKSET_STATE_UP) ? "Up" : "Down");
+
+	return CLI_SUCCESS;
+}
+
+static char *handle_ss7_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "ss7 show version";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_cli(a->fd, "libss7 version: %s\n", ss7_get_version());
+
+	return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry dahdi_ss7_cli[] = {
+	AST_CLI_DEFINE(handle_ss7_debug, "Enables SS7 debugging on a linkset"), 
+	AST_CLI_DEFINE(handle_ss7_no_debug, "Disables SS7 debugging on a linkset"), 
+	AST_CLI_DEFINE(handle_ss7_block_cic, "Blocks the given CIC"),
+	AST_CLI_DEFINE(handle_ss7_unblock_cic, "Unblocks the given CIC"),
+	AST_CLI_DEFINE(handle_ss7_block_linkset, "Blocks all CICs on a linkset"),
+	AST_CLI_DEFINE(handle_ss7_unblock_linkset, "Unblocks all CICs on a linkset"),
+	AST_CLI_DEFINE(handle_ss7_show_linkset, "Shows the status of a linkset"),
+	AST_CLI_DEFINE(handle_ss7_version, "Displays libss7 version"),
+};
+#endif /* HAVE_SS7 */
+
 static int __unload_module(void)
 {
 	struct dahdi_pvt *p, *pl;
@@ -12994,6 +13450,14 @@
 	}
 	ast_cli_unregister_multiple(dahdi_pri_cli, sizeof(dahdi_pri_cli) / sizeof(struct ast_cli_entry));
 	ast_unregister_application(dahdi_send_keypad_facility_app);
+#endif
+
+#if defined(HAVE_SS7)
+	for (i = 0; i < NUM_SPANS; i++) {
+		if (linksets[i].master != AST_PTHREADT_NULL)
+			pthread_cancel(linksets[i].master );
+	}
+	ast_cli_unregister_multiple(dahdi_ss7_cli, sizeof(dahdi_ss7_cli) / sizeof(struct ast_cli_entry));
 #endif
 
 	ast_cli_unregister_multiple(dahdi_cli, sizeof(dahdi_cli) / sizeof(struct ast_cli_entry));
@@ -13059,464 +13523,14 @@
 	for (i = 0; i < NUM_SPANS; i++) {
 		if (linksets[i].master && (linksets[i].master != AST_PTHREADT_NULL))
 			pthread_join(linksets[i].master, NULL);
-		dahdi_close(linksets[i].fds[i]);
+		for (j = 0; j < NUM_DCHANS; j++) {
+			dahdi_close(linksets[i].fds[j]);
+		}
 	}
 #endif /* HAVE_SS7 */
 
 	return 0;
 }
-
-#ifdef HAVE_SS7
-static int linkset_addsigchan(int sigchan)
-{
-	struct dahdi_ss7 *link;
-	int res;
-	int curfd;
-	struct dahdi_params p;
-	struct dahdi_bufferinfo bi;
-	struct dahdi_spaninfo si;
-
-
-	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;
-	} else
-		ss7_set_pc(link->ss7, cur_pointcode);
-
-	if (sigchan < 0) {
-		ast_log(LOG_ERROR, "Invalid sigchan!\n");
-		return -1;
-	} else {
-		if (link->numsigchans >= NUM_DCHANS) {
-			ast_log(LOG_ERROR, "Too many sigchans on linkset %d\n", cur_linkset);
-			return -1;
-		}
-		curfd = link->numsigchans;
-
-		link->fds[curfd] = open("/dev/dahdi/channel", O_RDWR, 0600);
-		if ((link->fds[curfd] < 0) || (ioctl(link->fds[curfd],DAHDI_SPECIFY,&sigchan) == -1)) {
-			ast_log(LOG_ERROR, "Unable to open SS7 sigchan %d (%s)\n", sigchan, strerror(errno));
-			return -1;
-		}
-		res = ioctl(link->fds[curfd], DAHDI_GET_PARAMS, &p);
-		if (res) {
-			dahdi_close(link->fds[curfd]);
-			link->fds[curfd] = -1;
-			ast_log(LOG_ERROR, "Unable to get parameters for sigchan %d (%s)\n", sigchan, strerror(errno));
-			return -1;
-		}
-		if ((p.sigtype != DAHDI_SIG_HDLCFCS) && (p.sigtype != DAHDI_SIG_HARDHDLC) && (p.sigtype != DAHDI_SIG_MTP2)) {
-			dahdi_close(link->fds[curfd]);
-			link->fds[curfd] = -1;
-			ast_log(LOG_ERROR, "sigchan %d is not in HDLC/FCS mode.\n", sigchan);
-			return -1;
-		}
-
-		bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
-		bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
-		bi.numbufs = 32;
-		bi.bufsize = 512;
-
-		if (ioctl(link->fds[curfd], DAHDI_SET_BUFINFO, &bi)) {
-			ast_log(LOG_ERROR, "Unable to set appropriate buffering on channel %d: %s\n", sigchan, strerror(errno));
-			dahdi_close(link->fds[curfd]);
-			link->fds[curfd] = -1;
-			return -1;
-		}
-
-		if (p.sigtype == DAHDI_SIG_MTP2)
-			ss7_add_link(link->ss7, SS7_TRANSPORT_DAHDIMTP2, link->fds[curfd]);
-		else
-			ss7_add_link(link->ss7, SS7_TRANSPORT_DAHDIDCHAN, link->fds[curfd]);
-
-		link->numsigchans++;
-
-		memset(&si, 0, sizeof(si));
-		res = ioctl(link->fds[curfd], DAHDI_SPANSTAT, &si);
-		if (res) {
-			dahdi_close(link->fds[curfd]);
-			link->fds[curfd] = -1;
-			ast_log(LOG_ERROR, "Unable to get span state for sigchan %d (%s)\n", sigchan, strerror(errno));
-		}
-
-		if (!si.alarms) {
-			link->linkstate[curfd] = LINKSTATE_DOWN;
-			ss7_link_noalarm(link->ss7, link->fds[curfd]);
-		} else {
-			link->linkstate[curfd] = LINKSTATE_DOWN | LINKSTATE_INALARM;
-			ss7_link_alarm(link->ss7, link->fds[curfd]);
-		}
-	}
-
-	if (cur_adjpointcode < 0) {
-		ast_log(LOG_ERROR, "Unspecified adjpointcode!\n");
-		return -1;
-	} else {
-		ss7_set_adjpc(link->ss7, link->fds[curfd], cur_adjpointcode);
-	}
-
-	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;
-}
-
-static char *handle_ss7_no_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	int span;
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "ss7 no debug linkset";
-		e->usage = 
-			"Usage: ss7 no debug linkset <span>\n"
-			"       Disables debugging on a given SS7 linkset\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-	if (a->argc < 5)
-		return CLI_SHOWUSAGE;
-	span = atoi(a->argv[4]);
-	if ((span < 1) || (span > NUM_SPANS)) {
-		ast_cli(a->fd, "Invalid linkset %s.  Should be a number from %d to %d\n", a->argv[4], 1, NUM_SPANS);
-		return CLI_SUCCESS;
-	}
-	if (!linksets[span-1].ss7) {
-		ast_cli(a->fd, "No SS7 running on linkset %d\n", span);
-		return CLI_SUCCESS;
-	}
-	if (linksets[span-1].ss7)
-		ss7_set_debug(linksets[span-1].ss7, 0);
-
-	ast_cli(a->fd, "Disabled debugging on linkset %d\n", span);
-	return CLI_SUCCESS;
-}
-
-static char *handle_ss7_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	int span;
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "ss7 debug linkset";
-		e->usage = 
-			"Usage: ss7 debug linkset <linkset>\n"
-			"       Enables debugging on a given SS7 linkset\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-	if (a->argc < 4)
-		return CLI_SHOWUSAGE;
-	span = atoi(a->argv[3]);
-	if ((span < 1) || (span > NUM_SPANS)) {
-		ast_cli(a->fd, "Invalid linkset %s.  Should be a number from %d to %d\n", a->argv[3], 1, NUM_SPANS);
-		return CLI_SUCCESS;
-	}
-	if (!linksets[span-1].ss7) {
-		ast_cli(a->fd, "No SS7 running on linkset %d\n", span);
-		return CLI_SUCCESS;
-	}
-	if (linksets[span-1].ss7)
-		ss7_set_debug(linksets[span-1].ss7, SS7_DEBUG_MTP2 | SS7_DEBUG_MTP3 | SS7_DEBUG_ISUP);
-
-	ast_cli(a->fd, "Enabled debugging on linkset %d\n", span);
-	return CLI_SUCCESS;
-}
-
-static char *handle_ss7_block_cic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	int linkset, cic;
-	int blocked = -1, i;
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "ss7 block cic";
-		e->usage = 
-			"Usage: ss7 block cic <linkset> <CIC>\n"
-			"       Sends a remote blocking request for the given CIC on the specified linkset\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-	if (a->argc == 5)
-		linkset = atoi(a->argv[3]);
-	else
-		return CLI_SHOWUSAGE;
-
-	if ((linkset < 1) || (linkset > NUM_SPANS)) {
-		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
-		return CLI_SUCCESS;
-	}
-
-	if (!linksets[linkset-1].ss7) {
-		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
-		return CLI_SUCCESS;
-	}
-
-	cic = atoi(a->argv[4]);
-
-	if (cic < 1) {
-		ast_cli(a->fd, "Invalid CIC specified!\n");
-		return CLI_SUCCESS;
-	}
-
-	for (i = 0; i < linksets[linkset-1].numchans; i++) {
-		if (linksets[linkset-1].pvts[i]->cic == cic) {
-			blocked = linksets[linkset-1].pvts[i]->locallyblocked;
-			if (!blocked) {
-				ast_mutex_lock(&linksets[linkset-1].lock);
-				isup_blo(linksets[linkset-1].ss7, cic, linksets[linkset-1].pvts[i]->dpc);
-				ast_mutex_unlock(&linksets[linkset-1].lock);
-			}
-		}
-	}
-
-	if (blocked < 0) {
-		ast_cli(a->fd, "Invalid CIC specified!\n");
-		return CLI_SUCCESS;
-	}
-
-	if (!blocked)
-		ast_cli(a->fd, "Sent blocking request for linkset %d on CIC %d\n", linkset, cic);
-	else
-		ast_cli(a->fd, "CIC %d already locally blocked\n", cic);
-
-	/* Break poll on the linkset so it sends our messages */
-	pthread_kill(linksets[linkset-1].master, SIGURG);
-
-	return CLI_SUCCESS;
-}
-
-static char *handle_ss7_block_linkset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	int linkset;
-	int i;
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "ss7 block linkset";
-		e->usage = 
-			"Usage: ss7 block linkset <linkset number>\n"
-			"       Sends a remote blocking request for all CICs on the given linkset\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-	if (a->argc == 4)
-		linkset = atoi(a->argv[3]);
-	else
-		return CLI_SHOWUSAGE;
-
-	if ((linkset < 1) || (linkset > NUM_SPANS)) {
-		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
-		return CLI_SUCCESS;
-	}
-
-	if (!linksets[linkset-1].ss7) {
-		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
-		return CLI_SUCCESS;
-	}
-
-	for (i = 0; i < linksets[linkset-1].numchans; i++) {
-		ast_cli(a->fd, "Sending remote blocking request on CIC %d\n", linksets[linkset-1].pvts[i]->cic);
-		ast_mutex_lock(&linksets[linkset-1].lock);
-		isup_blo(linksets[linkset-1].ss7, linksets[linkset-1].pvts[i]->cic, linksets[linkset-1].pvts[i]->dpc);
-		ast_mutex_unlock(&linksets[linkset-1].lock);
-	}
-
-	/* Break poll on the linkset so it sends our messages */
-	pthread_kill(linksets[linkset-1].master, SIGURG);
-
-	return CLI_SUCCESS;
-}
-
-static char *handle_ss7_unblock_cic(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	int linkset, cic;
-	int i, blocked = -1;
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "ss7 unblock cic";
-		e->usage = 
-			"Usage: ss7 unblock cic <linkset> <CIC>\n"
-			"       Sends a remote unblocking request for the given CIC on the specified linkset\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-
-	if (a->argc == 5)
-		linkset = atoi(a->argv[3]);
-	else
-		return CLI_SHOWUSAGE;
-
-	if ((linkset < 1) || (linkset > NUM_SPANS)) {
-		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
-		return CLI_SUCCESS;
-	}
-
-	if (!linksets[linkset-1].ss7) {
-		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
-		return CLI_SUCCESS;
-	}
-
-	cic = atoi(a->argv[4]);
-
-	if (cic < 1) {
-		ast_cli(a->fd, "Invalid CIC specified!\n");
-		return CLI_SUCCESS;
-	}
-
-	for (i = 0; i < linksets[linkset-1].numchans; i++) {
-		if (linksets[linkset-1].pvts[i]->cic == cic) {
-			blocked = linksets[linkset-1].pvts[i]->locallyblocked;
-			if (blocked) {
-				ast_mutex_lock(&linksets[linkset-1].lock);
-				isup_ubl(linksets[linkset-1].ss7, cic, linksets[linkset-1].pvts[i]->dpc);
-				ast_mutex_unlock(&linksets[linkset-1].lock);
-			}
-		}
-	}
-
-	if (blocked > 0)
-		ast_cli(a->fd, "Sent unblocking request for linkset %d on CIC %d\n", linkset, cic);
-
-	/* Break poll on the linkset so it sends our messages */
-	pthread_kill(linksets[linkset-1].master, SIGURG);
-
-	return CLI_SUCCESS;
-}
-
-static char *handle_ss7_unblock_linkset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	int linkset;
-	int i;
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "ss7 unblock linkset";
-		e->usage = 
-			"Usage: ss7 unblock linkset <linkset number>\n"
-			"       Sends a remote unblocking request for all CICs on the specified linkset\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-
-	if (a->argc == 4)
-		linkset = atoi(a->argv[3]);
-	else
-		return CLI_SHOWUSAGE;
-
-	if ((linkset < 1) || (linkset > NUM_SPANS)) {
-		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
-		return CLI_SUCCESS;
-	}
-
-	if (!linksets[linkset-1].ss7) {
-		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
-		return CLI_SUCCESS;
-	}
-
-	for (i = 0; i < linksets[linkset-1].numchans; i++) {
-		ast_cli(a->fd, "Sending remote unblock request on CIC %d\n", linksets[linkset-1].pvts[i]->cic);
-		ast_mutex_lock(&linksets[linkset-1].lock);
-		isup_ubl(linksets[linkset-1].ss7, linksets[linkset-1].pvts[i]->cic, linksets[linkset-1].pvts[i]->dpc);
-		ast_mutex_unlock(&linksets[linkset-1].lock);
-	}
-
-	/* Break poll on the linkset so it sends our messages */
-	pthread_kill(linksets[linkset-1].master, SIGURG);
-
-	return CLI_SUCCESS;
-}
-
-static char *handle_ss7_show_linkset(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	int linkset;
-	struct dahdi_ss7 *ss7;
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "ss7 show linkset";
-		e->usage = 
-			"Usage: ss7 show linkset <span>\n"
-			"       Shows the status of an SS7 linkset.\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-
-	if (a->argc < 4)
-		return CLI_SHOWUSAGE;
-	linkset = atoi(a->argv[3]);
-	if ((linkset < 1) || (linkset > NUM_SPANS)) {
-		ast_cli(a->fd, "Invalid linkset %s.  Should be a number %d to %d\n", a->argv[3], 1, NUM_SPANS);
-		return CLI_SUCCESS;
-	}
-	if (!linksets[linkset-1].ss7) {
-		ast_cli(a->fd, "No SS7 running on linkset %d\n", linkset);
-		return CLI_SUCCESS;
-	}
-	if (linksets[linkset-1].ss7)
-		ss7 = &linksets[linkset-1];
-
-	ast_cli(a->fd, "SS7 linkset %d status: %s\n", linkset, (ss7->state == LINKSET_STATE_UP) ? "Up" : "Down");
-
-	return CLI_SUCCESS;
-}
-
-static char *handle_ss7_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "ss7 show version";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-
-	ast_cli(a->fd, "libss7 version: %s\n", ss7_get_version());
-
-	return CLI_SUCCESS;
-}
-
-static struct ast_cli_entry dahdi_ss7_cli[] = {
-	AST_CLI_DEFINE(handle_ss7_debug, "Enables SS7 debugging on a linkset"), 
-	AST_CLI_DEFINE(handle_ss7_no_debug, "Disables SS7 debugging on a linkset"), 
-	AST_CLI_DEFINE(handle_ss7_block_cic, "Blocks the given CIC"),
-	AST_CLI_DEFINE(handle_ss7_unblock_cic, "Unblocks the given CIC"),
-	AST_CLI_DEFINE(handle_ss7_block_linkset, "Blocks all CICs on a linkset"),
-	AST_CLI_DEFINE(handle_ss7_unblock_linkset, "Unblocks all CICs on a linkset"),
-	AST_CLI_DEFINE(handle_ss7_show_linkset, "Shows the status of a linkset"),
-	AST_CLI_DEFINE(handle_ss7_version, "Displays libss7 version"),
-};
-#endif /* HAVE_SS7 */
 
 static int unload_module(void)
 {




More information about the svn-commits mailing list