lh | 2582795 | 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 | 2582795 | 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 | 228a7b8 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 14 | #include <sys/time.h>
|
lh | 59e0d00 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 15 | #include <string.h>
|
q.huang | fe1b405 | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 22 | #define LYNQ_SERVICE_PORT 8088
|
rjw | 8bdc56b | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 23 | #define DSET_IP_ADDRESS "127.0.0.1"
|
lh | 2582795 | 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 | 8657e74 | 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 | 2582795 | 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 | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 71 | static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
lh | 2582795 | 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 | 1343a5b | 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 | cdf816a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 77 |
|
rjw | 8bdc56b | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 85 |
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 86 | int s_call_urc_event_complete = 1;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 87 |
|
| 88 | enum{
|
| 89 | CALL_OFF=0,
|
| 90 | CALL_ON=1
|
| 91 | }call_state;
|
ll | 375c94d | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 110 | }LYNQ_E;
|
q.huang | b0eb7b0 | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 115 |
|
| 116 | int lynq_call_state =CALL_OFF;
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 117 | int lynq_call_client_sockfd = 0;
|
| 118 | int Global_uToken_call = 0;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 119 | int global_call_count =0;
|
| 120 | int global_call_auto_answer = 0;
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 121 | bool urc_call_recive_status = 1;
|
lh | 2582795 | 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 | 18d08bf | 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 | fe1b405 | 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 | 18d08bf | 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 | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 151 |
|
ll | 1343a5b | 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 | 2582795 | 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 | 8bdc56b | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 178 | if(ret==-1)
|
| 179 | {
|
ll | c10c957 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 180 | LYERRLOG("sendto error\n");
|
lh | 2582795 | 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 | 8bdc56b | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 193 | if(len == -1)
|
| 194 | {
|
ll | c10c957 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 195 | LYERRLOG("recvfrom error\n");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 196 | return -1;
|
| 197 | }
|
lh | 2582795 | 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 | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 205 | size_t stringlen;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 206 | const char16_t *s16;
|
| 207 | s16 = p.readString16Inplace(&stringlen);
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 208 | return strndup16to8(s16, stringlen);
|
lh | 2582795 | 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 | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 224 | client.uToken = Global_uToken_call;
|
lh | 2582795 | 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 | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 229 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 230 | {
|
| 231 | LYERRLOG("send request fail");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 232 | return -1;
|
| 233 | }
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 234 | get_response(lynq_call_client_sockfd,p);
|
lh | 2582795 | 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 | cdf816a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 244 | LYINFLOG("lynq_call_state:%d",lynq_call_state);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 245 | return 0;
|
| 246 | }
|
lh | cdf816a | 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 | 2582795 | 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 | 8657e74 | 2022-04-26 00:45:44 -0700 | [diff] [blame] | 285 | lynq_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
|
lh | 2582795 | 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 | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 313 | LYINFLOG("Update Call List");
|
lh | 2582795 | 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 | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 324 | LYINFLOG("wait Call state Change");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 325 | int ret = 0;
|
| 326 | int sec = 0;
|
| 327 | int usec = 0;
|
lh | 228a7b8 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 328 | struct timeval now;
|
| 329 | struct timespec timeout;
|
| 330 | gettimeofday(&now,NULL);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 331 | sec = mtime/1000;
|
| 332 | usec = mtime%1000;
|
lh | 228a7b8 | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 335 | pthread_mutex_lock(&call_state_change_mutex);
|
lh | 228a7b8 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 336 | ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
|
lh | 2582795 | 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 | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 342 | LYINFLOG("wait incming call");
|
lh | 2582795 | 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 | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 351 | LYINFLOG("check has call");
|
lh | 2582795 | 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 | be92dd1 | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 373 | void sendSignalToWaitCallStateChange()
|
| 374 | {
|
lh | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 375 | LYINFLOG("send Signal To Wait Call State Change");
|
lh | 2582795 | 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 | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 382 | LYINFLOG("send incoming call signal");
|
lh | 2582795 | 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 | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 401 | {
|
| 402 | int ret=0;
|
lh | be92dd1 | 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 | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 405 | lynq_call_list_t call_list[LYNQ_CALL_MAX];
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 406 | int update=0;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 407 | while(call_list_loop)
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 408 | {
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 409 | update=0;
|
ll | 375c94d | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 412 | LYDBGLOG("triggerGetCallList event!!!\n");
|
ll | 375c94d | 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 | 2210140 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 417 | LYDBGLOG("get current call list failure!!!\n");
|
| 418 | continue;
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 419 | }
|
lh | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 420 | LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 421 | for(int i = 0;i < LYNQ_CALL_MAX;i++)
|
| 422 | {
|
lh | be92dd1 | 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 | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 441 | if(call_list[i].direction == 1)//MT call
|
| 442 | {
|
lh | 4256e1b | 2022-05-13 03:02:19 -0700 | [diff] [blame^] | 443 | /*MT CALL state code
|
| 444 | **LYNQ_CALL_INCOMING = 4,
|
| 445 | **LYNQ_CALL_WAITING = 5,
|
| 446 | */
|
| 447 | if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 448 | {
|
ll | 45d3ea9 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 449 | /*you call me, and i call you,One party failed to dial*/
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 450 | if(!checkHasCall(call_list[i].addr))
|
| 451 | {
|
| 452 | lynqIncomingCallId = getUnusedElement();
|
| 453 | 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);
|
| 454 | sendSignalIncomingCall();
|
| 455 | }
|
lh | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 456 | else
|
| 457 | {
|
| 458 | int temp_call_id = find_call_id_with_addr(call_list[i].addr);
|
| 459 | /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
|
| 460 | **an incoming call until the status changes.
|
| 461 | **fix bug API-54
|
| 462 | */
|
| 463 | if((temp_call_id > 0) && (lynq_call_lists[temp_call_id].call_state == call_list[i].call_state))
|
| 464 | {
|
| 465 | sendSignalIncomingCall();
|
| 466 | }
|
| 467 | }
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 468 | }
|
ll | 45d3ea9 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 469 | /*if state changed*/
|
| 470 | else
|
| 471 | {
|
| 472 | /*update call state*/
|
| 473 | for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
|
| 474 | {
|
| 475 | if(strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)
|
| 476 | {
|
| 477 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
ll | 4461e95 | 2022-04-07 09:09:55 +0000 | [diff] [blame] | 478 | break;
|
ll | 45d3ea9 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 479 | }
|
| 480 | }
|
| 481 | }
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 482 | }
|
| 483 | else
|
| 484 | {
|
| 485 | if(call_list[i].call_id==0)
|
| 486 | {
|
| 487 | break;
|
| 488 | }
|
| 489 | for(int n = 0 ; n < LYNQ_CALL_MAX; n++)
|
| 490 | {
|
lh | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 491 | if((lynq_call_lists[n].hasTimeout == 1) && (strcmp(lynq_call_lists[n].addr,call_list[i].addr) == 0))
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 492 | {
|
lh | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 493 | cleanCallList(n);//if this call time out,need clean lynq call list.
|
| 494 | /*hangup call with call id*/
|
| 495 | lynq_call_hungup(&call_list[i].call_id);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 496 | lynq_call_lists[n].hasTimeout==0;
|
| 497 | continue;
|
| 498 | }
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 499 | LYDBGLOG("lynq_call_lists n is %d, used is %d, addr is %s addr2 %s\n",
|
| 500 | n,lynq_call_lists[n].used,call_list[i].addr,lynq_call_lists[n].addr);
|
| 501 | if(lynq_call_lists[n].used && (strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0))
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 502 | {
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 503 | LYINFLOG("updated\n");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 504 | 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 | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 505 | update=1;
|
| 506 | break;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 507 | }
|
| 508 | }
|
| 509 | 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,
|
| 510 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 511 | }
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 512 | }
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 513 | s_call_urc_event_complete = 1;
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 514 | if((isDial==1) && (update==1))
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 515 | {
|
| 516 | sendSignalToWaitCallStateChange();
|
| 517 | isDial = 0;
|
| 518 | }
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 519 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
| 520 | }
|
| 521 | return NULL;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 522 | }
|
| 523 |
|
| 524 | void lynqRespWatingEvent()
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 525 | {
|
| 526 | if(s_call_urc_event_complete==1)
|
| 527 | {
|
| 528 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 529 | pthread_cond_signal(&s_urc_call_state_change_cond);
|
| 530 | s_call_urc_event_complete = 0;
|
| 531 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 532 | }
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 533 | return;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 534 | }
|
| 535 |
|
| 536 | /*Warren add for T800 platform 2021/11/19 start*/
|
| 537 | int lynq_socket_client_start()
|
rjw | 8bdc56b | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 538 | {
|
| 539 | #if 0
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 540 | struct sockaddr_in lynq_socket_server_addr;
|
| 541 | /* init lynq_socket_server_addr */
|
| 542 | bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
|
| 543 | lynq_socket_server_addr.sin_family = AF_INET;
|
| 544 | lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 545 | lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
rjw | 8bdc56b | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 546 |
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 547 | /*
|
| 548 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
|
| 549 | {
|
ll | 2210140 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 550 | LYDBGLOG("[%s] is not a valid IPaddress\n", argv[1]);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 551 | exit(1);
|
| 552 | }
|
| 553 | */
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 554 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 555 | if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 556 | {
|
ll | c10c957 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 557 | LYERRLOG("connect error\n");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 558 | return -1;
|
| 559 | }
|
rjw | 8bdc56b | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 560 | #endif
|
| 561 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 562 | if (-1 == lynq_call_client_sockfd)
|
| 563 | {
|
| 564 | return lynq_call_client_sockfd;
|
| 565 | }
|
| 566 | /* 设置address */
|
| 567 | memset(&addr_serv, 0, sizeof(addr_serv));
|
| 568 | addr_serv.sin_family = AF_INET;
|
| 569 | addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
|
| 570 | addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 571 | len_addr_serv = sizeof(addr_serv);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 572 | return 0;
|
| 573 | }
|
| 574 | int lynq_update_call_list_loop()
|
| 575 | {
|
| 576 | int ret = 0;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 577 | pthread_attr_t attr;
|
| 578 | pthread_attr_init(&attr);
|
| 579 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | cdf816a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 580 | ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 581 | if(ret < 0)
|
| 582 | {
|
| 583 | LYERRLOG("lynq_update_call_list_loop fail!!!");
|
| 584 | return -1;
|
| 585 | }
|
| 586 | LYDBGLOG("lynq_update_call_list_loop success!!!\n");
|
| 587 | return 0;
|
| 588 |
|
| 589 | }
|
| 590 | void *thread_urc_recv(void *parg)
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 591 | {
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 592 | int socket_fd = (int64_t)parg;
|
| 593 | int len=0;
|
| 594 | socklen_t addr_len=0;
|
| 595 | uint8_t *dataLength = NULL;
|
| 596 | char urc_data[LYNQ_REC_BUF];
|
| 597 | int slot_id = -1;
|
| 598 | int resp_type = -1;
|
| 599 | int urcid = -1;
|
| 600 | Parcel *p = NULL;
|
| 601 | struct sockaddr_in dest_addr;
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 602 | #ifdef ECALL_SUPPORT
|
| 603 | int ecall_ind;
|
| 604 | #endif
|
| 605 |
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 606 | LYINFLOG("thread_urc_recv in running....\n");
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 607 | while(urc_call_recive_status)
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 608 | {
|
| 609 | bzero(urc_data,LYNQ_REC_BUF);
|
| 610 | //get data msg
|
| 611 | len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
|
| 612 | if(len <= 0)
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 613 | {
|
ll | c10c957 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 614 | LYERRLOG("thread_urc_recv step2 fail\n");
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 615 | break;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 616 | }
|
| 617 | LYDBGLOG("=====>urc data len<=====:%d\n",len);
|
| 618 | p = new Parcel();
|
| 619 | if(p==NULL)
|
| 620 | {
|
lh | 59e0d00 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 621 | LYERRLOG("new parcel failure!!!");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 622 | break;
|
| 623 | }
|
| 624 | p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
|
| 625 | p->setDataPosition(0);
|
| 626 | if(p->dataAvail() > 0)
|
| 627 | {
|
| 628 | p->readInt32(&resp_type);
|
| 629 | p->readInt32(&urcid);
|
| 630 | p->readInt32(&slot_id);
|
| 631 | //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 632 | switch (urcid)
|
| 633 | {
|
| 634 | case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
|
| 635 | {
|
| 636 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 637 | lynqRespWatingEvent();
|
| 638 | break;
|
| 639 | }
|
| 640 | case 1018://RIL_UNSOL_CALL_RING
|
| 641 | {
|
| 642 | if(global_call_auto_answer==1)
|
| 643 | {
|
| 644 | lynq_call_answer();
|
| 645 | }
|
| 646 | break;
|
| 647 | }
|
| 648 | case 1029://RIL_UNSOL_RINGBACK_TONE
|
| 649 | case 3049://RIL_UNSOL_CALL_INFO_INDICATION
|
| 650 | {
|
| 651 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d\n",resp_type,urcid,slot_id);
|
| 652 | break;
|
| 653 | }
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 654 | #ifdef ECALL_SUPPORT
|
| 655 | case RIL_UNSOL_ECALL_INDICATIONS:
|
| 656 | {
|
| 657 | p->readInt32(&ecall_ind);
|
| 658 | lynqIncomingEcallIndication=ecall_ind;
|
| 659 | if(LYNQ_ECALL_ACTIVE==lynqIncomingEcallIndication)
|
| 660 | {
|
| 661 | if(isDial==1)
|
| 662 | {
|
| 663 | p->readInt32(&lynqEcallId);
|
| 664 | sendSignalToWaitCallStateChange();
|
| 665 | usleep(300*1000);
|
| 666 | }
|
| 667 | }
|
| 668 | sendSignalIncomingECallEvent();
|
| 669 | break;
|
| 670 | }
|
| 671 | #endif
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 672 | default:
|
| 673 | break;
|
| 674 | }
|
| 675 | }
|
| 676 | delete p;
|
| 677 | p = NULL;
|
| 678 | }
|
| 679 | close(socket_fd);
|
| 680 | }
|
| 681 | int lynq_socket_urc_start()
|
| 682 | {
|
| 683 | int socket_fd=0;
|
| 684 | int rt=0;
|
| 685 | int len=0;
|
| 686 | int on=1;
|
| 687 | struct sockaddr_in urc_local_addr;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 688 | pthread_attr_t attr;
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 689 | socket_fd = socket(AF_INET,SOCK_DGRAM,0);
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 690 | if(socket_fd < 0)
|
| 691 | {
|
ll | c10c957 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 692 | LYERRLOG("creaet socket for udp fail\n");
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 693 | return -1;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 694 | }
|
| 695 | urc_local_addr.sin_family = AF_INET;
|
| 696 | urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
|
| 697 | urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
| 698 | /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 699 | rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
|
| 700 | if(rt<0)
|
| 701 | {
|
ll | c10c957 | 2022-03-01 09:18:53 +0000 | [diff] [blame] | 702 | LYERRLOG("SO_REUSEADDR fail\n");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 703 | return -1;
|
| 704 | }
|
| 705 | rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 706 | if (rt == -1)
|
| 707 | {
|
lh | 59e0d00 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 708 | LYERRLOG("bind failed");
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 709 | return -1;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 710 | }
|
| 711 | pthread_attr_init(&attr);
|
| 712 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | cdf816a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 713 | rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 714 | if(rt < 0)
|
| 715 | {
|
lh | 59e0d00 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 716 | LYERRLOG("urc loop failure!!!\n");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 717 | return -1;
|
| 718 | }
|
lh | 59e0d00 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 719 | LYDBGLOG("urc loop success!!!\n");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 720 | return 0;
|
| 721 | }
|
| 722 | int getSelfElement(char addr[])
|
| 723 | {
|
| 724 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 725 | {
|
| 726 | if(lynq_call_lists[i].used==1)
|
| 727 | {
|
| 728 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 729 | {
|
| 730 | return i;
|
| 731 | }
|
| 732 |
|
| 733 | }
|
| 734 | }
|
| 735 | return -1;
|
| 736 | }
|
| 737 |
|
| 738 | void lynq_call_state_change_test(int soc_id)
|
| 739 | {
|
ll | 2210140 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 740 | LYDBGLOG("call state change,sim:%d\n",soc_id);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 741 | }
|
| 742 | int lynq_init_call(int uToken)
|
ll | 1343a5b | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 743 | {
|
| 744 | if(g_lynq_call_init_flag == 1){
|
| 745 | LYDBGLOG("lynq init call failed!!!");
|
| 746 | return -1;
|
| 747 | }
|
| 748 | g_lynq_call_init_flag = 1;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 749 | int result = 0;
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 750 | Global_uToken_call = uToken;
|
lh | 59e0d00 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 751 | urc_call_recive_status = 1;
|
rjw | 8bdc56b | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 752 | client_size = sizeof(client_t);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 753 | LYLOGSET(LOG_INFO);
|
| 754 | LYLOGEINIT(USER_LOG_TAG);
|
| 755 | result = lynq_socket_client_start();
|
| 756 | if(result!=0)
|
| 757 | {
|
| 758 | return -1;
|
| 759 | }
|
| 760 | result = lynq_socket_urc_start();
|
| 761 | if(result!=0)
|
| 762 | {
|
| 763 | return -1;
|
| 764 | }
|
| 765 | result = lynq_update_call_list_loop();
|
| 766 | if(result!=0)
|
| 767 | {
|
| 768 | return -1;
|
| 769 | }
|
| 770 | memset(lynq_call_lists,0,sizeof(lynq_call_lists));
|
| 771 | LYDBGLOG("lynq init call success!!!");
|
| 772 | return 0;
|
| 773 | }
|
| 774 | int lynq_deinit_call()
|
| 775 | {
|
ll | 1343a5b | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 776 | if(g_lynq_call_init_flag == 0)
|
lh | cdf816a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 777 | {
|
ll | 1343a5b | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 778 | LYDBGLOG("lynq_deinit_call failed!!!");
|
| 779 | return -1;
|
lh | cdf816a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 780 | }
|
ll | 1343a5b | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 781 | else
|
| 782 | {
|
| 783 | g_lynq_call_init_flag = 0;
|
| 784 | int ret = -1;
|
| 785 | if(lynq_call_client_sockfd>0)
|
| 786 | {
|
| 787 | close(lynq_call_client_sockfd);
|
| 788 | }
|
| 789 | urc_call_recive_status = 0;
|
| 790 | call_list_loop = 0;
|
| 791 | if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
|
| 792 | {
|
| 793 | return -1;
|
| 794 | }
|
| 795 | ret = pthread_cancel(lynq_call_urc_tid);
|
| 796 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 797 | ret = pthread_cancel(lynq_call_list_loop_tid);
|
| 798 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 799 | ret = pthread_join(lynq_call_urc_tid,NULL);
|
| 800 | LYDBGLOG("pthread join ret = %d",ret);
|
| 801 | ret = pthread_join(lynq_call_list_loop_tid,NULL);
|
| 802 | LYDBGLOG("pthread join ret = %d",ret);
|
| 803 | return 0;
|
| 804 | }
|
rita | 47debb9 | 2022-04-07 06:08:13 -0400 | [diff] [blame] | 805 | }
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 806 |
|
| 807 | int lynq_set_common_request(int request_id, int argc, const char* format,...)
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 808 | {
|
| 809 | Parcel p;
|
| 810 | lynq_client_t client;
|
| 811 | int resp_type = -1;
|
| 812 | int request = -1;
|
| 813 | int slot_id = -1;
|
| 814 | int error = -1;
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 815 |
|
| 816 | client.uToken = Global_uToken_call;
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 817 | client.request = request_id;
|
| 818 | client.paramLen = argc;
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 819 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 820 | if(argc!=0)
|
| 821 | {
|
| 822 | va_list args;
|
| 823 | va_start(args, format);
|
| 824 | vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
|
| 825 | va_end(args);
|
| 826 | }
|
| 827 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 828 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
| 829 | {
|
| 830 | LYERRLOG("send request fail");
|
| 831 | return -1;
|
| 832 | }
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 833 | if(get_response(lynq_call_client_sockfd,p)==0)
|
| 834 | {
|
| 835 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 836 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 837 | }
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 838 | return error;
|
| 839 | }
|
| 840 |
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 841 | int lynq_get_common_request(int request_id, int* status)
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 842 | {
|
| 843 | Parcel p;
|
| 844 | lynq_client_t client;
|
| 845 | int resp_type = -1;
|
| 846 | int request = -1;
|
| 847 | int slot_id = -1;
|
| 848 | int error = -1;
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 849 | if(status==NULL)
|
| 850 | {
|
| 851 | LYERRLOG("status is null");
|
| 852 | return -1;
|
| 853 | }
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 854 | client.uToken = Global_uToken_call;
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 855 | client.request = request_id;
|
| 856 | client.paramLen = 0;
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 857 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 858 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 859 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
| 860 | {
|
| 861 | LYERRLOG("send request fail");
|
| 862 | return -1;
|
| 863 | }
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 864 | if(get_response(lynq_call_client_sockfd,p)==0)
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 865 | {
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 866 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 867 | p.readInt32(status);
|
| 868 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 869 | }
|
rita | 9b436d8 | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 870 | return error;
|
| 871 | }
|
| 872 |
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 873 | int lynq_call(int* handle,char addr[])
|
| 874 | {
|
| 875 | Parcel p;
|
| 876 | lynq_client_t client;
|
| 877 | int resp_type = -1;
|
| 878 | int request = -1;
|
| 879 | int slot_id = -1;
|
| 880 | int error = -1;
|
| 881 | int lynq_call_id = -1;
|
| 882 | if(addr==NULL)
|
| 883 | {
|
| 884 | LYERRLOG("Phone num is null!!!");
|
| 885 | return -1;
|
| 886 | }
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 887 | client.uToken = Global_uToken_call;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 888 | client.request = 10;//RIL_REQUEST_DIAL
|
| 889 | client.paramLen = 2;
|
| 890 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 891 | memcpy(client.param,addr,strlen(addr)+1);
|
| 892 | strcat(client.param," 0");
|
| 893 | LYERRLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 894 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 895 | {
|
| 896 | LYERRLOG("send request fail");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 897 | return -1;
|
| 898 | }
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 899 | get_response(lynq_call_client_sockfd,p);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 900 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 901 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 902 | lynq_call_id = updateAddr(addr);
|
| 903 | if(error==0)
|
| 904 | {
|
| 905 | isDial = 1;
|
ll | 45d3ea9 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 906 | if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 907 | {
|
lh | be92dd1 | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 908 | //if timeout,this call need destroy.
|
| 909 | isDial = 0;
|
| 910 |
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 911 | error = LYNQ_E_TIME_OUT;
|
| 912 | LYERRLOG("timeout:wait Call state fail!!!");
|
| 913 | lynq_call_lists[lynq_call_id].hasTimeout = 1;
|
| 914 | return error;
|
| 915 | }
|
| 916 | *handle = lynq_call_id;
|
| 917 | }
|
| 918 | return error;
|
| 919 | }
|
| 920 | int lynq_call_answer()
|
| 921 | {
|
| 922 | Parcel p;
|
| 923 | lynq_client_t client;
|
| 924 | int resp_type = -1;
|
| 925 | int request = -1;
|
| 926 | int slot_id = -1;
|
| 927 | int error = -1;
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 928 | client.uToken = Global_uToken_call;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 929 | client.request = 40;//RIL_REQUEST_DIAL
|
| 930 | client.paramLen = 0;
|
| 931 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 932 | LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 933 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 934 | {
|
| 935 | LYERRLOG("send request fail");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 936 | return -1;
|
| 937 | }
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 938 | get_response(lynq_call_client_sockfd,p);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 939 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 940 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 941 | return error;
|
| 942 | }
|
| 943 | int lynq_call_hungup(int* handle)
|
| 944 | {
|
| 945 | Parcel p;
|
| 946 | lynq_client_t client;
|
| 947 | int resp_type = -1;
|
| 948 | int request = -1;
|
| 949 | int slot_id = -1;
|
| 950 | int error = -1;
|
| 951 | int call_id = 0;
|
| 952 | int lynq_call_id = 0;
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 953 | if(handle==NULL||!((*handle>=0)&&(*handle<10)))
|
| 954 | {
|
| 955 | LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
|
| 956 | return LYNQ_E_CONFLICT;
|
| 957 | }
|
| 958 | client.uToken = Global_uToken_call;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 959 | client.request = 12;//RIL_REQUEST_HUNGUP
|
| 960 | client.paramLen = 1;
|
| 961 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 962 | lynq_call_id = *handle;
|
| 963 | call_id = lynq_call_lists[lynq_call_id].call_id;
|
| 964 | sprintf(client.param,"%d",call_id);
|
| 965 | LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 966 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 967 | {
|
| 968 | LYERRLOG("send request fail");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 969 | return -1;
|
| 970 | }
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 971 | get_response(lynq_call_client_sockfd,p);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 972 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 973 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 974 | if(error==0)
|
| 975 | {
|
| 976 | cleanCallList(lynq_call_id);
|
| 977 | }
|
| 978 | return error;
|
| 979 | }
|
| 980 | int lynq_call_hungup_all()
|
| 981 | {
|
| 982 | Parcel p;
|
| 983 | lynq_client_t client;
|
| 984 | int resp_type = -1;
|
| 985 | int request = -1;
|
| 986 | int slot_id = -1;
|
| 987 | int error = -1;
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 988 | client.uToken = Global_uToken_call;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 989 | client.request = 17;//RIL_REQUEST_UDUB
|
| 990 | client.paramLen = 0;
|
| 991 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 992 | LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s\n",client.uToken,client.request,client.paramLen,client.param);
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 993 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 994 | {
|
| 995 | LYERRLOG("send request fail");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 996 | return -1;
|
| 997 | }
|
lh | a35d4ee | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 998 | get_response(lynq_call_client_sockfd,p);
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 999 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 1000 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 1001 | return error;
|
| 1002 | }
|
| 1003 | int lynq_wait_incoming_call(int *handle)
|
| 1004 | {
|
| 1005 | waitIncomingCall();
|
| 1006 | *handle = lynqIncomingCallId;
|
| 1007 | LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
|
| 1008 | return 0;
|
| 1009 | }
|
| 1010 |
|
| 1011 | int lynq_set_auto_answercall(const int mode)
|
| 1012 | {
|
| 1013 | global_call_auto_answer = mode;
|
| 1014 | LYINFLOG("auto answer call mode =%d",mode);
|
| 1015 | return 0;
|
| 1016 | }
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1017 | int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
|
| 1018 | {
|
| 1019 | int lynq_call_id = 0;
|
| 1020 | if(handle==NULL)
|
| 1021 | {
|
| 1022 | return LYNQ_E_NULL_ANONALY;
|
| 1023 | }
|
| 1024 | lynq_call_id = *handle;
|
| 1025 | *call_state = lynq_call_lists[lynq_call_id].call_state;
|
| 1026 | *toa = lynq_call_lists[lynq_call_id].toa;
|
| 1027 | *direction = lynq_call_lists[lynq_call_id].direction;
|
| 1028 | memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
|
| 1029 | return 0;
|
| 1030 | }
|
| 1031 |
|
| 1032 | /*audio begin*/
|
ll | 7e055f2 | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1033 | static int judge_mic(const int enable){
|
ll | c603006 | 2022-02-14 08:58:16 +0000 | [diff] [blame] | 1034 | switch(enable){
|
| 1035 | case 0:
|
| 1036 | return 1;
|
| 1037 | case 1:
|
| 1038 | return 1;
|
| 1039 | default:
|
| 1040 | return 0;
|
ll | 7e055f2 | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1041 | }
|
| 1042 | }
|
| 1043 |
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1044 | int lynq_set_mute_mic(const int enable)
|
ll | 7e055f2 | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1045 | {
|
| 1046 | if(!judge_mic(enable)){
|
| 1047 | return LYNQ_E_CONFLICT;
|
| 1048 | }
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1049 | return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
|
| 1050 | }
|
| 1051 | int lynq_get_mute_mic(int *status)
|
| 1052 | {
|
| 1053 | return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1054 | }
|
ll | 45d3ea9 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1055 |
|
| 1056 | /**
|
| 1057 | * @brief Check whether DTMF is valid
|
| 1058 | *
|
| 1059 | * @param callnum dtmf eg:0-9 * #
|
| 1060 | * @return int
|
| 1061 | */
|
| 1062 | static int judge_dtmf(const char callnum)
|
| 1063 | {
|
| 1064 | if(callnum == '#')
|
| 1065 | {
|
| 1066 | return 1;
|
| 1067 | }
|
| 1068 | if(callnum == '*')
|
| 1069 | {
|
| 1070 | return 1;
|
| 1071 | }
|
| 1072 | if(callnum >= '0'&& callnum <= '9')
|
| 1073 | {
|
| 1074 | return 1;
|
| 1075 | }
|
| 1076 | return 0;
|
| 1077 | }
|
| 1078 |
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1079 | int lynq_set_DTMF(const char callnum)
|
| 1080 | {
|
ll | 45d3ea9 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1081 | if(!judge_dtmf(callnum))
|
| 1082 | {
|
| 1083 | return LYNQ_E_CONFLICT;
|
| 1084 | }
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1085 | if(!lynq_call_state)
|
| 1086 | {
|
| 1087 | LYERRLOG("LYNQ_E_CONFLICT");
|
| 1088 | return LYNQ_E_CONFLICT;
|
| 1089 | }
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1090 | return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1091 | }
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1092 | static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
|
| 1093 | if(set==LYNQ_E_VOLUMN_SET_DTMF){
|
| 1094 | if(volume < 0 ||volume >36){
|
| 1095 | return 0;
|
| 1096 | }
|
| 1097 | }
|
| 1098 | else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
|
| 1099 | {
|
| 1100 | if(volume < 1 ||volume >7){
|
| 1101 | return 0;
|
| 1102 | }
|
ll | 7e055f2 | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1103 | }
|
ll | 375c94d | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 1104 | return 1;
|
ll | 7e055f2 | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1105 | }
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1106 | int lynq_set_DTMF_volume(const int volume)
|
ll | 7e055f2 | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1107 | {
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1108 | if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
|
ll | 7e055f2 | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1109 | return LYNQ_E_CONFLICT;
|
| 1110 | }
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1111 | return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1112 | }
|
q.huang | 9ee6d5b | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1113 | int lynq_set_speech_volume(const int volume)//mixer_set_volume
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1114 | {
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1115 | if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1116 | {
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1117 | return LYNQ_E_CONFLICT;
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1118 | }
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1119 | return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1120 | }
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1121 | int lynq_get_speech_volume(int* volumn)//mixer_get_volume
|
| 1122 | {
|
| 1123 | return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
|
| 1124 | }
|
q.huang | 9ee6d5b | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1125 | int lynq_incall_record_start(const char* file_path)
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1126 | {
|
q.huang | 9ee6d5b | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1127 | return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1128 | }
|
| 1129 | int lynq_incall_record_stop()
|
| 1130 | {
|
q.huang | 9ee6d5b | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1131 | const char* unused_file="just_ocuupy_paramter_postion";
|
| 1132 | return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
|
q.huang | b0eb7b0 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1133 | }
|
| 1134 | /*audio end*/
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1135 |
|
| 1136 | #ifdef ECALL_SUPPORT
|
| 1137 | LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
|
| 1138 | {
|
| 1139 | switch(type)
|
| 1140 | {
|
| 1141 | case LYNQ_ECALL_TYPE_TEST:
|
| 1142 | return LYNQ_ECALL_TEST;
|
| 1143 | case LYNQ_ECALL_TYPE_RECONFIG:
|
| 1144 | return LYNQ_ECALL_RECONFIG;
|
| 1145 | default:
|
| 1146 | return LYNQ_ECALL_EMERGENCY;
|
| 1147 | }
|
| 1148 | }
|
| 1149 |
|
| 1150 | RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
|
| 1151 | {
|
| 1152 | switch(type)
|
| 1153 | {
|
| 1154 | case LYNQ_ECALL_TEST:
|
| 1155 | return ECALL_TEST;
|
| 1156 | case LYNQ_ECALL_RECONFIG:
|
| 1157 | return ECALL_RECONFIG;
|
| 1158 | default:
|
| 1159 | return ECALL_EMERGENCY;
|
| 1160 | }
|
| 1161 | }
|
| 1162 |
|
| 1163 | RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
|
| 1164 | {
|
| 1165 | switch(cat)
|
| 1166 | {
|
| 1167 | case LYNQ_EMER_CAT_MANUAL_ECALL:
|
| 1168 | return EMER_CAT_MANUAL_ECALL;
|
| 1169 | default:
|
| 1170 | return EMER_CAT_AUTO_ECALL;
|
| 1171 | }
|
| 1172 | }
|
| 1173 |
|
| 1174 |
|
| 1175 | int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
|
| 1176 | {
|
| 1177 | int error;
|
| 1178 |
|
| 1179 | if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
|
| 1180 | {
|
| 1181 | LYERRLOG("test_num is null or test_num_length %d s greater than %d\n ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
|
| 1182 | return -1;
|
| 1183 | }
|
| 1184 |
|
| 1185 | error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
|
| 1186 |
|
| 1187 | if(error==0)
|
| 1188 | {
|
| 1189 | snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
|
| 1190 | }
|
| 1191 |
|
| 1192 | return error;
|
| 1193 | }
|
| 1194 |
|
| 1195 |
|
q.huang | 892722f | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1196 | 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 unsigned char *msd_data,int msd_length)
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1197 | {
|
| 1198 | int error = -1;
|
| 1199 | int lynq_call_id = -1;
|
| 1200 | RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
|
q.huang | 9a9b876 | 2022-04-19 05:20:12 -0400 | [diff] [blame] | 1201 | RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
|
q.huang | 6a11976 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1202 | char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
|
| 1203 | unsigned int i;
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1204 |
|
q.huang | 892722f | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1205 | if(msd_length > MSD_MAX_LENGTH)
|
| 1206 | {
|
| 1207 | LYERRLOG("msd_length %d is greater than %d, parameter error\n",msd_length,MSD_MAX_LENGTH);
|
| 1208 | return -1;
|
| 1209 | }
|
q.huang | 892722f | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1210 |
|
q.huang | 6a11976 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1211 | for(i =0; i<msd_length;i++)
|
q.huang | 892722f | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1212 | {
|
q.huang | 6a11976 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1213 | sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
|
q.huang | 892722f | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1214 | }
|
| 1215 |
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1216 | lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
|
| 1217 |
|
| 1218 | LYINFLOG("e_call_addr is %s\n",e_call_addr[lynq_ecall_variant]);
|
| 1219 |
|
q.huang | 892722f | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1220 | error=lynq_set_common_request(RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", lynq_msd_data);
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1221 |
|
| 1222 | if(error==0)
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1223 | {
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1224 | isDial = 1;
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1225 | if(waitCallstateChange(30000)==ETIMEDOUT)//30000ms
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1226 | {
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1227 | isDial = 0;
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1228 | error = LYNQ_E_TIME_OUT;
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1229 | cleanCallList(lynq_call_id);
|
| 1230 | LYERRLOG("timeout:wait Call state fail!!!");
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1231 | return error;
|
| 1232 | }
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1233 |
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1234 | *handle = lynq_call_id;
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1235 | if(lynq_ecall_variant==LYNQ_ECALL_EMERGENCY){
|
| 1236 | lynq_call_lists[lynq_call_id].call_id=lynqEcallId;
|
| 1237 | }
|
| 1238 | LYINFLOG("lynq_fast_ecall handle is:%d, call id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
|
| 1239 |
|
| 1240 | }
|
| 1241 | else {
|
| 1242 | cleanCallList(lynq_call_id);
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1243 | }
|
| 1244 |
|
| 1245 | return error;
|
| 1246 | }
|
| 1247 |
|
| 1248 | int lynq_set_psap(int enable)
|
| 1249 | {
|
| 1250 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
|
| 1251 | }
|
| 1252 |
|
| 1253 | int lynq_psap_pull_msd()
|
| 1254 | {
|
| 1255 | return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
|
| 1256 | }
|
| 1257 |
|
| 1258 | int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
|
| 1259 | {
|
| 1260 | LYNQ_ECall_Variant lynq_ecall_variant;
|
| 1261 | int error = -1;
|
| 1262 | int lynq_call_id = -1;
|
| 1263 |
|
| 1264 | if(handle==NULL)
|
| 1265 | {
|
| 1266 | LYERRLOG("handle is NULL, parameter error \n ");
|
| 1267 | return -1;
|
| 1268 | }
|
| 1269 |
|
| 1270 | error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
|
| 1271 |
|
| 1272 | if(error==0)
|
| 1273 | {
|
| 1274 | lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
|
| 1275 |
|
| 1276 | lynq_call_id = updateAddr(e_call_addr[lynq_ecall_variant]);
|
| 1277 | isDial = 1;
|
| 1278 | if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
|
| 1279 | {
|
| 1280 | error = LYNQ_E_TIME_OUT;
|
| 1281 | LYERRLOG("timeout:wait Call state fail!!!");
|
| 1282 | lynq_call_lists[lynq_call_id].hasTimeout = 1;
|
| 1283 | return error;
|
| 1284 | }
|
| 1285 |
|
| 1286 | *handle = lynq_call_id;
|
| 1287 | }
|
| 1288 |
|
| 1289 | return error;
|
| 1290 | }
|
| 1291 |
|
| 1292 |
|
q.huang | bd6a306 | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1293 | int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length)
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1294 | {
|
q.huang | 6a11976 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1295 | char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
|
| 1296 | unsigned int i;
|
| 1297 |
|
q.huang | bd6a306 | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1298 | if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX) || msd_length > MSD_MAX_LENGTH)
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1299 | {
|
q.huang | bd6a306 | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1300 | LYERRLOG("handle is NULL or *handle %d is greater or equeal to %d or msd_length %d is greater than %d, parameter error\n",*handle,LYNQ_CALL_MAX,msd_length,MSD_MAX_LENGTH);
|
| 1301 | return -1;
|
| 1302 | }
|
q.huang | bd6a306 | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1303 |
|
q.huang | 6a11976 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1304 | for(i=0; i<msd_length;i++)
|
q.huang | bd6a306 | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1305 | {
|
q.huang | 6a11976 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1306 | sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1307 | }
|
| 1308 |
|
q.huang | bd6a306 | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1309 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,lynq_msd_data);
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1310 | }
|
| 1311 |
|
| 1312 | int lynq_set_ivs(int enable)
|
| 1313 | {
|
| 1314 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
|
| 1315 | }
|
| 1316 |
|
| 1317 | int lynq_reset_ivs()
|
| 1318 | {
|
| 1319 | return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
|
| 1320 | }
|
| 1321 |
|
| 1322 | int lynq_ivs_push_msd()
|
| 1323 | {
|
| 1324 | return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
|
| 1325 | }
|
q.huang | 18d08bf | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1326 |
|
| 1327 | int wait_ecall_event()
|
| 1328 | {
|
| 1329 | int ret = 0;
|
| 1330 | pthread_mutex_lock(&s_incoming_e_call_mutex);
|
| 1331 | ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
|
| 1332 | pthread_mutex_unlock(&s_incoming_e_call_mutex);
|
| 1333 | return ret;
|
| 1334 | }
|
| 1335 |
|
| 1336 | int lynq_wait_ecall_indication(LYNQ_ECall_Indication *eCall_Indication)
|
| 1337 | {
|
| 1338 | wait_ecall_event();
|
| 1339 | *eCall_Indication = lynqIncomingEcallIndication;
|
| 1340 | LYINFLOG("lynq incoming e-call indication id:%d",lynqIncomingEcallIndication);
|
| 1341 | return 0;
|
| 1342 | }
|
| 1343 |
|
q.huang | fe1b405 | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1344 | #endif
|
| 1345 |
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1346 | #if 0
|
| 1347 | int main(int argc,char **argv)
|
| 1348 | {
|
| 1349 | int n = 0;
|
| 1350 | n = lynq_init_call(lynq_call_state_change_test,2222);
|
| 1351 | if(n<0)
|
| 1352 | {
|
ll | 2210140 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 1353 | LYDBGLOG("lynq init call fail!!!\n");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1354 | return -1;
|
| 1355 | }
|
ll | 2210140 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 1356 | LYDBGLOG("lynq call init success!!!\n");
|
lh | 2582795 | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1357 | char phoneNum[LYNQ_PHONE_NUMBER_MAX];
|
| 1358 | sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
|
| 1359 | lynq_call(phoneNum);
|
| 1360 | while(1)
|
| 1361 | {
|
| 1362 | sleep(1);
|
| 1363 | }
|
| 1364 | return 0;
|
| 1365 | }
|
| 1366 | #endif
|
| 1367 | /*Warren add for T800 platform 2021/11/19 end*/
|