blob: 682d9e2e68e38985f1ef626e552713513d6764b1 [file] [log] [blame]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <pthread.h>
#include <stdbool.h>
#include <dlfcn.h>
static void *ecall_handle = NULL;
typedef struct
{
int cmdIdx;
char *funcName;
}st_api_test_case;
#define GSW_EU_ECALL_MAX_MSD 140
#define GSW_EU_ECALL_MAX_PHONE_NUMBER 82
typedef enum
{
GSW_EU_ECALL_TYPE_TEST = 1,
GSW_EU_ECALL_TYPE_EMERGENCY = 2,
GSW_EU_ECALL_TYPE_RECONFIG = 3,
} gsw_eu_ecall_type_e;
typedef struct
{
uint32_t msd_len;
uint8_t msd[GSW_EU_ECALL_MAX_MSD];
gsw_eu_ecall_type_e type;
int32_t auto_trigger;
char ecall_number[GSW_EU_ECALL_MAX_PHONE_NUMBER];
} gsw_eu_ecall_info_t;
typedef enum {
GSW_EU_ECALL_STATE_NONE = -1,
GSW_EU_ECALL_STATE_INACTIVE = 0,
GSW_EU_ECALL_STATE_ORIGINATING_CALL = 1,
GSW_EU_ECALL_STATE_IN_CALL_TRANSMITTING = 2,
GSW_EU_ECALL_STATE_WAITING_FOR_AL_ACK = 3,
GSW_EU_ECALL_STATE_IN_CALL = 4,
GSW_EU_ECALL_STATE_IDLE_ALLOW_MT_ECALL = 5,
} gsw_eu_ecall_state_e;
typedef enum {
GSW_EU_ECALL_MODE_NORMAL = 0,
GSW_EU_ECALL_MODE_ONLY = 1,
GSW_EU_ECALL_MODE_DEFAULT = 2,
} gsw_eu_ecall_mode_e;
typedef struct
{
uint8_t enable;
uint8_t voice_mute;
gsw_eu_ecall_mode_e mode;
uint8_t report_event;
uint16_t start_timer;
uint16_t hack_timer;
uint16_t trans_timer;
uint8_t fail_redial;
uint8_t drop_redial;
uint16_t cleardown_timer;
uint16_t init_timer;
uint16_t nad_reg_timer;
uint16_t nad_dereg_timer;
uint8_t standard;
uint16_t era_glonass_redial;
uint16_t auto_answer; //auto_answer
} gsw_eu_ecall_config_t;
typedef enum {
GSW_EU_ECALL_CONFIG_ENABLE = (1 << 0),
GSW_EU_ECALL_CONFIG_VOICE_MUTE = (1 << 1),
GSW_EU_ECALL_CONFIG_MODE = (1 << 2),
GSW_EU_ECALL_CONFIG_REPORT_EVENT = (1 << 3),
GSW_EU_ECALL_CONFIG_START_TIMER = (1 << 4),
GSW_EU_ECALL_CONFIG_HACK_TIMER = (1 << 5),
GSW_EU_ECALL_CONFIG_TRANS_TIMER = (1 << 6),
GSW_EU_ECALL_CONFIG_FAIL_REDIAL = (1 << 7),
GSW_EU_ECALL_CONFIG_DROP_REDIAL = (1 << 8),
GSW_EU_ECALL_CONFIG_CLEARDOWN_TIMER = (1 << 9),
GSW_EU_ECALL_CONFIG_INIT_TIMER = (1 << 10),
GSW_EU_ECALL_CONFIG_NAD_REG_TIMER = (1 << 11),
GSW_EU_ECALL_CONFIG_NAD_DEREG_TIMER = (1 << 12),
GSW_EU_ECALL_CONFIG_STANDARD = (1 << 13),
GSW_EU_ECALL_CONFIG_ERA_GLONASS_REDIAL = (1 << 14),
GSW_EU_ECALL_CONFIG_AUTO_ANSWER = (1 << 15),
} gsw_eu_ecall_config_e;
typedef enum {
GSW_EU_ECALL_EVENT_FAIL_NONE = 0,
GSW_EU_ECALL_EVENT_FAIL_TIMEOUT = 1,
GSW_EU_ECALL_EVENT_FAIL_HACK_TIMEOUT = 2,
GSW_EU_ECALL_EVENT_FAIL_MSD_TRANS_TIMEOUT = 3,
GSW_EU_ECALL_EVENT_FAIL_IVS_RESET_TIMEOUT = 4,
GSW_EU_ECALL_EVENT_FAIL_CLEAR_DOWN_FALLBACK_TIMEOUT = 5,
GSW_EU_ECALL_EVENT_FAIL_IVS_INITIATION_TIMEOUT = 6,
} gsw_eu_ecall_event_fail_e;
typedef enum {
GSW_EU_ECALL_EVENT_PROCESS_IVS_NONE = 0,
GSW_EU_ECALL_EVENT_PROCESS_IVS_START_RECEIVED_MSD = 1,
GSW_EU_ECALL_EVENT_PROCESS_IVS_NACK_RECEIVED = 2,
GSW_EU_ECALL_EVENT_PROCESS_IVS_ACK_RECEIVED = 3,
GSW_EU_ECALL_EVENT_PROCESS_IVS_TX_COMPLETED = 4,
GSW_EU_ECALL_EVENT_PROCESS_IVS_HLACK_RECEIVED = 5,
} gsw_eu_ecall_event_process_e;
typedef enum {
GSW_EU_ECALL_EVENT_MSDUPADTE_NONE = -1,
GSW_EU_ECALL_EVENT_MSDUPDATE_IVS_UPDATING_MSD = 0,
GSW_EU_ECALL_EVENT_MSDUPDATE_PSAP_REQURE_UPDATE_MSD = 1,
GSW_EU_ECALL_EVENT_MSDUPDATE_IVS_UPDATE_MSD_TIMEOUT = 2,
} gsw_eu_ecall_event_msdupdate_e;
typedef enum {
GSW_EU_ECALL_EVENT_ESTABLISH_NONE = -1,
GSW_EU_ECALL_EVENT_ESTABLISH_SUCCESS = 0,
GSW_EU_ECALL_EVENT_ESTABLISH_FAIL = 1,
} gsw_eu_ecall_event_establish_e;
typedef enum {
GSW_EU_ECALL_EVENT_EXTEND_STATE_NONE = -1,
GSW_EU_ECALL_EVENT_EXTEND_STATE_START_RECV_SYN = 0,
GSW_EU_ECALL_EVENT_EXTEND_STATE_T9_TIMEOUT = 1,
GSW_EU_ECALL_EVENT_EXTEND_STATE_T10_TIMEOUT = 2,
GSW_EU_ECALL_EVENT_EXTEND_STATE_IVS_ALACK_RECEIVED = 3,
GSW_EU_ECALL_EVENT_EXTEND_STATE_IVS_LLACK_RECEIVED = 4,
GSW_EU_ECALL_EVENT_EXTEND_STATE_STOPPED = 5,
GSW_EU_ECALL_EVENT_EXTEND_STATE_ANSWERING_INCOMING_PSAP_ECALL = 6,
GSW_EU_ECALL_EVENT_EXTEND_STATE_CLEARDOWN_RECEIVED = 7,
GSW_EU_ECALL_EVENT_EXTEND_STATE_CALLBACK_TIMEOUT = 8,
GSW_EU_ECALL_EVENT_IVS_NORMAL_CLEARING = 9,
GSW_EU_ECALL_EVENT_IVS_ABNORMAL_CLEARING = 10,
} gsw_eu_ecall_event_extend_state_e;
typedef struct
{
uint8_t ori_remainder_times;
uint16_t time;
} gsw_eu_ecall_event_originate_fail_redial_t;
typedef struct
{
uint8_t drop_remainder_times;
uint16_t time; /* The minimum time duration between the previous call attempt */
} gsw_eu_ecall_event_drop_redial_t;
typedef struct
{
gsw_eu_ecall_event_fail_e fail;
gsw_eu_ecall_event_process_e process;
gsw_eu_ecall_event_msdupdate_e msdupdate;
gsw_eu_ecall_event_establish_e establish;
uint16_t hack_code;
gsw_eu_ecall_event_originate_fail_redial_t ori_redial;
gsw_eu_ecall_event_drop_redial_t drop_redial;
gsw_eu_ecall_event_extend_state_e extend_state;
} gsw_eu_ecall_event_t;
typedef void (*gsw_eu_ecall_event_cb_f)(gsw_eu_ecall_event_t *p_event);
typedef enum {
GSW_EU_ECALL_MSD_TRANS_STATUS_NONE = -1,
GSW_EU_ECALL_MSD_TRANS_STATUS_SUCCESS = 0,
GSW_EU_ECALL_MSD_TRANS_STATUS_FAILURE = 1,
} gsw_eu_ecall_msd_trans_status_e;
typedef void (*gsw_eu_ecall_status_cb_f)(uint32_t id, gsw_eu_ecall_msd_trans_status_e status);
typedef int32_t (*gsw_eu_ecall_voice_init)(void);
typedef int32_t (*gsw_eu_ecall_voice_deinit)(void);
typedef int32_t (*gsw_eu_ecall_start)(gsw_eu_ecall_info_t *p_info);
typedef int32_t (*gsw_eu_ecall_hangup)(void);
typedef int32_t (*gsw_eu_ecall_updateMsd)(const uint8_t *msd, uint32_t msd_len);
typedef int32_t (*gsw_eu_ecall_pushMsd)(gsw_eu_ecall_state_e state);
typedef int32_t (*gsw_eu_ecall_getConfig)(gsw_eu_ecall_config_t *p_config);
typedef int32_t (*gsw_eu_ecall_setConfig)(int32_t item, gsw_eu_ecall_config_t *p_config);
typedef int32_t (*gsw_eu_ecall_setEventCB)(gsw_eu_ecall_event_cb_f cb);
typedef int32_t (*gsw_eu_ecall_setStatusCB)(gsw_eu_ecall_status_cb_f cb);
st_api_test_case api_testcases[] =
{
{0, "print_help"},
{1, "gsw_eu_ecall_voice_init"},
{2, "gsw_eu_ecall_voice_deinit"},
{3, "gsw_eu_ecall_start"},
{4, "gsw_eu_ecall_hangup"},
{5, "gsw_eu_ecall_updateMsd"},
{6, "gsw_eu_ecall_pushMsd"},
{7, "gsw_eu_ecall_getConfig"},
{8, "gsw_eu_ecall_setConfig"},
{9, "gsw_eu_ecall_setEventCB"},
{10, "gsw_eu_ecall_setStatusCB"},
{-1, NULL}
};
void sigint_handler(int sig)
{
printf("sigint_handler\n");
dlclose(ecall_handle);
ecall_handle = NULL;
exit(0);
}
static void gsw_eu_ecall_status_cb(uint32_t id, gsw_eu_ecall_msd_trans_status_e status)
{
printf("id is %u\n",id);
printf("status is %d\n",status);
}
static void gsw_eu_ecall_event_cb(gsw_eu_ecall_event_t *p_event)
{
printf("p_event->fail: %ud\n",p_event->fail);
printf("p_event->process: %d\n",p_event->process);
printf("p_event->msdupdate: %d\n",p_event->msdupdate);
printf("p_event->establish: %d\n",p_event->establish);
printf("p_event->hack_code: %d\n",p_event->hack_code);
printf("p_event->ori_redial.ori_remainder_times: %d\n",p_event->ori_redial.ori_remainder_times);
printf("p_event->ori_redial.time: %d\n",p_event->ori_redial.time);
printf("p_event->drop_redial.drop_remainder_times: %d\n",p_event->drop_redial.drop_remainder_times);
printf("p_event->drop_redial.time: %d\n",p_event->drop_redial.time);
printf("p_event->extend_state: %d\n",p_event->extend_state);
}
static void set_config(gsw_eu_ecall_config_t *p_config)
{
int ret = -1;
p_config->enable = 0;
p_config->voice_mute = 0;
p_config->mode = 0;
p_config->report_event = 0;
p_config->start_timer = 0;
p_config->hack_timer = 0;
p_config->trans_timer = 0;
p_config->cleardown_timer = 0;
p_config->drop_redial = 0;
p_config->init_timer = 0;
p_config->nad_reg_timer = 0;
p_config->nad_dereg_timer = 0;
p_config->standard = 0;
p_config->era_glonass_redial = 0;
p_config->auto_answer = 0;
printf("input p_config->fail_redial\n");
ret = scanf("%hhu", &p_config->fail_redial);
if(ret)
{
printf("input ret is %d\n",ret);
}
}
static void print_get_config(gsw_eu_ecall_config_t p_config)
{
printf("input p_config.enable: %d\n",p_config.enable);
printf("input p_config.voice_mute:%d\n",p_config.voice_mute);
printf("input p_config.mode:%d\n",p_config.mode);
printf("input p_config.report_event:%d\n",p_config.report_event);
printf("input p_config.start_timer:%d\n",p_config.start_timer);
printf("input p_config.hack_timer:%d\n",p_config.hack_timer);
printf("input p_config.trans_timer:%d\n",p_config.start_timer);
printf("input p_config.fail_redial:%d\n",p_config.fail_redial);
printf("input p_config.drop_redial:%d\n",p_config.drop_redial);
printf("input p_config.cleardown_timer:%d\n",p_config.cleardown_timer);
printf("input p_config.init_timer:%d\n",p_config.init_timer);
printf("input p_config.nad_reg_timer:%d\n",p_config.nad_reg_timer);
printf("input p_config.nad_dereg_timer:%d\n",p_config.nad_dereg_timer);
printf("input p_config.standard:%d\n",p_config.standard);
printf("input p_config.era_glonass_redial:%d\n",p_config.era_glonass_redial);
printf("input p_config.auto_answer:%d\n",p_config.auto_answer);
}
void print_help(void)
{
int i;
printf("Supported test cases:\n");
for(i = 0; ; i++)
{
if(api_testcases[i].cmdIdx == -1)
{
break;
}
printf("%d:\t%s\n", api_testcases[i].cmdIdx, api_testcases[i].funcName);
}
}
//static ecall_init_flag = 0;
int main(int argc,char *argv[])
{
gsw_eu_ecall_voice_init gsw_eu_ecall_voice_init_ptr = NULL;
gsw_eu_ecall_voice_deinit gsw_eu_ecall_voice_deinit_ptr = NULL;
gsw_eu_ecall_start gsw_eu_ecall_start_ptr = NULL;
gsw_eu_ecall_hangup gsw_eu_ecall_hangup_ptr = NULL;
gsw_eu_ecall_updateMsd gsw_eu_ecall_updateMsd_ptr = NULL;
gsw_eu_ecall_pushMsd gsw_eu_ecall_pushMsd_ptr = NULL;
gsw_eu_ecall_getConfig gsw_eu_ecall_getConfig_ptr = NULL;
gsw_eu_ecall_setConfig gsw_eu_ecall_setConfig_ptr = NULL;
gsw_eu_ecall_setEventCB gsw_eu_ecall_setEventCB_ptr = NULL;
gsw_eu_ecall_setStatusCB gsw_eu_ecall_setStatusCB_ptr = NULL;
void *ota_handle = dlopen("/lib/libgsw_lib.so", RTLD_NOW );
if(ota_handle == NULL)
{
printf("open lib failed\n");
return -1;
}
signal(SIGINT, sigint_handler);
ecall_handle = dlopen("/lib/libgsw_lib.so", RTLD_NOW );
if(ecall_handle == NULL)
{
printf("open lib failed\n");
return -1;
}
gsw_eu_ecall_voice_init_ptr = (gsw_eu_ecall_voice_init)dlsym(ecall_handle, "gsw_eu_ecall_voice_init");
if(gsw_eu_ecall_voice_init_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_voice_init failed\n");
return -1;
}
gsw_eu_ecall_voice_deinit_ptr = (gsw_eu_ecall_voice_deinit)dlsym(ecall_handle, "gsw_eu_ecall_voice_deinit");
if(gsw_eu_ecall_voice_deinit_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_voice_deinit failed\n");
return -1;
}
gsw_eu_ecall_start_ptr = (gsw_eu_ecall_start)dlsym(ecall_handle, "gsw_eu_ecall_start");
if(gsw_eu_ecall_start_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_start failed\n");
return -1;
}
gsw_eu_ecall_hangup_ptr = (gsw_eu_ecall_hangup)dlsym(ecall_handle, "gsw_eu_ecall_hangup");
if(gsw_eu_ecall_hangup_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_hangup failed\n");
return -1;
}
gsw_eu_ecall_updateMsd_ptr = (gsw_eu_ecall_updateMsd)dlsym(ecall_handle, "gsw_eu_ecall_updateMsd");
if(gsw_eu_ecall_updateMsd_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_updateMsd failed\n");
return -1;
}
gsw_eu_ecall_pushMsd_ptr = (gsw_eu_ecall_pushMsd)dlsym(ecall_handle, "gsw_eu_ecall_pushMsd");
if(gsw_eu_ecall_pushMsd_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_pushMsd failed\n");
return -1;
}
gsw_eu_ecall_getConfig_ptr = (gsw_eu_ecall_getConfig)dlsym(ecall_handle, "gsw_eu_ecall_getConfig");
if(gsw_eu_ecall_getConfig_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_getConfig failed\n");
return -1;
}
gsw_eu_ecall_setConfig_ptr = (gsw_eu_ecall_setConfig)dlsym(ecall_handle, "gsw_eu_ecall_setConfig");
if(gsw_eu_ecall_setConfig_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_setConfig failed\n");
return -1;
}
gsw_eu_ecall_setEventCB_ptr = (gsw_eu_ecall_setEventCB)dlsym(ecall_handle, "gsw_eu_ecall_setEventCB");
if(gsw_eu_ecall_setEventCB_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_setEventCB failed\n");
return -1;
}
gsw_eu_ecall_setStatusCB_ptr = (gsw_eu_ecall_setStatusCB)dlsym(ecall_handle, "gsw_eu_ecall_setStatusCB");
if(gsw_eu_ecall_setStatusCB_ptr == NULL)
{
printf("dlsym gsw_eu_ecall_setStatusCB failed\n");
return -1;
}
printf("Enter ecall api test \n");
int opt = -1;
while (1)
{
print_help();
int ret = scanf("%d",&opt);
if (ret == 1)
{
printf("输入的整数是:%d\n", opt);
}
switch(opt)
{
case 0 :
{
print_help();
break;
}
case 1 :
{
int32_t ret = -1;
printf("enter gsw_eu_ecall_voice_init");
ret = gsw_eu_ecall_voice_init_ptr();
printf("gsw_eu_ecall_voice_init ret = %d\n", ret);
break;
}
case 2 :
{
int32_t ret = -1;
printf("enter gsw_eu_ecall_voice_deinit\n");
ret = gsw_eu_ecall_voice_deinit_ptr();
printf("gsw_eu_ecall_voice_deinit ret = %d\n", ret);
break;
}
case 3 :
{
printf("enter gsw_eu_ecall_start\n");
gsw_eu_ecall_info_t info;
memset(&info,0,sizeof(info));
int type;
printf("Enter MSD data (hex values, space-separated): ");
ret = scanf("%140s",info.msd);
if(ret)
{
printf("input ret is %d\n",ret);
}
info.msd_len = (uint32_t)strlen((char*)info.msd);
printf("Enter eCall type (1: Test, 2: Emergency, 3: Reconfig):\n ");
ret = scanf("%d", &type);
if(ret)
{
printf("input ret is %d\n",ret);
}
info.type = (gsw_eu_ecall_type_e)type;
printf("Enter auto trigger (0: No, 1: Yes): \n");
ret=scanf("%d", &info.auto_trigger);
if(ret)
{
printf("input ret is %d\n",ret);
}
if(type == 1 || type == 3)
{
// 输入 eCall 号码
printf("Enter eCall number: \n");
ret = scanf("%82s", info.ecall_number);
if(ret)
{
printf("input ret is %d\n",ret);
}
}
ret = gsw_eu_ecall_start_ptr(&info);
printf("gsw_eu_ecall_start ret = %d\n", ret);
break;
}
case 4 :
{
int32_t ret = -1;
printf("enter gsw_eu_ecall_hangup\n");
ret = gsw_eu_ecall_hangup_ptr();
printf("gsw_eu_ecall_hangup ret = %d\n", ret);
break;
}
case 5 :
{
uint8_t msd[100] = "235646023026565";
int32_t ret = -1;
printf("enter gsw_eu_ecall_updateMsd\n");
ret = gsw_eu_ecall_updateMsd_ptr(msd, 100);
printf("gsw_eu_ecall_updateMsd ret = %d\n", ret);
break;
}
case 6 :
{
printf("enter gsw_eu_ecall_pushMsd\n");
gsw_eu_ecall_state_e state = -1;
int32_t ret = -1;
ret = gsw_eu_ecall_pushMsd_ptr(state);
printf("gsw_eu_ecall_pushMsd ret = %d\n", ret);
break;
}
case 7 :
{
printf("enter gsw_eu_ecall_getConfig\n");
gsw_eu_ecall_config_t config;
int32_t ret = -1;
memset(&config,0,sizeof(config));
ret = gsw_eu_ecall_getConfig_ptr(&config);
printf("gsw_eu_ecall_getConfig ret = %d\n", ret);
print_get_config(config);
break;
}
case 8 :
{
printf("enter gsw_eu_ecall_setConfig\n");
gsw_eu_ecall_config_t config;
//config.ori_timeout = 10;
int32_t ret = -1;
int32_t item = 128;
printf("item value %d\n",item);
set_config(&config);
ret = gsw_eu_ecall_setConfig_ptr(item, &config);
printf("gsw_eu_ecall_setConfig ret = %d\n", ret);
break;
}
case 9 :
{
printf("enter gsw_eu_ecall_setEventCB\n");
//gsw_eu_ecall_event_cb_f cb = NULL;
int32_t ret = -1;
ret = gsw_eu_ecall_setEventCB_ptr(gsw_eu_ecall_event_cb);
printf("gsw_eu_ecall_setEventCB ret = %d\n", ret);
break;
}
case 10 :
{
printf("""enter gsw_eu_ecall_setStatusCB\n");
int32_t ret = -1;
ret = gsw_eu_ecall_setStatusCB_ptr(gsw_eu_ecall_status_cb);
printf("gsw_eu_ecall_setStatusCB ret = %d\n", ret);
break;
}
default:
{
printf("default");
print_help();
break;
}
}
}
return 0;
}