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