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