#include <stdio.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <arpa/inet.h> | |
#include <fcntl.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <binder/Parcel.h> | |
#include <log/log.h> | |
#include "lynq_call.h" | |
#include <cutils/jstring.h> | |
#include <pthread.h> | |
#include "liblog/lynq_deflog.h" | |
#include <sys/time.h> | |
#define LYNQ_SERVICE_PORT 8088 | |
#define LYNQ_URC_SERVICE_PORT 8086 | |
#define LYNQ_REC_BUF 8192 | |
#define LYNQ_REQUEST_PARAM_BUF 8192 | |
#define LYQN_SEDN_BUF 1024*8+sizeof(int)*3 | |
#define USER_LOG_TAG "LYNQ_CALL" | |
using ::android::Parcel; | |
typedef enum { | |
LYNQ_CALL_ACTIVE = 0, | |
LYNQ_CALL_HOLDING = 1, | |
LYNQ_CALL_DIALING = 2, /* MO call only */ | |
LYNQ_CALL_ALERTING = 3, /* MO call only */ | |
LYNQ_CALL_INCOMING = 4, /* MT call only */ | |
LYNQ_CALL_WAITING = 5 ,/* MT call only */ | |
}lynq_call_state_t; | |
typedef struct{ | |
int uToken; | |
int request; | |
int paramLen; | |
char param[LYNQ_REQUEST_PARAM_BUF]; | |
}lynq_client_t; | |
typedef struct | |
{ | |
int used; | |
int call_id; | |
int call_state; | |
int toa; | |
int direction;/*0: MO call,1:MT call*/ | |
char addr[LYNQ_PHONE_NUMBER_MAX]; | |
int hasTimeout; | |
}lynq_call_list_e_t; | |
typedef struct | |
{ | |
int call_id; | |
int call_state; | |
int toa; | |
int direction;/*0: MO call,1:MT call*/ | |
char addr[LYNQ_PHONE_NUMBER_MAX]; | |
}lynq_call_list_t; | |
lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={}; | |
static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER; | |
static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER; | |
static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER; | |
static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER; | |
static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER; | |
static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER; | |
int s_urc_event_complete = 1; | |
enum{ | |
CALL_OFF=0, | |
CALL_ON=1 | |
}call_state; | |
typedef enum{ | |
LYNQ_E_CARDSTATE_ERROR=8000, | |
/* The voice service state is out of service*/ | |
LYNQ_E_STATE_OUT_OF_SERVICE=8001, | |
/* The voice service state is EMERGENCY_ONLY*/ | |
LYNQ_E_STATE_EMERGENCY_ONLY=8002, | |
/* The radio power is power off*/ | |
LYNQ_E_STATE_POWER_OFF=8003, | |
LYNQ_E_TIME_OUT=8004, | |
/*create or open sms DB fail */ | |
LYNQ_E_SMS_DB_FAIL=8005, | |
/*Failed to execute sql statement*/ | |
LYNQ_E_SMS_SQL_FAIL = 8006, | |
LYNQ_E_SMS_NOT_FIND = 8007, | |
/* The logic conflict*/ | |
LYNQ_E_CONFLICT=9000, | |
/*Null anomaly*/ | |
LYNQ_E_NULL_ANONALY=9001 | |
}LYNQ_E; | |
int lynq_call_state =CALL_OFF; | |
int lynq_client_sockfd = 0; | |
int Global_uToken = 0; | |
int global_call_count =0; | |
int global_call_auto_answer = 0; | |
bool urc_recive_status = 1; | |
bool call_list_loop = 1; | |
int isDial = 0; | |
int lynqIncomingCallId = 0; | |
int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error) | |
{ | |
if(p.dataAvail() > 0) | |
{ | |
p.readInt32(resp_type); | |
p.readInt32(request); | |
p.readInt32(slot_id); | |
p.readInt32(error); | |
return 0; | |
} | |
else | |
{ | |
return -1; | |
} | |
} | |
int send_request(int sockfd,lynq_client_t *client_tmp) | |
{ | |
int ret=0; | |
ret = write(sockfd, client_tmp, LYQN_SEDN_BUF); | |
if(ret==-1) | |
{ | |
perror("write error"); | |
return -1; | |
} | |
return 0; | |
} | |
int get_response(int sockfd,Parcel &p) | |
{ | |
int len = 0; | |
char recvline[LYNQ_REC_BUF]; | |
bzero(recvline,LYNQ_REC_BUF); | |
/* receive data from server */ | |
len = read(sockfd, recvline, LYNQ_REC_BUF); | |
if(len == -1) | |
{ | |
perror("read error"); | |
return -1; | |
} | |
printf("===>n=%d\n",len); | |
if (recvline != NULL) { | |
p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen); | |
p.setDataPosition(0); | |
} | |
return 0; | |
} | |
static char *strdupReadString(Parcel &p) { | |
size_t stringlen; | |
const char16_t *s16; | |
s16 = p.readString16Inplace(&stringlen); | |
return strndup16to8(s16, stringlen); | |
} | |
int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX]) | |
{ | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
int call_num = 0; | |
int temp = 0; | |
char *remote_phoneNum = NULL; | |
char *remote_name= NULL; | |
char *uusData = NULL; | |
client.uToken = Global_uToken; | |
client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS | |
client.paramLen = 0; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
if(error == 0) | |
{ | |
p.readInt32(&call_num); | |
global_call_count = call_num; | |
if(call_num<=0) | |
{ | |
lynq_call_state = CALL_OFF; | |
return 0; | |
} | |
for(int i = 0;i < call_num;i++) | |
{ | |
p.readInt32(&temp); | |
call_list[i].call_state = temp; | |
p.readInt32(&call_list[i].call_id); | |
p.readInt32(&call_list[i].toa); | |
p.readInt32(&temp); | |
p.readInt32(&temp); | |
call_list[i].direction = temp; | |
p.readInt32(&temp); | |
p.readInt32(&temp); | |
p.readInt32(&temp); | |
remote_phoneNum = strdupReadString(p); | |
memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum)); | |
LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state, | |
call_list[i].direction,call_list[i].addr,call_list[i].toa); | |
p.readInt32(&temp); | |
remote_name = strdupReadString(p); | |
p.readInt32(&temp); | |
p.readInt32(&temp); | |
if(temp==0) | |
{ | |
continue; | |
} | |
p.readInt32(&temp); /* UUS Information is present */ | |
p.readInt32(&temp); | |
p.readInt32(&temp); | |
p.read(uusData,temp); | |
} | |
} | |
return 0; | |
} | |
void cleanCallList(int lynq_call_id) | |
{ | |
lynq_call_lists[lynq_call_id].call_id = 0; | |
lynq_call_lists[lynq_call_id].call_state = 0; | |
lynq_call_lists[lynq_call_id].toa = 0; | |
lynq_call_lists[lynq_call_id].direction = 0; | |
lynq_call_lists[lynq_call_id].used = 0; | |
lynq_call_lists[lynq_call_id].hasTimeout = 0; | |
memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr)); | |
} | |
int getUnusedElement() | |
{ | |
for(int i=0;i < LYNQ_CALL_MAX; i++) | |
{ | |
if(lynq_call_lists[i].used!=1) | |
{ | |
return i; | |
} | |
} | |
return -1; | |
} | |
int updateAddr(char addr[]) | |
{ | |
int ret = 0; | |
ret = getUnusedElement(); | |
memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1); | |
lynq_call_lists[ret].used = 1; | |
return ret; | |
} | |
void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction) | |
{ | |
callList->call_id = call_id; | |
callList->call_state = call_state; | |
callList->toa = toa; | |
callList->direction = direction; | |
callList->used = 1; | |
callList->hasTimeout = 0; | |
return; | |
} | |
int waitCallstateChange(int mtime) | |
{ | |
int ret = 0; | |
int sec = 0; | |
int usec = 0; | |
struct timeval now; | |
struct timespec timeout; | |
gettimeofday(&now,NULL); | |
sec = mtime/1000; | |
usec = mtime%1000; | |
timeout.tv_sec = now.tv_sec+sec; | |
timeout.tv_nsec = now.tv_usec*1000+usec*1000000; | |
pthread_mutex_lock(&call_state_change_mutex); | |
ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout); | |
pthread_mutex_unlock(&call_state_change_mutex); | |
return ret; | |
} | |
int waitIncomingCall() | |
{ | |
int ret = 0; | |
pthread_mutex_lock(&s_incoming_call_mutex); | |
ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex); | |
pthread_mutex_unlock(&s_incoming_call_mutex); | |
return ret; | |
} | |
int checkHasCall(char addr[]) | |
{ | |
for(int i = 0;i<LYNQ_CALL_MAX;i++) | |
{ | |
if(strcmp(lynq_call_lists[i].addr,addr)==0) | |
{ | |
return 1; | |
} | |
} | |
return 0; | |
} | |
void sendSignalToWaitCallStateChange() | |
{ | |
pthread_mutex_lock(&call_state_change_mutex); | |
pthread_cond_signal(&call_state_change_cond); | |
pthread_mutex_unlock(&call_state_change_mutex); | |
} | |
void sendSignalIncomingCall() | |
{ | |
pthread_mutex_lock(&s_incoming_call_mutex); | |
pthread_cond_signal(&s_incoming_call_cond); | |
pthread_mutex_unlock(&s_incoming_call_mutex); | |
} | |
void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX]) | |
{ | |
callList->call_id = call_id; | |
callList->call_state = call_state; | |
callList->toa = toa; | |
callList->direction = direction; | |
memcpy(callList->addr,addr,strlen(addr)+1); | |
callList->used = 1; | |
callList->hasTimeout = 0; | |
return; | |
} | |
void *triggerGetCallList(void *parg) | |
{ | |
int ret=0; | |
lynq_call_list_t call_list[LYNQ_CALL_MAX]; | |
while(call_list_loop) | |
{ | |
pthread_mutex_lock(&s_urc_call_state_change_mutex); | |
pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex); | |
LYDBGLOG("triggerGetCallList event!!!\n"); | |
memset(call_list,0,sizeof(call_list)); | |
ret = lynq_get_current_call_list(call_list); | |
if(ret != 0) | |
{ | |
printf("get current call list failure!!!\n"); | |
break; | |
} | |
for(int i = 0;i < LYNQ_CALL_MAX;i++) | |
{ | |
if(call_list[i].direction == 1)//MT call | |
{ | |
if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */ | |
{ | |
if(!checkHasCall(call_list[i].addr)) | |
{ | |
lynqIncomingCallId = getUnusedElement(); | |
addCallListToLynqCallList(&lynq_call_lists[lynqIncomingCallId],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction,call_list[i].addr); | |
sendSignalIncomingCall(); | |
} | |
} | |
} | |
else | |
{ | |
if(call_list[i].call_id==0) | |
{ | |
break; | |
} | |
for(int n = 0 ; n < LYNQ_CALL_MAX; n++) | |
{ | |
if(lynq_call_lists[n].hasTimeout==1) | |
{ | |
/*hangup call with id*/ | |
lynq_call_hungup(&n); | |
lynq_call_lists[n].hasTimeout==0; | |
continue; | |
} | |
if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0) | |
{ | |
updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction); | |
} | |
} | |
LYDBGLOG("[count:%d]call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",i,call_list[i].call_id,call_list[i].call_state, | |
call_list[i].direction,call_list[i].addr,call_list[i].toa); | |
} | |
} | |
s_urc_event_complete = 1; | |
if(isDial==1) | |
{ | |
sendSignalToWaitCallStateChange(); | |
isDial = 0; | |
} | |
pthread_mutex_unlock(&s_urc_call_state_change_mutex); | |
} | |
return NULL; | |
} | |
void lynqRespWatingEvent() | |
{ | |
if(s_urc_event_complete==1) | |
{ | |
pthread_mutex_lock(&s_urc_call_state_change_mutex); | |
pthread_cond_signal(&s_urc_call_state_change_cond); | |
s_urc_event_complete = 0; | |
pthread_mutex_unlock(&s_urc_call_state_change_mutex); | |
} | |
return; | |
} | |
/*Warren add for T800 platform 2021/11/19 start*/ | |
int lynq_socket_client_start() | |
{ | |
struct sockaddr_in lynq_socket_server_addr; | |
/* init lynq_socket_server_addr */ | |
bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)); | |
lynq_socket_server_addr.sin_family = AF_INET; | |
lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT); | |
lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY); | |
/* | |
if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0) | |
{ | |
printf("[%s] is not a valid IPaddress\n", argv[1]); | |
exit(1); | |
} | |
*/ | |
lynq_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0); | |
if(connect(lynq_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1) | |
{ | |
perror("connect error"); | |
return -1; | |
} | |
return 0; | |
} | |
int lynq_update_call_list_loop() | |
{ | |
int ret = 0; | |
pthread_t tid; | |
pthread_attr_t attr; | |
pthread_attr_init(&attr); | |
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
ret = pthread_create(&tid,&attr,triggerGetCallList,NULL); | |
if(ret < 0) | |
{ | |
LYERRLOG("lynq_update_call_list_loop fail!!!"); | |
return -1; | |
} | |
LYDBGLOG("lynq_update_call_list_loop success!!!\n"); | |
return 0; | |
} | |
void *thread_urc_recv(void *parg) | |
{ | |
int socket_fd = (int64_t)parg; | |
int len=0; | |
socklen_t addr_len=0; | |
uint8_t *dataLength = NULL; | |
char urc_data[LYNQ_REC_BUF]; | |
int slot_id = -1; | |
int resp_type = -1; | |
int urcid = -1; | |
Parcel *p = NULL; | |
struct sockaddr_in dest_addr; | |
LYINFLOG("thread_urc_recv in running....\n"); | |
while(urc_recive_status) | |
{ | |
bzero(urc_data,LYNQ_REC_BUF); | |
//get data msg | |
//LYINFLOG("%s urc pre\n", __FUNCTION__); | |
len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len); | |
//LYINFLOG("%s urc begin\n", __FUNCTION__); | |
if(len <= 0) | |
{ | |
perror("thread_urc_recv step2 fail:"); | |
break; | |
} | |
//LYDBGLOG("=====>urc data len<=====:%d\n",len); | |
p = new Parcel(); | |
if(p==NULL) | |
{ | |
RLOGD("new parcel failure!!!"); | |
break; | |
} | |
p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen); | |
p->setDataPosition(0); | |
if(p->dataAvail() > 0) | |
{ | |
p->readInt32(&resp_type); | |
p->readInt32(&urcid); | |
p->readInt32(&slot_id); | |
//LYERRLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); | |
switch (urcid) | |
{ | |
case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED | |
{ | |
LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); | |
lynqRespWatingEvent(); | |
printf("%s state change\n", __FUNCTION__); | |
break; | |
} | |
case 1018://RIL_UNSOL_CALL_RING | |
{ | |
if(global_call_auto_answer==1) | |
{ | |
lynq_call_answer(); | |
} | |
break; | |
} | |
case 1029://RIL_UNSOL_RINGBACK_TONE | |
case 3049://RIL_UNSOL_CALL_INFO_INDICATION | |
{ | |
LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id); | |
break; | |
} | |
default: | |
break; | |
} | |
} | |
delete p; | |
p = NULL; | |
} | |
close(socket_fd); | |
} | |
int lynq_socket_urc_start() | |
{ | |
int socket_fd=0; | |
int rt=0; | |
int len=0; | |
int on=1; | |
struct sockaddr_in urc_local_addr; | |
pthread_t tid; | |
pthread_attr_t attr; | |
socket_fd = socket(AF_INET,SOCK_DGRAM,0); | |
printf("test 001\n"); | |
if(socket_fd < 0) | |
{ | |
perror("creaet socket for udp fail"); | |
return -1; | |
} | |
urc_local_addr.sin_family = AF_INET; | |
urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT); | |
urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY); | |
/* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/ | |
rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on); | |
if(rt<0) | |
{ | |
perror("SO_REUSEADDR fail\n"); | |
return -1; | |
} | |
rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr)); | |
if (rt == -1) | |
{ | |
perror("bind failed"); | |
return -1; | |
} | |
pthread_attr_init(&attr); | |
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
rt = pthread_create(&tid,&attr,thread_urc_recv,(void *)socket_fd); | |
if(rt < 0) | |
{ | |
printf("urc loop failure!!!\n"); | |
return -1; | |
} | |
printf("urc loop success!!!\n"); | |
return 0; | |
} | |
int getSelfElement(char addr[]) | |
{ | |
for(int i=0;i < LYNQ_CALL_MAX; i++) | |
{ | |
if(lynq_call_lists[i].used==1) | |
{ | |
if(strcmp(lynq_call_lists[i].addr,addr)==0) | |
{ | |
return i; | |
} | |
} | |
} | |
return -1; | |
} | |
void lynq_call_state_change_test(int soc_id) | |
{ | |
printf("call state change,sim:%d\n",soc_id); | |
} | |
int lynq_init_call(int uToken) | |
{ | |
int result = 0; | |
Global_uToken = uToken; | |
LYLOGSET(LOG_INFO); | |
LYLOGEINIT(USER_LOG_TAG); | |
result = lynq_socket_client_start(); | |
if(result!=0) | |
{ | |
return -1; | |
} | |
result = lynq_socket_urc_start(); | |
if(result!=0) | |
{ | |
return -1; | |
} | |
result = lynq_update_call_list_loop(); | |
if(result!=0) | |
{ | |
return -1; | |
} | |
memset(lynq_call_lists,0,sizeof(lynq_call_lists)); | |
LYDBGLOG("lynq init call success!!!"); | |
return 0; | |
} | |
int lynq_deinit_call() | |
{ | |
close(lynq_client_sockfd); | |
urc_recive_status = 0; | |
call_list_loop = 0; | |
return 0; | |
} | |
int lynq_call(int* handle,char addr[]) | |
{ | |
LYERRLOG("in %s handle is %p", __FUNCTION__, handle); | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
int lynq_call_id = -1; | |
if(addr==NULL) | |
{ | |
LYERRLOG("Phone num is null!!!"); | |
return -1; | |
} | |
client.uToken = Global_uToken; | |
client.request = 10;//RIL_REQUEST_DIAL | |
client.paramLen = 2; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
memcpy(client.param,addr,strlen(addr)+1); | |
strcat(client.param," 0"); | |
LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
lynq_call_id = updateAddr(addr); | |
LYERRLOG("lynq_call_id %d\n", lynq_call_id); | |
if(error==0) | |
{ | |
isDial = 1; | |
if(waitCallstateChange(3000)==ETIMEDOUT)//3000ms | |
{ | |
error = LYNQ_E_TIME_OUT; | |
LYERRLOG("timeout:wait Call state fail!!!"); | |
lynq_call_lists[lynq_call_id].hasTimeout = 1; | |
//*handle = lynq_call_id; | |
return error; | |
} | |
*handle = lynq_call_id; | |
} | |
return error; | |
} | |
int lynq_call_answer() | |
{ | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
client.uToken = Global_uToken; | |
client.request = 40;//RIL_REQUEST_DIAL | |
client.paramLen = 0; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
return error; | |
} | |
int lynq_call_hungup(int* handle) | |
{ | |
LYERRLOG("in %s handle is %p value is %d", __FUNCTION__, handle, *handle); | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
int call_id = 0; | |
int lynq_call_id = 0; | |
client.uToken = Global_uToken; | |
client.request = 12;//RIL_REQUEST_HUNGUP | |
client.paramLen = 1; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
lynq_call_id = *handle; | |
call_id = lynq_call_lists[lynq_call_id].call_id; | |
sprintf(client.param,"%d",call_id); | |
LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
if(error==0) | |
{ | |
cleanCallList(lynq_call_id); | |
} | |
return error; | |
} | |
int lynq_call_hungup_all() | |
{ | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
client.uToken = Global_uToken; | |
client.request = 17;//RIL_REQUEST_UDUB | |
client.paramLen = 0; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
return error; | |
} | |
int lynq_wait_incoming_call(int *handle) | |
{ | |
waitIncomingCall(); | |
*handle = lynqIncomingCallId; | |
LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId); | |
return 0; | |
} | |
int lynq_set_auto_answercall(const int mode) | |
{ | |
global_call_auto_answer = mode; | |
LYINFLOG("auto answer call mode =%d",mode); | |
return 0; | |
} | |
int lynq_get_mute_status(int *status) | |
{ | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
if(status==NULL) | |
{ | |
LYERRLOG("status is null"); | |
return -1; | |
} | |
client.uToken = Global_uToken; | |
client.request = 54;//RIL_REQUEST_GET_MUTE | |
client.paramLen = 0; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
p.readInt32(status); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
return error; | |
} | |
static int judge_mic(const int enable){ | |
if(enable != 1 || enable != 0){ | |
return 0; | |
} | |
} | |
int lynq_set_mute_mic(const int enable) | |
{ | |
if(judge_mic(enable)){ | |
return LYNQ_E_CONFLICT; | |
} | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
client.uToken = Global_uToken; | |
client.request = 53;//RIL_REQUEST_SET_MUTE | |
client.paramLen = 1; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
sprintf(client.param,"%d",enable); | |
LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
return error; | |
} | |
int lynq_set_DTMF(const char callnum) | |
{ | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
if(!lynq_call_state) | |
{ | |
LYERRLOG("LYNQ_E_CONFLICT"); | |
return LYNQ_E_CONFLICT; | |
} | |
client.uToken = Global_uToken; | |
client.request = 24;//RIL_REQUEST_DTMF | |
client.paramLen = 1; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
sprintf(client.param,"%c",callnum); | |
LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
return error; | |
} | |
static int judge_volume(const int volume){ | |
if(volume < 0 ||volume >36){ | |
return 0; | |
} | |
} | |
int lynq_set_DTMF_volume(const int volume) | |
{ | |
if(!judge_volume(volume)){ | |
return LYNQ_E_CONFLICT; | |
} | |
Parcel p; | |
lynq_client_t client; | |
int resp_type = -1; | |
int request = -1; | |
int slot_id = -1; | |
int error = -1; | |
//if(!lynq_call_state) | |
//{ | |
// LYERRLOG("LYNQ_E_CONFLICT"); | |
// return LYNQ_E_CONFLICT; | |
//} | |
client.uToken = Global_uToken; | |
client.request = 8003;//LYNQ_REQUEST_SET_DTMF_VOLUME | |
client.paramLen = 1; | |
bzero(client.param,LYNQ_REQUEST_PARAM_BUF); | |
sprintf(client.param,"%d",volume); | |
LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param); | |
if(send_request(lynq_client_sockfd,&client)==-1) | |
{ | |
LYERRLOG("send request fail"); | |
perror("[LYNQ_CALL] send request fail:"); | |
return -1; | |
} | |
get_response(lynq_client_sockfd,p); | |
JumpHeader(p,&resp_type,&request,&slot_id,&error); | |
LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error); | |
return 0; | |
} | |
int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[]) | |
{ | |
int lynq_call_id = 0; | |
if(handle==NULL) | |
{ | |
return LYNQ_E_NULL_ANONALY; | |
} | |
lynq_call_id = *handle; | |
*call_state = lynq_call_lists[lynq_call_id].call_state; | |
*toa = lynq_call_lists[lynq_call_id].toa; | |
*direction = lynq_call_lists[lynq_call_id].direction; | |
memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1); | |
return 0; | |
} | |
#if 0 | |
int main(int argc,char **argv) | |
{ | |
int n = 0; | |
n = lynq_init_call(lynq_call_state_change_test,2222); | |
if(n<0) | |
{ | |
printf("lynq init call fail!!!\n"); | |
return -1; | |
} | |
printf("lynq call init success!!!\n"); | |
char phoneNum[LYNQ_PHONE_NUMBER_MAX]; | |
sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1); | |
lynq_call(phoneNum); | |
while(1) | |
{ | |
sleep(1); | |
} | |
return 0; | |
} | |
#endif | |
/*Warren add for T800 platform 2021/11/19 end*/ |