[asterisk-commits] jpeeler: branch jpeeler/bug14877 r221483 - /team/jpeeler/bug14877/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 30 17:57:45 CDT 2009
Author: jpeeler
Date: Wed Sep 30 17:57:41 2009
New Revision: 221483
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=221483
Log:
have some code mr. subversion server
Modified:
team/jpeeler/bug14877/channels/chan_dahdi.c
Modified: team/jpeeler/bug14877/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/jpeeler/bug14877/channels/chan_dahdi.c?view=diff&rev=221483&r1=221482&r2=221483
==============================================================================
--- team/jpeeler/bug14877/channels/chan_dahdi.c (original)
+++ team/jpeeler/bug14877/channels/chan_dahdi.c Wed Sep 30 17:57:41 2009
@@ -2796,6 +2796,78 @@
pri->pri = pri->dchans[newslot];
return 0;
}
+
+static int pri_find_dchan_by_channel(int chan, int *offset, struct dahdi_pvt *p)
+{
+ struct dahdi_params par;
+ struct dahdi_params dchan_check;
+ struct dahdi_spaninfo si;
+ int fd;
+ int myfd;
+ int dchannelno;
+int res;
+ *offset = -1;
+
+ if (p->subs[SUB_REAL].dfd < 0) {
+ fd = open(DAHDI_FILE_CHANNEL, O_RDWR);
+ if (fd < 0) {
+ ast_log(LOG_WARNING, "Failed to open channel: %s\n", strerror(errno));
+ return -1;
+ }
+ if (ioctl(fd, DAHDI_SPECIFY, &chan)) {
+ ast_log(LOG_WARNING, "Failed to specify channel %d: %s %d\n", chan, strerror(errno), errno);
+ //do { *((int *)(0)) = 1; } while(0);
+ close(fd);
+ return -1;
+ }
+ } else {
+ fd = p->subs[SUB_REAL].dfd;
+ }
+ if (ioctl(fd, DAHDI_GET_PARAMS, &par)) {
+ ast_log(LOG_WARNING, "Failed to get channel parameters for channel %d: %s\n", chan, strerror(errno));
+ return -1;
+ }
+ memset(&si, 0, sizeof(si));
+ if ((res = ioctl(fd, DAHDI_SPANSTAT, &si))) {
+ ast_log(LOG_WARNING, "Failed to get span information on channel %d (span %d): %s\n", chan, par.spanno, strerror(errno));
+ast_log(LOG_WARNING, "jpeeler: res = %d\n", res);
+ close(fd);
+ return -1;
+ }
+
+ for (dchannelno = chan - par.chanpos + 1; dchannelno < si.totalchans + (chan - par.chanpos + 1); dchannelno++) {
+ast_log(LOG_WARNING, "jpeeler: in loop with dchannelno = %d, totalchans = %d\n", dchannelno, si.totalchans);
+ if (chan >= dchannelno) {
+ myfd = fd;
+ } else {
+ myfd = open(DAHDI_FILE_CHANNEL, O_RDWR);
+ if (ioctl(myfd, DAHDI_SPECIFY, &dchannelno)) {
+ ast_log(LOG_WARNING, "Failed to specify channel %d: %s\n", dchannelno, strerror(errno));
+ close(fd);
+ return -1;
+ }
+ }
+ if (ioctl(myfd, DAHDI_GET_PARAMS, &dchan_check)) {
+ ast_log(LOG_WARNING, "Failed to get channel parameters for channel %d: %s\n", chan, strerror(errno));
+ close(fd);
+ return -1;
+ }
+ if ((dchan_check.sigtype == DAHDI_SIG_HDLCFCS) || (dchan_check.sigtype == DAHDI_SIG_HARDHDLC)) {
+ *offset = dchannelno - (chan - par.chanpos + 1);
+ if (chan < dchannelno) {
+ close(myfd);
+ }
+ return dchannelno;
+ }
+ if (chan < dchannelno) {
+ast_log(LOG_WARNING, "closing %d because chan %d < dchannelno %d\n", myfd, chan, dchannelno);
+ close(myfd);
+ }
+ }
+
+ ast_log(LOG_WARNING, "Failed to find D-Channel on span %d!\n", par.spanno);
+ return -1;
+}
#endif
static int dahdi_hangup(struct ast_channel *ast)
@@ -7488,7 +7560,7 @@
}
#ifdef HAVE_PRI
-static int pri_resolve_span(int *span, int channel, int offset, struct dahdi_spaninfo *si)
+static int pri_resolve_span(int *span, int channel, int *offset, struct dahdi_spaninfo *si, struct dahdi_pvt *p)
{
int x;
int trunkgroup;
@@ -7505,6 +7577,7 @@
ast_log(LOG_WARNING, "Channel %d on span %d configured to use nonexistent trunk group %d\n", channel, *span, trunkgroup);
*span = -1;
} else {
+ int dchanno;
if (pris[*span].trunkgroup) {
ast_log(LOG_WARNING, "Unable to use span %d implicitly since it is trunk group %d (please use spanmap)\n", *span, pris[*span].trunkgroup);
*span = -1;
@@ -7512,22 +7585,17 @@
ast_log(LOG_WARNING, "Unable to use span %d implicitly since it is already part of trunk group %d\n", *span, pris[*span].mastertrunkgroup);
*span = -1;
} else {
- if (si->totalchans == 31) {
- /* E1 */
- pris[*span].dchannels[0] = 16 + offset;
- } else if (si->totalchans == 24) {
- /* T1 or J1 */
- pris[*span].dchannels[0] = 24 + offset;
- } else if (si->totalchans == 3) {
- /* BRI */
- pris[*span].dchannels[0] = 3 + offset;
- } else {
- ast_log(LOG_WARNING, "Unable to use span %d, since the D-channel cannot be located (unexpected span size of %d channels)\n", *span, si->totalchans);
+ dchanno = pri_find_dchan_by_channel(channel, offset, p);
+ /* bri must stay the same, E1 needs to be chan 16 */
+ if (dchanno < 1) {
+ ast_log(LOG_WARNING, "Unable to use span %d, since the D-channel cannot be located\n", *span);
*span = -1;
return 0;
}
+//ast_log(LOG_WARNING, "jpeeler: dchannel set to %d, how about %d, dchan fd = %d\n", 24 + offset, pri_find_dchan(&pris[*span]), pri_active_dchan_fd(&pris[*span]));
+ pris[*span].dchannels[0] = dchanno;
pris[*span].dchanavail[0] |= DCHAN_PROVISIONED;
- pris[*span].offset = offset;
+ pris[*span].offset = *offset;
pris[*span].span = *span + 1;
}
}
@@ -7671,11 +7739,12 @@
if (tmp) {
int chan_sig = conf->chan.sig;
if (!here) {
- if ((channel != CHAN_PSEUDO) && !pri) {
+ if ((channel != CHAN_PSEUDO) && !pri) { /* jpeeler: uhhh, pri is null here even for PRI channels! */
int count = 0;
snprintf(fn, sizeof(fn), "%d", channel);
/* Open non-blocking */
tmp->subs[SUB_REAL].dfd = dahdi_open(fn);
+ast_log(LOG_WARNING, "jpeeler: assigned fd %d to chan %d\n", tmp->subs[SUB_REAL].dfd, channel);
while (tmp->subs[SUB_REAL].dfd < 0 && reloading == 2 && count < 1000) { /* the kernel may not call dahdi_release fast enough for the open flagbit to be cleared in time */
usleep(1);
tmp->subs[SUB_REAL].dfd = dahdi_open(fn);
@@ -7736,7 +7805,7 @@
}
/* Store the logical span first based upon the real span */
tmp->logicalspan = pris[span].prilogicalspan;
- pri_resolve_span(&span, channel, (channel - p.chanpos), &si);
+ pri_resolve_span(&span, channel, &offset, &si, tmp);
if (span < 0) {
ast_log(LOG_WARNING, "Channel %d: Unable to find locate channel/trunk group!\n", channel);
destroy_dahdi_pvt(&tmp);
More information about the asterisk-commits
mailing list