[Feature][ZXW-10] support liblynq-call
Change-Id: I22af5b83e82b95efc09540751c33b4f6f7a19dec
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-call/liblynq-call.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-call/liblynq-call.bb
new file mode 100755
index 0000000..9ad8269
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-call/liblynq-call.bb
@@ -0,0 +1,49 @@
+inherit externalsrc package
+
+DESCRIPTION = "lynq call"
+LICENSE = "MobileTekProprietary"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=b1e07e8d88e26263e71d3a9e2aa9a2ff"
+DEPENDS += "libpal gstreamer1.0 glib-2.0 libapn liblynq-log libvendor-ril liblynq-shm libbinder"
+inherit workonsrc
+WORKONSRC = "${TOPDIR}/../src/lynq/lib/liblynq-call"
+
+TARGET_CC_ARCH += "${LDFLAGS}"
+BB_INCLUDE_ADD = "--sysroot=${STAGING_DIR_HOST}"
+BB_LDFLAGS_ADD = "--sysroot=${STAGING_DIR_HOST} -Wl,--hash-style=gnu"
+#Parameters passed to do_compile()
+EXTRA_OEMAKE = "'RAT_CONFIG_C2K_SUPPORT = ${RAT_CONFIG_C2K_SUPPORT}'\
+ 'MTK_MULTI_SIM_SUPPORT = ${MTK_MULTI_SIM_SUPPORT}'\
+ 'TARGET_PLATFORM = ${TARGET_PLATFORM}'"
+
+FILES_${PN} = "${base_libdir}/*.so \
+ ${base_bindir}\
+ ${base_sbindir} \
+ /etc/dbus-1/system.d/"
+FILES_${PN}-dev = "/test \
+ ${includedir}"
+FILES_${PN}-doc = "/doc"
+FILES_${PN}-dbg ="${base_bindir}/.debug \
+ ${base_libdir}/.debug \
+ ${base_sbindir}/.debug"
+INSANE_SKIP_${PN} += "already-stripped"
+INSANE_SKIP_${PN} += "installed-vs-shipped"
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+ if [ "${PACKAGE_ARCH}" = "cortexa7hf-vfp-vfpv4-neon" ]; then
+ oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -mfpu=neon-vfpv4 -mhard-float -Wl,--hash-style=gnu -DTELEPHONYWARE"
+ elif [ "${PACKAGE_ARCH}" = "cortexa7hf-neon-vfpv4" ]; then
+ oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -mfpu=neon-vfpv4 -mhard-float -Wl,--hash-style=gnu -DTELEPHONYWARE"
+ elif [ "${PACKAGE_ARCH}" = "cortexa53hf-neon-fp-armv8" ]; then
+ oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -mfpu=neon-vfpv4 -mhard-float -Wl,--hash-style=gnu -DTELEPHONYWARE -mhard-float -mfpu=neon-fp-armv8 -mfloat-abi=hard -mcpu=cortex-a53 -mtune=cortex-a53"
+ else
+ oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -Wl,--hash-style=gnu -DTELEPHONYWARE"
+ fi
+}
+
+do_install() {
+ oe_runmake install ROOT=${D}
+ if [ -d "${WORKONSRC}" ] ; then
+ install -d ${D}${includedir}
+ cp -af ${S}/include/libcall/ ${D}${includedir}/libcall
+ fi
+}
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/LICENSE b/cap/zx297520v3/src/lynq/lib/liblynq-call/LICENSE
new file mode 100755
index 0000000..605b7ea
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("MobileTek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to MobileTek Inc. and/or its licensors. Without
+the prior written permission of MobileTek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of MobileTek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+MobileTek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MobileTek SOFTWARE")
+RECEIVED FROM MobileTek AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. MobileTek EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES MobileTek PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE MobileTek SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MobileTek
+SOFTWARE. MobileTek SHALL ALSO NOT BE RESPONSIBLE FOR ANY MobileTek SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MobileTek'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MobileTek SOFTWARE
+RELEASED HEREUNDER WILL BE, AT MobileTek'S OPTION, TO REVISE OR REPLACE THE
+MobileTek SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO MobileTek FOR SUCH MobileTek SOFTWARE AT ISSUE.
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/include/libcall/lynq_call.h b/cap/zx297520v3/src/lynq/lib/liblynq-call/include/libcall/lynq_call.h
new file mode 100755
index 0000000..ec50ef7
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/include/libcall/lynq_call.h
@@ -0,0 +1,178 @@
+#ifndef LYNQ_CALL_H
+#define LYNQ_CALL_H 1
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define LYNQ_PHONE_NUMBER_MAX 32
+#define INDEX_IS_NUMBER( alpha_char ) \
+ ( ( (alpha_char >= '0') && (alpha_char <= '9') ) ? 1 : 0 )
+#define LYNQ_CALL_MAX 3
+#define LYNQ_CALL_FAIL_VENDOR_CAUSE 64
+#define MAX_IP_LENGTH 128
+#define MAX_VLAN_INFO_LENGTH 32
+#define MAX_SSRC_INFO_LENGTH 10 /*2^32=4294967296, 10 digit*/
+
+typedef enum {
+ LYNQ_CALL_FAIL_UNOBTAINABLE_NUMBER = 1,
+ LYNQ_CALL_FAIL_NORMAL = 16,
+ LYNQ_CALL_FAIL_BUSY = 17,
+ LYNQ_CALL_FAIL_CONGESTION = 34,
+ LYNQ_CALL_FAIL_ACM_LIMIT_EXCEEDED = 68,
+ LYNQ_CALL_FAIL_CALL_BARRED = 240,
+ LYNQ_CALL_FAIL_FDN_BLOCKED = 241,
+ LYNQ_CALL_FAIL_IMSI_UNKNOWN_IN_VLR = 242,
+ LYNQ_CALL_FAIL_IMEI_NOT_ACCEPTED = 243,
+ LYNQ_CALL_FAIL_DIAL_MODIFIED_TO_USSD = 244, /* STK Call Control */
+ LYNQ_CALL_FAIL_DIAL_MODIFIED_TO_SS = 245,
+ LYNQ_CALL_FAIL_DIAL_MODIFIED_TO_DIAL = 246,
+ LYNQ_CALL_FAIL_CDMA_LOCKED_UNTIL_POWER_CYCLE = 1000,
+ LYNQ_CALL_FAIL_CDMA_DROP = 1001,
+ LYNQ_CALL_FAIL_CDMA_INTERCEPT = 1002,
+ LYNQ_CALL_FAIL_CDMA_REORDER = 1003,
+ LYNQ_CALL_FAIL_CDMA_SO_REJECT = 1004,
+ LYNQ_CALL_FAIL_CDMA_RETRY_ORDER = 1005,
+ LYNQ_CALL_FAIL_CDMA_ACCESS_FAILURE = 1006,
+ LYNQ_CALL_FAIL_CDMA_PREEMPTED = 1007,
+ LYNQ_CALL_FAIL_CDMA_NOT_EMERGENCY = 1008, /* For non-emergency number dialed
+ during emergency callback mode */
+ LYNQ_CALL_FAIL_CDMA_ACCESS_BLOCKED = 1009, /* CDMA network access probes blocked */
+ LYNQ_CALL_FAIL_ERROR_UNSPECIFIED = 0xffff
+} lynq_last_call_fail_cause_t;
+typedef struct
+{
+ lynq_last_call_fail_cause_t cause_code;
+ char vendor_cause[LYNQ_CALL_FAIL_VENDOR_CAUSE];
+}lynqLastCallFailCause;
+int lynq_init_call(int uToken);
+int lynq_deinit_call();
+int lynq_call(int *handle,char addr[]);
+int lynq_call_answer();
+int lynq_call_hungup(int*handle);
+int lynq_call_hungup_all();
+int lynq_set_auto_answercall(const int mode);
+int lynq_get_mute_mic(int *status);
+int lynq_set_mute_mic(const int enable);
+int lynq_get_speech_volume(int *volume);
+int lynq_set_speech_volume(const int volume);
+int lynq_incall_record_start(const char* file_path);
+int lynq_incall_record_stop();
+int lynq_set_DTMF(const char callnum);
+int lynq_set_DTMF_volume(const int volume);
+int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[]);
+/*lei add for T8TSK-17 2022/7/20*/
+int lynq_switch_waiting_or_holding_and_active(void);
+int lynq_hangup_waiting_or_background(void);
+int lynq_hangup_foreground_resume_background(void);
+
+/*lei add for API-163/API-164 2023/1/3*/
+/**
+ * @brief wait_call_state_change
+ *
+ * @param handle call_id
+ * @return int
+ */
+int lynq_wait_call_state_change(int *handle);
+/*lei add for API-163/API-164 2023/1/3*/
+/*lei add for T8TSK-17 2022/7/20*/
+
+#ifdef ECALL_SUPPORT
+typedef enum{
+ LYNQ_ECALL_SET_NUMBER = 0, /* Set Number */
+ LYNQ_ECALL_SET_URI = 1, /* Set Uri */
+}LYNQ_ECall_Set_Type;
+
+typedef enum{
+ LYNQ_EMER_CAT_MANUAL_ECALL = 0, /* Manual Emergency eCall */
+ LYNQ_EMER_CAT_AUTO_ECALL = 1, /* Automatic Emergency eCall */
+}LYNQ_ECall_Category;
+
+typedef enum{
+ LYNQ_ECALL_TEST = 0, /* Test eCall */
+ LYNQ_ECALL_EMERGENCY = 1, /* Emergency eCall */
+ LYNQ_ECALL_RECONFIG = 2, /* Reconfiguration eCall */
+ LYNQ_ECALL_MO_MAX=3,
+ LYNQ_ECALL_CALLBACK = 3, /* Callback eCall */
+ LYNQ_ECALL_VAR_MAX,
+ LYNQ_ECALL_VAR_NONE=LYNQ_ECALL_VAR_MAX,
+}LYNQ_ECall_Variant;
+
+typedef enum{
+ LYNQ_ECALL_SENDING_START = 1,
+ LYNQ_ECALL_SENDING_MSD = 2,
+ LYNQ_ECALL_LLACK_RECEIVED = 3,
+ LYNQ_ECALL_ALACK_POSITIVE_RECEIVED = 4,
+ LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED = 5,
+ LYNQ_ECALL_DAILING = 9,
+ LYNQ_ECALL_ALERTING = 10,
+ LYNQ_ECALL_ACTIVE = 11,
+ LYNQ_ECALL_DISCONNECTED = 12,
+ LYNQ_ECALL_IMS_ACTIVE = 13,
+ LYNQ_ECALL_IMS_DISCONNECTED = 14,
+ LYNQ_ECALL_ABNORMAL_HANGUP=15,
+ LYNQ_ECALL_IMS_MSD_ACK = 20,
+ LYNQ_ECALL_IMS_UPDATE_MSD = 21,
+ LYNQ_ECALL_IMS_IN_BAND_TRANSFER = 22,
+ LYNQ_ECALL_IMS_MSD_NACK = 23,
+ LYNQ_ECALL_IMS_SRVCC = 24,
+ LYNQ_ECALL_ONLY_DEREGISTRATION = 31,
+ LYNQ_ECALL_MAY_DEREGISTER = 32,
+ LYNQ_ECALL_PSAP_CALLBACK_START = 40,
+ LYNQ_ECALL_PSAP_CALLBACK_IMS_UPDATE_MSD = 41,
+ LYNQ_ECALL_SENDING_START_IN_VOICE=8000,
+ LYNQ_ECALL_T2_TIMER_OUT = 9000,
+ LYNQ_ECALL_T5_TIMER_OUT = 9001,
+ LYNQ_ECALL_T6_TIMER_OUT = 9002,
+ LYNQ_ECALL_T7_TIMER_OUT = 9003,
+ LYNQ_ECALL_REDIAL_TIMER_OUT = 9004,
+ LYNQ_ECALL_AUTO_ANS_TIMER_OUT = 9005,
+ LYNQ_ECALL_AUTO_ANS_IMS_TIMER_OUT = 9006,
+ LYNQ_ECALL_UNSPECIFIED = 0xffff,
+}LYNQ_ECall_Indication;
+
+int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length);
+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);
+int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length);
+int lynq_set_ivs(int enable);
+int lynq_ivs_push_msd();
+int lynq_wait_ecall_indication(int* handle, LYNQ_ECall_Indication *eCall_Indication);
+#endif
+
+/*Audio Path setting begin*/
+typedef enum{
+ AUDIO_MODE_CODEC = 0, /* Codec */
+ AUDIO_MODE_RTP = 1, /* RTP */
+}LYNQ_Audio_Mode;
+
+typedef enum{
+ RTP_CLIENT = 0,
+ RTP_SERVER =1,
+ RTP_MODE_MAX
+}LYNQ_Rtp_Mode;
+
+typedef enum{
+ Rtp_Ssrc_random = 0,
+ Rtp_Ssrc_specific =1,
+}LYNQ_Rtp_Ssrc_Mode;
+
+/*set*/
+int lynq_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode);
+int lynq_set_remote_rtp_ip(const char* ip, const int ip_length);
+int lynq_set_vlan_info(const char* vlan_info, const int vlan_info_length);
+int lynq_set_rtp_port(const LYNQ_Rtp_Mode rtp_mode, const int port);
+int lynq_set_rtp_param(const int clock_rate,const int channels,const int latency); //only for client
+int lynq_set_call_rtp_ssrc(const LYNQ_Rtp_Ssrc_Mode ssrc_mode, const unsigned int ssrc);
+
+/*get*/
+LYNQ_Audio_Mode lynq_get_voice_audio_mode();
+int lynq_get_remote_rtp_ip(char* ip, const int ip_length);
+int lynq_get_vlan_info(char* vlan_info, const int vlan_info_length);
+int lynq_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port);
+int lynq_get_rtp_param(int* clock_rate,int* channels, int* latency);//only for client
+int lynq_get_call_rtp_ssrc(int* ssrc_mod, unsigned int* ssrc);
+/*Audio Path setting end*/
+
+void lynq_set_test_mode(const int test_mode);
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call.cpp
new file mode 100755
index 0000000..d1e2293
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call.cpp
@@ -0,0 +1,1517 @@
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <binder/Parcel.h>
+#include <log/log.h>
+#include <cutils/jstring.h>
+#include <pthread.h>
+#include "liblog/lynq_deflog.h"
+#include <sys/time.h>
+#include <string.h>
+#include <vendor-ril/telephony/ril.h>
+#include <vendor-ril/telephony/mtk_ril_sp.h>
+#include <vendor-ril/telephony/mtk_ril_ivt.h>
+#include "lynq_call.h"
+#include "lynq_module_common.h"
+#include "lynq_module_socket.h"
+#include "lynq_call_common.h"
+
+#define CALL_OFF (0)
+#define CALL_ON (1)
+#define USER_LOG_TAG "LYNQ_CALL"
+
+using ::android::Parcel;
+
+/**
+ * @brief mark call initialization state
+ * 0: deinit state
+ * 1: init state
+ */
+int g_module_init_flag = 0;
+
+ typedef enum {
+ LYNQ_CALL_ACTIVE = 0,
+ LYNQ_CALL_HOLDING = 1,
+ LYNQ_CALL_DIALING = 2, /* MO call only */
+ LYNQ_CALL_ALERTING = 3, /* MO call only */
+ LYNQ_CALL_INCOMING = 4, /* MT call only */
+ LYNQ_CALL_WAITING = 5, /* MT call only */
+ /*warren add for T800 platform 2022/04/26 start*/
+ LYNQ_CALL_END = 6, /*CALL END*/
+ /*warren add for T800 platform 2022/04/26 end*/
+}lynq_call_state_t;
+
+typedef struct
+{
+ int used;
+ int call_id;
+ int call_state;
+ int toa;
+ int direction;/*0: MO call,1:MT call*/
+ char addr[LYNQ_PHONE_NUMBER_MAX];
+}lynq_call_list_e_t;
+typedef struct
+{
+ int call_id;
+ int call_state;
+ int toa;
+ int direction;/*0: MO call,1:MT call*/
+ char addr[LYNQ_PHONE_NUMBER_MAX];
+}lynq_call_list_t;
+
+static lynq_call_list_e_t s_call_lists[LYNQ_CALL_MAX]={};
+static bool s_call_list_loop = 0;
+static pthread_t s_call_list_loop_tid = -1;
+static pthread_mutex_t s_notice_get_call_list_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t s_notice_get_call_list_cond = PTHREAD_COND_INITIALIZER;
+
+static int s_module_isDial = 0;
+static pthread_mutex_t call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t call_state_change_cond = PTHREAD_COND_INITIALIZER;
+static int s_CallId = 0;
+static pthread_mutex_t s_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t s_call_state_change_cond = PTHREAD_COND_INITIALIZER;
+
+static int s_module_call_state =CALL_OFF;
+static int s_call_auto_answer = 0;
+
+typedef enum{
+ LYNQ_E_VOLUMN_SET_DTMF,
+ LYNQ_E_VOLUMN_SET_SPEECH
+}LYNQ_E_VOLUMN_SET;
+
+#if 0
+int JumpHeader(Parcel &p,int *resp_type,int* token,int *request,int *slot_id,int *error)
+{
+ if(p.dataAvail() > 0)
+ {
+ p.readInt32(resp_type);
+ p.readInt32(token);
+ p.readInt32(request);
+ p.readInt32(slot_id);
+ p.readInt32(error);
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+}
+int send_request(int sockfd,lynq_client_t *client_tmp)
+{
+ int ret=0;
+ ret = sendto(sockfd, client_tmp, client_size, 0, (struct sockaddr *)&addr_serv, len_addr_serv);
+ if(ret==-1)
+ {
+ LYERRLOG("sendto error");
+ return -1;
+ }
+ return 0;
+}
+
+int get_response(int sockfd,Parcel &p)
+{
+ int len = 0;
+ char recvline[LYNQ_REC_BUF];
+ bzero(recvline,LYNQ_REC_BUF);
+ /* receive data from server */
+ len = recvfrom(sockfd,recvline,LYNQ_REC_BUF, 0, (struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);
+ if(len == -1)
+ {
+ LYERRLOG("recvfrom error");
+ return -1;
+ }
+ if (recvline != NULL) {
+ p.setData((uint8_t *)recvline,len); // p.setData((uint8_t *) buffer, buflen);
+ p.setDataPosition(0);
+ }
+ return 0;
+}
+#endif
+static char *strdupReadString(Parcel* &p) {
+ size_t stringlen;
+ const char16_t *s16;
+ s16 = p->readString16Inplace(&stringlen);
+ return strndup16to8(s16, stringlen);
+}
+
+int lynq_get_current_call_list(lynq_call_list_t call_list[LYNQ_CALL_MAX])
+{
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,8,RIL_REQUEST_GET_CURRENT_CALLS,0,"");
+ if(ret!=0)
+ {
+ return ret;
+ }
+
+ int call_num = 0;
+ int temp = 0;
+ char *remote_phoneNum;
+ char *remote_name;
+ char uusData[128];
+
+ p->readInt32(&call_num);
+
+ if(call_num<=0)
+ {
+ s_module_call_state = CALL_OFF;
+ LYINFLOG("lynq_call_state:%d",s_module_call_state);
+ delete p;
+ return RESULT_OK;
+ }
+ s_module_call_state = CALL_ON;
+ LYINFLOG("lynq_call_state:%d, call num is %d ",s_module_call_state,call_num);
+ for(int i = 0;i < call_num;i++)
+ {
+ p->readInt32(&temp);
+ call_list[i].call_state = temp;
+ p->readInt32(&call_list[i].call_id);
+ p->readInt32(&call_list[i].toa);
+ p->readInt32(&temp);
+ p->readInt32(&temp);
+ call_list[i].direction = temp;
+ p->readInt32(&temp);
+ p->readInt32(&temp);
+ p->readInt32(&temp);
+ remote_phoneNum = strdupReadString(p);
+ memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
+ if(remote_phoneNum !=NULL)
+ {
+ free(remote_phoneNum);
+ }
+ LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
+ call_list[i].direction,call_list[i].addr,call_list[i].toa);
+ p->readInt32(&temp);
+ remote_name = strdupReadString(p);
+ if(remote_name !=NULL)
+ {
+ free(remote_name);
+ }
+ p->readInt32(&temp);
+ p->readInt32(&temp);
+ if(temp==0)
+ {
+ continue;
+ }
+ p->readInt32(&temp); /* UUS Information is present */
+ p->readInt32(&temp);
+ p->readInt32(&temp);
+ if(temp<=128)
+ {
+ p->read(uusData,temp);
+ }
+ else
+ {
+ LYERRLOG("%s len %d is too great",__func__,temp);
+ delete p;
+ return LYNQ_E_MALLOC_ERROR;
+ }
+ }
+
+ delete p;
+ return RESULT_OK;
+
+#if 0
+ Parcel p;
+ lynq_client_t client;
+ int resp_type = -1;
+ int token;
+ int request = -1;
+ int slot_id = -1;
+ int error = -1;
+ int call_num = 0;
+ int temp = 0;
+ char *remote_phoneNum = NULL;
+ char *remote_name= NULL;
+ char *uusData = NULL;
+ client.uToken = Global_uToken_call;
+ client.request = 9;//RIL_REQUEST_GET_CURRENT_CALLS
+ client.paramLen = 0;
+ bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
+ LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
+ if(send_request(lynq_call_client_sockfd,&client)==-1)
+ {
+ LYERRLOG("send request fail");
+ return -1;
+ }
+ get_response(lynq_call_client_sockfd,p);
+ JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
+ LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
+ if(error == 0)
+ {
+ p.readInt32(&call_num);
+ global_call_count = call_num;
+ if(call_num<=0)
+ {
+ lynq_call_state = CALL_OFF;
+ LYINFLOG("lynq_call_state:%d",lynq_call_state);
+ return 0;
+ }
+ lynq_call_state = CALL_ON;
+ LYINFLOG("lynq_call_state:%d, call num is %d ",lynq_call_state,call_num);
+ for(int i = 0;i < call_num;i++)
+ {
+ p.readInt32(&temp);
+ call_list[i].call_state = temp;
+ p.readInt32(&call_list[i].call_id);
+ p.readInt32(&call_list[i].toa);
+ p.readInt32(&temp);
+ p.readInt32(&temp);
+ call_list[i].direction = temp;
+ p.readInt32(&temp);
+ p.readInt32(&temp);
+ p.readInt32(&temp);
+ remote_phoneNum = strdupReadString(p);
+ memcpy(call_list[i].addr,remote_phoneNum,strlen(remote_phoneNum));
+ LYINFLOG("call_id=%d,call_state=%d,direction=%d,addr=%s,toa=%d",call_list[i].call_id,call_list[i].call_state,
+ call_list[i].direction,call_list[i].addr,call_list[i].toa);
+ p.readInt32(&temp);
+ remote_name = strdupReadString(p);
+ p.readInt32(&temp);
+ p.readInt32(&temp);
+ if(temp==0)
+ {
+ continue;
+ }
+ p.readInt32(&temp); /* UUS Information is present */
+ p.readInt32(&temp);
+ p.readInt32(&temp);
+ p.read(uusData,temp);
+ }
+ }
+ return 0;
+#endif
+}
+
+void cleanCallList(int lynq_call_id)
+{
+ LYINFLOG("cleanCall local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
+ s_call_lists[lynq_call_id].call_id = 0;
+ s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
+ s_call_lists[lynq_call_id].toa = 0;
+ s_call_lists[lynq_call_id].direction = 0;
+ s_call_lists[lynq_call_id].used = 0;
+ memset(s_call_lists[lynq_call_id].addr,0,sizeof(s_call_lists[lynq_call_id].addr));
+}
+
+
+int getUnusedElement()
+{
+ for(int i=0;i < LYNQ_CALL_MAX; i++)
+ {
+ if(s_call_lists[i].used!=1)
+ {
+ return i;
+ }
+ }
+ return INVALID_ID;
+}
+int addAddr(char addr[], int call_id)
+{
+ int ret = 0;
+ ret = getUnusedElement();
+ memcpy(s_call_lists[ret].addr,addr,strlen(addr)+1);
+ s_call_lists[ret].call_id=call_id;
+ s_call_lists[ret].used = 1;
+ LYINFLOG("add local idx is %d addr is %s",ret,addr);
+ return ret;
+}
+void updateCallList(lynq_call_list_e_t *callList, int call_id,int call_state,int toa,int direction)
+{
+ LYINFLOG("Update original local id is %d, new local id is %d",callList->call_id,call_id);
+ callList->call_id = call_id;
+ callList->call_state = call_state;
+ callList->toa = toa;
+ callList->direction = direction;
+ return;
+}
+
+void wait_call_state()
+{
+ LYINFLOG("call state changed");
+ pthread_mutex_lock(&s_call_state_change_mutex);
+ pthread_cond_wait(&s_call_state_change_cond,&s_call_state_change_mutex);
+ pthread_mutex_unlock(&s_call_state_change_mutex);
+}
+
+int checkHasCall(char addr[])
+{
+ for(int i = 0;i<LYNQ_CALL_MAX;i++)
+ {
+ if(strcmp(s_call_lists[i].addr,addr)==0)
+ {
+ LYINFLOG("checkHasCall addr is %s idx is %d id is %d",addr,i,s_call_lists[i].call_id);
+ return true;
+ }
+ }
+ LYINFLOG("checkHasCall addr is %s , no idx is found",addr);
+ return false;
+}
+int find_call_id_with_addr(char *addr)
+{
+ for(int id = 0; id < LYNQ_CALL_MAX; id++)
+ {
+ if(s_call_lists[id].used && (strcmp(s_call_lists[id].addr,addr) == 0))
+ {
+ LYINFLOG("find addr %s in local list, local idx is %d id is %d",addr,id,s_call_lists[id].call_id);
+ return id;
+ }
+ }
+ LYINFLOG("find addr %s in local list , not found",addr);
+ return INVALID_ID;
+}
+int find_call_id_with_call_id(int call_id)
+{
+ for(int id = 0; id < LYNQ_CALL_MAX; id++)
+ {
+ if(s_call_lists[id].used && (s_call_lists[id].call_id == call_id))
+ {
+ LYINFLOG("find id %d in local list, local idx is %d, addr is %s",call_id,id,s_call_lists[id].addr);
+ return id;
+ }
+ }
+ LYINFLOG("find id %d in local list , not found",call_id);
+ return INVALID_ID;
+}
+void sendSignalToWaitCallStateChange()
+{
+ LYINFLOG("send Signal To Wait Call State Change");
+ pthread_mutex_lock(&call_state_change_mutex);
+ pthread_cond_signal(&call_state_change_cond);
+ pthread_mutex_unlock(&call_state_change_mutex);
+}
+void send_call_state_change()
+{
+ LYINFLOG("send call state change");
+ pthread_mutex_lock(&s_call_state_change_mutex);
+ pthread_cond_signal(&s_call_state_change_cond);
+ pthread_mutex_unlock(&s_call_state_change_mutex);
+}
+
+void cleanup_call_list_mutex(void *arg)
+{
+ pthread_mutex_unlock(&s_notice_get_call_list_mutex);
+}
+
+void update_end_state(int lynq_call_id)
+{
+ LYINFLOG("update_end_state local idx is %d, id is %d",lynq_call_id,s_call_lists[lynq_call_id].call_id);
+ s_call_lists[lynq_call_id].call_state = (int)LYNQ_CALL_END;
+}
+
+void *triggerGetCallList(void *parg)
+{
+ int ret=0;
+ bool call_end;
+ lynq_call_list_t call_list[LYNQ_CALL_MAX];
+ int update=0;
+ int cnt;
+ int i,n;
+#ifdef ECALL_SUPPORT
+ int handupIncomingMT=0;
+#endif
+ pthread_mutex_lock(&s_notice_get_call_list_mutex);
+ pthread_cleanup_push(cleanup_call_list_mutex, NULL); // thread cleanup handler
+ while(s_call_list_loop)
+ {
+ update=0;
+ pthread_cond_wait(&s_notice_get_call_list_cond, &s_notice_get_call_list_mutex);
+ LYDBGLOG("triggerGetCallList event!!!");
+ memset(call_list,0,sizeof(call_list));
+ ret = lynq_get_current_call_list(call_list);
+ if(ret != RESULT_OK)
+ {
+ LYDBGLOG("get current call list failure!!!");
+ continue;
+ }
+ LYINFLOG("++++++++++++++triggerGetCallList++++++++++++++");
+ LYINFLOG("clear local index begin");
+ cnt=0;
+ for(i = 0;i < LYNQ_CALL_MAX;i++)
+ {
+ if(s_call_lists[i].used ==0)
+ {
+ continue;
+ }
+ cnt++;
+ LYINFLOG("local idx is %d id is %d addr is %s state is %d direction is %d",i,s_call_lists[i].call_id,s_call_lists[i].addr,s_call_lists[i].call_state,s_call_lists[i].direction);
+
+ if(s_call_lists[i].call_id > 0)
+ {
+ call_end = 0;
+ for(n = 0; n < LYNQ_CALL_MAX; n++)
+ {
+ if(call_list[n].call_id == s_call_lists[i].call_id)
+ {
+ call_end = 1;
+ LYINFLOG("find lynq call local idx %d, service idx %d id is %d!!!",i,n,s_call_lists[i].call_id);
+ break;
+ }
+ }
+ if(call_end == 0)
+ {
+ LYINFLOG("MT/MO hungup,then clean call info local idx is %d id is %d",i, s_call_lists[i].call_id);
+ //update_end_state(i);//lei modify for:update end state for this call
+ cleanCallList(i);
+ send_call_state_change();//means mt/mo call is end
+ //cleanCallList(i);
+ }
+ } //fix bug API-54
+ else
+ {
+ LYINFLOG("local id is 0");
+ }
+ }
+ LYINFLOG("clear local index end, local used cnt is %d", cnt);
+
+ LYINFLOG("add or update local index begin ");
+ for (i = 0;i < LYNQ_CALL_MAX;i++)
+ {
+ if(call_list[i].call_id==0)
+ {
+ break;
+ }
+
+ 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,
+ call_list[i].direction,call_list[i].addr,call_list[i].toa);
+
+ if(call_list[i].direction == 1)//MT call
+ {
+ LYINFLOG("This is a MT CALL");
+ /*MT CALL state code
+ **LYNQ_CALL_INCOMING = 4,
+ **LYNQ_CALL_WAITING = 5,
+ */
+#ifdef ECALL_SUPPORT
+ if((call_list[i].call_state ==4) || (call_list[i].call_state ==5))
+ {
+ handupIncomingMT=Is_handup_IncomingMT(call_list[i].call_id);
+ LYINFLOG("handupIncomingMT is %d",handupIncomingMT);
+ if(handupIncomingMT)
+ {
+ lynq_call_hungup(&(call_list[i].call_id));
+ continue;
+ }
+ }
+#endif
+ /*you call me, and i call you,One party failed to dial*/
+ n = find_call_id_with_addr(call_list[i].addr);
+ if(n ==INVALID_ID)
+ {
+ n = addAddr(call_list[i].addr,call_list[i].call_id);
+ updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
+ s_CallId = call_list[i].call_id;
+ send_call_state_change();
+ }
+ else if(s_call_lists[n].call_state == call_list[i].call_state)
+ {
+ LYINFLOG("state not changed, state is %d ",call_list[i].call_state);
+ if(call_list[i].call_state ==4 || call_list[i].call_state ==5)
+ {
+ /*if call state not change,Maybe this call was ignored, so we need to continue to inform the user of
+ **an incoming call until the status changes.
+ **fix bug API-54
+ */
+ LYINFLOG("resend incoming call signal");
+ send_call_state_change();
+ }
+ }
+ else
+ {
+ LYINFLOG("state changed from %d to %d",s_call_lists[n].call_state,call_list[i].call_state);
+
+ updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);//update mt call
+ send_call_state_change();
+ }
+ }
+ else
+ {
+ LYINFLOG("This is a MO CALL");
+ call_end = 0;
+ for(n = 0 ; n < LYNQ_CALL_MAX; n++)
+ {
+ if(s_call_lists[n].used && ((strcmp(call_list[i].addr,s_call_lists[n].addr)==0)||(call_list[i].call_id==s_call_lists[n].call_id)))
+ {
+ if(s_call_lists[n].call_id==0)
+ {
+ LYINFLOG("add a call id");
+ update=1;//for send sigal
+ s_CallId = call_list[i].call_id;
+ }
+ LYINFLOG("local idx %d updated, original call id is %d origial addr is %s original state is %d",n,s_call_lists[n].call_id,s_call_lists[n].addr,s_call_lists[n].call_state);
+ updateCallList(&s_call_lists[n],call_list[i].call_id,call_list[i].call_state,call_list[i].toa,call_list[i].direction);
+ call_end = 1;
+ send_call_state_change();//means mo call is success
+ break;
+ }
+ }
+ if(call_end == 0)//1.there is no space to use 2.can't find addr in buffer 3.call_id not equal eg:when call is error return 8004/handle <= 0 will into this
+ {
+ LYINFLOG("need to hangup id %d", call_list[i].call_id);
+#ifdef ECALL_SUPPORT
+ if(IsECallDialing())
+ {
+ LYINFLOG("ecall is dialing, for the timebeing, don't huangup");
+ continue;
+ }
+#endif
+ LYINFLOG("hang up service call id %d",call_list[i].call_id);
+ lynq_call_hungup(&(call_list[i].call_id));
+ }
+
+ }
+ LYDBGLOG("servie idx %d end",i);
+ }
+ LYINFLOG("add or update local index end ");
+ if(s_module_isDial==1)
+ {
+ LYINFLOG("now is dialing");
+ if(update==1)
+ {
+ LYINFLOG("find added call");
+ sendSignalToWaitCallStateChange();
+ s_module_isDial = 0;
+ }
+ else
+ {
+ LYINFLOG("not find added call");
+ }
+ }
+ else
+ {
+ LYINFLOG("now is not dialing");
+ }
+ }
+ pthread_cleanup_pop(0);
+ pthread_mutex_unlock(&s_notice_get_call_list_mutex);
+ return NULL;
+}
+
+void lynqNoticeGetModuleCallList()
+{
+ pthread_mutex_lock(&s_notice_get_call_list_mutex);
+ pthread_cond_signal(&s_notice_get_call_list_cond);
+ pthread_mutex_unlock(&s_notice_get_call_list_mutex);
+
+}
+
+#if 0
+/*Warren add for T800 platform 2021/11/19 start*/
+int lynq_socket_client_start()
+{
+ #if 0
+ struct sockaddr_in lynq_socket_server_addr;
+ /* init lynq_socket_server_addr */
+ bzero(&lynq_socket_server_addr, sizeof(lynq_socket_server_addr));
+ lynq_socket_server_addr.sin_family = AF_INET;
+ lynq_socket_server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
+ lynq_socket_server_addr.sin_addr.s_addr = htons(INADDR_ANY);
+
+ /*
+ if(inet_pton(AF_INET,"127.0.0.1", &lynq_socket_server_addr.sin_addr) <= 0)
+ {
+ LYDBGLOG("[%s] is not a valid IPaddress", argv[1]);
+ exit(1);
+ }
+*/
+ lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if(connect(lynq_call_client_sockfd, (struct sockaddr *)&lynq_socket_server_addr, sizeof(lynq_socket_server_addr)) == -1)
+ {
+ LYERRLOG("connect error");
+ return -1;
+ }
+ #endif
+ lynq_call_client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (-1 == lynq_call_client_sockfd)
+ {
+ return lynq_call_client_sockfd;
+ }
+ struct timeval timeOut;
+ timeOut.tv_sec = 60;
+ timeOut.tv_usec = 0;
+ if (setsockopt(lynq_call_client_sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeOut, sizeof(timeOut)) < 0)
+ {
+ RLOGD("time out setting failed\n");
+ return -1;
+ }
+ /* 设置address */
+ memset(&addr_serv, 0, sizeof(addr_serv));
+ addr_serv.sin_family = AF_INET;
+ addr_serv.sin_addr.s_addr = inet_addr(DSET_IP_ADDRESS);
+ addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
+ len_addr_serv = sizeof(addr_serv);
+ return 0;
+}
+
+int lynq_socket_urc_start()
+{
+ int socket_fd=0;
+ int rt=0;
+ int len=0;
+ int on=1;
+ struct sockaddr_in urc_local_addr;
+ pthread_attr_t attr;
+ socket_fd = socket(AF_INET,SOCK_DGRAM,0);
+ if(socket_fd < 0)
+ {
+ LYERRLOG("creaet socket for udp fail");
+ return -1;
+ }
+ urc_local_addr.sin_family = AF_INET;
+ urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
+ urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
+ /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
+ rt = setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
+ if(rt<0)
+ {
+ LYERRLOG("SO_REUSEADDR fail");
+ return -1;
+ }
+ rt = bind(socket_fd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
+ if (rt == -1)
+ {
+ LYERRLOG("bind failed");
+ return -1;
+ }
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ rt = pthread_create(&lynq_call_urc_tid,&attr,thread_urc_recv,(void *)socket_fd);
+ if(rt < 0)
+ {
+ LYERRLOG("urc loop failure!!!");
+ return -1;
+ }
+ LYDBGLOG("urc loop success!!!");
+ return 0;
+}
+#endif
+
+void lynq_call_state_change_test(int soc_id)
+{
+ LYDBGLOG("call state change,sim:%d",soc_id);
+}
+
+int lynq_start_call_list_loop()
+{
+#if 0
+ int ret = 0;
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ s_notice_get_call_list_mutex = new pthread_mutex_t;
+ pthread_mutex_init(s_notice_get_call_list_mutex, NULL);
+ s_notice_get_call_list_cond = new pthread_cond_t;
+ LYINFLOG("liulei s_notice_get_call_list_mutex\n");
+ pthread_cond_init(s_notice_get_call_list_cond, NULL);
+ LYINFLOG("liulei s_notice_get_call_list_cond\n");
+#endif
+
+ s_call_list_loop = 1;
+ int ret = pthread_create(&s_call_list_loop_tid,/*&attr*/NULL,triggerGetCallList,NULL);
+ if(ret < 0)
+ {
+ LYERRLOG("lynq_update_call_list_loop fail!!!");
+ return -1;
+ }
+ LYINFLOG("lynq_update_call_list_loop success!!!");
+
+ memset(s_call_lists,0,sizeof(s_call_lists));
+ return 0;
+}
+
+int lynq_stop_call_list_loop()
+{
+ int ret;
+ pthread_mutex_lock(&s_notice_get_call_list_mutex);
+ s_call_list_loop = 0;
+ ret = pthread_cancel(s_call_list_loop_tid);
+ LYINFLOG("pthread cancel w_c_list ret = %d",ret);
+ pthread_mutex_unlock(&s_notice_get_call_list_mutex);
+ ret = pthread_join(s_call_list_loop_tid,NULL);
+ LYINFLOG("pthread join w_c_list ret = %d",ret);
+ s_call_list_loop_tid=-1;
+#if 0
+ pthread_mutex_destroy(s_notice_get_call_list_mutex);
+ pthread_cond_destroy(s_notice_get_call_list_cond);
+ delete s_notice_get_call_list_mutex;
+ //s_notice_get_call_list_mutex = NULL;
+ delete s_notice_get_call_list_cond;
+ //s_notice_get_call_list_cond = NULL;
+#endif
+
+ return 0;
+}
+
+int lynq_init_call(int utoken){
+ if(g_module_init_flag != MODULE_CLOSED)
+ {
+ LYERRLOG("module state is %d",g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ if(utoken <0){
+ LYERRLOG("utoken is less than 0",utoken);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+ g_module_init_flag = MODULE_SWITCHING;
+
+ LYLOGSET(LOG_INFO);
+ LYLOGEINIT(USER_LOG_TAG);
+
+ g_module_Global_uToken = utoken;
+
+ int ret = lynq_start_all_urc_socket_thread();
+ if(ret != RESULT_OK)
+ {
+ LYERRLOG("init socket urc fail!!!");
+ g_module_init_flag = MODULE_CLOSED;
+ return LYNQ_E_INNER_ERROR;
+ }
+
+ ret = lynq_start_all_rc_socket_thread();
+ if(ret !=RESULT_OK)
+ {
+ LYERRLOG("init socket client fail!!!");
+ lynq_close_all_urc_socket_thread();
+ g_module_init_flag = MODULE_CLOSED;
+ return LYNQ_E_INNER_ERROR;
+ }
+
+
+ int result = lynq_start_call_list_loop();
+ if(ret != RESULT_OK)
+ {
+ LYERRLOG("lynq_start_call_list_loop fail!!!");
+ lynq_close_all_urc_socket_thread();
+ lynq_close_all_rc_socket_thread();
+ g_module_init_flag = MODULE_CLOSED;
+ return LYNQ_E_INNER_ERROR;
+ }
+
+ lynq_init_rtp();
+
+ g_module_init_flag = MODULE_RUNNING;
+ return 0;
+}
+
+int lynq_deinit_call(void){
+
+ if (g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("module state is %d",g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ lynq_call_hungup_all();
+ lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
+ g_module_init_flag = MODULE_SWITCHING;
+ lynq_close_all_urc_socket_thread();
+ lynq_close_all_rc_socket_thread();
+ lynq_stop_call_list_loop();
+ g_module_init_flag = MODULE_CLOSED;
+ return 0;
+}
+
+#if 0
+int lynq_set_common_request(int request_id, int argc, const char* format,...)
+{
+ Parcel p;
+ lynq_client_t client;
+ int resp_type = -1;
+ int token;
+ int request = -1;
+ int slot_id = -1;
+ int error = -1;
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(request_id,5,p,argc,format,...);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+
+ client.uToken = Global_uToken_call;
+ client.request = request_id;
+ client.paramLen = argc;
+ bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
+ if(argc!=0)
+ {
+ va_list args;
+ va_start(args, format);
+ vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
+ va_end(args);
+ }
+ LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
+ if(send_request(lynq_call_client_sockfd,&client)==-1)
+ {
+ LYERRLOG("send request fail");
+ return -1;
+ }
+ if(get_response(lynq_call_client_sockfd,p)==0)
+ {
+ JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
+ LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
+ }
+ return error;
+
+
+}
+#endif
+
+int lynq_get_common_request(int request_id, int* status)
+{
+ if(status==NULL)
+ {
+ LYERRLOG("status is null");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,request_id,0,"");
+ if(ret==RESULT_OK)
+ {
+ p->readInt32(status);
+ delete p;
+ }
+ return ret;
+}
+
+int waitCallstateChange(int mtime)
+{
+ LYINFLOG("wait Call state Change");
+ int ret = 0;
+ int sec = 0;
+ int usec = 0;
+ struct timeval now;
+ struct timespec timeout;
+ gettimeofday(&now,NULL);
+ sec = mtime/1000;
+ usec = mtime%1000;
+ timeout.tv_sec = now.tv_sec+sec;
+ timeout.tv_nsec = now.tv_usec*1000+usec*1000000;
+ pthread_mutex_lock(&call_state_change_mutex);
+ ret = pthread_cond_timedwait(&call_state_change_cond,&call_state_change_mutex,&timeout);
+ pthread_mutex_unlock(&call_state_change_mutex);
+ return ret;
+}
+
+int IsNormalCallDailing()
+{
+ return s_module_isDial;
+}
+
+
+int lynq_call(int* handle,char addr[])
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+
+ int lynq_call_id = -1;
+
+ LYINFLOG("lynq_call begin addr %s",addr);
+ if(addr==NULL)
+ {
+ LYERRLOG("Phone num is null!!!");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ if(find_call_id_with_addr(addr)!=INVALID_ID)
+ {
+ LYERRLOG("addr %s exists",addr);
+ return LYNQ_E_CONFLICT;
+ }
+
+#ifdef ECALL_SUPPORT
+ if(lynq_ecall_is_running())
+ {
+ LYERRLOG("lynq_fast_ecall ecall is running");
+ return LYNQ_E_ECALL_BEING_RUNNING;
+ }
+#endif
+ Parcel* p=NULL;
+ lynq_call_id = addAddr(addr,0);
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DIAL,2,"%s %d",addr, 0);
+ if(ret!=0)
+ {
+ cleanCallList(lynq_call_id);
+ return ret;
+ }
+ delete p;
+ s_module_isDial = 1;
+ if(waitCallstateChange(6000)==ETIMEDOUT)//6000ms
+ {
+ //if timeout,this call need destroy.
+ s_module_isDial = 0;
+ LYERRLOG("lynq_call timeout:wait Call state fail!!! clear local idx %d",lynq_call_id);
+ cleanCallList(lynq_call_id);
+ send_call_state_change();
+ return LYNQ_E_TIME_OUT;
+ }
+ s_module_isDial = 0;
+ *handle = s_call_lists[lynq_call_id].call_id;
+ if(*handle > 0)
+ {
+ LYINFLOG("lynq_call dial addr %s suc, id is %d",addr,*handle);
+ return RESULT_OK;
+ }
+ else
+ {
+ LYERRLOG("lynq_call dial addr %s fail, invalid id",addr);
+ cleanCallList(lynq_call_id);
+ send_call_state_change();
+ return LYNQ_E_INVALID_ID_ANONALY;
+ }
+}
+
+int lynq_call_answer()
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ANSWER,0,"");
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+
+int lynq_call_hungup(int* handle)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ return LYNQ_E_CONFLICT;
+ }
+
+ if(handle==NULL||!((*handle>=0)&&(*handle<10)))
+ {
+ LYERRLOG("%s illegal input!!!!",__func__);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ int call_id = *handle;
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP,1,"%d",call_id);
+ if(ret!=0)
+ {
+ return ret;
+ }
+ delete p;
+
+ int lynq_call_id=find_call_id_with_call_id(call_id);
+ if(lynq_call_id!=INVALID_ID)
+ {
+ cleanCallList(lynq_call_id);
+ }
+
+ return RESULT_OK;
+}
+int lynq_call_hungup_all()
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_UDUB,0,"");
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+
+int lynq_wait_call_state_change(int *handle)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ wait_call_state();
+ *handle = s_CallId;
+ LYINFLOG("lynq mo/mt call id:%d",s_CallId);
+ return RESULT_OK;
+}
+
+int lynq_set_auto_answercall(const int mode)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ s_call_auto_answer = mode;
+ LYINFLOG("auto answer call mode =%d",mode);
+ return RESULT_OK;
+}
+
+int lynq_find_already_end()
+{
+ for(int i=0;i < LYNQ_CALL_MAX; i++)
+ {
+ if(s_call_lists[i].call_state == 6)
+ {
+ return 0;
+ }
+ }
+ return INVALID_ID;
+}
+
+int lynq_get_current_call_state(int *handle, int *call_state,int *toa,int *direction,char addr[])
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ int lynq_call_id = 0;
+ LYINFLOG("lynq_get_current_call_state begin ");
+ if(handle==NULL)
+ {
+ LYERRLOG("handle is NULL");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+ LYINFLOG("lynq_get_current_call_state %d\n ", *handle);
+ lynq_call_id = find_call_id_with_call_id(*handle);
+ if(lynq_call_id==INVALID_ID)
+ {
+ //find end state
+ if((*handle) >= 0)
+ {
+ *call_state = (int)LYNQ_CALL_END;
+ return RESULT_OK;
+ }
+ else
+ {
+ return LYNQ_E_INVALID_ID_ANONALY;
+ }
+ }
+ *call_state = s_call_lists[lynq_call_id].call_state;
+ *toa = s_call_lists[lynq_call_id].toa;
+ *direction = s_call_lists[lynq_call_id].direction;
+ memcpy(addr,s_call_lists[lynq_call_id].addr,strlen(s_call_lists[lynq_call_id].addr)+1);
+ return RESULT_OK;
+}
+
+int lynq_get_current_call_number()
+{
+ int cnt=0;
+ int i;
+ for(i = 0;i < LYNQ_CALL_MAX;i++)
+ {
+ if(s_call_lists[i].used !=0)
+ {
+ cnt++;
+ }
+ }
+
+ return cnt;
+}
+
+/*audio begin*/
+static int judge_mic(const int enable){
+ switch(enable){
+ case 0:
+ return true;
+ case 1:
+ return true;
+ default:
+ return false;
+ }
+}
+
+int lynq_set_mute_mic(const int enable)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ if(!judge_mic(enable)){
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+ // return lynq_set_common_request(53,1,"%d",enable); //RIL_REQUEST_SET_MUTE
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SET_MUTE,1,"%d",enable);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+int lynq_get_mute_mic(int *status)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ return lynq_get_common_request(RIL_REQUEST_GET_MUTE,status);//54
+}
+
+/**
+ * @brief Check whether DTMF is valid
+ *
+ * @param callnum dtmf eg:0-9 * #
+ * @return int
+ */
+static int judge_dtmf(const char callnum)
+{
+ if(callnum == '#')
+ {
+ return true;
+ }
+ if(callnum == '*')
+ {
+ return true;
+ }
+ if(callnum >= '0'&& callnum <= '9')
+ {
+ return true;
+ }
+ return false;
+}
+
+int lynq_switch_waiting_or_holding_and_active(void)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE,0,"");
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+
+#if 0
+ Parcel p;
+ lynq_client_t client;
+ int resp_type = -1;
+ int token;
+ int request = -1;
+ int slot_id = -1;
+ int error = -1;
+ client.uToken = Global_uToken_call;
+ client.request = RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE;
+ client.paramLen = 0;
+ bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
+ LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
+ pthread_mutex_lock(&g_lynq_call_sendto_mutex);
+ if(send_request(lynq_call_client_sockfd,&client)==-1)
+ {
+ LYERRLOG("send request fail");
+ return -1;
+ }
+ get_response(lynq_call_client_sockfd,p);
+ pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
+ JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
+ LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
+ return error;
+#endif
+}
+
+int lynq_hangup_waiting_or_background(void)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND,0,"");
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+#if 0
+ Parcel p;
+ lynq_client_t client;
+ int resp_type = -1;
+ int token;
+ int request = -1;
+ int slot_id = -1;
+ int error = -1;
+ client.uToken = Global_uToken_call;
+ client.request = RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND;
+ client.paramLen = 0;
+ bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
+ LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
+ pthread_mutex_lock(&g_lynq_call_sendto_mutex);
+ if(send_request(lynq_call_client_sockfd,&client)==-1)
+ {
+ LYERRLOG("send request fail");
+ return -1;
+ }
+ get_response(lynq_call_client_sockfd,p);
+ pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
+ JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
+ LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
+ return error;
+#endif
+}
+
+int lynq_hangup_foreground_resume_background(void)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND,0,"");
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+#if 0
+ Parcel p;
+ lynq_client_t client;
+ int resp_type = -1;
+ int token;
+ int request = -1;
+ int slot_id = -1;
+ int error = -1;
+ client.uToken = Global_uToken_call;
+ client.request = RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND;
+ client.paramLen = 0;
+ bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
+ LYDBGLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
+ pthread_mutex_lock(&g_lynq_call_sendto_mutex);
+ if(send_request(lynq_call_client_sockfd,&client)==-1)
+ {
+ LYERRLOG("send request fail");
+ return -1;
+ }
+ get_response(lynq_call_client_sockfd,p);
+ pthread_mutex_unlock(&g_lynq_call_sendto_mutex);
+ JumpHeader(p,&resp_type,&token,&request,&slot_id,&error);
+ LYINFLOG("resp_type=%d,request=%d,slot_id=%d,error_code=%d",resp_type,request,slot_id,error);
+ return error;
+#endif
+}
+
+int lynq_set_DTMF(const char callnum)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ if(!judge_dtmf(callnum))
+ {
+ return LYNQ_E_CONFLICT;
+ }
+ if(s_module_call_state!=CALL_ON)
+ {
+ LYERRLOG("LYNQ_E_CONFLICT");
+ return LYNQ_E_CONFLICT;
+ }
+
+// return lynq_set_common_request(24,1,"%c",callnum); //RIL_REQUEST_DTMF
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_DTMF,1,"%c",callnum);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+static int judge_volume(LYNQ_E_VOLUMN_SET set,const int volume){
+ if(set==LYNQ_E_VOLUMN_SET_DTMF){
+ if(volume < 0 ||volume >36){
+ return 0;
+ }
+ }
+ else if (set==LYNQ_E_VOLUMN_SET_SPEECH)
+ {
+ if(volume < 1 ||volume >7){
+ return 0;
+ }
+ }
+ return 1;
+}
+int lynq_set_DTMF_volume(const int volume)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ if(!judge_volume(LYNQ_E_VOLUMN_SET_DTMF,volume)){
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+// return lynq_set_common_request(8003,1,"%d",volume);//LYNQ_REQUEST_SET_DTMF_VOLUME
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_DTMF_VOLUME,1,"%d",volume);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+int lynq_set_speech_volume(const int volume)//mixer_set_volume
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ if(!judge_volume(LYNQ_E_VOLUMN_SET_SPEECH,volume))
+ {
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+// return lynq_set_common_request(8009,1,"%d",volume); //LYNQ_REQUEST_SET_SPEECH_VOLUME
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_SET_SPEECH_VOLUME,1,"%d",volume);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+int lynq_get_speech_volume(int* volumn)//mixer_get_volume
+{
+ return lynq_get_common_request(LYNQ_REQUEST_GET_SPEECH_VOLUME,volumn);//8010
+}
+int lynq_incall_record_start(const char* file_path)
+{
+// return lynq_set_common_request(8011,2,"%s %s","1",file_path); //LYNQ_REQUEST_RECORD
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","1",file_path);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+int lynq_incall_record_stop()
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ const char* unused_file="just_ocuupy_paramter_postion";
+// return lynq_set_common_request(8011,2,"%s %s","0",unused_file); //LYNQ_REQUEST_RECORD
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,LYNQ_REQUEST_RECORD,2,"%s %s","0",unused_file);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+/*audio end*/
+
+
+
+bool is_support_urc(int urc_id)
+{
+ switch(urc_id)
+ {
+ case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
+ case RIL_UNSOL_CALL_RING:
+ case RIL_UNSOL_RINGBACK_TONE:
+ case RIL_UNSOL_CALL_INFO_INDICATION:
+#ifdef ECALL_SUPPORT
+ case RIL_UNSOL_ECALL_INDICATIONS://9502
+#endif
+ return true;
+ default:
+ return false;
+ }
+}
+
+void urc_msg_process(Parcel *p)
+{
+ int resp_type;
+ int urcid;
+ int slot_id;
+
+ int size=p->dataSize();
+ p->readInt32(&resp_type);
+ p->readInt32(&urcid);
+ p->readInt32(&slot_id);
+ LYINFLOG("%s urc id = %d, slot_id = %d, size is %d, msg is %s",__func__, urcid,slot_id,size,requestToString(urcid));
+ switch (urcid)
+ {
+ case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED://1001
+ {
+ LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
+ lynqNoticeGetModuleCallList();
+ break;
+ }
+ case RIL_UNSOL_CALL_RING: //1018
+ {
+ if(s_call_auto_answer==1)
+ {
+ lynq_call_answer();
+ }
+ break;
+ }
+ case RIL_UNSOL_RINGBACK_TONE: //1029
+ case RIL_UNSOL_CALL_INFO_INDICATION://3049
+ {
+ LYINFLOG("**************:resp_type=%d,urcid=%d,slot_id=%d",resp_type,urcid,slot_id);
+ break;
+ }
+#ifdef ECALL_SUPPORT
+ case RIL_UNSOL_ECALL_INDICATIONS://9502
+ {
+ urc_ecall_msg_process(p);
+ }
+#endif
+ default:
+ break;
+ }
+}
+
+#if 0
+int main(int argc,char **argv)
+{
+ int n = 0;
+ n = lynq_init_call(lynq_call_state_change_test,2222);
+ if(n<0)
+ {
+ LYDBGLOG("lynq init call fail!!!");
+ return -1;
+ }
+ LYDBGLOG("lynq call init success!!!");
+ char phoneNum[LYNQ_PHONE_NUMBER_MAX];
+ sprintf(phoneNum,"18180053406 0",strlen("18180053406 0")+1);
+ lynq_call(phoneNum);
+ while(1)
+ {
+ sleep(1);
+ }
+ return 0;
+}
+#endif
+/*Warren add for T800 platform 2021/11/19 end*/
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_common.h b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_common.h
new file mode 100755
index 0000000..21077df
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_common.h
@@ -0,0 +1,23 @@
+#ifndef LYNQ_CALL_COMMON_H
+#define LYNQ_CALL_COMMON_H
+
+#define INVALID_ID (-1)
+
+int find_call_id_with_call_id(int call_id);
+int addAddr(char addr[], int call_id);
+int waitCallstateChange(int mtime);
+void sendSignalToWaitCallStateChange();
+void lynqNoticeGetModuleCallList();
+int IsNormalCallDailing();
+int lynq_get_current_call_number();
+
+#ifdef ECALL_SUPPORT
+int lynq_ecall_is_running();
+int IsECallDialing();
+int Is_handup_IncomingMT(int ecall_id);
+using ::android::Parcel;
+void urc_ecall_msg_process(Parcel *p);
+#endif
+
+void lynq_init_rtp();
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_ecall.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_ecall.cpp
new file mode 100755
index 0000000..d25675a
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_ecall.cpp
@@ -0,0 +1,703 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <binder/Parcel.h>
+#include <log/log.h>
+#include <cutils/jstring.h>
+#include <pthread.h>
+#include "liblog/lynq_deflog.h"
+#include <sys/time.h>
+#include <string.h>
+#include <vendor-ril/telephony/ril.h>
+#include <vendor-ril/telephony/mtk_ril_sp.h>
+#include <vendor-ril/telephony/mtk_ril_ivt.h>
+#include "lynq_call.h"
+#include "lynq_module_common.h"
+#include "lynq_module_socket.h"
+#include "lynq_call_common.h"
+
+#define USER_LOG_TAG "LYNQ_CALL"
+
+using ::android::Parcel;
+
+#ifdef ECALL_SUPPORT
+typedef enum{
+ LYNQ_ECALL_TYPE_TEST = 0, /* Test eCall */
+ LYNQ_ECALL_TYPE_RECONFIG = 1, /* Reconfiguration eCall */
+ LYNQ_ECALL_MANUAL_EMERGENCY = 2, /*Manual Emergency eCall */
+ LYNQ_ECALL_TYPE_AUTO_EMERGENCY = 3, /* Automatic Emergency eCall */
+}LYNQ_ECall_Type;
+typedef enum{
+ LYNQ_ECALL_DAILING_STATE_NONE =0,
+ LYNQ_ECALL_DAILING_STATE_STARTED = 1,
+ LYNQ_ECALL_DAILING_STATE_ANSWERED = 2,
+}LYNQ_ECall_Dailing_State;
+static LYNQ_ECall_Dailing_State s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
+int IsECallDialing()
+{
+ return s_module_is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE;
+}
+static int s_ecallId = INVALID_ID;
+char e_call_addr[LYNQ_ECALL_VAR_MAX][LYNQ_PHONE_NUMBER_MAX]={"test_ecall","emergency_ecall","reconf_ecall"};
+
+static pthread_mutex_t s_incoming_e_call_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t s_incoming_e_call_cond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t s_ecall_variable_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static LYNQ_ECall_Indication s_IncomingEcallIndication;
+int s_IncomingEcallId=INVALID_ID;
+LYNQ_ECall_Variant s_EcallVariant=LYNQ_ECALL_VAR_NONE;
+int s_ecall_whether_preempt=0;
+
+void sendSignalIncomingECallEvent()
+{
+ LYINFLOG("send incoming ecall event signal");
+ pthread_mutex_lock(&s_incoming_e_call_mutex);
+ pthread_cond_signal(&s_incoming_e_call_cond);
+ pthread_mutex_unlock(&s_incoming_e_call_mutex);
+}
+
+int lynq_is_msd_suc(LYNQ_ECall_Indication lynqIncomingEcallIndication)
+{
+ if(LYNQ_ECALL_LLACK_RECEIVED == lynqIncomingEcallIndication ||
+ LYNQ_ECALL_ALACK_POSITIVE_RECEIVED == lynqIncomingEcallIndication ||
+ LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED == lynqIncomingEcallIndication ||
+ //LYNQ_ECALL_T5_TIMER_OUT == lynqIncomingEcallIndication ||
+ LYNQ_ECALL_T6_TIMER_OUT == lynqIncomingEcallIndication ||
+ LYNQ_ECALL_T7_TIMER_OUT == lynqIncomingEcallIndication)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+int lynq_ecall_is_running()
+{
+ return (s_module_is_ecall_dial!=LYNQ_ECALL_DAILING_STATE_NONE) || (s_ecallId !=INVALID_ID || s_EcallVariant == LYNQ_ECALL_CALLBACK);
+}
+
+void print_ecall_info()
+{
+ LYERRLOG("%s is ecall dial is %d, ecall id is %d, ecall vairant is %d, incoming ecall ind is %d, incoming ecall id is %d, whether preempt is %d",__func__,s_module_is_ecall_dial,s_ecallId,s_EcallVariant,s_IncomingEcallIndication,s_IncomingEcallId,s_ecall_whether_preempt);
+}
+
+int lynq_ecall_is_permit_in_call(int ecall_id)
+{
+ return s_EcallVariant == LYNQ_ECALL_CALLBACK && (s_ecallId ==INVALID_ID || s_ecallId ==ecall_id);
+}
+
+int Is_handup_IncomingMT(int ecall_id)
+{
+ pthread_mutex_lock(&s_ecall_variable_mutex);
+ int handupIncomingMT=lynq_ecall_is_running() && (lynq_ecall_is_permit_in_call(ecall_id)==false);
+ pthread_mutex_unlock(&s_ecall_variable_mutex);
+ return handupIncomingMT;
+}
+
+int lynq_ecall_is_in_voice()
+{
+ return (s_module_is_ecall_dial==LYNQ_ECALL_DAILING_STATE_NONE) && (s_ecallId !=INVALID_ID);
+}
+
+LYNQ_ECall_Variant lynq_get_lynq_ecall_variant_from_lynq_type(LYNQ_ECall_Type type)
+{
+ switch(type)
+ {
+ case LYNQ_ECALL_TYPE_TEST:
+ return LYNQ_ECALL_TEST;
+ case LYNQ_ECALL_TYPE_RECONFIG:
+ return LYNQ_ECALL_RECONFIG;
+ default:
+ return LYNQ_ECALL_EMERGENCY;
+ }
+}
+
+RIL_ECall_Variant lynq_get_ril_ecall_variant_from_lynq_variant(LYNQ_ECall_Variant type)
+{
+ switch(type)
+ {
+ case LYNQ_ECALL_TEST:
+ return ECALL_TEST;
+ case LYNQ_ECALL_RECONFIG:
+ return ECALL_RECONFIG;
+ default:
+ return ECALL_EMERGENCY;
+ }
+}
+
+RIL_ECall_Category lynq_get_ril_ecall_cat_from_lynq_cat(LYNQ_ECall_Category cat)
+{
+ switch(cat)
+ {
+ case LYNQ_EMER_CAT_MANUAL_ECALL:
+ return EMER_CAT_MANUAL_ECALL;
+ default:
+ return EMER_CAT_AUTO_ECALL;
+ }
+}
+
+
+int lynq_set_test_num(LYNQ_ECall_Set_Type type, const char *test_num, int test_num_length)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ if(test_num==NULL || test_num_length > LYNQ_PHONE_NUMBER_MAX )
+ {
+ LYERRLOG("test_num is null or test_num_length %d s greater than %d ",test_num_length,LYNQ_PHONE_NUMBER_MAX);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+// error=lynq_set_common_request(RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_SET_TEST_NUM,2,"%d %s",type,test_num);
+ if(ret==RESULT_OK)
+ {
+ snprintf(e_call_addr[LYNQ_ECALL_TEST],LYNQ_PHONE_NUMBER_MAX,"%s",test_num);
+ delete p;
+ }
+ return ret;
+}
+
+int lynq_ecall_can_be_preempted(LYNQ_ECall_Variant old_variant,LYNQ_ECall_Variant new_variant)
+{
+ int ret;
+
+ if(old_variant == LYNQ_ECALL_EMERGENCY)
+ {
+ return false;
+ }
+ else if(new_variant == LYNQ_ECALL_EMERGENCY)
+ {
+ return true;
+ }
+ else if(old_variant==LYNQ_ECALL_DAILING_STATE_NONE)
+ {
+ return true;
+ }
+ else
+ {
+ ret = (s_ecall_whether_preempt & 0x01);
+ }
+ LYINFLOG("ecall clear conflict call, lynq_ecall_can_be_preempted is true");
+ return ret;
+}
+
+int lynq_clear_current_call()
+{
+ int cnt;
+ int ret=lynq_call_hungup_all();
+
+ if(ret!=RESULT_OK)
+ {
+ LYERRLOG("ecall clear conflict call, hangup all failure");
+ return ret;
+ }
+ cnt=0;
+ while(lynq_get_current_call_number()!=0 && cnt<80)
+ {
+ lynqNoticeGetModuleCallList();
+ usleep(200 * 1000);//200ms
+ cnt++;
+ }
+ if(lynq_get_current_call_number()!=0)
+ {
+ LYERRLOG("ecall clear conflict call, current call list can't cleared after 15s");
+ return LYNQ_E_INNER_ERROR;
+ }
+
+ LYINFLOG("ecall clear conflict call, after %d 0.2s, call list is cleared", cnt);
+ return RESULT_OK;
+}
+
+int lynq_clear_current_conflict_call(LYNQ_ECall_Variant old_variant,LYNQ_ECall_Variant new_variant)
+{
+ int cnt;
+ int ret;
+
+ if(lynq_ecall_is_running()==false)
+ {
+ if(lynq_get_current_call_number()==0)
+ {
+ LYINFLOG("ecall clear conflict call, no conflict ecall and normal call");
+ }
+ else if(s_ecall_whether_preempt & 0x02)
+ {
+ ret=lynq_clear_current_call();
+ LYERRLOG("ecall clear conflict call, relase current normal call ret is %d",ret);
+ }
+ return RESULT_OK;
+ }
+
+ LYINFLOG("ecall clear conflict call, two ecall occure at the same time, new is %d, old is %d, g_preempt is %d",new_variant,old_variant,s_ecall_whether_preempt);
+
+ if(lynq_ecall_can_be_preempted(old_variant,new_variant)==false)
+ {
+ LYERRLOG("ecall clear conflict call, new ecall %d can't preempt old ecall %d",new_variant,old_variant);
+ return LYNQ_E_CONFLICT;
+ }
+
+ ret=lynq_clear_current_call();
+ LYINFLOG("ecall clear conflict call, relase current call(including ecall) ret is %d",ret);
+
+ if(s_module_is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
+ {
+ sendSignalToWaitCallStateChange();
+ LYINFLOG("ecall clear conflict call, stop ecall in dailing status");
+ }
+
+ cnt=0;
+ while(lynq_ecall_is_running() && cnt<80)
+ {
+ usleep(200 * 1000);//200ms
+ cnt++;
+ }
+
+ if(lynq_ecall_is_running())
+ {
+ LYERRLOG("ecall clear conflict call, after 16s, lynq ecall is still running");
+ }
+ else
+ {
+ LYINFLOG("ecall clear conflict call, after %d 0.2s, ecall info is cleared", cnt);
+ }
+
+ sleep(3);// for ecall disconnect
+ print_ecall_info();
+ return RESULT_OK;
+}
+
+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)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ RIL_ECall_Variant ril_ecall_variant = lynq_get_ril_ecall_variant_from_lynq_variant (lynq_ecall_variant);
+ RIL_ECall_Category ril_ecall_cat = lynq_get_ril_ecall_cat_from_lynq_cat(lynq_ecall_cat);
+ char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
+ unsigned int i;
+
+ if(msd_length > MSD_MAX_LENGTH || msd_length <=0 || lynq_ecall_variant >=LYNQ_ECALL_MO_MAX)
+ {
+ LYERRLOG("lynq_fast_ecall msd_length %d or ecall variant %d parameter error",msd_length,lynq_ecall_variant);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ if(lynq_clear_current_conflict_call(s_EcallVariant,lynq_ecall_variant)!=0)
+ {
+ LYERRLOG("%s call lynq_clear_current_conflict_call false, old is %d, new is %d",__func__,s_EcallVariant,lynq_ecall_variant);
+ return LYNQ_E_CONFLICT;
+ }
+
+ pthread_mutex_lock(&s_ecall_variable_mutex);
+ s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_STARTED;
+ s_EcallVariant = lynq_ecall_variant;
+ s_ecallId = INVALID_ID;
+ pthread_mutex_unlock(&s_ecall_variable_mutex);
+
+ for(i =0; i<msd_length;i++)
+ {
+ sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
+ }
+
+
+ LYINFLOG("lynq_fast_ecall addr is %s",e_call_addr[lynq_ecall_variant]);
+
+// 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);
+
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_FAST_MAKE_ECALL,4,"%d %d %s %s",ril_ecall_cat, ril_ecall_variant, "null", lynq_msd_data);
+ if(ret!=RESULT_OK)
+ {
+ pthread_mutex_lock(&s_ecall_variable_mutex);
+ s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
+ s_EcallVariant = LYNQ_ECALL_VAR_NONE;
+ s_ecallId = INVALID_ID;
+ pthread_mutex_unlock(&s_ecall_variable_mutex);
+ return ret;
+ }
+
+ delete p;
+ if(waitCallstateChange(270000)==ETIMEDOUT)//4.5 min, dailing 1 min, alerting 1 min, sending msd 30s, redial 2min
+ {
+ pthread_mutex_lock(&s_ecall_variable_mutex);
+ LYERRLOG("lynq_fast_ecall timeout:wait Call state time out!!!");
+ s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
+ lynqNoticeGetModuleCallList();
+ pthread_mutex_unlock(&s_ecall_variable_mutex);
+ return LYNQ_E_TIME_OUT;
+ }
+ pthread_mutex_lock(&s_ecall_variable_mutex);
+ if(s_module_is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)
+ {
+ /*just dail, no recv answer*/
+ LYERRLOG("lynq_fast_ecall, no answer!");
+ s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
+ lynqNoticeGetModuleCallList();
+ pthread_mutex_unlock(&s_ecall_variable_mutex);
+ return LYNQ_E_ECALL_DAILING_NO_ANSWER;
+ }
+
+ s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
+ lynqNoticeGetModuleCallList();
+
+ if(s_ecallId != INVALID_ID)
+ {
+ *handle=s_ecallId;
+ LYINFLOG("lynq_fast_ecall id is %d",s_ecallId);
+ pthread_mutex_unlock(&s_ecall_variable_mutex);
+ return RESULT_OK;
+ }
+
+ LYERRLOG("lynq_fast_ecall service return fail");
+ pthread_mutex_unlock(&s_ecall_variable_mutex);
+ return LYNQ_E_INVALID_ID_ANONALY;
+
+}
+
+int lynq_set_psap(int enable)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+// return lynq_set_common_request(RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_SET_PSAP,1,"%d",enable);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+
+int lynq_psap_pull_msd()
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+// return lynq_set_common_request(RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_PSAP_PULL_MSD,0,"");
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+
+int lynq_make_ecall(int* handle, LYNQ_ECall_Type type)
+{
+ return RESULT_OK;
+#if 0
+ LYNQ_ECall_Variant lynq_ecall_variant;
+ int error = -1;
+ int lynq_call_id = -1;
+
+ if(handle==NULL)
+ {
+ LYERRLOG("handle is NULL, parameter error ");
+ return -1;
+ }
+
+ error=lynq_set_common_request(RIL_REQUEST_ECALL_MAKE_ECALL,1,"%d",type);
+
+ if(error==0)
+ {
+ lynq_ecall_variant=lynq_get_lynq_ecall_variant_from_lynq_type(type);
+
+ lynq_call_id = addAddr(e_call_addr[lynq_ecall_variant]);
+ s_module_isDial = 1;
+ if(waitCallstateChange(10000)==ETIMEDOUT)//10000ms
+ {
+ error = LYNQ_E_TIME_OUT;
+ LYERRLOG("timeout:wait Call state fail!!!");
+ return error;
+ }
+
+ *handle = lynq_call_id;
+ }
+
+ return error;
+#endif
+}
+
+
+int lynq_set_msd(int* handle, const unsigned char *msd_data, int msd_length)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ char lynq_msd_data[MSD_MAX_LENGTH*2+1]={0};
+ unsigned int i;
+
+ if(handle==NULL || ((*handle) >= LYNQ_CALL_MAX) || msd_length > MSD_MAX_LENGTH || msd_length <= 0 || msd_data ==NULL)
+ {
+ 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);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ for(i=0; i<msd_length;i++)
+ {
+ sprintf(&(lynq_msd_data[i<<1]),"%02x",msd_data[i]);
+ }
+
+ LYINFLOG("lynq_set_msd ");
+
+// return lynq_set_common_request(RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",*handle,lynq_msd_data);
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_SET_MSD,2,"%d %s",*handle,lynq_msd_data);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+
+int lynq_set_ivs(int enable)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ if(enable<0)
+ {
+ if(enable >-200)
+ {
+ goto set_ivs_end;
+// lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
+ }
+ else if(enable== -1000)
+ {
+ print_ecall_info();
+ }
+ else
+ {
+ s_ecall_whether_preempt= ((-200-enable) & 0x11);
+ }
+ return RESULT_OK;
+ }
+
+// return lynq_set_common_request(RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
+set_ivs_end:
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_SET_IVS,1,"%d",enable);
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+
+int lynq_reset_ivs()
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+// return lynq_set_common_request(RIL_REQUEST_ECALL_RESET_IVS,0,"");
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_RESET_IVS,0,"");
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+
+int lynq_ivs_push_msd()
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+// return lynq_set_common_request(RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
+ Parcel* p=NULL;
+ int ret=lynq_send_common_request(p,g_wait_time,RIL_REQUEST_ECALL_IVS_PUSH_MSD,0,"");
+ if(ret==RESULT_OK)
+ {
+ delete p;
+ }
+ return ret;
+}
+
+int wait_ecall_event()
+{
+ int ret = 0;
+ pthread_mutex_lock(&s_incoming_e_call_mutex);
+ ret = pthread_cond_wait(&s_incoming_e_call_cond,&s_incoming_e_call_mutex);
+ pthread_mutex_unlock(&s_incoming_e_call_mutex);
+ return ret;
+}
+
+int lynq_wait_ecall_indication(int* handle, LYNQ_ECall_Indication *eCall_Indication)
+{
+ if(g_module_init_flag != MODULE_RUNNING)
+ {
+ LYERRLOG("%s module state %d error",__func__,g_module_init_flag);
+ return LYNQ_E_CONFLICT;
+ }
+ wait_ecall_event();
+ *handle = s_IncomingEcallId;
+ *eCall_Indication = s_IncomingEcallIndication;
+ LYINFLOG("lynq_wait_ecall_indication handle %d, Ind id: %d", *handle, *eCall_Indication);
+ return RESULT_OK;
+}
+void urc_ecall_msg_process(Parcel *p)
+{
+ int ecall_ind;
+ int ecallId;
+ int send_signal_to_wait_call_state;
+ int handup_ecall_id;
+
+ pthread_mutex_lock(&s_ecall_variable_mutex);
+ send_signal_to_wait_call_state = false;
+ handup_ecall_id=false;
+ p->readInt32(&ecall_ind);
+ s_IncomingEcallIndication = ecall_ind;
+ p->readInt32(&ecallId);
+ s_IncomingEcallId = ecallId;
+ 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,s_module_is_ecall_dial,IsNormalCallDailing(),s_ecallId);
+ switch (s_IncomingEcallIndication)
+ {
+ case LYNQ_ECALL_ACTIVE:
+ if(s_module_is_ecall_dial)
+ {
+ s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_ANSWERED;
+ }
+ break;
+ case LYNQ_ECALL_SENDING_START:
+ if(lynq_ecall_is_in_voice())
+ {
+ LYINFLOG("recv msd in voice, ind is changed to %d",LYNQ_ECALL_SENDING_START_IN_VOICE);
+ s_IncomingEcallIndication = LYNQ_ECALL_SENDING_START_IN_VOICE;
+ }
+ break;
+ case LYNQ_ECALL_LLACK_RECEIVED:
+ case LYNQ_ECALL_ALACK_POSITIVE_RECEIVED:
+ case LYNQ_ECALL_ALACK_CLEARDOWN_RECEIVED:
+ //case LYNQ_ECALL_T5_TIMER_OUT: /*when Certificate CP 1.1.10.2, no msd start (ind 1), so T5 timeout is not regard as success*/
+ case LYNQ_ECALL_T6_TIMER_OUT:
+ case LYNQ_ECALL_T7_TIMER_OUT:
+ if(s_module_is_ecall_dial)
+ {
+ LYINFLOG("ecall is dialing, recv suc indication");
+ s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
+ if(ecallId >0 && find_call_id_with_call_id(ecallId)==INVALID_ID)
+ {
+ LYINFLOG("add ecall in loacl list");
+ s_ecallId = ecallId;
+ addAddr("ecall",s_ecallId);
+ }
+ send_signal_to_wait_call_state=true;
+ }
+ else if(ecallId >0 && (find_call_id_with_call_id(ecallId)==INVALID_ID) && (s_EcallVariant != LYNQ_ECALL_CALLBACK))
+ {
+ LYERRLOG("ecall is not in dialing and first recv suc indication, hangup");
+ handup_ecall_id=true;
+ }
+ else
+ {
+ LYERRLOG("ecall is not in dialing and not first recv suc indication");
+ }
+ break;
+ case LYNQ_ECALL_PSAP_CALLBACK_START:
+ if(lynq_ecall_is_running()==0)
+ {
+ if(ecallId>0)
+ {
+ LYINFLOG("ecall is not running, recv psap call back msd start, set ecall running");
+ s_EcallVariant = LYNQ_ECALL_CALLBACK;
+ s_ecallId = ecallId;
+ if(IsNormalCallDailing())
+ {
+ LYINFLOG("stop normal dial");
+ send_signal_to_wait_call_state=true;
+ }
+ else
+ {
+ LYINFLOG("no normal dial");
+ }
+ }
+ else
+ {
+ LYERRLOG("ecallId is abnormal in psap callback");
+ }
+ }
+ else
+ {
+ LYERRLOG("ecall is running, recv psap call back msd start");
+ }
+ break;
+ case LYNQ_ECALL_ABNORMAL_HANGUP:
+ if(s_module_is_ecall_dial == LYNQ_ECALL_DAILING_STATE_NONE)
+ {
+ LYERRLOG("ecall is not in dialing , recv abnormal hangup");
+ s_ecallId = INVALID_ID;
+ }
+ else if (s_module_is_ecall_dial == LYNQ_ECALL_DAILING_STATE_STARTED)
+ {
+ LYERRLOG("ecall is in dialing state, recv no answer, recv abnormal hangup, dont' redial");
+ s_ecallId = INVALID_ID;
+ send_signal_to_wait_call_state=true;
+ }
+ else {
+ LYINFLOG("ecall is in dialing and recv answer, recv abnormal hangup");
+ }
+ break;
+ case LYNQ_ECALL_DISCONNECTED:
+ case LYNQ_ECALL_REDIAL_TIMER_OUT:
+ case LYNQ_ECALL_T2_TIMER_OUT :
+ case LYNQ_ECALL_IMS_DISCONNECTED:
+ s_ecallId = INVALID_ID;
+ if(s_EcallVariant == LYNQ_ECALL_CALLBACK)
+ {
+ s_EcallVariant = LYNQ_ECALL_VAR_NONE; /*other type, needn't re-initialize*/
+ }
+ if(s_module_is_ecall_dial != LYNQ_ECALL_DAILING_STATE_NONE)
+ {
+ LYERRLOG("ecall is in dialing, recv like disconnect indication");
+ s_module_is_ecall_dial = LYNQ_ECALL_DAILING_STATE_NONE;
+ send_signal_to_wait_call_state=true;
+ }
+ else
+ {
+ LYINFLOG("ecall is not in dialing, recv like disconnect indication");
+ }
+ break;
+ default:
+ LYINFLOG("not special indication");
+ }
+ pthread_mutex_unlock(&s_ecall_variable_mutex);
+ if(send_signal_to_wait_call_state)
+ {
+ sendSignalToWaitCallStateChange();
+ }
+ sendSignalIncomingECallEvent();
+ if(handup_ecall_id)
+ {
+ lynq_call_hungup(&ecallId);
+ }
+ LYINFLOG("**************:RIL_UNSOL_ECALL_INDICATIONS, local ecall id is %d", s_ecallId);
+ return;
+}
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_rtp.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_rtp.cpp
new file mode 100755
index 0000000..4d6c1b3
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_call_rtp.cpp
@@ -0,0 +1,391 @@
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <binder/Parcel.h>
+#include <log/log.h>
+#include <cutils/jstring.h>
+#include <pthread.h>
+#include "liblog/lynq_deflog.h"
+#include <sys/time.h>
+#include <string.h>
+#include "lynq_call.h"
+#include "lynq_module_common.h"
+#include "lynq_call_common.h"
+
+#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\'"
+#define RTP_TO_CMD "gst-launch-1.0 -v alsasrc device=\'hw:0,6\' ! audioconvert ! audioresample ! alawenc ! rtppcmapay ! %s udpsink host=%s %s auto-multicast=true port=%d"
+#define RTP_VLAN_INFO_FORMAT "multicast-iface=\"%s\""
+#define RTP_SSRC_INFO_FORMAT " rtpmux name=mux ssrc=%u !"
+
+#define USER_LOG_TAG "LYNQ_CALL"
+
+typedef struct
+{
+ char ip[MAX_IP_LENGTH];
+ int port;
+ int ssrc_mode;
+ unsigned int ssrc;
+ char vlan_info[MAX_VLAN_INFO_LENGTH];
+}lynq_rtp_server_info;
+
+typedef struct
+{
+ int port;
+ int clockrate;
+ int latency;
+ int channels;
+}lynq_rtp_client_info;
+
+static lynq_rtp_client_info g_rtp_client_info;
+static lynq_rtp_server_info g_rtp_server_info;
+
+static pthread_t g_rtp_thread[RTP_MODE_MAX];
+static bool g_rtp_thread_valid[RTP_MODE_MAX];
+
+void lynq_init_rtp()
+{
+ memset(&g_rtp_client_info,0,sizeof(g_rtp_client_info));
+ memset(&g_rtp_server_info,0,sizeof(g_rtp_server_info));
+
+
+ lynq_set_rtp_param(8000,1,400);
+
+ for(int i=0;i<RTP_MODE_MAX;i++)
+ {
+ lynq_set_rtp_port(i,6666);
+ g_rtp_thread_valid[i] = 0;
+ }
+
+ LYDBGLOG("lynq init rtp success!!!");
+ return;
+}
+
+/*Audio Path setting begin*/
+/*sub function*/
+void lynq_set_rtp_mixer_ctrl(int enable_rtp)
+{
+ char cmd[256];
+ LYINFLOG("set_rtp_mixer_ctrl %d", enable_rtp);
+ if(enable_rtp)
+ {
+ sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 0);
+ system(cmd);
+ sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 1);
+ system(cmd);
+ sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 1);
+ system(cmd);
+ sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 1);
+ system(cmd);
+ sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 1);
+ system(cmd);
+ sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 1);
+ system(cmd);
+ }
+ else
+ {
+ sprintf(cmd, "amixer -D mtk_phonecall cset name=\"M2M_Speech_on\" %d", 0);
+ system(cmd);
+ sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH1 DL2_CH1\" %d", 0);
+ system(cmd);
+ sprintf(cmd, "amixer -c0 cset name=\"PCM_2_PB_CH2 DL2_CH2\" %d", 0);
+ system(cmd);
+ sprintf(cmd, "amixer -c0 cset name=\"UL2_CH1 PCM_2_CAP_CH1\" %d", 0);
+ system(cmd);
+ sprintf(cmd, "amixer -c0 cset name=\"UL2_CH2 PCM_2_CAP_CH1\" %d", 0);
+ system(cmd);
+ sprintf(cmd, "amixer -D mtk_phonecall cset name=\"Speech_on\" %d", 1);
+ system(cmd);
+ }
+}
+
+void* lynq_start_rtp_cmd(void *arg)
+{
+ int* rtp_mode= (int*) arg;
+ char cmd[384];
+ char vlan_para_string[sizeof(RTP_VLAN_INFO_FORMAT)+MAX_VLAN_INFO_LENGTH-2/*sizeof "%s"*/]={0};
+ char ssrc_para_string[sizeof(RTP_SSRC_INFO_FORMAT)+MAX_SSRC_INFO_LENGTH-2/*sizeof "%u"*/]={0};
+ LYINFLOG("lynq_start_rtp_cmd: rtp_mode is %d",(*rtp_mode));
+ if ((*rtp_mode) == RTP_CLIENT)
+ {
+ sprintf(cmd,RTP_FROM_CMD, \
+ g_rtp_client_info.port,g_rtp_client_info.clockrate,g_rtp_client_info.channels, \
+ g_rtp_client_info.latency);
+ // LYINFLOG("start from rtp play: cmd is %s",cmd);
+ system(cmd);
+ }
+ else if ((*rtp_mode) == RTP_SERVER)
+ {
+ if(strlen(g_rtp_server_info.vlan_info)>0)
+ {
+ sprintf(vlan_para_string,RTP_VLAN_INFO_FORMAT,g_rtp_server_info.vlan_info);
+ }
+
+ if(g_rtp_server_info.ssrc_mode == Rtp_Ssrc_specific)
+ {
+ sprintf(ssrc_para_string,RTP_SSRC_INFO_FORMAT,g_rtp_server_info.ssrc);
+ }
+ sprintf(cmd,RTP_TO_CMD, \
+ ssrc_para_string, g_rtp_server_info.ip,vlan_para_string,g_rtp_server_info.port);
+
+ LYINFLOG("start to rtp play: cmd is %s",cmd);
+ system(cmd);
+ }
+ return NULL;
+}
+
+int lynq_start_rtp_thread(int rtp_mode)
+{
+ int ret;
+ pthread_attr_t attr;
+ static int start_mode[RTP_MODE_MAX]={0,1};
+
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ ret = pthread_create(&(g_rtp_thread[rtp_mode]),&attr,lynq_start_rtp_cmd,&(start_mode[rtp_mode]));
+ if(ret != 0)
+ {
+ g_rtp_thread_valid[rtp_mode]=0;
+ LYERRLOG("rtp create %d pthread error, ret is %d",rtp_mode, ret);
+ return ret;
+ }
+ g_rtp_thread_valid[rtp_mode]=1;
+ return RESULT_OK;
+}
+
+/*set*/
+int lynq_set_voice_audio_mode(const LYNQ_Audio_Mode audio_mode)
+{
+ int ret;
+ int i;
+
+ if(audio_mode==AUDIO_MODE_RTP)
+ {
+ lynq_set_rtp_mixer_ctrl(1);
+ for(i=0;i<RTP_MODE_MAX;i++)
+ {
+ if(!g_rtp_thread_valid[i])
+ {
+ if(lynq_start_rtp_thread(i)!= 0)
+ {
+ LYERRLOG("start rtp %d fail",i);
+ break;
+ }
+ else
+ {
+ LYINFLOG("start rtp %d suc",i);
+ }
+ }
+ else
+ {
+ LYERRLOG("rtp %d needn't start",i);
+ }
+ }
+ if(i!= RTP_MODE_MAX)
+ {
+ LYERRLOG("start rtp whole fail");
+ lynq_set_voice_audio_mode(AUDIO_MODE_CODEC);
+ return RESULT_ERROR;
+ }
+ LYINFLOG("start rtp whole suc");
+ return RESULT_OK;
+ }
+ else if(audio_mode==AUDIO_MODE_CODEC)
+ {
+ for(i=0;i<RTP_MODE_MAX;i++)
+ {
+ if(g_rtp_thread_valid[i])
+ {
+ ret = pthread_cancel(g_rtp_thread[i]);
+ LYINFLOG("pthread cancel rtp %d ret = %d",i,ret);
+ ret = pthread_join(g_rtp_thread[i],NULL);
+ LYINFLOG("pthread join rtp %d ret = %d",i,ret);
+ g_rtp_thread_valid[i] = 0;
+ }
+ else
+ {
+ LYINFLOG("rtp %d needn't stop",i);
+ }
+ }
+ lynq_set_rtp_mixer_ctrl(0);
+ LYINFLOG("stop rtp suc");
+ }
+ return RESULT_OK;
+}
+int lynq_set_remote_rtp_ip(const char* ip, const int ip_length)
+{
+ if (NULL == ip)
+ {
+ LYERRLOG("ip is NULL!!!");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+ if ((ip_length < strlen(ip)+1) || (ip_length > MAX_IP_LENGTH))
+ {
+ LYERRLOG("incoming ip length error %d", ip_length);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ bzero(g_rtp_server_info.ip,MAX_IP_LENGTH);
+ strcpy(g_rtp_server_info.ip,ip);
+
+ LYINFLOG("lynq_set_remote_rtp_ip suc: ip is %s, length is %d", ip,ip_length);
+
+ return RESULT_OK;
+}
+int lynq_set_vlan_info(const char* vlan_info, const int vlan_info_length)
+{
+ if (NULL == vlan_info)
+ {
+ LYERRLOG("vlan_info is NULL!!!");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ if ((vlan_info_length < strlen(vlan_info)+1) || (vlan_info_length > MAX_VLAN_INFO_LENGTH))
+ {
+ LYERRLOG("incoming vlan_info error, vlan info length %d", vlan_info_length);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+
+ bzero(g_rtp_server_info.vlan_info,MAX_VLAN_INFO_LENGTH);
+ strcpy(g_rtp_server_info.vlan_info,vlan_info);
+
+ LYINFLOG("lynq_set_vlan_info suc: vlan is %s, length is %d", vlan_info,vlan_info_length);
+
+ return RESULT_OK;
+}
+int lynq_set_rtp_port(const LYNQ_Rtp_Mode rtp_mode, const int port)
+{
+ if (port < 0)
+ {
+ LYERRLOG("invalid port number %d", port);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+ if (rtp_mode == 0)
+ {
+ g_rtp_client_info.port = port;
+ }
+ else if (rtp_mode == 1)
+ {
+ g_rtp_server_info.port = port;
+ }
+ LYINFLOG("lynq_set_rtp_port suc: LYNQ_Rtp_Mode is %d, port is %d", rtp_mode, port);
+ return RESULT_OK;
+}
+int lynq_set_rtp_param(const int clock_rate,const int channels,const int latency) //only for client mode
+{
+ g_rtp_client_info.clockrate = clock_rate;
+ g_rtp_client_info.channels = channels;
+ g_rtp_client_info.latency = latency;
+ LYINFLOG("lynq_set_rtp_param suc: clockrate is %d, channels is %d, latency is %d", clock_rate, channels, latency);
+ return RESULT_OK;
+}
+int lynq_set_call_rtp_ssrc(const LYNQ_Rtp_Ssrc_Mode ssrc_mode,const unsigned int ssrc)
+{
+ if(ssrc_mode < Rtp_Ssrc_random || ssrc_mode > Rtp_Ssrc_specific)
+ {
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+ g_rtp_server_info.ssrc_mode = ssrc_mode;
+ g_rtp_server_info.ssrc = ssrc ;
+ LYINFLOG("%s suc: param is %d %d", __func__, ssrc_mode, ssrc);
+ return RESULT_OK;
+}
+/*get*/
+LYNQ_Audio_Mode lynq_get_voice_audio_mode()
+{
+ if(g_rtp_thread_valid[0])
+ {
+ return AUDIO_MODE_RTP;
+ }
+ else
+ {
+ return AUDIO_MODE_CODEC;
+ }
+}
+int lynq_get_remote_rtp_ip(char* ip, const int ip_length)
+{
+ if(ip==NULL)
+ {
+ LYERRLOG("ip is NULL");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ if(ip_length < strlen(g_rtp_server_info.ip)+1)
+ {
+ LYERRLOG("ip length %d is shorter than saved ip length %d",ip_length,strlen(g_rtp_server_info.ip)+1);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ bzero(ip,ip_length);
+ strcpy(ip,g_rtp_server_info.ip);
+
+ return RESULT_OK;
+}
+int lynq_get_vlan_info(char* vlan_info, const int vlan_info_length)
+{
+ if(vlan_info==NULL)
+ {
+ LYERRLOG("vlan info is NULL");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ if(vlan_info_length < strlen(g_rtp_server_info.vlan_info)+1)
+ {
+ LYERRLOG("vlan info length %d is shorter than saved vlan info length %d",vlan_info_length,strlen(g_rtp_server_info.vlan_info)+1);
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ bzero(vlan_info,vlan_info_length);
+ strcpy(vlan_info,g_rtp_server_info.vlan_info);
+
+ return RESULT_OK;
+}
+int lynq_get_rtp_port(const LYNQ_Rtp_Mode rtp_mode, int* port)
+{
+ if(port==NULL)
+ {
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+ if (rtp_mode == 0)
+ {
+ *port = g_rtp_client_info.port;
+ }
+ else if (rtp_mode == 1)
+ {
+ *port = g_rtp_server_info.port;
+ }
+ return RESULT_OK;
+}
+int lynq_get_rtp_param(int* clock_rate, int* channels, int* latency)//only for client mode
+{
+ if(clock_rate == NULL || channels ==NULL || latency ==NULL)
+ {
+ LYERRLOG("input parameter is NULL");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ *clock_rate = g_rtp_client_info.clockrate;
+ *channels = g_rtp_client_info.channels ;
+ *latency = g_rtp_client_info.latency;
+
+ return RESULT_OK;
+}
+int lynq_get_call_rtp_ssrc(int* ssrc_mode, unsigned int* ssrc)
+{
+ if(ssrc_mode == NULL || ssrc ==NULL)
+ {
+ LYERRLOG("input parameter is NULL");
+ return LYNQ_E_PARAMETER_ANONALY;
+ }
+
+ *ssrc_mode = g_rtp_server_info.ssrc_mode;
+ *ssrc = g_rtp_server_info.ssrc ;
+
+ return RESULT_OK;
+}
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_common.h b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_common.h
new file mode 100755
index 0000000..590971a
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_common.h
@@ -0,0 +1,75 @@
+#ifndef LYNQ_MODULE_COMMON_H
+#define LYNQ_MODULE_COMMON_H
+
+#define RESULT_OK (0)
+#define RESULT_ERROR (-1)
+
+/*the same with lynq_interface.h begin*/
+#define LYNQ_REQUEST_VENDOR_BASE 8000
+#define LYNQ_URC_VENDOR_BASE 9000
+#define LYNQ_AT_SNED (LYNQ_REQUEST_VENDOR_BASE +1)
+#define LYNQ_URC_CALL_STATUS_IND (LYNQ_URC_VENDOR_BASE+1)
+#define LYNQ_URC_DATA_STATUS_IND (LYNQ_URC_VENDOR_BASE+2)
+#define LYNQ_URC_DATA_CALL_STATUS_IND (LYNQ_URC_VENDOR_BASE+3)
+#define LYNQ_AUTO_ANSWER_CALL (LYNQ_REQUEST_VENDOR_BASE +2)
+#define LYNQ_REQUEST_SET_DTMF_VOLUME (LYNQ_REQUEST_VENDOR_BASE +3)
+#define LYNQ_URC_MODIFY_APNDB (LYNQ_URC_VENDOR_BASE+4)
+#define LYNQ_URC_RESET_APNDB (LYNQ_URC_VENDOR_BASE+5)
+
+
+#define LYNQ_REQUEST_WRITE_SMS_TO_MEMORY (LYNQ_REQUEST_VENDOR_BASE +4)
+#define LYNQ_REQUEST_READ_SMS_FROM_MEMORY (LYNQ_REQUEST_VENDOR_BASE + 5)
+#define LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY (LYNQ_REQUEST_VENDOR_BASE + 6)
+#define LYNQ_REQUEST_LIST_SMS_FROM_MEMORY (LYNQ_REQUEST_VENDOR_BASE + 7)
+#define LYNQ_REQUEST_SET_DEFAULT_SIM_ALL (LYNQ_REQUEST_VENDOR_BASE + 8)
+
+#define LYNQ_REQUEST_SET_SPEECH_VOLUME (LYNQ_REQUEST_VENDOR_BASE +9)
+#define LYNQ_REQUEST_GET_SPEECH_VOLUME (LYNQ_REQUEST_VENDOR_BASE +10)
+#define LYNQ_REQUEST_RECORD (LYNQ_REQUEST_VENDOR_BASE +11)
+#define LYNQ_REQUEST_OOS_RECOVER_TIMER_INTERVAL (LYNQ_REQUEST_VENDOR_BASE +12)
+#define LYNQ_REQUEST_OOS_DEEP_SLEEP_RECOVER_TIMER_INTERVAL (LYNQ_REQUEST_VENDOR_BASE +13)
+#define LYNQ_REQUEST_CHANGE_SCREEN_STATE (LYNQ_REQUEST_VENDOR_BASE + 14)/*jb.qi add for two sim suspend 2022/9/19*/
+#define LYNQ_REQUEST_CHANGE_RADIO (LYNQ_REQUEST_VENDOR_BASE + 15)
+/*the same with lynq_interface.h end*/
+
+typedef enum{
+ /*base abnormal*/
+ LYNQ_E_PARAMETER_ANONALY=7000,
+ LYNQ_E_SEND_REQUEST_FAIL=7001,
+ LYNQ_E_GET_HEAD_ERROR=7002,
+ LYNQ_E_INNER_ERROR=7100,
+ LYNQ_E_MALLOC_ERROR=7101,
+ /**/
+ LYNQ_E_CARDSTATE_ERROR=8000,
+ /* The voice service state is out of service*/
+ LYNQ_E_STATE_OUT_OF_SERVICE=8001,
+ /* The voice service state is EMERGENCY_ONLY*/
+ LYNQ_E_STATE_EMERGENCY_ONLY=8002,
+ /* The radio power is power off*/
+ LYNQ_E_STATE_POWER_OFF=8003,
+ LYNQ_E_TIME_OUT=8004,
+ /*create or open sms DB fail */
+ LYNQ_E_SMS_DB_FAIL=8005,
+ /*Failed to execute sql statement*/
+ LYNQ_E_SMS_SQL_FAIL = 8006,
+ LYNQ_E_SMS_NOT_FIND = 8007,
+ /* The logic conflict*/
+ LYNQ_E_CONFLICT=9000,
+ /*Null anomaly*/
+ LYNQ_E_NULL_ANONALY=9001,
+ /*Invalid id anomaly*/
+ LYNQ_E_INVALID_ID_ANONALY=9002,
+#ifdef ECALL_SUPPORT
+ LYNQ_E_ECALL_BEING_RUNNING =9003,
+ LYNQ_E_ECALL_MSD_LENGTH_ERROR =9004,
+ LYNQ_E_ECALL_DAILING_NO_ANSWER =9005,
+#endif
+}LYNQ_E;
+
+#define MODULE_CLOSED (0)
+#define MODULE_SWITCHING (1)
+#define MODULE_RUNNING (2)
+
+extern int g_module_init_flag;
+
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_socket.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_socket.cpp
new file mode 100755
index 0000000..ff45c02
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_socket.cpp
@@ -0,0 +1,1015 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <string.h>
+#include <unistd.h>
+#include <binder/Parcel.h>
+#include <log/log.h>
+#include <cutils/jstring.h>
+#include <pthread.h>
+#include <list>
+#include <vendor-ril/telephony/ril.h>
+#include <vendor-ril/telephony/mtk_ril_sp.h>
+#include "lynq_call.h"
+#include "lynq_module_common.h"
+#include "lynq_module_socket.h"
+#include "liblog/lynq_deflog.h"
+#include "lynq_shm.h"
+
+#define LYNQ_SERVICE_PORT 8088
+#define LYNQ_ADDRESS "127.0.0.1"
+#define LYNQ_URC_SERVICE_PORT 8086
+#define LYNQ_URC_ADDRESS "0.0.0.0"
+#define LYNQ_REQUEST_PARAM_BUF 8192
+#define LYNQ_REC_BUF 8192
+
+#define USER_LOG_TAG "LYNQ_NETWORK"
+
+typedef struct{
+ int uToken;
+ int request;
+ int paramLen;
+ char param[LYNQ_REQUEST_PARAM_BUF];
+}lynq_client_t;
+
+typedef struct{
+ int resp_type;
+ int token;
+ int request;
+ int slot_id;
+ int error;
+}lynq_resp_t;
+
+typedef struct{
+ int resp_type;
+ int urcid;
+}lynq_head_t;
+
+lynq_client_t client_t;
+lynq_resp_t response;
+
+int module_len_rc_addr_serv;
+int module_len_urc_addr_serv;
+struct sockaddr_in module_rc_addr_serv;
+struct sockaddr_in module_urc_addr_serv;
+static int module_rc_sock_fd = -1;
+static int module_urc_sock_fd = -1;
+int module_urc_status = 1;
+int module_rc_status = 1;
+pthread_t module_urc_tid = -1;
+pthread_t module_rc_tid = -1;
+static pthread_mutex_t s_urc_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/*hq add for set waiting time 2022/09/13 begin*/
+static pthread_mutex_t s_sendto_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t s_RecvMsgBlockMutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t s_WaitRecvMsgCond = PTHREAD_COND_INITIALIZER;
+#define BLOCK_RECV_MSG_LOCK() pthread_mutex_lock(&s_RecvMsgBlockMutex)
+#define BLOCK_RECV_MSG_UNLOCK() pthread_mutex_unlock(&s_RecvMsgBlockMutex)
+#define BLOCK_WAIT_RECV_MSG_TIME_OUT(a) pthread_cond_timedwait(&s_WaitRecvMsgCond, &s_RecvMsgBlockMutex,(a))
+#define BLOCK_WAKEUP_RECV_MSG() pthread_cond_broadcast(&s_WaitRecvMsgCond)
+static std::list<Parcel*> s_recv_parcel_list;
+const int waitResponse(int token,int time_out);
+/*hq add for set waiting time 2022/09/13 end*/
+
+/*hq add for urc process asynchronous 2022/12/26 begin*/
+static pthread_mutex_t s_ProcessUrcMsgBlockMutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t s_WaitProcessUrcMsgCond = PTHREAD_COND_INITIALIZER;
+
+#define BLOCK_PROCESS_URC_MSG_INIT() pthread_mutex_init(&s_ProcessUrcMsgBlockMutex,NULL)
+#define BLOCK_PROCESS_URC_MSG_LOCK() pthread_mutex_lock(&s_ProcessUrcMsgBlockMutex)
+#define BLOCK_PROCESS_URC_MSG_UNLOCK() pthread_mutex_unlock(&s_ProcessUrcMsgBlockMutex)
+#define BLOCK_WAIT_PROCESS_URC_MSG() pthread_cond_wait(&s_WaitProcessUrcMsgCond, &s_ProcessUrcMsgBlockMutex)
+#define BLOCK_WAKEUP_PROCESS_URC_MSG() pthread_cond_broadcast(&s_WaitProcessUrcMsgCond)
+static std::list<Parcel*> s_recv_urc_parcel_list;
+void *thread_urc_process(void *p);
+pthread_t module_urc_process_tid = -1;
+int module_urc_process_status = 1;
+/*hq add for urc process asynchronous 2022/12/26 end*/
+
+int g_module_Global_uToken = 0;
+int g_wait_time=5;
+
+/*inner test*/
+static int s_inner_test=0;
+
+/**@brief just for inner test
+* @param test_mode [IN]: test mode
+* 0:success
+* other:failure
+*/
+void lynq_set_test_mode(const int test_mode)
+{
+ if(test_mode<0)
+ {
+ g_wait_time = -test_mode;
+ }
+ else if(test_mode==9999)
+ {
+ LYERRLOG("%s inner test para %d %d",__func__,s_inner_test,g_wait_time);
+ }
+ else
+ {
+ s_inner_test = test_mode;
+ }
+}
+
+void cleanup_RecvMsgBlock_mutex(void *arg)
+{
+ BLOCK_RECV_MSG_UNLOCK();
+}
+
+/**@brief wait response with expected token and write msg to parcel in some time
+* @param p [IN]: pointer the parcel
+* @param token [IN]: the expected token for the response msg
+* @param time_out [IN]: timeout.
+* @return
+* 0:success
+* other:failure
+*/
+const int waitResponse(Parcel*& p, int token,int time_out)
+{
+ int waitToken = token;
+ int wakeup_token=-1;
+ int resp_type;
+ struct timeval now;
+ struct timespec timeout;
+ int ret;
+ std::list<Parcel*>::iterator iter;
+ int cnt=0;
+
+ gettimeofday(&now,NULL);
+ timeout.tv_sec = now.tv_sec+time_out; //timeout is 1min
+ timeout.tv_nsec = now.tv_usec*1000;
+
+ LYINFLOG("%s wait token is %d, wait time is %d",__func__,waitToken,time_out);
+
+ BLOCK_RECV_MSG_LOCK();
+ pthread_cleanup_push(cleanup_RecvMsgBlock_mutex, NULL); // thread cleanup handler
+ while(module_rc_status) {
+ cnt++;
+ for(iter=s_recv_parcel_list.begin();iter!=s_recv_parcel_list.end();++iter)
+ {
+ (*iter)->setDataPosition(0);
+ (*iter)->readInt32(&resp_type);
+ (*iter)->readInt32(&wakeup_token);
+ if(wakeup_token==waitToken)
+ {
+ LYINFLOG("%s get waitToken",__func__);
+ p=(*iter);
+ p->setDataPosition(0);
+ s_recv_parcel_list.erase(iter);
+ goto waitResponse_end;
+ }
+ }
+ LYINFLOG("%s no wait Token in msg list, list size is %d",__func__,s_recv_parcel_list.size());
+ ret=BLOCK_WAIT_RECV_MSG_TIME_OUT(&timeout);
+ if(ret!=0)
+ {
+ LYERRLOG("%s no expected token %d after %d second",__func__,waitToken,time_out);
+ break;
+ }
+ }
+waitResponse_end:
+ LYINFLOG("%s wait token is %d wakeup_token is %d, cnt is %d",__func__,waitToken,wakeup_token,cnt);
+ pthread_cleanup_pop(0);
+ BLOCK_RECV_MSG_UNLOCK();
+ return wakeup_token==waitToken ? 0:LYNQ_E_TIME_OUT;
+}
+
+/**@brief print solicied response msg's head information
+* @param head [IN]: head information
+* @return none
+*/
+void PrintHeader(lynq_resp_t& head)
+{
+ LYINFLOG("resp_type=%d,token=%d,request=%d,slot_id=%d,error_code=%d",head.resp_type,head.token,head.request,head.slot_id,head.error);
+}
+
+/**@brief get solicied response msg's head
+* @param head [OUT]: head information
+* @return
+* 0:success
+* other:failure
+*/
+int GetHeader(Parcel* &p, lynq_resp_t& head)
+{
+ LYINFLOG("get header");
+ if(p->dataAvail() > 0)
+ {
+ p->readInt32(&(head.resp_type));
+ p->readInt32(&(head.token));
+ p->readInt32(&(head.request));
+ p->readInt32(&(head.slot_id));
+ p->readInt32(&(head.error));
+ PrintHeader(head);
+ return RESULT_OK;
+ }
+ else
+ {
+ return RESULT_ERROR;
+ }
+}
+
+/**@brief send msg to service and get response from service
+* @param request_id [IN]: request id
+* @param time_out [IN]: wait time uplimit
+* @param p [IN]: point to response msg's parcel
+* @param argc [IN]: how many parameters in parameter string
+* @param format [IN]: parameter string's format
+* @param ... [IN]: the specific parameter
+* @return
+* 0:success
+* other:failure
+*/
+int lynq_send_common_request(Parcel*& p, int time_out, int request_id, int argc, const char* format,...)
+{
+ lynq_client_t client;
+ int ret;
+ int send_num;
+
+ client.uToken = g_module_Global_uToken;
+ g_module_Global_uToken=(g_module_Global_uToken+1)%10000;/*0-10000*/
+ client.request = request_id;
+ client.paramLen = argc;
+ bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
+ if(argc!=0)
+ {
+ va_list args;
+ va_start(args, format);
+ vsnprintf(client.param, LYNQ_REQUEST_PARAM_BUF, format, args);
+ va_end(args);
+ }
+ LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
+ pthread_mutex_lock(&s_sendto_mutex);
+ if(s_inner_test==1)
+ {
+ send_num = 1;
+ }
+ else
+ {
+ send_num = sendto(module_rc_sock_fd,&client,sizeof(client),0,(struct sockaddr *)&module_rc_addr_serv,module_len_rc_addr_serv);
+ }
+ if(s_inner_test>=1000)
+ {
+ time_out = s_inner_test-1000;
+ }
+ pthread_mutex_unlock(&s_sendto_mutex);
+
+ if(send_num <= 0)
+ {
+ LYERRLOG("send request fail, send num is %d", send_num);
+ return LYNQ_E_SEND_REQUEST_FAIL;
+ }
+ ret = waitResponse(p, client.uToken,time_out);
+
+ if(ret==0)
+ {
+ lynq_resp_t head;
+ ret=GetHeader(p,head);
+ if(ret!=0)
+ {
+ LYERRLOG("%s %d get head error %d",__func__,client.uToken,ret);
+ delete p;
+ return LYNQ_E_GET_HEAD_ERROR;
+ }
+ if(head.error!=0)
+ {
+ LYERRLOG("%s %d mdm return head error %d",__func__,client.uToken,head.error);
+ delete p;
+ return head.error;
+ }
+ LYERRLOG("%s %d suc",__func__,client.uToken);
+ return RESULT_OK;
+ }
+
+ LYERRLOG("%s %d fail, ret is %d",__func__,client.uToken,ret);
+
+ return ret;
+}
+
+/*hq add for urc broadcase optimisson 2023/01/03 begin*/
+#define SHM_BUFFER_INDEX_OFFSET 1
+#define SHM_BUFFER_SIZE_OFFSET 16
+#define SHM_BUFFER_INDEX_MASK 0x0000007F
+#define SHM_BUFFER_SIZE_MASK 0x0000FFFF
+
+bool urc_data_is_in_shm_data(int responseType,int& level, int& index, int& size)
+{
+ int shm_index=((responseType>>SHM_BUFFER_INDEX_OFFSET)&SHM_BUFFER_INDEX_MASK);
+ if (shm_index>0)
+ {
+ index=shm_index-1;
+ size=((responseType>>SHM_BUFFER_SIZE_OFFSET)&SHM_BUFFER_SIZE_MASK);
+ if(size>=sizeof(int32_t)*3 && get_shem_buffer_level(size,&level))
+ {
+ LYINFLOG("urc_data_is_in_shm_data level is %d, index is %d size is %d",level,index,size);
+ return true;
+ }
+ }
+ LYINFLOG("urc_data_is_in_shm_data return false, responseType is %d",responseType);
+ return false;
+}
+/*hq add for urc broadcase optimisson 2023/01/03 end*/
+
+void *thread_urc_recv(void *p)
+{
+ Parcel *urc_p =NULL;
+ char urc_data[LYNQ_REC_BUF];
+ int res = 0;
+ lynq_head_t* phead;
+ int level,index,size;
+ uint8_t * shm_buffer;
+
+ LYINFLOG("urc recv thread is running");
+ while(module_urc_status)
+ {
+ bzero(urc_data,LYNQ_REC_BUF);
+ res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);
+ if(res<sizeof(int32_t)*2)
+ {
+ LYERRLOG("thread_urc_recv step2 fail: res is %d",res);
+ continue;
+ }
+
+ phead=(lynq_head_t*) urc_data;
+ if(is_support_urc(phead->urcid)==false)
+ {
+ continue;
+ }
+ urc_p = new Parcel();
+ if(urc_p == NULL)
+ {
+ LYERRLOG("new parcel failure!!!");
+ continue;
+ }
+ if(urc_data_is_in_shm_data(phead->resp_type,level,index,size))
+ {
+ shm_buffer = (uint8_t *) get_shem_buffer(level,index);
+ LYINFLOG("shm pointer is %p", shm_buffer);
+ urc_p->setData(shm_buffer,size); // p.setData((uint8_t *) buffer, buflen);
+ }
+ else if(res>=sizeof(int32_t)*3)
+ {
+ urc_p->setData((uint8_t *)urc_data,res); // p.setData((uint8_t *) buffer, buflen);
+ }
+ else
+ {
+ LYERRLOG("res %d error!!!", res);
+ delete urc_p;
+ urc_p = NULL;
+ continue;
+ }
+ urc_p->setDataPosition(0);
+ if(urc_p->dataAvail()>0)
+ {
+ BLOCK_PROCESS_URC_MSG_LOCK();
+ s_recv_urc_parcel_list.push_back(urc_p);
+ BLOCK_WAKEUP_PROCESS_URC_MSG();
+ BLOCK_PROCESS_URC_MSG_UNLOCK();
+ }
+ else
+ {
+ delete urc_p;
+ urc_p = NULL;
+ }
+ }
+ LYINFLOG("urc recv thread ended");
+ return NULL;
+}
+
+void cleanup_urc_process_mutex(void *arg)
+{
+ BLOCK_PROCESS_URC_MSG_UNLOCK();
+}
+
+void *thread_urc_process(void *p)
+{
+ Parcel *urc_p =NULL;
+ std::list<Parcel*>::iterator iter;
+
+ LYINFLOG("urc process thread is running");
+ pthread_cleanup_push(cleanup_urc_process_mutex, NULL); // thread cleanup handler
+ while(module_urc_process_status)
+ {
+ BLOCK_PROCESS_URC_MSG_LOCK();
+ while(s_recv_urc_parcel_list.empty())
+ {
+ BLOCK_WAIT_PROCESS_URC_MSG();
+ }
+ iter=s_recv_urc_parcel_list.begin();
+ urc_p=(*iter);
+ s_recv_urc_parcel_list.erase(iter);
+ BLOCK_PROCESS_URC_MSG_UNLOCK();
+ urc_p->setDataPosition(0);
+ if(urc_p->dataAvail()>0)
+ {
+ pthread_mutex_lock(&s_urc_mutex);
+ urc_msg_process(urc_p);
+ pthread_mutex_unlock(&s_urc_mutex);
+ }
+ delete urc_p;
+ urc_p = NULL;
+ }
+ pthread_cleanup_pop(0);
+ LYINFLOG("urc process thread ended");
+ return NULL;
+}
+
+void lynq_close_urc_rev_thread()
+{
+ int ret;
+
+ BLOCK_PROCESS_URC_MSG_LOCK(); //just cancel urc process tid when recv from
+ module_urc_status = 0;
+ if(module_urc_tid!=-1)
+ {
+ ret = pthread_cancel(module_urc_tid);
+ LYINFLOG("pthread cancel urc rev ret = %d",ret);
+ }
+ BLOCK_PROCESS_URC_MSG_UNLOCK();
+ if(module_urc_tid != -1)
+ {
+ ret = pthread_join(module_urc_tid,NULL);
+ LYINFLOG("pthread join urc tid ret = %d",ret);
+ module_urc_tid =-1;
+ }
+}
+
+void lynq_close_urc_process_thread()
+{
+ int ret;
+ BLOCK_PROCESS_URC_MSG_LOCK(); //just cancel urc process tid when not process urc msg in list
+ pthread_mutex_lock(&s_urc_mutex); //just cancel urc process tid when not process urg msg avoid mutual lock for tid may call pthread_cond_wait
+ module_urc_process_status = 0;
+ if(module_urc_process_tid!=-1)
+ {
+ ret = pthread_cancel(module_urc_process_tid);
+ LYINFLOG("pthread cancel urc process ret = %d",ret);
+ }
+ pthread_mutex_unlock(&s_urc_mutex);
+ BLOCK_PROCESS_URC_MSG_UNLOCK();
+ if(module_urc_process_tid != -1)
+ {
+ ret = pthread_join(module_urc_process_tid,NULL);
+ LYINFLOG("pthread join urc process tid ret = %d",ret);
+ module_urc_process_tid =-1;
+ }
+}
+
+int lynq_setup_urc_socket()
+{
+ int on = 1;
+ int ret = 0;
+ module_len_urc_addr_serv = sizeof(sockaddr_in);
+ module_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (module_urc_sock_fd <0){
+ LYERRLOG("urc socket error");
+ return RESULT_ERROR;
+ }
+ module_urc_addr_serv.sin_family = AF_INET;
+ module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);
+ module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);
+ /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
+ ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
+ if(ret <0)
+ {
+ LYERRLOG("urc socket set error");
+ close(module_urc_sock_fd);
+ module_urc_sock_fd =-1;
+ return RESULT_ERROR;
+ }
+ ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));
+ if(ret <0)
+ {
+ LYERRLOG("urc socket bind error");
+ close(module_urc_sock_fd);
+ module_urc_sock_fd =-1;
+ return RESULT_ERROR;
+ }
+ return RESULT_OK;
+}
+
+void lynq_close_urc_socket()
+{
+ if (module_urc_sock_fd >= 0)
+ {
+ close(module_urc_sock_fd);
+ module_urc_sock_fd =-1;
+ }
+}
+
+int lynq_start_all_urc_socket_thread()
+{
+
+ if(ril_init_mem()!=0)
+ {
+ LYERRLOG("ril_init_mem fail");
+ return RESULT_ERROR;
+ }
+
+ int ret= lynq_setup_urc_socket();
+ if(ret!=RESULT_OK)
+ {
+ LYERRLOG("call lynq_setup_urc_socket fail");
+ ril_deinit_mem();
+ return RESULT_ERROR;
+ }
+
+ BLOCK_PROCESS_URC_MSG_INIT();
+ BLOCK_PROCESS_URC_MSG_LOCK();
+ std::list<Parcel*>::iterator iter;
+ for(iter=s_recv_urc_parcel_list.begin();iter!=s_recv_urc_parcel_list.end();++iter)
+ {
+ delete (*iter);
+ }
+ s_recv_urc_parcel_list.clear();
+ BLOCK_PROCESS_URC_MSG_UNLOCK();
+
+ pthread_mutex_init(&s_urc_mutex, NULL);
+
+ module_urc_status = 1;
+ // pthread_attr_init(&attr);
+ // pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ ret = pthread_create(&module_urc_tid,/*&attr*/NULL,thread_urc_recv,NULL);
+ if(ret <0)
+ {
+ LYERRLOG("urc recv pthread create error");
+ module_urc_status = 0;
+ lynq_close_urc_socket();
+ ril_deinit_mem();
+ return RESULT_ERROR;
+ }
+
+ module_urc_process_status = 1;
+ ret = pthread_create(&module_urc_process_tid,/*&attr*/NULL,thread_urc_process,NULL);
+ if(ret <0)
+ {
+ LYERRLOG("urc process pthread create error");
+ module_urc_process_status = 0;
+ lynq_close_urc_socket();
+ lynq_close_urc_rev_thread();
+ ril_deinit_mem();
+ return RESULT_ERROR;
+ }
+
+ LYINFLOG("urc start success");
+
+ return RESULT_OK;
+}
+
+void lynq_close_all_urc_socket_thread()
+{
+
+ lynq_close_urc_rev_thread();
+ lynq_close_urc_socket();
+ lynq_close_urc_process_thread();
+
+ BLOCK_PROCESS_URC_MSG_LOCK();
+ std::list<Parcel*>::iterator iter;
+ for(iter=s_recv_urc_parcel_list.begin();iter!=s_recv_urc_parcel_list.end();++iter)
+ {
+ delete (*iter);
+ }
+ s_recv_urc_parcel_list.clear();
+ BLOCK_PROCESS_URC_MSG_UNLOCK();
+
+ ril_deinit_mem();
+}
+
+/**@ a thread just for recv\buffer solicited msg's response and notice waiting thread
+* @param p [IN]: no meaning
+* @return
+* always null
+*/
+void *thread_rc_recv(void *p)
+{
+ Parcel* rc_p;
+ std::list<Parcel*>::iterator iter;
+ int resp_type = -1;
+ char rc_data[LYNQ_REC_BUF];
+ int rc_len;
+ int null_cnt=0;
+ int wakeup_token;
+
+ LYINFLOG("rc thread is running");
+ while(module_rc_status)
+ {
+ bzero(rc_data,LYNQ_REC_BUF);
+ while(true)
+ {
+ rc_len = recvfrom(module_rc_sock_fd,rc_data,sizeof(rc_data),0,(struct sockaddr *)&module_rc_addr_serv,(socklen_t *)&module_len_rc_addr_serv);
+ if(rc_len<sizeof(int32_t)*2)
+ {
+ LYERRLOG("%s recv len %d less %d",__func__, rc_len,sizeof(int)*2);
+ continue;
+ }
+ rc_p= new Parcel;
+ if(rc_p==NULL)
+ {
+ null_cnt++;
+ LYERRLOG("%s rc_p is NULL, cnt is %d",__func__, null_cnt);
+ if(null_cnt>20)
+ {
+ goto rc_recv_end;
+ }
+ continue;
+ }
+ else
+ {
+ null_cnt=0;
+ }
+
+ rc_p->setData((uint8_t *)rc_data,rc_len); // p.setData((uint8_t *) buffer, buflen);
+ rc_p->setDataPosition(0);
+ if(rc_p->dataAvail()>0)
+ {
+ rc_p->readInt32(&resp_type);
+ rc_p->readInt32(&wakeup_token);
+ BLOCK_RECV_MSG_LOCK();
+ s_recv_parcel_list.push_back(rc_p);
+ LYINFLOG("%s wakeup token is %d, list size is %d!",__func__,wakeup_token,s_recv_parcel_list.size());
+ if(s_recv_parcel_list.size()>20) //max 20
+ {
+ iter=s_recv_parcel_list.begin();
+ (*iter)->setDataPosition(0);
+ (*iter)->readInt32(&resp_type);
+ (*iter)->readInt32(&wakeup_token);
+ delete (*(s_recv_parcel_list.begin()));
+ LYERRLOG("%s wakeup token %d is deleted!",__func__,wakeup_token);
+ s_recv_parcel_list.erase(iter);
+ }
+ BLOCK_WAKEUP_RECV_MSG();
+ BLOCK_RECV_MSG_UNLOCK();
+ break;
+ }
+ else
+ {
+ LYERRLOG("%s rc_p data Avail %d not greater than 0",__func__, rc_p->dataAvail());
+ delete rc_p;
+ }
+ }
+ }
+
+rc_recv_end:
+ LYINFLOG("rc thread ended");
+ return NULL;
+}
+
+int lynq_start_all_rc_socket_thread()
+{
+ module_rc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if(module_rc_sock_fd < 0)
+ {
+ LYERRLOG("socket open error");
+ return -1;
+ }
+
+ LYINFLOG("module_rc_sock_fd = %d",module_rc_sock_fd);
+
+ memset(&module_rc_addr_serv, 0, sizeof(module_rc_addr_serv));
+ module_rc_addr_serv.sin_family = AF_INET;
+ module_rc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_ADDRESS);
+ module_rc_addr_serv.sin_port = htons(LYNQ_SERVICE_PORT);
+ module_len_rc_addr_serv = sizeof(module_rc_addr_serv);
+
+ BLOCK_RECV_MSG_LOCK();
+ std::list<Parcel*>::iterator iter;
+ for(iter=s_recv_parcel_list.begin();iter!=s_recv_parcel_list.end();++iter)
+ {
+ delete (*iter);
+ }
+ s_recv_parcel_list.clear();
+ BLOCK_RECV_MSG_UNLOCK();
+
+// pthread_attr_t attr;
+ int ret;
+
+ pthread_mutex_init(&s_sendto_mutex, NULL);
+ pthread_mutex_init(&s_RecvMsgBlockMutex, NULL);
+
+ module_rc_status = 1;
+// pthread_attr_init(&attr);
+// pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ ret = pthread_create(&module_rc_tid,/*&attr*/NULL,thread_rc_recv,NULL);
+ if(ret <0)
+ {
+ LYERRLOG("rc pthread create error");
+ module_rc_status =0;
+ close(module_rc_sock_fd);
+ module_rc_sock_fd =-1;
+ return ret;
+ }
+
+ LYINFLOG("rc start success");
+
+ return RESULT_OK;
+}
+
+void lynq_close_all_rc_socket_thread()
+{
+ int ret;
+ BLOCK_RECV_MSG_LOCK();
+ module_rc_status = 0;
+ BLOCK_WAKEUP_RECV_MSG();
+ if(module_rc_tid != -1)
+ {
+ ret = pthread_cancel(module_rc_tid);
+ LYINFLOG("pthread cancel rc ret = %d",ret);
+ }
+ BLOCK_RECV_MSG_UNLOCK();
+ if(module_rc_tid != -1)
+ {
+ ret = pthread_join(module_rc_tid,NULL);
+ module_rc_tid =-1;
+ LYINFLOG("pthread join rc tid ret = %d",ret);
+
+ }
+
+ if (module_rc_sock_fd > 0)
+ {
+ close(module_rc_sock_fd);
+ module_rc_sock_fd =-1;
+ }
+
+ BLOCK_RECV_MSG_LOCK();
+ std::list<Parcel*>::iterator iter;
+ for(iter=s_recv_parcel_list.begin();iter!=s_recv_parcel_list.end();++iter)
+ {
+ delete (*iter);
+ }
+ s_recv_parcel_list.clear();
+ BLOCK_RECV_MSG_UNLOCK();
+}
+
+const char * requestToString(int request)
+{
+ /*
+ cat libs/telephony/ril_commands.h \
+ | egrep "^ *{RIL_" \
+ | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
+
+
+ cat libs/telephony/ril_unsol_commands.h \
+ | egrep "^ *{RIL_" \
+ | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
+
+ */
+ switch(request) {
+ case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
+ case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
+ case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
+ case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
+ case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
+ case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
+ case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
+ case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
+ case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
+ case RIL_REQUEST_DIAL: return "DIAL";
+ case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
+ case RIL_REQUEST_HANGUP: return "HANGUP";
+ case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
+ case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
+ case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
+ case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
+ case RIL_REQUEST_UDUB: return "UDUB";
+ case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
+ case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
+ case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
+ case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
+ case RIL_REQUEST_OPERATOR: return "OPERATOR";
+ case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
+ case RIL_REQUEST_DTMF: return "DTMF";
+ case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
+ case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
+ case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
+ case RIL_REQUEST_SIM_IO: return "SIM_IO";
+ case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
+ case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
+ case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
+ case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
+ case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
+ case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
+ case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
+ case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
+ case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
+ case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
+ case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
+ case RIL_REQUEST_ANSWER: return "ANSWER";
+ case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
+ case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
+ case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
+ case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
+ case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
+ case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
+ case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
+ case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
+ case RIL_REQUEST_DTMF_START: return "DTMF_START";
+ case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
+ case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
+ case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
+ case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
+ case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
+ case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
+ case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
+ case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
+ case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
+ case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
+ case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
+ case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
+ case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
+ case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
+ case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
+ case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
+ case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
+ case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
+ case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
+ case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
+ case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
+ case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
+ case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
+ case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
+ case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
+ case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
+ case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
+ case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
+ case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
+ case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
+ case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
+ case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
+ case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
+ case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
+ case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
+ case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
+ case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
+ case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION:return "GSM_SMS_BROADCAST_ACTIVATION";
+ case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
+ case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
+ case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
+ case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
+ case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
+ case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
+ case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
+ case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
+ case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
+ case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
+ case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
+ case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
+ case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
+ case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
+ case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
+ case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
+ case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
+ case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
+ case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
+ case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
+ case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
+ case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
+ case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
+ case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
+ case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
+ case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
+ case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
+ case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
+ case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
+ case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
+ case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
+ case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
+ case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
+ case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
+ case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
+ case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
+ case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
+ case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
+ case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
+ case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
+ case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
+ case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
+ case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
+ case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
+ case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
+ case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
+ case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
+ case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
+ case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
+ case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
+ case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
+ case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
+ case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
+ case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
+ case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
+ case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
+ case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
+ case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
+ case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
+ case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
+ case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
+ case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
+ case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
+ case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
+ case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
+ case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
+ case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
+ case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
+ case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
+ case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
+ case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
+ case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
+ case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
+ case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
+ case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
+ case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
+ case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
+ case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
+ case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
+ case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
+ case RIL_REQUEST_SET_TRM: return "RIL_REQUEST_SET_TRM";
+ case RIL_REQUEST_SET_IMS_ENABLE:return "RIL_REQUEST_SET_IMS_ENABLE";
+ case RIL_REQUEST_SET_AUDIO_PATH: return "SET_AUDIO_PATH";
+ case RIL_REQUEST_HANGUP_ALL: return "HANGUP_ALL";
+ case RIL_REQUEST_FORCE_RELEASE_CALL: return "FORCE_RELEASE_CALL";
+ case RIL_REQUEST_EMERGENCY_DIAL: return "RIL_REQUEST_EMERGENCY_DIAL";
+ case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: return "RIL_REQUEST_SET_ECC_SERVICE_CATEGORY";
+ case RIL_REQUEST_SET_ECC_LIST: return "RIL_REQUEST_SET_ECC_LIST";
+ case RIL_REQUEST_AT_COMMAND_WITH_PROXY: return "AT_COMMAND_WITH_PROXY";
+ case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION";
+ case RIL_REQUEST_SET_CLIP: return "RIL_REQUEST_SET_CLIP";
+ case RIL_REQUEST_GET_COLP: return "RIL_REQUEST_GET_COLP";
+ case RIL_REQUEST_SET_COLP: return "RIL_REQUEST_SET_COLP";
+ case RIL_REQUEST_GET_COLR: return "RIL_REQUEST_GET_COLR";
+ case RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER: return "ADD_IMS_CONFERENCE_CALL_MEMBER";
+ case RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER: return "REMOVE_IMS_CONFERENCE_CALL_MEMBER";
+ case RIL_REQUEST_CONFERENCE_DIAL: return "CONFERENCE_DIAL";
+ case RIL_REQUEST_DIAL_WITH_SIP_URI: return "DIAL_WITH_SIP_URI";
+ case RIL_REQUEST_HOLD_CALL: return "HOLD_CALL";
+ case RIL_REQUEST_RESUME_CALL: return "RESUME_CALL";
+ case RIL_UNSOL_ECONF_SRVCC_INDICATION : return "ECONF_SRVCC_INDICATION";
+ case RIL_UNSOL_ECONF_RESULT_INDICATION : return "ECONF_RESULT_INDICATION";
+ case RIL_UNSOL_MAL_AT_INFO : return "UNSOL_MAL_AT_INFO";
+ case RIL_REQUEST_MODEM_POWEROFF: return "MODEM_POWEROFF";
+ case RIL_REQUEST_MODEM_POWERON: return "MODEM_POWERON";
+ case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
+ case RIL_REQUEST_QUERY_ICCID: return "RIL_REQUEST_QUERY_ICCID";
+ case RIL_UNSOL_TX_POWER: return "RIL_UNSOL_TX_POWER";
+ case RIL_UNSOL_NETWORK_INFO: return "RIL_UNSOL_NETWORK_INFO";
+ case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
+ case RIL_REQUEST_SET_IMSCFG: return "RIL_REQUEST_SET_IMSCFG";
+#ifdef ECALL_SUPPORT
+ case RIL_REQUEST_ECALL_FAST_MAKE_ECALL: return "ECALL_FAST_MAKE_ECALL";
+ case RIL_REQUEST_ECALL_SET_IVS: return "RIL_REQUEST_ECALL_SET_IVS";
+ case RIL_REQUEST_ECALL_SET_PSAP: return "RIL_REQUEST_ECALL_SET_PSAP";
+ case RIL_REQUEST_ECALL_MAKE_ECALL: return "RIL_REQUEST_ECALL_MAKE_ECALL";
+ case RIL_REQUEST_ECALL_IVS_PUSH_MSD: return "RIL_REQUEST_ECALL_IVS_PUSH_MSD";
+ case RIL_REQUEST_ECALL_PSAP_PULL_MSD: return "RIL_REQUEST_ECALL_PSAP_PULL_MSD";
+ case RIL_UNSOL_ECALL_MSDHACK : return "ECALL_MSDHACK";
+ case RIL_REQUEST_ECALL_SET_MSD: return "RIL_REQUEST_ECALL_SET_MSD";
+ case RIL_REQUEST_ECALL_CTRL_SEQUENCE: return "ECALL_SET_CTRL_SEQUENCE";
+ case RIL_UNSOL_ECALL_INDICATIONS : return "ECALL_INDICATIONS";
+ case RIL_REQUEST_ECALL_RESET_IVS: return "RIL_REQUEST_ECALL_RESET_IVS";
+ case RIL_REQUEST_ECALL_SET_PRI: return "RIL_REQUEST_ECALL_SET_PRI";
+ case RIL_REQUEST_ECALL_SET_TEST_NUM: return "RIL_REQUEST_ECALL_SET_TEST_NUM";
+ case RIL_REQUEST_ECALL_SET_RECONF_NUM: return "RIL_REQUEST_ECALL_SET_RECONF_NUM";
+ case RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD: return "RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD";
+ case RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME: return "RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME";
+ case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: return "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE";
+#endif /*ECALL_SUPPORT*/
+#ifdef KEEP_ALIVE
+ case RIL_REQUEST_START_KEEPALIVE_PRO: return "RIL_REQUEST_START_KEEPALIVE_PRO";
+ case RIL_REQUEST_STOP_KEEPALIVE_PRO: return "RIL_REQUEST_STOP_KEEPALIVE_PRO";
+ case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return "RIL_UNSOL_KEEPALIVE_STATUS_PRO";
+#endif /*KEEP_ALIVE*/
+ case RIL_REQUEST_SEND_USSI: return "SEND_USSI";
+ case RIL_REQUEST_CANCEL_USSI: return "CANCEL_USSI";
+ case RIL_REQUEST_GET_SMS_SIM_MEM_STATUS: return "GET_SMS_SIM_MEM_STATUS";
+ case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return "RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR";
+ case RIL_REQUEST_REPORT_AIRPLANE_MODE: return "RIL_REQUEST_REPORT_AIRPLANE_MODE";
+ case RIL_REQUEST_SET_ECC_NUM: return "RIL_REQUEST_SET_ECC_NUM";
+ case RIL_REQUEST_GET_ECC_NUM: return "RIL_REQUEST_GET_ECC_NUM";
+ case RIL_UNSOL_ECC_NUM: return "RIL_UNSOL_ECC_NUM";
+ case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT: return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT";
+ case RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE";
+ case RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE";
+ case RIL_UNSOL_CALL_INFO_INDICATION: return "RIL_UNSOL_CALL_INFO_INDICATION";
+ case RIL_REQUEST_MODIFY_APN: return "RIL_REQUEST_MODIFY_APN";
+ case RIL_REQUEST_RESET_APN: return "RIL_REQUEST_RESET_APN";
+ case RIL_REQUEST_QUERY_SIM_RETRY_COUNT: return "RIL_REQUEST_QUERY_SIM_RETRY_COUNT";
+ case RIL_REQUEST_QUERY_EID: return "RIL_REQUEST_QUERY_EID";
+ case LYNQ_REQUEST_SET_DTMF_VOLUME: return "RIL_REQUEST_SET_DTMF_VOLUME";
+ case LYNQ_REQUEST_SET_SPEECH_VOLUME: return "RIL_REQUEST_SET_SPEECH_VOLUME";
+ case LYNQ_REQUEST_GET_SPEECH_VOLUME: return "RIL_REQUEST_GET_SPEECH_VOLUME";
+ case LYNQ_REQUEST_RECORD: return "RIL_REQUEST_RECORD";
+ /*warren add for t800 ril service 2022/1/22 start*/
+ case LYNQ_REQUEST_WRITE_SMS_TO_MEMORY: return "LYNQ_REQUEST_WRITE_SMS_TO_MEMORY";
+ case LYNQ_REQUEST_READ_SMS_FROM_MEMORY: return "LYNQ_REQUEST_READ_SMS_FROM_MEMORY";
+ case LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY: return "LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY";
+ case LYNQ_REQUEST_LIST_SMS_FROM_MEMORY: return "LYNQ_REQUEST_LIST_SMS_FROM_MEMORY";
+ case LYNQ_REQUEST_SET_DEFAULT_SIM_ALL:return "SET_DEFAULT_SIM_ALL";
+ case LYNQ_REQUEST_CHANGE_SCREEN_STATE:return "LYNQ_REQUEST_CHANGE_SCREEN_STATE";/*jb.qi add for two sim sleep 2022/9/19*/
+ case LYNQ_REQUEST_CHANGE_RADIO:return "LYNQ_REQUEST_CHANGE_RADIO";/*lei add for factory test of sleep 2022/9/19*/
+ /*warren add for t800 ril service 2022/1/22 end*/
+ default: return "<unknown request>";
+ }
+}
+
+
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_socket.h b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_socket.h
new file mode 100755
index 0000000..41c0d1c
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/lynq_module_socket.h
@@ -0,0 +1,21 @@
+#ifndef LYNQ_MODULE_SOCKET_H
+#define LYNQ_MODULE_SOCKET_H
+
+using ::android::Parcel;
+
+int lynq_set_test_network(const int test_mode);
+
+extern int g_module_Global_uToken;
+extern int g_wait_time;
+int lynq_send_common_request(Parcel*& p, int time_out, int request_id, int argc, const char* format,...);
+int lynq_start_all_urc_socket_thread();
+void lynq_close_all_urc_socket_thread();
+int lynq_start_all_rc_socket_thread();
+void lynq_close_all_rc_socket_thread();
+
+const char * requestToString(int request);
+
+void urc_msg_process(Parcel *p);
+bool is_support_urc(int urc_id);
+
+#endif
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-call/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-call/makefile
new file mode 100755
index 0000000..21e0cb5
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-call/makefile
@@ -0,0 +1,75 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+ -std=c++11 \
+ -g -Os \
+ -flto \
+ -DRIL_SHLIB \
+ -DATCI_PARSE \
+ -fPIC \
+ -DKEEP_ALIVE \
+ -DECALL_SUPPORT \
+ -fpermissive \
+
+
+ifeq ($(strip $(TARGET_PLATFORM)), T106)
+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -DHAVE_ENDIAN_H -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_POSIX_FILEMAP -DHAVE_STRLCPY -DHAVE_PRCTL -DHAVE_MEMSET16 -DHAVE_MEMSET32 -DANDROID_SMP=0
+endif
+
+$(warning ################# lynq data demo ROOT: $(ROOT),includedir:$(includedir))
+LOCAL_PATH = .
+
+LOCAL_C_INCLUDES = \
+ -I. \
+ -I$(LOCAL_PATH)/include/libcall \
+ -I$(ROOT)$(includedir)/logger \
+ -I$(ROOT)$(includedir)/liblog \
+ -I$(ROOT)$(includedir)/vendor-ril \
+ -I$(ROOT)$(includedir)/lynq_shm \
+
+
+LOCAL_LIBS := \
+ -L. \
+ -ldl \
+ -lstdc++ \
+ -llog \
+ -lcutils \
+ -lutils \
+ -lbinder \
+ -lpthread \
+ -llynq-log \
+ -llynq-shm \
+
+SOURCES = $(wildcard *.cpp)
+
+EXECUTABLE = liblynq-call.so
+
+OBJECTS=$(SOURCES:.cpp=.o)
+
+
+.PHONY: build clean install pack_rootfs
+all: build
+$(EXECUTABLE): $(OBJECTS)
+ $(CXX) -shared -Wl,--no-undefined $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.cpp
+ $(CXX) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+build: $(EXECUTABLE)
+ $(warning ########## build $(EXECUTABLE) ##########)
+install:
+ mkdir -p $(ROOT)$(base_libdir)/
+ install $(EXECUTABLE) $(ROOT)$(base_libdir)/
+ mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk
+pack_rootfs:
+ mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/
+ cp -af $(EXECUTABLE) $(PACK_INITRAMFS_TO)$(base_libdir)/
+ $(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(EXECUTABLE)
+ mkdir -p $(PACK_TO)$(base_libdir)/
+ cp -af $(EXECUTABLE) $(PACK_TO)$(base_libdir)/
+ $(CROSS)strip $(PACK_TO)$(base_libdir)/$(EXECUTABLE)
+.PHONY: clean
+clean:
+ $(RM) $(OBJECTS) $(EXECUTABLE)
+ -find . -name "*.o" -delete