[asterisk-commits] rmudgett: branch rmudgett/sig_ss7 r261912 - /team/rmudgett/sig_ss7/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri May 7 13:51:43 CDT 2010
Author: rmudgett
Date: Fri May 7 13:51:39 2010
New Revision: 261912
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=261912
Log:
Separate non-DAHDI SS7 code out of linkset_addsigchan() into sig_ss7_add_sigchan().
Modified:
team/rmudgett/sig_ss7/channels/chan_dahdi.c
team/rmudgett/sig_ss7/channels/sig_ss7.h
Modified: team/rmudgett/sig_ss7/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/sig_ss7/channels/chan_dahdi.c?view=diff&rev=261912&r1=261911&r2=261912
==============================================================================
--- team/rmudgett/sig_ss7/channels/chan_dahdi.c (original)
+++ team/rmudgett/sig_ss7/channels/chan_dahdi.c Fri May 7 13:51:39 2010
@@ -16050,125 +16050,115 @@
}
#if defined(HAVE_SS7)
-/* BUGBUG need to convert for sig_ss7 similar to prepare_pri() */
static int linkset_addsigchan(int sigchan)
{
struct dahdi_ss7 *link;
int res;
int curfd;
- struct dahdi_params p;
+ struct dahdi_params params;
struct dahdi_bufferinfo bi;
struct dahdi_spaninfo si;
-
+ if (sigchan < 0) {
+ ast_log(LOG_ERROR, "Invalid sigchan!\n");
+ return -1;
+ }
+ if (cur_ss7type < 0) {
+ ast_log(LOG_ERROR, "Unspecified or invalid ss7type\n");
+ return -1;
+ }
+ if (cur_pointcode < 0) {
+ ast_log(LOG_ERROR, "Unspecified pointcode!\n");
+ return -1;
+ }
+ if (cur_adjpointcode < 0) {
+ ast_log(LOG_ERROR, "Unspecified adjpointcode!\n");
+ return -1;
+ }
+ 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;
+ }
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");
+ if (link->ss7.numsigchans >= SIG_SS7_NUM_DCHANS) {
+ ast_log(LOG_ERROR, "Too many sigchans on linkset %d\n", cur_linkset);
return -1;
}
- if (!link->ss7.ss7) {
- link->ss7.ss7 = ss7_new(cur_ss7type);
- }
-
- if (!link->ss7.ss7) {
- ast_log(LOG_ERROR, "Can't create new SS7!\n");
+ curfd = link->ss7.numsigchans;
+
+ /* Open signaling channel */
+ link->ss7.fds[curfd] = open("/dev/dahdi/channel", O_RDWR, 0600);
+ if (link->ss7.fds[curfd] < 0) {
+ ast_log(LOG_ERROR, "Unable to open SS7 sigchan %d (%s)\n", sigchan,
+ strerror(errno));
return -1;
}
-
- link->ss7.type = cur_ss7type;
-
- if (cur_pointcode < 0) {
- ast_log(LOG_ERROR, "Unspecified pointcode!\n");
+ if (ioctl(link->ss7.fds[curfd], DAHDI_SPECIFY, &sigchan) == -1) {
+ dahdi_close_ss7_fd(link, curfd);
+ ast_log(LOG_ERROR, "Unable to specify SS7 sigchan %d (%s)\n", sigchan,
+ strerror(errno));
return -1;
- } else
- ss7_set_pc(link->ss7.ss7, cur_pointcode);
-
- if (sigchan < 0) {
- ast_log(LOG_ERROR, "Invalid sigchan!\n");
+ }
+
+ /* Get signaling channel parameters */
+ memset(¶ms, 0, sizeof(params));
+ res = ioctl(link->ss7.fds[curfd], DAHDI_GET_PARAMS, ¶ms);
+ if (res) {
+ dahdi_close_ss7_fd(link, curfd);
+ ast_log(LOG_ERROR, "Unable to get parameters for sigchan %d (%s)\n", sigchan,
+ strerror(errno));
return -1;
- } else {
- if (link->ss7.numsigchans >= SIG_SS7_NUM_DCHANS) {
- ast_log(LOG_ERROR, "Too many sigchans on linkset %d\n", cur_linkset);
- return -1;
- }
- curfd = link->ss7.numsigchans;
-
- link->ss7.fds[curfd] = open("/dev/dahdi/channel", O_RDWR, 0600);
- if ((link->ss7.fds[curfd] < 0) || (ioctl(link->ss7.fds[curfd],DAHDI_SPECIFY,&sigchan) == -1)) {
- ast_log(LOG_ERROR, "Unable to open SS7 sigchan %d (%s)\n", sigchan, strerror(errno));
- return -1;
- }
- memset(&p, 0, sizeof(p));
- res = ioctl(link->ss7.fds[curfd], DAHDI_GET_PARAMS, &p);
- if (res) {
- dahdi_close_ss7_fd(link, curfd);
- 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_ss7_fd(link, curfd);
- ast_log(LOG_ERROR, "sigchan %d is not in HDLC/FCS mode.\n", sigchan);
- return -1;
- }
-
- memset(&bi, 0, sizeof(bi));
- bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
- bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
- bi.numbufs = 32;
- bi.bufsize = 512;
-
- if (ioctl(link->ss7.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_ss7_fd(link, curfd);
- return -1;
- }
-
- if (p.sigtype == DAHDI_SIG_MTP2)
- ss7_add_link(link->ss7.ss7, SS7_TRANSPORT_DAHDIMTP2, link->ss7.fds[curfd]);
- else
- ss7_add_link(link->ss7.ss7, SS7_TRANSPORT_DAHDIDCHAN, link->ss7.fds[curfd]);
-
- link->ss7.numsigchans++;
-
- memset(&si, 0, sizeof(si));
- res = ioctl(link->ss7.fds[curfd], DAHDI_SPANSTAT, &si);
- if (res) {
- dahdi_close_ss7_fd(link, curfd);
- ast_log(LOG_ERROR, "Unable to get span state for sigchan %d (%s)\n", sigchan, strerror(errno));
- }
-
- if (!si.alarms) {
- link->ss7.linkstate[curfd] = LINKSTATE_DOWN;
- ss7_link_noalarm(link->ss7.ss7, link->ss7.fds[curfd]);
- } else {
- link->ss7.linkstate[curfd] = LINKSTATE_DOWN | LINKSTATE_INALARM;
- ss7_link_alarm(link->ss7.ss7, link->ss7.fds[curfd]);
- }
- }
-
- if (cur_adjpointcode < 0) {
- ast_log(LOG_ERROR, "Unspecified adjpointcode!\n");
+ }
+ if (params.sigtype != DAHDI_SIG_HDLCFCS
+ && params.sigtype != DAHDI_SIG_HARDHDLC
+ && params.sigtype != DAHDI_SIG_MTP2) {
+ dahdi_close_ss7_fd(link, curfd);
+ ast_log(LOG_ERROR, "sigchan %d is not in HDLC/FCS mode.\n", sigchan);
return -1;
- } else {
- ss7_set_adjpc(link->ss7.ss7, link->ss7.fds[curfd], cur_adjpointcode);
- }
-
- if (cur_defaultdpc < 0) {
- ast_log(LOG_ERROR, "Unspecified defaultdpc!\n");
+ }
+
+ /* Set signaling channel buffer policy. */
+ memset(&bi, 0, sizeof(bi));
+ bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
+ bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
+ bi.numbufs = 32;
+ bi.bufsize = 512;
+ if (ioctl(link->ss7.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_ss7_fd(link, curfd);
return -1;
}
- if (cur_networkindicator < 0) {
- ast_log(LOG_ERROR, "Invalid networkindicator!\n");
+ /* Get current signaling channel alarm status. */
+ memset(&si, 0, sizeof(si));
+ res = ioctl(link->ss7.fds[curfd], DAHDI_SPANSTAT, &si);
+ if (res) {
+ dahdi_close_ss7_fd(link, curfd);
+ ast_log(LOG_ERROR, "Unable to get span state for sigchan %d (%s)\n", sigchan,
+ strerror(errno));
+ }
+
+ res = sig_ss7_add_sigchan(&link->ss7, curfd, cur_ss7type,
+ (params.sigtype == DAHDI_SIG_MTP2)
+ ? SS7_TRANSPORT_DAHDIMTP2
+ : SS7_TRANSPORT_DAHDIDCHAN,
+ si.alarms, cur_networkindicator, cur_pointcode, cur_adjpointcode);
+ if (res) {
+ dahdi_close_ss7_fd(link, curfd);
return -1;
- } else
- ss7_set_network_ind(link->ss7.ss7, cur_networkindicator);
+ }
+
+ ++link->ss7.numsigchans;
return 0;
}
@@ -18356,6 +18346,53 @@
}
/*!
+ * \brief Setup and add a SS7 link channel.
+ * \since 1.8
+ *
+ * \param linkset Controlling linkset for the channel.
+ * \param which Link index of the signaling channel.
+ * \param ss7type Switch type of the linkset
+ * \param transport Signaling transport of channel.
+ * \param inalarm Non-zero if the channel is in alarm.
+ * \param networkindicator User configuration parameter.
+ * \param pointcode User configuration parameter.
+ * \param adjpointcode User configuration parameter.
+ *
+ * \retval 0 on success.
+ * \retval -1 on error.
+ */
+int sig_ss7_add_sigchan(struct sig_ss7_linkset *linkset, int which, int ss7type, int transport, int inalarm, int networkindicator, int pointcode, int adjpointcode)
+{
+ if (!linkset->ss7) {
+ linkset->type = ss7type;
+ linkset->ss7 = ss7_new(ss7type);
+ if (!linkset->ss7) {
+ ast_log(LOG_ERROR, "Can't create new SS7!\n");
+ return -1;
+ }
+ }
+
+ ss7_set_network_ind(linkset->ss7, networkindicator);
+ ss7_set_pc(linkset->ss7, pointcode);
+
+ if (ss7_add_link(linkset->ss7, transport, linkset->fds[which])) {
+ ast_log(LOG_WARNING, "Could not add SS7 link!\n");
+ }
+
+ if (inalarm) {
+ linkset->linkstate[which] = LINKSTATE_DOWN | LINKSTATE_INALARM;
+ ss7_link_alarm(linkset->ss7, linkset->fds[which]);
+ } else {
+ linkset->linkstate[which] = LINKSTATE_DOWN;
+ ss7_link_noalarm(linkset->ss7, linkset->fds[which]);
+ }
+
+ ss7_set_adjpc(linkset->ss7, linkset->fds[which], adjpointcode);
+
+ return 0;
+}
+
+/*!
* \brief Determine if the specified channel is available for an outgoing call.
* \since 1.8
*
Modified: team/rmudgett/sig_ss7/channels/sig_ss7.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/sig_ss7/channels/sig_ss7.h?view=diff&rev=261912&r1=261911&r2=261912
==============================================================================
--- team/rmudgett/sig_ss7/channels/sig_ss7.h (original)
+++ team/rmudgett/sig_ss7/channels/sig_ss7.h Fri May 7 13:51:39 2010
@@ -228,8 +228,11 @@
};
void sig_ss7_set_alarm(struct sig_ss7_chan *p, int in_alarm);
+
void sig_ss7_link_alarm(struct sig_ss7_linkset *linkset, int which);
void sig_ss7_link_noalarm(struct sig_ss7_linkset *linkset, int which);
+int sig_ss7_add_sigchan(struct sig_ss7_linkset *linkset, int which, int ss7type, int transport, int inalarm, int networkindicator, int pointcode, int adjpointcode);
+
int sig_ss7_available(struct sig_ss7_chan *p);
int sig_ss7_call(struct sig_ss7_chan *p, struct ast_channel *ast, char *rdest);
int sig_ss7_hangup(struct sig_ss7_chan *p, struct ast_channel *ast);
More information about the asterisk-commits
mailing list