freetdm: fix wink/flash in ftmod_wanpipe
This commit is contained in:
parent
309ced0eac
commit
a3499c5343
|
@ -1243,6 +1243,8 @@ static FIO_GET_ALARMS_FUNCTION(wanpipe_get_alarms)
|
|||
*/
|
||||
static __inline__ ftdm_status_t wanpipe_channel_process_event(ftdm_channel_t *fchan, ftdm_oob_event_t *event_id, wanpipe_tdm_api_t *tdm_api)
|
||||
{
|
||||
ftdm_status_t status = FTDM_SUCCESS;
|
||||
|
||||
switch(tdm_api->wp_tdm_cmd.event.wp_tdm_api_event_type) {
|
||||
case WP_API_EVENT_LINK_STATUS:
|
||||
{
|
||||
|
@ -1260,13 +1262,15 @@ static __inline__ ftdm_status_t wanpipe_channel_process_event(ftdm_channel_t *fc
|
|||
case WP_API_EVENT_RXHOOK:
|
||||
{
|
||||
if (fchan->type == FTDM_CHAN_TYPE_FXS) {
|
||||
*event_id = tdm_api->wp_tdm_cmd.event.wp_tdm_api_event_hook_state & WP_TDMAPI_EVENT_RXHOOK_OFF ? FTDM_OOB_OFFHOOK : FTDM_OOB_ONHOOK;
|
||||
*event_id = tdm_api->wp_tdm_cmd.event.wp_tdm_api_event_hook_state
|
||||
& WP_TDMAPI_EVENT_RXHOOK_OFF ? FTDM_OOB_OFFHOOK : FTDM_OOB_ONHOOK;
|
||||
ftdm_log_chan(fchan, FTDM_LOG_DEBUG, "Got wanpipe %s\n", ftdm_oob_event2str(*event_id));
|
||||
if (*event_id == FTDM_OOB_OFFHOOK) {
|
||||
if (ftdm_test_flag(fchan, FTDM_CHANNEL_FLASH)) {
|
||||
ftdm_clear_flag(fchan, FTDM_CHANNEL_FLASH);
|
||||
ftdm_clear_flag(fchan, FTDM_CHANNEL_WINK);
|
||||
*event_id = FTDM_OOB_FLASH;
|
||||
goto event;
|
||||
goto done;
|
||||
} else {
|
||||
ftdm_set_flag(fchan, FTDM_CHANNEL_WINK);
|
||||
}
|
||||
|
@ -1275,12 +1279,14 @@ static __inline__ ftdm_status_t wanpipe_channel_process_event(ftdm_channel_t *fc
|
|||
ftdm_clear_flag(fchan, FTDM_CHANNEL_WINK);
|
||||
ftdm_clear_flag(fchan, FTDM_CHANNEL_FLASH);
|
||||
*event_id = FTDM_OOB_WINK;
|
||||
goto event;
|
||||
ftdm_log_chan(fchan, FTDM_LOG_DEBUG, "Wink flag is set, delivering %s\n",
|
||||
ftdm_oob_event2str(*event_id));
|
||||
goto done;
|
||||
} else {
|
||||
ftdm_set_flag(fchan, FTDM_CHANNEL_FLASH);
|
||||
}
|
||||
}
|
||||
break;
|
||||
status = FTDM_BREAK;
|
||||
} else {
|
||||
ftdm_status_t status;
|
||||
wanpipe_tdm_api_t onhook_tdm_api;
|
||||
|
@ -1355,8 +1361,8 @@ static __inline__ ftdm_status_t wanpipe_channel_process_event(ftdm_channel_t *fc
|
|||
}
|
||||
break;
|
||||
}
|
||||
event:
|
||||
return FTDM_SUCCESS;
|
||||
done:
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1385,12 +1391,16 @@ FIO_CHANNEL_NEXT_EVENT_FUNCTION(wanpipe_channel_next_event)
|
|||
}
|
||||
|
||||
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "read wanpipe event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type);
|
||||
if ((wanpipe_channel_process_event(ftdmchan, &event_id, &tdm_api)) != FTDM_SUCCESS) {
|
||||
status = wanpipe_channel_process_event(ftdmchan, &event_id, &tdm_api);
|
||||
if (status == FTDM_BREAK) {
|
||||
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "Ignoring event for now\n");
|
||||
} else if (status != FTDM_SUCCESS) {
|
||||
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "Failed to process event from channel\n");
|
||||
return FTDM_FAIL;
|
||||
} else {
|
||||
ftdmchan->last_event_time = 0;
|
||||
}
|
||||
|
||||
ftdmchan->last_event_time = 0;
|
||||
span->event_header.e_type = FTDM_EVENT_OOB;
|
||||
span->event_header.enum_id = event_id;
|
||||
span->event_header.channel = ftdmchan;
|
||||
|
@ -1409,8 +1419,10 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_span_next_event)
|
|||
uint32_t i,err;
|
||||
ftdm_oob_event_t event_id;
|
||||
for(i = 1; i <= span->chan_count; i++) {
|
||||
/* as a hack for wink/flash detection, wanpipe_poll_event overrides the timeout parameter
|
||||
* to force the user to call this function each 5ms or so to detect the timeout of our wink/flash */
|
||||
if (span->channels[i]->last_event_time && !ftdm_test_flag(span->channels[i], FTDM_CHANNEL_EVENT)) {
|
||||
uint32_t diff = (uint32_t)(ftdm_current_time_in_ms() - span->channels[i]->last_event_time);
|
||||
ftdm_time_t diff = ftdm_current_time_in_ms() - span->channels[i]->last_event_time;
|
||||
/* XX printf("%u %u %u\n", diff, (unsigned)ftdm_current_time_in_ms(), (unsigned)span->channels[i]->last_event_time); */
|
||||
if (ftdm_test_flag(span->channels[i], FTDM_CHANNEL_WINK)) {
|
||||
if (diff > wp_globals.wink_ms) {
|
||||
|
@ -1418,6 +1430,7 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_span_next_event)
|
|||
ftdm_clear_flag_locked(span->channels[i], FTDM_CHANNEL_FLASH);
|
||||
ftdm_set_flag_locked(span->channels[i], FTDM_CHANNEL_OFFHOOK);
|
||||
event_id = FTDM_OOB_OFFHOOK;
|
||||
ftdm_log_chan(span->channels[i], FTDM_LOG_DEBUG, "Diff since last event = %llums, delivering %s now\n", diff, ftdm_oob_event2str(event_id));
|
||||
goto event;
|
||||
}
|
||||
}
|
||||
|
@ -1436,11 +1449,13 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_span_next_event)
|
|||
|
||||
sangoma_tdm_txsig_onhook(ftdmchan->sockfd,&tdm_api);
|
||||
}
|
||||
ftdm_log_chan(span->channels[i], FTDM_LOG_DEBUG, "Diff since last event = %llums, delivering %s now\n", diff, ftdm_oob_event2str(event_id));
|
||||
goto event;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ftdm_test_flag(span->channels[i], FTDM_CHANNEL_EVENT)) {
|
||||
ftdm_status_t status;
|
||||
wanpipe_tdm_api_t tdm_api;
|
||||
ftdm_channel_t *ftdmchan = span->channels[i];
|
||||
memset(&tdm_api, 0, sizeof(tdm_api));
|
||||
|
@ -1448,18 +1463,22 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_span_next_event)
|
|||
|
||||
err = sangoma_tdm_read_event(ftdmchan->sockfd, &tdm_api);
|
||||
if (err != FTDM_SUCCESS) {
|
||||
snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno));
|
||||
ftdm_log_chan(span->channels[i], FTDM_LOG_ERROR, "read wanpipe event got error: %s\n", strerror(errno));
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
ftdm_log_chan(span->channels[i], FTDM_LOG_DEBUG, "read wanpipe event %d\n", tdm_api.wp_tdm_cmd.event.wp_tdm_api_event_type);
|
||||
|
||||
ftdm_channel_lock(ftdmchan);
|
||||
if ((wanpipe_channel_process_event(ftdmchan, &event_id, &tdm_api)) != FTDM_SUCCESS) {
|
||||
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "Failed to process events from channel\n");
|
||||
status = wanpipe_channel_process_event(ftdmchan, &event_id, &tdm_api);
|
||||
ftdm_channel_unlock(ftdmchan);
|
||||
|
||||
if (status == FTDM_BREAK) {
|
||||
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "Ignoring event for now\n");
|
||||
continue;
|
||||
} else if (status != FTDM_SUCCESS) {
|
||||
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "Failed to process event from channel\n");
|
||||
return FTDM_FAIL;
|
||||
}
|
||||
ftdm_channel_unlock(ftdmchan);
|
||||
|
||||
event:
|
||||
|
||||
|
@ -1471,7 +1490,7 @@ FIO_SPAN_NEXT_EVENT_FUNCTION(wanpipe_span_next_event)
|
|||
return FTDM_SUCCESS;
|
||||
}
|
||||
}
|
||||
return FTDM_FAIL;
|
||||
return FTDM_BREAK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue