lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1 | #include <stdio.h>
|
| 2 | #include <sys/types.h>
|
| 3 | #include <sys/socket.h>
|
| 4 | #include <arpa/inet.h>
|
| 5 | #include <fcntl.h>
|
| 6 | #include <string.h>
|
| 7 | #include <stdlib.h>
|
| 8 | #include <unistd.h>
|
| 9 | #include <binder/Parcel.h>
|
| 10 | #include <log/log.h>
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 11 | #include <cutils/jstring.h>
|
| 12 | #include <pthread.h>
|
| 13 | #include "liblog/lynq_deflog.h"
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 14 | #include <sys/time.h>
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 15 | #include <string.h>
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 16 | #include <vendor-ril/telephony/ril.h>
|
| 17 | #include <vendor-ril/telephony/mtk_ril_sp.h>
|
| 18 | #include <vendor-ril/telephony/mtk_ril_ivt.h>
|
| 19 | #include "lynq_call.h"
|
| 20 |
|
| 21 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 22 | #define LYNQ_SERVICE_PORT 8088
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 23 | #define DSET_IP_ADDRESS "127.0.0.1"
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 24 | #define LYNQ_URC_SERVICE_PORT 8086
|
| 25 | #define LYNQ_REC_BUF 8192
|
| 26 | #define LYNQ_REQUEST_PARAM_BUF 8192
|
| 27 | #define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
|
| 28 | #define USER_LOG_TAG "LYNQ_CALL"
|
| 29 |
|
| 30 | using ::android::Parcel;
|
| 31 | typedef enum {
|
| 32 | LYNQ_CALL_ACTIVE = 0,
|
| 33 | LYNQ_CALL_HOLDING = 1,
|
| 34 | LYNQ_CALL_DIALING = 2, /* MO call only */
|
| 35 | LYNQ_CALL_ALERTING = 3, /* MO call only */
|
| 36 | LYNQ_CALL_INCOMING = 4, /* MT call only */
|
| 37 | LYNQ_CALL_WAITING = 5 ,/* MT call only */
|
| 38 | }lynq_call_state_t;
|
| 39 |
|
| 40 | typedef struct{
|
| 41 | int uToken;
|
| 42 | int request;
|
| 43 | int paramLen;
|
| 44 | char param[LYNQ_REQUEST_PARAM_BUF];
|
| 45 | }lynq_client_t;
|
| 46 | typedef struct
|
| 47 | {
|
| 48 | int used;
|
| 49 | int call_id;
|
| 50 | int call_state;
|
| 51 | int toa;
|
| 52 | int direction;/*0: MO call,1:MT call*/
|
| 53 | char addr[LYNQ_PHONE_NUMBER_MAX];
|
| 54 | int hasTimeout;
|
| 55 | }lynq_call_list_e_t;
|
| 56 | typedef struct
|
| 57 | {
|
| 58 | int call_id;
|
| 59 | int call_state;
|
| 60 | int toa;
|
| 61 | int direction;/*0: MO call,1:MT call*/
|
| 62 | char addr[LYNQ_PHONE_NUMBER_MAX];
|
| 63 | }lynq_call_list_t;
|
| 64 |
|
| 65 | lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
|
| 66 | static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 67 | static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 68 | static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 69 | static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
| 70 | static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 71 | static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 72 | pthread_t lynq_call_urc_tid = -1;
|
| 73 | pthread_t lynq_call_list_loop_tid = -1;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 74 |
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 75 | /*lei add*/
|
| 76 | /* socket文件描述符 */
|
| 77 | int len_addr_serv;
|
| 78 | struct sockaddr_in addr_serv;
|
| 79 | lynq_client_t client_t;
|
| 80 | int client_size = 0;
|
| 81 | /*lei add*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 82 |
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 83 | int s_call_urc_event_complete = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 84 |
|
| 85 | enum{
|
| 86 | CALL_OFF=0,
|
| 87 | CALL_ON=1
|
| 88 | }call_state;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 89 | typedef enum{
|
| 90 | LYNQ_E_CARDSTATE_ERROR=8000,
|
| 91 | /* The voice service state is out of service*/
|
| 92 | LYNQ_E_STATE_OUT_OF_SERVICE=8001,
|
| 93 | /* The voice service state is EMERGENCY_ONLY*/
|
| 94 | LYNQ_E_STATE_EMERGENCY_ONLY=8002,
|
| 95 | /* The radio power is power off*/
|
| 96 | LYNQ_E_STATE_POWER_OFF=8003,
|
| 97 | LYNQ_E_TIME_OUT=8004,
|
| 98 | /*create or open sms DB fail */
|
| 99 | LYNQ_E_SMS_DB_FAIL=8005,
|
| 100 | /*Failed to execute sql statement*/
|
| 101 | LYNQ_E_SMS_SQL_FAIL = 8006,
|
| 102 | LYNQ_E_SMS_NOT_FIND = 8007,
|
| 103 | /* The logic conflict*/
|
| 104 | LYNQ_E_CONFLICT=9000,
|
| 105 | /*Null anomaly*/
|
| 106 | LYNQ_E_NULL_ANONALY=9001
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 107 | }LYNQ_E;
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 108 | typedef enum{
|
| 109 | LYNQ_E_VOLUMN_SET_DTMF,
|
| 110 | LYNQ_E_VOLUMN_SET_SPEECH
|
| 111 | }LYNQ_E_VOLUMN_SET;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 112 |
|
| 113 | int lynq_call_state =CALL_OFF;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 114 | int lynq_call_client_sockfd = 0;
|
| 115 | int Global_uToken_call = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 116 | int global_call_count =0;
|
| 117 | int global_call_auto_answer = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 118 | bool urc_call_recive_status = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 119 | bool call_list_loop = 1;
|
| 120 | int isDial = 0;
|
| 121 | int lynqIncomingCallId = 0;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 122 |
|
| 123 | #ifdef ECALL_SUPPORT
|
| 124 | typedef enum{
|
| 125 | LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
|
| 126 | LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 127 | LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
|
| 128 | LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */\
|
| 129 | }LYNQ_ECall_Type;
|
| 130 |
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 131 | char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"","null","112"};
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 | static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 136 | static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
|
| 137 |
|
| 138 | LYNQ_ECall_Indication lynqIncomingEcallIndication;
|
| 139 | int lynqEcallId;
|
| 140 |
|
| 141 | void sendSignalIncomingECallEvent()
|
| 142 | {
|
| 143 | pthread_mutex_lock(&s_incoming_e_call_mutex);
|
| 144 | pthread_cond_signal(&s_incoming_e_call_cond);
|
| 145 | pthread_mutex_unlock(&s_incoming_e_call_mutex);
|
| 146 | }
|
| 147 | #endif
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 148 |
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 149 | /**
|
| 150 | * @brief mark call initialization state
|
| 151 | * 0: deinit state
|
| 152 | * 1: init state
|
| 153 | */
|
| 154 | int g_lynq_call_init_flag = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 155 |
|
| 156 | int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
|
| 157 | {
|
| 158 | if(p.dataAvail() > 0)
|
| 159 | {
|
| 160 | p.readInt32(resp_type);
|
| 161 | p.readInt32(request);
|
| 162 | p.readInt32(slot_id);
|
| 163 | p.readInt32(error);
|
| 164 | return 0;
|
| 165 | }
|
| 166 | else
|
| 167 | {
|
| 168 | return -1;
|
| 169 | }
|
| 170 | }
|
| 171 | int send_request(int sockfd,lynq_client_t *client_tmp)
|
| 172 | {
|
| 173 | int ret=0;
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 174 | ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 175 | if(ret==-1)
|
| 176 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 177 | LYERRLOG("sendto error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 178 | return -1;
|
| 179 | }
|
| 180 | return 0;
|
| 181 | }
|
| 182 |
|
| 183 | int get_response(int sockfd,Parcel &p)
|
| 184 | {
|
| 185 | int len = 0;
|
| 186 | char recvline[LYNQ_REC_BUF];
|
| 187 | bzero(recvline,LYNQ_REC_BUF);
|
| 188 | /* receive data from server */
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 189 | len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 190 | if(len == -1)
|
| 191 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 192 | LYERRLOG("recvfrom error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 193 | return -1;
|
| 194 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 195 | if (recvline != NULL) {
|
| 196 | p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
|
| 197 | p.setDataPosition(0);
|
| 198 | }
|
| 199 | return 0;
|
| 200 | }
|
| 201 | static char *strdupReadString(Parcel &p) {
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 202 | size_t stringlen;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 203 | const char16_t *s16;
|
| 204 | s16 = p.readString16Inplace(&stringlen);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 205 | return strndup16to8(s16, stringlen);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 206 | }
|
| 207 |
|
| 208 | int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
|
| 209 | {
|
| 210 | Parcel p;
|
| 211 | lynq_client_t client;
|
| 212 | int resp_type = -1;
|
| 213 | int request = -1;
|
| 214 | int slot_id = -1;
|
| 215 | int error = -1;
|
| 216 | int call_num = 0;
|
| 217 | int temp = 0;
|
| 218 | char *remote_phoneNum = NULL;
|
| 219 | char *remote_name= NULL;
|
| 220 | char *uusData = NULL;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 221 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 222 | client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
|
| 223 | client.paramLen = 0;
|
| 224 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 225 | LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 226 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 227 | {
|
| 228 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 229 | return -1;
|
| 230 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 231 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 232 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 233 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 234 | if(error == 0)
|
| 235 | {
|
| 236 | p.readInt32(&call_num);
|
| 237 | global_call_count = call_num;
|
| 238 | if(call_num<=0)
|
| 239 | {
|
| 240 | lynq_call_state = CALL_OFF;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 241 | LYINFLOG("lynq_call_state:%d",lynq_call_state);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 242 | return 0;
|
| 243 | }
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 244 | lynq_call_state = CALL_ON;
|
| 245 | LYINFLOG("lynq_call_state:%d",lynq_call_state);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 246 | for(int i = 0;i < call_num;i++)
|
| 247 | {
|
| 248 | p.readInt32(&temp);
|
| 249 | call_list[i].call_state = temp;
|
| 250 | p.readInt32(&call_list[i].call_id);
|
| 251 | p.readInt32(&call_list[i].toa);
|
| 252 | p.readInt32(&temp);
|
| 253 | p.readInt32(&temp);
|
| 254 | call_list[i].direction = temp;
|
| 255 | p.readInt32(&temp);
|
| 256 | p.readInt32(&temp);
|
| 257 | p.readInt32(&temp);
|
| 258 | remote_phoneNum = strdupReadString(p);
|
| 259 | memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
|
| 260 | LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
|
| 261 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 262 | p.readInt32(&temp);
|
| 263 | remote_name = strdupReadString(p);
|
| 264 | p.readInt32(&temp);
|
| 265 | p.readInt32(&temp);
|
| 266 | if(temp==0)
|
| 267 | {
|
| 268 | continue;
|
| 269 | }
|
| 270 | p.readInt32(&temp); /* UUS Information is present */
|
| 271 | p.readInt32(&temp);
|
| 272 | p.readInt32(&temp);
|
| 273 | p.read(uusData,temp);
|
| 274 | }
|
| 275 | }
|
| 276 | return 0;
|
| 277 | }
|
| 278 |
|
| 279 | void cleanCallList(int lynq_call_id)
|
| 280 | {
|
| 281 | lynq_call_lists[lynq_call_id].call_id = 0;
|
| 282 | lynq_call_lists[lynq_call_id].call_state = 0;
|
| 283 | lynq_call_lists[lynq_call_id].toa = 0;
|
| 284 | lynq_call_lists[lynq_call_id].direction = 0;
|
| 285 | lynq_call_lists[lynq_call_id].used = 0;
|
| 286 | lynq_call_lists[lynq_call_id].hasTimeout = 0;
|
| 287 | memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
|
| 288 | }
|
| 289 | int getUnusedElement()
|
| 290 | {
|
| 291 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 292 | {
|
| 293 | if(lynq_call_lists[i].used!=1)
|
| 294 | {
|
| 295 | return i;
|
| 296 | }
|
| 297 | }
|
| 298 | return -1;
|
| 299 | }
|
| 300 | int updateAddr(char addr[])
|
| 301 | {
|
| 302 | int ret = 0;
|
| 303 | ret = getUnusedElement();
|
| 304 | memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
|
| 305 | lynq_call_lists[ret].used = 1;
|
| 306 | return ret;
|
| 307 | }
|
| 308 | void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
|
| 309 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 310 | LYINFLOG("Update Call List");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 311 | callList->call_id = call_id;
|
| 312 | callList->call_state = call_state;
|
| 313 | callList->toa = toa;
|
| 314 | callList->direction = direction;
|
| 315 | callList->used = 1;
|
| 316 | callList->hasTimeout = 0;
|
| 317 | return;
|
| 318 | }
|
| 319 | int waitCallstateChange(int mtime)
|
| 320 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 321 | LYINFLOG("wait Call state Change");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 322 | int ret = 0;
|
| 323 | int sec = 0;
|
| 324 | int usec = 0;
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 325 | struct timeval now;
|
| 326 | struct timespec timeout;
|
| 327 | gettimeofday(&now,NULL);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 328 | sec = mtime/1000;
|
| 329 | usec = mtime%1000;
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 330 | timeout.tv_sec = now.tv_sec+sec;
|
| 331 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 332 | pthread_mutex_lock(&call_state_change_mutex);
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 333 | ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 334 | pthread_mutex_unlock(&call_state_change_mutex);
|
| 335 | return ret;
|
| 336 | }
|
| 337 | int waitIncomingCall()
|
| 338 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 339 | LYINFLOG("wait incming call");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 340 | int ret = 0;
|
| 341 | pthread_mutex_lock(&s_incoming_call_mutex);
|
| 342 | ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
|
| 343 | pthread_mutex_unlock(&s_incoming_call_mutex);
|
| 344 | return ret;
|
| 345 | }
|
| 346 | int checkHasCall(char addr[])
|
| 347 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 348 | LYINFLOG("check has call");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 349 | for(int i = 0;i<LYNQ_CALL_MAX;i++)
|
| 350 | {
|
| 351 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 352 | {
|
| 353 | return 1;
|
| 354 | }
|
| 355 | }
|
| 356 | return 0;
|
| 357 | }
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 358 | int find_call_id_with_addr(char *addr)
|
| 359 | {
|
| 360 | LYINFLOG("find call id with addr!!!");
|
| 361 | for(int id = 0; id < LYNQ_CALL_MAX; id++)
|
| 362 | {
|
| 363 | if(strcmp(lynq_call_lists[id].addr,addr) == 0)
|
| 364 | {
|
| 365 | return id;
|
| 366 | }
|
| 367 | }
|
| 368 | return -1;
|
| 369 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 370 | void sendSignalToWaitCallStateChange()
|
| 371 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 372 | LYINFLOG("send Signal To Wait Call State Change");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 373 | pthread_mutex_lock(&call_state_change_mutex);
|
| 374 | pthread_cond_signal(&call_state_change_cond);
|
| 375 | pthread_mutex_unlock(&call_state_change_mutex);
|
| 376 | }
|
| 377 | void sendSignalIncomingCall()
|
| 378 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 379 | LYINFLOG("send incoming call signal");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 380 | pthread_mutex_lock(&s_incoming_call_mutex);
|
| 381 | pthread_cond_signal(&s_incoming_call_cond);
|
| 382 | pthread_mutex_unlock(&s_incoming_call_mutex);
|
| 383 | }
|
| 384 |
|
| 385 | void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
|
| 386 | {
|
| 387 | callList->call_id = call_id;
|
| 388 | callList->call_state = call_state;
|
| 389 | callList->toa = toa;
|
| 390 | callList->direction = direction;
|
| 391 | memcpy(callList->addr,addr,strlen(addr)+1);
|
| 392 | callList->used = 1;
|
| 393 | callList->hasTimeout = 0;
|
| 394 | return;
|
| 395 | }
|
| 396 |
|
| 397 | void *triggerGetCallList(void *parg)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 398 | {
|
| 399 | int ret=0;
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 400 | bool call_end;
|
| 401 | call_end = 0;//0:this call end,1:call on
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 402 | lynq_call_list_t call_list[LYNQ_CALL_MAX];
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 403 | int update=0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 404 | while(call_list_loop)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 405 | {
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 406 | update=0;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 407 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 408 | pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 409 | LYDBGLOG("triggerGetCallList event!!!\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 410 | memset(call_list,0,sizeof(call_list));
|
| 411 | ret = lynq_get_current_call_list(call_list);
|
| 412 | if(ret != 0)
|
| 413 | {
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 414 | LYDBGLOG("get current call list failure!!!\n");
|
| 415 | continue;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 416 | }
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 417 | LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 418 | for(int i = 0;i < LYNQ_CALL_MAX;i++)
|
| 419 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 420 | if(strlen(lynq_call_lists[i].addr) != 0)
|
| 421 | {
|
| 422 | call_end = 0;
|
| 423 | for(int id = 0; id < LYNQ_CALL_MAX; id++)
|
| 424 | {
|
| 425 | if(strcmp(call_list[id].addr,lynq_call_lists[i].addr) == 0)
|
| 426 | {
|
| 427 | call_end = 1;
|
| 428 | LYINFLOG("find lynq call i %d, id %d!!!",i,id);
|
| 429 | }
|
| 430 | }
|
| 431 | if(call_end == 0)
|
| 432 | {
|
| 433 | LYINFLOG("MT hungup,then clean call info");
|
| 434 | cleanCallList(i);
|
| 435 | continue;
|
| 436 | }
|
| 437 | } //fix bug API-54
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 438 | if(call_list[i].direction == 1)//MT call
|
| 439 | {
|
| 440 | if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
|
| 441 | {
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 442 | /*you call me, and i call you,One party failed to dial*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 443 | if(!checkHasCall(call_list[i].addr))
|
| 444 | {
|
| 445 | lynqIncomingCallId = getUnusedElement();
|
| 446 | 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);
|
| 447 | sendSignalIncomingCall();
|
| 448 | }
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 449 | else
|
| 450 | {
|
| 451 | int temp_call_id = find_call_id_with_addr(call_list[i].addr);
|
| 452 | /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
|
| 453 | **an incoming call until the status changes.
|
| 454 | **fix bug API-54
|
| 455 | */
|
| 456 | if((temp_call_id > 0) && (lynq_call_lists[temp_call_id].call_state == call_list[i].call_state))
|
| 457 | {
|
| 458 | sendSignalIncomingCall();
|
| 459 | }
|
| 460 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 461 | }
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 462 | /*if state changed*/
|
| 463 | else
|
| 464 | {
|
| 465 | /*update call state*/
|
| 466 | for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
|
| 467 | {
|
| 468 | if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
|
| 469 | {
|
| 470 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
ll | 90a255c | 2022-04-07 09:09:55 +0000 | [diff] [blame] | 471 | break;
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 472 | }
|
| 473 | }
|
| 474 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 475 | }
|
| 476 | else
|
| 477 | {
|
| 478 | if(call_list[i].call_id==0)
|
| 479 | {
|
| 480 | break;
|
| 481 | }
|
| 482 | for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
|
| 483 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 484 | if((lynq_call_lists[n].hasTimeout == 1) && (strcmp(lynq_call_lists[n].addr,call_list[i].addr) == 0))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 485 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 486 | cleanCallList(n);//if this call time out,need clean lynq call list.
|
| 487 | /*hangup call with call id*/
|
| 488 | lynq_call_hungup(&call_list[i].call_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 489 | lynq_call_lists[n].hasTimeout==0;
|
| 490 | continue;
|
| 491 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 492 | LYDBGLOG("lynq_call_lists n is %d, used is %d, addr is %s addr2 %s\n",
|
| 493 | n,lynq_call_lists[n].used,call_list[i].addr,lynq_call_lists[n].addr);
|
| 494 | if(lynq_call_lists[n].used && (strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 495 | {
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 496 | LYINFLOG("updated\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 497 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 498 | update=1;
|
| 499 | break;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 500 | }
|
| 501 | }
|
| 502 | 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,
|
| 503 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 504 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 505 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 506 | s_call_urc_event_complete = 1;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 507 | if((isDial==1) && (update==1))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 508 | {
|
| 509 | sendSignalToWaitCallStateChange();
|
| 510 | isDial = 0;
|
| 511 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 512 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
| 513 | }
|
| 514 | return NULL;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 515 | }
|
| 516 |
|
| 517 | void lynqRespWatingEvent()
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 518 | {
|
| 519 | if(s_call_urc_event_complete==1)
|
| 520 | {
|
| 521 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 522 | pthread_cond_signal(&s_urc_call_state_change_cond);
|
| 523 | s_call_urc_event_complete = 0;
|
| 524 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 525 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 526 | return;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 527 | }
|
| 528 |
|
| 529 | /*Warren add for T800 platform 2021/11/19 start*/
|
| 530 | int lynq_socket_client_start()
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 531 | {
|
| 532 | #if 0
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 533 | struct sockaddr_in lynq_socket_server_addr;
|
| 534 | /* init lynq_socket_server_addr */
|
| 535 | bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
|
| 536 | lynq_socket_server_addr.sin_family = AF_INET;
|
| 537 | lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 538 | lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 539 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 540 | /*
|
| 541 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
|
| 542 | {
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 543 | LYDBGLOG("[%s] is not a valid IPaddress\n", argv[1]);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 544 | exit(1);
|
| 545 | }
|
| 546 | */
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 547 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 548 | if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 549 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 550 | LYERRLOG("connect error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 551 | return -1;
|
| 552 | }
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 553 | #endif
|
| 554 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 555 | if (-1 == lynq_call_client_sockfd)
|
| 556 | {
|
| 557 | return lynq_call_client_sockfd;
|
| 558 | }
|
| 559 | /* 设置address */
|
| 560 | memset(&addr_serv, 0, sizeof(addr_serv));
|
| 561 | addr_serv.sin_family = AF_INET;
|
| 562 | addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
|
| 563 | addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 564 | len_addr_serv = sizeof(addr_serv);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 565 | return 0;
|
| 566 | }
|
| 567 | int lynq_update_call_list_loop()
|
| 568 | {
|
| 569 | int ret = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 570 | pthread_attr_t attr;
|
| 571 | pthread_attr_init(&attr);
|
| 572 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 573 | ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 574 | if(ret < 0)
|
| 575 | {
|
| 576 | LYERRLOG("lynq_update_call_list_loop fail!!!");
|
| 577 | return -1;
|
| 578 | }
|
| 579 | LYDBGLOG("lynq_update_call_list_loop success!!!\n");
|
| 580 | return 0;
|
| 581 |
|
| 582 | }
|
| 583 | void *thread_urc_recv(void *parg)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 584 | {
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 585 | int socket_fd = (int64_t)parg;
|
| 586 | int len=0;
|
| 587 | socklen_t addr_len=0;
|
| 588 | uint8_t *dataLength = NULL;
|
| 589 | char urc_data[LYNQ_REC_BUF];
|
| 590 | int slot_id = -1;
|
| 591 | int resp_type = -1;
|
| 592 | int urcid = -1;
|
| 593 | Parcel *p = NULL;
|
| 594 | struct sockaddr_in dest_addr;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 595 | #ifdef ECALL_SUPPORT
|
| 596 | int ecall_ind;
|
| 597 | #endif
|
| 598 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 599 | LYINFLOG("thread_urc_recv in running....\n");
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 600 | while(urc_call_recive_status)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 601 | {
|
| 602 | bzero(urc_data,LYNQ_REC_BUF);
|
| 603 | //get data msg
|
| 604 | len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
|
| 605 | if(len <= 0)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 606 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 607 | LYERRLOG("thread_urc_recv step2 fail\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 608 | break;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 609 | }
|
| 610 | LYDBGLOG("=====>urc data len<=====:%d\n",len);
|
| 611 | p = new Parcel();
|
| 612 | if(p==NULL)
|
| 613 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 614 | LYERRLOG("new parcel failure!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 615 | break;
|
| 616 | }
|
| 617 | p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
|
| 618 | p->setDataPosition(0);
|
| 619 | if(p->dataAvail() > 0)
|
| 620 | {
|
| 621 | p->readInt32(&resp_type);
|
| 622 | p->readInt32(&urcid);
|
| 623 | p->readInt32(&slot_id);
|
| 624 | //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 625 | switch (urcid)
|
| 626 | {
|
| 627 | case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
|
| 628 | {
|
| 629 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 630 | lynqRespWatingEvent();
|
| 631 | break;
|
| 632 | }
|
| 633 | case 1018://RIL_UNSOL_CALL_RING
|
| 634 | {
|
| 635 | if(global_call_auto_answer==1)
|
| 636 | {
|
| 637 | lynq_call_answer();
|
| 638 | }
|
| 639 | break;
|
| 640 | }
|
| 641 | case 1029://RIL_UNSOL_RINGBACK_TONE
|
| 642 | case 3049://RIL_UNSOL_CALL_INFO_INDICATION
|
| 643 | {
|
| 644 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 645 | break;
|
| 646 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 647 | #ifdef ECALL_SUPPORT
|
| 648 | case RIL_UNSOL_ECALL_INDICATIONS:
|
| 649 | {
|
| 650 | p->readInt32(&ecall_ind);
|
| 651 | lynqIncomingEcallIndication=ecall_ind;
|
| 652 | if(LYNQ_ECALL_ACTIVE==lynqIncomingEcallIndication)
|
| 653 | {
|
| 654 | if(isDial==1)
|
| 655 | {
|
| 656 | p->readInt32(&lynqEcallId);
|
| 657 | sendSignalToWaitCallStateChange();
|
| 658 | usleep(300*1000);
|
| 659 | }
|
| 660 | }
|
| 661 | sendSignalIncomingECallEvent();
|
| 662 | break;
|
| 663 | }
|
| 664 | #endif
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 665 | default:
|
| 666 | break;
|
| 667 | }
|
| 668 | }
|
| 669 | delete p;
|
| 670 | p = NULL;
|
| 671 | }
|
| 672 | close(socket_fd);
|
| 673 | }
|
| 674 | int lynq_socket_urc_start()
|
| 675 | {
|
| 676 | int socket_fd=0;
|
| 677 | int rt=0;
|
| 678 | int len=0;
|
| 679 | int on=1;
|
| 680 | struct sockaddr_in urc_local_addr;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 681 | pthread_attr_t attr;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 682 | socket_fd = socket(AF_INET,SOCK_DGRAM,0);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 683 | if(socket_fd < 0)
|
| 684 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 685 | LYERRLOG("creaet socket for udp fail\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 686 | return -1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 687 | }
|
| 688 | urc_local_addr.sin_family = AF_INET;
|
| 689 | urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
|
| 690 | urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
| 691 | /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 692 | rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
|
| 693 | if(rt<0)
|
| 694 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 695 | LYERRLOG("SO_REUSEADDR fail\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 696 | return -1;
|
| 697 | }
|
| 698 | rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 699 | if (rt == -1)
|
| 700 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 701 | LYERRLOG("bind failed");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 702 | return -1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 703 | }
|
| 704 | pthread_attr_init(&attr);
|
| 705 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 706 | rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 707 | if(rt < 0)
|
| 708 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 709 | LYERRLOG("urc loop failure!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 710 | return -1;
|
| 711 | }
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 712 | LYDBGLOG("urc loop success!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 713 | return 0;
|
| 714 | }
|
| 715 | int getSelfElement(char addr[])
|
| 716 | {
|
| 717 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 718 | {
|
| 719 | if(lynq_call_lists[i].used==1)
|
| 720 | {
|
| 721 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 722 | {
|
| 723 | return i;
|
| 724 | }
|
| 725 |
|
| 726 | }
|
| 727 | }
|
| 728 | return -1;
|
| 729 | }
|
| 730 |
|
| 731 | void lynq_call_state_change_test(int soc_id)
|
| 732 | {
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 733 | LYDBGLOG("call state change,sim:%d\n",soc_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 734 | }
|
| 735 | int lynq_init_call(int uToken)
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 736 | {
|
| 737 | if(g_lynq_call_init_flag == 1){
|
| 738 | LYDBGLOG("lynq init call failed!!!");
|
| 739 | return -1;
|
| 740 | }
|
| 741 | g_lynq_call_init_flag = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 742 | int result = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 743 | Global_uToken_call = uToken;
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 744 | urc_call_recive_status = 1;
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 745 | client_size = sizeof(client_t);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 746 | LYLOGSET(LOG_INFO);
|
| 747 | LYLOGEINIT(USER_LOG_TAG);
|
| 748 | result = lynq_socket_client_start();
|
| 749 | if(result!=0)
|
| 750 | {
|
| 751 | return -1;
|
| 752 | }
|
| 753 | result = lynq_socket_urc_start();
|
| 754 | if(result!=0)
|
| 755 | {
|
| 756 | return -1;
|
| 757 | }
|
| 758 | result = lynq_update_call_list_loop();
|
| 759 | if(result!=0)
|
| 760 | {
|
| 761 | return -1;
|
| 762 | }
|
| 763 | memset(lynq_call_lists,0,sizeof(lynq_call_lists));
|
| 764 | LYDBGLOG("lynq init call success!!!");
|
| 765 | return 0;
|
| 766 | }
|
| 767 | int lynq_deinit_call()
|
| 768 | {
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 769 | if(g_lynq_call_init_flag == 0)
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 770 | {
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 771 | LYDBGLOG("lynq_deinit_call failed!!!");
|
| 772 | return -1;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 773 | }
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 774 | else
|
| 775 | {
|
| 776 | g_lynq_call_init_flag = 0;
|
| 777 | int ret = -1;
|
| 778 | if(lynq_call_client_sockfd>0)
|
| 779 | {
|
| 780 | close(lynq_call_client_sockfd);
|
| 781 | }
|
| 782 | urc_call_recive_status = 0;
|
| 783 | call_list_loop = 0;
|
| 784 | if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
|
| 785 | {
|
| 786 | return -1;
|
| 787 | }
|
| 788 | ret = pthread_cancel(lynq_call_urc_tid);
|
| 789 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 790 | ret = pthread_cancel(lynq_call_list_loop_tid);
|
| 791 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 792 | ret = pthread_join(lynq_call_urc_tid,NULL);
|
| 793 | LYDBGLOG("pthread join ret = %d",ret);
|
| 794 | ret = pthread_join(lynq_call_list_loop_tid,NULL);
|
| 795 | LYDBGLOG("pthread join ret = %d",ret);
|
| 796 | return 0;
|
| 797 | }
|
rita | 98e2e9c | 2022-04-07 06:08:13 -0400 | [diff] [blame] | 798 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 799 |
|
| 800 | int lynq_set_common_request(int request_id, int argc, const char* format,...)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 801 | {
|
| 802 | Parcel p;
|
| 803 | lynq_client_t client;
|
| 804 | int resp_type = -1;
|
| 805 | int request = -1;
|
| 806 | int slot_id = -1;
|
| 807 | int error = -1;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 808 |
|
| 809 | client.uToken = Global_uToken_call;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 810 | client.request = request_id;
|
| 811 | client.paramLen = argc;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 812 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 813 | if(argc!=0)
|
| 814 | {
|
| 815 | va_list args;
|
| 816 | va_start(args, format);
|
| 817 | vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
|
| 818 | va_end(args);
|
| 819 | }
|
| 820 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 821 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
| 822 | {
|
| 823 | LYERRLOG("send request fail");
|
| 824 | return -1;
|
| 825 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 826 | if(get_response(lynq_call_client_sockfd,p)==0)
|
| 827 | {
|
| 828 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 829 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 830 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 831 | return error;
|
| 832 | }
|
| 833 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 834 | int lynq_get_common_request(int request_id, int* status)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 835 | {
|
| 836 | Parcel p;
|
| 837 | lynq_client_t client;
|
| 838 | int resp_type = -1;
|
| 839 | int request = -1;
|
| 840 | int slot_id = -1;
|
| 841 | int error = -1;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 842 | if(status==NULL)
|
| 843 | {
|
| 844 | LYERRLOG("status is null");
|
| 845 | return -1;
|
| 846 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 847 | client.uToken = Global_uToken_call;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 848 | client.request = request_id;
|
| 849 | client.paramLen = 0;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 850 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 851 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 852 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
| 853 | {
|
| 854 | LYERRLOG("send request fail");
|
| 855 | return -1;
|
| 856 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 857 | if(get_response(lynq_call_client_sockfd,p)==0)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 858 | {
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 859 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 860 | p.readInt32(status);
|
| 861 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 862 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 863 | return error;
|
| 864 | }
|
| 865 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 866 | int lynq_call(int* handle,char addr[])
|
| 867 | {
|
| 868 | Parcel p;
|
| 869 | lynq_client_t client;
|
| 870 | int resp_type = -1;
|
| 871 | int request = -1;
|
| 872 | int slot_id = -1;
|
| 873 | int error = -1;
|
| 874 | int lynq_call_id = -1;
|
| 875 | if(addr==NULL)
|
| 876 | {
|
| 877 | LYERRLOG("Phone num is null!!!");
|
| 878 | return -1;
|
| 879 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 880 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 881 | client.request = 10;//RIL_REQUEST_DIAL
|
| 882 | client.paramLen = 2;
|
| 883 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 884 | memcpy(client.param,addr,strlen(addr)+1);
|
| 885 | strcat(client.param," 0");
|
| 886 | LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 887 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 888 | {
|
| 889 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 890 | return -1;
|
| 891 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 892 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 893 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 894 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 895 | lynq_call_id = updateAddr(addr);
|
| 896 | if(error==0)
|
| 897 | {
|
| 898 | isDial = 1;
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 899 | if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 900 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 901 | //if timeout,this call need destroy.
|
| 902 | isDial = 0;
|
| 903 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 904 | error = LYNQ_E_TIME_OUT;
|
| 905 | LYERRLOG("timeout:wait Call state fail!!!");
|
| 906 | lynq_call_lists[lynq_call_id].hasTimeout = 1;
|
| 907 | return error;
|
| 908 | }
|
| 909 | *handle = lynq_call_id;
|
| 910 | }
|
| 911 | return error;
|
| 912 | }
|
| 913 | int lynq_call_answer()
|
| 914 | {
|
| 915 | Parcel p;
|
| 916 | lynq_client_t client;
|
| 917 | int resp_type = -1;
|
| 918 | int request = -1;
|
| 919 | int slot_id = -1;
|
| 920 | int error = -1;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 921 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 922 | client.request = 40;//RIL_REQUEST_DIAL
|
| 923 | client.paramLen = 0;
|
| 924 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 925 | LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 926 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 927 | {
|
| 928 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 929 | return -1;
|
| 930 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 931 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 932 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 933 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 934 | return error;
|
| 935 | }
|
| 936 | int lynq_call_hungup(int* handle)
|
| 937 | {
|
| 938 | Parcel p;
|
| 939 | lynq_client_t client;
|
| 940 | int resp_type = -1;
|
| 941 | int request = -1;
|
| 942 | int slot_id = -1;
|
| 943 | int error = -1;
|
| 944 | int call_id = 0;
|
| 945 | int lynq_call_id = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 946 | if(handle==NULL||!((*handle>=0)&&(*handle<10)))
|
| 947 | {
|
| 948 | LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
|
| 949 | return LYNQ_E_CONFLICT;
|
| 950 | }
|
| 951 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 952 | client.request = 12;//RIL_REQUEST_HUNGUP
|
| 953 | client.paramLen = 1;
|
| 954 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 955 | lynq_call_id = *handle;
|
| 956 | call_id = lynq_call_lists[lynq_call_id].call_id;
|
| 957 | sprintf(client.param,"%d",call_id);
|
| 958 | LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 959 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 960 | {
|
| 961 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 962 | return -1;
|
| 963 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 964 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 965 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 966 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 967 | if(error==0)
|
| 968 | {
|
| 969 | cleanCallList(lynq_call_id);
|
| 970 | }
|
| 971 | return error;
|
| 972 | }
|
| 973 | int lynq_call_hungup_all()
|
| 974 | {
|
| 975 | Parcel p;
|
| 976 | lynq_client_t client;
|
| 977 | int resp_type = -1;
|
| 978 | int request = -1;
|
| 979 | int slot_id = -1;
|
| 980 | int error = -1;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 981 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 982 | client.request = 17;//RIL_REQUEST_UDUB
|
| 983 | client.paramLen = 0;
|
| 984 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 985 | LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 986 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 987 | {
|
| 988 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 989 | return -1;
|
| 990 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 991 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 992 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 993 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 994 | return error;
|
| 995 | }
|
| 996 | int lynq_wait_incoming_call(int *handle)
|
| 997 | {
|
| 998 | waitIncomingCall();
|
| 999 | *handle = lynqIncomingCallId;
|
| 1000 | LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
|
| 1001 | return 0;
|
| 1002 | }
|
| 1003 |
|
| 1004 | int lynq_set_auto_answercall(const int mode)
|
| 1005 | {
|
| 1006 | global_call_auto_answer = mode;
|
| 1007 | LYINFLOG("auto answer call mode =%d",mode);
|
| 1008 | return 0;
|
| 1009 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1010 | int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
|
| 1011 | {
|
| 1012 | int lynq_call_id = 0;
|
| 1013 | if(handle==NULL)
|
| 1014 | {
|
| 1015 | return LYNQ_E_NULL_ANONALY;
|
| 1016 | }
|
| 1017 | lynq_call_id = *handle;
|
| 1018 | *call_state = lynq_call_lists[lynq_call_id].call_state;
|
| 1019 | *toa = lynq_call_lists[lynq_call_id].toa;
|
| 1020 | *direction = lynq_call_lists[lynq_call_id].direction;
|
| 1021 | memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
|
| 1022 | return 0;
|
| 1023 | }
|
| 1024 |
|
| 1025 | /*audio begin*/
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1026 | static int judge_mic(const int enable){
|
ll | f512fa3 | 2022-02-14 08:58:16 +0000 | [diff] [blame] | 1027 | switch(enable){
|
| 1028 | case 0:
|
| 1029 | return 1;
|
| 1030 | case 1:
|
| 1031 | return 1;
|
| 1032 | default:
|
| 1033 | return 0;
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1034 | }
|
| 1035 | }
|
| 1036 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1037 | int lynq_set_mute_mic(const int enable)
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1038 | {
|
| 1039 | if(!judge_mic(enable)){
|
| 1040 | return LYNQ_E_CONFLICT;
|
| 1041 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1042 | return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
|
| 1043 | }
|
| 1044 | int lynq_get_mute_mic(int *status)
|
| 1045 | {
|
| 1046 | return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1047 | }
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1048 |
|
| 1049 | /**
|
| 1050 | * @brief Check whether DTMF is valid
|
| 1051 | *
|
| 1052 | * @param callnum dtmf eg:0-9 * #
|
| 1053 | * @return int
|
| 1054 | */
|
| 1055 | static int judge_dtmf(const char callnum)
|
| 1056 | {
|
| 1057 | if(callnum == '#')
|
| 1058 | {
|
| 1059 | return 1;
|
| 1060 | }
|
| 1061 | if(callnum == '*')
|
| 1062 | {
|
| 1063 | return 1;
|
| 1064 | }
|
| 1065 | if(callnum >= '0'&& callnum <= '9')
|
| 1066 | {
|
| 1067 | return 1;
|
| 1068 | }
|
| 1069 | return 0;
|
| 1070 | }
|
| 1071 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1072 | int lynq_set_DTMF(const char callnum)
|
| 1073 | {
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1074 | if(!judge_dtmf(callnum))
|
| 1075 | {
|
| 1076 | return LYNQ_E_CONFLICT;
|
| 1077 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1078 | if(!lynq_call_state)
|
| 1079 | {
|
| 1080 | LYERRLOG("LYNQ_E_CONFLICT");
|
| 1081 | return LYNQ_E_CONFLICT;
|
| 1082 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1083 | return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1084 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1085 | static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
|
| 1086 | if(set==LYNQ_E_VOLUMN_SET_DTMF){
|
| 1087 | if(volume < 0 ||volume >36){
|
| 1088 | return 0;
|
| 1089 | }
|
| 1090 | }
|
| 1091 | else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
|
| 1092 | {
|
| 1093 | if(volume < 1 ||volume >7){
|
| 1094 | return 0;
|
| 1095 | }
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1096 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 1097 | return 1;
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1098 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1099 | int lynq_set_DTMF_volume(const int volume)
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1100 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1101 | if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1102 | return LYNQ_E_CONFLICT;
|
| 1103 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1104 | return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1105 | }
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1106 | int lynq_set_speech_volume(const int volume)//mixer_set_volume
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1107 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1108 | if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1109 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1110 | return LYNQ_E_CONFLICT;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1111 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1112 | return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1113 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1114 | int lynq_get_speech_volume(int* volumn)//mixer_get_volume
|
| 1115 | {
|
| 1116 | return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
|
| 1117 | }
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1118 | int lynq_incall_record_start(const char* file_path)
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1119 | {
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1120 | return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1121 | }
|
| 1122 | int lynq_incall_record_stop()
|
| 1123 | {
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1124 | const char* unused_file="just_ocuupy_paramter_postion";
|
| 1125 | return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1126 | }
|
| 1127 | /*audio end*/
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1128 |
|
| 1129 | #ifdef ECALL_SUPPORT
|
| 1130 | LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
|
| 1131 | {
|
| 1132 | switch(type)
|
| 1133 | {
|
| 1134 | case LYNQ_ECALL_TYPE_TEST:
|
| 1135 | return LYNQ_ECALL_TEST;
|
| 1136 | case LYNQ_ECALL_TYPE_RECONFIG:
|
| 1137 | return LYNQ_ECALL_RECONFIG;
|
| 1138 | default:
|
| 1139 | return LYNQ_ECALL_EMERGENCY;
|
| 1140 | }
|
| 1141 | }
|
| 1142 |
|
| 1143 | RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
|
| 1144 | {
|
| 1145 | switch(type)
|
| 1146 | {
|
| 1147 | case LYNQ_ECALL_TEST:
|
| 1148 | return ECALL_TEST;
|
| 1149 | case LYNQ_ECALL_RECONFIG:
|
| 1150 | return ECALL_RECONFIG;
|
| 1151 | default:
|
| 1152 | return ECALL_EMERGENCY;
|
| 1153 | }
|
| 1154 | }
|
| 1155 |
|
| 1156 | RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
|
| 1157 | {
|
| 1158 | switch(cat)
|
| 1159 | {
|
| 1160 | case LYNQ_EMER_CAT_MANUAL_ECALL:
|
| 1161 | return EMER_CAT_MANUAL_ECALL;
|
| 1162 | default:
|
| 1163 | return EMER_CAT_AUTO_ECALL;
|
| 1164 | }
|
| 1165 | }
|
| 1166 |
|
| 1167 |
|
| 1168 | int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
|
| 1169 | {
|
| 1170 | int error;
|
| 1171 |
|
| 1172 | if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
|
| 1173 | {
|
| 1174 | LYERRLOG("test_num is null or test_num_length %d s greater than %d\n ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
|
| 1175 | return -1;
|
| 1176 | }
|
| 1177 |
|
| 1178 | error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
|
| 1179 |
|
| 1180 | if(error==0)
|
| 1181 | {
|
| 1182 | snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
|
| 1183 | }
|
| 1184 |
|
| 1185 | return error;
|
| 1186 | }
|
| 1187 |
|
| 1188 |
|
| 1189 | int lynq_fast_ecall(int* handle, LYNQ_ECall_Category lynq_ecall_cat, LYNQ_ECall_Variant lynq_ecall_variant, const char *addr, int addr_length, const char *msd_data, int msd_length)
|
| 1190 | {
|
| 1191 | int error = -1;
|
| 1192 | int lynq_call_id = -1;
|
| 1193 | RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
|
q.huang | 5247303 | 2022-04-19 05:20:12 -0400 | [diff] [blame] | 1194 | RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1195 |
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 1196 | lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
|
| 1197 |
|
| 1198 | LYINFLOG("e_call_addr is %s\n",e_call_addr[lynq_ecall_variant]);
|
| 1199 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1200 | error=lynq_set_common_request(RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", msd_data);
|
| 1201 |
|
| 1202 | if(error==0)
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 1203 | {
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1204 | isDial = 1;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 1205 | if(waitCallstateChange(30000)==ETIMEDOUT)//30000ms
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1206 | {
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 1207 | isDial = 0;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1208 | error = LYNQ_E_TIME_OUT;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 1209 | cleanCallList(lynq_call_id);
|
| 1210 | LYERRLOG("timeout:wait Call state fail!!!");
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1211 | return error;
|
| 1212 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 1213 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1214 | *handle = lynq_call_id;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 1215 | if(lynq_ecall_variant==LYNQ_ECALL_EMERGENCY){
|
| 1216 | lynq_call_lists[lynq_call_id].call_id=lynqEcallId;
|
| 1217 | }
|
| 1218 | LYINFLOG("lynq_fast_ecall handle is:%d, call id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
|
| 1219 |
|
| 1220 | }
|
| 1221 | else {
|
| 1222 | cleanCallList(lynq_call_id);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1223 | }
|
| 1224 |
|
| 1225 | return error;
|
| 1226 | }
|
| 1227 |
|
| 1228 | int lynq_set_psap(int enable)
|
| 1229 | {
|
| 1230 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
|
| 1231 | }
|
| 1232 |
|
| 1233 | int lynq_psap_pull_msd()
|
| 1234 | {
|
| 1235 | return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
|
| 1236 | }
|
| 1237 |
|
| 1238 | int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
|
| 1239 | {
|
| 1240 | LYNQ_ECall_Variant lynq_ecall_variant;
|
| 1241 | int error = -1;
|
| 1242 | int lynq_call_id = -1;
|
| 1243 |
|
| 1244 | if(handle==NULL)
|
| 1245 | {
|
| 1246 | LYERRLOG("handle is NULL, parameter error \n ");
|
| 1247 | return -1;
|
| 1248 | }
|
| 1249 |
|
| 1250 | error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
|
| 1251 |
|
| 1252 | if(error==0)
|
| 1253 | {
|
| 1254 | lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
|
| 1255 |
|
| 1256 | lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
|
| 1257 | isDial = 1;
|
| 1258 | if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
|
| 1259 | {
|
| 1260 | error = LYNQ_E_TIME_OUT;
|
| 1261 | LYERRLOG("timeout:wait Call state fail!!!");
|
| 1262 | lynq_call_lists[lynq_call_id].hasTimeout = 1;
|
| 1263 | return error;
|
| 1264 | }
|
| 1265 |
|
| 1266 | *handle = lynq_call_id;
|
| 1267 | }
|
| 1268 |
|
| 1269 | return error;
|
| 1270 | }
|
| 1271 |
|
| 1272 |
|
| 1273 | int lynq_set_msd(int* handle, const char *msd_data, int msd_length)
|
| 1274 | {
|
| 1275 | if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX))
|
| 1276 | {
|
| 1277 | LYERRLOG("handle is NULL or *handle %d is greater or equeal to %d, parameter error\n",*handle,LYNQ_CALL_MAX);
|
| 1278 | return -1;
|
| 1279 | }
|
| 1280 |
|
| 1281 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,msd_data);
|
| 1282 | }
|
| 1283 |
|
| 1284 | int lynq_set_ivs(int enable)
|
| 1285 | {
|
| 1286 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
|
| 1287 | }
|
| 1288 |
|
| 1289 | int lynq_reset_ivs()
|
| 1290 | {
|
| 1291 | return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
|
| 1292 | }
|
| 1293 |
|
| 1294 | int lynq_ivs_push_msd()
|
| 1295 | {
|
| 1296 | return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
|
| 1297 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame^] | 1298 |
|
| 1299 | int wait_ecall_event()
|
| 1300 | {
|
| 1301 | int ret = 0;
|
| 1302 | pthread_mutex_lock(&s_incoming_e_call_mutex);
|
| 1303 | ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
|
| 1304 | pthread_mutex_unlock(&s_incoming_e_call_mutex);
|
| 1305 | return ret;
|
| 1306 | }
|
| 1307 |
|
| 1308 | int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)
|
| 1309 | {
|
| 1310 | wait_ecall_event();
|
| 1311 | *eCall_Indication = lynqIncomingEcallIndication;
|
| 1312 | LYINFLOG("lynq incoming e-call indication id:%d",lynqIncomingEcallIndication);
|
| 1313 | return 0;
|
| 1314 | }
|
| 1315 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1316 | #endif
|
| 1317 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1318 | #if 0
|
| 1319 | int main(int argc,char **argv)
|
| 1320 | {
|
| 1321 | int n = 0;
|
| 1322 | n = lynq_init_call(lynq_call_state_change_test,2222);
|
| 1323 | if(n<0)
|
| 1324 | {
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 1325 | LYDBGLOG("lynq init call fail!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1326 | return -1;
|
| 1327 | }
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 1328 | LYDBGLOG("lynq call init success!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1329 | char phoneNum[LYNQ_PHONE_NUMBER_MAX];
|
| 1330 | sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
|
| 1331 | lynq_call(phoneNum);
|
| 1332 | while(1)
|
| 1333 | {
|
| 1334 | sleep(1);
|
| 1335 | }
|
| 1336 | return 0;
|
| 1337 | }
|
| 1338 | #endif
|
| 1339 | /*Warren add for T800 platform 2021/11/19 end*/
|