diff --git a/libs/freetdm/src/openzap.c b/libs/freetdm/src/openzap.c index c82f6f7608..a33bcdbc98 100644 --- a/libs/freetdm/src/openzap.c +++ b/libs/freetdm/src/openzap.c @@ -212,15 +212,17 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct j = span_max; } + + for(;;) { span = &zint->spans[j]; - + if (!zap_test_flag(span, ZAP_SPAN_CONFIGURED)) { goto next_loop; } if (direction == ZAP_TOP_DOWN) { - if (j == span_max) { + if (j > span_max) { break; } } else { @@ -228,7 +230,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct break; } } - + if (direction == ZAP_TOP_DOWN) { i = 1; } else { @@ -238,7 +240,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct for(;;) { if (direction == ZAP_TOP_DOWN) { - if (i == span->chan_count) { + if (i > span->chan_count) { break; } } else { @@ -246,7 +248,7 @@ zap_status_t zap_channel_open_any(const char *name, unsigned span_id, zap_direct break; } } - + check = &span->channels[i]; if (zap_test_flag(check, ZAP_CHANNEL_READY) && !zap_test_flag(check, ZAP_CHANNEL_OPEN)) { diff --git a/libs/freetdm/src/testapp.c b/libs/freetdm/src/testapp.c index dbd7d989ee..ab429f0f79 100644 --- a/libs/freetdm/src/testapp.c +++ b/libs/freetdm/src/testapp.c @@ -15,8 +15,9 @@ int main(int argc, char *argv[]) printf("OpenZAP loaded\n"); - if (zap_channel_open("wanpipe", 1, 1, &chan) == ZAP_SUCCESS) { + if (zap_channel_open_any("wanpipe", 0, ZAP_TOP_DOWN, &chan) == ZAP_SUCCESS) { int x = 0; + printf("opened channel %d:%d\n", chan->span_id, chan->chan_id); if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) { ms = 0; @@ -53,6 +54,8 @@ int main(int argc, char *argv[]) printf("wait fail [%s]\n", chan->last_error); } } + } else { + printf("open fail [%s]\n", chan->last_error); } zap_global_destroy();