update core

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4181 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-02-09 20:03:07 +00:00
parent 1eacf043d2
commit f03226debb
11 changed files with 176 additions and 177 deletions

View File

@ -2,7 +2,7 @@
<settings> <settings>
<param name="debug" value="0"/> <param name="debug" value="0"/>
<param name="dialplan" value="XML"/> <param name="dialplan" value="XML"/>
<param name="mtu" value="320"/> <param name="ms-per-frame" value="20"/>
<param name="dtmf-on" value="800"/> <param name="dtmf-on" value="800"/>
<param name="dtmf-off" value="100"/> <param name="dtmf-off" value="100"/>
<param name="supress-dtmf-tone" value="yes"/> <param name="supress-dtmf-tone" value="yes"/>

View File

@ -612,13 +612,13 @@ SWITCH_DECLARE(void) switch_core_service_session(switch_core_session_t *session,
\param caller_profile the originator's caller profile \param caller_profile the originator's caller profile
\param new_session a NULL pointer to aim at the newly created session \param new_session a NULL pointer to aim at the newly created session
\param pool optional existing memory pool to donate to the session \param pool optional existing memory pool to donate to the session
\return SWITCH_STATUS_SUCCESS if the session was created \return the cause code of the attempted call
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_session_outgoing_channel(switch_core_session_t *session, SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_core_session_t *session,
char *endpoint_name, char *endpoint_name,
switch_caller_profile_t *caller_profile, switch_caller_profile_t *caller_profile,
switch_core_session_t **new_session, switch_core_session_t **new_session,
switch_memory_pool_t *pool); switch_memory_pool_t *pool);
/*! /*!
\brief Answer the channel of a given session \brief Answer the channel of a given session

View File

@ -172,7 +172,7 @@ struct switch_io_event_hooks {
/*! \brief A table of i/o routines that an endpoint interface can implement */ /*! \brief A table of i/o routines that an endpoint interface can implement */
struct switch_io_routines { struct switch_io_routines {
/*! creates an outgoing session from given session, caller profile */ /*! creates an outgoing session from given session, caller profile */
switch_status_t (*outgoing_channel)(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t *); switch_call_cause_t (*outgoing_channel)(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t *);
/*! answers the given session's channel */ /*! answers the given session's channel */
switch_status_t (*answer_channel)(switch_core_session_t *); switch_status_t (*answer_channel)(switch_core_session_t *);
/*! read a frame from a session */ /*! read a frame from a session */

View File

@ -180,8 +180,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_ring(switch_core_session_t *session); static switch_status_t channel_on_ring(switch_core_session_t *session);
static switch_status_t channel_on_loopback(switch_core_session_t *session); static switch_status_t channel_on_loopback(switch_core_session_t *session);
static switch_status_t channel_on_transmit(switch_core_session_t *session); static switch_status_t channel_on_transmit(switch_core_session_t *session);
static switch_status_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool); switch_core_session_t **new_session, switch_memory_pool_t *pool);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id); switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
@ -1508,8 +1508,8 @@ static const switch_loadable_module_interface_t channel_module_interface = {
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool! that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/ */
static switch_status_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool) switch_core_session_t **new_session, switch_memory_pool_t *pool)
{ {
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
struct private_object *tech_pvt; struct private_object *tech_pvt;
@ -1534,7 +1534,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Invalid URL!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Invalid URL!\n");
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
} }
if ((dnis = strchr(callto, ':'))) { if ((dnis = strchr(callto, ':'))) {
@ -1571,17 +1571,17 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
if (!ldl_handle_ready(mdl_profile->handle)) { if (!ldl_handle_ready(mdl_profile->handle)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doh! we are not logged in yet!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doh! we are not logged in yet!\n");
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if (!(full_id = ldl_handle_probe(mdl_profile->handle, callto, user, idbuf, sizeof(idbuf)))) { if (!(full_id = ldl_handle_probe(mdl_profile->handle, callto, user, idbuf, sizeof(idbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown Recipient!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown Recipient!\n");
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); terminate_session(new_session, __LINE__, SWITCH_CAUSE_NO_USER_RESPONSE);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_NO_USER_RESPONSE;
} }
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown Profile!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unknown Profile!\n");
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
@ -1601,7 +1601,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if (outbound_profile) { if (outbound_profile) {
@ -1616,7 +1616,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doh! no caller profile\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doh! no caller profile\n");
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
@ -1633,15 +1633,15 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
ldl_session_set_value(dlsession, "caller_id_number", outbound_profile->caller_id_number); ldl_session_set_value(dlsession, "caller_id_number", outbound_profile->caller_id_number);
tech_pvt->dlsession = dlsession; tech_pvt->dlsession = dlsession;
if (!get_codecs(tech_pvt)) { if (!get_codecs(tech_pvt)) {
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); terminate_session(new_session, __LINE__, SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL;
} }
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_CAUSE_SUCCESS;
} }
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }

View File

@ -426,8 +426,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_ring(switch_core_session_t *session); static switch_status_t channel_on_ring(switch_core_session_t *session);
static switch_status_t channel_on_loopback(switch_core_session_t *session); static switch_status_t channel_on_loopback(switch_core_session_t *session);
static switch_status_t channel_on_transmit(switch_core_session_t *session); static switch_status_t channel_on_transmit(switch_core_session_t *session);
static switch_status_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool); switch_core_session_t **new_session, switch_memory_pool_t *pool);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id); switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
@ -802,8 +802,8 @@ static const switch_loadable_module_interface_t channel_module_interface = {
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool! that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/ */
static switch_status_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool) switch_core_session_t **new_session, switch_memory_pool_t *pool)
{ {
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
private_t *tech_pvt; private_t *tech_pvt;
@ -819,7 +819,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if (outbound_profile) { if (outbound_profile) {
@ -834,18 +834,18 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if ((tech_pvt->iax_session = iax_session_new()) == 0) { if ((tech_pvt->iax_session = iax_session_new()) == 0) {
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if (iax_set_codec(tech_pvt, tech_pvt->iax_session, &req, &cap, &samprate, IAX_QUERY) != SWITCH_STATUS_SUCCESS) { if (iax_set_codec(tech_pvt, tech_pvt->iax_session, &req, &cap, &samprate, IAX_QUERY) != SWITCH_STATUS_SUCCESS) {
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_BEARERCAPABILITY_NOTIMPL;
} }
if (samprate) { if (samprate) {
@ -859,10 +859,10 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_CAUSE_SUCCESS;
} }
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }

View File

@ -142,9 +142,9 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_ring(switch_core_session_t *session); static switch_status_t channel_on_ring(switch_core_session_t *session);
static switch_status_t channel_on_loopback(switch_core_session_t *session); static switch_status_t channel_on_loopback(switch_core_session_t *session);
static switch_status_t channel_on_transmit(switch_core_session_t *session); static switch_status_t channel_on_transmit(switch_core_session_t *session);
static switch_status_t channel_outgoing_channel(switch_core_session_t *session, static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool); switch_core_session_t **new_session, switch_memory_pool_t *pool);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id); switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
@ -824,8 +824,8 @@ static const switch_loadable_module_interface_t channel_module_interface = {
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool! that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/ */
static switch_status_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool) switch_core_session_t **new_session, switch_memory_pool_t *pool)
{ {
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) { if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
@ -844,7 +844,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if (outbound_profile) { if (outbound_profile) {
@ -860,16 +860,16 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_CAUSE_SUCCESS;
} }
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }

View File

@ -330,8 +330,8 @@ static switch_status_t sofia_on_loopback(switch_core_session_t *session);
static switch_status_t sofia_on_transmit(switch_core_session_t *session); static switch_status_t sofia_on_transmit(switch_core_session_t *session);
static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool); switch_core_session_t **new_session, switch_memory_pool_t *pool);
static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id); switch_io_flag_t flags, int stream_id);
@ -1246,6 +1246,7 @@ static int hangup_cause_to_sip(switch_call_cause_t cause) {
return 501; return 501;
case SWITCH_CAUSE_NORMAL_UNSPECIFIED: case SWITCH_CAUSE_NORMAL_UNSPECIFIED:
return 480; return 480;
case SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL:
case SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION: case SWITCH_CAUSE_NORMAL_CIRCUIT_CONGESTION:
case SWITCH_CAUSE_NETWORK_OUT_OF_ORDER: case SWITCH_CAUSE_NETWORK_OUT_OF_ORDER:
case SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE: case SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE:
@ -2182,10 +2183,10 @@ static void logger(void *logarg, char const *fmt, va_list ap)
} }
static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool) switch_core_session_t **new_session, switch_memory_pool_t *pool)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
switch_core_session_t *nsession; switch_core_session_t *nsession;
char *data, *profile_name, *dest; char *data, *profile_name, *dest;
sofia_profile_t *profile; sofia_profile_t *profile;
@ -2213,6 +2214,7 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
if (!(dest = strchr(profile_name, '/'))) { if (!(dest = strchr(profile_name, '/'))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
cause = SWITCH_CAUSE_INVALID_NUMBER_FORMAT;
goto done; goto done;
} }
@ -2221,6 +2223,7 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
if (!(profile = (sofia_profile_t *) switch_core_hash_find(globals.profile_hash, profile_name))) { if (!(profile = (sofia_profile_t *) switch_core_hash_find(globals.profile_hash, profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Profile\n");
terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__); terminate_session(&nsession, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
goto done; goto done;
} }
@ -2233,7 +2236,8 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
tech_pvt->dest = switch_core_session_strdup(nsession, buf); tech_pvt->dest = switch_core_session_strdup(nsession, buf);
} else { } else {
terminate_session(&nsession, SWITCH_CAUSE_NO_ROUTE_DESTINATION, __LINE__); cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION;
terminate_session(&nsession, cause, __LINE__);
goto done; goto done;
} }
} else if (!strchr(dest, '@')) { } else if (!strchr(dest, '@')) {
@ -2243,7 +2247,8 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
tech_pvt->dest = switch_core_session_strdup(nsession, buf); tech_pvt->dest = switch_core_session_strdup(nsession, buf);
} else { } else {
terminate_session(&nsession, SWITCH_CAUSE_NO_ROUTE_DESTINATION, __LINE__); cause = SWITCH_CAUSE_NO_ROUTE_DESTINATION;
terminate_session(&nsession, cause, __LINE__);
goto done; goto done;
} }
} else { } else {
@ -2261,7 +2266,7 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(nchannel, CS_INIT); switch_channel_set_state(nchannel, CS_INIT);
*new_session = nsession; *new_session = nsession;
status = SWITCH_STATUS_SUCCESS; cause = SWITCH_CAUSE_SUCCESS;
if (session) { if (session) {
//char *val; //char *val;
//switch_channel_t *channel = switch_core_session_get_channel(session); //switch_channel_t *channel = switch_core_session_get_channel(session);
@ -2269,7 +2274,7 @@ static switch_status_t sofia_outgoing_channel(switch_core_session_t *session, sw
} }
done: done:
return status; return cause;
} }

View File

@ -71,12 +71,12 @@ typedef enum {
} TFLAGS; } TFLAGS;
#define DEFAULT_MTU 160 #define DEFAULT_SAMPLES_PER_FRAME 160
static struct { static struct {
int debug; int debug;
int panic; int panic;
uint32_t mtu; uint32_t samples_per_frame;
int dtmf_on; int dtmf_on;
int dtmf_off; int dtmf_off;
int supress_dtmf_tone; int supress_dtmf_tone;
@ -92,7 +92,6 @@ struct wanpipe_pri_span {
int dchan; int dchan;
unsigned int bchans; unsigned int bchans;
int node; int node;
int mtu;
int pswitch; int pswitch;
char *dialplan; char *dialplan;
unsigned int l1; unsigned int l1;
@ -134,6 +133,7 @@ struct private_object {
unsigned int skip_read_frames; unsigned int skip_read_frames;
unsigned int skip_write_frames; unsigned int skip_write_frames;
switch_mutex_t *flag_mutex; switch_mutex_t *flag_mutex;
int frame_size;
#ifdef DOTRACE #ifdef DOTRACE
int fd; int fd;
int fd2; int fd2;
@ -296,8 +296,8 @@ static switch_status_t wanpipe_on_init(switch_core_session_t *session);
static switch_status_t wanpipe_on_hangup(switch_core_session_t *session); static switch_status_t wanpipe_on_hangup(switch_core_session_t *session);
static switch_status_t wanpipe_on_loopback(switch_core_session_t *session); static switch_status_t wanpipe_on_loopback(switch_core_session_t *session);
static switch_status_t wanpipe_on_transmit(switch_core_session_t *session); static switch_status_t wanpipe_on_transmit(switch_core_session_t *session);
static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool); switch_core_session_t **new_session, switch_memory_pool_t *pool);
static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id); switch_io_flag_t flags, int stream_id);
static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
@ -323,9 +323,8 @@ static switch_status_t wanpipe_on_init(switch_core_session_t *session)
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
wanpipe_tdm_api_t tdm_api = {{0}}; wanpipe_tdm_api_t tdm_api = {{0}};
int err = 0; int err = 0;
unsigned int mtu_mru;
unsigned int rate = 8000; unsigned int rate = 8000;
int new_mtu = ((globals.mtu / 8) / 2);
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
assert(channel != NULL); assert(channel != NULL);
@ -337,23 +336,11 @@ static switch_status_t wanpipe_on_init(switch_core_session_t *session)
err = sangoma_tdm_set_codec(tech_pvt->wpsock->fd, &tdm_api, WP_SLINEAR); err = sangoma_tdm_set_codec(tech_pvt->wpsock->fd, &tdm_api, WP_SLINEAR);
mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->wpsock->fd, &tdm_api); sangoma_tdm_set_usr_period(tech_pvt->wpsock->fd, &tdm_api, globals.samples_per_frame / 8);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE INIT MTU is %d\n", mtu_mru); tech_pvt->frame_size = sangoma_tdm_get_usr_mtu_mru(tech_pvt->wpsock->fd, &tdm_api);
if (mtu_mru != globals.mtu) {
sangoma_tdm_set_usr_period(tech_pvt->wpsock->fd, &tdm_api, 40);
err = sangoma_tdm_set_usr_period(tech_pvt->wpsock->fd, &tdm_api, new_mtu);
mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->wpsock->fd, &tdm_api);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ADJUSTED MTU AFTER SETTING IT TO %d is %d %d [%s]\n", new_mtu, mtu_mru, err, strerror(err));
if (mtu_mru != globals.mtu) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failure to adjust MTU\n");
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
}
}
if (switch_core_codec_init if (switch_core_codec_init
(&tech_pvt->read_codec, "L16", NULL, rate, 20, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, (&tech_pvt->read_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@ -361,7 +348,7 @@ static switch_status_t wanpipe_on_init(switch_core_session_t *session)
} }
if (switch_core_codec_init if (switch_core_codec_init
(&tech_pvt->write_codec, "L16", NULL, rate, 20, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, (&tech_pvt->write_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
@ -449,12 +436,14 @@ static switch_status_t wanpipe_on_hangup(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE HANGUP\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE HANGUP\n");
if (!switch_test_flag(tech_pvt, TFLAG_NOSIG)) { if (!switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
pri_hangup(tech_pvt->spri->pri, tech_pvt->call, tech_pvt->cause); pri_hangup(tech_pvt->spri->pri, tech_pvt->call, switch_channel_get_cause(channel));
pri_destroycall(tech_pvt->spri->pri, tech_pvt->call); pri_destroycall(tech_pvt->spri->pri, tech_pvt->call);
switch_mutex_lock(globals.channel_mutex);
if (chanmap->map[tech_pvt->callno]) { if (chanmap->map[tech_pvt->callno]) {
chanmap->map[tech_pvt->callno][0] = '\0'; chanmap->map[tech_pvt->callno][0] = '\0';
} }
switch_mutex_unlock(globals.channel_mutex);
/* /*
pri_hangup(tech_pvt->spri->pri, pri_hangup(tech_pvt->spri->pri,
tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.call, tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.call,
@ -521,7 +510,7 @@ static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
uint8_t *bp; uint8_t *bp;
uint32_t bytes = 0; uint32_t bytes = 0;
int res = 0; int bread = 0;
char digit_str[80]; char digit_str[80];
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
@ -530,7 +519,6 @@ static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) { if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -539,8 +527,7 @@ static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch
*frame = NULL; *frame = NULL;
memset(tech_pvt->databuf, 0, sizeof(tech_pvt->databuf)); memset(tech_pvt->databuf, 0, sizeof(tech_pvt->databuf));
while (bytes < globals.mtu) { while (bytes < globals.samples_per_frame * 2) {
if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) { if (switch_test_flag(tech_pvt, TFLAG_BYE) || tech_pvt->wpsock->fd < 0) {
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -550,7 +537,7 @@ static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
if ((res = sangoma_readmsg_socket(tech_pvt->wpsock->fd, if ((bread = sangoma_readmsg_socket(tech_pvt->wpsock->fd,
&tech_pvt->hdrframe, &tech_pvt->hdrframe,
sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) { sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
if (errno == EBUSY) { if (errno == EBUSY) {
@ -560,7 +547,7 @@ static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch
} }
} }
bytes += res; bytes += bread;
bp += bytes; bp += bytes;
} }
@ -571,8 +558,8 @@ static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch
tech_pvt->read_frame.datalen = bytes; tech_pvt->read_frame.datalen = bytes;
tech_pvt->read_frame.samples = bytes / 2; tech_pvt->read_frame.samples = bytes / 2;
res = teletone_dtmf_detect (&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples); teletone_dtmf_detect (&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
res = teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str)); teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
if(digit_str[0]) { if(digit_str[0]) {
switch_channel_queue_dtmf(channel, digit_str); switch_channel_queue_dtmf(channel, digit_str);
@ -622,8 +609,8 @@ static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switc
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
if ((bread = switch_buffer_read(tech_pvt->dtmf_buffer, dtmf, globals.mtu)) < globals.mtu) { if ((bread = switch_buffer_read(tech_pvt->dtmf_buffer, dtmf, tech_pvt->frame_size)) < tech_pvt->frame_size) {
while (bread < globals.mtu) { while (bread < tech_pvt->frame_size) {
dtmf[bread++] = 0; dtmf[bread++] = 0;
} }
} }
@ -674,14 +661,14 @@ static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switc
#endif #endif
#ifdef DOTRACE #ifdef DOTRACE
write(tech_pvt->fd, bp, (int) globals.mtu); write(tech_pvt->fd, bp, (int) tech_pvt->frame_size);
#endif #endif
towrite = bytes >= globals.mtu ? globals.mtu : bytes; towrite = bytes >= tech_pvt->frame_size ? tech_pvt->frame_size : bytes;
if (towrite < globals.mtu) { if (towrite < tech_pvt->frame_size) {
int diff = globals.mtu - towrite; int diff = tech_pvt->frame_size - towrite;
memset(bp + towrite, 0, diff); memset(bp + towrite, 0, diff);
towrite = globals.mtu; towrite = tech_pvt->frame_size;
} }
result = sangoma_sendmsg_socket(tech_pvt->wpsock->fd, result = sangoma_sendmsg_socket(tech_pvt->wpsock->fd,
@ -689,7 +676,7 @@ static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switc
if (result < 0) { if (result < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Bad Write frame len %u write %d bytes returned %d (%s)!\n", towrite, "Bad Write frame len %u write %d bytes returned %d (%s)!\n", towrite,
globals.mtu, result, strerror(errno)); tech_pvt->frame_size, result, strerror(errno));
if (errno == EBUSY) { if (errno == EBUSY) {
continue; continue;
} }
@ -846,8 +833,8 @@ static const switch_loadable_module_interface_t wanpipe_module_interface = {
}; };
static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool) switch_core_session_t **new_session, switch_memory_pool_t *pool)
{ {
char *bchan = NULL; char *bchan = NULL;
char name[128] = ""; char name[128] = "";
@ -862,12 +849,12 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
if (bchan) { if (bchan) {
bchan++; bchan++;
if (!bchan) { if (!bchan) {
return SWITCH_STATUS_FALSE; return SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL;
} }
outbound_profile->destination_number++; outbound_profile->destination_number++;
} else if (!globals.configured_spans) { } else if (!globals.configured_spans) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error No Spans Configured.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error No Spans Configured.\n");
return SWITCH_STATUS_FALSE; SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
} }
@ -885,7 +872,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
@ -902,17 +889,21 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
num = caller_profile->destination_number; num = caller_profile->destination_number;
if ((p = strchr(num, '/'))) { if ((p = strchr(num, '/'))) {
*p++ = '\0'; *p++ = '\0';
if (*num != 'a') {
if (*num == 'a') {
span = 1;
autospan = 1;
} else if (*num = 'A') {
span = MAX_SPANS - 1;
autospan = -1;
} else {
if (num && *num > 47 && *num < 58) { if (num && *num > 47 && *num < 58) {
span = atoi(num); span = atoi(num);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invlid Syntax\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invlid Syntax\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
} else {
span = 0;
autospan = 1;
} }
num = p; num = p;
if ((p = strchr(num, '/'))) { if ((p = strchr(num, '/'))) {
@ -926,13 +917,13 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invlid Syntax\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invlid Syntax\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
caller_profile->destination_number = p; caller_profile->destination_number = p;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invlid Syntax\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invlid Syntax\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
} }
} }
@ -946,64 +937,70 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
if (!wp_open(tech_pvt, span, chan)) { if (!wp_open(tech_pvt, span, chan)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n", span, chan, strerror(errno)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n", span, chan, strerror(errno));
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
switch_set_flag_locked(tech_pvt, TFLAG_NOSIG); switch_set_flag_locked(tech_pvt, TFLAG_NOSIG);
snprintf(name, sizeof(name), "WanPipe/%s/nosig-%04x", bchan, rand() & 0xffff); snprintf(name, sizeof(name), "WanPipe/%s/nosig", bchan);
switch_channel_set_name(channel, name); switch_channel_set_name(channel, name);
switch_channel_set_caller_profile(channel, caller_profile); switch_channel_set_caller_profile(channel, caller_profile);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid address\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid address\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL;
} }
} else { } else {
switch_mutex_lock(globals.channel_mutex); switch_mutex_lock(globals.channel_mutex);
do { channo = 0;
if (autospan) { while (!channo) {
span++; if (autospan > 0 && span == MAX_SPANS - 1) {
break;
} }
if ((spri = &SPANS[span]->spri) && switch_test_flag(spri, SANGOMA_PRI_READY)) {
chanmap = spri->private_info;
if (channo == 0) {
if (autochan > 0) {
for(channo = 1; channo < SANGOMA_MAX_CHAN_PER_SPAN; channo++) {
if ((SPANS[span]->bchans & (1 << channo)) && !chanmap->map[channo][0]) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel %d\n", channo);
break;
}
}
} else if (autochan < 0) {
for(channo = SANGOMA_MAX_CHAN_PER_SPAN; channo > 0; channo--) {
if ((SPANS[span]->bchans & (1 << channo)) && !chanmap->map[channo][0]) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel %d\n", channo);
break;
}
}
}
if (channo <= 0 || channo == (SANGOMA_MAX_CHAN_PER_SPAN)) { if (autospan < 0 && span == 0) {
channo = 0; break;
break; }
if (SPANS[span] && (spri = &SPANS[span]->spri) && switch_test_flag(spri, SANGOMA_PRI_READY)) {
chanmap = spri->private_info;
if (autochan > 0) {
for(channo = 1; channo < SANGOMA_MAX_CHAN_PER_SPAN; channo++) {
if ((SPANS[span]->bchans & (1 << channo)) && !chanmap->map[channo][0]) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel s%dc%d\n", span, channo);
goto done;
}
} }
} channo = 0;
if (channo) { } else if (autochan < 0) {
break; for(channo = SANGOMA_MAX_CHAN_PER_SPAN; channo > 0; channo--) {
if ((SPANS[span]->bchans & (1 << channo)) && !chanmap->map[channo][0]) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel s%dc%d\n", span, channo);
goto done;
}
}
channo = 0;
} }
} }
} while(autospan && span < MAX_SPANS && !spri && !channo);
if (autospan > 0) {
span++;
} else if (autospan < 0) {
span--;
}
}
done:
switch_mutex_unlock(globals.channel_mutex); switch_mutex_unlock(globals.channel_mutex);
if (!spri || channo == 0 || channo == (SANGOMA_MAX_CHAN_PER_SPAN)) { if (!spri || channo == 0 || channo == (SANGOMA_MAX_CHAN_PER_SPAN)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No Free Channels!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No Free Channels!\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_SWITCH_CONGESTION;
} }
if (spri && (tech_pvt->call = pri_new_call(spri->pri))) { if (spri && (tech_pvt->call = pri_new_call(spri->pri))) {
struct pri_sr *sr; struct pri_sr *sr;
snprintf(name, sizeof(name), "WanPipe/s%dc%d/%s-%04x", spri->span, channo, caller_profile->destination_number, rand() & 0xffff); snprintf(name, sizeof(name), "WanPipe/s%dc%d/%s", spri->span, channo, caller_profile->destination_number);
switch_channel_set_name(channel, name); switch_channel_set_name(channel, name);
switch_channel_set_caller_profile(channel, caller_profile); switch_channel_set_caller_profile(channel, caller_profile);
sr = pri_sr_new(); sr = pri_sr_new();
@ -1024,14 +1021,14 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
if (pri_setup(spri->pri, tech_pvt->call , sr)) { if (pri_setup(spri->pri, tech_pvt->call , sr)) {
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
pri_sr_free(sr); pri_sr_free(sr);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if (!wp_open(tech_pvt, spri->span, channo)) { if (!wp_open(tech_pvt, spri->span, channo)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd!\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
pri_sr_free(sr); pri_sr_free(sr);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
pri_sr_free(sr); pri_sr_free(sr);
switch_copy_string(chanmap->map[channo], switch_copy_string(chanmap->map[channo],
@ -1043,16 +1040,16 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_CAUSE_SUCCESS;
} }
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
@ -1144,9 +1141,12 @@ static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, p
tech_pvt->cause = pevent->hangup.cause; tech_pvt->cause = pevent->hangup.cause;
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, tech_pvt->cause);
switch_mutex_lock(globals.channel_mutex);
chanmap->map[pevent->hangup.channel][0] = '\0'; chanmap->map[pevent->hangup.channel][0] = '\0';
switch_mutex_unlock(globals.channel_mutex);
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
} }
@ -1190,6 +1190,7 @@ static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type,
switch_core_session_message_t *msg; switch_core_session_message_t *msg;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d\n", spri->span, pevent->proceeding.channel); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d\n", spri->span, pevent->proceeding.channel);
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
assert(channel != NULL); assert(channel != NULL);
@ -1203,7 +1204,7 @@ static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
} }
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d but it's not in use?\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d but it's not in use?\n",
@ -1463,7 +1464,7 @@ static switch_status_t config_wanpipe(int reload)
int current_span = 0, min_span = 0, max_span = 0; int current_span = 0, min_span = 0, max_span = 0;
switch_xml_t cfg, xml, settings, param, span; switch_xml_t cfg, xml, settings, param, span;
globals.mtu = DEFAULT_MTU; globals.samples_per_frame = DEFAULT_SAMPLES_PER_FRAME;
globals.dtmf_on = 150; globals.dtmf_on = 150;
globals.dtmf_off = 50; globals.dtmf_off = 50;
@ -1482,8 +1483,8 @@ static switch_status_t config_wanpipe(int reload)
if (!strcmp(var, "debug")) { if (!strcmp(var, "debug")) {
globals.debug = atoi(val); globals.debug = atoi(val);
} else if (!strcmp(var, "mtu")) { } else if (!strcmp(var, "ms-per-frame")) {
globals.mtu = atoi(val); globals.samples_per_frame = atoi(val) * 8;
} else if (!strcmp(var, "dtmf-on")) { } else if (!strcmp(var, "dtmf-on")) {
globals.dtmf_on = atoi(val); globals.dtmf_on = atoi(val);
} else if (!strcmp(var, "dtmf-off")) { } else if (!strcmp(var, "dtmf-off")) {
@ -1578,14 +1579,6 @@ static switch_status_t config_wanpipe(int reload)
SPANS[current_span]->l1 = str2l1(val); SPANS[current_span]->l1 = str2l1(val);
} else if (!strcmp(var, "dialplan")) { } else if (!strcmp(var, "dialplan")) {
set_global_dialplan(val); set_global_dialplan(val);
} else if (!strcmp(var, "mtu")) {
int mtu = atoi(val);
if (mtu >= 10 && mtu < 960) {
SPANS[current_span]->mtu = mtu;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid MTU (%s)!\n", val);
}
} }
} }
} }

View File

@ -169,7 +169,7 @@ static switch_status_t woomera_on_hangup(switch_core_session_t *session);
static switch_status_t woomera_on_ring(switch_core_session_t *session); static switch_status_t woomera_on_ring(switch_core_session_t *session);
static switch_status_t woomera_on_loopback(switch_core_session_t *session); static switch_status_t woomera_on_loopback(switch_core_session_t *session);
static switch_status_t woomera_on_transmit(switch_core_session_t *session); static switch_status_t woomera_on_transmit(switch_core_session_t *session);
static switch_status_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool); switch_core_session_t **new_session, switch_memory_pool_t *pool);
static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id); switch_io_flag_t flags, int stream_id);
@ -481,8 +481,8 @@ static const switch_loadable_module_interface_t woomera_module_interface = {
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool! that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/ */
static switch_status_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile, static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t *pool) switch_core_session_t **new_session, switch_memory_pool_t *pool)
{ {
if ((*new_session = switch_core_session_request(&woomera_endpoint_interface, pool)) != 0) { if ((*new_session = switch_core_session_request(&woomera_endpoint_interface, pool)) != 0) {
struct private_object *tech_pvt; struct private_object *tech_pvt;
@ -500,7 +500,7 @@ static switch_status_t woomera_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
if (outbound_profile) { if (outbound_profile) {
@ -516,16 +516,16 @@ static switch_status_t woomera_outgoing_channel(switch_core_session_t *session,
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT); switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS; return SWITCH_CAUSE_SUCCESS;
} }
return SWITCH_STATUS_GENERR; return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
} }

View File

@ -1542,21 +1542,22 @@ SWITCH_DECLARE(int) switch_core_session_get_stream_count(switch_core_session_t *
return session->stream_count; return session->stream_count;
} }
SWITCH_DECLARE(switch_status_t) switch_core_session_outgoing_channel(switch_core_session_t *session, SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_core_session_t *session,
char *endpoint_name, char *endpoint_name,
switch_caller_profile_t *caller_profile, switch_caller_profile_t *caller_profile,
switch_core_session_t **new_session, switch_core_session_t **new_session,
switch_memory_pool_t *pool) switch_memory_pool_t *pool)
{ {
switch_io_event_hook_outgoing_channel_t *ptr; switch_io_event_hook_outgoing_channel_t *ptr;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
const switch_endpoint_interface_t *endpoint_interface; const switch_endpoint_interface_t *endpoint_interface;
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
switch_caller_profile_t *outgoing_profile = caller_profile; switch_caller_profile_t *outgoing_profile = caller_profile;
switch_call_cause_t cause = SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL;
if ((endpoint_interface = switch_loadable_module_get_endpoint_interface(endpoint_name)) == 0) { if ((endpoint_interface = switch_loadable_module_get_endpoint_interface(endpoint_name)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate channel type %s\n", endpoint_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate channel type %s\n", endpoint_name);
return SWITCH_STATUS_FALSE; return SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED;
} }
if (endpoint_interface->io_routines->outgoing_channel) { if (endpoint_interface->io_routines->outgoing_channel) {
@ -1595,10 +1596,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_outgoing_channel(switch_core
} }
} }
if ((status = endpoint_interface->io_routines->outgoing_channel(session, if ((cause = endpoint_interface->io_routines->outgoing_channel(session,
outgoing_profile, outgoing_profile,
new_session, new_session,
pool)) == SWITCH_STATUS_SUCCESS) { pool)) == SWITCH_CAUSE_SUCCESS) {
if (session) { if (session) {
for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) { for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) {
if ((status = ptr->outgoing_channel(session, caller_profile, *new_session)) != SWITCH_STATUS_SUCCESS) { if ((status = ptr->outgoing_channel(session, caller_profile, *new_session)) != SWITCH_STATUS_SUCCESS) {
@ -1607,11 +1608,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_outgoing_channel(switch_core
} }
} }
} else { } else {
return status; return cause;
} }
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate outgoing channel interface for %s\n", endpoint_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not locate outgoing channel interface for %s\n", endpoint_name);
return SWITCH_STATUS_FALSE; return SWITCH_CAUSE_CHAN_NOT_IMPLEMENTED;
} }
if (*new_session) { if (*new_session) {
@ -1688,7 +1689,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_outgoing_channel(switch_core
} }
} }
return status; return cause;
} }
SWITCH_DECLARE(switch_status_t) switch_core_session_answer_channel(switch_core_session_t *session) SWITCH_DECLARE(switch_status_t) switch_core_session_answer_channel(switch_core_session_t *session)

View File

@ -2678,8 +2678,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
} }
if (switch_core_session_outgoing_channel(session, chan_type, caller_profiles[i], &peer_sessions[i], pool) != SWITCH_STATUS_SUCCESS) { if ((reason = switch_core_session_outgoing_channel(session, chan_type, caller_profiles[i], &peer_sessions[i], pool)) != SWITCH_CAUSE_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel! cause: %s\n", switch_channel_cause2str(reason));
if (pool) { if (pool) {
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);
} }