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>
|
| 11 | #include "lynq_call.h"
|
| 12 | #include <cutils/jstring.h>
|
| 13 | #include <pthread.h>
|
| 14 | #include "liblog/lynq_deflog.h"
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 15 | #include <sys/time.h>
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 16 | #include <string.h>
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 17 | #define LYNQ_SERVICE_PORT 8088
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 18 | #define DSET_IP_ADDRESS "127.0.0.1"
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 19 | #define LYNQ_URC_SERVICE_PORT 8086
|
| 20 | #define LYNQ_REC_BUF 8192
|
| 21 | #define LYNQ_REQUEST_PARAM_BUF 8192
|
| 22 | #define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
|
| 23 | #define USER_LOG_TAG "LYNQ_CALL"
|
| 24 |
|
| 25 | using ::android::Parcel;
|
| 26 | typedef enum {
|
| 27 | LYNQ_CALL_ACTIVE = 0,
|
| 28 | LYNQ_CALL_HOLDING = 1,
|
| 29 | LYNQ_CALL_DIALING = 2, /* MO call only */
|
| 30 | LYNQ_CALL_ALERTING = 3, /* MO call only */
|
| 31 | LYNQ_CALL_INCOMING = 4, /* MT call only */
|
| 32 | LYNQ_CALL_WAITING = 5 ,/* MT call only */
|
| 33 | }lynq_call_state_t;
|
| 34 |
|
| 35 | typedef struct{
|
| 36 | int uToken;
|
| 37 | int request;
|
| 38 | int paramLen;
|
| 39 | char param[LYNQ_REQUEST_PARAM_BUF];
|
| 40 | }lynq_client_t;
|
| 41 | typedef struct
|
| 42 | {
|
| 43 | int used;
|
| 44 | int call_id;
|
| 45 | int call_state;
|
| 46 | int toa;
|
| 47 | int direction;/*0: MO call,1:MT call*/
|
| 48 | char addr[LYNQ_PHONE_NUMBER_MAX];
|
| 49 | int hasTimeout;
|
| 50 | }lynq_call_list_e_t;
|
| 51 | typedef struct
|
| 52 | {
|
| 53 | int call_id;
|
| 54 | int call_state;
|
| 55 | int toa;
|
| 56 | int direction;/*0: MO call,1:MT call*/
|
| 57 | char addr[LYNQ_PHONE_NUMBER_MAX];
|
| 58 | }lynq_call_list_t;
|
| 59 |
|
| 60 | lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
|
| 61 | static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 62 | static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 63 | static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 64 | static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
| 65 | static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 66 | static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 67 | pthread_t lynq_call_urc_tid = -1;
|
| 68 | pthread_t lynq_call_list_loop_tid = -1;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 69 |
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 70 | /*lei add*/
|
| 71 | /* socket文件描述符 */
|
| 72 | int len_addr_serv;
|
| 73 | struct sockaddr_in addr_serv;
|
| 74 | lynq_client_t client_t;
|
| 75 | int client_size = 0;
|
| 76 | /*lei add*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 77 |
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 78 | int s_call_urc_event_complete = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 79 |
|
| 80 | enum{
|
| 81 | CALL_OFF=0,
|
| 82 | CALL_ON=1
|
| 83 | }call_state;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 84 | typedef enum{
|
| 85 | LYNQ_E_CARDSTATE_ERROR=8000,
|
| 86 | /* The voice service state is out of service*/
|
| 87 | LYNQ_E_STATE_OUT_OF_SERVICE=8001,
|
| 88 | /* The voice service state is EMERGENCY_ONLY*/
|
| 89 | LYNQ_E_STATE_EMERGENCY_ONLY=8002,
|
| 90 | /* The radio power is power off*/
|
| 91 | LYNQ_E_STATE_POWER_OFF=8003,
|
| 92 | LYNQ_E_TIME_OUT=8004,
|
| 93 | /*create or open sms DB fail */
|
| 94 | LYNQ_E_SMS_DB_FAIL=8005,
|
| 95 | /*Failed to execute sql statement*/
|
| 96 | LYNQ_E_SMS_SQL_FAIL = 8006,
|
| 97 | LYNQ_E_SMS_NOT_FIND = 8007,
|
| 98 | /* The logic conflict*/
|
| 99 | LYNQ_E_CONFLICT=9000,
|
| 100 | /*Null anomaly*/
|
| 101 | LYNQ_E_NULL_ANONALY=9001
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 102 | }LYNQ_E;
|
| 103 |
|
| 104 | int lynq_call_state =CALL_OFF;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 105 | int lynq_call_client_sockfd = 0;
|
| 106 | int Global_uToken_call = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 107 | int global_call_count =0;
|
| 108 | int global_call_auto_answer = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 109 | bool urc_call_recive_status = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 110 | bool call_list_loop = 1;
|
| 111 | int isDial = 0;
|
| 112 | int lynqIncomingCallId = 0;
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 113 | /**
|
| 114 | * @brief mark call initialization state
|
| 115 | * 0: deinit state
|
| 116 | * 1: init state
|
| 117 | */
|
| 118 | int g_lynq_call_init_flag = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 119 |
|
| 120 | int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
|
| 121 | {
|
| 122 | if(p.dataAvail() > 0)
|
| 123 | {
|
| 124 | p.readInt32(resp_type);
|
| 125 | p.readInt32(request);
|
| 126 | p.readInt32(slot_id);
|
| 127 | p.readInt32(error);
|
| 128 | return 0;
|
| 129 | }
|
| 130 | else
|
| 131 | {
|
| 132 | return -1;
|
| 133 | }
|
| 134 | }
|
| 135 | int send_request(int sockfd,lynq_client_t *client_tmp)
|
| 136 | {
|
| 137 | int ret=0;
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 138 | 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] | 139 | if(ret==-1)
|
| 140 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 141 | LYERRLOG("sendto error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 142 | return -1;
|
| 143 | }
|
| 144 | return 0;
|
| 145 | }
|
| 146 |
|
| 147 | int get_response(int sockfd,Parcel &p)
|
| 148 | {
|
| 149 | int len = 0;
|
| 150 | char recvline[LYNQ_REC_BUF];
|
| 151 | bzero(recvline,LYNQ_REC_BUF);
|
| 152 | /* receive data from server */
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 153 | 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] | 154 | if(len == -1)
|
| 155 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 156 | LYERRLOG("recvfrom error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 157 | return -1;
|
| 158 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 159 | if (recvline != NULL) {
|
| 160 | p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
|
| 161 | p.setDataPosition(0);
|
| 162 | }
|
| 163 | return 0;
|
| 164 | }
|
| 165 | static char *strdupReadString(Parcel &p) {
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 166 | size_t stringlen;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 167 | const char16_t *s16;
|
| 168 | s16 = p.readString16Inplace(&stringlen);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 169 | return strndup16to8(s16, stringlen);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 170 | }
|
| 171 |
|
| 172 | int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
|
| 173 | {
|
| 174 | Parcel p;
|
| 175 | lynq_client_t client;
|
| 176 | int resp_type = -1;
|
| 177 | int request = -1;
|
| 178 | int slot_id = -1;
|
| 179 | int error = -1;
|
| 180 | int call_num = 0;
|
| 181 | int temp = 0;
|
| 182 | char *remote_phoneNum = NULL;
|
| 183 | char *remote_name= NULL;
|
| 184 | char *uusData = NULL;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 185 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 186 | client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
|
| 187 | client.paramLen = 0;
|
| 188 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 189 | 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] | 190 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 191 | {
|
| 192 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 193 | return -1;
|
| 194 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 195 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 196 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 197 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 198 | if(error == 0)
|
| 199 | {
|
| 200 | p.readInt32(&call_num);
|
| 201 | global_call_count = call_num;
|
| 202 | if(call_num<=0)
|
| 203 | {
|
| 204 | lynq_call_state = CALL_OFF;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 205 | LYINFLOG("lynq_call_state:%d",lynq_call_state);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 206 | return 0;
|
| 207 | }
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 208 | lynq_call_state = CALL_ON;
|
| 209 | LYINFLOG("lynq_call_state:%d",lynq_call_state);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 210 | for(int i = 0;i < call_num;i++)
|
| 211 | {
|
| 212 | p.readInt32(&temp);
|
| 213 | call_list[i].call_state = temp;
|
| 214 | p.readInt32(&call_list[i].call_id);
|
| 215 | p.readInt32(&call_list[i].toa);
|
| 216 | p.readInt32(&temp);
|
| 217 | p.readInt32(&temp);
|
| 218 | call_list[i].direction = temp;
|
| 219 | p.readInt32(&temp);
|
| 220 | p.readInt32(&temp);
|
| 221 | p.readInt32(&temp);
|
| 222 | remote_phoneNum = strdupReadString(p);
|
| 223 | memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
|
| 224 | LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
|
| 225 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 226 | p.readInt32(&temp);
|
| 227 | remote_name = strdupReadString(p);
|
| 228 | p.readInt32(&temp);
|
| 229 | p.readInt32(&temp);
|
| 230 | if(temp==0)
|
| 231 | {
|
| 232 | continue;
|
| 233 | }
|
| 234 | p.readInt32(&temp); /* UUS Information is present */
|
| 235 | p.readInt32(&temp);
|
| 236 | p.readInt32(&temp);
|
| 237 | p.read(uusData,temp);
|
| 238 | }
|
| 239 | }
|
| 240 | return 0;
|
| 241 | }
|
| 242 |
|
| 243 | void cleanCallList(int lynq_call_id)
|
| 244 | {
|
| 245 | lynq_call_lists[lynq_call_id].call_id = 0;
|
| 246 | lynq_call_lists[lynq_call_id].call_state = 0;
|
| 247 | lynq_call_lists[lynq_call_id].toa = 0;
|
| 248 | lynq_call_lists[lynq_call_id].direction = 0;
|
| 249 | lynq_call_lists[lynq_call_id].used = 0;
|
| 250 | lynq_call_lists[lynq_call_id].hasTimeout = 0;
|
| 251 | memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
|
| 252 | }
|
| 253 | int getUnusedElement()
|
| 254 | {
|
| 255 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 256 | {
|
| 257 | if(lynq_call_lists[i].used!=1)
|
| 258 | {
|
| 259 | return i;
|
| 260 | }
|
| 261 | }
|
| 262 | return -1;
|
| 263 | }
|
| 264 | int updateAddr(char addr[])
|
| 265 | {
|
| 266 | int ret = 0;
|
| 267 | ret = getUnusedElement();
|
| 268 | memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
|
| 269 | lynq_call_lists[ret].used = 1;
|
| 270 | return ret;
|
| 271 | }
|
| 272 | void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
|
| 273 | {
|
| 274 | callList->call_id = call_id;
|
| 275 | callList->call_state = call_state;
|
| 276 | callList->toa = toa;
|
| 277 | callList->direction = direction;
|
| 278 | callList->used = 1;
|
| 279 | callList->hasTimeout = 0;
|
| 280 | return;
|
| 281 | }
|
| 282 | int waitCallstateChange(int mtime)
|
| 283 | {
|
| 284 | int ret = 0;
|
| 285 | int sec = 0;
|
| 286 | int usec = 0;
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 287 | struct timeval now;
|
| 288 | struct timespec timeout;
|
| 289 | gettimeofday(&now,NULL);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 290 | sec = mtime/1000;
|
| 291 | usec = mtime%1000;
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 292 | timeout.tv_sec = now.tv_sec+sec;
|
| 293 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 294 | pthread_mutex_lock(&call_state_change_mutex);
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 295 | ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 296 | pthread_mutex_unlock(&call_state_change_mutex);
|
| 297 | return ret;
|
| 298 | }
|
| 299 | int waitIncomingCall()
|
| 300 | {
|
| 301 | int ret = 0;
|
| 302 | pthread_mutex_lock(&s_incoming_call_mutex);
|
| 303 | ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
|
| 304 | pthread_mutex_unlock(&s_incoming_call_mutex);
|
| 305 | return ret;
|
| 306 | }
|
| 307 | int checkHasCall(char addr[])
|
| 308 | {
|
| 309 | for(int i = 0;i<LYNQ_CALL_MAX;i++)
|
| 310 | {
|
| 311 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 312 | {
|
| 313 | return 1;
|
| 314 | }
|
| 315 | }
|
| 316 | return 0;
|
| 317 | }
|
| 318 | void sendSignalToWaitCallStateChange()
|
| 319 | {
|
| 320 | pthread_mutex_lock(&call_state_change_mutex);
|
| 321 | pthread_cond_signal(&call_state_change_cond);
|
| 322 | pthread_mutex_unlock(&call_state_change_mutex);
|
| 323 | }
|
| 324 | void sendSignalIncomingCall()
|
| 325 | {
|
| 326 | pthread_mutex_lock(&s_incoming_call_mutex);
|
| 327 | pthread_cond_signal(&s_incoming_call_cond);
|
| 328 | pthread_mutex_unlock(&s_incoming_call_mutex);
|
| 329 | }
|
| 330 |
|
| 331 | void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
|
| 332 | {
|
| 333 | callList->call_id = call_id;
|
| 334 | callList->call_state = call_state;
|
| 335 | callList->toa = toa;
|
| 336 | callList->direction = direction;
|
| 337 | memcpy(callList->addr,addr,strlen(addr)+1);
|
| 338 | callList->used = 1;
|
| 339 | callList->hasTimeout = 0;
|
| 340 | return;
|
| 341 | }
|
| 342 |
|
| 343 | void *triggerGetCallList(void *parg)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 344 | {
|
| 345 | int ret=0;
|
| 346 | lynq_call_list_t call_list[LYNQ_CALL_MAX];
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 347 | while(call_list_loop)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 348 | {
|
| 349 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 350 | 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] | 351 | LYDBGLOG("triggerGetCallList event!!!\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 352 | memset(call_list,0,sizeof(call_list));
|
| 353 | ret = lynq_get_current_call_list(call_list);
|
| 354 | if(ret != 0)
|
| 355 | {
|
| 356 | printf("get current call list failure!!!\n");
|
| 357 | break;
|
| 358 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 359 | for(int i = 0;i < LYNQ_CALL_MAX;i++)
|
| 360 | {
|
| 361 | if(call_list[i].direction == 1)//MT call
|
| 362 | {
|
| 363 | if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
|
| 364 | {
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame^] | 365 | /*you call me, and i call you,One party failed to dial*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 366 | if(!checkHasCall(call_list[i].addr))
|
| 367 | {
|
| 368 | lynqIncomingCallId = getUnusedElement();
|
| 369 | 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);
|
| 370 | sendSignalIncomingCall();
|
| 371 | }
|
| 372 | }
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame^] | 373 | /*if state changed*/
|
| 374 | else
|
| 375 | {
|
| 376 | /*update call state*/
|
| 377 | for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
|
| 378 | {
|
| 379 | if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
|
| 380 | {
|
| 381 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
| 382 | }
|
| 383 | }
|
| 384 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 385 | }
|
| 386 | else
|
| 387 | {
|
| 388 | if(call_list[i].call_id==0)
|
| 389 | {
|
| 390 | break;
|
| 391 | }
|
| 392 | for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
|
| 393 | {
|
| 394 | if(lynq_call_lists[n].hasTimeout==1)
|
| 395 | {
|
| 396 | /*hangup call with id*/
|
| 397 | lynq_call_hungup(&n);
|
| 398 | lynq_call_lists[n].hasTimeout==0;
|
| 399 | continue;
|
| 400 | }
|
| 401 | if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
|
| 402 | {
|
| 403 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
| 404 | }
|
| 405 | }
|
| 406 | 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,
|
| 407 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 408 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 409 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 410 | s_call_urc_event_complete = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 411 | if(isDial==1)
|
| 412 | {
|
| 413 | sendSignalToWaitCallStateChange();
|
| 414 | isDial = 0;
|
| 415 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 416 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
| 417 | }
|
| 418 | return NULL;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 419 | }
|
| 420 |
|
| 421 | void lynqRespWatingEvent()
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 422 | {
|
| 423 | if(s_call_urc_event_complete==1)
|
| 424 | {
|
| 425 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 426 | pthread_cond_signal(&s_urc_call_state_change_cond);
|
| 427 | s_call_urc_event_complete = 0;
|
| 428 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 429 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 430 | return;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 431 | }
|
| 432 |
|
| 433 | /*Warren add for T800 platform 2021/11/19 start*/
|
| 434 | int lynq_socket_client_start()
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 435 | {
|
| 436 | #if 0
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 437 | struct sockaddr_in lynq_socket_server_addr;
|
| 438 | /* init lynq_socket_server_addr */
|
| 439 | bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
|
| 440 | lynq_socket_server_addr.sin_family = AF_INET;
|
| 441 | lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 442 | lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 443 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 444 | /*
|
| 445 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
|
| 446 | {
|
| 447 | printf("[%s] is not a valid IPaddress\n", argv[1]);
|
| 448 | exit(1);
|
| 449 | }
|
| 450 | */
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 451 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 452 | 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] | 453 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 454 | LYERRLOG("connect error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 455 | return -1;
|
| 456 | }
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 457 | #endif
|
| 458 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 459 | if (-1 == lynq_call_client_sockfd)
|
| 460 | {
|
| 461 | return lynq_call_client_sockfd;
|
| 462 | }
|
| 463 | /* 设置address */
|
| 464 | memset(&addr_serv, 0, sizeof(addr_serv));
|
| 465 | addr_serv.sin_family = AF_INET;
|
| 466 | addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
|
| 467 | addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 468 | len_addr_serv = sizeof(addr_serv);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 469 | return 0;
|
| 470 | }
|
| 471 | int lynq_update_call_list_loop()
|
| 472 | {
|
| 473 | int ret = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 474 | pthread_attr_t attr;
|
| 475 | pthread_attr_init(&attr);
|
| 476 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 477 | ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 478 | if(ret < 0)
|
| 479 | {
|
| 480 | LYERRLOG("lynq_update_call_list_loop fail!!!");
|
| 481 | return -1;
|
| 482 | }
|
| 483 | LYDBGLOG("lynq_update_call_list_loop success!!!\n");
|
| 484 | return 0;
|
| 485 |
|
| 486 | }
|
| 487 | void *thread_urc_recv(void *parg)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 488 | {
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 489 | int socket_fd = (int64_t)parg;
|
| 490 | int len=0;
|
| 491 | socklen_t addr_len=0;
|
| 492 | uint8_t *dataLength = NULL;
|
| 493 | char urc_data[LYNQ_REC_BUF];
|
| 494 | int slot_id = -1;
|
| 495 | int resp_type = -1;
|
| 496 | int urcid = -1;
|
| 497 | Parcel *p = NULL;
|
| 498 | struct sockaddr_in dest_addr;
|
| 499 | LYINFLOG("thread_urc_recv in running....\n");
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 500 | while(urc_call_recive_status)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 501 | {
|
| 502 | bzero(urc_data,LYNQ_REC_BUF);
|
| 503 | //get data msg
|
| 504 | len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
|
| 505 | if(len <= 0)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 506 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 507 | LYERRLOG("thread_urc_recv step2 fail\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 508 | break;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 509 | }
|
| 510 | LYDBGLOG("=====>urc data len<=====:%d\n",len);
|
| 511 | p = new Parcel();
|
| 512 | if(p==NULL)
|
| 513 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 514 | LYERRLOG("new parcel failure!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 515 | break;
|
| 516 | }
|
| 517 | p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
|
| 518 | p->setDataPosition(0);
|
| 519 | if(p->dataAvail() > 0)
|
| 520 | {
|
| 521 | p->readInt32(&resp_type);
|
| 522 | p->readInt32(&urcid);
|
| 523 | p->readInt32(&slot_id);
|
| 524 | //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 525 | switch (urcid)
|
| 526 | {
|
| 527 | case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
|
| 528 | {
|
| 529 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 530 | lynqRespWatingEvent();
|
| 531 | break;
|
| 532 | }
|
| 533 | case 1018://RIL_UNSOL_CALL_RING
|
| 534 | {
|
| 535 | if(global_call_auto_answer==1)
|
| 536 | {
|
| 537 | lynq_call_answer();
|
| 538 | }
|
| 539 | break;
|
| 540 | }
|
| 541 | case 1029://RIL_UNSOL_RINGBACK_TONE
|
| 542 | case 3049://RIL_UNSOL_CALL_INFO_INDICATION
|
| 543 | {
|
| 544 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 545 | break;
|
| 546 | }
|
| 547 | default:
|
| 548 | break;
|
| 549 | }
|
| 550 | }
|
| 551 | delete p;
|
| 552 | p = NULL;
|
| 553 | }
|
| 554 | close(socket_fd);
|
| 555 | }
|
| 556 | int lynq_socket_urc_start()
|
| 557 | {
|
| 558 | int socket_fd=0;
|
| 559 | int rt=0;
|
| 560 | int len=0;
|
| 561 | int on=1;
|
| 562 | struct sockaddr_in urc_local_addr;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 563 | pthread_attr_t attr;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 564 | socket_fd = socket(AF_INET,SOCK_DGRAM,0);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 565 | if(socket_fd < 0)
|
| 566 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 567 | LYERRLOG("creaet socket for udp fail\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 568 | return -1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 569 | }
|
| 570 | urc_local_addr.sin_family = AF_INET;
|
| 571 | urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
|
| 572 | urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
| 573 | /* 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] | 574 | rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
|
| 575 | if(rt<0)
|
| 576 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 577 | LYERRLOG("SO_REUSEADDR fail\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 578 | return -1;
|
| 579 | }
|
| 580 | rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 581 | if (rt == -1)
|
| 582 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 583 | LYERRLOG("bind failed");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 584 | return -1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 585 | }
|
| 586 | pthread_attr_init(&attr);
|
| 587 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 588 | 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] | 589 | if(rt < 0)
|
| 590 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 591 | LYERRLOG("urc loop failure!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 592 | return -1;
|
| 593 | }
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 594 | LYDBGLOG("urc loop success!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 595 | return 0;
|
| 596 | }
|
| 597 | int getSelfElement(char addr[])
|
| 598 | {
|
| 599 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 600 | {
|
| 601 | if(lynq_call_lists[i].used==1)
|
| 602 | {
|
| 603 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 604 | {
|
| 605 | return i;
|
| 606 | }
|
| 607 |
|
| 608 | }
|
| 609 | }
|
| 610 | return -1;
|
| 611 | }
|
| 612 |
|
| 613 | void lynq_call_state_change_test(int soc_id)
|
| 614 | {
|
| 615 | printf("call state change,sim:%d\n",soc_id);
|
| 616 | }
|
| 617 | int lynq_init_call(int uToken)
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 618 | {
|
| 619 | if(g_lynq_call_init_flag == 1){
|
| 620 | LYDBGLOG("lynq init call failed!!!");
|
| 621 | return -1;
|
| 622 | }
|
| 623 | g_lynq_call_init_flag = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 624 | int result = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 625 | Global_uToken_call = uToken;
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 626 | urc_call_recive_status = 1;
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 627 | client_size = sizeof(client_t);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 628 | LYLOGSET(LOG_INFO);
|
| 629 | LYLOGEINIT(USER_LOG_TAG);
|
| 630 | result = lynq_socket_client_start();
|
| 631 | if(result!=0)
|
| 632 | {
|
| 633 | return -1;
|
| 634 | }
|
| 635 | result = lynq_socket_urc_start();
|
| 636 | if(result!=0)
|
| 637 | {
|
| 638 | return -1;
|
| 639 | }
|
| 640 | result = lynq_update_call_list_loop();
|
| 641 | if(result!=0)
|
| 642 | {
|
| 643 | return -1;
|
| 644 | }
|
| 645 | memset(lynq_call_lists,0,sizeof(lynq_call_lists));
|
| 646 | LYDBGLOG("lynq init call success!!!");
|
| 647 | return 0;
|
| 648 | }
|
| 649 | int lynq_deinit_call()
|
| 650 | {
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 651 | if(g_lynq_call_init_flag == 0)
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 652 | {
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 653 | LYDBGLOG("lynq_deinit_call failed!!!");
|
| 654 | return -1;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 655 | }
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 656 | else
|
| 657 | {
|
| 658 | g_lynq_call_init_flag = 0;
|
| 659 | int ret = -1;
|
| 660 | if(lynq_call_client_sockfd>0)
|
| 661 | {
|
| 662 | close(lynq_call_client_sockfd);
|
| 663 | }
|
| 664 | urc_call_recive_status = 0;
|
| 665 | call_list_loop = 0;
|
| 666 | if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
|
| 667 | {
|
| 668 | return -1;
|
| 669 | }
|
| 670 | ret = pthread_cancel(lynq_call_urc_tid);
|
| 671 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 672 | ret = pthread_cancel(lynq_call_list_loop_tid);
|
| 673 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 674 | ret = pthread_join(lynq_call_urc_tid,NULL);
|
| 675 | LYDBGLOG("pthread join ret = %d",ret);
|
| 676 | ret = pthread_join(lynq_call_list_loop_tid,NULL);
|
| 677 | LYDBGLOG("pthread join ret = %d",ret);
|
| 678 | return 0;
|
| 679 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 680 | }
|
| 681 | int lynq_call(int* handle,char addr[])
|
| 682 | {
|
| 683 | Parcel p;
|
| 684 | lynq_client_t client;
|
| 685 | int resp_type = -1;
|
| 686 | int request = -1;
|
| 687 | int slot_id = -1;
|
| 688 | int error = -1;
|
| 689 | int lynq_call_id = -1;
|
| 690 | if(addr==NULL)
|
| 691 | {
|
| 692 | LYERRLOG("Phone num is null!!!");
|
| 693 | return -1;
|
| 694 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 695 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 696 | client.request = 10;//RIL_REQUEST_DIAL
|
| 697 | client.paramLen = 2;
|
| 698 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 699 | memcpy(client.param,addr,strlen(addr)+1);
|
| 700 | strcat(client.param," 0");
|
| 701 | 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] | 702 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 703 | {
|
| 704 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 705 | return -1;
|
| 706 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 707 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 708 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 709 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 710 | lynq_call_id = updateAddr(addr);
|
| 711 | if(error==0)
|
| 712 | {
|
| 713 | isDial = 1;
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame^] | 714 | if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 715 | {
|
| 716 | error = LYNQ_E_TIME_OUT;
|
| 717 | LYERRLOG("timeout:wait Call state fail!!!");
|
| 718 | lynq_call_lists[lynq_call_id].hasTimeout = 1;
|
| 719 | return error;
|
| 720 | }
|
| 721 | *handle = lynq_call_id;
|
| 722 | }
|
| 723 | return error;
|
| 724 | }
|
| 725 | int lynq_call_answer()
|
| 726 | {
|
| 727 | Parcel p;
|
| 728 | lynq_client_t client;
|
| 729 | int resp_type = -1;
|
| 730 | int request = -1;
|
| 731 | int slot_id = -1;
|
| 732 | int error = -1;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 733 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 734 | client.request = 40;//RIL_REQUEST_DIAL
|
| 735 | client.paramLen = 0;
|
| 736 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 737 | 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] | 738 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 739 | {
|
| 740 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 741 | return -1;
|
| 742 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 743 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 744 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 745 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 746 | return error;
|
| 747 | }
|
| 748 | int lynq_call_hungup(int* handle)
|
| 749 | {
|
| 750 | Parcel p;
|
| 751 | lynq_client_t client;
|
| 752 | int resp_type = -1;
|
| 753 | int request = -1;
|
| 754 | int slot_id = -1;
|
| 755 | int error = -1;
|
| 756 | int call_id = 0;
|
| 757 | int lynq_call_id = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 758 | if(handle==NULL||!((*handle>=0)&&(*handle<10)))
|
| 759 | {
|
| 760 | LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
|
| 761 | return LYNQ_E_CONFLICT;
|
| 762 | }
|
| 763 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 764 | client.request = 12;//RIL_REQUEST_HUNGUP
|
| 765 | client.paramLen = 1;
|
| 766 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 767 | lynq_call_id = *handle;
|
| 768 | call_id = lynq_call_lists[lynq_call_id].call_id;
|
| 769 | sprintf(client.param,"%d",call_id);
|
| 770 | 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] | 771 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 772 | {
|
| 773 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 774 | return -1;
|
| 775 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 776 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 777 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 778 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 779 | if(error==0)
|
| 780 | {
|
| 781 | cleanCallList(lynq_call_id);
|
| 782 | }
|
| 783 | return error;
|
| 784 | }
|
| 785 | int lynq_call_hungup_all()
|
| 786 | {
|
| 787 | Parcel p;
|
| 788 | lynq_client_t client;
|
| 789 | int resp_type = -1;
|
| 790 | int request = -1;
|
| 791 | int slot_id = -1;
|
| 792 | int error = -1;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 793 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 794 | client.request = 17;//RIL_REQUEST_UDUB
|
| 795 | client.paramLen = 0;
|
| 796 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 797 | 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] | 798 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 799 | {
|
| 800 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 801 | return -1;
|
| 802 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 803 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 804 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 805 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 806 | return error;
|
| 807 | }
|
| 808 | int lynq_wait_incoming_call(int *handle)
|
| 809 | {
|
| 810 | waitIncomingCall();
|
| 811 | *handle = lynqIncomingCallId;
|
| 812 | LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
|
| 813 | return 0;
|
| 814 | }
|
| 815 |
|
| 816 | int lynq_set_auto_answercall(const int mode)
|
| 817 | {
|
| 818 | global_call_auto_answer = mode;
|
| 819 | LYINFLOG("auto answer call mode =%d",mode);
|
| 820 | return 0;
|
| 821 | }
|
| 822 | int lynq_get_mute_status(int *status)
|
| 823 | {
|
| 824 | Parcel p;
|
| 825 | lynq_client_t client;
|
| 826 | int resp_type = -1;
|
| 827 | int request = -1;
|
| 828 | int slot_id = -1;
|
| 829 | int error = -1;
|
| 830 | if(status==NULL)
|
| 831 | {
|
| 832 | LYERRLOG("status is null");
|
| 833 | return -1;
|
| 834 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 835 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 836 | client.request = 54;//RIL_REQUEST_GET_MUTE
|
| 837 | client.paramLen = 0;
|
| 838 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 839 | 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] | 840 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 841 | {
|
| 842 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 843 | return -1;
|
| 844 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 845 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 846 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 847 | p.readInt32(status);
|
| 848 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 849 | return error;
|
| 850 | }
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 851 |
|
| 852 | static int judge_mic(const int enable){
|
ll | f512fa3 | 2022-02-14 08:58:16 +0000 | [diff] [blame] | 853 | switch(enable){
|
| 854 | case 0:
|
| 855 | return 1;
|
| 856 | case 1:
|
| 857 | return 1;
|
| 858 | default:
|
| 859 | return 0;
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 860 | }
|
| 861 | }
|
| 862 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 863 | int lynq_set_mute_mic(const int enable)
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 864 | {
|
| 865 | if(!judge_mic(enable)){
|
| 866 | return LYNQ_E_CONFLICT;
|
| 867 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 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;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 874 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 875 | client.request = 53;//RIL_REQUEST_SET_MUTE
|
| 876 | client.paramLen = 1;
|
| 877 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 878 | sprintf(client.param,"%d",enable);
|
| 879 | 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] | 880 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 881 | {
|
| 882 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 883 | return -1;
|
| 884 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 885 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 886 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 887 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 888 | return error;
|
| 889 | }
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame^] | 890 |
|
| 891 | /**
|
| 892 | * @brief Check whether DTMF is valid
|
| 893 | *
|
| 894 | * @param callnum dtmf eg:0-9 * #
|
| 895 | * @return int
|
| 896 | */
|
| 897 | static int judge_dtmf(const char callnum)
|
| 898 | {
|
| 899 | if(callnum == '#')
|
| 900 | {
|
| 901 | return 1;
|
| 902 | }
|
| 903 | if(callnum == '*')
|
| 904 | {
|
| 905 | return 1;
|
| 906 | }
|
| 907 | if(callnum >= '0'&& callnum <= '9')
|
| 908 | {
|
| 909 | return 1;
|
| 910 | }
|
| 911 | return 0;
|
| 912 | }
|
| 913 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 914 | int lynq_set_DTMF(const char callnum)
|
| 915 | {
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame^] | 916 | if(!judge_dtmf(callnum))
|
| 917 | {
|
| 918 | return LYNQ_E_CONFLICT;
|
| 919 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 920 | Parcel p;
|
| 921 | lynq_client_t client;
|
| 922 | int resp_type = -1;
|
| 923 | int request = -1;
|
| 924 | int slot_id = -1;
|
| 925 | int error = -1;
|
| 926 | if(!lynq_call_state)
|
| 927 | {
|
| 928 | LYERRLOG("LYNQ_E_CONFLICT");
|
| 929 | return LYNQ_E_CONFLICT;
|
| 930 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 931 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 932 | client.request = 24;//RIL_REQUEST_DTMF
|
| 933 | client.paramLen = 1;
|
| 934 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 935 | sprintf(client.param,"%c",callnum);
|
| 936 | 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] | 937 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 938 | {
|
| 939 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 940 | return -1;
|
| 941 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 942 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 943 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 944 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 945 | return error;
|
| 946 |
|
| 947 | }
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 948 |
|
| 949 | static int judge_volume(const int volume){
|
| 950 | if(volume < 0 ||volume >36){
|
| 951 | return 0;
|
| 952 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 953 | return 1;
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 954 | }
|
| 955 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 956 | int lynq_set_DTMF_volume(const int volume)
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 957 | {
|
| 958 | if(!judge_volume(volume)){
|
| 959 | return LYNQ_E_CONFLICT;
|
| 960 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 961 | Parcel p;
|
| 962 | lynq_client_t client;
|
| 963 | int resp_type = -1;
|
| 964 | int request = -1;
|
| 965 | int slot_id = -1;
|
| 966 | int error = -1;
|
| 967 | //if(!lynq_call_state)
|
| 968 | //{
|
| 969 | // LYERRLOG("LYNQ_E_CONFLICT");
|
| 970 | // return LYNQ_E_CONFLICT;
|
| 971 | //}
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 972 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 973 | client.request = 8003;//LYNQ_REQUEST_SET_DTMF_VOLUME
|
| 974 | client.paramLen = 1;
|
| 975 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 976 | sprintf(client.param,"%d",volume);
|
| 977 | 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] | 978 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 979 | {
|
| 980 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 981 | return -1;
|
| 982 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 983 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 984 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 985 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 986 | return 0;
|
| 987 | }
|
| 988 | int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
|
| 989 | {
|
| 990 | int lynq_call_id = 0;
|
| 991 | if(handle==NULL)
|
| 992 | {
|
| 993 | return LYNQ_E_NULL_ANONALY;
|
| 994 | }
|
| 995 | lynq_call_id = *handle;
|
| 996 | *call_state = lynq_call_lists[lynq_call_id].call_state;
|
| 997 | *toa = lynq_call_lists[lynq_call_id].toa;
|
| 998 | *direction = lynq_call_lists[lynq_call_id].direction;
|
| 999 | memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
|
| 1000 | return 0;
|
| 1001 | }
|
| 1002 |
|
| 1003 | #if 0
|
| 1004 | int main(int argc,char **argv)
|
| 1005 | {
|
| 1006 | int n = 0;
|
| 1007 | n = lynq_init_call(lynq_call_state_change_test,2222);
|
| 1008 | if(n<0)
|
| 1009 | {
|
| 1010 | printf("lynq init call fail!!!\n");
|
| 1011 | return -1;
|
| 1012 | }
|
| 1013 | printf("lynq call init success!!!\n");
|
| 1014 | char phoneNum[LYNQ_PHONE_NUMBER_MAX];
|
| 1015 | sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
|
| 1016 | lynq_call(phoneNum);
|
| 1017 | while(1)
|
| 1018 | {
|
| 1019 | sleep(1);
|
| 1020 | }
|
| 1021 | return 0;
|
| 1022 | }
|
| 1023 | #endif
|
| 1024 | /*Warren add for T800 platform 2021/11/19 end*/
|