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