From 6cbf8a0167d9a3d79ff3846e14bc90dbf4fe7371 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 10 Nov 2010 19:03:15 -0500 Subject: [PATCH 01/10] freetdm: ISDN - Changes to used ftdm IO for d-channel --- .../freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 1 - .../ftmod_sangoma_boost/ftmod_sangoma_boost.c | 8 +- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.c | 168 ++++++++++++++---- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.h | 51 +++--- .../ftmod_sangoma_isdn_cfg.c | 33 ++-- .../ftmod_sangoma_isdn_stack_cfg.c | 107 +++++------ .../ftmod_sangoma_isdn_stack_cntrl.c | 83 ++++++--- .../ftmod_sangoma_isdn_stack_hndl.c | 2 +- .../ftmod_sangoma_isdn_stack_out.c | 11 ++ .../ftmod_sangoma_isdn_stack_rcv.c | 24 ++- .../ftmod_sangoma_isdn_support.c | 35 +++- libs/freetdm/src/include/private/ftdm_core.h | 2 + libs/freetdm/src/include/private/ftdm_types.h | 3 +- 13 files changed, 369 insertions(+), 159 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index 65c9dfc11f..d64e711e73 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -53,7 +53,6 @@ //#define IODEBUG /* helper macros */ -#define FTDM_SPAN_IS_BRI(x) ((x)->trunk_type == FTDM_TRUNK_BRI || (x)->trunk_type == FTDM_TRUNK_BRI_PTMP) #define FTDM_SPAN_IS_NT(x) (((ftdm_isdn_data_t *)(x)->signal_data)->mode == Q921_NT) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index a975204b62..c9691e232b 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -1557,11 +1557,11 @@ static __inline__ ftdm_status_t state_advance(ftdm_channel_t *ftdmchan) ftdm_set_string(event.calling_name, ftdmchan->caller_data.cid_name); ftdm_set_string(event.rdnis.digits, ftdmchan->caller_data.rdnis.digits); if (strlen(ftdmchan->caller_data.rdnis.digits)) { - event.rdnis.digits_count = (uint8_t)strlen(ftdmchan->caller_data.rdnis.digits)+1; - event.rdnis.ton = ftdmchan->caller_data.rdnis.type; - event.rdnis.npi = ftdmchan->caller_data.rdnis.plan; + event.rdnis.digits_count = (uint8_t)strlen(ftdmchan->caller_data.rdnis.digits)+1; + event.rdnis.ton = ftdmchan->caller_data.rdnis.type; + event.rdnis.npi = ftdmchan->caller_data.rdnis.plan; } - + event.calling.screening_ind = ftdmchan->caller_data.screen; event.calling.presentation_ind = ftdmchan->caller_data.pres; 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 22c89cb920..04c3b86c5e 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 @@ -47,6 +47,8 @@ static ftdm_status_t ftdm_sangoma_isdn_start(ftdm_span_t *span); ftdm_channel_t* ftdm_sangoma_isdn_process_event_states(ftdm_span_t *span, sngisdn_event_data_t *sngisdn_event); static void ftdm_sangoma_isdn_advance_chan_states(ftdm_channel_t *ftdmchan); +static void ftdm_sangoma_isdn_poll_events(ftdm_span_t *span); +static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_event_t event); static void ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdmchan); static void ftdm_sangoma_isdn_process_stack_event (ftdm_span_t *span, sngisdn_event_data_t *sngisdn_event); @@ -56,7 +58,7 @@ static sng_isdn_event_interface_t g_sngisdn_event_interface; ftdm_sngisdn_data_t g_sngisdn_data; -extern ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt); +extern ftdm_status_t sngisdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt); extern ftdm_status_t sngisdn_check_free_ids(void); ftdm_state_map_t sangoma_isdn_state_map = { @@ -238,6 +240,106 @@ static __inline__ void ftdm_sangoma_isdn_advance_chan_states(ftdm_channel_t *ftd } } +static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_event_t event) +{ + + switch (event) { + /* Check if the span woke up from power-saving mode */ + case FTDM_OOB_ALARM_CLEAR: + sngisdn_snd_event(span, SNG_L1EVENT_ALARM_OFF); + if (FTDM_SPAN_IS_BRI(span)) { + ftdm_channel_t *ftdmchan; + ftdm_iterator_t *chaniter = NULL; + ftdm_iterator_t *curr = NULL; + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; + + chaniter = ftdm_span_get_chan_iterator(span, NULL); + for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) { + ftdmchan = (ftdm_channel_t*)ftdm_iterator_current(curr); + sngisdn_chan_data_t *sngisdn_info = ftdmchan->call_data; + + if (ftdm_test_flag(sngisdn_info, FLAG_ACTIVATING)) { + ftdm_clear_flag(sngisdn_info, FLAG_ACTIVATING); + + ftdm_sched_timer(signal_data->sched, "delayed_setup", 1, sngisdn_delayed_setup, (void*) ftdmchan->call_data, NULL); + } + } + ftdm_iterator_free(chaniter); + } + break; + case FTDM_OOB_ALARM_TRAP: + sngisdn_snd_event(span, SNG_L1EVENT_ALARM_ON); + break; + default: + /* Ignore other events for now */ + break; + } +} + +static void ftdm_sangoma_isdn_poll_events(ftdm_span_t *span) +{ + ftdm_status_t ret_status; + ret_status = ftdm_span_poll_event(span, 0, NULL); + switch(ret_status) { + case FTDM_SUCCESS: + { + ftdm_event_t *event; + while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS) { + ftdm_sangoma_isdn_process_phy_events(span, event->enum_id); + } + } + break; + case FTDM_TIMEOUT: + /* No events pending */ + break; + default: + ftdm_log(FTDM_LOG_WARNING, "%s:Failed to poll span event\n", span->name); + } +} + +static void *ftdm_sangoma_isdn_dchan_run(ftdm_thread_t *me, void *obj) +{ + uint8_t data[1000]; + ftdm_status_t status = FTDM_SUCCESS; + ftdm_wait_flag_t wflags = FTDM_READ; + ftdm_span_t *span = (ftdm_span_t*) obj; + ftdm_channel_t *dchan = ((sngisdn_span_data_t*)span->signal_data)->dchan; + ftdm_size_t len = 0; + + + ftdm_assert(dchan, "Span does not have a dchannel"); + ftdm_channel_open_chan(dchan); + + while (ftdm_running() && !(ftdm_test_flag(span, FTDM_SPAN_STOP_THREAD))) { + wflags = FTDM_READ; + status = ftdm_channel_wait(dchan, &wflags, 0); + switch(status) { + case FTDM_FAIL: + ftdm_log_chan_msg(dchan, FTDM_LOG_CRIT, "Failed to wait for d-channel\n"); + break; + case FTDM_TIMEOUT: + break; + case FTDM_SUCCESS: + if ((wflags & FTDM_READ)) { + len = 1000; + status = ftdm_channel_read(dchan, data, &len); + if (status == FTDM_SUCCESS) { + sngisdn_snd_data(span, data, len); + } else { + ftdm_log_chan_msg(dchan, FTDM_LOG_WARNING, "Failed to read from channel \n"); + } + } else { + ftdm_log_chan_msg(dchan, FTDM_LOG_CRIT, "Failed to poll for d-channel\n"); + } + break; + default: + ftdm_log_chan_msg(dchan, FTDM_LOG_CRIT, "Unhandled IO event\n"); + } + } + ftdm_channel_close(&dchan); + return NULL; +} + static void *ftdm_sangoma_isdn_run(ftdm_thread_t *me, void *obj) { ftdm_interrupt_t *ftdm_sangoma_isdn_int[2]; @@ -300,21 +402,8 @@ static void *ftdm_sangoma_isdn_run(ftdm_thread_t *me, void *obj) } /* Poll for events, e.g HW DTMF */ - ret_status = ftdm_span_poll_event(span, 0, NULL); - switch(ret_status) { - case FTDM_SUCCESS: - { - ftdm_event_t *event; - while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS); - } - break; - case FTDM_TIMEOUT: - /* No events pending */ - break; - default: - ftdm_log(FTDM_LOG_WARNING, "%s:Failed to poll span event\n", span->name); - } - + ftdm_sangoma_isdn_poll_events(span); + if (ftdm_sched_get_time_to_next_timer(signal_data->sched, &sleep) == FTDM_SUCCESS) { if (sleep < 0 || sleep > SNGISDN_EVENT_POLL_RATE) { sleep = SNGISDN_EVENT_POLL_RATE; @@ -498,8 +587,20 @@ static void ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdmchan) } break; case FTDM_CHANNEL_STATE_DIALING: /* outgoing call request */ - { - sngisdn_snd_setup(ftdmchan); + { + if (FTDM_SPAN_IS_BRI(ftdmchan->span) && + ftdm_test_flag(ftdmchan, FTDM_CHANNEL_IN_ALARM) && + ftdm_test_flag(ftdmchan->span, FTDM_SPAN_PWR_SAVING)) { + + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) ftdmchan->span->signal_data; + + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "Requesting Line activation\n"); + sngisdn_set_flag(sngisdn_info, FLAG_ACTIVATING); + sngisdn_wake_up_phy(ftdmchan->span); + ftdm_sched_timer(signal_data->sched, "timer_t3", signal_data->timer_t3*1000, sngisdn_t3_timeout, (void*) sngisdn_info, NULL); + } else { + sngisdn_snd_setup(ftdmchan); + } } break; case FTDM_CHANNEL_STATE_PROGRESS: @@ -592,7 +693,7 @@ static void ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdmchan) sngisdn_snd_release(ftdmchan, 0); if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_SIG_UP)) { - sng_isdn_set_avail_rate(ftdmchan->span, SNGISDN_AVAIL_DOWN); + sngisdn_set_avail_rate(ftdmchan->span, SNGISDN_AVAIL_DOWN); } } else { sngisdn_snd_disconnect(ftdmchan); @@ -747,7 +848,7 @@ static FIO_SPAN_SET_SIG_STATUS_FUNCTION(ftdm_sangoma_isdn_set_span_sig_status) static ftdm_status_t ftdm_sangoma_isdn_start(ftdm_span_t *span) { ftdm_log(FTDM_LOG_INFO,"Starting span %s:%u.\n",span->name,span->span_id); - if (sng_isdn_stack_start(span) != FTDM_SUCCESS) { + if (sngisdn_stack_start(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "Failed to start span %s\n", span->name); return FTDM_FAIL; } @@ -761,6 +862,12 @@ static ftdm_status_t ftdm_sangoma_isdn_start(ftdm_span_t *span) return FTDM_FAIL; } + /*start the dchan monitor thread*/ + if (ftdm_thread_create_detached(ftdm_sangoma_isdn_dchan_run, span) != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_CRIT,"Failed to start Sangoma ISDN d-channel Monitor Thread!\n"); + return FTDM_FAIL; + } + ftdm_log(FTDM_LOG_DEBUG,"Finished starting span %s\n", span->name); return FTDM_SUCCESS; } @@ -782,7 +889,7 @@ static ftdm_status_t ftdm_sangoma_isdn_stop(ftdm_span_t *span) ftdm_sleep(10); } - if (sng_isdn_stack_stop(span) != FTDM_SUCCESS) { + if (sngisdn_stack_stop(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "Failed to stop span %s\n", span->name); } @@ -834,7 +941,7 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_isdn_span_config) return FTDM_FAIL; } - if (sng_isdn_stack_cfg(span) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "Sangoma ISDN Stack configuration failed\n"); return FTDM_FAIL; } @@ -856,9 +963,8 @@ static FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(ftdm_sangoma_isdn_span_config) if (span->trunk_type == FTDM_TRUNK_BRI_PTMP || span->trunk_type == FTDM_TRUNK_BRI) { - - ftdm_set_flag(span, FTDM_SPAN_USE_AV_RATE); - sng_isdn_set_avail_rate(span, SNGISDN_AVAIL_PWR_SAVING); + + sngisdn_set_avail_rate(span, SNGISDN_AVAIL_PWR_SAVING); } /* Initialize scheduling context */ @@ -906,7 +1012,9 @@ static FIO_SIG_LOAD_FUNCTION(ftdm_sangoma_isdn_init) g_sngisdn_event_interface.sta.sng_q921_trc_ind = sngisdn_rcv_q921_trace; g_sngisdn_event_interface.sta.sng_q931_sta_ind = sngisdn_rcv_q931_ind; g_sngisdn_event_interface.sta.sng_q931_trc_ind = sngisdn_rcv_q931_trace; - g_sngisdn_event_interface.sta.sng_cc_sta_ind = sngisdn_rcv_cc_ind; + g_sngisdn_event_interface.sta.sng_cc_sta_ind = sngisdn_rcv_cc_ind; + + g_sngisdn_event_interface.io.sng_data_req = sngisdn_rcv_data_req; for(i=1;i<=MAX_VARIANTS;i++) { ftdm_mutex_create(&g_sngisdn_data.ccs[i].mutex); @@ -914,7 +1022,7 @@ static FIO_SIG_LOAD_FUNCTION(ftdm_sangoma_isdn_init) /* initalize sng_isdn library */ - ftdm_assert_return(!sng_isdn_init(&g_sngisdn_event_interface), FTDM_FAIL, "Failed to initialize stack\n"); + ftdm_assert_return(!sng_isdn_init(&g_sngisdn_event_interface), FTDM_FAIL, "Failed to initialize stack\n"); return FTDM_SUCCESS; } @@ -968,11 +1076,11 @@ static FIO_API_FUNCTION(ftdm_sangoma_isdn_api) goto done; } if (!strcasecmp(trace_opt, "q921")) { - sng_isdn_activate_trace(span, SNGISDN_TRACE_Q921); + sngisdn_activate_trace(span, SNGISDN_TRACE_Q921); } else if (!strcasecmp(trace_opt, "q931")) { - sng_isdn_activate_trace(span, SNGISDN_TRACE_Q931); + sngisdn_activate_trace(span, SNGISDN_TRACE_Q931); } else if (!strcasecmp(trace_opt, "disable")) { - sng_isdn_activate_trace(span, SNGISDN_TRACE_DISABLE); + sngisdn_activate_trace(span, SNGISDN_TRACE_DISABLE); } else { stream->write_function(stream, "-ERR invalid trace option \n"); } 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 e84392e22a..75262c9627 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 @@ -74,6 +74,7 @@ typedef enum { FLAG_DELAYED_REL = (1 << 7), FLAG_SENT_PROCEED = (1 << 8), FLAG_SEND_DISC = (1 << 9), + FLAG_ACTIVATING = (1 << 10), /* Used for BRI only, flag is set after we request line CONNECTED */ } sngisdn_flag_t; @@ -167,6 +168,7 @@ typedef struct sngisdn_chan_data { /* Span specific data */ typedef struct sngisdn_span_data { ftdm_span_t *ftdm_span; + ftdm_channel_t *dchan; uint8_t link_id; uint8_t switchtype; uint8_t signalling; /* SNGISDN_SIGNALING_CPE or SNGISDN_SIGNALING_NET */ @@ -181,6 +183,7 @@ typedef struct sngisdn_span_data { uint8_t facility; int8_t facility_timeout; uint8_t num_local_numbers; + uint8_t timer_t3; char* local_numbers[SNGISDN_NUM_LOCAL_NUMBERS]; ftdm_sched_t *sched; ftdm_queue_t *event_queue; @@ -275,7 +278,7 @@ void stack_hdr_init(Header *hdr); void stack_pst_init(Pst *pst); FT_DECLARE_INLINE(ftdm_status_t) get_ftdmchan_by_spInstId(int16_t cc_id, uint32_t spInstId, sngisdn_chan_data_t **sngisdn_data); FT_DECLARE_INLINE(ftdm_status_t) get_ftdmchan_by_suInstId(int16_t cc_id, uint32_t suInstId, sngisdn_chan_data_t **sngisdn_data); -FT_DECLARE_INLINE(ftdm_status_t) sng_isdn_set_avail_rate(ftdm_span_t *ftdmspan, sngisdn_avail_t avail); +FT_DECLARE_INLINE(ftdm_status_t) sngisdn_set_avail_rate(ftdm_span_t *ftdmspan, sngisdn_avail_t avail); /* Outbound Call Control functions */ void sngisdn_snd_setup(ftdm_channel_t *ftdmchan); @@ -290,25 +293,28 @@ void sngisdn_snd_reset(ftdm_channel_t *ftdmchan); void sngisdn_snd_con_complete(ftdm_channel_t *ftdmchan); void sngisdn_snd_info_req(ftdm_channel_t *ftdmchan); void sngisdn_snd_status_enq(ftdm_channel_t *ftdmchan); +void sngisdn_snd_data(ftdm_span_t *span, uint8_t *data, ftdm_size_t len); +void sngisdn_snd_event(ftdm_span_t *span, sng_isdn_l1_event_t l1_event); /* Inbound Call Control functions */ -void sngisdn_rcv_con_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, ConEvnt *conEvnt, int16_t dChan, uint8_t ces); -void sngisdn_rcv_con_cfm (int16_t suId, uint32_t suInstId, uint32_t spInstId, CnStEvnt *cnStEvnt, int16_t dChan, uint8_t ces); -void sngisdn_rcv_cnst_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, CnStEvnt *cnStEvnt, uint8_t evntType, int16_t dChan, uint8_t ces); -void sngisdn_rcv_disc_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, DiscEvnt *discEvnt); -void sngisdn_rcv_rel_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, RelEvnt *relEvnt); -void sngisdn_rcv_dat_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, InfoEvnt *infoEvnt); -void sngisdn_rcv_sshl_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, SsHlEvnt *ssHlEvnt, uint8_t action); -void sngisdn_rcv_sshl_cfm (int16_t suId, uint32_t suInstId, uint32_t spInstId, SsHlEvnt *ssHlEvnt, uint8_t action); -void sngisdn_rcv_rmrt_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, RmRtEvnt *rmRtEvnt, uint8_t action); -void sngisdn_rcv_rmrt_cfm (int16_t suId, uint32_t suInstId, uint32_t spInstId, RmRtEvnt *rmRtEvnt, uint8_t action); -void sngisdn_rcv_flc_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, StaEvnt *staEvnt); -void sngisdn_rcv_fac_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, FacEvnt *facEvnt, uint8_t evntType, int16_t dChan, uint8_t ces); -void sngisdn_rcv_sta_cfm ( int16_t suId, uint32_t suInstId, uint32_t spInstId, StaEvnt *staEvnt); -void sngisdn_rcv_srv_ind ( int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces); -void sngisdn_rcv_srv_cfm ( int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces); -void sngisdn_rcv_rst_cfm ( int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType); -void sngisdn_rcv_rst_ind ( int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType); +void sngisdn_rcv_con_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, ConEvnt *conEvnt, int16_t dChan, uint8_t ces); +void sngisdn_rcv_con_cfm(int16_t suId, uint32_t suInstId, uint32_t spInstId, CnStEvnt *cnStEvnt, int16_t dChan, uint8_t ces); +void sngisdn_rcv_cnst_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, CnStEvnt *cnStEvnt, uint8_t evntType, int16_t dChan, uint8_t ces); +void sngisdn_rcv_disc_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, DiscEvnt *discEvnt); +void sngisdn_rcv_rel_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, RelEvnt *relEvnt); +void sngisdn_rcv_dat_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, InfoEvnt *infoEvnt); +void sngisdn_rcv_sshl_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, SsHlEvnt *ssHlEvnt, uint8_t action); +void sngisdn_rcv_sshl_cfm(int16_t suId, uint32_t suInstId, uint32_t spInstId, SsHlEvnt *ssHlEvnt, uint8_t action); +void sngisdn_rcv_rmrt_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, RmRtEvnt *rmRtEvnt, uint8_t action); +void sngisdn_rcv_rmrt_cfm(int16_t suId, uint32_t suInstId, uint32_t spInstId, RmRtEvnt *rmRtEvnt, uint8_t action); +void sngisdn_rcv_flc_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, StaEvnt *staEvnt); +void sngisdn_rcv_fac_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, FacEvnt *facEvnt, uint8_t evntType, int16_t dChan, uint8_t ces); +void sngisdn_rcv_sta_cfm(int16_t suId, uint32_t suInstId, uint32_t spInstId, StaEvnt *staEvnt); +void sngisdn_rcv_srv_ind(int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces); +void sngisdn_rcv_srv_cfm(int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces); +void sngisdn_rcv_rst_cfm(int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType); +void sngisdn_rcv_rst_ind(int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType); +int16_t sngisdn_rcv_data_req(uint16_t spId, uint8_t *buff, uint32_t length); void sngisdn_process_con_ind (sngisdn_event_data_t *sngisdn_event); void sngisdn_process_con_cfm (sngisdn_event_data_t *sngisdn_event); @@ -364,15 +370,18 @@ static __inline__ void sngisdn_set_flag(sngisdn_chan_data_t *sngisdn_info, sngis void handle_sng_log(uint8_t level, char *fmt,...); void sngisdn_set_span_sig_status(ftdm_span_t *ftdmspan, ftdm_signaling_status_t status); +void sngisdn_delayed_setup(void* p_sngisdn_info); void sngisdn_delayed_release(void* p_sngisdn_info); void sngisdn_delayed_connect(void* p_sngisdn_info); void sngisdn_delayed_disconnect(void* p_sngisdn_info); void sngisdn_facility_timeout(void* p_sngisdn_info); +void sngisdn_t3_timeout(void* p_sngisdn_info); /* Stack management functions */ -ftdm_status_t sng_isdn_stack_cfg(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_start(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_stop(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_cfg(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_start(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_stop(ftdm_span_t *span); +ftdm_status_t sngisdn_wake_up_phy(ftdm_span_t *span); void sngisdn_print_phy_stats(ftdm_stream_handle_t *stream, ftdm_span_t *span); void sngisdn_print_spans(ftdm_stream_handle_t *stream); 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 64d7a2403f..43e35b6dfd 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 @@ -56,9 +56,11 @@ ftdm_status_t add_local_number(const char* val, ftdm_span_t *span) ftdm_status_t parse_switchtype(const char* switch_name, ftdm_span_t *span) { unsigned i; - + ftdm_iterator_t *chaniter = NULL; + ftdm_iterator_t *curr = NULL; sngisdn_dchan_data_t *dchan_data; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; + switch(span->trunk_type) { case FTDM_TRUNK_T1: if (!strcasecmp(switch_name, "ni2") || @@ -122,9 +124,9 @@ ftdm_status_t parse_switchtype(const char* switch_name, ftdm_span_t *span) /* add this span to its ent_cc */ signal_data->cc_id = i; - /* create a new dchan */ /* for NFAS - no-dchan on b-channels only links */ + /* create a new dchan */ /* for NFAS - no-dchan on b-channels-only links */ g_sngisdn_data.num_dchan++; - signal_data->dchan_id = g_sngisdn_data.num_dchan; + signal_data->dchan_id = g_sngisdn_data.num_dchan; dchan_data = &g_sngisdn_data.dchans[signal_data->dchan_id]; dchan_data->num_spans++; @@ -136,16 +138,23 @@ ftdm_status_t parse_switchtype(const char* switch_name, ftdm_span_t *span) ftdm_log(FTDM_LOG_DEBUG, "%s: cc_id:%d dchan_id:%d span_id:%d\n", span->name, signal_data->cc_id, signal_data->dchan_id, signal_data->span_id); - /* Add the channels to the span */ - for (i=1;i<=span->chan_count;i++) { - unsigned chan_id; - ftdm_channel_t *ftdmchan = span->channels[i]; - /* NFAS is not supported on E1, so span_id will always be 1 for E1 so this will work for E1 as well */ - chan_id = ((signal_data->span_id-1)*NUM_T1_CHANNELS_PER_SPAN)+ftdmchan->physical_chan_id; - dchan_data->channels[chan_id] = (sngisdn_chan_data_t*)ftdmchan->call_data; - dchan_data->num_chans++; + + chaniter = ftdm_span_get_chan_iterator(span, NULL); + for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) { + int32_t chan_id; + ftdm_channel_t *ftdmchan = (ftdm_channel_t*)ftdm_iterator_current(curr); + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921) { + /* set the d-channel */ + signal_data->dchan = ftdmchan; + } else { + /* Add the channels to the span */ + /* NFAS is not supported on E1, so span_id will always be 1 for E1 so this will work for E1 as well */ + chan_id = ((signal_data->span_id-1)*NUM_T1_CHANNELS_PER_SPAN)+ftdmchan->physical_chan_id; + dchan_data->channels[chan_id] = (sngisdn_chan_data_t*)ftdmchan->call_data; + dchan_data->num_chans++; + } } - + ftdm_iterator_free(chaniter); return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c index bb46fb7fba..eabaa7affc 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c @@ -38,52 +38,52 @@ extern ftdm_sngisdn_data_t g_sngisdn_data; uint8_t sng_isdn_stack_switchtype(sngisdn_switchtype_t switchtype); -ftdm_status_t sng_isdn_cfg_phy(ftdm_span_t *span); -ftdm_status_t sng_isdn_cfg_q921(ftdm_span_t *span); -ftdm_status_t sng_isdn_cfg_q931(ftdm_span_t *span); -ftdm_status_t sng_isdn_cfg_cc(ftdm_span_t *span); +ftdm_status_t sngisdn_cfg_phy(ftdm_span_t *span); +ftdm_status_t sngisdn_cfg_q921(ftdm_span_t *span); +ftdm_status_t sngisdn_cfg_q931(ftdm_span_t *span); +ftdm_status_t sngisdn_cfg_cc(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_cfg_phy_gen(void); -ftdm_status_t sng_isdn_stack_cfg_q921_gen(void); -ftdm_status_t sng_isdn_stack_cfg_q931_gen(void); -ftdm_status_t sng_isdn_stack_cfg_cc_gen(void); +ftdm_status_t sngisdn_stack_cfg_phy_gen(void); +ftdm_status_t sngisdn_stack_cfg_q921_gen(void); +ftdm_status_t sngisdn_stack_cfg_q931_gen(void); +ftdm_status_t sngisdn_stack_cfg_cc_gen(void); -ftdm_status_t sng_isdn_stack_cfg_phy_psap(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_cfg_q921_msap(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_cfg_q921_dlsap(ftdm_span_t *span, uint8_t management); -ftdm_status_t sng_isdn_stack_cfg_q931_tsap(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_cfg_q931_dlsap(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_cfg_q931_lce(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_cfg_phy_psap(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_cfg_q921_msap(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_cfg_q921_dlsap(ftdm_span_t *span, uint8_t management); +ftdm_status_t sngisdn_stack_cfg_q931_tsap(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_cfg_q931_dlsap(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_cfg_q931_lce(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_cfg_cc_sap(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_cfg_cc_sap(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_cfg(ftdm_span_t *span) +ftdm_status_t sngisdn_stack_cfg(ftdm_span_t *span) { sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; if (!g_sngisdn_data.gen_config_done) { g_sngisdn_data.gen_config_done = 1; ftdm_log(FTDM_LOG_DEBUG, "Starting general stack configuration\n"); - if(sng_isdn_stack_cfg_phy_gen()!= FTDM_SUCCESS) { + if(sngisdn_stack_cfg_phy_gen()!= FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "Failed general physical configuration\n"); return FTDM_FAIL; } ftdm_log(FTDM_LOG_DEBUG, "General stack physical done\n"); - if(sng_isdn_stack_cfg_q921_gen()!= FTDM_SUCCESS) { + if(sngisdn_stack_cfg_q921_gen()!= FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "Failed general q921 configuration\n"); return FTDM_FAIL; } ftdm_log(FTDM_LOG_DEBUG, "General stack q921 done\n"); - if(sng_isdn_stack_cfg_q931_gen()!= FTDM_SUCCESS) { + if(sngisdn_stack_cfg_q931_gen()!= FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "Failed general q921 configuration\n"); return FTDM_FAIL; } ftdm_log(FTDM_LOG_DEBUG, "General stack q931 done\n"); - if(sng_isdn_stack_cfg_cc_gen()!= FTDM_SUCCESS) { + if(sngisdn_stack_cfg_cc_gen()!= FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "Failed general CC configuration\n"); return FTDM_FAIL; } @@ -92,26 +92,26 @@ ftdm_status_t sng_isdn_stack_cfg(ftdm_span_t *span) } /* TODO: for NFAS, should only call these function for spans with d-chans */ - if (sng_isdn_stack_cfg_phy_psap(span) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg_phy_psap(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "%s:phy_psap configuration failed\n", span->name); return FTDM_FAIL; } ftdm_log(FTDM_LOG_DEBUG, "%s:phy_psap configuration done\n", span->name); - if (sng_isdn_stack_cfg_q921_msap(span) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg_q921_msap(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "%s:q921_msap configuration failed\n", span->name); return FTDM_FAIL; } ftdm_log(FTDM_LOG_DEBUG, "%s:q921_msap configuration done\n", span->name); - if (sng_isdn_stack_cfg_q921_dlsap(span, 0) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg_q921_dlsap(span, 0) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "%s:q921_dlsap configuration failed\n", span->name); return FTDM_FAIL; } ftdm_log(FTDM_LOG_DEBUG, "%s:q921_dlsap configuration done\n", span->name); if (span->trunk_type == FTDM_TRUNK_BRI_PTMP) { - if (sng_isdn_stack_cfg_q921_dlsap(span, 1) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg_q921_dlsap(span, 1) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "%s:q921_dlsap management configuration failed\n", span->name); return FTDM_FAIL; } @@ -119,13 +119,13 @@ ftdm_status_t sng_isdn_stack_cfg(ftdm_span_t *span) } - if (sng_isdn_stack_cfg_q931_dlsap(span) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg_q931_dlsap(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "%s:q931_dlsap configuration failed\n", span->name); return FTDM_FAIL; } ftdm_log(FTDM_LOG_DEBUG, "%s:q931_dlsap configuration done\n", span->name); - if (sng_isdn_stack_cfg_q931_lce(span) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg_q931_lce(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "%s:q931_lce configuration failed\n", span->name); return FTDM_FAIL; } @@ -134,13 +134,13 @@ ftdm_status_t sng_isdn_stack_cfg(ftdm_span_t *span) if (!g_sngisdn_data.ccs[signal_data->cc_id].config_done) { g_sngisdn_data.ccs[signal_data->cc_id].config_done = 1; /* if BRI, need to configure dlsap_mgmt */ - if (sng_isdn_stack_cfg_q931_tsap(span) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg_q931_tsap(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "%s:q931_tsap configuration failed\n", span->name); return FTDM_FAIL; } ftdm_log(FTDM_LOG_DEBUG, "%s:q931_tsap configuration done\n", span->name); - if (sng_isdn_stack_cfg_cc_sap(span) != FTDM_SUCCESS) { + if (sngisdn_stack_cfg_cc_sap(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "%s:cc_sap configuration failed\n", span->name); return FTDM_FAIL; } @@ -153,7 +153,7 @@ ftdm_status_t sng_isdn_stack_cfg(ftdm_span_t *span) -ftdm_status_t sng_isdn_stack_cfg_phy_gen(void) +ftdm_status_t sngisdn_stack_cfg_phy_gen(void) { /*local variables*/ L1Mngmt cfg; /*configuration structure*/ @@ -191,14 +191,11 @@ ftdm_status_t sng_isdn_stack_cfg_phy_gen(void) return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_stack_cfg_phy_psap(ftdm_span_t *span) -{ - ftdm_iterator_t *chaniter; - ftdm_iterator_t *curr; +ftdm_status_t sngisdn_stack_cfg_phy_psap(ftdm_span_t *span) +{ L1Mngmt cfg; Pst pst; - int32_t d_channel_fd = -1; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; /* initalize the post structure */ @@ -220,25 +217,13 @@ ftdm_status_t sng_isdn_stack_cfg_phy_psap(ftdm_span_t *span) cfg.hdr.elmId.elmnt = STPSAP; cfg.hdr.elmId.elmntInst1 = signal_data->link_id; - - - /* Find the d-channel */ - chaniter = ftdm_span_get_chan_iterator(span, NULL); - for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) { - ftdm_channel_t *ftdmchan = (ftdm_channel_t*)ftdm_iterator_current(curr); - if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921) { - d_channel_fd = (int32_t)ftdmchan->sockfd; - break; - } - } - ftdm_iterator_free(chaniter); - - if(d_channel_fd < 0) { + + if (!signal_data->dchan) { ftdm_log(FTDM_LOG_ERROR, "%s:No d-channels specified\n", span->name); return FTDM_FAIL; - } - - cfg.t.cfg.s.l1PSAP.sockfd = d_channel_fd; + } + + cfg.t.cfg.s.l1PSAP.sockfd = (int32_t)signal_data->dchan->sockfd; switch(span->trunk_type) { case FTDM_TRUNK_E1: @@ -257,7 +242,7 @@ ftdm_status_t sng_isdn_stack_cfg_phy_psap(ftdm_span_t *span) return FTDM_FAIL; } cfg.t.cfg.s.l1PSAP.spId = signal_data->link_id; - + if (sng_isdn_phy_config(&pst, &cfg)) { return FTDM_FAIL; } @@ -265,7 +250,7 @@ ftdm_status_t sng_isdn_stack_cfg_phy_psap(ftdm_span_t *span) } -ftdm_status_t sng_isdn_stack_cfg_q921_gen(void) +ftdm_status_t sngisdn_stack_cfg_q921_gen(void) { BdMngmt cfg; Pst pst; @@ -308,7 +293,7 @@ ftdm_status_t sng_isdn_stack_cfg_q921_gen(void) return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_stack_cfg_q921_msap(ftdm_span_t *span) +ftdm_status_t sngisdn_stack_cfg_q921_msap(ftdm_span_t *span) { BdMngmt cfg; Pst pst; @@ -401,7 +386,7 @@ ftdm_status_t sng_isdn_stack_cfg_q921_msap(ftdm_span_t *span) return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_stack_cfg_q921_dlsap(ftdm_span_t *span, uint8_t management) +ftdm_status_t sngisdn_stack_cfg_q921_dlsap(ftdm_span_t *span, uint8_t management) { BdMngmt cfg; Pst pst; @@ -483,7 +468,7 @@ ftdm_status_t sng_isdn_stack_cfg_q921_dlsap(ftdm_span_t *span, uint8_t managemen return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_stack_cfg_q931_gen(void) +ftdm_status_t sngisdn_stack_cfg_q931_gen(void) { InMngmt cfg; Pst pst; @@ -538,7 +523,7 @@ ftdm_status_t sng_isdn_stack_cfg_q931_gen(void) } /* Link between CC and q931 */ -ftdm_status_t sng_isdn_stack_cfg_q931_tsap(ftdm_span_t *span) +ftdm_status_t sngisdn_stack_cfg_q931_tsap(ftdm_span_t *span) { InMngmt cfg; Pst pst; @@ -601,7 +586,7 @@ ftdm_status_t sng_isdn_stack_cfg_q931_tsap(ftdm_span_t *span) return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_stack_cfg_q931_dlsap(ftdm_span_t *span) +ftdm_status_t sngisdn_stack_cfg_q931_dlsap(ftdm_span_t *span) { InMngmt cfg; Pst pst; @@ -851,7 +836,7 @@ ftdm_status_t sng_isdn_stack_cfg_q931_dlsap(ftdm_span_t *span) return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_stack_cfg_q931_lce(ftdm_span_t *span) +ftdm_status_t sngisdn_stack_cfg_q931_lce(ftdm_span_t *span) { InMngmt cfg; Pst pst; @@ -927,7 +912,7 @@ ftdm_status_t sng_isdn_stack_cfg_q931_lce(ftdm_span_t *span) } -ftdm_status_t sng_isdn_stack_cfg_cc_gen(void) +ftdm_status_t sngisdn_stack_cfg_cc_gen(void) { CcMngmt cfg; Pst pst; @@ -966,7 +951,7 @@ ftdm_status_t sng_isdn_stack_cfg_cc_gen(void) } -ftdm_status_t sng_isdn_stack_cfg_cc_sap(ftdm_span_t *span) +ftdm_status_t sngisdn_stack_cfg_cc_sap(ftdm_span_t *span) { CcMngmt cfg; Pst pst; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c index 27c16c2a51..d8e6c8e00d 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c @@ -37,27 +37,27 @@ void stack_resp_hdr_init(Header *hdr); -ftdm_status_t sng_isdn_activate_phy(ftdm_span_t *span); -ftdm_status_t sng_isdn_deactivate_phy(ftdm_span_t *span); +ftdm_status_t sngisdn_activate_phy(ftdm_span_t *span); +ftdm_status_t sngisdn_deactivate_phy(ftdm_span_t *span); -ftdm_status_t sng_isdn_activate_cc(ftdm_span_t *span); -ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt); +ftdm_status_t sngisdn_activate_cc(ftdm_span_t *span); +ftdm_status_t sngisdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt); -ftdm_status_t sng_isdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction); -ftdm_status_t sng_isdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction); +ftdm_status_t sngisdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction); +ftdm_status_t sngisdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction); extern ftdm_sngisdn_data_t g_sngisdn_data; -ftdm_status_t sng_isdn_stack_stop(ftdm_span_t *span); +ftdm_status_t sngisdn_stack_stop(ftdm_span_t *span); -ftdm_status_t sng_isdn_stack_start(ftdm_span_t *span) +ftdm_status_t sngisdn_stack_start(ftdm_span_t *span) { sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; - if (sng_isdn_cntrl_q921(span, ABND_ENA, NOTUSED) != FTDM_SUCCESS) { + if (sngisdn_cntrl_q921(span, ABND_ENA, NOTUSED) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack q921\n", span->name); return FTDM_FAIL; } @@ -72,7 +72,7 @@ ftdm_status_t sng_isdn_stack_start(ftdm_span_t *span) ftdm_log(FTDM_LOG_DEBUG, "%s:Stack q921 activated\n", span->name); if (!g_sngisdn_data.ccs[signal_data->cc_id].activation_done) { g_sngisdn_data.ccs[signal_data->cc_id].activation_done = 1; - if (sng_isdn_activate_cc(span) != FTDM_SUCCESS) { + if (sngisdn_activate_cc(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack CC\n", span->name); return FTDM_FAIL; } @@ -80,7 +80,7 @@ ftdm_status_t sng_isdn_stack_start(ftdm_span_t *span) } - if (sng_isdn_cntrl_q931(span, ABND_ENA, SAELMNT) != FTDM_SUCCESS) { + if (sngisdn_cntrl_q931(span, ABND_ENA, SAELMNT) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack q931\n", span->name); return FTDM_FAIL; } @@ -90,20 +90,20 @@ ftdm_status_t sng_isdn_stack_start(ftdm_span_t *span) return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_stack_stop(ftdm_span_t *span) +ftdm_status_t sngisdn_stack_stop(ftdm_span_t *span) { /* Stop L1 first, so we do not receive any more frames */ - if (sng_isdn_deactivate_phy(span) != FTDM_SUCCESS) { + if (sngisdn_deactivate_phy(span) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack phy\n", span->name); return FTDM_FAIL; } - if (sng_isdn_cntrl_q931(span, AUBND_DIS, SAELMNT) != FTDM_SUCCESS) { + if (sngisdn_cntrl_q931(span, AUBND_DIS, SAELMNT) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack q931\n", span->name); return FTDM_FAIL; } - if (sng_isdn_cntrl_q921(span, AUBND_DIS, SAELMNT) != FTDM_SUCCESS) { + if (sngisdn_cntrl_q921(span, AUBND_DIS, SAELMNT) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack q921\n", span->name); return FTDM_FAIL; } @@ -113,7 +113,7 @@ ftdm_status_t sng_isdn_stack_stop(ftdm_span_t *span) } -ftdm_status_t sng_isdn_activate_phy(ftdm_span_t *span) +ftdm_status_t sngisdn_activate_phy(ftdm_span_t *span) { /* There is no need to start phy, as it will Q921 will send a activate request to phy when it starts */ @@ -121,7 +121,7 @@ ftdm_status_t sng_isdn_activate_phy(ftdm_span_t *span) return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_deactivate_phy(ftdm_span_t *span) +ftdm_status_t sngisdn_deactivate_phy(ftdm_span_t *span) { L1Mngmt cntrl; Pst pst; @@ -155,8 +155,41 @@ ftdm_status_t sng_isdn_deactivate_phy(ftdm_span_t *span) return FTDM_SUCCESS; } +ftdm_status_t sngisdn_wake_up_phy(ftdm_span_t *span) +{ + L1Mngmt cntrl; + Pst pst; -ftdm_status_t sng_isdn_activate_cc(ftdm_span_t *span) + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; + + /* initalize the post structure */ + stack_pst_init(&pst); + + /* insert the destination Entity */ + pst.dstEnt = ENTL1; + + /* initalize the control structure */ + memset(&cntrl, 0, sizeof(cntrl)); + + /* initalize the control header */ + stack_hdr_init(&cntrl.hdr); + + cntrl.hdr.msgType = TCNTRL; /* configuration */ + cntrl.hdr.entId.ent = ENTL1; /* entity */ + cntrl.hdr.entId.inst = S_INST; /* instance */ + cntrl.hdr.elmId.elmnt = STTSAP; /* SAP Specific cntrl */ + + cntrl.t.cntrl.action = AENA; + cntrl.t.cntrl.subAction = SAELMNT; + cntrl.t.cntrl.sapId = signal_data->link_id; + + if (sng_isdn_phy_cntrl(&pst, &cntrl)) { + return FTDM_FAIL; + } + return FTDM_SUCCESS; +} + +ftdm_status_t sngisdn_activate_cc(ftdm_span_t *span) { CcMngmt cntrl; Pst pst; @@ -190,7 +223,7 @@ ftdm_status_t sng_isdn_activate_cc(ftdm_span_t *span) return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt) +ftdm_status_t sngisdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt) { sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; switch (trace_opt) { @@ -199,7 +232,7 @@ ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t tra ftdm_log(FTDM_LOG_INFO, "s%d Disabling q921 trace\n", signal_data->link_id); sngisdn_clear_trace_flag(signal_data, SNGISDN_TRACE_Q921); - if (sng_isdn_cntrl_q921(span, ADISIMM, SATRC) != FTDM_SUCCESS) { + if (sngisdn_cntrl_q921(span, ADISIMM, SATRC) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "s%d Failed to disable q921 trace\n"); } } @@ -207,7 +240,7 @@ ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t tra ftdm_log(FTDM_LOG_INFO, "s%d Disabling q931 trace\n", signal_data->link_id); sngisdn_clear_trace_flag(signal_data, SNGISDN_TRACE_Q931); - if (sng_isdn_cntrl_q931(span, ADISIMM, SATRC) != FTDM_SUCCESS) { + if (sngisdn_cntrl_q931(span, ADISIMM, SATRC) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "s%d Failed to disable q931 trace\n"); } } @@ -217,7 +250,7 @@ ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t tra ftdm_log(FTDM_LOG_INFO, "s%d Enabling q921 trace\n", signal_data->link_id); sngisdn_set_trace_flag(signal_data, SNGISDN_TRACE_Q921); - if (sng_isdn_cntrl_q921(span, AENA, SATRC) != FTDM_SUCCESS) { + if (sngisdn_cntrl_q921(span, AENA, SATRC) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "s%d Failed to enable q921 trace\n"); } } @@ -227,7 +260,7 @@ ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t tra ftdm_log(FTDM_LOG_INFO, "s%d Enabling q931 trace\n", signal_data->link_id); sngisdn_set_trace_flag(signal_data, SNGISDN_TRACE_Q931); - if (sng_isdn_cntrl_q931(span, AENA, SATRC) != FTDM_SUCCESS) { + if (sngisdn_cntrl_q931(span, AENA, SATRC) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "s%d Failed to enable q931 trace\n"); } } @@ -237,7 +270,7 @@ ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t tra } -ftdm_status_t sng_isdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction) +ftdm_status_t sngisdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction) { InMngmt cntrl; Pst pst; @@ -276,7 +309,7 @@ ftdm_status_t sng_isdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t sub } -ftdm_status_t sng_isdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction) +ftdm_status_t sngisdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction) { BdMngmt cntrl; Pst pst; 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 7ca408538a..37613cc33d 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 @@ -539,7 +539,7 @@ void sngisdn_process_rel_ind (sngisdn_event_data_t *sngisdn_event) case FTDM_CHANNEL_STATE_DIALING: /* Remote side rejected our SETUP message on outbound call */ if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_SIG_UP)) { - sng_isdn_set_avail_rate(ftdmchan->span, SNGISDN_AVAIL_DOWN); + sngisdn_set_avail_rate(ftdmchan->span, SNGISDN_AVAIL_DOWN); } /* fall-through */ case FTDM_CHANNEL_STATE_PROGRESS: diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c index 3284d54165..bf44cb2e0a 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c @@ -600,6 +600,17 @@ void sngisdn_snd_release(ftdm_channel_t *ftdmchan, uint8_t glare) return; } +void sngisdn_snd_data(ftdm_span_t *span, uint8_t *data, ftdm_size_t len) +{ + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; + sng_isdn_data_ind(signal_data->link_id, data, len); +} + +void sngisdn_snd_event(ftdm_span_t *span, sng_isdn_l1_event_t l1_event) +{ + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; + sng_isdn_event_ind(signal_data->link_id, l1_event); +} /* For Emacs: diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c index 5580f3a950..e7ebc8f20b 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c @@ -736,7 +736,7 @@ void sngisdn_rcv_q931_ind(InMngmt *status) DECODE_LCM_CAUSE(status->t.usta.alarm.cause), status->t.usta.alarm.cause); sngisdn_set_span_sig_status(ftdmspan, FTDM_SIG_STATE_UP); - sng_isdn_set_avail_rate(ftdmspan, SNGISDN_AVAIL_UP); + sngisdn_set_avail_rate(ftdmspan, SNGISDN_AVAIL_UP); } else { ftdm_log(FTDM_LOG_WARNING, "[SNGISDN Q931] s%d: %s: %s(%d): %s(%d)\n", status->t.usta.suId, @@ -745,7 +745,7 @@ void sngisdn_rcv_q931_ind(InMngmt *status) DECODE_LCM_CAUSE(status->t.usta.alarm.cause), status->t.usta.alarm.cause); sngisdn_set_span_sig_status(ftdmspan, FTDM_SIG_STATE_DOWN); - sng_isdn_set_avail_rate(ftdmspan, SNGISDN_AVAIL_PWR_SAVING); + sngisdn_set_avail_rate(ftdmspan, SNGISDN_AVAIL_PWR_SAVING); } } break; @@ -866,6 +866,26 @@ end_of_trace: return; } +int16_t sngisdn_rcv_data_req(uint16_t spId, uint8_t *buff, uint32_t length) +{ + ftdm_status_t status; + ftdm_wait_flag_t flags = FTDM_WRITE; + sngisdn_span_data_t *signal_data = g_sngisdn_data.spans[spId]; + ftdm_assert(signal_data, "Received Data request on unconfigured span\n"); + + status = signal_data->dchan->fio->wait(signal_data->dchan, &flags, 10); + if (status != FTDM_SUCCESS) { + ftdm_log_chan_msg(signal_data->dchan, FTDM_LOG_WARNING, "transmit timed-out\n"); + return -1; + } + status = signal_data->dchan->fio->write(signal_data->dchan, buff, (ftdm_size_t*)&length); + if (status != FTDM_SUCCESS) { + ftdm_log_chan_msg(signal_data->dchan, FTDM_LOG_CRIT, "Failed to transmit frame\n"); + return -1; + } + return 0; +} + void sngisdn_rcv_sng_assert(char *message) { ftdm_assert(0, message); 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 f54f7db61c..a418103bed 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 @@ -137,7 +137,7 @@ FT_DECLARE_INLINE(ftdm_status_t) get_ftdmchan_by_spInstId(int16_t cc_id, uint32_ return FTDM_SUCCESS; } -ftdm_status_t sng_isdn_set_avail_rate(ftdm_span_t *span, sngisdn_avail_t avail) +ftdm_status_t sngisdn_set_avail_rate(ftdm_span_t *span, sngisdn_avail_t avail) { if (span->trunk_type == FTDM_TRUNK_BRI || @@ -382,6 +382,39 @@ ftdm_status_t cpy_calling_name_from_user(ConEvnt *conEvnt, ftdm_channel_t *ftdmc return FTDM_SUCCESS; } +void sngisdn_t3_timeout(void* p_sngisdn_info) +{ + sngisdn_chan_data_t *sngisdn_info = (sngisdn_chan_data_t*)p_sngisdn_info; + ftdm_channel_t *ftdmchan = sngisdn_info->ftdmchan; + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) ftdmchan->span->signal_data; + + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Timer T3 expired (suId:%d suInstId:%u spInstId:%u)\n", + signal_data->cc_id, sngisdn_info->glare.spInstId, sngisdn_info->glare.suInstId); + ftdm_mutex_lock(ftdmchan->mutex); + if (ftdm_test_flag(sngisdn_info, FLAG_ACTIVATING)){ + /* PHY layer timed-out, need to clear the call */ + ftdm_log_chan(ftdmchan, FTDM_LOG_INFO, "Failed to Wake-Up line (suId:%d suInstId:%u spInstId:%u)\n", + signal_data->cc_id, sngisdn_info->glare.spInstId, sngisdn_info->glare.suInstId); + + ftdmchan->caller_data.hangup_cause = FTDM_CAUSE_NO_ROUTE_DESTINATION; + ftdm_clear_flag(sngisdn_info, FLAG_ACTIVATING); + ftdm_set_flag(sngisdn_info, FLAG_LOCAL_ABORT); + ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING); + } + ftdm_mutex_unlock(ftdmchan->mutex); +} + +void sngisdn_delayed_setup(void* p_sngisdn_info) +{ + sngisdn_chan_data_t *sngisdn_info = (sngisdn_chan_data_t*)p_sngisdn_info; + ftdm_channel_t *ftdmchan = sngisdn_info->ftdmchan; + + ftdm_mutex_lock(ftdmchan->mutex); + sngisdn_snd_setup(ftdmchan); + ftdm_mutex_unlock(ftdmchan->mutex); + return; +} + void sngisdn_delayed_release(void* p_sngisdn_info) { sngisdn_chan_data_t *sngisdn_info = (sngisdn_chan_data_t*)p_sngisdn_info; diff --git a/libs/freetdm/src/include/private/ftdm_core.h b/libs/freetdm/src/include/private/ftdm_core.h index 8bdbdd60f8..239eb4a3d9 100644 --- a/libs/freetdm/src/include/private/ftdm_core.h +++ b/libs/freetdm/src/include/private/ftdm_core.h @@ -222,6 +222,8 @@ extern "C" { #define ftdm_is_dtmf(key) ((key > 47 && key < 58) || (key > 64 && key < 69) || (key > 96 && key < 101) || key == 35 || key == 42 || key == 87 || key == 119) +#define FTDM_SPAN_IS_BRI(x) ((x)->trunk_type == FTDM_TRUNK_BRI || (x)->trunk_type == FTDM_TRUNK_BRI_PTMP) + /*! \brief Copy flags from one arbitrary object to another \command dest the object to copy the flags to diff --git a/libs/freetdm/src/include/private/ftdm_types.h b/libs/freetdm/src/include/private/ftdm_types.h index bddefd9be6..78ac8f63eb 100644 --- a/libs/freetdm/src/include/private/ftdm_types.h +++ b/libs/freetdm/src/include/private/ftdm_types.h @@ -176,10 +176,11 @@ typedef enum { FTDM_SPAN_USE_CHAN_QUEUE = (1 << 6), FTDM_SPAN_SUGGEST_CHAN_ID = (1 << 7), FTDM_SPAN_USE_AV_RATE = (1 << 8), + FTDM_SPAN_PWR_SAVING = (1 << 9), /* If you use this flag, you MUST call ftdm_span_trigger_signals to deliver the user signals * after having called ftdm_send_span_signal(), which with this flag it will just enqueue the signal * for later delivery */ - FTDM_SPAN_USE_SIGNALS_QUEUE = (1 << 9), + FTDM_SPAN_USE_SIGNALS_QUEUE = (1 << 10), } ftdm_span_flag_t; /*! \brief Channel supported features */ From 93aa30076b01be366f8f1c487b7b561f5bd7e074 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 10 Nov 2010 19:23:48 -0500 Subject: [PATCH 02/10] Fixed conflicts --- .../ftmod_sangoma_isdn_stack_cntrl.c | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c index 1714ac185c..d8e6c8e00d 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c @@ -113,40 +113,6 @@ ftdm_status_t sngisdn_stack_stop(ftdm_span_t *span) } -ftdm_status_t sngisdn_wake_up_phy(ftdm_span_t *span) -{ - L1Mngmt cntrl; - Pst pst; - - sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; - - /* initalize the post structure */ - stack_pst_init(&pst); - - /* insert the destination Entity */ - pst.dstEnt = ENTL1; - - /* initalize the control structure */ - memset(&cntrl, 0, sizeof(cntrl)); - - /* initalize the control header */ - stack_hdr_init(&cntrl.hdr); - - cntrl.hdr.msgType = TCNTRL; /* configuration */ - cntrl.hdr.entId.ent = ENTL1; /* entity */ - cntrl.hdr.entId.inst = S_INST; /* instance */ - cntrl.hdr.elmId.elmnt = STTSAP; /* SAP Specific cntrl */ - - cntrl.t.cntrl.action = AENA; - cntrl.t.cntrl.subAction = SAELMNT; - cntrl.t.cntrl.sapId = signal_data->link_id; - - if (sng_isdn_phy_cntrl(&pst, &cntrl)) { - return FTDM_FAIL; - } - return FTDM_SUCCESS; -} - ftdm_status_t sngisdn_activate_phy(ftdm_span_t *span) { From d0b6117325ded66fdbcb8a8c3630386e671675f9 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 11 Nov 2010 18:43:53 -0500 Subject: [PATCH 03/10] FIX for windows IO --- libs/freetdm/cyginstall.sh | 4 +-- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.c | 22 ++++++------ .../ftmod_sangoma_isdn_stack_out.c | 1 + .../ftmod_sangoma_isdn_stack_rcv.c | 34 +++++++++++++------ .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 3 +- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/libs/freetdm/cyginstall.sh b/libs/freetdm/cyginstall.sh index 9d486b7dce..311df939af 100644 --- a/libs/freetdm/cyginstall.sh +++ b/libs/freetdm/cyginstall.sh @@ -5,8 +5,8 @@ fsdir=../.. set -x cp Debug/mod/*.dll $fsdir/Debug/mod/ cp mod_freetdm/Debug/*.pdb $fsdir/Debug/mod/ -cp Debug/*.dll $fsdir/Debug/ -cp Debug/*.pdb $fsdir/Debug/ +cp Debug/*.dll $fsdir/Debug/mod/ +cp Debug/*.pdb $fsdir/Debug/mod/ #cp Debug/testsangomaboost.exe $fsdir/Debug/ echo "FRIENDLY REMINDER: RECOMPILE ftmod_wanpipe WHENEVER YOU INSTALL NEW DRIVERS" set +x 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 69743115fe..98b09e9305 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 @@ -52,10 +52,10 @@ static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_eve static void ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdmchan); static void ftdm_sangoma_isdn_process_stack_event (ftdm_span_t *span, sngisdn_event_data_t *sngisdn_event); -static ftdm_io_interface_t g_sngisdn_io_interface; -static sng_isdn_event_interface_t g_sngisdn_event_interface; +static ftdm_io_interface_t g_sngisdn_io_interface; +static sng_isdn_event_interface_t g_sngisdn_event_interface; -ftdm_sngisdn_data_t g_sngisdn_data; +ftdm_sngisdn_data_t g_sngisdn_data; extern ftdm_status_t sngisdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt); extern ftdm_status_t sngisdn_check_free_ids(void); @@ -248,6 +248,7 @@ static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_eve sngisdn_snd_event(span, SNG_L1EVENT_ALARM_OFF); if (FTDM_SPAN_IS_BRI(span)) { ftdm_channel_t *ftdmchan; + sngisdn_chan_data_t *sngisdn_info; ftdm_iterator_t *chaniter = NULL; ftdm_iterator_t *curr = NULL; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; @@ -255,7 +256,7 @@ static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_eve chaniter = ftdm_span_get_chan_iterator(span, NULL); for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) { ftdmchan = (ftdm_channel_t*)ftdm_iterator_current(curr); - sngisdn_chan_data_t *sngisdn_info = ftdmchan->call_data; + sngisdn_info = (sngisdn_chan_data_t*)ftdmchan->call_data; if (ftdm_test_flag(sngisdn_info, FLAG_ACTIVATING)) { ftdm_clear_flag(sngisdn_info, FLAG_ACTIVATING); @@ -277,8 +278,7 @@ static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_eve static void ftdm_sangoma_isdn_poll_events(ftdm_span_t *span) { - ftdm_status_t ret_status; - ftdm_channel_t *ftdmchan; + ftdm_status_t ret_status; ftdm_iterator_t *chaniter = NULL; ftdm_iterator_t *curr = NULL; @@ -315,7 +315,7 @@ static void *ftdm_sangoma_isdn_dchan_run(ftdm_thread_t *me, void *obj) while (ftdm_running() && !(ftdm_test_flag(span, FTDM_SPAN_STOP_THREAD))) { wflags = FTDM_READ; - status = ftdm_channel_wait(dchan, &wflags, 0); + status = ftdm_channel_wait(dchan, &wflags, 10000); switch(status) { case FTDM_FAIL: ftdm_log_chan_msg(dchan, FTDM_LOG_CRIT, "Failed to wait for d-channel\n"); @@ -331,8 +331,10 @@ static void *ftdm_sangoma_isdn_dchan_run(ftdm_thread_t *me, void *obj) } else { ftdm_log_chan_msg(dchan, FTDM_LOG_WARNING, "Failed to read from channel \n"); } +#ifndef WIN32 /* It is valid on WIN32 for poll to return without errors, but no flags set */ } else { ftdm_log_chan_msg(dchan, FTDM_LOG_CRIT, "Failed to poll for d-channel\n"); +#endif } break; default: @@ -986,7 +988,7 @@ static FIO_SIG_LOAD_FUNCTION(ftdm_sangoma_isdn_init) ftdm_log(FTDM_LOG_INFO, "Loading ftmod_sangoma_isdn...\n"); memset(&g_sngisdn_data, 0, sizeof(g_sngisdn_data)); - + memset(&g_sngisdn_event_interface, 0, sizeof(g_sngisdn_event_interface)); /* set callbacks */ g_sngisdn_event_interface.cc.sng_con_ind = sngisdn_rcv_con_ind; g_sngisdn_event_interface.cc.sng_con_cfm = sngisdn_rcv_con_cfm; @@ -1017,8 +1019,8 @@ static FIO_SIG_LOAD_FUNCTION(ftdm_sangoma_isdn_init) g_sngisdn_event_interface.sta.sng_q931_trc_ind = sngisdn_rcv_q931_trace; g_sngisdn_event_interface.sta.sng_cc_sta_ind = sngisdn_rcv_cc_ind; - g_sngisdn_event_interface.io.sng_data_req = sngisdn_rcv_data_req; - + g_sngisdn_event_interface.io.sng_data_req = sngisdn_rcv_data_req; + for(i=1;i<=MAX_VARIANTS;i++) { ftdm_mutex_create(&g_sngisdn_data.ccs[i].mutex); } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c index 163265177f..c0ee11d980 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c @@ -37,6 +37,7 @@ extern ftdm_status_t cpy_calling_num_from_user(CgPtyNmb *cgPtyNmb, ftdm_caller_data_t *ftdm); extern ftdm_status_t cpy_called_num_from_user(CdPtyNmb *cdPtyNmb, ftdm_caller_data_t *ftdm); extern ftdm_status_t cpy_calling_name_from_user(ConEvnt *conEvnt, ftdm_channel_t *ftdmchan); +extern ftdm_status_t cpy_redir_num_from_user(RedirNmb *redirNmb, ftdm_caller_data_t *ftdm); void sngisdn_snd_setup(ftdm_channel_t *ftdmchan) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c index e7ebc8f20b..940006451a 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c @@ -873,16 +873,30 @@ int16_t sngisdn_rcv_data_req(uint16_t spId, uint8_t *buff, uint32_t length) sngisdn_span_data_t *signal_data = g_sngisdn_data.spans[spId]; ftdm_assert(signal_data, "Received Data request on unconfigured span\n"); - status = signal_data->dchan->fio->wait(signal_data->dchan, &flags, 10); - if (status != FTDM_SUCCESS) { - ftdm_log_chan_msg(signal_data->dchan, FTDM_LOG_WARNING, "transmit timed-out\n"); - return -1; - } - status = signal_data->dchan->fio->write(signal_data->dchan, buff, (ftdm_size_t*)&length); - if (status != FTDM_SUCCESS) { - ftdm_log_chan_msg(signal_data->dchan, FTDM_LOG_CRIT, "Failed to transmit frame\n"); - return -1; - } + do { + flags = FTDM_WRITE; + status = signal_data->dchan->fio->wait(signal_data->dchan, &flags, 1000); + if (status != FTDM_SUCCESS) { + ftdm_log_chan_msg(signal_data->dchan, FTDM_LOG_WARNING, "transmit timed-out\n"); + return -1; + } + + + if ((flags & FTDM_WRITE)) { + status = signal_data->dchan->fio->write(signal_data->dchan, buff, (ftdm_size_t*)&length); + if (status != FTDM_SUCCESS) { + ftdm_log_chan_msg(signal_data->dchan, FTDM_LOG_CRIT, "Failed to transmit frame\n"); + return -1; + } + break; + /* On WIN32, it is possible for poll to return without FTDM_WRITE flag set, so we try to retransmit */ +#ifndef WIN32 + } else { + ftdm_log_chan_msg(signal_data->dchan, FTDM_LOG_WARNING, "Failed to poll for d-channel\n"); + return -1; +#endif + } + } while(1); return 0; } diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 896b8eebd8..f40f2b20c7 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -115,7 +115,7 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_next_event); static __inline__ int tdmv_api_wait_socket(ftdm_channel_t *ftdmchan, int timeout, int *flags) { -#ifdef LIBSANGOMA_VERSION +#ifdef LIBSANGOMA_VERSION int err; uint32_t inflags = *flags; uint32_t outflags = 0; @@ -130,6 +130,7 @@ static __inline__ int tdmv_api_wait_socket(ftdm_channel_t *ftdmchan, int timeout if (err == SANG_STATUS_APIPOLL_TIMEOUT) { err = 0; } + return err; #else struct pollfd pfds[1]; From caacb24500b1294a93cea6fa5345bd9605492c99 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 15 Nov 2010 14:13:01 -0500 Subject: [PATCH 04/10] freetdm: Changes for FTDM IO commands --- libs/freetdm/src/ftdm_io.c | 3 + .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.c | 10 +- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.h | 8 +- .../ftmod_sangoma_isdn_stack_cfg.c | 347 +++++++++--------- .../ftmod_sangoma_isdn_stack_out.c | 63 +++- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 51 ++- libs/freetdm/src/include/private/ftdm_core.h | 40 ++ 7 files changed, 329 insertions(+), 193 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 1ede703a41..15e853236d 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -56,6 +56,9 @@ #define FTDM_READ_TRACE_INDEX 0 #define FTDM_WRITE_TRACE_INDEX 1 +ftdm_time_t time_last_throttle_log = 0; +ftdm_time_t time_current_throttle_log = 0; + static int time_is_init = 0; static void time_init(void) 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 98b09e9305..5142de5211 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 @@ -242,10 +242,10 @@ static __inline__ void ftdm_sangoma_isdn_advance_chan_states(ftdm_channel_t *ftd static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_event_t event) { + sngisdn_snd_event(span, event); switch (event) { /* Check if the span woke up from power-saving mode */ case FTDM_OOB_ALARM_CLEAR: - sngisdn_snd_event(span, SNG_L1EVENT_ALARM_OFF); if (FTDM_SPAN_IS_BRI(span)) { ftdm_channel_t *ftdmchan; sngisdn_chan_data_t *sngisdn_info; @@ -267,9 +267,6 @@ static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_eve ftdm_iterator_free(chaniter); } break; - case FTDM_OOB_ALARM_TRAP: - sngisdn_snd_event(span, SNG_L1EVENT_ALARM_ON); - break; default: /* Ignore other events for now */ break; @@ -327,7 +324,7 @@ static void *ftdm_sangoma_isdn_dchan_run(ftdm_thread_t *me, void *obj) len = 1000; status = ftdm_channel_read(dchan, data, &len); if (status == FTDM_SUCCESS) { - sngisdn_snd_data(span, data, len); + sngisdn_snd_data(dchan, data, len); } else { ftdm_log_chan_msg(dchan, FTDM_LOG_WARNING, "Failed to read from channel \n"); } @@ -1019,7 +1016,8 @@ static FIO_SIG_LOAD_FUNCTION(ftdm_sangoma_isdn_init) g_sngisdn_event_interface.sta.sng_q931_trc_ind = sngisdn_rcv_q931_trace; g_sngisdn_event_interface.sta.sng_cc_sta_ind = sngisdn_rcv_cc_ind; - g_sngisdn_event_interface.io.sng_data_req = sngisdn_rcv_data_req; + g_sngisdn_event_interface.io.sng_l1_data_req = sngisdn_rcv_l1_data_req; + g_sngisdn_event_interface.io.sng_l1_cmd_req = sngisdn_rcv_l1_cmd_req; for(i=1;i<=MAX_VARIANTS;i++) { ftdm_mutex_create(&g_sngisdn_data.ccs[i].mutex); 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 75262c9627..7c66c38acf 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 @@ -293,8 +293,8 @@ void sngisdn_snd_reset(ftdm_channel_t *ftdmchan); void sngisdn_snd_con_complete(ftdm_channel_t *ftdmchan); void sngisdn_snd_info_req(ftdm_channel_t *ftdmchan); void sngisdn_snd_status_enq(ftdm_channel_t *ftdmchan); -void sngisdn_snd_data(ftdm_span_t *span, uint8_t *data, ftdm_size_t len); -void sngisdn_snd_event(ftdm_span_t *span, sng_isdn_l1_event_t l1_event); +void sngisdn_snd_data(ftdm_channel_t *dchan, uint8_t *data, ftdm_size_t len); +void sngisdn_snd_event(ftdm_channel_t *span, sng_isdn_l1_event_t l1_event); /* Inbound Call Control functions */ void sngisdn_rcv_con_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, ConEvnt *conEvnt, int16_t dChan, uint8_t ces); @@ -314,7 +314,9 @@ void sngisdn_rcv_srv_ind(int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces) void sngisdn_rcv_srv_cfm(int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces); void sngisdn_rcv_rst_cfm(int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType); void sngisdn_rcv_rst_ind(int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType); -int16_t sngisdn_rcv_data_req(uint16_t spId, uint8_t *buff, uint32_t length); +int16_t sngisdn_rcv_l1_data_req(uint16_t spId, sng_isdn_l1_frame_t *l1_frame); +int16_t sngisdn_rcv_l1_cmd_req(uint16_t spId, sng_l1_cmd_t *l1_cmd); + void sngisdn_process_con_ind (sngisdn_event_data_t *sngisdn_event); void sngisdn_process_con_cfm (sngisdn_event_data_t *sngisdn_event); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c index eabaa7affc..6c75fb3a81 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c @@ -156,34 +156,34 @@ ftdm_status_t sngisdn_stack_cfg(ftdm_span_t *span) ftdm_status_t sngisdn_stack_cfg_phy_gen(void) { /*local variables*/ - L1Mngmt cfg; /*configuration structure*/ - Pst pst; /*post structure*/ + L1Mngmt cfg; /*configuration structure*/ + Pst pst; /*post structure*/ - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); - /* insert the destination Entity */ - pst.dstEnt = ENTL1; + /* insert the destination Entity */ + pst.dstEnt = ENTL1; - /*clear the configuration structure*/ + /*clear the configuration structure*/ memset(&cfg, 0, sizeof(cfg)); - /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); + /*fill in some general sections of the header*/ + stack_hdr_init(&cfg.hdr); - /*fill in the specific fields of the header*/ - cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTL1; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STGEN; + /*fill in the specific fields of the header*/ + cfg.hdr.msgType = TCFG; + cfg.hdr.entId.ent = ENTL1; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STGEN; - stack_pst_init(&cfg.t.cfg.s.l1Gen.sm ); - cfg.t.cfg.s.l1Gen.sm.srcEnt = ENTL1; - cfg.t.cfg.s.l1Gen.sm.dstEnt = ENTSM; + stack_pst_init(&cfg.t.cfg.s.l1Gen.sm ); + cfg.t.cfg.s.l1Gen.sm.srcEnt = ENTL1; + cfg.t.cfg.s.l1Gen.sm.dstEnt = ENTSM; - cfg.t.cfg.s.l1Gen.nmbLnks = MAX_L1_LINKS+1; - cfg.t.cfg.s.l1Gen.poolTrUpper = POOL_UP_TR; /* upper pool threshold */ - cfg.t.cfg.s.l1Gen.poolTrLower = POOL_LW_TR; /* lower pool threshold */ + cfg.t.cfg.s.l1Gen.nmbLnks = MAX_L1_LINKS; + cfg.t.cfg.s.l1Gen.poolTrUpper = POOL_UP_TR; /* upper pool threshold */ + cfg.t.cfg.s.l1Gen.poolTrLower = POOL_LW_TR; /* lower pool threshold */ if (sng_isdn_phy_config(&pst, &cfg)) { return FTDM_FAIL; @@ -193,38 +193,38 @@ ftdm_status_t sngisdn_stack_cfg_phy_gen(void) ftdm_status_t sngisdn_stack_cfg_phy_psap(ftdm_span_t *span) { - L1Mngmt cfg; - Pst pst; + L1Mngmt cfg; + Pst pst; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); - /* insert the destination Entity */ - pst.dstEnt = ENTL1; + /* insert the destination Entity */ + pst.dstEnt = ENTL1; - /*clear the configuration structure*/ + /*clear the configuration structure*/ memset(&cfg, 0, sizeof(cfg)); - /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); + /*fill in some general sections of the header*/ + stack_hdr_init(&cfg.hdr); - /*fill in the specific fields of the header*/ - cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTL1; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STPSAP; + /*fill in the specific fields of the header*/ + cfg.hdr.msgType = TCFG; + cfg.hdr.entId.ent = ENTL1; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STPSAP; cfg.hdr.elmId.elmntInst1 = signal_data->link_id; - + if (!signal_data->dchan) { ftdm_log(FTDM_LOG_ERROR, "%s:No d-channels specified\n", span->name); return FTDM_FAIL; - } + } cfg.t.cfg.s.l1PSAP.sockfd = (int32_t)signal_data->dchan->sockfd; - + switch(span->trunk_type) { case FTDM_TRUNK_E1: cfg.t.cfg.s.l1PSAP.type = SNG_L1_TYPE_PRI; @@ -240,9 +240,9 @@ ftdm_status_t sngisdn_stack_cfg_phy_psap(ftdm_span_t *span) default: ftdm_log(FTDM_LOG_ERROR, "%s:Unsupported trunk type %d\n", span->name, span->trunk_type); return FTDM_FAIL; - } - cfg.t.cfg.s.l1PSAP.spId = signal_data->link_id; - + } + cfg.t.cfg.s.l1PSAP.spId = signal_data->link_id; + if (sng_isdn_phy_config(&pst, &cfg)) { return FTDM_FAIL; } @@ -253,25 +253,25 @@ ftdm_status_t sngisdn_stack_cfg_phy_psap(ftdm_span_t *span) ftdm_status_t sngisdn_stack_cfg_q921_gen(void) { BdMngmt cfg; - Pst pst; + Pst pst; - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); /* insert the destination Entity */ - pst.dstEnt = ENTLD; + pst.dstEnt = ENTLD; - /*clear the configuration structure*/ - memset(&cfg, 0, sizeof(cfg)); + /*clear the configuration structure*/ + memset(&cfg, 0, sizeof(cfg)); /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); - - cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTLD; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STGEN; - /* fill in the Gen Conf structures internal pst struct */ + stack_hdr_init(&cfg.hdr); - stack_pst_init(&cfg.t.cfg.s.bdGen.sm); + cfg.hdr.msgType = TCFG; + cfg.hdr.entId.ent = ENTLD; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STGEN; + /* fill in the Gen Conf structures internal pst struct */ + + stack_pst_init(&cfg.t.cfg.s.bdGen.sm); cfg.t.cfg.s.bdGen.sm.dstEnt = ENTSM; /* entity */ @@ -284,8 +284,8 @@ ftdm_status_t sngisdn_stack_cfg_q921_gen(void) #ifdef LAPD_3_4 cfg.t.cfg.s.bdGen.timeRes = 100; /* timer resolution = 1 sec */ #endif - cfg.t.cfg.s.bdGen.poolTrUpper = 2; /* upper pool threshold */ - cfg.t.cfg.s.bdGen.poolTrLower = 1; /* lower pool threshold */ + cfg.t.cfg.s.bdGen.poolTrUpper = 2; /* upper pool threshold */ + cfg.t.cfg.s.bdGen.poolTrLower = 1; /* lower pool threshold */ if (sng_isdn_q921_config(&pst, &cfg)) { return FTDM_FAIL; @@ -296,27 +296,27 @@ ftdm_status_t sngisdn_stack_cfg_q921_gen(void) ftdm_status_t sngisdn_stack_cfg_q921_msap(ftdm_span_t *span) { BdMngmt cfg; - Pst pst; + Pst pst; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); /* insert the destination Entity */ - pst.dstEnt = ENTLD; + pst.dstEnt = ENTLD; - /*clear the configuration structure*/ - memset(&cfg, 0, sizeof(cfg)); + /*clear the configuration structure*/ + memset(&cfg, 0, sizeof(cfg)); /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); + stack_hdr_init(&cfg.hdr); cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTLD; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STMSAP; + cfg.hdr.entId.ent = ENTLD; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STMSAP; cfg.t.cfg.s.bdMSAP.lnkNmb = signal_data->link_id; - + cfg.t.cfg.s.bdMSAP.maxOutsFrms = 24; /* MAC window */ cfg.t.cfg.s.bdMSAP.tQUpperTrs = 32; /* Tx Queue Upper Threshold */ cfg.t.cfg.s.bdMSAP.tQLowerTrs = 24; /* Tx Queue Lower Threshold */ @@ -328,7 +328,7 @@ ftdm_status_t sngisdn_stack_cfg_q921_msap(ftdm_span_t *span) cfg.t.cfg.s.bdMSAP.route = RTESPEC; /* Route */ cfg.t.cfg.s.bdMSAP.dstProcId = SFndProcId(); /* destination proc id */ cfg.t.cfg.s.bdMSAP.dstEnt = ENTL1; /* entity */ - cfg.t.cfg.s.bdMSAP.dstInst = S_INST; /* instance */ + cfg.t.cfg.s.bdMSAP.dstInst = S_INST; /* instance */ cfg.t.cfg.s.bdMSAP.t201Tmr = 1; /* T201 - should be equal to t200Tmr */ cfg.t.cfg.s.bdMSAP.t202Tmr = 2; /* T202 */ cfg.t.cfg.s.bdMSAP.bndRetryCnt = 2; /* bind retry counter */ @@ -377,7 +377,7 @@ ftdm_status_t sngisdn_stack_cfg_q921_msap(ftdm_span_t *span) if (signal_data->setup_arb == SNGISDN_OPT_TRUE) { cfg.t.cfg.s.bdMSAP.setUpArb = ACTIVE; } else if (signal_data->setup_arb == SNGISDN_OPT_FALSE) { - cfg.t.cfg.s.bdMSAP.setUpArb = PASSIVE; + cfg.t.cfg.s.bdMSAP.setUpArb = PASSIVE; } if (sng_isdn_q921_config(&pst, &cfg)) { @@ -389,24 +389,24 @@ ftdm_status_t sngisdn_stack_cfg_q921_msap(ftdm_span_t *span) ftdm_status_t sngisdn_stack_cfg_q921_dlsap(ftdm_span_t *span, uint8_t management) { BdMngmt cfg; - Pst pst; + Pst pst; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); /* insert the destination Entity */ - pst.dstEnt = ENTLD; + pst.dstEnt = ENTLD; - /*clear the configuration structure*/ - memset(&cfg, 0, sizeof(cfg)); + /*clear the configuration structure*/ + memset(&cfg, 0, sizeof(cfg)); /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); + stack_hdr_init(&cfg.hdr); /*fill in the specific fields of the header*/ - cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTLD; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STDLSAP; + cfg.hdr.msgType = TCFG; + cfg.hdr.entId.ent = ENTLD; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STDLSAP; cfg.t.cfg.s.bdDLSAP.lnkNmb = signal_data->link_id; @@ -418,10 +418,10 @@ ftdm_status_t sngisdn_stack_cfg_q921_dlsap(ftdm_span_t *span, uint8_t management } else { cfg.t.cfg.s.bdDLSAP.k = 7; /* k */ } - + cfg.t.cfg.s.bdDLSAP.n200 = 3; /* n200 */ cfg.t.cfg.s.bdDLSAP.congTmr = 300; /* congestion timer */ - cfg.t.cfg.s.bdDLSAP.t200Tmr = 1; /* t1 changed from 25 */ + cfg.t.cfg.s.bdDLSAP.t200Tmr = 1; /* t1 changed from 25 */ cfg.t.cfg.s.bdDLSAP.t203Tmr = 10; /* t3 changed from 50 */ cfg.t.cfg.s.bdDLSAP.mod = 128; /* modulo */ cfg.t.cfg.s.bdDLSAP.selector = 0; /* Selector 0 */ @@ -471,28 +471,28 @@ ftdm_status_t sngisdn_stack_cfg_q921_dlsap(ftdm_span_t *span, uint8_t management ftdm_status_t sngisdn_stack_cfg_q931_gen(void) { InMngmt cfg; - Pst pst; + Pst pst; - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); - /* insert the destination Entity */ - pst.dstEnt = ENTIN; + /* insert the destination Entity */ + pst.dstEnt = ENTIN; - /*clear the configuration structure*/ + /*clear the configuration structure*/ memset(&cfg, 0, sizeof(cfg)); - /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); + /*fill in some general sections of the header*/ + stack_hdr_init(&cfg.hdr); - /*fill in the specific fields of the header*/ - cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTIN; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STGEN; + /*fill in the specific fields of the header*/ + cfg.hdr.msgType = TCFG; + cfg.hdr.entId.ent = ENTIN; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STGEN; - /* fill in the Gen Conf structures internal pst struct */ - stack_pst_init(&cfg.t.cfg.s.inGen.sm); + /* fill in the Gen Conf structures internal pst struct */ + stack_pst_init(&cfg.t.cfg.s.inGen.sm); cfg.t.cfg.s.inGen.nmbSaps = MAX_VARIANTS+1; /* Total number of variants supported */ @@ -526,26 +526,26 @@ ftdm_status_t sngisdn_stack_cfg_q931_gen(void) ftdm_status_t sngisdn_stack_cfg_q931_tsap(ftdm_span_t *span) { InMngmt cfg; - Pst pst; + Pst pst; unsigned i; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); - /* insert the destination Entity */ - pst.dstEnt = ENTIN; + /* insert the destination Entity */ + pst.dstEnt = ENTIN; - /*clear the configuration structure*/ + /*clear the configuration structure*/ memset(&cfg, 0, sizeof(cfg)); - /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); + /*fill in some general sections of the header*/ + stack_hdr_init(&cfg.hdr); - /*fill in the specific fields of the header*/ - cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTIN; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STTSAP; + /*fill in the specific fields of the header*/ + cfg.hdr.msgType = TCFG; + cfg.hdr.entId.ent = ENTIN; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STTSAP; cfg.t.cfg.s.inTSAP.sapId = signal_data->cc_id; @@ -589,31 +589,31 @@ ftdm_status_t sngisdn_stack_cfg_q931_tsap(ftdm_span_t *span) ftdm_status_t sngisdn_stack_cfg_q931_dlsap(ftdm_span_t *span) { InMngmt cfg; - Pst pst; + Pst pst; unsigned i; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); - /* insert the destination Entity */ - pst.dstEnt = ENTIN; + /* insert the destination Entity */ + pst.dstEnt = ENTIN; - /*clear the configuration structure*/ + /*clear the configuration structure*/ memset(&cfg, 0, sizeof(cfg)); - /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); + /*fill in some general sections of the header*/ + stack_hdr_init(&cfg.hdr); + + /*fill in the specific fields of the header*/ + cfg.hdr.msgType = TCFG; + cfg.hdr.entId.ent = ENTIN; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STDLSAP; - /*fill in the specific fields of the header*/ - cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTIN; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STDLSAP; - cfg.hdr.response.selector=0; - + cfg.t.cfg.s.inDLSAP.sapId = signal_data->link_id; cfg.t.cfg.s.inDLSAP.spId = signal_data->link_id; cfg.t.cfg.s.inDLSAP.swtch = sng_isdn_stack_switchtype(signal_data->switchtype); @@ -659,7 +659,7 @@ ftdm_status_t sngisdn_stack_cfg_q931_dlsap(ftdm_span_t *span) cfg.t.cfg.s.inDLSAP.ctldInt[1] = 1; } - cfg.t.cfg.s.inDLSAP.numRstInd = 255; + cfg.t.cfg.s.inDLSAP.numRstInd = 255; cfg.t.cfg.s.inDLSAP.relOpt = TRUE; #ifdef ISDN_SRV cfg.t.cfg.s.inDLSAP.bcas = FALSE; @@ -839,36 +839,36 @@ ftdm_status_t sngisdn_stack_cfg_q931_dlsap(ftdm_span_t *span) ftdm_status_t sngisdn_stack_cfg_q931_lce(ftdm_span_t *span) { InMngmt cfg; - Pst pst; + Pst pst; uint8_t i; - uint8_t numCes=1; + uint8_t numCes=1; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; if (span->trunk_type == FTDM_TRUNK_BRI_PTMP && signal_data->signalling == SNGISDN_SIGNALING_NET) { numCes = 8; } - /* initalize the post structure */ - stack_pst_init(&pst); + /* initalize the post structure */ + stack_pst_init(&pst); - /* insert the destination Entity */ - pst.dstEnt = ENTIN; + /* insert the destination Entity */ + pst.dstEnt = ENTIN; - /*clear the configuration structure*/ + /*clear the configuration structure*/ memset(&cfg, 0, sizeof(cfg)); - /*fill in some general sections of the header*/ - stack_hdr_init(&cfg.hdr); + /*fill in some general sections of the header*/ + stack_hdr_init(&cfg.hdr); - /*fill in the specific fields of the header*/ - cfg.hdr.msgType = TCFG; - cfg.hdr.entId.ent = ENTIN; - cfg.hdr.entId.inst = S_INST; - cfg.hdr.elmId.elmnt = STDLC; + /*fill in the specific fields of the header*/ + cfg.hdr.msgType = TCFG; + cfg.hdr.entId.ent = ENTIN; + cfg.hdr.entId.inst = S_INST; + cfg.hdr.elmId.elmnt = STDLC; cfg.hdr.response.selector=0; cfg.t.cfg.s.inLCe.sapId = signal_data->link_id; - + cfg.t.cfg.s.inLCe.lnkUpDwnInd = TRUE; cfg.t.cfg.s.inLCe.tCon.enb = TRUE; @@ -877,7 +877,7 @@ ftdm_status_t sngisdn_stack_cfg_q931_lce(ftdm_span_t *span) cfg.t.cfg.s.inLCe.tDisc.val = 35; cfg.t.cfg.s.inLCe.t314.enb = FALSE; /* if segmentation enabled, set to TRUE */ cfg.t.cfg.s.inLCe.t314.val = 35; - + cfg.t.cfg.s.inLCe.t332i.enb = FALSE; /* set to TRUE for NFAS */ #ifdef NFAS @@ -897,7 +897,6 @@ ftdm_status_t sngisdn_stack_cfg_q931_lce(ftdm_span_t *span) cfg.t.cfg.s.inLCe.tRstAck.enb = TRUE; cfg.t.cfg.s.inLCe.tRstAck.val = 10; - cfg.t.cfg.s.inLCe.usid = 0; cfg.t.cfg.s.inLCe.tid = 0; @@ -983,11 +982,11 @@ ftdm_status_t sngisdn_stack_cfg_cc_sap(ftdm_span_t *span) cfg.t.cfg.s.ccISAP.pst.dstInst = S_INST; cfg.t.cfg.s.ccISAP.pst.dstProcId = SFndProcId(); - cfg.t.cfg.s.ccISAP.pst.prior = PRIOR0; - cfg.t.cfg.s.ccISAP.pst.route = RTESPEC; - cfg.t.cfg.s.ccISAP.pst.region = S_REG; - cfg.t.cfg.s.ccISAP.pst.pool = S_POOL; - cfg.t.cfg.s.ccISAP.pst.selector = 0; + cfg.t.cfg.s.ccISAP.pst.prior = PRIOR0; + cfg.t.cfg.s.ccISAP.pst.route = RTESPEC; + cfg.t.cfg.s.ccISAP.pst.region = S_REG; + cfg.t.cfg.s.ccISAP.pst.pool = S_POOL; + cfg.t.cfg.s.ccISAP.pst.selector = 0; cfg.t.cfg.s.ccISAP.suId = signal_data->cc_id; cfg.t.cfg.s.ccISAP.spId = signal_data->cc_id; @@ -1005,19 +1004,19 @@ ftdm_status_t sngisdn_stack_cfg_cc_sap(ftdm_span_t *span) void stack_pst_init(Pst *pst) { memset(pst, 0, sizeof(Pst)); - /*fill in the post structure*/ - pst->dstProcId = SFndProcId(); - pst->dstInst = S_INST; + /*fill in the post structure*/ + pst->dstProcId = SFndProcId(); + pst->dstInst = S_INST; - pst->srcProcId = SFndProcId(); - pst->srcEnt = ENTSM; - pst->srcInst = S_INST; + pst->srcProcId = SFndProcId(); + pst->srcEnt = ENTSM; + pst->srcInst = S_INST; - pst->prior = PRIOR0; - pst->route = RTESPEC; - pst->region = S_REG; - pst->pool = S_POOL; - pst->selector = 0; + pst->prior = PRIOR0; + pst->route = RTESPEC; + pst->region = S_REG; + pst->pool = S_POOL; + pst->selector = 0; return; } @@ -1026,21 +1025,21 @@ void stack_pst_init(Pst *pst) void stack_hdr_init(Header *hdr) { hdr->msgType = 0; - hdr->msgLen = 0; - hdr->entId.ent = 0; - hdr->entId.inst = 0; - hdr->elmId.elmnt = 0; - hdr->elmId.elmntInst1 = 0; - hdr->elmId.elmntInst2 = 0; - hdr->elmId.elmntInst3 = 0; - hdr->seqNmb = 0; - hdr->version = 0; - hdr->response.prior = PRIOR0; - hdr->response.route = RTESPEC; - hdr->response.mem.region = S_REG; - hdr->response.mem.pool = S_POOL; - hdr->transId = 0; - hdr->response.selector = 0; + hdr->msgLen = 0; + hdr->entId.ent = 0; + hdr->entId.inst = 0; + hdr->elmId.elmnt = 0; + hdr->elmId.elmntInst1 = 0; + hdr->elmId.elmntInst2 = 0; + hdr->elmId.elmntInst3 = 0; + hdr->seqNmb = 0; + hdr->version = 0; + hdr->response.prior = PRIOR0; + hdr->response.route = RTESPEC; + hdr->response.mem.region = S_REG; + hdr->response.mem.pool = S_POOL; + hdr->transId = 0; + hdr->response.selector = 0; return; } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c index c0ee11d980..94bd6e23e1 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c @@ -595,16 +595,65 @@ void sngisdn_snd_release(ftdm_channel_t *ftdmchan, uint8_t glare) return; } -void sngisdn_snd_data(ftdm_span_t *span, uint8_t *data, ftdm_size_t len) +/* We received an incoming frame on the d-channel, send data to the stack */ +void sngisdn_snd_data(ftdm_channel_t *dchan, uint8_t *data, ftdm_size_t len) { - sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; - sng_isdn_data_ind(signal_data->link_id, data, len); + l1_frame_t l1_frame; + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) dchan->span->signal_data; + + memset(&l1_frame, 0, sizeof(l1_frame)); + l1_frame.len = len; + + memcpy(&l1_frame.data, data, len); + + if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_CRC)) { + l1_frame.flags |= SNG_L1FRAME_ERROR_CRC; + } + + if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_FRAME)) { + l1_frame.flags |= SNG_L1FRAME_ERROR_FRAME; + } + + if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_ABORT)) { + l1_frame.flags |= SNG_L1FRAME_ERROR_ABORT; + } + + if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_FIFO)) { + l1_frame.flags |= SNG_L1FRAME_ERROR_FIFO; + } + + if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_DMA)) { + l1_frame.flags |= SNG_L1FRAME_ERROR_DMA; + } + + if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_QUEUE_THRES)) { + /* Should we trigger congestion here? */ + l1_frame.flags |= SNG_L1FRAME_QUEUE_THRES; + } + + if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_QUEUE_FULL)) { + /* Should we trigger congestion here? */ + l1_frame.flags |= SNG_L1FRAME_QUEUE_FULL; + } + + sng_isdn_data_ind(signal_data->link_id, &l1_frame); } -void sngisdn_snd_event(ftdm_span_t *span, sng_isdn_l1_event_t l1_event) -{ - sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; - sng_isdn_event_ind(signal_data->link_id, l1_event); +void sngisdn_snd_event(ftdm_channel_t *dchan, ftdm_oob_event_t event) +{ + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) dchan->span->signal_data; + switch(event) { + case FTDM_OOB_ALARM_CLEAR: + sng_isdn_event_ind(signal_data->link_id, SNG_L1EVENT_ALARM_OFF); + break; + case FTDM_OOB_ALARM_TRAP: + sng_isdn_event_ind(signal_data->link_id, SNG_L1EVENT_ALARM_ON); + break; + default: + /* We do not care about the other OOB events for now */ + return; + } + return; } diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index f40f2b20c7..d6573ac2de 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -170,7 +170,7 @@ static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan) static __inline__ sng_fd_t __tdmv_api_open_span_chan(int span, int chan) { return __sangoma_open_tdmapi_span_chan(span, chan); -} +} #endif static ftdm_io_interface_t wanpipe_interface; @@ -759,6 +759,49 @@ static FIO_COMMAND_FUNCTION(wanpipe_command) return FTDM_SUCCESS; } +static void wanpipe_read_stats(ftdmchan, wp_tdm_api_rx_hdr_t *rx_stats) +{ + ftdmchan->iostats.s.rx.error_flags = 0; + if (rx_stats->rx_hdr_errors) { + wanpipe_reset_stats(ftdmchan); + ftdm_log_chan_msg_throttle(ftdmchan, "IO errors\n"); + } + + ftdmchan->iostats.s.rx_queue_size = rx_stats->rx_h.rx_h.max_rx_queue_length; + ftdmchan->iostats.s.rx_queue_len = rx_stats->rx_h.current_number_of_frames_in_rx_queue; + + if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_ABORT); + } + if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_DMA); + } + if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_FIFO); + } + if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_CRC); + } + if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_FRAME); + } + + if (ftdmchan->iostats.s.rx_queue_len >= (0.8*ftdmchan->iostats.s.rx_queue_size)) { + ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Rx Queue length exceeded threshold (%d/%d)\n", + ftdmchan->iostats.s.rx_queue_len, ftdmchan->iostats.s.rx_queue_size); + + ftdm_set_flag(&(ftdmchan->iostats.s.rx), FTDM_IOSTATS_ERROR_QUEUE_THRES); + } + + if (ftdmchan->iostats.s.rx_queue_len >= ftdmchan->iostats.s.rx_queue_size) { + ftdm_log_chan(ftdmchan, FTDM_LOG_CRIT, "Rx Queue Full (%d/%d)\n", + ftdmchan->iostats.s.rx_queue_len, ftdmchan->iostats.s.rx_queue_size); + + ftdm_set_flag(&(ftdmchan->iostats.s.rx), FTDM_IOSTATS_ERROR_QUEUE_FULL); + } + return; +} + /** * \brief Reads data from a Wanpipe channel * \param ftdmchan Channel to read from @@ -787,9 +830,11 @@ static FIO_READ_FUNCTION(wanpipe_read) snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Failed to read from sangoma device: %s (%d)\n", strerror(errno), rx_len); return FTDM_FAIL; - } - + } + if (ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_IO_STATS)) { + wanpipe_read_stats(ftdmchan, &hdrframe); + } return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/include/private/ftdm_core.h b/libs/freetdm/src/include/private/ftdm_core.h index c5f3c4b821..6cbf589044 100644 --- a/libs/freetdm/src/include/private/ftdm_core.h +++ b/libs/freetdm/src/include/private/ftdm_core.h @@ -357,6 +357,7 @@ typedef struct { } ftdm_dtmf_debug_t; #endif + typedef struct { const char *file; const char *func; @@ -366,6 +367,33 @@ typedef struct { ftdm_time_t time; } ftdm_channel_history_entry_t; +typedef enum { + FTDM_IOSTATS_ERROR_CRC = (1<<0), + FTDM_IOSTATS_ERROR_FRAME = (1<<1), + FTDM_IOSTATS_ERROR_ABORT = (1<<2), + FTDM_IOSTATS_ERROR_FIFO = (1<<3), + FTDM_IOSTATS_ERROR_DMA = (1<<4), + FTDM_IOSTATS_ERROR_QUEUE_THRES = (1<<5), /* Queue reached high threshold */ + FTDM_IOSTATS_ERROR_QUEUE_FULL = (1<<6), /* Queue is full */ +} ftdm_iostats_error_type_t; + +typedef struct { + union { + struct { + uint32_t errors; + uint16_t flags; + uint8_t rx_queue_size; /* max queue size configured */ + uint8_t rx_queue_len; /* Current number of elements in queue */ + } rx; + struct { + uint32_t errors; + uint16_t flags; + uint8_t tx_queue_size; /* max queue size configured */ + uint8_t tx_queue_len; /* Current number of elements in queue */ + } tx; + } s; +} ftdm_channel_iostats_t; + /* 2^8 table size, one for each byte (sample) value */ #define FTDM_GAINS_TABLE_SIZE 256 struct ftdm_channel { @@ -438,6 +466,7 @@ struct ftdm_channel { int availability_rate; void *user_private; ftdm_timer_id_t hangup_timer; + ftdm_channel_iostats_t iostats; #ifdef FTDM_DEBUG_DTMF ftdm_dtmf_debug_t dtmfdbg; #endif @@ -632,10 +661,21 @@ FT_DECLARE(void) ftdm_channel_clear_detected_tones(ftdm_channel_t *ftdmchan); #define ftdm_channel_lock(chan) ftdm_mutex_lock(chan->mutex) #define ftdm_channel_unlock(chan) ftdm_mutex_unlock(chan->mutex) + +#define ftdm_log_throttle(level, ...) \ + time_current_throttle_log = ftdm_current_time_in_ms(); \ + if (time_current_throttle_log - time_last_throttle_log > FTDM_THROTTLE_LOG_INTERVAL) {\ + ftdm_log(level, __VA_ARGS__); \ + time_last_throttle_log = time_current_throttle_log; \ + } + #define ftdm_log_chan_ex(fchan, file, func, line, level, format, ...) ftdm_log(file, func, line, level, "[s%dc%d][%d:%d] " format, fchan->span_id, fchan->chan_id, fchan->physical_span_id, fchan->physical_chan_id, __VA_ARGS__) #define ftdm_log_chan(fchan, level, format, ...) ftdm_log(level, "[s%dc%d][%d:%d] " format, fchan->span_id, fchan->chan_id, fchan->physical_span_id, fchan->physical_chan_id, __VA_ARGS__) #define ftdm_log_chan_msg(fchan, level, msg) ftdm_log(level, "[s%dc%d][%d:%d] " msg, fchan->span_id, fchan->chan_id, fchan->physical_span_id, fchan->physical_chan_id) +#define ftdm_log_chan_throttle(fchan, level, format, ...) ftdm_log_throttle(level, "[s%dc%d][%d:%d] " format, fchan->span_id, fchan->chan_id, fchan->physical_span_id, fchan->physical_chan_id, __VA_ARGS__) +#define ftdm_log_chan_msg_throttle(fchan, level, format, ...) ftdm_log_throttle(level, "[s%dc%d][%d:%d] " format, fchan->span_id, fchan->chan_id, fchan->physical_span_id, fchan->physical_chan_id, __VA_ARGS__) + #define ftdm_span_lock(span) ftdm_mutex_lock(span->mutex) #define ftdm_span_unlock(span) ftdm_mutex_unlock(span->mutex) From a2add139638907d3c36ee935c2f0b51db7821fd0 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 15 Nov 2010 19:16:09 -0500 Subject: [PATCH 05/10] freetdm:Changes for shared IO --- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.c | 51 +++++++++++--- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.h | 5 +- .../ftmod_sangoma_isdn_stack_out.c | 28 +++++--- .../ftmod_sangoma_isdn_stack_rcv.c | 47 ++++++++++++- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 67 ++++++++++++------- libs/freetdm/src/include/freetdm.h | 5 +- libs/freetdm/src/include/private/ftdm_core.h | 2 +- libs/freetdm/src/include/private/ftdm_types.h | 1 + 8 files changed, 153 insertions(+), 53 deletions(-) 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 5142de5211..674fea21c5 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 @@ -51,6 +51,8 @@ static void ftdm_sangoma_isdn_poll_events(ftdm_span_t *span); static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_event_t event); static void ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdmchan); static void ftdm_sangoma_isdn_process_stack_event (ftdm_span_t *span, sngisdn_event_data_t *sngisdn_event); +static void ftdm_sangoma_isdn_wakeup_phy(ftdm_channel_t *dchan); +static void ftdm_sangoma_isdn_dchan_set_queue_size(ftdm_channel_t *ftdmchan); static ftdm_io_interface_t g_sngisdn_io_interface; static sng_isdn_event_interface_t g_sngisdn_event_interface; @@ -241,8 +243,9 @@ static __inline__ void ftdm_sangoma_isdn_advance_chan_states(ftdm_channel_t *ftd static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_event_t event) { - - sngisdn_snd_event(span, event); + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; + sngisdn_snd_event(signal_data->dchan, event); + switch (event) { /* Check if the span woke up from power-saving mode */ case FTDM_OOB_ALARM_CLEAR: @@ -251,8 +254,7 @@ static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_eve sngisdn_chan_data_t *sngisdn_info; ftdm_iterator_t *chaniter = NULL; ftdm_iterator_t *curr = NULL; - sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) span->signal_data; - + chaniter = ftdm_span_get_chan_iterator(span, NULL); for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) { ftdmchan = (ftdm_channel_t*)ftdm_iterator_current(curr); @@ -261,7 +263,7 @@ static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_eve if (ftdm_test_flag(sngisdn_info, FLAG_ACTIVATING)) { ftdm_clear_flag(sngisdn_info, FLAG_ACTIVATING); - ftdm_sched_timer(signal_data->sched, "delayed_setup", 1, sngisdn_delayed_setup, (void*) ftdmchan->call_data, NULL); + ftdm_sched_timer(signal_data->sched, "delayed_setup", 1000, sngisdn_delayed_setup, (void*) ftdmchan->call_data, NULL); } } ftdm_iterator_free(chaniter); @@ -276,9 +278,7 @@ static void ftdm_sangoma_isdn_process_phy_events(ftdm_span_t *span, ftdm_oob_eve static void ftdm_sangoma_isdn_poll_events(ftdm_span_t *span) { ftdm_status_t ret_status; - ftdm_iterator_t *chaniter = NULL; - ftdm_iterator_t *curr = NULL; - + ret_status = ftdm_span_poll_event(span, 0, NULL); switch(ret_status) { case FTDM_SUCCESS: @@ -297,6 +297,33 @@ static void ftdm_sangoma_isdn_poll_events(ftdm_span_t *span) } } +static void ftdm_sangoma_isdn_dchan_set_queue_size(ftdm_channel_t *dchan) +{ + ftdm_status_t ret_status; + uint32_t queue_size; + + queue_size = SNGISDN_DCHAN_QUEUE_LEN; + ret_status = ftdm_channel_command(dchan, FTDM_COMMAND_SET_RX_QUEUE_SIZE, &queue_size); + ftdm_assert(ret_status == FTDM_SUCCESS, "Failed to set Rx Queue size"); + + queue_size = SNGISDN_DCHAN_QUEUE_LEN; + ret_status = ftdm_channel_command(dchan, FTDM_COMMAND_SET_TX_QUEUE_SIZE, &queue_size); + ftdm_assert(ret_status == FTDM_SUCCESS, "Failed to set Tx Queue size"); + + RETVOID; +} + +static void ftdm_sangoma_isdn_wakeup_phy(ftdm_channel_t *dchan) +{ + ftdm_status_t ret_status; + ftdm_channel_hw_link_status_t status = FTDM_HW_LINK_CONNECTED; + ret_status = ftdm_channel_command(dchan, FTDM_COMMAND_SET_LINK_STATUS, &status); + if (ret_status != FTDM_SUCCESS) { + ftdm_log_chan_msg(dchan, FTDM_LOG_WARNING, "Failed to wake-up link\n"); + } + return; +} + static void *ftdm_sangoma_isdn_dchan_run(ftdm_thread_t *me, void *obj) { uint8_t data[1000]; @@ -306,7 +333,9 @@ static void *ftdm_sangoma_isdn_dchan_run(ftdm_thread_t *me, void *obj) ftdm_channel_t *dchan = ((sngisdn_span_data_t*)span->signal_data)->dchan; ftdm_size_t len = 0; - + ftdm_channel_set_feature(dchan, FTDM_CHANNEL_FEATURE_IO_STATS); + ftdm_sangoma_isdn_dchan_set_queue_size(dchan); + ftdm_assert(dchan, "Span does not have a dchannel"); ftdm_channel_open_chan(dchan); @@ -597,8 +626,8 @@ static void ftdm_sangoma_isdn_process_state_change(ftdm_channel_t *ftdmchan) sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) ftdmchan->span->signal_data; ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "Requesting Line activation\n"); - sngisdn_set_flag(sngisdn_info, FLAG_ACTIVATING); - sngisdn_wake_up_phy(ftdmchan->span); + sngisdn_set_flag(sngisdn_info, FLAG_ACTIVATING); + ftdm_sangoma_isdn_wakeup_phy(ftdmchan); ftdm_sched_timer(signal_data->sched, "timer_t3", signal_data->timer_t3*1000, sngisdn_t3_timeout, (void*) sngisdn_info, NULL); } else { sngisdn_snd_setup(ftdmchan); 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 7c66c38acf..8208aa14bd 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 @@ -60,6 +60,7 @@ #define SNGISDN_EVENT_QUEUE_SIZE 100 #define SNGISDN_EVENT_POLL_RATE 100 #define SNGISDN_NUM_LOCAL_NUMBERS 8 +#define SNGISDN_DCHAN_QUEUE_LEN 200 /* TODO: rename all *_cc_* to *_an_* */ @@ -294,7 +295,7 @@ void sngisdn_snd_con_complete(ftdm_channel_t *ftdmchan); void sngisdn_snd_info_req(ftdm_channel_t *ftdmchan); void sngisdn_snd_status_enq(ftdm_channel_t *ftdmchan); void sngisdn_snd_data(ftdm_channel_t *dchan, uint8_t *data, ftdm_size_t len); -void sngisdn_snd_event(ftdm_channel_t *span, sng_isdn_l1_event_t l1_event); +void sngisdn_snd_event(ftdm_channel_t *dchan, ftdm_oob_event_t event); /* Inbound Call Control functions */ void sngisdn_rcv_con_ind(int16_t suId, uint32_t suInstId, uint32_t spInstId, ConEvnt *conEvnt, int16_t dChan, uint8_t ces); @@ -314,7 +315,7 @@ void sngisdn_rcv_srv_ind(int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces) void sngisdn_rcv_srv_cfm(int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces); void sngisdn_rcv_rst_cfm(int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType); void sngisdn_rcv_rst_ind(int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType); -int16_t sngisdn_rcv_l1_data_req(uint16_t spId, sng_isdn_l1_frame_t *l1_frame); +int16_t sngisdn_rcv_l1_data_req(uint16_t spId, sng_l1_frame_t *l1_frame); int16_t sngisdn_rcv_l1_cmd_req(uint16_t spId, sng_l1_cmd_t *l1_cmd); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c index 94bd6e23e1..8842ef5934 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c @@ -598,7 +598,7 @@ void sngisdn_snd_release(ftdm_channel_t *ftdmchan, uint8_t glare) /* We received an incoming frame on the d-channel, send data to the stack */ void sngisdn_snd_data(ftdm_channel_t *dchan, uint8_t *data, ftdm_size_t len) { - l1_frame_t l1_frame; + sng_l1_frame_t l1_frame; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) dchan->span->signal_data; memset(&l1_frame, 0, sizeof(l1_frame)); @@ -606,32 +606,32 @@ void sngisdn_snd_data(ftdm_channel_t *dchan, uint8_t *data, ftdm_size_t len) memcpy(&l1_frame.data, data, len); - if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_CRC)) { + if (ftdm_test_flag(&(dchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_CRC)) { l1_frame.flags |= SNG_L1FRAME_ERROR_CRC; } - if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_FRAME)) { + if (ftdm_test_flag(&(dchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_FRAME)) { l1_frame.flags |= SNG_L1FRAME_ERROR_FRAME; } - if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_ABORT)) { + if (ftdm_test_flag(&(dchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_ABORT)) { l1_frame.flags |= SNG_L1FRAME_ERROR_ABORT; } - if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_FIFO)) { + if (ftdm_test_flag(&(dchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_FIFO)) { l1_frame.flags |= SNG_L1FRAME_ERROR_FIFO; } - if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_ERROR_DMA)) { + if (ftdm_test_flag(&(dchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_DMA)) { l1_frame.flags |= SNG_L1FRAME_ERROR_DMA; } - if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_QUEUE_THRES)) { + if (ftdm_test_flag(&(dchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_QUEUE_THRES)) { /* Should we trigger congestion here? */ l1_frame.flags |= SNG_L1FRAME_QUEUE_THRES; } - if (ftdm_test_flag(&(dchan->iostats.s.rx), FTDM_IOSTATS_QUEUE_FULL)) { + if (ftdm_test_flag(&(dchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_QUEUE_FULL)) { /* Should we trigger congestion here? */ l1_frame.flags |= SNG_L1FRAME_QUEUE_FULL; } @@ -640,14 +640,20 @@ void sngisdn_snd_data(ftdm_channel_t *dchan, uint8_t *data, ftdm_size_t len) } void sngisdn_snd_event(ftdm_channel_t *dchan, ftdm_oob_event_t event) -{ +{ + sng_l1_event_t l1_event; + memset(&l1_event, 0, sizeof(l1_event)); + + sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) dchan->span->signal_data; switch(event) { case FTDM_OOB_ALARM_CLEAR: - sng_isdn_event_ind(signal_data->link_id, SNG_L1EVENT_ALARM_OFF); + l1_event.type = SNG_L1EVENT_ALARM_OFF; + sng_isdn_event_ind(signal_data->link_id, &l1_event); break; case FTDM_OOB_ALARM_TRAP: - sng_isdn_event_ind(signal_data->link_id, SNG_L1EVENT_ALARM_ON); + l1_event.type = SNG_L1EVENT_ALARM_ON; + sng_isdn_event_ind(signal_data->link_id, &l1_event); break; default: /* We do not care about the other OOB events for now */ diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c index 940006451a..e3898b9096 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c @@ -866,13 +866,15 @@ end_of_trace: return; } -int16_t sngisdn_rcv_data_req(uint16_t spId, uint8_t *buff, uint32_t length) +/* The stacks is wants to transmit a frame */ +int16_t sngisdn_rcv_l1_data_req(uint16_t spId, sng_l1_frame_t *l1_frame) { ftdm_status_t status; ftdm_wait_flag_t flags = FTDM_WRITE; sngisdn_span_data_t *signal_data = g_sngisdn_data.spans[spId]; ftdm_assert(signal_data, "Received Data request on unconfigured span\n"); - + ftdm_size_t length = l1_frame->len; + do { flags = FTDM_WRITE; status = signal_data->dchan->fio->wait(signal_data->dchan, &flags, 1000); @@ -883,7 +885,7 @@ int16_t sngisdn_rcv_data_req(uint16_t spId, uint8_t *buff, uint32_t length) if ((flags & FTDM_WRITE)) { - status = signal_data->dchan->fio->write(signal_data->dchan, buff, (ftdm_size_t*)&length); + status = signal_data->dchan->fio->write(signal_data->dchan, l1_frame->data, (ftdm_size_t*)&length); if (status != FTDM_SUCCESS) { ftdm_log_chan_msg(signal_data->dchan, FTDM_LOG_CRIT, "Failed to transmit frame\n"); return -1; @@ -900,6 +902,45 @@ int16_t sngisdn_rcv_data_req(uint16_t spId, uint8_t *buff, uint32_t length) return 0; } +int16_t sngisdn_rcv_l1_cmd_req(uint16_t spId, sng_l1_cmd_t *l1_cmd) +{ + sngisdn_span_data_t *signal_data = g_sngisdn_data.spans[spId]; + ftdm_assert(signal_data, "Received Data request on unconfigured span\n"); + + switch(l1_cmd->type) { + case SNG_L1CMD_SET_LINK_STATUS: + { + ftdm_channel_hw_link_status_t status = FTDM_HW_LINK_CONNECTED; + ftdm_channel_command(signal_data->dchan, FTDM_COMMAND_SET_LINK_STATUS, &status); + } + break; + case SNG_L1CMD_GET_LINK_STATUS: + { + ftdm_channel_hw_link_status_t status = 0; + ftdm_channel_command(signal_data->dchan, FTDM_COMMAND_GET_LINK_STATUS, &status); + if (status == FTDM_HW_LINK_CONNECTED) { + l1_cmd->cmd.status = 1; + } else if (status == FTDM_HW_LINK_DISCONNECTED) { + l1_cmd->cmd.status = 0; + } else { + ftdm_log_chan(signal_data->dchan, FTDM_LOG_CRIT, "Invalid link status reported %d\n", status); + l1_cmd->cmd.status = 0; + } + } + break; + case SNG_L1CMD_FLUSH_STATS: + ftdm_channel_command(signal_data->dchan, FTDM_COMMAND_FLUSH_IOSTATS, NULL); + break; + case SNG_L1CMD_FLUSH_BUFFERS: + ftdm_channel_command(signal_data->dchan, FTDM_COMMAND_FLUSH_BUFFERS, NULL); + break; + default: + ftdm_log_chan(signal_data->dchan, FTDM_LOG_CRIT, "Unsupported channel command:%d\n", l1_cmd->type); + return -1; + } + return 0; +} + void sngisdn_rcv_sng_assert(char *message) { ftdm_assert(0, message); diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index d6573ac2de..f9fbb5c044 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -746,6 +746,28 @@ static FIO_COMMAND_FUNCTION(wanpipe_command) } } break; + case FTDM_COMMAND_FLUSH_BUFFERS: + { + err = sangoma_flush_bufs(ftdmchan->sockfd, &tdm_api); + } + break; + case FTDM_COMMAND_FLUSH_IOSTATS: + { + err = sangoma_flush_stats(ftdmchan->sockfd, &tdm_api); + } + break; + case FTDM_COMMAND_SET_RX_QUEUE_SIZE: + { + uint32_t queue_size = FTDM_COMMAND_OBJ_INT; + err = sangoma_set_rx_queue_sz(ftdmchan->sockfd, &tdm_api, queue_size); + } + break; + case FTDM_COMMAND_SET_TX_QUEUE_SIZE: + { + uint32_t queue_size = FTDM_COMMAND_OBJ_INT; + err = sangoma_set_tx_queue_sz(ftdmchan->sockfd, &tdm_api, queue_size); + } + break; default: break; }; @@ -759,45 +781,42 @@ static FIO_COMMAND_FUNCTION(wanpipe_command) return FTDM_SUCCESS; } -static void wanpipe_read_stats(ftdmchan, wp_tdm_api_rx_hdr_t *rx_stats) +static void wanpipe_read_stats(ftdm_channel_t *ftdmchan, wp_tdm_api_rx_hdr_t *rx_stats) { - ftdmchan->iostats.s.rx.error_flags = 0; - if (rx_stats->rx_hdr_errors) { - wanpipe_reset_stats(ftdmchan); - ftdm_log_chan_msg_throttle(ftdmchan, "IO errors\n"); - } + ftdmchan->iostats.stats.rx.flags = 0; - ftdmchan->iostats.s.rx_queue_size = rx_stats->rx_h.rx_h.max_rx_queue_length; - ftdmchan->iostats.s.rx_queue_len = rx_stats->rx_h.current_number_of_frames_in_rx_queue; + ftdmchan->iostats.stats.rx.errors = rx_stats->wp_api_rx_hdr_errors; + ftdmchan->iostats.stats.rx.rx_queue_size = rx_stats->wp_api_rx_hdr_max_queue_length; + ftdmchan->iostats.stats.rx.rx_queue_len = rx_stats->wp_api_rx_hdr_number_of_frames_in_queue; - if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_ABORT); + if (rx_stats->wp_api_rx_hdr_error_map & (1<iostats.stats.rx), FTDM_IOSTATS_ERROR_ABORT); } - if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_DMA); + if (rx_stats->wp_api_rx_hdr_error_map & (1<iostats.stats.rx), FTDM_IOSTATS_ERROR_DMA); } - if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_FIFO); + if (rx_stats->wp_api_rx_hdr_error_map & (1<iostats.stats.rx), FTDM_IOSTATS_ERROR_FIFO); } - if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_CRC); + if (rx_stats->wp_api_rx_hdr_error_map & (1<iostats.stats.rx), FTDM_IOSTATS_ERROR_CRC); } - if (rx_stats->rx_h.wp_api_rx_hdr_error_map & (1<iostats.s.rx), FTDM_IOSTATS_ERROR_FRAME); + if (rx_stats->wp_api_rx_hdr_error_map & (1<iostats.stats.rx), FTDM_IOSTATS_ERROR_FRAME); } - if (ftdmchan->iostats.s.rx_queue_len >= (0.8*ftdmchan->iostats.s.rx_queue_size)) { + if (ftdmchan->iostats.stats.rx.rx_queue_len >= (0.8*ftdmchan->iostats.stats.rx.rx_queue_size)) { ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Rx Queue length exceeded threshold (%d/%d)\n", - ftdmchan->iostats.s.rx_queue_len, ftdmchan->iostats.s.rx_queue_size); + ftdmchan->iostats.stats.rx.rx_queue_len, ftdmchan->iostats.stats.rx.rx_queue_size); - ftdm_set_flag(&(ftdmchan->iostats.s.rx), FTDM_IOSTATS_ERROR_QUEUE_THRES); + ftdm_set_flag(&(ftdmchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_QUEUE_THRES); } - if (ftdmchan->iostats.s.rx_queue_len >= ftdmchan->iostats.s.rx_queue_size) { + if (ftdmchan->iostats.stats.rx.rx_queue_len >= ftdmchan->iostats.stats.rx.rx_queue_size) { ftdm_log_chan(ftdmchan, FTDM_LOG_CRIT, "Rx Queue Full (%d/%d)\n", - ftdmchan->iostats.s.rx_queue_len, ftdmchan->iostats.s.rx_queue_size); + ftdmchan->iostats.stats.rx.rx_queue_len, ftdmchan->iostats.stats.rx.rx_queue_size); - ftdm_set_flag(&(ftdmchan->iostats.s.rx), FTDM_IOSTATS_ERROR_QUEUE_FULL); + ftdm_set_flag(&(ftdmchan->iostats.stats.rx), FTDM_IOSTATS_ERROR_QUEUE_FULL); } return; } diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 64ecc2e357..52a5456df1 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -430,12 +430,15 @@ typedef enum { FTDM_COMMAND_FLUSH_TX_BUFFERS, FTDM_COMMAND_FLUSH_RX_BUFFERS, FTDM_COMMAND_FLUSH_BUFFERS, + FTDM_COMMAND_FLUSH_IOSTATS, FTDM_COMMAND_SET_PRE_BUFFER_SIZE, FTDM_COMMAND_SET_LINK_STATUS, FTDM_COMMAND_GET_LINK_STATUS, FTDM_COMMAND_ENABLE_LOOP, FTDM_COMMAND_DISABLE_LOOP, - FTDM_COMMAND_COUNT + FTDM_COMMAND_COUNT, + FTDM_COMMAND_SET_RX_QUEUE_SIZE, + FTDM_COMMAND_SET_TX_QUEUE_SIZE, } ftdm_command_t; /*! \brief Custom memory handler hooks. Not recommended to use unless you need memory allocation customizations */ diff --git a/libs/freetdm/src/include/private/ftdm_core.h b/libs/freetdm/src/include/private/ftdm_core.h index 6cbf589044..c7a1533320 100644 --- a/libs/freetdm/src/include/private/ftdm_core.h +++ b/libs/freetdm/src/include/private/ftdm_core.h @@ -391,7 +391,7 @@ typedef struct { uint8_t tx_queue_size; /* max queue size configured */ uint8_t tx_queue_len; /* Current number of elements in queue */ } tx; - } s; + } stats; } ftdm_channel_iostats_t; /* 2^8 table size, one for each byte (sample) value */ diff --git a/libs/freetdm/src/include/private/ftdm_types.h b/libs/freetdm/src/include/private/ftdm_types.h index 78ac8f63eb..d9cefc3c6f 100644 --- a/libs/freetdm/src/include/private/ftdm_types.h +++ b/libs/freetdm/src/include/private/ftdm_types.h @@ -194,6 +194,7 @@ typedef enum { FTDM_CHANNEL_FEATURE_CALLWAITING = (1 << 6), /*!< Channel will allow call waiting (ie: FXS devices) (read/write) */ FTDM_CHANNEL_FEATURE_HWEC = (1<<7), /*!< Channel has a hardware echo canceller */ FTDM_CHANNEL_FEATURE_HWEC_DISABLED_ON_IDLE = (1<<8), /*!< hardware echo canceller is disabled when there are no calls on this channel */ + FTDM_CHANNEL_FEATURE_IO_STATS = (1<<9), /*!< Channel supports IO statistics (HDLC channels only) */ } ftdm_channel_feature_t; typedef enum { From 65be57d212e601de396d57821bb499a4d802a1c7 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 16 Nov 2010 12:41:56 -0500 Subject: [PATCH 06/10] Fixed for windows compilation issues --- .../ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c | 3 ++- .../ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c index 8842ef5934..b0848379e9 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_out.c @@ -642,10 +642,11 @@ void sngisdn_snd_data(ftdm_channel_t *dchan, uint8_t *data, ftdm_size_t len) void sngisdn_snd_event(ftdm_channel_t *dchan, ftdm_oob_event_t event) { sng_l1_event_t l1_event; + sngisdn_span_data_t *signal_data = NULL; memset(&l1_event, 0, sizeof(l1_event)); - sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*) dchan->span->signal_data; + signal_data = (sngisdn_span_data_t*) dchan->span->signal_data; switch(event) { case FTDM_OOB_ALARM_CLEAR: l1_event.type = SNG_L1EVENT_ALARM_OFF; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c index e3898b9096..02e0bdf71b 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_rcv.c @@ -871,9 +871,10 @@ int16_t sngisdn_rcv_l1_data_req(uint16_t spId, sng_l1_frame_t *l1_frame) { ftdm_status_t status; ftdm_wait_flag_t flags = FTDM_WRITE; - sngisdn_span_data_t *signal_data = g_sngisdn_data.spans[spId]; - ftdm_assert(signal_data, "Received Data request on unconfigured span\n"); + sngisdn_span_data_t *signal_data = g_sngisdn_data.spans[spId]; ftdm_size_t length = l1_frame->len; + + ftdm_assert(signal_data, "Received Data request on unconfigured span\n"); do { flags = FTDM_WRITE; From c5070aaf52bb37ec63731e82be04f8e78057df21 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 16 Nov 2010 14:56:19 -0500 Subject: [PATCH 07/10] Fixed cyginstall.sh script --- libs/freetdm/cyginstall.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/cyginstall.sh b/libs/freetdm/cyginstall.sh index 311df939af..e2d5885c4e 100644 --- a/libs/freetdm/cyginstall.sh +++ b/libs/freetdm/cyginstall.sh @@ -5,7 +5,8 @@ fsdir=../.. set -x cp Debug/mod/*.dll $fsdir/Debug/mod/ cp mod_freetdm/Debug/*.pdb $fsdir/Debug/mod/ -cp Debug/*.dll $fsdir/Debug/mod/ +cp Debug/freetdm.dll $fsdir/Debug/ +cp Debug/ftmod_*.dll $fsdir/Debug/mod/ cp Debug/*.pdb $fsdir/Debug/mod/ #cp Debug/testsangomaboost.exe $fsdir/Debug/ echo "FRIENDLY REMINDER: RECOMPILE ftmod_wanpipe WHENEVER YOU INSTALL NEW DRIVERS" From 553255c63195ecbc87cdaa72394e425bc6a0f52a Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 19 Nov 2010 14:33:57 -0500 Subject: [PATCH 08/10] Fixed some windows compile warnings from merge --- conf/autoload_configs/callcenter.conf.xml | 1 - conf/autoload_configs/erlang_event.conf.xml | 9 - conf/autoload_configs/modules.conf.xml | 96 -- conf/autoload_configs/switch.conf.xml | 6 - conf/autoload_configs/voicemail.conf.xml | 7 +- conf/dialplan/default.xml | 845 ++---------------- conf/sip_profiles/internal.xml | 20 - conf/skinny_profiles/internal.xml | 2 +- conf/vars.xml | 2 +- .../ftmod_sangoma_isdn/ftmod_sangoma_isdn.h | 8 +- .../ftmod_sangoma_isdn_stack_cntrl.c | 1 - .../ftmod_sangoma_isdn_support.c | 26 +- 12 files changed, 108 insertions(+), 915 deletions(-) diff --git a/conf/autoload_configs/callcenter.conf.xml b/conf/autoload_configs/callcenter.conf.xml index a069413ac6..9140193b22 100644 --- a/conf/autoload_configs/callcenter.conf.xml +++ b/conf/autoload_configs/callcenter.conf.xml @@ -13,7 +13,6 @@ - diff --git a/conf/autoload_configs/erlang_event.conf.xml b/conf/autoload_configs/erlang_event.conf.xml index 62deb84f67..ec14e21a25 100644 --- a/conf/autoload_configs/erlang_event.conf.xml +++ b/conf/autoload_configs/erlang_event.conf.xml @@ -2,16 +2,7 @@ - - - - - diff --git a/conf/autoload_configs/modules.conf.xml b/conf/autoload_configs/modules.conf.xml index f5627fe965..90d66f5798 100644 --- a/conf/autoload_configs/modules.conf.xml +++ b/conf/autoload_configs/modules.conf.xml @@ -1,113 +1,17 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/conf/autoload_configs/switch.conf.xml b/conf/autoload_configs/switch.conf.xml index 896dd0e712..7a68a7f2bd 100644 --- a/conf/autoload_configs/switch.conf.xml +++ b/conf/autoload_configs/switch.conf.xml @@ -15,11 +15,6 @@ - - - - - @@ -86,7 +81,6 @@ - diff --git a/conf/autoload_configs/voicemail.conf.xml b/conf/autoload_configs/voicemail.conf.xml index 06bd6f6dca..14ad98b41c 100644 --- a/conf/autoload_configs/voicemail.conf.xml +++ b/conf/autoload_configs/voicemail.conf.xml @@ -33,10 +33,9 @@ - --> - - - + + + diff --git a/conf/dialplan/default.xml b/conf/dialplan/default.xml index 42a3bcc31f..9e762b97a2 100644 --- a/conf/dialplan/default.xml +++ b/conf/dialplan/default.xml @@ -1,763 +1,88 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + +service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/conf/sip_profiles/internal.xml b/conf/sip_profiles/internal.xml index 93558a3584..50833bfbec 100644 --- a/conf/sip_profiles/internal.xml +++ b/conf/sip_profiles/internal.xml @@ -42,26 +42,6 @@ - - - - - - diff --git a/conf/skinny_profiles/internal.xml b/conf/skinny_profiles/internal.xml index 52da89741d..5feac1ffbf 100644 --- a/conf/skinny_profiles/internal.xml +++ b/conf/skinny_profiles/internal.xml @@ -16,7 +16,7 @@ - + diff --git a/conf/vars.xml b/conf/vars.xml index fced2ef139..c638a80582 100644 --- a/conf/vars.xml +++ b/conf/vars.xml @@ -195,7 +195,7 @@ - + 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 052fbd4021..d8c0e48d2c 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 @@ -270,9 +270,11 @@ extern ftdm_sngisdn_data_t g_sngisdn_data; ftdm_status_t ftmod_isdn_parse_cfg(ftdm_conf_parameter_t *ftdm_parameters, ftdm_span_t *span); /* Support functions */ -FT_DECLARE(uint32_t) get_unique_suInstId(int16_t cc_id); -FT_DECLARE(void) clear_call_data(sngisdn_chan_data_t *sngisdn_info); -FT_DECLARE(void) clear_call_glare_data(sngisdn_chan_data_t *sngisdn_info); +uint32_t get_unique_suInstId(int16_t cc_id); +void clear_call_data(sngisdn_chan_data_t *sngisdn_info); +void clear_call_glare_data(sngisdn_chan_data_t *sngisdn_info); +ftdm_status_t sngisdn_set_avail_rate(ftdm_span_t *span, sngisdn_avail_t avail); +ftdm_status_t sngisdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt); void stack_hdr_init(Header *hdr); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c index d8e6c8e00d..225244f57e 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c @@ -41,7 +41,6 @@ ftdm_status_t sngisdn_activate_phy(ftdm_span_t *span); ftdm_status_t sngisdn_deactivate_phy(ftdm_span_t *span); ftdm_status_t sngisdn_activate_cc(ftdm_span_t *span); -ftdm_status_t sngisdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt); ftdm_status_t sngisdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction); ftdm_status_t sngisdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction); 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 7e083073fd..7871debba4 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 @@ -39,7 +39,7 @@ ftdm_status_t sngisdn_check_free_ids(void); extern ftdm_sngisdn_data_t g_sngisdn_data; void get_memory_info(void); -FT_DECLARE(void) clear_call_data(sngisdn_chan_data_t *sngisdn_info) +void clear_call_data(sngisdn_chan_data_t *sngisdn_info) { uint32_t cc_id = ((sngisdn_span_data_t*)sngisdn_info->ftdmchan->span->signal_data)->cc_id; @@ -56,7 +56,7 @@ FT_DECLARE(void) clear_call_data(sngisdn_chan_data_t *sngisdn_info) return; } -FT_DECLARE(void) clear_call_glare_data(sngisdn_chan_data_t *sngisdn_info) +void clear_call_glare_data(sngisdn_chan_data_t *sngisdn_info) { ftdm_log_chan(sngisdn_info->ftdmchan, FTDM_LOG_DEBUG, "Clearing glare data (suId:%d suInstId:%u spInstId:%u actv-suInstId:%u actv-spInstId:%u)\n", sngisdn_info->glare.suId, @@ -81,7 +81,7 @@ FT_DECLARE(void) clear_call_glare_data(sngisdn_chan_data_t *sngisdn_info) } -FT_DECLARE(uint32_t) get_unique_suInstId(int16_t cc_id) +uint32_t get_unique_suInstId(int16_t cc_id) { uint32_t suInstId; ftdm_assert_return((cc_id > 0 && cc_id <=MAX_VARIANTS), FTDM_FAIL, "Invalid cc_id\n"); @@ -103,7 +103,7 @@ FT_DECLARE(uint32_t) get_unique_suInstId(int16_t cc_id) return 0; } -FT_DECLARE(ftdm_status_t) get_ftdmchan_by_suInstId(int16_t cc_id, uint32_t suInstId, sngisdn_chan_data_t **sngisdn_data) +ftdm_status_t get_ftdmchan_by_suInstId(int16_t cc_id, uint32_t suInstId, sngisdn_chan_data_t **sngisdn_data) { ftdm_assert_return((cc_id > 0 && cc_id <=MAX_VARIANTS), FTDM_FAIL, "Invalid cc_id\n"); ftdm_assert_return(g_sngisdn_data.ccs[cc_id].activation_done, FTDM_FAIL, "Trying to find call on unconfigured CC\n"); @@ -115,7 +115,7 @@ FT_DECLARE(ftdm_status_t) get_ftdmchan_by_suInstId(int16_t cc_id, uint32_t suIns return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) get_ftdmchan_by_spInstId(int16_t cc_id, uint32_t spInstId, sngisdn_chan_data_t **sngisdn_data) +ftdm_status_t get_ftdmchan_by_spInstId(int16_t cc_id, uint32_t spInstId, sngisdn_chan_data_t **sngisdn_data) { ftdm_assert_return((cc_id > 0 && cc_id <=MAX_VARIANTS), FTDM_FAIL, "Invalid cc_id\n"); ftdm_assert_return(g_sngisdn_data.ccs[cc_id].activation_done, FTDM_FAIL, "Trying to find call on unconfigured CC\n"); @@ -147,7 +147,7 @@ ftdm_status_t sngisdn_set_avail_rate(ftdm_span_t *span, sngisdn_avail_t avail) return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) cpy_calling_num_from_stack(ftdm_caller_data_t *ftdm, CgPtyNmb *cgPtyNmb) +ftdm_status_t cpy_calling_num_from_stack(ftdm_caller_data_t *ftdm, CgPtyNmb *cgPtyNmb) { if (cgPtyNmb->eh.pres != PRSNT_NODEF) { return FTDM_FAIL; @@ -174,7 +174,7 @@ FT_DECLARE(ftdm_status_t) cpy_calling_num_from_stack(ftdm_caller_data_t *ftdm, C return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) cpy_called_num_from_stack(ftdm_caller_data_t *ftdm, CdPtyNmb *cdPtyNmb) +ftdm_status_t cpy_called_num_from_stack(ftdm_caller_data_t *ftdm, CdPtyNmb *cdPtyNmb) { if (cdPtyNmb->eh.pres != PRSNT_NODEF) { return FTDM_FAIL; @@ -196,7 +196,7 @@ FT_DECLARE(ftdm_status_t) cpy_called_num_from_stack(ftdm_caller_data_t *ftdm, Cd return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) cpy_redir_num_from_stack(ftdm_caller_data_t *ftdm, RedirNmb *redirNmb) +ftdm_status_t cpy_redir_num_from_stack(ftdm_caller_data_t *ftdm, RedirNmb *redirNmb) { if (redirNmb->eh.pres != PRSNT_NODEF) { return FTDM_FAIL; @@ -216,7 +216,7 @@ FT_DECLARE(ftdm_status_t) cpy_redir_num_from_stack(ftdm_caller_data_t *ftdm, Red return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) cpy_calling_name_from_stack(ftdm_caller_data_t *ftdm, Display *display) +ftdm_status_t cpy_calling_name_from_stack(ftdm_caller_data_t *ftdm, Display *display) { if (display->eh.pres != PRSNT_NODEF) { return FTDM_FAIL; @@ -229,7 +229,7 @@ FT_DECLARE(ftdm_status_t) cpy_calling_name_from_stack(ftdm_caller_data_t *ftdm, return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) cpy_calling_num_from_user(CgPtyNmb *cgPtyNmb, ftdm_caller_data_t *ftdm) +ftdm_status_t cpy_calling_num_from_user(CgPtyNmb *cgPtyNmb, ftdm_caller_data_t *ftdm) { uint8_t len = strlen(ftdm->cid_num.digits); if (!len) { @@ -257,7 +257,7 @@ FT_DECLARE(ftdm_status_t) cpy_calling_num_from_user(CgPtyNmb *cgPtyNmb, ftdm_cal return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) cpy_called_num_from_user(CdPtyNmb *cdPtyNmb, ftdm_caller_data_t *ftdm) +ftdm_status_t cpy_called_num_from_user(CdPtyNmb *cdPtyNmb, ftdm_caller_data_t *ftdm) { uint8_t len = strlen(ftdm->dnis.digits); if (!len) { @@ -287,7 +287,7 @@ FT_DECLARE(ftdm_status_t) cpy_called_num_from_user(CdPtyNmb *cdPtyNmb, ftdm_call return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) cpy_redir_num_from_user(RedirNmb *redirNmb, ftdm_caller_data_t *ftdm) +ftdm_status_t cpy_redir_num_from_user(RedirNmb *redirNmb, ftdm_caller_data_t *ftdm) { uint8_t len = strlen(ftdm->rdnis.digits); if (!len) { @@ -319,7 +319,7 @@ FT_DECLARE(ftdm_status_t) cpy_redir_num_from_user(RedirNmb *redirNmb, ftdm_calle } -FT_DECLARE(ftdm_status_t) cpy_calling_name_from_user(ConEvnt *conEvnt, ftdm_channel_t *ftdmchan) +ftm_status_t cpy_calling_name_from_user(ConEvnt *conEvnt, ftdm_channel_t *ftdmchan) { uint8_t len; ftdm_caller_data_t *ftdm = &ftdmchan->caller_data; From 5c128405b836188ba02f989c0c682fb77c6de2f9 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 19 Nov 2010 14:41:26 -0500 Subject: [PATCH 09/10] Fix for windows compile errors introduced during previous merge --- .../ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h | 13 +++++++++++++ .../ftmod_sangoma_isdn/ftmod_sangoma_isdn_support.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) 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 d8c0e48d2c..81a98cf0d3 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 @@ -273,6 +273,10 @@ ftdm_status_t ftmod_isdn_parse_cfg(ftdm_conf_parameter_t *ftdm_parameters, ftdm_ uint32_t get_unique_suInstId(int16_t cc_id); void clear_call_data(sngisdn_chan_data_t *sngisdn_info); void clear_call_glare_data(sngisdn_chan_data_t *sngisdn_info); +ftdm_status_t get_ftdmchan_by_suInstId(int16_t cc_id, uint32_t suInstId, sngisdn_chan_data_t **sngisdn_data); +ftdm_status_t get_ftdmchan_by_spInstId(int16_t cc_id, uint32_t spInstId, sngisdn_chan_data_t **sngisdn_data); + + ftdm_status_t sngisdn_set_avail_rate(ftdm_span_t *span, sngisdn_avail_t avail); ftdm_status_t sngisdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt); @@ -354,6 +358,15 @@ void sngisdn_rcv_cc_ind(CcMngmt *status); void sngisdn_rcv_sng_log(uint8_t level, char *fmt,...); void sngisdn_rcv_sng_assert(char *message); +ftdm_status_t cpy_calling_num_from_stack(ftdm_caller_data_t *ftdm, CgPtyNmb *cgPtyNmb); +ftdm_status_t cpy_called_num_from_stack(ftdm_caller_data_t *ftdm, CdPtyNmb *cdPtyNmb); +ftdm_status_t cpy_redir_num_from_stack(ftdm_caller_data_t *ftdm, RedirNmb *redirNmb); +ftdm_status_t cpy_calling_name_from_stack(ftdm_caller_data_t *ftdm, Display *display); +ftdm_status_t cpy_calling_num_from_user(CgPtyNmb *cgPtyNmb, ftdm_caller_data_t *ftdm); +ftdm_status_t cpy_called_num_from_user(CdPtyNmb *cdPtyNmb, ftdm_caller_data_t *ftdm); +ftdm_status_t cpy_redir_num_from_user(RedirNmb *redirNmb, ftdm_caller_data_t *ftdm); +ftdm_status_t cpy_calling_name_from_user(ConEvnt *conEvnt, ftdm_channel_t *ftdmchan); + uint8_t sngisdn_get_infoTranCap_from_stack(ftdm_bearer_cap_t bearer_capability); uint8_t sngisdn_get_usrInfoLyr1Prot_from_stack(ftdm_user_layer1_prot_t layer1_prot); ftdm_bearer_cap_t sngisdn_get_infoTranCap_from_user(uint8_t bearer_capability); 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 7871debba4..056bf66ef2 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 @@ -319,7 +319,7 @@ ftdm_status_t cpy_redir_num_from_user(RedirNmb *redirNmb, ftdm_caller_data_t *ft } -ftm_status_t cpy_calling_name_from_user(ConEvnt *conEvnt, ftdm_channel_t *ftdmchan) +ftdm_status_t cpy_calling_name_from_user(ConEvnt *conEvnt, ftdm_channel_t *ftdmchan) { uint8_t len; ftdm_caller_data_t *ftdm = &ftdmchan->caller_data; From 53c41c0463a332447fd5cf1007265dc45446beec Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Sat, 20 Nov 2010 10:25:02 -0500 Subject: [PATCH 10/10] freetdm: ISDN - Fix for main loop going to sleep without processing events from IO module --- libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.c | 1 + 1 file changed, 1 insertion(+) 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 56efcb491c..cb96107ac3 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 @@ -431,6 +431,7 @@ static void *ftdm_sangoma_isdn_run(ftdm_thread_t *me, void *obj) /* Poll for events, e.g HW DTMF */ ftdm_sangoma_isdn_poll_events(span); + ftdm_span_trigger_signals(span); if (ftdm_sched_get_time_to_next_timer(signal_data->sched, &sleep) == FTDM_SUCCESS) { if (sleep < 0 || sleep > SNGISDN_EVENT_POLL_RATE) {