From a4942a13d6c38f61d2d6492b8292e555b016fca8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 27 Jun 2007 19:18:13 +0000 Subject: [PATCH] update git-svn-id: http://svn.openzap.org/svn/openzap/trunk@298 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_zt.h | 3 ++- libs/openzap/src/zap_analog.c | 13 +++++++++++-- libs/openzap/src/zap_io.c | 7 ++++--- libs/openzap/src/zap_wanpipe.c | 3 ++- libs/openzap/src/zap_zt.c | 8 ++++---- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libs/openzap/src/include/zap_zt.h b/libs/openzap/src/include/zap_zt.h index eb707671e9..46aab35eb6 100644 --- a/libs/openzap/src/include/zap_zt.h +++ b/libs/openzap/src/include/zap_zt.h @@ -233,7 +233,8 @@ ZT_SIG_HDLCFCS = ((1 << 9) | ZT_SIG_HDLCRAW) #define ZT_CODE 'J' -#define ZT_GET_BLOCKSIZE _IOW (ZT_CODE, 1, int) /* Get Transfer Block Size. */ + +#define ZT_GET_BLOCKSIZE _IOR (ZT_CODE, 1, int) /* Get Transfer Block Size. */ #define ZT_SET_BLOCKSIZE _IOW (ZT_CODE, 2, int) /* Set Transfer Block Size. */ #define ZT_FLUSH _IOW (ZT_CODE, 3, int) /* Flush Buffer(s) and stop I/O */ #define ZT_SYNC _IOW (ZT_CODE, 4, int) /* Wait for Write to Finish */ diff --git a/libs/openzap/src/zap_analog.c b/libs/openzap/src/zap_analog.c index 23b1ec1a55..23a9054dd0 100644 --- a/libs/openzap/src/zap_analog.c +++ b/libs/openzap/src/zap_analog.c @@ -215,7 +215,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) sig.chan_id = zchan->chan_id; sig.span_id = zchan->span_id; sig.channel = zchan; - + + assert(interval != 0); while (zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) { zap_wait_flag_t flags = ZAP_READ; @@ -279,11 +280,14 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) break; case ZAP_CHANNEL_STATE_HANGUP: { - if (state_counter > 500) { + if (zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && zchan->last_state >= ZAP_CHANNEL_STATE_IDLE) { zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_BUSY); } else { + if (zap_test_flag(zchan, ZAP_CHANNEL_RINGING)) { + zap_channel_command(zchan, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + } zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_DOWN); } } @@ -577,6 +581,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj) done: zap_channel_done(zchan); + + if (zchan->type == ZAP_CHAN_TYPE_FXO && zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) { zap_channel_command(zchan, ZAP_COMMAND_ONHOOK, NULL); } @@ -638,6 +644,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even break; case ZAP_OOB_ONHOOK: { + if (zap_test_flag(event->channel, ZAP_CHANNEL_RINGING)) { + zap_channel_command(event->channel, ZAP_COMMAND_GENERATE_RING_OFF, NULL); + } zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN); } break; diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index 4ebaaa6bc8..c15ac3c1ab 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -577,12 +577,11 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta { int ok = 1; - zap_mutex_lock(zchan->mutex); - if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) { return ZAP_FAIL; } + zap_mutex_lock(zchan->mutex); switch(zchan->state) { case ZAP_CHANNEL_STATE_HANGUP: case ZAP_CHANNEL_STATE_TERMINATING: @@ -641,7 +640,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta if (state == zchan->state) { ok = 0; } - + if (ok) { zap_set_flag(zchan, ZAP_CHANNEL_STATE_CHANGE); zap_set_flag(zchan->span, ZAP_SPAN_STATE_CHANGE); @@ -1209,11 +1208,13 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo if (!zchan->zio->command) { snprintf(zchan->last_error, sizeof(zchan->last_error), "method not implemented"); + zap_log(ZAP_LOG_ERROR, "no commnand functon!\n"); GOTO_STATUS(done, ZAP_FAIL); } status = zchan->zio->command(zchan, command, obj); + done: zap_mutex_unlock(zchan->mutex); return status; diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index 7a7536f914..4537e547ff 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -543,7 +543,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) int err = 0; memset(&tdm_api, 0, sizeof(tdm_api)); - + switch(command) { case ZAP_COMMAND_OFFHOOK: { @@ -593,6 +593,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) snprintf(zchan->last_error, sizeof(zchan->last_error), "Ring-off Failed"); return ZAP_FAIL; } + zap_clear_pflag_locked(zchan, WP_RINGING); zap_clear_flag_locked(zchan, ZAP_CHANNEL_RINGING); } break; diff --git a/libs/openzap/src/zap_zt.c b/libs/openzap/src/zap_zt.c index 5f2a60b052..be33a7c536 100644 --- a/libs/openzap/src/zap_zt.c +++ b/libs/openzap/src/zap_zt.c @@ -61,7 +61,6 @@ 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); sockfd = open(path, O_RDWR); if (sockfd != ZT_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &zchan) == ZAP_SUCCESS) { @@ -308,6 +307,8 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure) static ZIO_OPEN_FUNCTION(zt_open) { + zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); + if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE; } else { @@ -317,7 +318,6 @@ static ZIO_OPEN_FUNCTION(zt_open) 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; zchan->packet_len = blocksize; zchan->native_codec = zchan->effective_codec; @@ -404,14 +404,14 @@ static ZIO_COMMAND_FUNCTION(zt_command) break; case ZAP_COMMAND_GET_INTERVAL: { + if (!(err = ioctl(zchan->sockfd, ZT_GET_BLOCKSIZE, &zchan->packet_len))) { zchan->native_interval = zchan->packet_len / 8; if (zchan->effective_codec == ZAP_CODEC_SLIN) { zchan->packet_len *= 2; } ZAP_COMMAND_OBJ_INT = zchan->native_interval; - } - + } } break; case ZAP_COMMAND_SET_INTERVAL: