From 35ba58e64994efa0a2c97a08b5164a5ea9f20679 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 30 Nov 2010 16:45:05 -0500 Subject: [PATCH 1/2] freetdm - ISDN:Fix for windows compilation issues --- libs/freetdm/src/ftdm_call_utils.c | 12 +++---- libs/freetdm/src/ftdm_io.c | 2 -- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.c | 4 +-- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.h | 31 +++++++++++++++++-- .../ftmod_sangoma_isdn_stack_hndl.c | 5 ++- .../ftmod_sangoma_isdn_support.c | 8 ++--- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/libs/freetdm/src/ftdm_call_utils.c b/libs/freetdm/src/ftdm_call_utils.c index 52d2557a01..69f2fb4fff 100644 --- a/libs/freetdm/src/ftdm_call_utils.c +++ b/libs/freetdm/src/ftdm_call_utils.c @@ -38,7 +38,7 @@ FT_DECLARE(ftdm_status_t) ftdm_set_npi(const char *string, uint8_t *target) { - int val; + uint8_t val; ftdm_status_t status = FTDM_SUCCESS; val = ftdm_str2ftdm_npi(string); @@ -53,7 +53,7 @@ FT_DECLARE(ftdm_status_t) ftdm_set_npi(const char *string, uint8_t *target) FT_DECLARE(ftdm_status_t) ftdm_set_ton(const char *string, uint8_t *target) { - int val; + uint8_t val; ftdm_status_t status = FTDM_SUCCESS; val = ftdm_str2ftdm_ton(string); @@ -68,7 +68,7 @@ FT_DECLARE(ftdm_status_t) ftdm_set_ton(const char *string, uint8_t *target) FT_DECLARE(ftdm_status_t) ftdm_set_bearer_capability(const char *string, uint8_t *target) { - int val; + uint8_t val; ftdm_status_t status = FTDM_SUCCESS; val = ftdm_str2ftdm_bearer_cap(string); @@ -84,7 +84,7 @@ FT_DECLARE(ftdm_status_t) ftdm_set_bearer_capability(const char *string, uint8_t FT_DECLARE(ftdm_status_t) ftdm_set_bearer_layer1(const char *string, uint8_t *target) { - int val; + uint8_t val; ftdm_status_t status = FTDM_SUCCESS; val = ftdm_str2ftdm_usr_layer1_prot(string); @@ -100,7 +100,7 @@ FT_DECLARE(ftdm_status_t) ftdm_set_bearer_layer1(const char *string, uint8_t *ta FT_DECLARE(ftdm_status_t) ftdm_set_screening_ind(const char *string, uint8_t *target) { - int val; + uint8_t val; ftdm_status_t status = FTDM_SUCCESS; val = ftdm_str2ftdm_screening(string); @@ -116,7 +116,7 @@ FT_DECLARE(ftdm_status_t) ftdm_set_screening_ind(const char *string, uint8_t *ta FT_DECLARE(ftdm_status_t) ftdm_set_presentation_ind(const char *string, uint8_t *target) { - int val; + uint8_t val; ftdm_status_t status = FTDM_SUCCESS; val = ftdm_str2ftdm_presentation(string); diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index bcaa15a77c..5ba7e389f8 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -38,8 +38,6 @@ */ #define _GNU_SOURCE -#ifndef WIN32 -#endif #include "private/ftdm_core.h" #include #ifdef WIN32 diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c index 02927d7c88..03b5a5fb1d 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c @@ -799,9 +799,7 @@ static void ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdmchan) break; case FTDM_CHANNEL_STATE_DOWN: /* the call is finished and removed */ { - uint8_t glare = 0; - - glare = sngisdn_test_flag(sngisdn_info, FLAG_GLARE); + uint8_t glare = sngisdn_test_flag(sngisdn_info, FLAG_GLARE); /* clear all of the call specific data store in the channel structure */ clear_call_data(sngisdn_info); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h index 9cddecb04e..b9ab3395ae 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h @@ -64,6 +64,33 @@ /* TODO: rename all *_cc_* to *_an_* */ +#define SNGISDN_ENUM_NAMES(_NAME, _STRINGS) static const char * _NAME [] = { _STRINGS , NULL }; +#define SNGISDN_STR2ENUM_P(_FUNC1, _FUNC2, _TYPE) _TYPE _FUNC1 (const char *name); const char * _FUNC2 (_TYPE type); +#define SNGISDN_STR2ENUM(_FUNC1, _FUNC2, _TYPE, _STRINGS, _MAX) \ + _TYPE _FUNC1 (const char *name) \ +{ \ + int i; \ + _TYPE t = _MAX ; \ + \ + for (i = 0; i < _MAX ; i++) { \ + if (!strcasecmp(name, _STRINGS[i])) { \ + t = (_TYPE) i; \ + break; \ +} \ +} \ + \ + return t; \ +} \ + const char * _FUNC2 (_TYPE type) \ +{ \ + if (type > _MAX) { \ + type = _MAX; \ +} \ + return _STRINGS[(int)type]; \ +} \ + + + typedef enum { FLAG_RESET_RX = (1 << 0), FLAG_RESET_TX = (1 << 1), @@ -153,7 +180,7 @@ typedef enum { SNGISDN_PROGIND_DESCR_INVALID, } ftdm_sngisdn_progind_descr_t; #define SNGISDN_PROGIND_DESCR_STRINGS "not-end-to-end-isdn", "destination-is-non-isdn", "origination-is-non-isdn", "call-returned-to-isdn", "service-change", "inband-info-available", "invalid" -FTDM_STR2ENUM_P(ftdm_str2ftdm_sngisdn_progind_descr, ftdm_sngisdn_progind_descr2str, ftdm_sngisdn_progind_descr_t); +SNGISDN_STR2ENUM_P(ftdm_str2ftdm_sngisdn_progind_descr, ftdm_sngisdn_progind_descr2str, ftdm_sngisdn_progind_descr_t); typedef enum { /* User */ @@ -174,7 +201,7 @@ typedef enum { SNGISDN_PROGIND_LOC_INVALID, } ftdm_sngisdn_progind_loc_t; #define SNGISDN_PROGIND_LOC_STRINGS "user", "private-net-local-user", "public-net-local-user", "transit-network", "public-net-remote-user", "private-net-remote-user", "beyond-interworking", "invalid" -FTDM_STR2ENUM_P(ftdm_str2ftdm_sngisdn_progind_loc, ftdm_sngisdn_progind_loc2str, ftdm_sngisdn_progind_loc_t); +SNGISDN_STR2ENUM_P(ftdm_str2ftdm_sngisdn_progind_loc, ftdm_sngisdn_progind_loc2str, ftdm_sngisdn_progind_loc_t); typedef struct ftdm_sngisdn_prog_ind { ftdm_sngisdn_progind_loc_t loc; /* location */ diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_hndl.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_hndl.c index c4e9f4a33f..d557ca3ba0 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_hndl.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_hndl.c @@ -255,10 +255,9 @@ void sngisdn_process_con_cfm (sngisdn_event_data_t *sngisdn_event) uint8_t ces = sngisdn_event->ces; sngisdn_chan_data_t *sngisdn_info = sngisdn_event->sngisdn_info; ftdm_channel_t *ftdmchan = sngisdn_info->ftdmchan; - - ISDN_FUNC_TRACE_ENTER(__FUNCTION__); - CnStEvnt *cnStEvnt = &sngisdn_event->event.cnStEvnt; + + ISDN_FUNC_TRACE_ENTER(__FUNCTION__); ftdm_assert(!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_STATE_CHANGE), "State change flag pending\n"); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c index 964d06caaf..42bcd1e20a 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c @@ -37,11 +37,11 @@ /* ftmod_sangoma_isdn specific enum look-up functions */ -FTDM_ENUM_NAMES(SNGISDN_PROGIND_DESCR_NAMES, SNGISDN_PROGIND_DESCR_STRINGS) -FTDM_STR2ENUM(ftdm_str2ftdm_sngisdn_progind_descr, ftdm_sngisdn_progind_descr2str, ftdm_sngisdn_progind_descr_t, SNGISDN_PROGIND_DESCR_NAMES, SNGISDN_PROGIND_DESCR_INVALID) +SNGISDN_ENUM_NAMES(SNGISDN_PROGIND_DESCR_NAMES, SNGISDN_PROGIND_DESCR_STRINGS) +SNGISDN_STR2ENUM(ftdm_str2ftdm_sngisdn_progind_descr, ftdm_sngisdn_progind_descr2str, ftdm_sngisdn_progind_descr_t, SNGISDN_PROGIND_DESCR_NAMES, SNGISDN_PROGIND_DESCR_INVALID) -FTDM_ENUM_NAMES(SNGISDN_PROGIND_LOC_NAMES, SNGISDN_PROGIND_LOC_STRINGS) -FTDM_STR2ENUM(ftdm_str2ftdm_sngisdn_progind_loc, ftdm_sngisdn_progind_loc2str, ftdm_sngisdn_progind_loc_t, SNGISDN_PROGIND_LOC_NAMES, SNGISDN_PROGIND_LOC_INVALID) +SNGISDN_ENUM_NAMES(SNGISDN_PROGIND_LOC_NAMES, SNGISDN_PROGIND_LOC_STRINGS) +SNGISDN_STR2ENUM(ftdm_str2ftdm_sngisdn_progind_loc, ftdm_sngisdn_progind_loc2str, ftdm_sngisdn_progind_loc_t, SNGISDN_PROGIND_LOC_NAMES, SNGISDN_PROGIND_LOC_INVALID) ftdm_status_t sngisdn_check_free_ids(void); From 71e8ed8180d50227cf324c218cd13039c51a51dd Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 1 Dec 2010 17:02:58 -0500 Subject: [PATCH 2/2] freetdm: ISDN - Fix for not being able to open d-channel when span is in alarm --- libs/freetdm/src/ftdm_io.c | 39 ++++++++++--------- .../ftmod_sangoma_isdn_cfg.c | 2 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 5ba7e389f8..3dd1aa9ece 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -1764,16 +1764,26 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan) ftdm_mutex_lock(ftdmchan->mutex); - if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_SUSPENDED)) { - snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is suspended\n"); - ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Cannot open channel when is suspended\n"); - goto done; - } - - if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_IN_ALARM) && !ftdm_test_flag(ftdmchan->span, FTDM_SPAN_PWR_SAVING)) { - snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is alarmed\n"); - ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Cannot open channel when is alarmed\n"); - goto done; + if (FTDM_IS_VOICE_CHANNEL(ftdmchan)) { + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_SUSPENDED)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is suspended\n"); + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Cannot open channel when is suspended\n"); + goto done; + } + + if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_IN_ALARM) && !ftdm_test_flag(ftdmchan->span, FTDM_SPAN_PWR_SAVING)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "Channel is alarmed\n"); + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Cannot open channel when is alarmed\n"); + goto done; + } + + if (globals.cpu_monitor.alarm && + globals.cpu_monitor.alarm_action_flags & FTDM_CPU_ALARM_ACTION_REJECT) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "CPU usage alarm is on - refusing to open channel\n"); + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "CPU usage alarm is on - refusing to open channel\n"); + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_SWITCH_CONGESTION; + goto done; + } } if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_READY)) { @@ -1782,15 +1792,6 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_chan(ftdm_channel_t *ftdmchan) goto done; } - if (globals.cpu_monitor.alarm && - globals.cpu_monitor.alarm_action_flags & FTDM_CPU_ALARM_ACTION_REJECT) { - snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", "CPU usage alarm is on - refusing to open channel\n"); - ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "CPU usage alarm is on - refusing to open channel\n"); - ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_SWITCH_CONGESTION; - goto done; - } - - status = ftdmchan->fio->open(ftdmchan); if (status == FTDM_SUCCESS) { ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OPEN | FTDM_CHANNEL_INUSE); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_cfg.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_cfg.c index 6afab42a89..cce10cc1dd 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_cfg.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_cfg.c @@ -280,7 +280,7 @@ ftdm_status_t ftmod_isdn_parse_cfg(ftdm_conf_parameter_t *ftdm_parameters, ftdm_ } else if (!strcasecmp(var, "outbound-bearer_cap")) { ftdm_set_bearer_capability(val, (uint8_t*)&span->default_caller_data.bearer_capability); } else if (!strcasecmp(var, "outbound-bearer_layer1")) { - ftdm_set_bearer_layer1(val, &span->default_caller_data.bearer_layer1); + ftdm_set_bearer_layer1(val, (uint8_t*)&span->default_caller_data.bearer_layer1); } else if (!strcasecmp(var, "channel-restart-on-link-up")) { parse_yesno(var, val, &signal_data->restart_opt); } else if (!strcasecmp(var, "local-number")) {