From c406e3eadc5d07c5441462a58efc211c0be4337c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 20 Jun 2007 17:53:09 +0000 Subject: [PATCH] tmp git-svn-id: http://svn.openzap.org/svn/openzap/trunk@277 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 18 ++++---- libs/openzap/src/zap_io.c | 1 + libs/openzap/src/zap_isdn.c | 12 ++--- libs/openzap/src/zap_zt.c | 76 ++++++++++++++++++++++--------- 4 files changed, 71 insertions(+), 36 deletions(-) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index 897e92e0c5..b972e4ff1d 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -131,13 +131,13 @@ struct zt_chanconfig { char netdev_name[16]; /* name for the hdlc network device */ }; -struct zt_bufferinfo { -/* used in ZT_SET_BUFINFO and ZT_GET_BUFINFO */ - int txbufpolicy; /* Policy for handling receive buffers */ - int rxbufpolicy; /* Policy for handling receive buffers */ - int numbufs; /* How many buffers to use */ - int bufsize; /* How big each buffer is */ - int readbufs; /* How many read buffers are full (read-only) */ +struct zt_bufferinfo { +/* used in ZT_SET_BUFINFO and ZT_GET_BUFINFO */ + int txbufpolicy; /* Policy for handling receive buffers */ + int rxbufpolicy; /* Policy for handling receive buffers */ + int numbufs; /* How many buffers to use */ + int bufsize; /* How big each buffer is */ + int readbufs; /* How many read buffers are full (read-only) */ int writebufs; /* How many write buffers are full (read-only) */ }; @@ -250,8 +250,8 @@ ZT_SIG_EM = (1 << 6) /* E&M */ #define ZT_SETGAINS _IOWR (ZT_CODE, 17, struct zt_gains) /* Set Channel audio gains */ #define ZT_SPANCONFIG _IOW (ZT_CODE, 18, struct zt_lineconfig)/* Set Line (T1) Configurations and start system */ #define ZT_CHANCONFIG _IOW (ZT_CODE, 19, struct zt_chanconfig)/* Set Channel Configuration */ -#define ZT_SET_BUFINFO _IOW (ZT_CODE, 27, struct zt_bufferinfo)/* Set buffer policy */ -#define ZT_GET_BUFINFO _IOR (ZT_CODE, 28, struct zt_bufferinfo)/* Get current buffer info */ +#define ZT_SET_BUFINFO _IOW (ZT_CODE, 27, struct zt_bufferinfo)/* Set buffer policy */ +#define ZT_GET_BUFINFO _IOR (ZT_CODE, 28, struct zt_bufferinfo)/* Get current buffer info */ #define ZT_AUDIOMODE _IOW (ZT_CODE, 32, int) /* Set a clear channel into audio mode */ #define ZT_ECHOCANCEL _IOW (ZT_CODE, 33, int) /* Control Echo Canceller */ #define ZT_HDLCRAWMODE _IOW (ZT_CODE, 36, int) /* Set a clear channel into HDLC w/out FCS checking/calculation mode */ diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 083ded5d96..771d74c8f1 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1695,6 +1695,7 @@ static zap_status_t load_config(void) if (zap_span_create(zio, &span) == ZAP_SUCCESS) { zap_log(ZAP_LOG_DEBUG, "created span %d of type %s\n", span->span_id, type); + d = 0; } else { zap_log(ZAP_LOG_CRIT, "failure creating span of type %s\n", type); span = NULL; diff --git a/libs/openzap/src/zap_isdn.c b/libs/openzap/src/zap_isdn.c index 2424314b1c..ea0f7690e4 100644 --- a/libs/openzap/src/zap_isdn.c +++ b/libs/openzap/src/zap_isdn.c @@ -441,13 +441,13 @@ static void *zap_isdn_run(zap_thread_t *me, void *obj) if (flags & ZAP_READ) { len = sizeof(buf); if (zap_channel_read(data->dchan, buf, &len) == ZAP_SUCCESS) { -#ifdef IODEBUG - //char bb[4096] = ""; - //print_hex_bytes(buf, len, bb, sizeof(bb)); + //#ifdef IODEBUG + char bb[4096] = ""; + 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); Q921Rx12(&data->q921); diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 3461721440..4e8679a06f 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -49,7 +49,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za { unsigned configured = 0, x; const char ctlpath[] = "/dev/zap/ctl"; - char path[128] = ""; + char path[] = "/dev/zap/channel"; zt_params_t ztp; zap_socket_t ctlfd = ZT_INVALID_SOCKET; @@ -66,10 +66,12 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za zap_socket_t sockfd = ZT_INVALID_SOCKET; int len; - snprintf(path, sizeof(path), "/dev/zap/%d", x); + //snprintf(path, sizeof(path), "/dev/zap/%d", x); sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { + ioctl(sockfd, ZT_SPECIFY, &x); + if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) { struct zt_chanconfig cc; memset(&cc, 0, sizeof(cc)); @@ -118,29 +120,31 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za close(sockfd); break; } + + len = zt_globals.eclevel; + if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } } - len = zt_globals.eclevel; - if (ioctl(chan->sockfd, ZT_ECHOCANCEL, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - close(sockfd); - continue; - } - - len = zt_globals.codec_ms * 8; - if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { - zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", - path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); - close(sockfd); - continue; - } + if (chan->type != ZAP_CHAN_TYPE_DQ921 && chan->type != ZAP_CHAN_TYPE_DQ931) { + len = zt_globals.codec_ms * 8; + if (ioctl(chan->sockfd, ZT_SET_BLOCKSIZE, &len)) { + zap_log(ZAP_LOG_INFO, "failure configuring device %s as OpenZAP device %d:%d fd:%d err:%s\n", + path, chan->span_id, chan->chan_id, sockfd, strerror(errno)); + close(sockfd); + continue; + } - chan->packet_len = len; - chan->effective_interval = chan->native_interval = chan->packet_len / 8; + chan->packet_len = len; + chan->effective_interval = chan->native_interval = chan->packet_len / 8; - if (chan->effective_codec == ZAP_CODEC_SLIN) { - chan->packet_len *= 2; + if (chan->effective_codec == ZAP_CODEC_SLIN) { + chan->packet_len *= 2; + } } if (ioctl(sockfd, ZT_GET_PARAMS, &ztp) < 0) { @@ -164,6 +168,20 @@ 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.flash_time = zt_globals.flash_ms; @@ -290,6 +308,22 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) static ZIO_OPEN_FUNCTION(zt_open) { + if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { + zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; + } else { + int ms = zt_globals.codec_ms; + int err; + if ((err = ioctl(zchan->sockfd, ZT_SET_BLOCKSIZE, &ms))) { + snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno)); + return ZAP_FAIL; + } else { + zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); + zchan->effective_interval = zchan->native_interval = ms; + zchan->packet_len = zchan->native_interval * 8; + zchan->native_codec = zchan->effective_codec; + } + + } return ZAP_SUCCESS; }