From 8d980e65f6fb2e2aba0cf8e8f8df44a4079fc0cb Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 19 Feb 2010 21:18:13 +0000 Subject: [PATCH] added new commands to enable/disable hardware loop and some boost code to handle ss7 loops git-svn-id: http://svn.openzap.org/svn/openzap/trunk@1038 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/zap_types.h | 3 + .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 63 ++++++++++++++++++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 8 +++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 72c467c398..f318da6d56 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -284,6 +284,8 @@ typedef enum { ZAP_COMMAND_FLUSH_RX_BUFFERS, ZAP_COMMAND_FLUSH_BUFFERS, ZAP_COMMAND_SET_PRE_BUFFER_SIZE, + ZAP_COMMAND_ENABLE_LOOP, + ZAP_COMMAND_DISABLE_LOOP, ZAP_COMMAND_COUNT } zap_command_t; @@ -341,6 +343,7 @@ typedef enum { ZAP_CHANNEL_STATE_CANCEL, ZAP_CHANNEL_STATE_HANGUP, ZAP_CHANNEL_STATE_HANGUP_COMPLETE, + ZAP_CHANNEL_STATE_IN_LOOP, ZAP_CHANNEL_STATE_INVALID } zap_channel_state_t; #define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \ diff --git a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 04ee26ccb0..ffecef279d 100644 --- a/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -774,6 +774,48 @@ static void handle_call_start(zap_span_t *span, sangomabc_connection_t *mcon, sa } +static void handle_call_loop_start(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +{ + zap_status_t res = ZAP_FAIL; + zap_channel_t *zchan; + + if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 0))) { + zap_log(ZAP_LOG_CRIT, "CANNOT START LOOP, CHAN NOT AVAILABLE %d:%d\n", event->span+1,event->chan+1); + return; + } + + if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) { + zap_log(ZAP_LOG_CRIT, "CANNOT START LOOP, CANT OPEN CHAN %d:%d\n", event->span+1,event->chan+1); + return; + } + + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_IN_LOOP, 0, res); + if (res != ZAP_SUCCESS) { + zap_log(ZAP_LOG_CRIT, "yay, could not set the state of the channel to IN_LOOP, loop will fail\n"); + zap_channel_done(zchan); + /* FIXME: do we need to send an error? */ + return; + } + zap_channel_command(zchan, ZAP_COMMAND_ENABLE_LOOP, NULL); +} + +static void handle_call_loop_stop(zap_span_t *span, sangomabc_connection_t *mcon, sangomabc_short_event_t *event) +{ + zap_channel_t *zchan; + zap_status_t res = ZAP_FAIL; + if (!(zchan = find_zchan(span, (sangomabc_short_event_t*)event, 1))) { + zap_log(ZAP_LOG_CRIT, "CANNOT STOP LOOP, INVALID CHAN REQUESTED %d:%d\n", event->span+1,event->chan+1); + return; + } + if (zchan->state != ZAP_CHANNEL_STATE_IN_LOOP) { + zap_log(ZAP_LOG_ERROR, "Got stop loop request in a channel that is not in loop, ignoring ...\n"); + /* FIXME: do we need to send an error? */ + return; + } + zap_channel_command(zchan, ZAP_COMMAND_DISABLE_LOOP, NULL); + zap_set_state_r(zchan, ZAP_CHANNEL_STATE_DOWN, 0, res); +} + /** * \brief Handler for heartbeat event * \param mcon sangoma boost connection @@ -955,10 +997,10 @@ static int parse_sangoma_event(zap_span_t *span, sangomabc_connection_t *mcon, s nack_map[event->call_setup_id] = 0; break; case SIGBOOST_EVENT_INSERT_CHECK_LOOP: - //handle_call_loop_start(event); + handle_call_loop_start(span, mcon, event); break; case SIGBOOST_EVENT_REMOVE_CHECK_LOOP: - //handle_call_stop(event); + handle_call_loop_stop(span, mcon, event); break; case SIGBOOST_EVENT_SYSTEM_RESTART_ACK: handle_restart_ack(mcon, span, event); @@ -1177,6 +1219,11 @@ static __inline__ void state_advance(zap_channel_t *zchan) status = zap_span_send_signal(zchan->span, &sig); } break; + case ZAP_CHANNEL_STATE_IN_LOOP: + { + /* nothing to do, we sent the ZAP_COMMAND_ENABLE_LOOP command in handle_call_loop_start() right away */ + } + break; default: break; } @@ -1541,6 +1588,18 @@ static zap_state_map_t boost_state_map = { {ZAP_CHANNEL_STATE_RESTART, ZAP_END}, {ZAP_CHANNEL_STATE_DOWN, ZAP_END} }, + { + ZSD_INBOUND, + ZSM_UNACCEPTABLE, + {ZAP_CHANNEL_STATE_DOWN}, + {ZAP_CHANNEL_STATE_IN_LOOP, ZAP_END} + }, + { + ZSD_INBOUND, + ZSM_UNACCEPTABLE, + {ZAP_CHANNEL_STATE_IN_LOOP}, + {ZAP_CHANNEL_STATE_DOWN, ZAP_END} + }, { ZSD_INBOUND, ZSM_UNACCEPTABLE, diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index eba1db3465..190edc2a8d 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -593,6 +593,14 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) //code me } break; + case ZAP_COMMAND_ENABLE_LOOP: + { + // code me + } + case ZAP_COMMAND_DISABLE_LOOP: + { + // code me + } case ZAP_COMMAND_SET_INTERVAL: { err=sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, ZAP_COMMAND_OBJ_INT);