34 #include "libsangoma-pvt.h"
35 #include "wanpipe_includes.h"
37 #ifdef WP_API_FEATURE_LIBSNG_HWEC
39 #include "wanpipe_events.h"
40 #include "wanec_api.h"
41 #include "wanec_iface_api.h"
43 #if defined (__WINDOWS__)
44 # include "wanpipe_time.h"
45 # pragma comment( lib, "waneclib" )
48 static int libsng_hwec_verbosity_level = 0x00;
54 static sangoma_status_t sangoma_hwec_bypass(
char *device_name,
int enable,
unsigned int fe_chan_map)
57 wanec_api_hwec_t hwec;
59 memset(&hwec, 0,
sizeof(wanec_api_hwec_t));
62 hwec.fe_chan_map = fe_chan_map;
65 rc = wanec_api_hwec(device_name, libsng_hwec_verbosity_level, &hwec);
70 static int sangoma_hwec_is_numeric_parameter(
char *parameter)
73 static char *WANEC_numeric_params[] = {
74 "WANEC_TailDisplacement",
75 "WANEC_MaxPlayoutBuffers",
76 "WANEC_MaxConfBridges",
77 "WANEC_EchoOperationMode",
78 "WANEC_ComfortNoiseMode",
79 "WANEC_NonLinearityBehaviorA",
80 "WANEC_NonLinearityBehaviorB",
81 "WANEC_DoubleTalkBehavior",
82 "WANEC_RinLevelControlGainDb",
83 "WANEC_SoutLevelControlGainDb",
84 "WANEC_RinAutomaticLevelControlTargetDb",
85 "WANEC_SoutAutomaticLevelControlTargetDb",
86 "WANEC_RinHighLevelCompensationThresholdDb",
87 "WANEC_AnrSnrEnhancementDb",
88 "WANEC_AecTailLength",
93 while(WANEC_numeric_params[i]){
94 if (!wp_strncasecmp(parameter, WANEC_numeric_params[i], strlen(parameter))) {
109 memset(&tdm_api, 0x00,
sizeof(tdm_api));
111 WANPIPE_API_INIT_CHAN((&tdm_api), ec_api->fe_chan);
121 DBG_HWEC(
"sangoma_cmd_exec() Failed: err %d !\n", err);
126 if (WAN_EC_API_RC_OK != ec_api->err) {
130 case WAN_EC_API_RC_INVALID_STATE:
131 DBG_HWEC(
"WP_API_CMD_EC_IOCTL Failed: Invalid State: %s !\n",
132 WAN_EC_STATE_DECODE(ec_api->state));
134 case WAN_EC_API_RC_FAILED:
135 case WAN_EC_API_RC_INVALID_CMD:
136 case WAN_EC_API_RC_INVALID_DEV:
137 case WAN_EC_API_RC_BUSY:
138 case WAN_EC_API_RC_INVALID_CHANNELS:
139 case WAN_EC_API_RC_INVALID_PORT:
141 DBG_HWEC(
"WP_API_CMD_EC_IOCTL Failed: %s !\n",
142 WAN_EC_API_RC_DECODE(ec_api->err));
168 memset(custom_param, 0x00,
sizeof(*custom_param));
170 strncpy( custom_param->name, parameter_name,
sizeof(custom_param->name) );
172 if (sangoma_hwec_is_numeric_parameter(parameter_name)) {
173 custom_param->dValue = atoi(parameter_value);
175 strncpy(custom_param->sValue, parameter_value,
sizeof(custom_param->sValue));
218 wanec_api_config_t config;
220 memset(&config, 0x00,
sizeof(config));
222 if (number_of_custom_params >= 1 && number_of_custom_params <= 4) {
224 wan_custom_param_t *custom_parms_ptr;
225 unsigned int i, custom_params_memory_size;
227 custom_params_memory_size =
sizeof(wan_custom_param_t) * number_of_custom_params;
233 custom_parms_ptr = malloc(custom_params_memory_size);
234 if (!custom_parms_ptr) {
238 memset(custom_parms_ptr, 0x00, custom_params_memory_size);
240 for (i = 0; i < number_of_custom_params; i++) {
242 strcpy( custom_parms_ptr[i].name, custom_params[i].name );
244 if (sangoma_hwec_is_numeric_parameter(custom_params[i].name)) {
245 custom_parms_ptr[i].dValue = atoi(custom_params[i].sValue);
247 strcpy(custom_parms_ptr[i].sValue, custom_params[i].sValue);
251 config.conf.param_no = number_of_custom_params;
252 config.conf.params = custom_parms_ptr;
257 rc = wanec_api_config( device_name, libsng_hwec_verbosity_level, &config );
259 if (config.conf.params) {
260 free(config.conf.params);
286 wanec_api_release_t release;
288 memset(&release, 0,
sizeof(wanec_api_release_t));
290 rc = wanec_api_release( device_name, libsng_hwec_verbosity_level, &release );
301 wanec_api_opmode_t opmode;
303 memset(&opmode, 0,
sizeof(wanec_api_opmode_t));
306 opmode.fe_chan_map = fe_chan_map;
316 rc = wanec_api_opmode(device_name, libsng_hwec_verbosity_level, &opmode);
391 return sangoma_hwec_bypass(device_name, 1 , fe_chan_map);
418 return sangoma_hwec_bypass(device_name, 0 , fe_chan_map);;
467 wanec_api_modify_t channelModify;
468 wan_custom_param_t custom_param;
470 memset(&channelModify, 0x00,
sizeof(channelModify));
474 channelModify.fe_chan_map = channel_map;
475 channelModify.conf.param_no = 1;
476 channelModify.conf.params = &custom_param;
478 rc = wanec_api_modify( device_name, libsng_hwec_verbosity_level, &channelModify );
508 wanec_api_tone_t tone;
510 memset(&tone, 0,
sizeof(wanec_api_tone_t));
513 tone.enable = enable;
514 tone.fe_chan_map = fe_chan_map;
515 tone.port_map = port_map;
516 tone.type_map = WAN_EC_TONE_PRESENT | WAN_EC_TONE_STOP;
518 rc = wanec_api_tone( device_name, libsng_hwec_verbosity_level, &tone );
544 wanec_api_stats_t stats;
546 memset(&stats, 0,
sizeof(wanec_api_stats_t));
549 stats.fe_chan = fe_chan;
552 rc = wanec_api_stats( device_name, libsng_hwec_verbosity_level, &stats );
577 wanec_api_bufferload_t bufferload;
579 memset(&bufferload, 0,
sizeof(wanec_api_bufferload_t));
582 bufferload.buffer = filename;
583 bufferload.pcmlaw = pcmlaw;
585 rc = wanec_api_buffer_load( device_name, libsng_hwec_verbosity_level, &bufferload );
590 *out_buffer_id = bufferload.buffer_id;
605 sangoma_status_t _LIBSNG_CALL sangoma_hwec_audio_mem_buffer_load(
char *device_name,
unsigned char *buffer,
unsigned int in_size,
char pcmlaw,
int *out_buffer_id)
608 wanec_api_membufferload_t bufferload;
610 memset(&bufferload, 0,
sizeof(bufferload));
613 bufferload.buffer = buffer;
614 bufferload.size = in_size;
615 bufferload.pcmlaw = pcmlaw;
617 rc = wanec_api_mem_buffer_load( device_name, libsng_hwec_verbosity_level, &bufferload );
622 *out_buffer_id = bufferload.buffer_id;
641 wanec_api_bufferunload_t bufferunload;
643 memset(&bufferunload, 0,
sizeof(wanec_api_bufferunload_t));
645 bufferunload.buffer_id = (
unsigned int)in_buffer_id;
647 rc = wanec_api_buffer_unload( device_name, libsng_hwec_verbosity_level, &bufferunload);
678 unsigned char port,
int in_buffer_id,
int start,
679 int repeat_cnt,
int duration)
682 wanec_api_playout_t playout;
684 memset(&playout, 0,
sizeof(wanec_api_playout_t));
686 playout.start =
start;
687 playout.fe_chan = fe_chan_map;
688 playout.buffer_id = in_buffer_id;
690 playout.notifyonstop = 1;
691 playout.user_event_id = 0xA5;
692 playout.repeat_cnt = repeat_cnt;
693 playout.duration = (duration) ? duration : cOCT6100_INVALID_VALUE;
695 rc = wanec_api_playout( device_name, libsng_hwec_verbosity_level, &playout);
714 if (verbosity_level >= 0 || verbosity_level <= 3) {
715 libsng_hwec_verbosity_level = verbosity_level;
716 wanec_api_set_lib_verbosity(verbosity_level);
744 int *hwec_api_return_code, wanec_chan_stats_t *wanec_chan_stats,
int verbose,
int reset)
749 memset(&ec_api, 0x00,
sizeof(ec_api));
751 ec_api.cmd = WAN_EC_API_CMD_STATS_FULL;
753 ec_api.verbose = verbose;
756 ec_api.fe_chan_map = (1 << fe_chan);
759 ec_api.u_chan_stats.reset = reset;
761 err = sangoma_hwec_ioctl(fd, &ec_api);
768 memcpy(wanec_chan_stats, &ec_api.u_chan_stats,
sizeof(*wanec_chan_stats));
770 *hwec_api_return_code = ec_api.err;
794 int *hwec_api_return_code, wanec_chip_stats_t *wanec_chip_stats,
int verbose,
int reset)
800 memset(&ec_api, 0x00,
sizeof(ec_api));
802 ec_api.cmd = WAN_EC_API_CMD_STATS_FULL;
804 ec_api.verbose = verbose;
807 ec_api.fe_chan_map = 0;
810 ec_api.u_chip_stats.reset = reset;
812 err = sangoma_hwec_ioctl(fd, &ec_api);
819 memcpy(wanec_chip_stats, &ec_api.u_chip_stats,
sizeof(*wanec_chip_stats));
821 *hwec_api_return_code = ec_api.err;
844 int *hwec_api_return_code, wanec_chip_image_t *wanec_chip_image,
int verbose)
849 memset(&ec_api, 0x00,
sizeof(ec_api));
851 ec_api.cmd = WAN_EC_API_CMD_STATS_IMAGE;
853 ec_api.verbose = verbose;
856 ec_api.u_chip_image.f_ChipImageInfo = wanec_chip_image->f_ChipImageInfo;
858 err = sangoma_hwec_ioctl(fd, &ec_api);
864 *hwec_api_return_code = ec_api.err;
890 int *hwec_api_return_code,
int enable,
int verbose)
895 memset(&ec_api, 0x00,
sizeof(ec_api));
898 ec_api.cmd = WAN_EC_API_CMD_HWDTMF_REMOVAL_ENABLE;
900 ec_api.cmd = WAN_EC_API_CMD_HWDTMF_REMOVAL_DISABLE;
903 ec_api.verbose = verbose;
906 ec_api.fe_chan_map = (1 << fe_chan);
908 err = sangoma_hwec_ioctl(fd, &ec_api);
914 *hwec_api_return_code = ec_api.err;
sangoma_status_t _LIBSNG_CALL sangoma_hwec_config_power_off(char *device_name, unsigned int fe_chan_map)
Set the channel state in the echo canceller to POWER OFF. This disables echo cancellatio logic inside...
sangoma_status_t _LIBSNG_CALL sangoma_hwec_disable(char *device_name, unsigned int fe_chan_map)
Force AFT FPGA to bypass the echo canceller. This command effectively disables echo cancellation sinc...
sangoma_status_t _LIBSNG_CALL sangoma_hwec_config_operation_mode(char *device_name, int mode, unsigned int fe_chan_map)
Modify channel operation mode.
Wanpipe API Library header for Sangoma AFT T1/E1/Analog/BRI/Serial Hardware -.
sangoma_status_t _LIBSNG_CALL sangoma_hwec_config_release(char *device_name)
Release resources allocated by sangoma_hwec_config_init(). For single-port cards, such as A101 and A2...
sangoma_status_t _LIBSNG_CALL sangoma_hwec_get_chip_image_info(sng_fd_t fd, int *hwec_api_return_code, wanec_chip_image_t *wanec_chip_image, int verbose)
Get information about Firmware Image of EC chip.
sangoma_status_t _LIBSNG_CALL sangoma_hwec_audio_buffer_load(char *device_name, char *filename, char pcmlaw, int *out_buffer_id)
Load audio buffer to EC chip. The buffer can be played out using the sangoma_hwec_audio_buffer_playou...
sangoma_status_t _LIBSNG_CALL sangoma_hwec_get_global_chip_statistics(sng_fd_t fd, int *hwec_api_return_code, wanec_chip_stats_t *wanec_chip_stats, int verbose, int reset)
Get Global statistics from EC chip.
sangoma_status_t _LIBSNG_CALL sangoma_hwec_audio_buffer_playout(char *device_name, unsigned int fe_chan_map, unsigned char port, int in_buffer_id, int start, int repeat_cnt, int duration)
Start playing out an audio buffer previously loaded by sangoma_hwec_audio_buffer_load().
int _LIBSNG_CALL sangoma_cmd_exec(sng_fd_t fd, wanpipe_api_t *tdm_api)
Execute Sangoma API Command.
sangoma_status_t _LIBSNG_CALL sangoma_hwec_config_channel_parameter(char *device_name, char *parameter, char *parameter_value, unsigned int channel_map)
Modify channel configuration parameters.
int sng_fd_t
Windows/Unix file handle abstraction.
sangoma_status_t _LIBSNG_CALL sangoma_hwec_print_statistics(char *device_name, int full, unsigned int fe_chan)
Read and print Chip/Channel statistics from EC chip.
#define SANGOMA_INIT_TDM_API_CMD_RESULT(_name_)
Initialize the 'result' in wanpipe_api_t to SANG_STATUS_GENERAL_ERROR.
int32_t sangoma_status_t
return status from sangoma APIs
sangoma_status_t _LIBSNG_CALL sangoma_hwec_config_power_on(char *device_name, unsigned int fe_chan_map)
Set the channel state in the echo canceller to NORMAL/POWER ON. This enables echo cancelation logic i...
int start(sangoma_interface *sang_if)
Run the main sangoma interface hanlder code.
#define _LIBSNG_CALL
Not used in Linux.
sangoma_status_t _LIBSNG_CALL sangoma_hwec_config_init(char *device_name, wan_custom_param_t custom_params[], unsigned int number_of_custom_params)
Load Firmware image onto EC chip and allocated per-port resources in HWEC API. All chip-wide configur...
Wanpipe API Command Structure.
sangoma_status_t _LIBSNG_CALL sangoma_hwec_config_verbosity(int verbosity_level)
Set Verbosity level of EC API Driver and Library. The level controls amount of data printed to stdout...
void _LIBSNG_CALL sangoma_hwec_initialize_custom_parameter_structure(wan_custom_param_t *custom_param, char *parameter_name, char *parameter_value)
Initialize Custom Paramter structure.
sangoma_status_t _LIBSNG_CALL sangoma_hwec_enable(char *device_name, unsigned int fe_chan_map)
Redirect audio stream from AFT FPGA to EC chip. This command effectively enables echo cancellation si...
wan_iovec_t iovec_list[WAN_IOVEC_LIST_LEN]
sangoma_status_t _LIBSNG_CALL sangoma_hwec_config_tone_detection(char *device_name, int tone_id, int enable, unsigned int fe_chan_map, unsigned char port_map)
Enable/Disable tone detection (such as DTMF) of channels from channel map.