#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 */
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;
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);
}
}
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);
}
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;
{
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:
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);
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;
int err = 0;
memset(&tdm_api, 0, sizeof(tdm_api));
-
+
switch(command) {
case ZAP_COMMAND_OFFHOOK:
{
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;
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) {
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 {
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;
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: