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
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 28 | #define INVALID_ID (-1)
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 29 | #define RTP_FROM_CMD "gst-launch-1.0 -v udpsrc port=%d caps=\'application/x-rtp, media=(string)audio, clock-rate=(int)%d, channels=(int)%d\' ! rtpjitterbuffer latency=%d ! rtppcmadepay ! alawdec ! audioresample ! audioconvert ! alsasink device=\'hw:0,2\'"
|
| 30 | #define RTP_TO_CMD "gst-launch-1.0 -v alsasrc device=\'hw:0,6\' ! audioconvert ! audioresample ! alawenc ! rtppcmapay ! udpsink host=%s auto-multicast=true port=%d"
|
| 31 | #define MAX_IP_LENGTH 128
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 32 | #define USER_LOG_TAG "LYNQ_CALL"
|
| 33 |
|
| 34 | using ::android::Parcel;
|
| 35 | typedef enum {
|
| 36 | LYNQ_CALL_ACTIVE = 0,
|
| 37 | LYNQ_CALL_HOLDING = 1,
|
| 38 | LYNQ_CALL_DIALING = 2, /* MO call only */
|
| 39 | LYNQ_CALL_ALERTING = 3, /* MO call only */
|
| 40 | LYNQ_CALL_INCOMING = 4, /* MT call only */
|
lh | e45b700 | 2022-04-26 00:45:44 -0700 | [diff] [blame] | 41 | LYNQ_CALL_WAITING = 5, /* MT call only */
|
| 42 | /*warren add for T800 platform 2022/04/26 start*/
|
| 43 | LYNQ_CALL_END = 6, /*CALL END*/
|
| 44 | /*warren add for T800 platform 2022/04/26 end*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 45 | }lynq_call_state_t;
|
| 46 |
|
| 47 | typedef struct{
|
| 48 | int uToken;
|
| 49 | int request;
|
| 50 | int paramLen;
|
| 51 | char param[LYNQ_REQUEST_PARAM_BUF];
|
| 52 | }lynq_client_t;
|
| 53 | typedef struct
|
| 54 | {
|
| 55 | int used;
|
| 56 | int call_id;
|
| 57 | int call_state;
|
| 58 | int toa;
|
| 59 | int direction;/*0: MO call,1:MT call*/
|
| 60 | char addr[LYNQ_PHONE_NUMBER_MAX];
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 61 | }lynq_call_list_e_t;
|
| 62 | typedef struct
|
| 63 | {
|
| 64 | int call_id;
|
| 65 | int call_state;
|
| 66 | int toa;
|
| 67 | int direction;/*0: MO call,1:MT call*/
|
| 68 | char addr[LYNQ_PHONE_NUMBER_MAX];
|
| 69 | }lynq_call_list_t;
|
| 70 |
|
| 71 | lynq_call_list_e_t lynq_call_lists[LYNQ_CALL_MAX]={};
|
| 72 | static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 73 | static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 74 | static pthread_mutex_t s_urc_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 75 | static pthread_cond_t s_urc_call_state_change_cond = PTHREAD_COND_INITIALIZER;
|
| 76 | static pthread_mutex_t s_incoming_call_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 77 | static pthread_cond_t s_incoming_call_cond = PTHREAD_COND_INITIALIZER;
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 78 | pthread_t lynq_call_urc_tid = -1;
|
| 79 | pthread_t lynq_call_list_loop_tid = -1;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 80 |
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 81 | /*lei add*/
|
| 82 | /* socket文件描述符 */
|
| 83 | int len_addr_serv;
|
| 84 | struct sockaddr_in addr_serv;
|
| 85 | lynq_client_t client_t;
|
| 86 | int client_size = 0;
|
| 87 | /*lei add*/
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 88 |
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 89 | int s_call_urc_event_complete = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 90 |
|
| 91 | enum{
|
| 92 | CALL_OFF=0,
|
| 93 | CALL_ON=1
|
| 94 | }call_state;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 95 | typedef enum{
|
| 96 | LYNQ_E_CARDSTATE_ERROR=8000,
|
| 97 | /* The voice service state is out of service*/
|
| 98 | LYNQ_E_STATE_OUT_OF_SERVICE=8001,
|
| 99 | /* The voice service state is EMERGENCY_ONLY*/
|
| 100 | LYNQ_E_STATE_EMERGENCY_ONLY=8002,
|
| 101 | /* The radio power is power off*/
|
| 102 | LYNQ_E_STATE_POWER_OFF=8003,
|
| 103 | LYNQ_E_TIME_OUT=8004,
|
| 104 | /*create or open sms DB fail */
|
| 105 | LYNQ_E_SMS_DB_FAIL=8005,
|
| 106 | /*Failed to execute sql statement*/
|
| 107 | LYNQ_E_SMS_SQL_FAIL = 8006,
|
| 108 | LYNQ_E_SMS_NOT_FIND = 8007,
|
| 109 | /* The logic conflict*/
|
| 110 | LYNQ_E_CONFLICT=9000,
|
| 111 | /*Null anomaly*/
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 112 | LYNQ_E_NULL_ANONALY=9001,
|
| 113 | /*Invalid id anomaly*/
|
| 114 | LYNQ_E_INVALID_ID_ANONALY=9002,
|
| 115 | #ifdef ECALL_SUPPORT
|
| 116 | LYNQ_E_ECALL_BEING_RUNNING =9003,
|
| 117 | LYNQ_E_ECALL_MSD_LENGTH_ERROR =9004,
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 118 | LYNQ_E_ECALL_DAILING_NO_ANSWER =9005,
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 119 | #endif
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 120 | }LYNQ_E;
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 121 | typedef enum{
|
| 122 | LYNQ_E_VOLUMN_SET_DTMF,
|
| 123 | LYNQ_E_VOLUMN_SET_SPEECH
|
| 124 | }LYNQ_E_VOLUMN_SET;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 125 |
|
| 126 | int lynq_call_state =CALL_OFF;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 127 | int lynq_call_client_sockfd = 0;
|
| 128 | int Global_uToken_call = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 129 | int global_call_count =0;
|
| 130 | int global_call_auto_answer = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 131 | bool urc_call_recive_status = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 132 | bool call_list_loop = 1;
|
| 133 | int isDial = 0;
|
| 134 | int lynqIncomingCallId = 0;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 135 |
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 136 | /*rtp begin*/
|
| 137 | typedef struct
|
| 138 | {
|
| 139 | char ip[MAX_IP_LENGTH];
|
| 140 | int port;
|
| 141 | }lynq_rtp_server_info;
|
| 142 |
|
| 143 | typedef struct
|
| 144 | {
|
| 145 | int port;
|
| 146 | int clockrate;
|
| 147 | int latency;
|
| 148 | int channels;
|
| 149 | }lynq_rtp_client_info;
|
| 150 |
|
| 151 | static lynq_rtp_client_info g_rtp_client_info;
|
| 152 | static lynq_rtp_server_info g_rtp_server_info;
|
| 153 |
|
| 154 | static pthread_t g_rtp_thread[RTP_MODE_MAX];
|
| 155 | static bool g_rtp_thread_valid[RTP_MODE_MAX];
|
| 156 |
|
| 157 | /*rtp end*/
|
| 158 |
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 159 | #ifdef ECALL_SUPPORT
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 160 | int lynq_set_common_request(int request_id, int argc, const char* format,...);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 161 | int g_ecallId = INVALID_ID;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 162 | typedef enum{
|
| 163 | LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
|
| 164 | LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 165 | LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 166 | LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 167 | }LYNQ_ECall_Type;
|
| 168 |
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 169 | typedef enum{
|
| 170 | LYNQ_ECALL_DAILING_STATE_NONE =0,
|
| 171 | LYNQ_ECALL_DAILING_STATE_STARTED = 1,
|
| 172 | LYNQ_ECALL_DAILING_STATE_ANSWERED = 2,
|
| 173 | }LYNQ_ECall_Dailing_State;
|
| 174 |
|
| 175 | LYNQ_ECall_Dailing_State is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 176 | char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"test_ecall","emergency_ecall","reconf_ecall"};
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 177 |
|
| 178 | static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
|
| 179 | static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
|
| 180 |
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 181 | LYNQ_ECall_Indication g_lynqIncomingEcallIndication;
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 182 | int g_lynqIncomingEcallId;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 183 |
|
| 184 | void sendSignalIncomingECallEvent()
|
| 185 | {
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 186 | LYINFLOG("send incoming ecall event signal");
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 187 | pthread_mutex_lock(&s_incoming_e_call_mutex);
|
| 188 | pthread_cond_signal(&s_incoming_e_call_cond);
|
| 189 | pthread_mutex_unlock(&s_incoming_e_call_mutex);
|
| 190 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 191 |
|
| 192 | int lynq_is_msd_suc(LYNQ_ECall_Indication lynqIncomingEcallIndication)
|
| 193 | {
|
| 194 | if(LYNQ_ECALL_LLACK_RECEIVED == lynqIncomingEcallIndication ||
|
| 195 | LYNQ_ECALL_ALACK_POSITIVE_RECEIVED == lynqIncomingEcallIndication ||
|
| 196 | LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED == lynqIncomingEcallIndication ||
|
| 197 | LYNQ_ECALL_T5_TIMER_OUT == lynqIncomingEcallIndication ||
|
| 198 | LYNQ_ECALL_T6_TIMER_OUT == lynqIncomingEcallIndication ||
|
| 199 | LYNQ_ECALL_T7_TIMER_OUT == lynqIncomingEcallIndication)
|
| 200 | {
|
| 201 | return 1;
|
| 202 | }
|
| 203 |
|
| 204 | return 0;
|
| 205 | }
|
| 206 |
|
| 207 | int lynq_ecall_is_running()
|
| 208 | {
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 209 | return (is_ecall_dial!=LYNQ_ECALL_DAILING_STATE_NONE) || (g_ecallId !=INVALID_ID);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 210 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 211 | #endif
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 212 |
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 213 | /**
|
| 214 | * @brief mark call initialization state
|
| 215 | * 0: deinit state
|
| 216 | * 1: init state
|
| 217 | */
|
| 218 | int g_lynq_call_init_flag = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 219 |
|
| 220 | int JumpHeader(Parcel &p,int *resp_type,int *request,int *slot_id,int *error)
|
| 221 | {
|
| 222 | if(p.dataAvail() > 0)
|
| 223 | {
|
| 224 | p.readInt32(resp_type);
|
| 225 | p.readInt32(request);
|
| 226 | p.readInt32(slot_id);
|
| 227 | p.readInt32(error);
|
| 228 | return 0;
|
| 229 | }
|
| 230 | else
|
| 231 | {
|
| 232 | return -1;
|
| 233 | }
|
| 234 | }
|
| 235 | int send_request(int sockfd,lynq_client_t *client_tmp)
|
| 236 | {
|
| 237 | int ret=0;
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 238 | 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] | 239 | if(ret==-1)
|
| 240 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 241 | LYERRLOG("sendto error");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 242 | return -1;
|
| 243 | }
|
| 244 | return 0;
|
| 245 | }
|
| 246 |
|
| 247 | int get_response(int sockfd,Parcel &p)
|
| 248 | {
|
| 249 | int len = 0;
|
| 250 | char recvline[LYNQ_REC_BUF];
|
| 251 | bzero(recvline,LYNQ_REC_BUF);
|
| 252 | /* receive data from server */
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 253 | 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] | 254 | if(len == -1)
|
| 255 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 256 | LYERRLOG("recvfrom error");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 257 | return -1;
|
| 258 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 259 | if (recvline != NULL) {
|
| 260 | p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
|
| 261 | p.setDataPosition(0);
|
| 262 | }
|
| 263 | return 0;
|
| 264 | }
|
| 265 | static char *strdupReadString(Parcel &p) {
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 266 | size_t stringlen;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 267 | const char16_t *s16;
|
| 268 | s16 = p.readString16Inplace(&stringlen);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 269 | return strndup16to8(s16, stringlen);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 270 | }
|
| 271 |
|
| 272 | int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
|
| 273 | {
|
| 274 | Parcel p;
|
| 275 | lynq_client_t client;
|
| 276 | int resp_type = -1;
|
| 277 | int request = -1;
|
| 278 | int slot_id = -1;
|
| 279 | int error = -1;
|
| 280 | int call_num = 0;
|
| 281 | int temp = 0;
|
| 282 | char *remote_phoneNum = NULL;
|
| 283 | char *remote_name= NULL;
|
| 284 | char *uusData = NULL;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 285 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 286 | client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
|
| 287 | client.paramLen = 0;
|
| 288 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 289 | LYINFLOG("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] | 290 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 291 | {
|
| 292 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 293 | return -1;
|
| 294 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 295 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 296 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 297 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 298 | if(error == 0)
|
| 299 | {
|
| 300 | p.readInt32(&call_num);
|
| 301 | global_call_count = call_num;
|
| 302 | if(call_num<=0)
|
| 303 | {
|
| 304 | lynq_call_state = CALL_OFF;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 305 | LYINFLOG("lynq_call_state:%d",lynq_call_state);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 306 | return 0;
|
| 307 | }
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 308 | lynq_call_state = CALL_ON;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 309 | LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 310 | for(int i = 0;i < call_num;i++)
|
| 311 | {
|
| 312 | p.readInt32(&temp);
|
| 313 | call_list[i].call_state = temp;
|
| 314 | p.readInt32(&call_list[i].call_id);
|
| 315 | p.readInt32(&call_list[i].toa);
|
| 316 | p.readInt32(&temp);
|
| 317 | p.readInt32(&temp);
|
| 318 | call_list[i].direction = temp;
|
| 319 | p.readInt32(&temp);
|
| 320 | p.readInt32(&temp);
|
| 321 | p.readInt32(&temp);
|
| 322 | remote_phoneNum = strdupReadString(p);
|
| 323 | memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
|
| 324 | LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
|
| 325 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 326 | p.readInt32(&temp);
|
| 327 | remote_name = strdupReadString(p);
|
| 328 | p.readInt32(&temp);
|
| 329 | p.readInt32(&temp);
|
| 330 | if(temp==0)
|
| 331 | {
|
| 332 | continue;
|
| 333 | }
|
| 334 | p.readInt32(&temp); /* UUS Information is present */
|
| 335 | p.readInt32(&temp);
|
| 336 | p.readInt32(&temp);
|
| 337 | p.read(uusData,temp);
|
| 338 | }
|
| 339 | }
|
| 340 | return 0;
|
| 341 | }
|
| 342 |
|
| 343 | void cleanCallList(int lynq_call_id)
|
| 344 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 345 | LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,lynq_call_lists[lynq_call_id].call_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 346 | lynq_call_lists[lynq_call_id].call_id = 0;
|
lh | e45b700 | 2022-04-26 00:45:44 -0700 | [diff] [blame] | 347 | lynq_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 348 | lynq_call_lists[lynq_call_id].toa = 0;
|
| 349 | lynq_call_lists[lynq_call_id].direction = 0;
|
| 350 | lynq_call_lists[lynq_call_id].used = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 351 | memset(lynq_call_lists[lynq_call_id].addr,0,sizeof(lynq_call_lists[lynq_call_id].addr));
|
| 352 | }
|
| 353 | int getUnusedElement()
|
| 354 | {
|
| 355 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 356 | {
|
| 357 | if(lynq_call_lists[i].used!=1)
|
| 358 | {
|
| 359 | return i;
|
| 360 | }
|
| 361 | }
|
| 362 | return -1;
|
| 363 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 364 | int addAddr(char addr[])
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 365 | {
|
| 366 | int ret = 0;
|
| 367 | ret = getUnusedElement();
|
| 368 | memcpy(lynq_call_lists[ret].addr,addr,strlen(addr)+1);
|
| 369 | lynq_call_lists[ret].used = 1;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 370 | LYINFLOG("add local idx is %d addr is %s",ret,addr);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 371 | return ret;
|
| 372 | }
|
| 373 | void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
|
| 374 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 375 | LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 376 | callList->call_id = call_id;
|
| 377 | callList->call_state = call_state;
|
| 378 | callList->toa = toa;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 379 | callList->direction = direction;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 380 | return;
|
| 381 | }
|
| 382 | int waitCallstateChange(int mtime)
|
| 383 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 384 | LYINFLOG("wait Call state Change");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 385 | int ret = 0;
|
| 386 | int sec = 0;
|
| 387 | int usec = 0;
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 388 | struct timeval now;
|
| 389 | struct timespec timeout;
|
| 390 | gettimeofday(&now,NULL);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 391 | sec = mtime/1000;
|
| 392 | usec = mtime%1000;
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 393 | timeout.tv_sec = now.tv_sec+sec;
|
| 394 | timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 395 | pthread_mutex_lock(&call_state_change_mutex);
|
lh | 2afc773 | 2022-01-10 02:24:31 -0800 | [diff] [blame] | 396 | ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 397 | pthread_mutex_unlock(&call_state_change_mutex);
|
| 398 | return ret;
|
| 399 | }
|
| 400 | int waitIncomingCall()
|
| 401 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 402 | LYINFLOG("wait incming call");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 403 | int ret = 0;
|
| 404 | pthread_mutex_lock(&s_incoming_call_mutex);
|
| 405 | ret = pthread_cond_wait(&s_incoming_call_cond,&s_incoming_call_mutex);
|
| 406 | pthread_mutex_unlock(&s_incoming_call_mutex);
|
| 407 | return ret;
|
| 408 | }
|
| 409 | int checkHasCall(char addr[])
|
| 410 | {
|
| 411 | for(int i = 0;i<LYNQ_CALL_MAX;i++)
|
| 412 | {
|
| 413 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 414 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 415 | LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,lynq_call_lists[i].call_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 416 | return 1;
|
| 417 | }
|
| 418 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 419 | LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 420 | return 0;
|
| 421 | }
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 422 | int find_call_id_with_addr(char *addr)
|
| 423 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 424 | for(int id = 0; id < LYNQ_CALL_MAX; id++)
|
| 425 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 426 | if(lynq_call_lists[id].used && (strcmp(lynq_call_lists[id].addr,addr) == 0))
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 427 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 428 | LYINFLOG("find addr %s in local list, local idx is %d id is %d",addr,id,lynq_call_lists[id].call_id);
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 429 | return id;
|
| 430 | }
|
| 431 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 432 | LYINFLOG("find addr %s in local list , not found",addr);
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 433 | return -1;
|
| 434 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 435 | int find_call_id_with_call_id(int call_id)
|
| 436 | {
|
| 437 | for(int id = 0; id < LYNQ_CALL_MAX; id++)
|
| 438 | {
|
| 439 | if(lynq_call_lists[id].used && (lynq_call_lists[id].call_id == call_id))
|
| 440 | {
|
| 441 | LYINFLOG("find id %d in local list, local idx is %d, addr is %s",call_id,id,lynq_call_lists[id].addr);
|
| 442 | return id;
|
| 443 | }
|
| 444 | }
|
| 445 | LYINFLOG("find id %d in local list , not found",call_id);
|
| 446 | return INVALID_ID;
|
| 447 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 448 | void sendSignalToWaitCallStateChange()
|
| 449 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 450 | LYINFLOG("send Signal To Wait Call State Change");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 451 | pthread_mutex_lock(&call_state_change_mutex);
|
| 452 | pthread_cond_signal(&call_state_change_cond);
|
| 453 | pthread_mutex_unlock(&call_state_change_mutex);
|
| 454 | }
|
| 455 | void sendSignalIncomingCall()
|
| 456 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 457 | LYINFLOG("send incoming call signal");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 458 | pthread_mutex_lock(&s_incoming_call_mutex);
|
| 459 | pthread_cond_signal(&s_incoming_call_cond);
|
| 460 | pthread_mutex_unlock(&s_incoming_call_mutex);
|
| 461 | }
|
| 462 |
|
| 463 | void addCallListToLynqCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction,char addr[LYNQ_PHONE_NUMBER_MAX])
|
| 464 | {
|
| 465 | callList->call_id = call_id;
|
| 466 | callList->call_state = call_state;
|
| 467 | callList->toa = toa;
|
| 468 | callList->direction = direction;
|
| 469 | memcpy(callList->addr,addr,strlen(addr)+1);
|
| 470 | callList->used = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 471 | return;
|
| 472 | }
|
| 473 |
|
| 474 | void *triggerGetCallList(void *parg)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 475 | {
|
| 476 | int ret=0;
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 477 | bool call_end;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 478 | lynq_call_list_t call_list[LYNQ_CALL_MAX];
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 479 | int update=0;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 480 | int cnt;
|
| 481 | int i,n;
|
| 482 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 483 | while(call_list_loop)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 484 | {
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 485 | update=0;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 486 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 487 | pthread_cond_wait(&s_urc_call_state_change_cond, &s_urc_call_state_change_mutex);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 488 | LYDBGLOG("triggerGetCallList event!!!");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 489 | memset(call_list,0,sizeof(call_list));
|
| 490 | ret = lynq_get_current_call_list(call_list);
|
| 491 | if(ret != 0)
|
| 492 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 493 | LYDBGLOG("get current call list failure!!!");
|
ll | bc03533 | 2022-04-11 05:49:51 +0000 | [diff] [blame] | 494 | continue;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 495 | }
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 496 | LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 497 | LYINFLOG("clear local index begin");
|
| 498 | cnt=0;
|
| 499 | for(i = 0;i < LYNQ_CALL_MAX;i++)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 500 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 501 | if(lynq_call_lists[i].used ==0)
|
| 502 | {
|
| 503 | continue;
|
| 504 | }
|
| 505 | cnt++;
|
| 506 | LYINFLOG("local idx is %d id is %d addr is %s state is %d direction is %d",i,lynq_call_lists[i].call_id,lynq_call_lists[i].addr,lynq_call_lists[i].call_state,lynq_call_lists[i].direction);
|
| 507 |
|
| 508 | if(lynq_call_lists[i].call_id > 0)
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 509 | {
|
| 510 | call_end = 0;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 511 | for(n = 0; n < LYNQ_CALL_MAX; n++)
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 512 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 513 | if(call_list[n].call_id == lynq_call_lists[i].call_id)
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 514 | {
|
| 515 | call_end = 1;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 516 | LYINFLOG("find lynq call local idx %d, service idx %d id is %d!!!",i,n,lynq_call_lists[i].call_id);
|
| 517 | break;
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 518 | }
|
| 519 | }
|
| 520 | if(call_end == 0)
|
| 521 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 522 | LYINFLOG("MT hungup,then clean call info local idx is %d id is %d",i, lynq_call_lists[i].call_id);
|
| 523 | cleanCallList(i);
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 524 | }
|
| 525 | } //fix bug API-54
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 526 | else
|
| 527 | {
|
| 528 | LYINFLOG("local id is 0");
|
| 529 | }
|
| 530 | }
|
| 531 | LYINFLOG("clear local index end, local used cnt is %d", cnt);
|
| 532 |
|
| 533 | LYINFLOG("add or update local index begin ");
|
| 534 | for (i = 0;i < LYNQ_CALL_MAX;i++)
|
| 535 | {
|
| 536 | if(call_list[i].call_id==0)
|
| 537 | {
|
| 538 | break;
|
| 539 | }
|
| 540 |
|
| 541 | LYINFLOG("servie idx %d begin: call_id=%d, call_state=%d, direction=%d, addr=%s, toa=%d",i,call_list[i].call_id, call_list[i].call_state,
|
| 542 | call_list[i].direction,call_list[i].addr,call_list[i].toa);
|
| 543 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 544 | if(call_list[i].direction == 1)//MT call
|
| 545 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 546 | LYINFLOG("This is a MT CALL");
|
lh | 0fd3b01 | 2022-05-13 03:02:19 -0700 | [diff] [blame] | 547 | /*MT CALL state code
|
| 548 | **LYNQ_CALL_INCOMING = 4,
|
| 549 | **LYNQ_CALL_WAITING = 5,
|
| 550 | */
|
| 551 | if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 552 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 553 | #ifdef ECALL_SUPPORT
|
| 554 | if(lynq_ecall_is_running())
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 555 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 556 | lynq_call_hungup(&(call_list[i].call_id));
|
| 557 | continue;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 558 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 559 | #endif
|
| 560 | }
|
| 561 | /*you call me, and i call you,One party failed to dial*/
|
| 562 | n = find_call_id_with_addr(call_list[i].addr);
|
| 563 | if(n ==INVALID_ID)
|
| 564 | {
|
| 565 | n = addAddr(call_list[i].addr);
|
| 566 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
| 567 | lynqIncomingCallId = call_list[i].call_id;
|
| 568 | sendSignalIncomingCall();
|
| 569 | }
|
| 570 | else if(lynq_call_lists[n].call_state == call_list[i].call_state)
|
| 571 | {
|
| 572 | LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
|
| 573 | if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 574 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 575 | /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
|
| 576 | **an incoming call until the status changes.
|
| 577 | **fix bug API-54
|
| 578 | */
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 579 | LYINFLOG("resend incoming call signal");
|
| 580 | sendSignalIncomingCall();
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 581 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 582 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 583 | else
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 584 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 585 | LYINFLOG("state changed from %d to %d",lynq_call_lists[n].call_state,call_list[i].call_state);
|
| 586 |
|
| 587 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
| 588 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 589 | }
|
| 590 | else
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 591 | {
|
| 592 | LYINFLOG("This is a MO CALL");
|
| 593 | call_end = 0;
|
| 594 | for(n = 0 ; n < LYNQ_CALL_MAX; n++)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 595 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 596 | if(lynq_call_lists[n].used && ((strcmp(call_list[i].addr,lynq_call_lists[n].addr)==0)||(call_list[i].call_id==lynq_call_lists[n].call_id)))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 597 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 598 | if(lynq_call_lists[n].call_id==0)
|
| 599 | {
|
| 600 | LYINFLOG("add a call id");
|
| 601 | update=1;
|
| 602 | }
|
| 603 | LYINFLOG("local idx %d updated, original call id is %d origial addr is %s original state is %d",n,lynq_call_lists[n].call_id,lynq_call_lists[n].addr,lynq_call_lists[n].call_state);
|
| 604 | updateCallList(&lynq_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
|
| 605 | call_end = 1;
|
| 606 | break;
|
| 607 | }
|
| 608 | }
|
| 609 |
|
| 610 | if(call_end == 0)
|
| 611 | {
|
| 612 | LYINFLOG("need to hangup id %d", call_list[i].call_id);
|
| 613 | #ifdef ECALL_SUPPORT
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 614 | if(is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 615 | {
|
| 616 | LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 617 | continue;
|
| 618 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 619 | #endif
|
| 620 | LYINFLOG("hang up service call id %d",call_list[i].call_id);
|
| 621 | lynq_call_hungup(&(call_list[i].call_id));
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 622 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 623 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 624 | LYDBGLOG("servie idx %d end",i);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 625 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 626 | LYINFLOG("add or update local index end ");
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 627 | s_call_urc_event_complete = 1;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 628 | if(isDial==1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 629 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 630 | LYINFLOG("now is dialing");
|
| 631 | if(update==1)
|
| 632 | {
|
| 633 | LYINFLOG("find added call");
|
| 634 | sendSignalToWaitCallStateChange();
|
| 635 | isDial = 0;
|
| 636 | }
|
| 637 | else
|
| 638 | {
|
| 639 | LYINFLOG("not find added call");
|
| 640 | }
|
| 641 | }
|
| 642 | else
|
| 643 | {
|
| 644 | LYINFLOG("now is not dialing");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 645 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 646 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
| 647 | }
|
| 648 | return NULL;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 649 | }
|
| 650 |
|
| 651 | void lynqRespWatingEvent()
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 652 | {
|
| 653 | if(s_call_urc_event_complete==1)
|
| 654 | {
|
| 655 | pthread_mutex_lock(&s_urc_call_state_change_mutex);
|
| 656 | pthread_cond_signal(&s_urc_call_state_change_cond);
|
| 657 | s_call_urc_event_complete = 0;
|
| 658 | pthread_mutex_unlock(&s_urc_call_state_change_mutex);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 659 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 660 | return;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 661 | }
|
| 662 |
|
| 663 | /*Warren add for T800 platform 2021/11/19 start*/
|
| 664 | int lynq_socket_client_start()
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 665 | {
|
| 666 | #if 0
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 667 | struct sockaddr_in lynq_socket_server_addr;
|
| 668 | /* init lynq_socket_server_addr */
|
| 669 | bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
|
| 670 | lynq_socket_server_addr.sin_family = AF_INET;
|
| 671 | lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 672 | lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 673 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 674 | /*
|
| 675 | if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
|
| 676 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 677 | LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 678 | exit(1);
|
| 679 | }
|
| 680 | */
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 681 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 682 | 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] | 683 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 684 | LYERRLOG("connect error");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 685 | return -1;
|
| 686 | }
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 687 | #endif
|
| 688 | lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
| 689 | if (-1 == lynq_call_client_sockfd)
|
| 690 | {
|
| 691 | return lynq_call_client_sockfd;
|
| 692 | }
|
| 693 | /* 设置address */
|
| 694 | memset(&addr_serv, 0, sizeof(addr_serv));
|
| 695 | addr_serv.sin_family = AF_INET;
|
| 696 | addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
|
| 697 | addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
|
| 698 | len_addr_serv = sizeof(addr_serv);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 699 | return 0;
|
| 700 | }
|
| 701 | int lynq_update_call_list_loop()
|
| 702 | {
|
| 703 | int ret = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 704 | pthread_attr_t attr;
|
| 705 | pthread_attr_init(&attr);
|
| 706 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 707 | ret = pthread_create(&lynq_call_list_loop_tid,&attr,triggerGetCallList,NULL);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 708 | if(ret < 0)
|
| 709 | {
|
| 710 | LYERRLOG("lynq_update_call_list_loop fail!!!");
|
| 711 | return -1;
|
| 712 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 713 | LYDBGLOG("lynq_update_call_list_loop success!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 714 | return 0;
|
| 715 |
|
| 716 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 717 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 718 | void *thread_urc_recv(void *parg)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 719 | {
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 720 | int socket_fd = (int64_t)parg;
|
| 721 | int len=0;
|
| 722 | socklen_t addr_len=0;
|
| 723 | uint8_t *dataLength = NULL;
|
| 724 | char urc_data[LYNQ_REC_BUF];
|
| 725 | int slot_id = -1;
|
| 726 | int resp_type = -1;
|
| 727 | int urcid = -1;
|
| 728 | Parcel *p = NULL;
|
| 729 | struct sockaddr_in dest_addr;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 730 | #ifdef ECALL_SUPPORT
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 731 | int ecall_ind;
|
| 732 | int ecallId;
|
| 733 | int unused_callid;
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 734 | #endif
|
| 735 |
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 736 | LYINFLOG("thread_urc_recv in running....");
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 737 | while(urc_call_recive_status)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 738 | {
|
| 739 | bzero(urc_data,LYNQ_REC_BUF);
|
| 740 | //get data msg
|
| 741 | len = recvfrom(socket_fd,urc_data,LYNQ_REC_BUF,0,(struct sockaddr *)&dest_addr,&addr_len);
|
| 742 | if(len <= 0)
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 743 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 744 | LYERRLOG("thread_urc_recv step2 fail");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 745 | break;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 746 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 747 | LYDBGLOG("=====>urc data len<=====:%d",len);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 748 | p = new Parcel();
|
| 749 | if(p==NULL)
|
| 750 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 751 | LYERRLOG("new parcel failure!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 752 | break;
|
| 753 | }
|
| 754 | p->setData((uint8_t *)urc_data,len); // p.setData((uint8_t *) buffer, buflen);
|
| 755 | p->setDataPosition(0);
|
| 756 | if(p->dataAvail() > 0)
|
| 757 | {
|
| 758 | p->readInt32(&resp_type);
|
| 759 | p->readInt32(&urcid);
|
| 760 | p->readInt32(&slot_id);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 761 | //LYDBGLOG("*******Warren test*******:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 762 | switch (urcid)
|
| 763 | {
|
| 764 | case 1001://RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED
|
| 765 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 766 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 767 | lynqRespWatingEvent();
|
| 768 | break;
|
| 769 | }
|
| 770 | case 1018://RIL_UNSOL_CALL_RING
|
| 771 | {
|
| 772 | if(global_call_auto_answer==1)
|
| 773 | {
|
| 774 | lynq_call_answer();
|
| 775 | }
|
| 776 | break;
|
| 777 | }
|
| 778 | case 1029://RIL_UNSOL_RINGBACK_TONE
|
| 779 | case 3049://RIL_UNSOL_CALL_INFO_INDICATION
|
| 780 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 781 | LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 782 | break;
|
| 783 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 784 | #ifdef ECALL_SUPPORT
|
| 785 | case RIL_UNSOL_ECALL_INDICATIONS:
|
| 786 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 787 | p->readInt32(&ecall_ind);
|
| 788 | g_lynqIncomingEcallIndication = ecall_ind;
|
| 789 | p->readInt32(&ecallId);
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 790 | g_lynqIncomingEcallId = ecallId;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 791 | LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS ,Id %d, ind %d, ecall dialing is %d, normal dialing is %d, local ecall id is %d",ecallId,ecall_ind,is_ecall_dial,isDial,g_ecallId);
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 792 | switch (g_lynqIncomingEcallIndication)
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 793 | {
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 794 | case LYNQ_ECALL_ACTIVE:
|
| 795 | if(is_ecall_dial)
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 796 | {
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 797 | is_ecall_dial = LYNQ_ECALL_DAILING_STATE_ANSWERED;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 798 | }
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 799 | break;
|
| 800 | case LYNQ_ECALL_LLACK_RECEIVED:
|
| 801 | case LYNQ_ECALL_ALACK_POSITIVE_RECEIVED:
|
| 802 | case LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED:
|
| 803 | case LYNQ_ECALL_T5_TIMER_OUT:
|
| 804 | case LYNQ_ECALL_T6_TIMER_OUT:
|
| 805 | case LYNQ_ECALL_T7_TIMER_OUT:
|
| 806 | if(is_ecall_dial)
|
| 807 | {
|
| 808 | LYINFLOG("ecall is dialing, recv suc indication");
|
| 809 | is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
|
| 810 | if(ecallId >0 && find_call_id_with_call_id(ecallId)==INVALID_ID)
|
| 811 | {
|
| 812 | LYINFLOG("add ecall in loacl list");
|
| 813 | g_ecallId = ecallId;
|
| 814 | unused_callid=addAddr("ecall");
|
| 815 | lynq_call_lists[unused_callid].call_id=g_ecallId;
|
| 816 | }
|
| 817 | sendSignalToWaitCallStateChange();
|
| 818 | }
|
| 819 | else if(ecallId >0 && (find_call_id_with_call_id(ecallId)==INVALID_ID))
|
| 820 | {
|
| 821 | LYERRLOG("ecall is not in dialing and first recv suc indication, hangup");
|
| 822 | lynq_call_hungup(&ecallId);
|
| 823 | }
|
| 824 | else
|
| 825 | {
|
| 826 | LYERRLOG("ecall is not in dialing and not first recv suc indication");
|
| 827 | }
|
| 828 | break;
|
| 829 | case LYNQ_ECALL_PSAP_CALLBACK_START:
|
| 830 | if(lynq_ecall_is_running()==0)
|
| 831 | {
|
| 832 | LYINFLOG("ecall is not running, recv psap call back msd start, set ecall in dialing");
|
| 833 | if(find_call_id_with_call_id(ecallId)!=INVALID_ID)
|
| 834 | {
|
| 835 | g_ecallId = ecallId;
|
| 836 | if(isDial)
|
| 837 | {
|
| 838 | LYINFLOG("stop normal dial");
|
| 839 | sendSignalToWaitCallStateChange();
|
| 840 | }
|
| 841 | else
|
| 842 | {
|
| 843 | LYINFLOG("no normal dial");
|
| 844 | }
|
| 845 | }
|
| 846 | else
|
| 847 | {
|
| 848 | LYERRLOG("can't find ecall id in local list");
|
| 849 | }
|
| 850 | }
|
| 851 | else
|
| 852 | {
|
| 853 | LYERRLOG("ecall is running, recv psap call back msd start");
|
| 854 | }
|
| 855 | break;
|
| 856 | case LYNQ_ECALL_ABNORMAL_HANGUP:
|
| 857 | if(is_ecall_dial == LYNQ_ECALL_DAILING_STATE_NONE)
|
| 858 | {
|
| 859 | LYERRLOG("ecall is not in dialing , recv abnormal hangup");
|
| 860 | g_ecallId = INVALID_ID;
|
| 861 | }
|
| 862 | else if (is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)
|
| 863 | {
|
| 864 | LYERRLOG("ecall is in dialing state, recv no answer, recv abnormal hangup, dont' redial");
|
| 865 | g_ecallId = INVALID_ID;
|
| 866 | sendSignalToWaitCallStateChange();
|
| 867 | }
|
| 868 | else {
|
| 869 | LYINFLOG("ecall is in dialing and recv answer, recv abnormal hangup");
|
| 870 | }
|
| 871 | break;
|
| 872 | case LYNQ_ECALL_DISCONNECTED:
|
| 873 | case LYNQ_ECALL_REDIAL_TIMER_OUT:
|
| 874 | case LYNQ_ECALL_T2_TIMER_OUT :
|
| 875 | case LYNQ_ECALL_IMS_DISCONNECTED:
|
| 876 | g_ecallId = INVALID_ID;
|
| 877 | if(is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
|
| 878 | {
|
| 879 | LYERRLOG("ecall is in dialing, recv like disconnect indication");
|
| 880 | is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
|
| 881 | sendSignalToWaitCallStateChange();
|
| 882 | }
|
| 883 | else
|
| 884 | {
|
| 885 | LYINFLOG("ecall is not in dialing, recv like disconnect indication");
|
| 886 | }
|
| 887 | break;
|
| 888 | default:
|
| 889 | LYINFLOG("not special indication");
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 890 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 891 | sendSignalIncomingECallEvent();
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 892 | LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS, local ecall id is %d", g_ecallId);
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 893 | break;
|
| 894 | }
|
| 895 | #endif
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 896 | default:
|
| 897 | break;
|
| 898 | }
|
| 899 | }
|
| 900 | delete p;
|
| 901 | p = NULL;
|
| 902 | }
|
| 903 | close(socket_fd);
|
| 904 | }
|
| 905 | int lynq_socket_urc_start()
|
| 906 | {
|
| 907 | int socket_fd=0;
|
| 908 | int rt=0;
|
| 909 | int len=0;
|
| 910 | int on=1;
|
| 911 | struct sockaddr_in urc_local_addr;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 912 | pthread_attr_t attr;
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 913 | socket_fd = socket(AF_INET,SOCK_DGRAM,0);
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 914 | if(socket_fd < 0)
|
| 915 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 916 | LYERRLOG("creaet socket for udp fail");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 917 | return -1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 918 | }
|
| 919 | urc_local_addr.sin_family = AF_INET;
|
| 920 | urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
|
| 921 | urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
|
| 922 | /* 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] | 923 | rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
|
| 924 | if(rt<0)
|
| 925 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 926 | LYERRLOG("SO_REUSEADDR fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 927 | return -1;
|
| 928 | }
|
| 929 | rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 930 | if (rt == -1)
|
| 931 | {
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 932 | LYERRLOG("bind failed");
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 933 | return -1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 934 | }
|
| 935 | pthread_attr_init(&attr);
|
| 936 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 937 | 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] | 938 | if(rt < 0)
|
| 939 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 940 | LYERRLOG("urc loop failure!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 941 | return -1;
|
| 942 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 943 | LYDBGLOG("urc loop success!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 944 | return 0;
|
| 945 | }
|
| 946 | int getSelfElement(char addr[])
|
| 947 | {
|
| 948 | for(int i=0;i < LYNQ_CALL_MAX; i++)
|
| 949 | {
|
| 950 | if(lynq_call_lists[i].used==1)
|
| 951 | {
|
| 952 | if(strcmp(lynq_call_lists[i].addr,addr)==0)
|
| 953 | {
|
| 954 | return i;
|
| 955 | }
|
| 956 |
|
| 957 | }
|
| 958 | }
|
| 959 | return -1;
|
| 960 | }
|
| 961 |
|
| 962 | void lynq_call_state_change_test(int soc_id)
|
| 963 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 964 | LYDBGLOG("call state change,sim:%d",soc_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 965 | }
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 966 |
|
| 967 | void lynq_init_rtp()
|
| 968 | {
|
| 969 | memset(&g_rtp_client_info,0,sizeof(g_rtp_client_info));
|
| 970 | memset(&g_rtp_server_info,0,sizeof(g_rtp_server_info));
|
| 971 |
|
| 972 |
|
| 973 | lynq_set_rtp_param(8000,1,400);
|
| 974 |
|
| 975 | for(int i=0;i<RTP_MODE_MAX;i++)
|
| 976 | {
|
q.huang | 0ae26e4 | 2022-06-30 09:55:45 +0800 | [diff] [blame] | 977 | lynq_set_rtp_port(i,6666);
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 978 | g_rtp_thread_valid[i] = 0;
|
| 979 | }
|
| 980 |
|
| 981 | LYDBGLOG("lynq init rtp success!!!");
|
| 982 | return;
|
| 983 | }
|
| 984 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 985 | int lynq_init_call(int uToken)
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 986 | {
|
| 987 | if(g_lynq_call_init_flag == 1){
|
| 988 | LYDBGLOG("lynq init call failed!!!");
|
| 989 | return -1;
|
| 990 | }
|
| 991 | g_lynq_call_init_flag = 1;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 992 | int result = 0;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 993 | Global_uToken_call = uToken;
|
lh | 21502f5 | 2022-01-27 00:27:12 -0800 | [diff] [blame] | 994 | urc_call_recive_status = 1;
|
rjw | 5d2a50e | 2022-02-28 15:01:49 +0800 | [diff] [blame] | 995 | client_size = sizeof(client_t);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 996 | LYLOGSET(LOG_INFO);
|
| 997 | LYLOGEINIT(USER_LOG_TAG);
|
| 998 | result = lynq_socket_client_start();
|
| 999 | if(result!=0)
|
| 1000 | {
|
| 1001 | return -1;
|
| 1002 | }
|
| 1003 | result = lynq_socket_urc_start();
|
| 1004 | if(result!=0)
|
| 1005 | {
|
| 1006 | return -1;
|
| 1007 | }
|
| 1008 | result = lynq_update_call_list_loop();
|
| 1009 | if(result!=0)
|
| 1010 | {
|
| 1011 | return -1;
|
| 1012 | }
|
| 1013 | memset(lynq_call_lists,0,sizeof(lynq_call_lists));
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1014 |
|
| 1015 | lynq_init_rtp();
|
| 1016 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1017 | LYDBGLOG("lynq init call success!!!");
|
| 1018 | return 0;
|
| 1019 | }
|
| 1020 | int lynq_deinit_call()
|
| 1021 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1022 | int ret;
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 1023 | if(g_lynq_call_init_flag == 0)
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 1024 | {
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 1025 | LYDBGLOG("lynq_deinit_call failed!!!");
|
| 1026 | return -1;
|
lh | ec17b0a | 2022-02-13 23:56:05 -0800 | [diff] [blame] | 1027 | }
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 1028 | else
|
| 1029 | {
|
| 1030 | g_lynq_call_init_flag = 0;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1031 | lynq_call_hungup_all();
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 1032 | if(lynq_call_client_sockfd>0)
|
| 1033 | {
|
| 1034 | close(lynq_call_client_sockfd);
|
| 1035 | }
|
| 1036 | urc_call_recive_status = 0;
|
| 1037 | call_list_loop = 0;
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1038 | lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
|
ll | a8c25a8 | 2022-03-17 05:31:33 +0000 | [diff] [blame] | 1039 | if(lynq_call_urc_tid == -1 || lynq_call_list_loop_tid == -1)
|
| 1040 | {
|
| 1041 | return -1;
|
| 1042 | }
|
| 1043 | ret = pthread_cancel(lynq_call_urc_tid);
|
| 1044 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 1045 | ret = pthread_cancel(lynq_call_list_loop_tid);
|
| 1046 | LYDBGLOG("pthread cancel ret = %d",ret);
|
| 1047 | ret = pthread_join(lynq_call_urc_tid,NULL);
|
| 1048 | LYDBGLOG("pthread join ret = %d",ret);
|
| 1049 | ret = pthread_join(lynq_call_list_loop_tid,NULL);
|
| 1050 | LYDBGLOG("pthread join ret = %d",ret);
|
| 1051 | return 0;
|
| 1052 | }
|
rita | 98e2e9c | 2022-04-07 06:08:13 -0400 | [diff] [blame] | 1053 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1054 |
|
| 1055 | int lynq_set_common_request(int request_id, int argc, const char* format,...)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1056 | {
|
| 1057 | Parcel p;
|
| 1058 | lynq_client_t client;
|
| 1059 | int resp_type = -1;
|
| 1060 | int request = -1;
|
| 1061 | int slot_id = -1;
|
| 1062 | int error = -1;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1063 |
|
| 1064 | client.uToken = Global_uToken_call;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1065 | client.request = request_id;
|
| 1066 | client.paramLen = argc;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1067 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1068 | if(argc!=0)
|
| 1069 | {
|
| 1070 | va_list args;
|
| 1071 | va_start(args, format);
|
| 1072 | vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
|
| 1073 | va_end(args);
|
| 1074 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1075 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1076 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
| 1077 | {
|
| 1078 | LYERRLOG("send request fail");
|
| 1079 | return -1;
|
| 1080 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1081 | if(get_response(lynq_call_client_sockfd,p)==0)
|
| 1082 | {
|
| 1083 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 1084 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 1085 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1086 | return error;
|
| 1087 | }
|
| 1088 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1089 | int lynq_get_common_request(int request_id, int* status)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1090 | {
|
| 1091 | Parcel p;
|
| 1092 | lynq_client_t client;
|
| 1093 | int resp_type = -1;
|
| 1094 | int request = -1;
|
| 1095 | int slot_id = -1;
|
| 1096 | int error = -1;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1097 | if(status==NULL)
|
| 1098 | {
|
| 1099 | LYERRLOG("status is null");
|
| 1100 | return -1;
|
| 1101 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1102 | client.uToken = Global_uToken_call;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1103 | client.request = request_id;
|
| 1104 | client.paramLen = 0;
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1105 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1106 | LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1107 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
| 1108 | {
|
| 1109 | LYERRLOG("send request fail");
|
| 1110 | return -1;
|
| 1111 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1112 | if(get_response(lynq_call_client_sockfd,p)==0)
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1113 | {
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1114 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 1115 | p.readInt32(status);
|
| 1116 | 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] | 1117 | }
|
rita | 089527e | 2022-04-07 01:55:39 -0400 | [diff] [blame] | 1118 | return error;
|
| 1119 | }
|
| 1120 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1121 | int lynq_call(int* handle,char addr[])
|
| 1122 | {
|
| 1123 | Parcel p;
|
| 1124 | lynq_client_t client;
|
| 1125 | int resp_type = -1;
|
| 1126 | int request = -1;
|
| 1127 | int slot_id = -1;
|
| 1128 | int error = -1;
|
| 1129 | int lynq_call_id = -1;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1130 |
|
| 1131 | LYINFLOG("lynq_call begin addr %s",addr);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1132 | if(addr==NULL)
|
| 1133 | {
|
| 1134 | LYERRLOG("Phone num is null!!!");
|
| 1135 | return -1;
|
| 1136 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1137 |
|
| 1138 | if(find_call_id_with_addr(addr)!=INVALID_ID)
|
| 1139 | {
|
| 1140 | LYERRLOG("addr %s exists",addr);
|
| 1141 | return LYNQ_E_CONFLICT;
|
| 1142 | }
|
| 1143 |
|
| 1144 | #ifdef ECALL_SUPPORT
|
| 1145 | if(lynq_ecall_is_running())
|
| 1146 | {
|
| 1147 | LYERRLOG("lynq_fast_ecall ecall is running");
|
| 1148 | return LYNQ_E_ECALL_BEING_RUNNING;
|
| 1149 | }
|
| 1150 | #endif
|
| 1151 |
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 1152 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1153 | client.request = 10;//RIL_REQUEST_DIAL
|
| 1154 | client.paramLen = 2;
|
| 1155 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
| 1156 | memcpy(client.param,addr,strlen(addr)+1);
|
| 1157 | strcat(client.param," 0");
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1158 | lynq_call_id = addAddr(addr);
|
| 1159 | LYINFLOG("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] | 1160 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1161 | {
|
| 1162 | LYERRLOG("send request fail");
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1163 | cleanCallList(lynq_call_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1164 | return -1;
|
| 1165 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 1166 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1167 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 1168 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1169 | if(error==0)
|
| 1170 | {
|
| 1171 | isDial = 1;
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1172 | if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1173 | {
|
lh | d1e457c | 2022-04-19 06:01:25 -0700 | [diff] [blame] | 1174 | //if timeout,this call need destroy.
|
| 1175 | isDial = 0;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1176 | error = LYNQ_E_TIME_OUT;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1177 | LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
|
| 1178 | cleanCallList(lynq_call_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1179 | return error;
|
| 1180 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1181 | isDial = 0;
|
| 1182 | *handle = lynq_call_lists[lynq_call_id].call_id;
|
| 1183 | if(*handle > 0)
|
| 1184 | {
|
| 1185 | LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
|
| 1186 | return 0;
|
| 1187 | }
|
| 1188 | else
|
| 1189 | {
|
| 1190 | LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
|
| 1191 | cleanCallList(lynq_call_id);
|
| 1192 | return LYNQ_E_INVALID_ID_ANONALY;
|
| 1193 | }
|
| 1194 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1195 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1196 | LYERRLOG("lynq_call dial addr %s fail, service error %d",addr, error);
|
| 1197 | cleanCallList(lynq_call_id);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1198 | return error;
|
| 1199 | }
|
| 1200 | int lynq_call_answer()
|
| 1201 | {
|
| 1202 | Parcel p;
|
| 1203 | lynq_client_t client;
|
| 1204 | int resp_type = -1;
|
| 1205 | int request = -1;
|
| 1206 | int slot_id = -1;
|
| 1207 | int error = -1;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 1208 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1209 | client.request = 40;//RIL_REQUEST_DIAL
|
| 1210 | client.paramLen = 0;
|
| 1211 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1212 | LYINFLOG("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] | 1213 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1214 | {
|
| 1215 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1216 | return -1;
|
| 1217 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 1218 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1219 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 1220 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 1221 | return error;
|
| 1222 | }
|
| 1223 | int lynq_call_hungup(int* handle)
|
| 1224 | {
|
| 1225 | Parcel p;
|
| 1226 | lynq_client_t client;
|
| 1227 | int resp_type = -1;
|
| 1228 | int request = -1;
|
| 1229 | int slot_id = -1;
|
| 1230 | int error = -1;
|
| 1231 | int call_id = 0;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1232 | int lynq_call_id;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 1233 | if(handle==NULL||!((*handle>=0)&&(*handle<10)))
|
| 1234 | {
|
| 1235 | LYERRLOG("[%s] illegal input!!!!",__FUNCTION__);
|
| 1236 | return LYNQ_E_CONFLICT;
|
| 1237 | }
|
| 1238 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1239 | client.request = 12;//RIL_REQUEST_HUNGUP
|
| 1240 | client.paramLen = 1;
|
| 1241 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1242 | call_id = *handle;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1243 | sprintf(client.param,"%d",call_id);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1244 | LYINFLOG("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] | 1245 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1246 | {
|
| 1247 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1248 | return -1;
|
| 1249 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 1250 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1251 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 1252 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 1253 | if(error==0)
|
| 1254 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1255 | lynq_call_id=find_call_id_with_call_id(call_id);
|
| 1256 | if(lynq_call_id!=INVALID_ID)
|
| 1257 | {
|
| 1258 | cleanCallList(lynq_call_id);
|
| 1259 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1260 | }
|
| 1261 | return error;
|
| 1262 | }
|
| 1263 | int lynq_call_hungup_all()
|
| 1264 | {
|
| 1265 | Parcel p;
|
| 1266 | lynq_client_t client;
|
| 1267 | int resp_type = -1;
|
| 1268 | int request = -1;
|
| 1269 | int slot_id = -1;
|
| 1270 | int error = -1;
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 1271 | client.uToken = Global_uToken_call;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1272 | client.request = 17;//RIL_REQUEST_UDUB
|
| 1273 | client.paramLen = 0;
|
| 1274 | bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1275 | LYDBGLOG("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] | 1276 | if(send_request(lynq_call_client_sockfd,&client)==-1)
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1277 | {
|
| 1278 | LYERRLOG("send request fail");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1279 | return -1;
|
| 1280 | }
|
lh | 42c1e57 | 2022-01-25 18:47:39 -0800 | [diff] [blame] | 1281 | get_response(lynq_call_client_sockfd,p);
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1282 | JumpHeader(p,&resp_type,&request,&slot_id,&error);
|
| 1283 | LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
|
| 1284 | return error;
|
| 1285 | }
|
| 1286 | int lynq_wait_incoming_call(int *handle)
|
| 1287 | {
|
| 1288 | waitIncomingCall();
|
| 1289 | *handle = lynqIncomingCallId;
|
| 1290 | LYINFLOG("lynq incoming call id:%d",lynqIncomingCallId);
|
| 1291 | return 0;
|
| 1292 | }
|
| 1293 |
|
| 1294 | int lynq_set_auto_answercall(const int mode)
|
| 1295 | {
|
| 1296 | global_call_auto_answer = mode;
|
| 1297 | LYINFLOG("auto answer call mode =%d",mode);
|
| 1298 | return 0;
|
| 1299 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1300 | int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
|
| 1301 | {
|
| 1302 | int lynq_call_id = 0;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1303 | LYINFLOG("lynq_get_current_call_state begin ");
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1304 | if(handle==NULL)
|
| 1305 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1306 | LYERRLOG("handle is NULL");
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1307 | return LYNQ_E_NULL_ANONALY;
|
| 1308 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1309 | lynq_call_id = find_call_id_with_call_id(*handle);
|
| 1310 | if(lynq_call_id==INVALID_ID)
|
| 1311 | {
|
| 1312 | return LYNQ_E_INVALID_ID_ANONALY;
|
| 1313 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1314 | *call_state = lynq_call_lists[lynq_call_id].call_state;
|
| 1315 | *toa = lynq_call_lists[lynq_call_id].toa;
|
| 1316 | *direction = lynq_call_lists[lynq_call_id].direction;
|
| 1317 | memcpy(addr,lynq_call_lists[lynq_call_id].addr,strlen(lynq_call_lists[lynq_call_id].addr)+1);
|
| 1318 | return 0;
|
| 1319 | }
|
| 1320 |
|
| 1321 | /*audio begin*/
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1322 | static int judge_mic(const int enable){
|
ll | f512fa3 | 2022-02-14 08:58:16 +0000 | [diff] [blame] | 1323 | switch(enable){
|
| 1324 | case 0:
|
| 1325 | return 1;
|
| 1326 | case 1:
|
| 1327 | return 1;
|
| 1328 | default:
|
| 1329 | return 0;
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1330 | }
|
| 1331 | }
|
| 1332 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1333 | int lynq_set_mute_mic(const int enable)
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1334 | {
|
| 1335 | if(!judge_mic(enable)){
|
| 1336 | return LYNQ_E_CONFLICT;
|
| 1337 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1338 | return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
|
| 1339 | }
|
| 1340 | int lynq_get_mute_mic(int *status)
|
| 1341 | {
|
| 1342 | return lynq_get_common_request(54,status);//RIL_REQUEST_GET_MUTE
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1343 | }
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1344 |
|
| 1345 | /**
|
| 1346 | * @brief Check whether DTMF is valid
|
| 1347 | *
|
| 1348 | * @param callnum dtmf eg:0-9 * #
|
| 1349 | * @return int
|
| 1350 | */
|
| 1351 | static int judge_dtmf(const char callnum)
|
| 1352 | {
|
| 1353 | if(callnum == '#')
|
| 1354 | {
|
| 1355 | return 1;
|
| 1356 | }
|
| 1357 | if(callnum == '*')
|
| 1358 | {
|
| 1359 | return 1;
|
| 1360 | }
|
| 1361 | if(callnum >= '0'&& callnum <= '9')
|
| 1362 | {
|
| 1363 | return 1;
|
| 1364 | }
|
| 1365 | return 0;
|
| 1366 | }
|
| 1367 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1368 | int lynq_set_DTMF(const char callnum)
|
| 1369 | {
|
ll | 72bf6c1 | 2022-03-24 10:22:25 +0800 | [diff] [blame] | 1370 | if(!judge_dtmf(callnum))
|
| 1371 | {
|
| 1372 | return LYNQ_E_CONFLICT;
|
| 1373 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1374 | if(!lynq_call_state)
|
| 1375 | {
|
| 1376 | LYERRLOG("LYNQ_E_CONFLICT");
|
| 1377 | return LYNQ_E_CONFLICT;
|
| 1378 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1379 | return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1380 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1381 | static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
|
| 1382 | if(set==LYNQ_E_VOLUMN_SET_DTMF){
|
| 1383 | if(volume < 0 ||volume >36){
|
| 1384 | return 0;
|
| 1385 | }
|
| 1386 | }
|
| 1387 | else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
|
| 1388 | {
|
| 1389 | if(volume < 1 ||volume >7){
|
| 1390 | return 0;
|
| 1391 | }
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1392 | }
|
ll | 04ae414 | 2022-01-27 05:54:38 +0000 | [diff] [blame] | 1393 | return 1;
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1394 | }
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1395 | int lynq_set_DTMF_volume(const int volume)
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1396 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1397 | if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
|
ll | dc99c9b | 2022-01-24 12:16:22 +0000 | [diff] [blame] | 1398 | return LYNQ_E_CONFLICT;
|
| 1399 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1400 | 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] | 1401 | }
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1402 | int lynq_set_speech_volume(const int volume)//mixer_set_volume
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1403 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1404 | if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1405 | {
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1406 | return LYNQ_E_CONFLICT;
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1407 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1408 | 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] | 1409 | }
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1410 | int lynq_get_speech_volume(int* volumn)//mixer_get_volume
|
| 1411 | {
|
| 1412 | return lynq_get_common_request(8010,volumn);//LYNQ_REQUEST_GET_SPEECH_VOLUME
|
| 1413 | }
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1414 | int lynq_incall_record_start(const char* file_path)
|
q.huang | ec88da9 | 2022-03-29 04:17:32 -0400 | [diff] [blame] | 1415 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1416 | 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] | 1417 | }
|
| 1418 | int lynq_incall_record_stop()
|
| 1419 | {
|
q.huang | b212fde | 2022-04-05 23:11:02 -0400 | [diff] [blame] | 1420 | const char* unused_file="just_ocuupy_paramter_postion";
|
| 1421 | 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] | 1422 | }
|
| 1423 | /*audio end*/
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1424 |
|
| 1425 | #ifdef ECALL_SUPPORT
|
| 1426 | LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
|
| 1427 | {
|
| 1428 | switch(type)
|
| 1429 | {
|
| 1430 | case LYNQ_ECALL_TYPE_TEST:
|
| 1431 | return LYNQ_ECALL_TEST;
|
| 1432 | case LYNQ_ECALL_TYPE_RECONFIG:
|
| 1433 | return LYNQ_ECALL_RECONFIG;
|
| 1434 | default:
|
| 1435 | return LYNQ_ECALL_EMERGENCY;
|
| 1436 | }
|
| 1437 | }
|
| 1438 |
|
| 1439 | RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
|
| 1440 | {
|
| 1441 | switch(type)
|
| 1442 | {
|
| 1443 | case LYNQ_ECALL_TEST:
|
| 1444 | return ECALL_TEST;
|
| 1445 | case LYNQ_ECALL_RECONFIG:
|
| 1446 | return ECALL_RECONFIG;
|
| 1447 | default:
|
| 1448 | return ECALL_EMERGENCY;
|
| 1449 | }
|
| 1450 | }
|
| 1451 |
|
| 1452 | RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
|
| 1453 | {
|
| 1454 | switch(cat)
|
| 1455 | {
|
| 1456 | case LYNQ_EMER_CAT_MANUAL_ECALL:
|
| 1457 | return EMER_CAT_MANUAL_ECALL;
|
| 1458 | default:
|
| 1459 | return EMER_CAT_AUTO_ECALL;
|
| 1460 | }
|
| 1461 | }
|
| 1462 |
|
| 1463 |
|
| 1464 | int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
|
| 1465 | {
|
| 1466 | int error;
|
| 1467 |
|
| 1468 | if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
|
| 1469 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1470 | LYERRLOG("test_num is null or test_num_length %d s greater than %d ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1471 | return -1;
|
| 1472 | }
|
| 1473 |
|
| 1474 | error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
|
| 1475 |
|
| 1476 | if(error==0)
|
| 1477 | {
|
| 1478 | snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
|
| 1479 | }
|
| 1480 |
|
| 1481 | return error;
|
| 1482 | }
|
| 1483 |
|
q.huang | 633b9af | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1484 | 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 | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1485 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1486 | int error;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1487 | 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] | 1488 | RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
|
q.huang | 497c977 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1489 | char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
|
| 1490 | unsigned int i;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1491 | if(lynq_ecall_is_running())
|
q.huang | 633b9af | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1492 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1493 | LYERRLOG("lynq_fast_ecall ecall is running");
|
| 1494 | return LYNQ_E_ECALL_BEING_RUNNING;
|
| 1495 | }
|
| 1496 |
|
| 1497 | if(msd_length > MSD_MAX_LENGTH || msd_length <=0)
|
| 1498 | {
|
| 1499 | LYERRLOG("lynq_fast_ecall msd_length %d is greater than %d or <= 0, parameter error",msd_length,MSD_MAX_LENGTH);
|
| 1500 | return LYNQ_E_ECALL_MSD_LENGTH_ERROR;
|
q.huang | 633b9af | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1501 | }
|
q.huang | 633b9af | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1502 |
|
q.huang | 497c977 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1503 | for(i =0; i<msd_length;i++)
|
q.huang | 633b9af | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1504 | {
|
q.huang | 497c977 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1505 | sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
|
q.huang | 633b9af | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1506 | }
|
| 1507 |
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1508 |
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1509 | LYINFLOG("lynq_fast_ecall addr is %s",e_call_addr[lynq_ecall_variant]);
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1510 |
|
q.huang | 633b9af | 2022-05-10 20:37:21 +0800 | [diff] [blame] | 1511 | 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 | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1512 |
|
| 1513 | if(error==0)
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1514 | {
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 1515 | is_ecall_dial = LYNQ_ECALL_DAILING_STATE_STARTED;
|
q.huang | 33ec056 | 2022-07-01 11:38:26 +0800 | [diff] [blame^] | 1516 | if(waitCallstateChange(270000)==ETIMEDOUT)//4.5 min, dailing 1 min, alerting 1 min, sending msd 30s, redial 2min
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1517 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1518 | LYERRLOG("lynq_fast_ecall timeout:wait Call state time out!!!");
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 1519 | is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1520 | lynqRespWatingEvent();
|
| 1521 | return LYNQ_E_TIME_OUT;
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1522 | }
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 1523 | if(is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)
|
| 1524 | {
|
| 1525 | /*just dail, no recv answer*/
|
| 1526 | LYERRLOG("lynq_fast_ecall, no answer!");
|
| 1527 | is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
|
| 1528 | lynqRespWatingEvent();
|
| 1529 | return LYNQ_E_ECALL_DAILING_NO_ANSWER;
|
| 1530 | }
|
| 1531 |
|
| 1532 | is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1533 | lynqRespWatingEvent();
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1534 |
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1535 | if(g_ecallId != INVALID_ID)
|
| 1536 | {
|
| 1537 | *handle=g_ecallId;
|
| 1538 | LYINFLOG("lynq_fast_ecall id is %d",g_ecallId);
|
| 1539 | return 0;
|
| 1540 | }
|
| 1541 | else
|
| 1542 | {
|
| 1543 | LYERRLOG("lynq_fast_ecall service return fail");
|
| 1544 | return LYNQ_E_INVALID_ID_ANONALY;
|
| 1545 | }
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1546 | }
|
| 1547 |
|
| 1548 | return error;
|
| 1549 | }
|
| 1550 |
|
| 1551 | int lynq_set_psap(int enable)
|
| 1552 | {
|
| 1553 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
|
| 1554 | }
|
| 1555 |
|
| 1556 | int lynq_psap_pull_msd()
|
| 1557 | {
|
| 1558 | return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
|
| 1559 | }
|
| 1560 |
|
| 1561 | int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
|
| 1562 | {
|
| 1563 | LYNQ_ECall_Variant lynq_ecall_variant;
|
| 1564 | int error = -1;
|
| 1565 | int lynq_call_id = -1;
|
| 1566 |
|
| 1567 | if(handle==NULL)
|
| 1568 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1569 | LYERRLOG("handle is NULL, parameter error ");
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1570 | return -1;
|
| 1571 | }
|
| 1572 |
|
| 1573 | error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
|
| 1574 |
|
| 1575 | if(error==0)
|
| 1576 | {
|
| 1577 | lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
|
| 1578 |
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1579 | lynq_call_id = addAddr(e_call_addr[lynq_ecall_variant]);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1580 | isDial = 1;
|
| 1581 | if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
|
| 1582 | {
|
| 1583 | error = LYNQ_E_TIME_OUT;
|
| 1584 | LYERRLOG("timeout:wait Call state fail!!!");
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1585 | return error;
|
| 1586 | }
|
| 1587 |
|
| 1588 | *handle = lynq_call_id;
|
| 1589 | }
|
| 1590 |
|
| 1591 | return error;
|
| 1592 | }
|
| 1593 |
|
| 1594 |
|
q.huang | 8f0978b | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1595 | int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length)
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1596 | {
|
q.huang | 497c977 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1597 | char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
|
| 1598 | unsigned int i;
|
| 1599 |
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1600 | if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX) || msd_length > MSD_MAX_LENGTH || msd_length == 0 || msd_data ==NULL)
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1601 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1602 | LYERRLOG("lynq_set_msd handle is NULL or *handle %d is greater or equeal to %d or msd_length %d is greater than %d or msd_data %s is NULL, parameter error",*handle,LYNQ_CALL_MAX,msd_length,MSD_MAX_LENGTH, msd_data);
|
q.huang | 8f0978b | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1603 | return -1;
|
| 1604 | }
|
q.huang | 8f0978b | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1605 |
|
q.huang | 497c977 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1606 | for(i=0; i<msd_length;i++)
|
q.huang | 8f0978b | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1607 | {
|
q.huang | 497c977 | 2022-05-11 20:10:38 +0800 | [diff] [blame] | 1608 | sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1609 | }
|
| 1610 |
|
| 1611 | LYINFLOG("lynq_set_msd ");
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1612 |
|
q.huang | 8f0978b | 2022-05-10 20:49:46 +0800 | [diff] [blame] | 1613 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",lynq_call_lists[(*handle)].call_id,lynq_msd_data);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1614 | }
|
| 1615 |
|
| 1616 | int lynq_set_ivs(int enable)
|
| 1617 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1618 | if(enable<0)
|
| 1619 | {
|
| 1620 | lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
|
| 1621 | return 0;
|
| 1622 | }
|
| 1623 |
|
| 1624 | return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1625 | }
|
| 1626 |
|
| 1627 | int lynq_reset_ivs()
|
| 1628 | {
|
| 1629 | return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
|
| 1630 | }
|
| 1631 |
|
| 1632 | int lynq_ivs_push_msd()
|
| 1633 | {
|
| 1634 | return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
|
| 1635 | }
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1636 |
|
| 1637 | int wait_ecall_event()
|
| 1638 | {
|
| 1639 | int ret = 0;
|
| 1640 | pthread_mutex_lock(&s_incoming_e_call_mutex);
|
| 1641 | ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1642 | pthread_mutex_unlock(&s_incoming_e_call_mutex);
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1643 | return ret;
|
| 1644 | }
|
| 1645 |
|
q.huang | 476aae6 | 2022-06-30 19:39:20 +0800 | [diff] [blame] | 1646 | int lynq_wait_ecall_indication(int* handle, LYNQ_ECall_Indication *eCall_Indication)
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1647 | {
|
| 1648 | wait_ecall_event();
|
q.huang | 476aae6 | 2022-06-30 19:39:20 +0800 | [diff] [blame] | 1649 | *handle = g_lynqIncomingEcallId;
|
q.huang | ce82b97 | 2022-06-21 14:57:02 +0800 | [diff] [blame] | 1650 | *eCall_Indication = g_lynqIncomingEcallIndication;
|
q.huang | 476aae6 | 2022-06-30 19:39:20 +0800 | [diff] [blame] | 1651 | LYINFLOG("lynq_wait_ecall_indication handle %d, Ind id: %d", *handle, *eCall_Indication);
|
q.huang | 8b33ed5 | 2022-04-19 20:27:44 -0400 | [diff] [blame] | 1652 | return 0;
|
| 1653 | }
|
| 1654 |
|
q.huang | 714145d | 2022-04-18 00:09:50 -0400 | [diff] [blame] | 1655 | #endif
|
| 1656 |
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1657 | /*Audio Path setting begin*/
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1658 | /*sub function*/
|
| 1659 | void lynq_set_rtp_mixer_ctrl(int enable_rtp)
|
| 1660 | {
|
| 1661 | char cmd[256];
|
| 1662 | LYINFLOG("set_rtp_mixer_ctrl %d", enable_rtp);
|
| 1663 | if(enable_rtp)
|
| 1664 | {
|
| 1665 | sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 0);
|
| 1666 | system(cmd);
|
| 1667 | sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 1);
|
| 1668 | system(cmd);
|
| 1669 | sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 1);
|
| 1670 | system(cmd);
|
| 1671 | sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 1);
|
| 1672 | system(cmd);
|
| 1673 | sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 1);
|
| 1674 | system(cmd);
|
| 1675 | sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 1);
|
| 1676 | system(cmd);
|
| 1677 | }
|
| 1678 | else
|
| 1679 | {
|
| 1680 | sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 1);
|
| 1681 | system(cmd);
|
| 1682 | sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 0);
|
| 1683 | system(cmd);
|
| 1684 | sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 0);
|
| 1685 | system(cmd);
|
| 1686 | sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 0);
|
| 1687 | system(cmd);
|
| 1688 | sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 0);
|
| 1689 | system(cmd);
|
| 1690 | sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 0);
|
| 1691 | system(cmd);
|
| 1692 | }
|
| 1693 | }
|
| 1694 |
|
| 1695 | void* lynq_start_rtp_cmd(void *arg)
|
| 1696 | {
|
| 1697 | int* rtp_mode= (int*) arg;
|
| 1698 | char cmd[384];
|
| 1699 | LYINFLOG("lynq_start_rtp_cmd: rtp_mode is %d",(*rtp_mode));
|
| 1700 | if ((*rtp_mode) == RTP_CLIENT)
|
| 1701 | {
|
| 1702 | sprintf(cmd,RTP_FROM_CMD, \
|
| 1703 | g_rtp_client_info.port,g_rtp_client_info.clockrate,g_rtp_client_info.channels, \
|
| 1704 | g_rtp_client_info.latency);
|
| 1705 | LYINFLOG("start from rtp play: cmd is %s",cmd);
|
| 1706 | system(cmd);
|
| 1707 | }
|
| 1708 | else if ((*rtp_mode) == RTP_SERVER)
|
| 1709 | {
|
| 1710 | sprintf(cmd,RTP_TO_CMD, \
|
| 1711 | g_rtp_server_info.ip,g_rtp_server_info.port);
|
| 1712 | LYINFLOG("start to rtp play: cmd is %s",cmd);
|
| 1713 | system(cmd);
|
| 1714 | }
|
| 1715 | return NULL;
|
| 1716 | }
|
| 1717 |
|
| 1718 | int lynq_start_rtp_thread(int rtp_mode)
|
| 1719 | {
|
| 1720 | int ret;
|
| 1721 | pthread_attr_t attr;
|
| 1722 | static int start_mode[RTP_MODE_MAX]={0,1};
|
| 1723 |
|
| 1724 | pthread_attr_init(&attr);
|
| 1725 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 1726 | ret = pthread_create(&(g_rtp_thread[rtp_mode]),&attr,lynq_start_rtp_cmd,&(start_mode[rtp_mode]));
|
| 1727 | if(ret != 0)
|
| 1728 | {
|
| 1729 | g_rtp_thread_valid[rtp_mode]=0;
|
| 1730 | LYERRLOG("rtp create %d pthread error, ret is %d",rtp_mode, ret);
|
| 1731 | return ret;
|
| 1732 | }
|
| 1733 | g_rtp_thread_valid[rtp_mode]=1;
|
| 1734 | return 0;
|
| 1735 | }
|
| 1736 |
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1737 | /*set*/
|
| 1738 | int lynq_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode)
|
| 1739 | {
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1740 | int ret;
|
| 1741 | int i;
|
| 1742 |
|
| 1743 | if(audio_mode==AUDIO_MODE_RTP)
|
| 1744 | {
|
| 1745 | lynq_set_rtp_mixer_ctrl(1);
|
| 1746 | for(i=0;i<RTP_MODE_MAX;i++)
|
| 1747 | {
|
| 1748 | if(!g_rtp_thread_valid[i])
|
| 1749 | {
|
| 1750 | if(lynq_start_rtp_thread(i)!= 0)
|
| 1751 | {
|
| 1752 | LYERRLOG("start rtp %d fail",i);
|
| 1753 | break;
|
| 1754 | }
|
| 1755 | else
|
| 1756 | {
|
| 1757 | LYINFLOG("start rtp %d suc",i);
|
| 1758 | }
|
| 1759 | }
|
| 1760 | else
|
| 1761 | {
|
| 1762 | LYERRLOG("rtp %d needn't start",i);
|
| 1763 | }
|
| 1764 | }
|
| 1765 | if(i!= RTP_MODE_MAX)
|
| 1766 | {
|
| 1767 | LYERRLOG("start rtp whole fail");
|
| 1768 | lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
|
| 1769 | return 1;
|
| 1770 | }
|
| 1771 | LYINFLOG("start rtp whole suc");
|
| 1772 | return 0;
|
| 1773 | }
|
| 1774 | else if(audio_mode==AUDIO_MODE_CODEC)
|
| 1775 | {
|
| 1776 | for(i=0;i<RTP_MODE_MAX;i++)
|
| 1777 | {
|
| 1778 | if(g_rtp_thread_valid[i])
|
| 1779 | {
|
| 1780 | ret = pthread_cancel(g_rtp_thread[i]);
|
| 1781 | LYINFLOG("pthread cancel rtp %d ret = %d",i,ret);
|
| 1782 | ret = pthread_join(g_rtp_thread[i],NULL);
|
| 1783 | LYINFLOG("pthread join rtp %d ret = %d",i,ret);
|
| 1784 | g_rtp_thread_valid[i] = 0;
|
| 1785 | }
|
| 1786 | else
|
| 1787 | {
|
| 1788 | LYINFLOG("rtp %d needn't stop",i);
|
| 1789 | }
|
| 1790 | }
|
| 1791 | lynq_set_rtp_mixer_ctrl(0);
|
| 1792 | LYINFLOG("stop rtp suc");
|
| 1793 | }
|
| 1794 | return 0;
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1795 | }
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1796 | int lynq_set_remote_rtp_ip(const char* ip, const int ip_length)
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1797 | {
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1798 | if (NULL == ip)
|
| 1799 | {
|
| 1800 | LYERRLOG("ip is NULL!!!");
|
| 1801 | return -1;
|
| 1802 | }
|
| 1803 | if ((ip_length < strlen(ip)+1) || (ip_length > MAX_IP_LENGTH))
|
| 1804 | {
|
| 1805 | LYERRLOG("incoming ip length error %d", ip_length);
|
| 1806 | return -1;
|
| 1807 | }
|
| 1808 |
|
| 1809 | bzero(g_rtp_server_info.ip,MAX_IP_LENGTH);
|
| 1810 | strcpy(g_rtp_server_info.ip,ip);
|
| 1811 |
|
| 1812 | LYINFLOG("lynq_set_remote_rtp_ip suc: ip is %s, length is %d", ip,ip_length);
|
| 1813 |
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1814 | return 0;
|
| 1815 | }
|
q.huang | 2d5b28c | 2022-06-06 20:23:15 +0800 | [diff] [blame] | 1816 | int lynq_set_rtp_port(const LYNQ_Rtp_Mode rtp_mode, const int port)
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1817 | {
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1818 | if (port < 0)
|
| 1819 | {
|
| 1820 | LYERRLOG("invalid port number %d", port);
|
| 1821 | return -1;
|
| 1822 | }
|
| 1823 | if (rtp_mode == 0)
|
| 1824 | {
|
| 1825 | g_rtp_client_info.port = port;
|
| 1826 | }
|
| 1827 | else if (rtp_mode == 1)
|
| 1828 | {
|
| 1829 | g_rtp_server_info.port = port;
|
| 1830 | }
|
| 1831 | LYINFLOG("lynq_set_rtp_port suc: LYNQ_Rtp_Mode is %d, port is %d", rtp_mode, port);
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1832 | return 0;
|
| 1833 | }
|
| 1834 | int lynq_set_rtp_param(const int clock_rate,const int channels,const int latency) //only for client mode
|
| 1835 | {
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1836 | g_rtp_client_info.clockrate = clock_rate;
|
| 1837 | g_rtp_client_info.channels = channels;
|
| 1838 | g_rtp_client_info.latency = latency;
|
| 1839 | LYINFLOG("lynq_set_rtp_param suc: clockrate is %d, channels is %d, latency is %d", clock_rate, channels, latency);
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1840 | return 0;
|
| 1841 | }
|
| 1842 | /*get*/
|
| 1843 | LYNQ_Audio_Mode lynq_get_voice_audio_mode()
|
| 1844 | {
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1845 | if(g_rtp_thread_valid[0])
|
| 1846 | {
|
| 1847 | return AUDIO_MODE_RTP;
|
| 1848 | }
|
| 1849 | else
|
| 1850 | {
|
| 1851 | return AUDIO_MODE_CODEC;
|
| 1852 | }
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1853 | }
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1854 | int lynq_get_remote_rtp_ip(char* ip, const int ip_length)
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1855 | {
|
| 1856 | if(ip==NULL)
|
| 1857 | {
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1858 | LYERRLOG("ip is NULL");
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1859 | return 1;
|
| 1860 | }
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1861 |
|
| 1862 | if(ip_length < strlen(g_rtp_server_info.ip)+1)
|
| 1863 | {
|
| 1864 | LYERRLOG("ip lenght %d is shorter than saved ip length %d",ip_length,strlen(g_rtp_server_info.ip)+1);
|
| 1865 | return 1;
|
| 1866 | }
|
| 1867 | bzero(ip,ip_length);
|
| 1868 | strcpy(ip,g_rtp_server_info.ip);
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1869 | return 0;
|
| 1870 | }
|
| 1871 | int lynq_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port)
|
| 1872 | {
|
| 1873 | if(port==NULL)
|
| 1874 | {
|
| 1875 | return 1;
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1876 | }
|
| 1877 | if (rtp_mode == 0)
|
| 1878 | {
|
| 1879 | *port = g_rtp_client_info.port;
|
| 1880 | }
|
| 1881 | else if (rtp_mode == 1)
|
| 1882 | {
|
| 1883 | *port = g_rtp_server_info.port;
|
| 1884 | }
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1885 | return 0;
|
| 1886 | }
|
| 1887 | int lynq_get_rtp_param(int* clock_rate, int* channels, int* latency)//only for client mode
|
| 1888 | {
|
| 1889 | if(clock_rate == NULL || channels ==NULL || latency ==NULL)
|
| 1890 | {
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1891 | LYERRLOG("input parameter is NULL");
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1892 | return 1;
|
| 1893 | }
|
| 1894 |
|
q.huang | cb7b729 | 2022-06-28 20:12:01 +0800 | [diff] [blame] | 1895 | *clock_rate = g_rtp_client_info.clockrate;
|
| 1896 | *channels = g_rtp_client_info.channels ;
|
| 1897 | *latency = g_rtp_client_info.latency;
|
| 1898 |
|
q.huang | 5ca6c07 | 2022-06-06 16:15:31 +0800 | [diff] [blame] | 1899 | return 0;
|
| 1900 | }
|
| 1901 | /*Audio Path setting end*/
|
| 1902 |
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1903 | #if 0
|
| 1904 | int main(int argc,char **argv)
|
| 1905 | {
|
| 1906 | int n = 0;
|
| 1907 | n = lynq_init_call(lynq_call_state_change_test,2222);
|
| 1908 | if(n<0)
|
| 1909 | {
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1910 | LYDBGLOG("lynq init call fail!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1911 | return -1;
|
| 1912 | }
|
q.huang | 70b7649 | 2022-06-02 14:49:02 +0800 | [diff] [blame] | 1913 | LYDBGLOG("lynq call init success!!!");
|
lh | 7b0674a | 2022-01-10 00:34:35 -0800 | [diff] [blame] | 1914 | char phoneNum[LYNQ_PHONE_NUMBER_MAX];
|
| 1915 | sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
|
| 1916 | lynq_call(phoneNum);
|
| 1917 | while(1)
|
| 1918 | {
|
| 1919 | sleep(1);
|
| 1920 | }
|
| 1921 | return 0;
|
| 1922 | }
|
| 1923 | #endif
|
| 1924 | /*Warren add for T800 platform 2021/11/19 end*/
|