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>
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 11 | #include <cutils/jstring.h>
|
| 12 | #include <pthread.h>
|
| 13 | #include "liblog/lynq_deflog.h"
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 14 | #include <sys/time.h>
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 15 | #include <string.h>
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 16 | #include <vendor-ril/telephony/ril.h>
|
| 17 | #include <vendor-ril/telephony/mtk_ril_sp.h>
|
| 18 | #include <vendor-ril/telephony/mtk_ril_ivt.h>
|
| 19 | #include "lynq_call.h"
|
| 20 |
|
| 21 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 22 | #define LYNQ_SERVICE_PORT 8088
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 23 | #define DSET_IP_ADDRESS "127.0.0.1"
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 24 | #define LYNQ_URC_SERVICE_PORT 8086
|
| 25 | #define LYNQ_REC_BUF 8192
|
| 26 | #define LYNQ_REQUEST_PARAM_BUF 8192
|
| 27 | #define LYQN_SEDN_BUF 1024*8+sizeof(int)*3
|
| 28 | #define USER_LOG_TAG "LYNQ_CALL"
|
| 29 |
|
| 30 | using ::android::Parcel;
|
| 31 | typedef enum {
|
| 32 | LYNQ_CALL_ACTIVE = 0,
|
| 33 | LYNQ_CALL_HOLDING = 1,
|
| 34 | LYNQ_CALL_DIALING = 2, /* MO call only */
|
| 35 | LYNQ_CALL_ALERTING = 3, /* MO call only */
|
| 36 | LYNQ_CALL_INCOMING = 4, /* MT call only */
|
lh | e45b700 | 2022-04-26 00:45:44 -0700 | [diff] [blame^] | 37 | LYNQ_CALL_WAITING = 5, /* MT call only */
|
| 38 | /*warren add for T800 platform 2022/04/26 start*/
|
| 39 | LYNQ_CALL_END = 6, /*CALL END*/
|
| 40 | /*warren add for T800 platform 2022/04/26 end*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 41 | }lynq_call_state_t;
|
| 42 |
|
| 43 | typedef struct{
|
| 44 | int uToken;
|
| 45 | int request;
|
| 46 | int paramLen;
|
| 47 | char param[LYNQ_REQUEST_PARAM_BUF];
|
| 48 | }lynq_client_t;
|
| 49 | typedef struct
|
| 50 | {
|
| 51 | int used;
|
| 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 | int hasTimeout;
|
| 58 | }lynq_call_list_e_t;
|
| 59 | typedef struct
|
| 60 | {
|
| 61 | int call_id;
|
| 62 | int call_state;
|
| 63 | int toa;
|
| 64 | int direction;/*0: MO call,1:MT call*/
|
| 65 | char addr[LYNQ_PHONE_NUMBER_MAX];
|
| 66 | }lynq_call_list_t;
|
| 67 |
|
| 68 | lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
|
| 69 | static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 70 | static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 71 | static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 72 | static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
| 73 | static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 74 | static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 75 | pthread_t lynq_call_urc_tid = -1;
|
| 76 | pthread_t lynq_call_list_loop_tid = -1;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 77 |
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 78 | /*lei add*/
|
| 79 | /* socket文件描述符 */
|
| 80 | int len_addr_serv;
|
| 81 | struct sockaddr_in addr_serv;
|
| 82 | lynq_client_t client_t;
|
| 83 | int client_size = 0;
|
| 84 | /*lei add*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 85 |
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 86 | int s_call_urc_event_complete = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 87 |
|
| 88 | enum{
|
| 89 | CALL_OFF=0,
|
| 90 | CALL_ON=1
|
| 91 | }call_state;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 92 | typedef enum{
|
| 93 | LYNQ_E_CARDSTATE_ERROR=8000,
|
| 94 | /* The voice service state is out of service*/
|
| 95 | LYNQ_E_STATE_OUT_OF_SERVICE=8001,
|
| 96 | /* The voice service state is EMERGENCY_ONLY*/
|
| 97 | LYNQ_E_STATE_EMERGENCY_ONLY=8002,
|
| 98 | /* The radio power is power off*/
|
| 99 | LYNQ_E_STATE_POWER_OFF=8003,
|
| 100 | LYNQ_E_TIME_OUT=8004,
|
| 101 | /*create or open sms DB fail */
|
| 102 | LYNQ_E_SMS_DB_FAIL=8005,
|
| 103 | /*Failed to execute sql statement*/
|
| 104 | LYNQ_E_SMS_SQL_FAIL = 8006,
|
| 105 | LYNQ_E_SMS_NOT_FIND = 8007,
|
| 106 | /* The logic conflict*/
|
| 107 | LYNQ_E_CONFLICT=9000,
|
| 108 | /*Null anomaly*/
|
| 109 | LYNQ_E_NULL_ANONALY=9001
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 110 | }LYNQ_E;
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 111 | typedef enum{
|
| 112 | LYNQ_E_VOLUMN_SET_DTMF,
|
| 113 | LYNQ_E_VOLUMN_SET_SPEECH
|
| 114 | }LYNQ_E_VOLUMN_SET;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 115 |
|
| 116 | int lynq_call_state =CALL_OFF;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 117 | int lynq_call_client_sockfd = 0;
|
| 118 | int Global_uToken_call = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 119 | int global_call_count =0;
|
| 120 | int global_call_auto_answer = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 121 | bool urc_call_recive_status = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 122 | bool call_list_loop = 1;
|
| 123 | int isDial = 0;
|
| 124 | int lynqIncomingCallId = 0;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 125 |
|
| 126 | #ifdef ECALL_SUPPORT
|
| 127 | typedef enum{
|
| 128 | LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
|
| 129 | LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 130 | LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
|
| 131 | LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */\
|
| 132 | }LYNQ_ECall_Type;
|
| 133 |
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 134 | char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"","null","112"};
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 | static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 139 | static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
|
| 140 |
|
| 141 | LYNQ_ECall_Indication lynqIncomingEcallIndication;
|
| 142 | int lynqEcallId;
|
| 143 |
|
| 144 | void sendSignalIncomingECallEvent()
|
| 145 | {
|
| 146 | pthread_mutex_lock(&s_incoming_e_call_mutex);
|
| 147 | pthread_cond_signal(&s_incoming_e_call_cond);
|
| 148 | pthread_mutex_unlock(&s_incoming_e_call_mutex);
|
| 149 | }
|
| 150 | #endif
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 151 |
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 152 | /**
|
| 153 | * @brief mark call initialization state
|
| 154 | * 0: deinit state
|
| 155 | * 1: init state
|
| 156 | */
|
| 157 | int g_lynq_call_init_flag = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 158 |
|
| 159 | int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
|
| 160 | {
|
| 161 | if(p.dataAvail() > 0)
|
| 162 | {
|
| 163 | p.readInt32(resp_type);
|
| 164 | p.readInt32(request);
|
| 165 | p.readInt32(slot_id);
|
| 166 | p.readInt32(error);
|
| 167 | return 0;
|
| 168 | }
|
| 169 | else
|
| 170 | {
|
| 171 | return -1;
|
| 172 | }
|
| 173 | }
|
| 174 | int send_request(int sockfd,lynq_client_t *client_tmp)
|
| 175 | {
|
| 176 | int ret=0;
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 177 | 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] | 178 | if(ret==-1)
|
| 179 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 180 | LYERRLOG("sendto error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 181 | return -1;
|
| 182 | }
|
| 183 | return 0;
|
| 184 | }
|
| 185 |
|
| 186 | int get_response(int sockfd,Parcel &p)
|
| 187 | {
|
| 188 | int len = 0;
|
| 189 | char recvline[LYNQ_REC_BUF];
|
| 190 | bzero(recvline,LYNQ_REC_BUF);
|
| 191 | /* receive data from server */
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 192 | 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] | 193 | if(len == -1)
|
| 194 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 195 | LYERRLOG("recvfrom error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 196 | return -1;
|
| 197 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 198 | if (recvline != NULL) {
|
| 199 | p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
|
| 200 | p.setDataPosition(0);
|
| 201 | }
|
| 202 | return 0;
|
| 203 | }
|
| 204 | static char *strdupReadString(Parcel &p) {
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 205 | size_t stringlen;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 206 | const char16_t *s16;
|
| 207 | s16 = p.readString16Inplace(&stringlen);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 208 | return strndup16to8(s16, stringlen);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 209 | }
|
| 210 |
|
| 211 | int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
|
| 212 | {
|
| 213 | Parcel p;
|
| 214 | lynq_client_t client;
|
| 215 | int resp_type = -1;
|
| 216 | int request = -1;
|
| 217 | int slot_id = -1;
|
| 218 | int error = -1;
|
| 219 | int call_num = 0;
|
| 220 | int temp = 0;
|
| 221 | char *remote_phoneNum = NULL;
|
| 222 | char *remote_name= NULL;
|
| 223 | char *uusData = NULL;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 224 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 225 | client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
|
| 226 | client.paramLen = 0;
|
| 227 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 228 | 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] | 229 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 230 | {
|
| 231 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 232 | return -1;
|
| 233 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 234 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 235 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 236 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 237 | if(error == 0)
|
| 238 | {
|
| 239 | p.readInt32(&call_num);
|
| 240 | global_call_count = call_num;
|
| 241 | if(call_num<=0)
|
| 242 | {
|
| 243 | lynq_call_state = CALL_OFF;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 244 | LYINFLOG("lynq_call_state:%d",lynq_call_state);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 245 | return 0;
|
| 246 | }
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 247 | lynq_call_state = CALL_ON;
|
| 248 | LYINFLOG("lynq_call_state:%d",lynq_call_state);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 249 | for(int i = 0;i < call_num;i++)
|
| 250 | {
|
| 251 | p.readInt32(&temp);
|
| 252 | call_list[i].call_state = temp;
|
| 253 | p.readInt32(&call_list[i].call_id);
|
| 254 | p.readInt32(&call_list[i].toa);
|
| 255 | p.readInt32(&temp);
|
| 256 | p.readInt32(&temp);
|
| 257 | call_list[i].direction = temp;
|
| 258 | p.readInt32(&temp);
|
| 259 | p.readInt32(&temp);
|
| 260 | p.readInt32(&temp);
|
| 261 | remote_phoneNum = strdupReadString(p);
|
| 262 | memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
|
| 263 | LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
|
| 264 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 265 | p.readInt32(&temp);
|
| 266 | remote_name = strdupReadString(p);
|
| 267 | p.readInt32(&temp);
|
| 268 | p.readInt32(&temp);
|
| 269 | if(temp==0)
|
| 270 | {
|
| 271 | continue;
|
| 272 | }
|
| 273 | p.readInt32(&temp); /* UUS Information is present */
|
| 274 | p.readInt32(&temp);
|
| 275 | p.readInt32(&temp);
|
| 276 | p.read(uusData,temp);
|
| 277 | }
|
| 278 | }
|
| 279 | return 0;
|
| 280 | }
|
| 281 |
|
| 282 | void cleanCallList(int lynq_call_id)
|
| 283 | {
|
| 284 | lynq_call_lists[lynq_call_id].call_id = 0;
|
lh | e45b700 | 2022-04-26 00:45:44 -0700 | [diff] [blame^] | 285 | lynq_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 286 | lynq_call_lists[lynq_call_id].toa = 0;
|
| 287 | lynq_call_lists[lynq_call_id].direction = 0;
|
| 288 | lynq_call_lists[lynq_call_id].used = 0;
|
| 289 | lynq_call_lists[lynq_call_id].hasTimeout = 0;
|
| 290 | memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
|
| 291 | }
|
| 292 | int getUnusedElement()
|
| 293 | {
|
| 294 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 295 | {
|
| 296 | if(lynq_call_lists[i].used!=1)
|
| 297 | {
|
| 298 | return i;
|
| 299 | }
|
| 300 | }
|
| 301 | return -1;
|
| 302 | }
|
| 303 | int updateAddr(char addr[])
|
| 304 | {
|
| 305 | int ret = 0;
|
| 306 | ret = getUnusedElement();
|
| 307 | memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
|
| 308 | lynq_call_lists[ret].used = 1;
|
| 309 | return ret;
|
| 310 | }
|
| 311 | void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
|
| 312 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 313 | LYINFLOG("Update Call List");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 314 | callList->call_id = call_id;
|
| 315 | callList->call_state = call_state;
|
| 316 | callList->toa = toa;
|
| 317 | callList->direction = direction;
|
| 318 | callList->used = 1;
|
| 319 | callList->hasTimeout = 0;
|
| 320 | return;
|
| 321 | }
|
| 322 | int waitCallstateChange(int mtime)
|
| 323 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 324 | LYINFLOG("wait Call state Change");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 325 | int ret = 0;
|
| 326 | int sec = 0;
|
| 327 | int usec = 0;
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 328 | struct timeval now;
|
| 329 | struct timespec timeout;
|
| 330 | gettimeofday(&now,NULL);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 331 | sec = mtime/1000;
|
| 332 | usec = mtime%1000;
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 333 | timeout.tv_sec = now.tv_sec+sec;
|
| 334 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 335 | pthread_mutex_lock(&call_state_change_mutex);
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 336 | ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 337 | pthread_mutex_unlock(&call_state_change_mutex);
|
| 338 | return ret;
|
| 339 | }
|
| 340 | int waitIncomingCall()
|
| 341 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 342 | LYINFLOG("wait incming call");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 343 | int ret = 0;
|
| 344 | pthread_mutex_lock(&s_incoming_call_mutex);
|
| 345 | ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
|
| 346 | pthread_mutex_unlock(&s_incoming_call_mutex);
|
| 347 | return ret;
|
| 348 | }
|
| 349 | int checkHasCall(char addr[])
|
| 350 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 351 | LYINFLOG("check has call");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 352 | for(int i = 0;i<LYNQ_CALL_MAX;i++)
|
| 353 | {
|
| 354 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 355 | {
|
| 356 | return 1;
|
| 357 | }
|
| 358 | }
|
| 359 | return 0;
|
| 360 | }
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 361 | int find_call_id_with_addr(char *addr)
|
| 362 | {
|
| 363 | LYINFLOG("find call id with addr!!!");
|
| 364 | for(int id = 0; id < LYNQ_CALL_MAX; id++)
|
| 365 | {
|
| 366 | if(strcmp(lynq_call_lists[id].addr,addr) == 0)
|
| 367 | {
|
| 368 | return id;
|
| 369 | }
|
| 370 | }
|
| 371 | return -1;
|
| 372 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 373 | void sendSignalToWaitCallStateChange()
|
| 374 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 375 | LYINFLOG("send Signal To Wait Call State Change");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 376 | pthread_mutex_lock(&call_state_change_mutex);
|
| 377 | pthread_cond_signal(&call_state_change_cond);
|
| 378 | pthread_mutex_unlock(&call_state_change_mutex);
|
| 379 | }
|
| 380 | void sendSignalIncomingCall()
|
| 381 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 382 | LYINFLOG("send incoming call signal");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 383 | pthread_mutex_lock(&s_incoming_call_mutex);
|
| 384 | pthread_cond_signal(&s_incoming_call_cond);
|
| 385 | pthread_mutex_unlock(&s_incoming_call_mutex);
|
| 386 | }
|
| 387 |
|
| 388 | void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
|
| 389 | {
|
| 390 | callList->call_id = call_id;
|
| 391 | callList->call_state = call_state;
|
| 392 | callList->toa = toa;
|
| 393 | callList->direction = direction;
|
| 394 | memcpy(callList->addr,addr,strlen(addr)+1);
|
| 395 | callList->used = 1;
|
| 396 | callList->hasTimeout = 0;
|
| 397 | return;
|
| 398 | }
|
| 399 |
|
| 400 | void *triggerGetCallList(void *parg)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 401 | {
|
| 402 | int ret=0;
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 403 | bool call_end;
|
| 404 | call_end = 0;//0:this call end,1:call on
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 405 | lynq_call_list_t call_list[LYNQ_CALL_MAX];
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 406 | int update=0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 407 | while(call_list_loop)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 408 | {
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 409 | update=0;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 410 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 411 | 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] | 412 | LYDBGLOG("triggerGetCallList event!!!\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 413 | memset(call_list,0,sizeof(call_list));
|
| 414 | ret = lynq_get_current_call_list(call_list);
|
| 415 | if(ret != 0)
|
| 416 | {
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 417 | LYDBGLOG("get current call list failure!!!\n");
|
| 418 | continue;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 419 | }
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 420 | LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 421 | for(int i = 0;i < LYNQ_CALL_MAX;i++)
|
| 422 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 423 | if(strlen(lynq_call_lists[i].addr) != 0)
|
| 424 | {
|
| 425 | call_end = 0;
|
| 426 | for(int id = 0; id < LYNQ_CALL_MAX; id++)
|
| 427 | {
|
| 428 | if(strcmp(call_list[id].addr,lynq_call_lists[i].addr) == 0)
|
| 429 | {
|
| 430 | call_end = 1;
|
| 431 | LYINFLOG("find lynq call i %d, id %d!!!",i,id);
|
| 432 | }
|
| 433 | }
|
| 434 | if(call_end == 0)
|
| 435 | {
|
| 436 | LYINFLOG("MT hungup,then clean call info");
|
| 437 | cleanCallList(i);
|
| 438 | continue;
|
| 439 | }
|
| 440 | } //fix bug API-54
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 441 | if(call_list[i].direction == 1)//MT call
|
| 442 | {
|
| 443 | if(call_list[i].call_state ==4)//LYNQ_CALL_INCOMING = 4, /* MT call only */
|
| 444 | {
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 445 | /*you call me, and i call you,One party failed to dial*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 446 | if(!checkHasCall(call_list[i].addr))
|
| 447 | {
|
| 448 | lynqIncomingCallId = getUnusedElement();
|
| 449 | 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);
|
| 450 | sendSignalIncomingCall();
|
| 451 | }
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 452 | else
|
| 453 | {
|
| 454 | int temp_call_id = find_call_id_with_addr(call_list[i].addr);
|
| 455 | /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
|
| 456 | **an incoming call until the status changes.
|
| 457 | **fix bug API-54
|
| 458 | */
|
| 459 | if((temp_call_id > 0) && (lynq_call_lists[temp_call_id].call_state == call_list[i].call_state))
|
| 460 | {
|
| 461 | sendSignalIncomingCall();
|
| 462 | }
|
| 463 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 464 | }
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 465 | /*if state changed*/
|
| 466 | else
|
| 467 | {
|
| 468 | /*update call state*/
|
| 469 | for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
|
| 470 | {
|
| 471 | if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
|
| 472 | {
|
| 473 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
ll | 90a255c | 2022-04-07 09:09:55 +0000 | [diff] [blame] | 474 | break;
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 475 | }
|
| 476 | }
|
| 477 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 478 | }
|
| 479 | else
|
| 480 | {
|
| 481 | if(call_list[i].call_id==0)
|
| 482 | {
|
| 483 | break;
|
| 484 | }
|
| 485 | for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
|
| 486 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 487 | if((lynq_call_lists[n].hasTimeout == 1) && (strcmp(lynq_call_lists[n].addr,call_list[i].addr) == 0))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 488 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 489 | cleanCallList(n);//if this call time out,need clean lynq call list.
|
| 490 | /*hangup call with call id*/
|
| 491 | lynq_call_hungup(&call_list[i].call_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 492 | lynq_call_lists[n].hasTimeout==0;
|
| 493 | continue;
|
| 494 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 495 | LYDBGLOG("lynq_call_lists n is %d, used is %d, addr is %s addr2 %s\n",
|
| 496 | n,lynq_call_lists[n].used,call_list[i].addr,lynq_call_lists[n].addr);
|
| 497 | if(lynq_call_lists[n].used && (strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 498 | {
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 499 | LYINFLOG("updated\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 500 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 501 | update=1;
|
| 502 | break;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 503 | }
|
| 504 | }
|
| 505 | 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,
|
| 506 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 507 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 508 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 509 | s_call_urc_event_complete = 1;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 510 | if((isDial==1) && (update==1))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 511 | {
|
| 512 | sendSignalToWaitCallStateChange();
|
| 513 | isDial = 0;
|
| 514 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 515 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
| 516 | }
|
| 517 | return NULL;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 518 | }
|
| 519 |
|
| 520 | void lynqRespWatingEvent()
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 521 | {
|
| 522 | if(s_call_urc_event_complete==1)
|
| 523 | {
|
| 524 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 525 | pthread_cond_signal(&s_urc_call_state_change_cond);
|
| 526 | s_call_urc_event_complete = 0;
|
| 527 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 528 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 529 | return;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 530 | }
|
| 531 |
|
| 532 | /*Warren add for T800 platform 2021/11/19 start*/
|
| 533 | int lynq_socket_client_start()
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 534 | {
|
| 535 | #if 0
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 536 | struct sockaddr_in lynq_socket_server_addr;
|
| 537 | /* init lynq_socket_server_addr */
|
| 538 | bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
|
| 539 | lynq_socket_server_addr.sin_family = AF_INET;
|
| 540 | lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 541 | lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 542 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 543 | /*
|
| 544 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
|
| 545 | {
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 546 | LYDBGLOG("[%s] is not a valid IPaddress\n", argv[1]);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 547 | exit(1);
|
| 548 | }
|
| 549 | */
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 550 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 551 | 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] | 552 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 553 | LYERRLOG("connect error\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 554 | return -1;
|
| 555 | }
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 556 | #endif
|
| 557 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 558 | if (-1 == lynq_call_client_sockfd)
|
| 559 | {
|
| 560 | return lynq_call_client_sockfd;
|
| 561 | }
|
| 562 | /* 设置address */
|
| 563 | memset(&addr_serv, 0, sizeof(addr_serv));
|
| 564 | addr_serv.sin_family = AF_INET;
|
| 565 | addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
|
| 566 | addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 567 | len_addr_serv = sizeof(addr_serv);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 568 | return 0;
|
| 569 | }
|
| 570 | int lynq_update_call_list_loop()
|
| 571 | {
|
| 572 | int ret = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 573 | pthread_attr_t attr;
|
| 574 | pthread_attr_init(&attr);
|
| 575 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 576 | ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 577 | if(ret < 0)
|
| 578 | {
|
| 579 | LYERRLOG("lynq_update_call_list_loop fail!!!");
|
| 580 | return -1;
|
| 581 | }
|
| 582 | LYDBGLOG("lynq_update_call_list_loop success!!!\n");
|
| 583 | return 0;
|
| 584 |
|
| 585 | }
|
| 586 | void *thread_urc_recv(void *parg)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 587 | {
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 588 | int socket_fd = (int64_t)parg;
|
| 589 | int len=0;
|
| 590 | socklen_t addr_len=0;
|
| 591 | uint8_t *dataLength = NULL;
|
| 592 | char urc_data[LYNQ_REC_BUF];
|
| 593 | int slot_id = -1;
|
| 594 | int resp_type = -1;
|
| 595 | int urcid = -1;
|
| 596 | Parcel *p = NULL;
|
| 597 | struct sockaddr_in dest_addr;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 598 | #ifdef ECALL_SUPPORT
|
| 599 | int ecall_ind;
|
| 600 | #endif
|
| 601 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 602 | LYINFLOG("thread_urc_recv in running....\n");
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 603 | while(urc_call_recive_status)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 604 | {
|
| 605 | bzero(urc_data,LYNQ_REC_BUF);
|
| 606 | //get data msg
|
| 607 | len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
|
| 608 | if(len <= 0)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 609 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 610 | LYERRLOG("thread_urc_recv step2 fail\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 611 | break;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 612 | }
|
| 613 | LYDBGLOG("=====>urc data len<=====:%d\n",len);
|
| 614 | p = new Parcel();
|
| 615 | if(p==NULL)
|
| 616 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 617 | LYERRLOG("new parcel failure!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 618 | break;
|
| 619 | }
|
| 620 | p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
|
| 621 | p->setDataPosition(0);
|
| 622 | if(p->dataAvail() > 0)
|
| 623 | {
|
| 624 | p->readInt32(&resp_type);
|
| 625 | p->readInt32(&urcid);
|
| 626 | p->readInt32(&slot_id);
|
| 627 | //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 628 | switch (urcid)
|
| 629 | {
|
| 630 | case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
|
| 631 | {
|
| 632 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 633 | lynqRespWatingEvent();
|
| 634 | break;
|
| 635 | }
|
| 636 | case 1018://RIL_UNSOL_CALL_RING
|
| 637 | {
|
| 638 | if(global_call_auto_answer==1)
|
| 639 | {
|
| 640 | lynq_call_answer();
|
| 641 | }
|
| 642 | break;
|
| 643 | }
|
| 644 | case 1029://RIL_UNSOL_RINGBACK_TONE
|
| 645 | case 3049://RIL_UNSOL_CALL_INFO_INDICATION
|
| 646 | {
|
| 647 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 648 | break;
|
| 649 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 650 | #ifdef ECALL_SUPPORT
|
| 651 | case RIL_UNSOL_ECALL_INDICATIONS:
|
| 652 | {
|
| 653 | p->readInt32(&ecall_ind);
|
| 654 | lynqIncomingEcallIndication=ecall_ind;
|
| 655 | if(LYNQ_ECALL_ACTIVE==lynqIncomingEcallIndication)
|
| 656 | {
|
| 657 | if(isDial==1)
|
| 658 | {
|
| 659 | p->readInt32(&lynqEcallId);
|
| 660 | sendSignalToWaitCallStateChange();
|
| 661 | usleep(300*1000);
|
| 662 | }
|
| 663 | }
|
| 664 | sendSignalIncomingECallEvent();
|
| 665 | break;
|
| 666 | }
|
| 667 | #endif
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 668 | default:
|
| 669 | break;
|
| 670 | }
|
| 671 | }
|
| 672 | delete p;
|
| 673 | p = NULL;
|
| 674 | }
|
| 675 | close(socket_fd);
|
| 676 | }
|
| 677 | int lynq_socket_urc_start()
|
| 678 | {
|
| 679 | int socket_fd=0;
|
| 680 | int rt=0;
|
| 681 | int len=0;
|
| 682 | int on=1;
|
| 683 | struct sockaddr_in urc_local_addr;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 684 | pthread_attr_t attr;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 685 | socket_fd = socket(AF_INET,SOCK_DGRAM,0);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 686 | if(socket_fd < 0)
|
| 687 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 688 | LYERRLOG("creaet socket for udp fail\n");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 689 | return -1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 690 | }
|
| 691 | urc_local_addr.sin_family = AF_INET;
|
| 692 | urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
|
| 693 | urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
| 694 | /* 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] | 695 | rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
|
| 696 | if(rt<0)
|
| 697 | {
|
ll | 3fe0346 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 698 | LYERRLOG("SO_REUSEADDR fail\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 699 | return -1;
|
| 700 | }
|
| 701 | rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 702 | if (rt == -1)
|
| 703 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 704 | LYERRLOG("bind failed");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 705 | return -1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 706 | }
|
| 707 | pthread_attr_init(&attr);
|
| 708 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 709 | 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] | 710 | if(rt < 0)
|
| 711 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 712 | LYERRLOG("urc loop failure!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 713 | return -1;
|
| 714 | }
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 715 | LYDBGLOG("urc loop success!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 716 | return 0;
|
| 717 | }
|
| 718 | int getSelfElement(char addr[])
|
| 719 | {
|
| 720 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 721 | {
|
| 722 | if(lynq_call_lists[i].used==1)
|
| 723 | {
|
| 724 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 725 | {
|
| 726 | return i;
|
| 727 | }
|
| 728 |
|
| 729 | }
|
| 730 | }
|
| 731 | return -1;
|
| 732 | }
|
| 733 |
|
| 734 | void lynq_call_state_change_test(int soc_id)
|
| 735 | {
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 736 | LYDBGLOG("call state change,sim:%d\n",soc_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 737 | }
|
| 738 | int lynq_init_call(int uToken)
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 739 | {
|
| 740 | if(g_lynq_call_init_flag == 1){
|
| 741 | LYDBGLOG("lynq init call failed!!!");
|
| 742 | return -1;
|
| 743 | }
|
| 744 | g_lynq_call_init_flag = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 745 | int result = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 746 | Global_uToken_call = uToken;
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 747 | urc_call_recive_status = 1;
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 748 | client_size = sizeof(client_t);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 749 | LYLOGSET(LOG_INFO);
|
| 750 | LYLOGEINIT(USER_LOG_TAG);
|
| 751 | result = lynq_socket_client_start();
|
| 752 | if(result!=0)
|
| 753 | {
|
| 754 | return -1;
|
| 755 | }
|
| 756 | result = lynq_socket_urc_start();
|
| 757 | if(result!=0)
|
| 758 | {
|
| 759 | return -1;
|
| 760 | }
|
| 761 | result = lynq_update_call_list_loop();
|
| 762 | if(result!=0)
|
| 763 | {
|
| 764 | return -1;
|
| 765 | }
|
| 766 | memset(lynq_call_lists,0,sizeof(lynq_call_lists));
|
| 767 | LYDBGLOG("lynq init call success!!!");
|
| 768 | return 0;
|
| 769 | }
|
| 770 | int lynq_deinit_call()
|
| 771 | {
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 772 | if(g_lynq_call_init_flag == 0)
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 773 | {
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 774 | LYDBGLOG("lynq_deinit_call failed!!!");
|
| 775 | return -1;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 776 | }
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 777 | else
|
| 778 | {
|
| 779 | g_lynq_call_init_flag = 0;
|
| 780 | int ret = -1;
|
| 781 | if(lynq_call_client_sockfd>0)
|
| 782 | {
|
| 783 | close(lynq_call_client_sockfd);
|
| 784 | }
|
| 785 | urc_call_recive_status = 0;
|
| 786 | call_list_loop = 0;
|
| 787 | if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
|
| 788 | {
|
| 789 | return -1;
|
| 790 | }
|
| 791 | ret = pthread_cancel(lynq_call_urc_tid);
|
| 792 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 793 | ret = pthread_cancel(lynq_call_list_loop_tid);
|
| 794 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 795 | ret = pthread_join(lynq_call_urc_tid,NULL);
|
| 796 | LYDBGLOG("pthread join ret = %d",ret);
|
| 797 | ret = pthread_join(lynq_call_list_loop_tid,NULL);
|
| 798 | LYDBGLOG("pthread join ret = %d",ret);
|
| 799 | return 0;
|
| 800 | }
|
rita | 98e2e9c | 2022-04-07 06:08:13 -0400 | [diff] [blame] | 801 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 802 |
|
| 803 | int lynq_set_common_request(int request_id, int argc, const char* format,...)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 804 | {
|
| 805 | Parcel p;
|
| 806 | lynq_client_t client;
|
| 807 | int resp_type = -1;
|
| 808 | int request = -1;
|
| 809 | int slot_id = -1;
|
| 810 | int error = -1;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 811 |
|
| 812 | client.uToken = Global_uToken_call;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 813 | client.request = request_id;
|
| 814 | client.paramLen = argc;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 815 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 816 | if(argc!=0)
|
| 817 | {
|
| 818 | va_list args;
|
| 819 | va_start(args, format);
|
| 820 | vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
|
| 821 | va_end(args);
|
| 822 | }
|
| 823 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 824 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
| 825 | {
|
| 826 | LYERRLOG("send request fail");
|
| 827 | return -1;
|
| 828 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 829 | if(get_response(lynq_call_client_sockfd,p)==0)
|
| 830 | {
|
| 831 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 832 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 833 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 834 | return error;
|
| 835 | }
|
| 836 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 837 | int lynq_get_common_request(int request_id, int* status)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 838 | {
|
| 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;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 845 | if(status==NULL)
|
| 846 | {
|
| 847 | LYERRLOG("status is null");
|
| 848 | return -1;
|
| 849 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 850 | client.uToken = Global_uToken_call;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 851 | client.request = request_id;
|
| 852 | client.paramLen = 0;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 853 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 854 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 855 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
| 856 | {
|
| 857 | LYERRLOG("send request fail");
|
| 858 | return -1;
|
| 859 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 860 | if(get_response(lynq_call_client_sockfd,p)==0)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 861 | {
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 862 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 863 | p.readInt32(status);
|
| 864 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 865 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 866 | return error;
|
| 867 | }
|
| 868 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 869 | int lynq_call(int* handle,char addr[])
|
| 870 | {
|
| 871 | Parcel p;
|
| 872 | lynq_client_t client;
|
| 873 | int resp_type = -1;
|
| 874 | int request = -1;
|
| 875 | int slot_id = -1;
|
| 876 | int error = -1;
|
| 877 | int lynq_call_id = -1;
|
| 878 | if(addr==NULL)
|
| 879 | {
|
| 880 | LYERRLOG("Phone num is null!!!");
|
| 881 | return -1;
|
| 882 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 883 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 884 | client.request = 10;//RIL_REQUEST_DIAL
|
| 885 | client.paramLen = 2;
|
| 886 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 887 | memcpy(client.param,addr,strlen(addr)+1);
|
| 888 | strcat(client.param," 0");
|
| 889 | 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] | 890 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 891 | {
|
| 892 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 893 | return -1;
|
| 894 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 895 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 896 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 897 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 898 | lynq_call_id = updateAddr(addr);
|
| 899 | if(error==0)
|
| 900 | {
|
| 901 | isDial = 1;
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 902 | if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 903 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 904 | //if timeout,this call need destroy.
|
| 905 | isDial = 0;
|
| 906 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 907 | error = LYNQ_E_TIME_OUT;
|
| 908 | LYERRLOG("timeout:wait Call state fail!!!");
|
| 909 | lynq_call_lists[lynq_call_id].hasTimeout = 1;
|
| 910 | return error;
|
| 911 | }
|
| 912 | *handle = lynq_call_id;
|
| 913 | }
|
| 914 | return error;
|
| 915 | }
|
| 916 | int lynq_call_answer()
|
| 917 | {
|
| 918 | Parcel p;
|
| 919 | lynq_client_t client;
|
| 920 | int resp_type = -1;
|
| 921 | int request = -1;
|
| 922 | int slot_id = -1;
|
| 923 | int error = -1;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 924 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 925 | client.request = 40;//RIL_REQUEST_DIAL
|
| 926 | client.paramLen = 0;
|
| 927 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 928 | 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] | 929 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 930 | {
|
| 931 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 932 | return -1;
|
| 933 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 934 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 935 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 936 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 937 | return error;
|
| 938 | }
|
| 939 | int lynq_call_hungup(int* handle)
|
| 940 | {
|
| 941 | Parcel p;
|
| 942 | lynq_client_t client;
|
| 943 | int resp_type = -1;
|
| 944 | int request = -1;
|
| 945 | int slot_id = -1;
|
| 946 | int error = -1;
|
| 947 | int call_id = 0;
|
| 948 | int lynq_call_id = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 949 | if(handle==NULL||!((*handle>=0)&&(*handle<10)))
|
| 950 | {
|
| 951 | LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
|
| 952 | return LYNQ_E_CONFLICT;
|
| 953 | }
|
| 954 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 955 | client.request = 12;//RIL_REQUEST_HUNGUP
|
| 956 | client.paramLen = 1;
|
| 957 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 958 | lynq_call_id = *handle;
|
| 959 | call_id = lynq_call_lists[lynq_call_id].call_id;
|
| 960 | sprintf(client.param,"%d",call_id);
|
| 961 | 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] | 962 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 963 | {
|
| 964 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 965 | return -1;
|
| 966 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 967 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 968 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 969 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 970 | if(error==0)
|
| 971 | {
|
| 972 | cleanCallList(lynq_call_id);
|
| 973 | }
|
| 974 | return error;
|
| 975 | }
|
| 976 | int lynq_call_hungup_all()
|
| 977 | {
|
| 978 | Parcel p;
|
| 979 | lynq_client_t client;
|
| 980 | int resp_type = -1;
|
| 981 | int request = -1;
|
| 982 | int slot_id = -1;
|
| 983 | int error = -1;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 984 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 985 | client.request = 17;//RIL_REQUEST_UDUB
|
| 986 | client.paramLen = 0;
|
| 987 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 988 | 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] | 989 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 990 | {
|
| 991 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 992 | return -1;
|
| 993 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 994 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 995 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 996 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 997 | return error;
|
| 998 | }
|
| 999 | int lynq_wait_incoming_call(int *handle)
|
| 1000 | {
|
| 1001 | waitIncomingCall();
|
| 1002 | *handle = lynqIncomingCallId;
|
| 1003 | LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
|
| 1004 | return 0;
|
| 1005 | }
|
| 1006 |
|
| 1007 | int lynq_set_auto_answercall(const int mode)
|
| 1008 | {
|
| 1009 | global_call_auto_answer = mode;
|
| 1010 | LYINFLOG("auto answer call mode =%d",mode);
|
| 1011 | return 0;
|
| 1012 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1013 | int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
|
| 1014 | {
|
| 1015 | int lynq_call_id = 0;
|
| 1016 | if(handle==NULL)
|
| 1017 | {
|
| 1018 | return LYNQ_E_NULL_ANONALY;
|
| 1019 | }
|
| 1020 | lynq_call_id = *handle;
|
| 1021 | *call_state = lynq_call_lists[lynq_call_id].call_state;
|
| 1022 | *toa = lynq_call_lists[lynq_call_id].toa;
|
| 1023 | *direction = lynq_call_lists[lynq_call_id].direction;
|
| 1024 | memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
|
| 1025 | return 0;
|
| 1026 | }
|
| 1027 |
|
| 1028 | /*audio begin*/
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1029 | static int judge_mic(const int enable){
|
ll | f512fa3 | 2022-02-14 08:58:16 +0000 | [diff] [blame] | 1030 | switch(enable){
|
| 1031 | case 0:
|
| 1032 | return 1;
|
| 1033 | case 1:
|
| 1034 | return 1;
|
| 1035 | default:
|
| 1036 | return 0;
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1037 | }
|
| 1038 | }
|
| 1039 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1040 | int lynq_set_mute_mic(const int enable)
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1041 | {
|
| 1042 | if(!judge_mic(enable)){
|
| 1043 | return LYNQ_E_CONFLICT;
|
| 1044 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1045 | return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
|
| 1046 | }
|
| 1047 | int lynq_get_mute_mic(int *status)
|
| 1048 | {
|
| 1049 | return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1050 | }
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1051 |
|
| 1052 | /**
|
| 1053 | * @brief Check whether DTMF is valid
|
| 1054 | *
|
| 1055 | * @param callnum dtmf eg:0-9 * #
|
| 1056 | * @return int
|
| 1057 | */
|
| 1058 | static int judge_dtmf(const char callnum)
|
| 1059 | {
|
| 1060 | if(callnum == '#')
|
| 1061 | {
|
| 1062 | return 1;
|
| 1063 | }
|
| 1064 | if(callnum == '*')
|
| 1065 | {
|
| 1066 | return 1;
|
| 1067 | }
|
| 1068 | if(callnum >= '0'&& callnum <= '9')
|
| 1069 | {
|
| 1070 | return 1;
|
| 1071 | }
|
| 1072 | return 0;
|
| 1073 | }
|
| 1074 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1075 | int lynq_set_DTMF(const char callnum)
|
| 1076 | {
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1077 | if(!judge_dtmf(callnum))
|
| 1078 | {
|
| 1079 | return LYNQ_E_CONFLICT;
|
| 1080 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1081 | if(!lynq_call_state)
|
| 1082 | {
|
| 1083 | LYERRLOG("LYNQ_E_CONFLICT");
|
| 1084 | return LYNQ_E_CONFLICT;
|
| 1085 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1086 | return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1087 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1088 | static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
|
| 1089 | if(set==LYNQ_E_VOLUMN_SET_DTMF){
|
| 1090 | if(volume < 0 ||volume >36){
|
| 1091 | return 0;
|
| 1092 | }
|
| 1093 | }
|
| 1094 | else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
|
| 1095 | {
|
| 1096 | if(volume < 1 ||volume >7){
|
| 1097 | return 0;
|
| 1098 | }
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1099 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 1100 | return 1;
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1101 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1102 | int lynq_set_DTMF_volume(const int volume)
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1103 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1104 | if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1105 | return LYNQ_E_CONFLICT;
|
| 1106 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1107 | return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1108 | }
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1109 | int lynq_set_speech_volume(const int volume)//mixer_set_volume
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1110 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1111 | if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1112 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1113 | return LYNQ_E_CONFLICT;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1114 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1115 | return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1116 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1117 | int lynq_get_speech_volume(int* volumn)//mixer_get_volume
|
| 1118 | {
|
| 1119 | return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
|
| 1120 | }
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1121 | int lynq_incall_record_start(const char* file_path)
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1122 | {
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1123 | return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1124 | }
|
| 1125 | int lynq_incall_record_stop()
|
| 1126 | {
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1127 | const char* unused_file="just_ocuupy_paramter_postion";
|
| 1128 | return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1129 | }
|
| 1130 | /*audio end*/
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1131 |
|
| 1132 | #ifdef ECALL_SUPPORT
|
| 1133 | LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
|
| 1134 | {
|
| 1135 | switch(type)
|
| 1136 | {
|
| 1137 | case LYNQ_ECALL_TYPE_TEST:
|
| 1138 | return LYNQ_ECALL_TEST;
|
| 1139 | case LYNQ_ECALL_TYPE_RECONFIG:
|
| 1140 | return LYNQ_ECALL_RECONFIG;
|
| 1141 | default:
|
| 1142 | return LYNQ_ECALL_EMERGENCY;
|
| 1143 | }
|
| 1144 | }
|
| 1145 |
|
| 1146 | RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
|
| 1147 | {
|
| 1148 | switch(type)
|
| 1149 | {
|
| 1150 | case LYNQ_ECALL_TEST:
|
| 1151 | return ECALL_TEST;
|
| 1152 | case LYNQ_ECALL_RECONFIG:
|
| 1153 | return ECALL_RECONFIG;
|
| 1154 | default:
|
| 1155 | return ECALL_EMERGENCY;
|
| 1156 | }
|
| 1157 | }
|
| 1158 |
|
| 1159 | RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
|
| 1160 | {
|
| 1161 | switch(cat)
|
| 1162 | {
|
| 1163 | case LYNQ_EMER_CAT_MANUAL_ECALL:
|
| 1164 | return EMER_CAT_MANUAL_ECALL;
|
| 1165 | default:
|
| 1166 | return EMER_CAT_AUTO_ECALL;
|
| 1167 | }
|
| 1168 | }
|
| 1169 |
|
| 1170 |
|
| 1171 | int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
|
| 1172 | {
|
| 1173 | int error;
|
| 1174 |
|
| 1175 | if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
|
| 1176 | {
|
| 1177 | LYERRLOG("test_num is null or test_num_length %d s greater than %d\n ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
|
| 1178 | return -1;
|
| 1179 | }
|
| 1180 |
|
| 1181 | error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
|
| 1182 |
|
| 1183 | if(error==0)
|
| 1184 | {
|
| 1185 | snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
|
| 1186 | }
|
| 1187 |
|
| 1188 | return error;
|
| 1189 | }
|
| 1190 |
|
| 1191 |
|
| 1192 | int lynq_fast_ecall(int* handle, LYNQ_ECall_Category lynq_ecall_cat, LYNQ_ECall_Variant lynq_ecall_variant, const char *addr, int addr_length, const char *msd_data, int msd_length)
|
| 1193 | {
|
| 1194 | int error = -1;
|
| 1195 | int lynq_call_id = -1;
|
| 1196 | RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
|
q.huang | 5247303 | 2022-04-19 05:20:12 -0400 | [diff] [blame] | 1197 | RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1198 |
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1199 | lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
|
| 1200 |
|
| 1201 | LYINFLOG("e_call_addr is %s\n",e_call_addr[lynq_ecall_variant]);
|
| 1202 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1203 | error=lynq_set_common_request(RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", msd_data);
|
| 1204 |
|
| 1205 | if(error==0)
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1206 | {
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1207 | isDial = 1;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1208 | if(waitCallstateChange(30000)==ETIMEDOUT)//30000ms
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1209 | {
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1210 | isDial = 0;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1211 | error = LYNQ_E_TIME_OUT;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1212 | cleanCallList(lynq_call_id);
|
| 1213 | LYERRLOG("timeout:wait Call state fail!!!");
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1214 | return error;
|
| 1215 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1216 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1217 | *handle = lynq_call_id;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1218 | if(lynq_ecall_variant==LYNQ_ECALL_EMERGENCY){
|
| 1219 | lynq_call_lists[lynq_call_id].call_id=lynqEcallId;
|
| 1220 | }
|
| 1221 | LYINFLOG("lynq_fast_ecall handle is:%d, call id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
|
| 1222 |
|
| 1223 | }
|
| 1224 | else {
|
| 1225 | cleanCallList(lynq_call_id);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1226 | }
|
| 1227 |
|
| 1228 | return error;
|
| 1229 | }
|
| 1230 |
|
| 1231 | int lynq_set_psap(int enable)
|
| 1232 | {
|
| 1233 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
|
| 1234 | }
|
| 1235 |
|
| 1236 | int lynq_psap_pull_msd()
|
| 1237 | {
|
| 1238 | return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
|
| 1239 | }
|
| 1240 |
|
| 1241 | int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
|
| 1242 | {
|
| 1243 | LYNQ_ECall_Variant lynq_ecall_variant;
|
| 1244 | int error = -1;
|
| 1245 | int lynq_call_id = -1;
|
| 1246 |
|
| 1247 | if(handle==NULL)
|
| 1248 | {
|
| 1249 | LYERRLOG("handle is NULL, parameter error \n ");
|
| 1250 | return -1;
|
| 1251 | }
|
| 1252 |
|
| 1253 | error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
|
| 1254 |
|
| 1255 | if(error==0)
|
| 1256 | {
|
| 1257 | lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
|
| 1258 |
|
| 1259 | lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
|
| 1260 | isDial = 1;
|
| 1261 | if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
|
| 1262 | {
|
| 1263 | error = LYNQ_E_TIME_OUT;
|
| 1264 | LYERRLOG("timeout:wait Call state fail!!!");
|
| 1265 | lynq_call_lists[lynq_call_id].hasTimeout = 1;
|
| 1266 | return error;
|
| 1267 | }
|
| 1268 |
|
| 1269 | *handle = lynq_call_id;
|
| 1270 | }
|
| 1271 |
|
| 1272 | return error;
|
| 1273 | }
|
| 1274 |
|
| 1275 |
|
| 1276 | int lynq_set_msd(int* handle, const char *msd_data, int msd_length)
|
| 1277 | {
|
| 1278 | if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX))
|
| 1279 | {
|
| 1280 | LYERRLOG("handle is NULL or *handle %d is greater or equeal to %d, parameter error\n",*handle,LYNQ_CALL_MAX);
|
| 1281 | return -1;
|
| 1282 | }
|
| 1283 |
|
| 1284 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,msd_data);
|
| 1285 | }
|
| 1286 |
|
| 1287 | int lynq_set_ivs(int enable)
|
| 1288 | {
|
| 1289 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
|
| 1290 | }
|
| 1291 |
|
| 1292 | int lynq_reset_ivs()
|
| 1293 | {
|
| 1294 | return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
|
| 1295 | }
|
| 1296 |
|
| 1297 | int lynq_ivs_push_msd()
|
| 1298 | {
|
| 1299 | return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
|
| 1300 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1301 |
|
| 1302 | int wait_ecall_event()
|
| 1303 | {
|
| 1304 | int ret = 0;
|
| 1305 | pthread_mutex_lock(&s_incoming_e_call_mutex);
|
| 1306 | ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
|
| 1307 | pthread_mutex_unlock(&s_incoming_e_call_mutex);
|
| 1308 | return ret;
|
| 1309 | }
|
| 1310 |
|
| 1311 | int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)
|
| 1312 | {
|
| 1313 | wait_ecall_event();
|
| 1314 | *eCall_Indication = lynqIncomingEcallIndication;
|
| 1315 | LYINFLOG("lynq incoming e-call indication id:%d",lynqIncomingEcallIndication);
|
| 1316 | return 0;
|
| 1317 | }
|
| 1318 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1319 | #endif
|
| 1320 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1321 | #if 0
|
| 1322 | int main(int argc,char **argv)
|
| 1323 | {
|
| 1324 | int n = 0;
|
| 1325 | n = lynq_init_call(lynq_call_state_change_test,2222);
|
| 1326 | if(n<0)
|
| 1327 | {
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 1328 | LYDBGLOG("lynq init call fail!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1329 | return -1;
|
| 1330 | }
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 1331 | LYDBGLOG("lynq call init success!!!\n");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1332 | char phoneNum[LYNQ_PHONE_NUMBER_MAX];
|
| 1333 | sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
|
| 1334 | lynq_call(phoneNum);
|
| 1335 | while(1)
|
| 1336 | {
|
| 1337 | sleep(1);
|
| 1338 | }
|
| 1339 | return 0;
|
| 1340 | }
|
| 1341 | #endif
|
| 1342 | /*Warren add for T800 platform 2021/11/19 end*/
|