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