#include "gsw_voice_interface.h" | |
#include <dlfcn.h> | |
#include <pthread.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
// mbtk includes | |
typedef unsigned int uint32; | |
typedef unsigned char uint8; | |
typedef unsigned short uint16; | |
typedef void (*mbtk_info_callback_func)(const void* data, int data_len); | |
typedef struct | |
{ | |
int client_fd; | |
pthread_t read_thread_id; | |
int exit_fd[2]; | |
bool is_waitting; | |
pthread_cond_t cond; | |
pthread_mutex_t mutex; | |
pthread_mutex_t send_mutex; | |
// Temp response data. | |
uint16 info_err; | |
uint16 data_len; | |
void *data; | |
//mbtk wyq for server_ready_status add start | |
char server_ready_status; | |
//mbtk wyq for server_ready_status add end | |
mbtk_info_callback_func net_state_cb; | |
mbtk_info_callback_func call_state_cb; | |
mbtk_info_callback_func sms_state_cb; | |
mbtk_info_callback_func radio_state_cb; | |
mbtk_info_callback_func sim_state_cb; | |
mbtk_info_callback_func pdp_state_cb; | |
//add signal by xr | |
mbtk_info_callback_func signal_state_cb; | |
} mbtk_info_handle_t; | |
typedef struct | |
{ | |
uint8 call_wait; | |
uint8 dir1; | |
uint8 dir; | |
uint8 state; | |
uint8 mode; | |
uint8 mpty; | |
char phone_number[100]; | |
uint8 type; | |
uint8 pas; | |
uint8 disconnected_id; | |
uint8 end_reason[128]; | |
} __attribute__((packed)) mbtk_call_info_t; | |
typedef enum { | |
MBTK_CLCC = 1, | |
MBTK_CPAS, | |
MBTK_DISCONNECTED, | |
} mbtk_call_enum; | |
typedef enum { | |
MBTK_CALL_RADY, //MT allows commands from TA/TE | |
MBTK_CALL_UNAVAILABLE, //MT does not allow commands from TA/TE | |
MBTK_CALL_UNKNOWN, //MT is not guaranteed to respond to instructions | |
MBTK_CALL_RINGING, //MT is ready for commands from TA/TE, but the ringer is active | |
MBTK_CALL_PROGRESS, //MT is ready for commands from TA/TE, but a call is in progress | |
MBTK_CALL_ASLEEP, //MT is unable to process commands from TA/TE because it is in a low functionality state | |
MBTK_CALL_ACTIVE, | |
} mbtk_call_pas_enum; | |
//----------------end_reason start------------ | |
//mbtk end_reason define | |
#define MBTK_VOICE_END_REASON_UNKNOWN "0 " | |
#define MBTK_VOICE_END_REASON_UNASSIGNED_NUMBER "1 " | |
#define MBTK_VOICE_END_REASON_NO_ROUTE_DES "3 " | |
#define MBTK_VOICE_END_REASON_CHANNEL_UNACCEPTABLE "6 " | |
#define MBTK_VOICE_END_REASON_OPERATOR_DETERMINED_BARRING "8 " | |
#define MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING "16 " | |
#define MBTK_VOICE_END_REASON_USER_BUSY "17 " | |
#define MBTK_VOICE_END_REASON_NO_USER_RESPONDING "18 " | |
#define MBTK_VOICE_END_REASON_USER_ALERTING_NO_ANSWER "19 " | |
#define MBTK_VOICE_END_REASON_CALL_REJECTED "21 " | |
#define MBTK_VOICE_END_REASON_NUMBER_CHANGED "22 " | |
#define MBTK_VOICE_END_REASON_PREEMPTION "25 " | |
#define MBTK_VOICE_END_REASON_NON_SELECTED_USER_CLEARING "26 " | |
#define MBTK_VOICE_END_REASON_DESTINATION_OUT_OF_ORDER "27 " | |
#define MBTK_VOICE_END_REASON_INVALID_NUMBER_FORMAT "28 " | |
#define MBTK_VOICE_END_REASON_FACILITY_REJECTED "29 " | |
#define MBTK_VOICE_END_REASON_STATUS_ENQUIRY "30 " | |
#define MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED "31 " | |
#define MBTK_VOICE_END_REASON_NO_CIRCUIT_AVAILABLE "34 " | |
#define MBTK_VOICE_END_REASON_NETWORK_OUT_OF_ORDER "38 " | |
#define MBTK_VOICE_END_REASON_TEMPORARY_FAILURE "41 " | |
#define MBTK_VOICE_END_REASON_SWITCHING_EQUIPMENT_CONGESTION "42 " | |
#define MBTK_VOICE_END_REASON_ACCESS_INFORMATION_DISCARDED "43 " | |
#define MBTK_VOICE_END_REASON_REQUESTED_CIRCUIT_UNAVAILABLE "44 " | |
#define MBTK_VOICE_END_REASON_RESOURCE_UNAVAILABLE "47 " | |
#define MBTK_VOICE_END_REASON_QOS_UNAVAILABLE "49 " | |
#define MBTK_VOICE_END_REASON_REQUESTED_FACILITY_NOT_SUBSCRIBED "50 " | |
#define MBTK_VOICE_END_REASON_INCOMING_CALLS_BARRED_WITHIN_CUG "55 " | |
#define MBTK_VOICE_END_REASON_BEARER_CAPABILITY_NOT_AUTHORIZED "57 " | |
#define MBTK_VOICE_END_REASON_BEARER_CAPABILITY_NOT_AVAILABLE "58 " | |
#define MBTK_VOICE_END_REASON_SERVICE_NOT_AVAILABLE "63 " | |
#define MBTK_VOICE_END_REASON_BEARER_SERVICE_NOT_IMPLEMENTED "65 " | |
#define MBTK_VOICE_END_REASON_ACM_MAX_REACHED "68 " | |
#define MBTK_VOICE_END_REASON_FACILITY_NOT_IMPLEMENTED "69 " | |
#define MBTK_VOICE_END_REASON_ONLY_RDI_BEARER_CAPABILITY_AVAILABLE "70 " | |
#define MBTK_VOICE_END_REASON_SERVICE_NOT_IMPLEMENTED "79 " | |
#define MBTK_VOICE_END_REASON_INVALID_TRANSACTION_ID "81 " | |
#define MBTK_VOICE_END_REASON_USER_NOT_MEMBER_OF_CUG "87 " | |
#define MBTK_VOICE_END_REASON_INCOMPATIBLE_DESTINATION "88 " | |
#define MBTK_VOICE_END_REASON_INVALID_TRANSIT_NETWORK_SELECTION "91 " | |
#define MBTK_VOICE_END_REASON_INCORRECT_MESSAGE "95 " | |
#define MBTK_VOICE_END_REASON_INVALID_MANDATORY_INFORMATION "96 " | |
#define MBTK_VOICE_END_REASON_MESSAGE_TYPE_NON_EXISTENT "97 " | |
#define MBTK_VOICE_END_REASON_MESSAGE_TYPE_WRONG_STATE "98 " | |
#define MBTK_VOICE_END_REASON_INFORMATION_ELEMENT_NOT_EXISTENT "99 " | |
#define MBTK_VOICE_END_REASON_CONDITIONAL_IE_ERROR "100 " | |
#define MBTK_VOICE_END_REASON_MESSAGE_WRONG_STATE "101 " | |
#define MBTK_VOICE_END_REASON_RECOVERY_AFTER_TIMER_EXPIRY "102 " | |
#define MBTK_VOICE_END_REASON_PROTOCOL_ERROR_UNSPECIFIED "111 " | |
#define MBTK_VOICE_END_REASON_INERWORKING_UNSPECIFIED "127 " | |
#define MBTK_VOICE_END_REASON_CALL_BARRING "224 " | |
#define MBTK_VOICE_END_REASON_FDN_BLOCKED "241 " | |
#define MBTK_VOICE_END_REASON_END "end" | |
typedef enum{ | |
GSW_LOCAL_END_NORMAL = 0, | |
GSW_PEER_END_NORMAL, | |
GSW_OTHER_END_NORMAL, | |
GSW_END_ABNORMAL, | |
} gsw_call_end_reason_enum; | |
const char* g_normal_end_reason[] = { | |
MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING, | |
MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED, | |
}; | |
int gsw_global_end_reason = GSW_OTHER_END_NORMAL; | |
//----------------end_reason end------------ | |
typedef uint32_t voice_client_handle_type; | |
static mbtk_info_handle_t* call_info_handle = NULL; | |
static int level_call = 0; | |
int gsw_voice_init_flag = 0; | |
int auto_answer_flag = 0; | |
voice_client_handle_type g_call_val = -1; | |
CallStateInd gsw_voice_callback = NULL; | |
int state_t = 0; | |
char* phone_num_t = NULL; | |
char* phone_num_t2 = NULL; | |
int call_id_t = 0; | |
int call_id_t2 = 0; | |
#define lib_mbtk_path "/lib/libmbtk_lib.so" | |
static void *dlHandle_mbtk; | |
static mbtk_info_handle_t* (*mbtk_info_handle_get)(void); | |
int (*mbtk_call_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb); | |
int (*mbtk_call_start)(mbtk_info_handle_t* handle, char* phone_number); | |
int (*mbtk_call_hang)(mbtk_info_handle_t* handle); | |
int (*mbtk_a_call_hang)(mbtk_info_handle_t* handle, int phone_id); | |
int (*mbtk_call_answer)(mbtk_info_handle_t* handle); | |
int (*mbtk_call_reg_get)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg); | |
static void (*mbtk_log)(int level, const char *format, ...); | |
static void (*mbtk_log_init)(char *path, char *tag); | |
/*rtp begin*/ | |
int (*mbtk_rtp_init)(); | |
int (*mbtk_rtp_deinit)(); | |
int (*mbtk_rtp_enable)(bool enable); | |
int (*mbtk_rtp_remote_ip_set)(const char *ipv4); | |
int (*mbtk_rtp_server_port_set)(int port); | |
int (*mbtk_rtp_client_port_set)(int port); | |
int (*mbtk_rtp_sample_rate_set)(int sample_rate); | |
int (*mbtk_rtp_channel_set)(int channel); | |
int (*mbtk_rtp_vlan_set)(const char *vlan); | |
/*rtp end*/ | |
#ifndef LOG_ERR_LEVEL | |
#define LOG_ERR_LEVEL 3 /* error conditions */ | |
#endif | |
#ifndef LOG_WARN_LEVEL | |
#define LOG_WARN_LEVEL 4 /* warning conditions */ | |
#endif | |
#ifndef LOG_INFO_LEVEL | |
#define LOG_INFO_LEVEL 6 /* informational */ | |
#endif | |
#ifndef LOG_DEBUG_LEVEL | |
#define LOG_DEBUG_LEVEL 7 /* debug-level messages */ | |
#endif | |
#ifndef LOG_VERBOSE_LEVEL | |
#define LOG_VERBOSE_LEVEL 8 | |
#endif | |
#define GSW_VOICE "[HAL][GSW_VOICE]" | |
#define LOGV(fmt, args ...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define LOGI(fmt, args...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define LOGD(fmt, args...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define LOGW(fmt, args...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define LOGE(fmt, args...) \ | |
do{ \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \ | |
} while(0) | |
#define MODULE_INIT_CHECK(init_flag) \ | |
if(init_flag == 0) \ | |
{ \ | |
return GSW_HAL_ERROR_GNSS_DATA_CALL_DEINIT; \ | |
} | |
#define VOICE_MODULE_INIT_CHECK() MODULE_INIT_CHECK(gsw_voice_init_flag) | |
static int mbtk_rtp_api_import() | |
{ | |
mbtk_rtp_init = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_init"); | |
if (mbtk_rtp_init == NULL) | |
{ | |
LOGE("mbtk_rtp_init dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_rtp_deinit = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_deinit"); | |
if (mbtk_rtp_deinit == NULL) | |
{ | |
LOGE("mbtk_rtp_deinit dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_rtp_enable = (int (*)(bool enable))dlsym(dlHandle_mbtk, "mbtk_rtp_enable"); | |
if (mbtk_rtp_enable == NULL) | |
{ | |
LOGE("mbtk_rtp_enable dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_rtp_remote_ip_set = (int (*)(const char *ipv4))dlsym(dlHandle_mbtk, "mbtk_rtp_remote_ip_set"); | |
if (mbtk_rtp_remote_ip_set == NULL) | |
{ | |
LOGE("mbtk_rtp_remote_ip_set dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_rtp_server_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_server_port_set"); | |
if (mbtk_rtp_server_port_set == NULL) | |
{ | |
LOGE("mbtk_rtp_server_port_set dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_rtp_client_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_client_port_set"); | |
if (mbtk_rtp_client_port_set == NULL) | |
{ | |
LOGE("mbtk_rtp_client_port_set dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_rtp_sample_rate_set = (int (*)(int sample_rate))dlsym(dlHandle_mbtk, "mbtk_rtp_sample_rate_set"); | |
if (mbtk_rtp_sample_rate_set == NULL) | |
{ | |
LOGE("mbtk_rtp_sample_rate_set dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_rtp_channel_set = (int (*)(int channel))dlsym(dlHandle_mbtk, "mbtk_rtp_channel_set"); | |
if (mbtk_rtp_channel_set == NULL) | |
{ | |
LOGE("mbtk_rtp_channel_set dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_rtp_vlan_set = (int (*)(const char *vlan))dlsym(dlHandle_mbtk, "mbtk_rtp_vlan_set"); | |
if (mbtk_rtp_vlan_set == NULL) | |
{ | |
LOGE("mbtk_rtp_vlan_set dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
static int mbtk_call_api_import() | |
{ | |
dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW); | |
if (dlHandle_mbtk == NULL) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init"); | |
if (mbtk_log_init == NULL) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log"); | |
if (mbtk_log == NULL) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get"); | |
if (mbtk_info_handle_get == NULL) | |
{ | |
LOGE("mbtk_info_handle_get dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_call_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_call_state_change_cb_reg"); | |
if(mbtk_call_state_change_cb_reg == NULL) | |
{ | |
LOGE("mbtk_call_state_change_cb_reg dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_call_start = (int (*)(mbtk_info_handle_t* handle, char* phone_number))dlsym(dlHandle_mbtk, "mbtk_call_start"); | |
if(mbtk_call_start == NULL) | |
{ | |
LOGE("mbtk_call_start dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_call_answer = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_answer"); | |
if(mbtk_call_answer == NULL) | |
{ | |
LOGE("mbtk_call_answer dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_call_hang = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_hang"); | |
if(mbtk_call_hang == NULL) | |
{ | |
LOGE("mbtk_call_hang dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_a_call_hang = (int (*)(mbtk_info_handle_t* handle, int phone_id))dlsym(dlHandle_mbtk, "mbtk_a_call_hang"); | |
if(mbtk_a_call_hang == NULL) | |
{ | |
LOGE("mbtk_a_call_hang dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_call_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_call_reg_get"); | |
if(mbtk_call_reg_get == NULL) | |
{ | |
LOGE("mbtk_call_reg_get dlsym fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return mbtk_rtp_api_import(); | |
} | |
static void end_reason_mbtk_to_gsw(char* mbtk_reason) | |
{ | |
LOGE("mbtk_reason:%s\n", mbtk_reason); | |
gsw_global_end_reason = GSW_END_ABNORMAL; | |
int length=sizeof (g_normal_end_reason)/ sizeof(g_normal_end_reason[0]); | |
for(int i = 0; i<length; i++) | |
{ | |
if(0 == strncmp(mbtk_reason, g_normal_end_reason[i], strlen(g_normal_end_reason[i]))) | |
{ | |
gsw_global_end_reason=GSW_OTHER_END_NORMAL; | |
return; | |
} | |
} | |
return; | |
} | |
void gsw_call_state_change_cb(const void *data, int data_len) | |
{ | |
mbtk_call_info_t *reg = (mbtk_call_info_t *)data; | |
switch (reg->call_wait) | |
{ | |
case MBTK_CLCC: | |
{ | |
LOGD("RING : %d, %d, %d, %d, %d, %s, %d, %d, end_reason:%s", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->disconnected_id, reg->end_reason); | |
//printf("RING : %d, %d, %d, %d, %d, %s, %d, %d, end_reason:%s\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->disconnected_id, reg->end_reason); | |
switch(reg->state) | |
{ | |
case 0: | |
state_t = GSW_VOICE_CALL_CONNECTED; | |
break; | |
case 1: | |
state_t = GSW_VOICE_CALL_HOLDING; | |
break; | |
case 2: | |
state_t = GSW_VOICE_CALL_DIALING; | |
break; | |
case 3: | |
state_t = GSW_VOICE_CALL_ALERTING; | |
break; | |
case 4: | |
state_t = GSW_VOICE_CALL_INCOMING; | |
break; | |
case 5: | |
state_t = GSW_VOICE_CALL_WAITING; | |
break; | |
case 6: | |
{ | |
state_t = GSW_VOICE_CALL_END; | |
call_id_t = reg->dir1; | |
end_reason_mbtk_to_gsw((char *)reg->end_reason); | |
break; | |
} | |
} | |
if(gsw_voice_callback) | |
{ | |
gsw_voice_callback(reg->dir1, state_t); | |
} | |
} | |
break; | |
case MBTK_DISCONNECTED: | |
{ | |
LOGD("RING : call dis connected!"); | |
LOGD("RING : %d, %d, %d, %d, %d, %s, %d, %d, end_reason:%s", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->disconnected_id, reg->end_reason); | |
//printf("RING : %d, %d, %d, %d, %d, %s, %d, %d, end_reason:%s\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->disconnected_id, reg->end_reason); | |
state_t = GSW_VOICE_CALL_END; | |
call_id_t = reg->dir1; | |
end_reason_mbtk_to_gsw((char *)reg->end_reason); | |
if(gsw_voice_callback) | |
{ | |
gsw_voice_callback(reg->disconnected_id, state_t); | |
} | |
} | |
break; | |
case MBTK_CPAS: | |
LOGD("CALL : Call state = %d", reg->pas); | |
switch (reg->pas) | |
{ | |
case MBTK_CALL_RADY: | |
LOGD("CALL: call READY"); | |
break; | |
case MBTK_CALL_UNAVAILABLE: | |
LOGD("CALL: call unavaliable"); | |
break; | |
case MBTK_CALL_UNKNOWN: | |
LOGD("CALL: call unknown"); | |
break; | |
case MBTK_CALL_RINGING: | |
LOGD("CALL: call ringing"); | |
break; | |
case MBTK_CALL_PROGRESS: | |
LOGD("CALL: call progress"); | |
break; | |
case MBTK_CALL_ASLEEP: | |
LOGD("CALL: call asleep"); | |
break; | |
case MBTK_CALL_ACTIVE: | |
LOGD("CALL: call active"); | |
break; | |
default: | |
//LOGE("\r\n"); | |
break; | |
} | |
break; | |
default: | |
LOGE("RING : None call_wait = %d", reg->call_wait); | |
break; | |
} | |
} | |
/** | |
* @brief init voice sdk,and register the status indicated callback function | |
* @param [in] CallStateInd ind: status indicated callback function | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_sdk_init(CallStateInd ind) | |
{ | |
int ret; | |
if (gsw_voice_init_flag == 1 && call_info_handle != NULL) | |
{ | |
return GSW_HAL_SUCCESS; | |
} | |
if(ind == NULL) | |
{ | |
LOGE("parameter is null\n"); | |
return GSW_HAL_ARG_INVALID; | |
} | |
ret = mbtk_call_api_import(); | |
if(ret != 0) | |
{ | |
if(mbtk_log != NULL) | |
{ | |
LOGE("[gsw_voice_sdk_init]mbtk_call_api_import fail\n"); | |
} | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
mbtk_log_init("syslog", "MBTK_RIL"); | |
if(ret < 0) | |
{ | |
LOGE("mbtk_call_api_import fail,ret = %d\n",ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
ret=mbtk_rtp_init(); | |
if(ret!=0) | |
{ | |
LOGE("[gsw_voice_sdk_init]mbtk_rtp_init fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
if(call_info_handle == NULL) | |
{ | |
call_info_handle = mbtk_info_handle_get(); | |
if(call_info_handle != NULL) | |
{ | |
LOGE("create gsw_voice_sdk_init success\n"); | |
ret = mbtk_call_state_change_cb_reg(call_info_handle, gsw_call_state_change_cb); | |
if(ret) | |
{ | |
LOGE("mbtk_call_state_change_cb_reg fail,ret = %d\n",ret); | |
(void) mbtk_rtp_deinit(); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
else | |
{ | |
gsw_voice_init_flag = 1; | |
gsw_voice_callback = ind; | |
LOGE("create gsw_voice_sdk_init success\n"); | |
return GSW_HAL_SUCCESS; | |
} | |
} | |
else | |
{ | |
(void) mbtk_rtp_deinit(); | |
LOGE("create gsw_voice_sdk_init fail\n"); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief set speaker_volume | |
* @param [in] int32_t volume:1(Min)-7(Max) | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_set_speaker_volume(int32_t volume) | |
{ | |
//UNUSED(volume); | |
VOICE_MODULE_INIT_CHECK(); | |
char cmd[128] = {0}; | |
int lv = 0; | |
memset(cmd ,0x00, sizeof(cmd)); | |
if(volume < 1 || volume > 7) | |
{ | |
LOGE("Error volume : %d", volume); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
else | |
{ | |
switch(volume) | |
{ | |
case 1 : | |
lv = -36; | |
break; | |
case 2 : | |
lv = -36; | |
break; | |
case 3 : | |
lv = -27; | |
break; | |
case 4 : | |
lv = -18; | |
break; | |
case 5 : | |
lv = -9; | |
break; | |
case 6 : | |
lv = 0; | |
break; | |
case 7: | |
lv = 12; | |
break; | |
default: | |
break; | |
} | |
} | |
sprintf(cmd, "ubus call audio_if config_dspgain \"{\'type\':%d,\'gain\':%d}\"", 1, lv); | |
// sLOGE(cmd, "ubus call audio_if volume_set \'{\"param0\":%d}\'", lv); | |
int err = system(cmd); | |
if ((err != -1) && (err != 127)) | |
{ | |
LOGE("Set success."); | |
level_call = volume; | |
} | |
else | |
{ | |
LOGE("Error : %d", err); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief start a voice call | |
* @param [in] char *callNumber | |
* @param [out] CallHandle *handle | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_normal_voice_start(CallHandle *handle, const char *callNumber) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
mbtk_call_info_t reg = {0}; | |
int ret = -1; | |
if(handle == NULL) | |
{ | |
LOGE("handle is null\n"); | |
return GSW_HAL_ARG_INVALID; | |
} | |
if(callNumber == NULL) | |
{ | |
LOGE("callNumber is null\n"); | |
return GSW_HAL_ARG_INVALID; | |
} | |
ret = mbtk_call_start(call_info_handle, (char *)callNumber); | |
if(ret != 0) | |
{ | |
LOGE("mbtk_call_start fail,ret = %d\n",ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
//get call id | |
mbtk_call_reg_get(call_info_handle, ®); | |
LOGE("call id = %d\n",reg.dir1); | |
*handle = reg.dir1; | |
LOGE("gsw_voice_normal_voice_start id = %d\n", (int)*handle); | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief answer a voice call | |
* @param [in] CallHandle handle | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_answer(CallHandle handle) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
int ret = -1; | |
ret = mbtk_call_answer(call_info_handle); | |
if(ret != 0) | |
{ | |
LOGE("mbtk_call_answer fail,ret = %d\n", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
else | |
{ | |
LOGE("mbtk_call_answer success\n"); | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief hangup a voice call | |
* @param [in] CallHandle handle | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_hangup(CallHandle handle) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
int ret = -1; | |
ret = mbtk_a_call_hang(call_info_handle,handle); | |
if(ret != 0) | |
{ | |
LOGE("mbtk_a_call_hang fail,ret = %d\n", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
else | |
{ | |
LOGE("mbtk_a_call_hang success\n"); | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief set auto answer mode | |
* @param [in] int32_t mode:0-1, 0:NO(close auto answer), 1:YES(auto answer) | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_set_auto_answer_mode(int32_t mode) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
if(mode == 1) | |
{ | |
int ret = -1; | |
ret = mbtk_call_answer(call_info_handle); | |
if(ret != 0) | |
{ | |
LOGE("mbtk_call_answer fail,ret = %d\n", ret); | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
else | |
{ | |
LOGE("mbtk_call_answer success\n"); | |
} | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
int32_t gsw_voice_get_current_call_end_reason(CallHandle handle) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
return gsw_global_end_reason; | |
} | |
/*##########################################rtp begin*/ | |
/** | |
* @brief set audio mode | |
* @param [in] AudioMode audioMode | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_set_audio_mode(AudioMode audioMode) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
int ret=mbtk_rtp_enable(audioMode); | |
if(ret !=0 ) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief set rtp ip address of remote | |
* @param [in] char *ip :ip address | |
* @param [in] int32_t len: length | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_set_remote_rtp_ip(const char *ip, int32_t len) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
int ret=mbtk_rtp_remote_ip_set(ip); | |
if(ret !=0 ) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief set rtp mode and port | |
* @param [in] RTPMode rtpMode: rtp mode | |
* @param [in] int32_t port:rtp port | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_set_rtp_port(RTPMode rtpMode, int32_t port) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
int ret; | |
if(rtpMode==GSW_RTP_CLIENT) | |
{ | |
ret = mbtk_rtp_client_port_set(port); | |
} | |
else | |
{ | |
ret = mbtk_rtp_server_port_set(port); | |
} | |
if(ret !=0 ) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief set rtp mode and port | |
* @param [in] int32_t clockRate: clock rate | |
* @param [in] int32_t channel:channel | |
* @param [in] int32_t latency:latency | |
* @param [out] None | |
* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL | |
*/ | |
int32_t gsw_voice_set_rtp_param(int32_t clockRate, int32_t channel, int32_t latency) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
int ret=mbtk_rtp_channel_set(channel); | |
if(ret==0) | |
{ | |
ret=mbtk_rtp_sample_rate_set(clockRate); | |
} | |
if(ret !=0 ) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/** | |
* @brief set rtp vlan | |
* @param [in] interfaceName network interface name | |
* @retval 0: success | |
* @retval other: fail | |
*/ | |
int32_t gsw_voice_set_rtp_vlan_info(const char *interfaceName) | |
{ | |
VOICE_MODULE_INIT_CHECK(); | |
int ret=mbtk_rtp_vlan_set(interfaceName); | |
if(ret !=0 ) | |
{ | |
return GSW_HAL_NORMAL_FAIL; | |
} | |
return GSW_HAL_SUCCESS; | |
} | |
/*##########################################rtp end*/ | |