git-svn-id: http://svn.openzap.org/svn/openzap/trunk@278 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Anthony Minessale 2007-06-20 20:30:10 +00:00
parent c406e3eadc
commit 599829cedb
3 changed files with 65 additions and 37 deletions

View File

@ -217,7 +217,10 @@ ZT_SIG_FXSKS = ((1 << 2) | (1 << 13)), /* FXS, Kewlstart */
ZT_SIG_FXOLS = ((1 << 3) | (1 << 12)), /* FXO, Loopstart */ ZT_SIG_FXOLS = ((1 << 3) | (1 << 12)), /* FXO, Loopstart */
ZT_SIG_FXOGS = ((1 << 4) | (1 << 12)), /* FXO, Groupstart */ ZT_SIG_FXOGS = ((1 << 4) | (1 << 12)), /* FXO, Groupstart */
ZT_SIG_FXOKS = ((1 << 5) | (1 << 12)), /* FXO, Kewlstart */ ZT_SIG_FXOKS = ((1 << 5) | (1 << 12)), /* FXO, Kewlstart */
ZT_SIG_EM = (1 << 6) /* E&M */ ZT_SIG_EM = (1 << 6), /* E&M */
ZT_SIG_CLEAR = (1 << 7),
ZT_SIG_HDLCRAW = ((1 << 8) | ZT_SIG_CLEAR),
ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW)
} zt_sigtype_t; } zt_sigtype_t;

View File

@ -173,9 +173,9 @@ static L3INT zap_isdn_931_34(void *pvt, L2UCHAR *msg, L2INT mlen)
static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen) static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen)
{ {
int ret; int ret;
char bb[4096] = ""; //char bb[4096] = "";
print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb)); //print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb));
zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb); //zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb);
ret = Q931Rx23(pvt, msg, mlen); ret = Q931Rx23(pvt, msg, mlen);
if (ret != 0) if (ret != 0)
@ -441,14 +441,14 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj)
if (flags & ZAP_READ) { if (flags & ZAP_READ) {
len = sizeof(buf); len = sizeof(buf);
if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) {
//#ifdef IODEBUG #ifdef IODEBUG
char bb[4096] = ""; //char bb[4096] = "";
print_hex_bytes(buf, len, bb, sizeof(bb)); //print_hex_bytes(buf, len, bb, sizeof(bb));
print_bits(buf, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb);
//#endif
//print_bits(buf, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
//zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)len, LINE, bb);
#endif
Q921QueueHDLCFrame(&data->q921, buf, (int)len); Q921QueueHDLCFrame(&data->q921, buf, (int)len);
Q921Rx12(&data->q921); Q921Rx12(&data->q921);
} }

View File

@ -53,7 +53,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
zt_params_t ztp; zt_params_t ztp;
zap_socket_t ctlfd = ZT_INVALID_SOCKET; zap_socket_t ctlfd = ZT_INVALID_SOCKET;
if ((ctlfd = open(ctlpath, O_RDWR)) < 0) { if ((ctlfd = open(ctlpath, O_RDWR)) < 0) {
zap_log(ZAP_LOG_ERROR, "Cannot open control device\n"); zap_log(ZAP_LOG_ERROR, "Cannot open control device\n");
return 0; return 0;
@ -68,9 +67,31 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
//snprintf(path, sizeof(path), "/dev/zap/%d", x); //snprintf(path, sizeof(path), "/dev/zap/%d", x);
sockfd = open(path, O_RDWR); sockfd = open(path, O_RDWR);
if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) {
ioctl(sockfd, ZT_SPECIFY, &x);
#if 1
if (ioctl(sockfd, ZT_SPECIFY, &x)) {
zap_log(ZAP_LOG_INFO, "failure configuring device %s chan %d fd %d (%s)\n", path, x, ctlfd, strerror(errno));
close(sockfd);
continue;
}
#endif
#if 1
if (chan->type == ZAP_CHAN_TYPE_DQ921) {
struct zt_bufferinfo binfo;
memset(&binfo, 0, sizeof(binfo));
binfo.txbufpolicy = 0;
binfo.rxbufpolicy = 0;
binfo.numbufs = 32;
binfo.bufsize = 1024;
if (ioctl(sockfd, ZT_SET_BUFINFO, &binfo)) {
zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd);
close(sockfd);
continue;
}
}
#endif
if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) {
struct zt_chanconfig cc; struct zt_chanconfig cc;
@ -152,10 +173,17 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
close(sockfd); close(sockfd);
continue; continue;
} }
if (chan->type == ZAP_CHAN_TYPE_DQ921) {
if ((ztp.sig_type != ZT_SIG_HDLCRAW) && (ztp.sig_type != ZT_SIG_HDLCFCS)) {
zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd);
close(sockfd);
continue;
}
}
zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd); zap_log(ZAP_LOG_INFO, "configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd);
chan->rate = 8000; chan->rate = 8000;
chan->physical_span_id = ztp.span_no; chan->physical_span_id = ztp.span_no;
chan->physical_chan_id = ztp.chan_no; chan->physical_chan_id = ztp.chan_no;
@ -168,19 +196,6 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
} }
} }
if (chan->type == ZAP_CHAN_TYPE_DQ921) {
struct zt_bufferinfo binfo;
memset(&binfo, 0, sizeof(binfo));
binfo.txbufpolicy = 0;
binfo.rxbufpolicy = 0;
binfo.numbufs = 32;
binfo.bufsize = 1024;
if (ioctl(sockfd, ZT_SET_BUFINFO, &binfo)) {
zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d\n", path, chan->span_id, chan->chan_id, sockfd);
close(sockfd);
continue;
}
}
ztp.wink_time = zt_globals.wink_ms; ztp.wink_time = zt_globals.wink_ms;
ztp.flash_time = zt_globals.flash_ms; ztp.flash_time = zt_globals.flash_ms;
@ -190,7 +205,8 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
close(sockfd); close(sockfd);
continue; continue;
} }
if (!zap_strlen_zero(name)) { if (!zap_strlen_zero(name)) {
zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name)); zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name));
} }
@ -311,15 +327,15 @@ static ZIO_OPEN_FUNCTION(zt_open)
if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) {
zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE;
} else { } else {
int ms = zt_globals.codec_ms; int blocksize = zt_globals.codec_ms * (zchan->rate / 1000);
int err; int err;
if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &ms))) { if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &blocksize))) {
snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
return ZAP_FAIL; return ZAP_FAIL;
} else { } else {
zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL);
zchan->effective_interval = zchan->native_interval = ms; zchan->effective_interval = zchan->native_interval;
zchan->packet_len = zchan->native_interval * 8; zchan->packet_len = blocksize;
zchan->native_codec = zchan->effective_codec; zchan->native_codec = zchan->effective_codec;
} }
@ -593,12 +609,15 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event)
static ZIO_READ_FUNCTION(zt_read) static ZIO_READ_FUNCTION(zt_read)
{ {
zap_ssize_t r = 0; zap_ssize_t r = 0;
//*datalen = zchan->packet_len;
*datalen = zchan->packet_len;
r = read(zchan->sockfd, data, *datalen); r = read(zchan->sockfd, data, *datalen);
if (r >= 0) { if (r >= 0) {
*datalen = r; *datalen = r;
if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
*datalen -= 2;
}
return ZAP_SUCCESS; return ZAP_SUCCESS;
} }
@ -608,9 +627,15 @@ static ZIO_READ_FUNCTION(zt_read)
static ZIO_WRITE_FUNCTION(zt_write) static ZIO_WRITE_FUNCTION(zt_write)
{ {
zap_ssize_t w = 0; zap_ssize_t w = 0;
zap_size_t bytes = *datalen;
w = write(zchan->sockfd, data, *datalen); if (zchan->type == ZAP_CHAN_TYPE_DQ921) {
memset(data+bytes, 0, 2);
bytes += 2;
}
w = write(zchan->sockfd, data, bytes);
if (w >= 0) { if (w >= 0) {
*datalen = w; *datalen = w;
return ZAP_SUCCESS; return ZAP_SUCCESS;