[Feature] add GA346 baseline version
Change-Id: Ic62933698569507dcf98240cdf5d9931ae34348f
diff --git a/src/telephonyware/3.0/hardware/ril/fusion/rild/Android.mk b/src/telephonyware/3.0/hardware/ril/fusion/rild/Android.mk
new file mode 100644
index 0000000..2c74b88
--- /dev/null
+++ b/src/telephonyware/3.0/hardware/ril/fusion/rild/Android.mk
@@ -0,0 +1,73 @@
+# Copyright 2006 The Android Open Source Project
+
+ifeq ($(MTK_RIL_MODE), c6m_1rild)
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ rild.c
+
+
+LOCAL_SHARED_LIBRARIES := \
+ libmtkrillog \
+ libmtkproperty \
+ libmtkcutils \
+ librilfusion \
+ libmtkrilutils \
+ libsysenv \
+ libmtkconfigutils
+
+LOCAL_CFLAGS := -DRIL_SHLIB
+
+# remove the below on the platform that not support sysenv
+LOCAL_CFLAGS += -DMTK_SYSENV_SUPPORT
+LOCAL_SHARED_LIBRARIES += liblog
+
+ifneq ($(MTK_NUM_MODEM_PROTOCOL),1)
+ LOCAL_CFLAGS += -DANDROID_MULTI_SIM
+endif
+
+ifeq ($(MTK_NUM_MODEM_PROTOCOL), 2)
+ LOCAL_CFLAGS += -DANDROID_SIM_COUNT_2
+endif
+
+ifeq ($(MTK_NUM_MODEM_PROTOCOL), 3)
+ LOCAL_CFLAGS += -DANDROID_SIM_COUNT_3
+endif
+
+ifeq ($(MTK_NUM_MODEM_PROTOCOL), 4)
+ LOCAL_CFLAGS += -DANDROID_SIM_COUNT_4
+endif
+
+ifeq ("$(wildcard vendor/mediatek/internal/mtkrild_enable)","")
+ LOCAL_CFLAGS += -D__PRODUCTION_RELEASE__
+endif
+
+LOCAL_CFLAGS += -DMTK_MUX_CHANNEL_64
+LOCAL_CFLAGS += -DMTK_IMS_CHANNEL_SUPPORT
+LOCAL_CFLAGS += -DMTK_USE_HIDL
+#used to check if support telephonyware
+LOCAL_CFLAGS += -DMTK_TELEPHONYWARE_SUPPORT
+
+LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/librilfusion \
+ $(MTK_PATH_SOURCE)/external/libsysenv \
+ $(TOP)/$(MTK_PATH_SOURCE)/hardware/ril/platformlib/include/log \
+ $(TOP)/$(MTK_PATH_SOURCE)/hardware/ril/platformlib/include/property \
+ $(TOP)/$(MTK_PATH_SOURCE)/hardware/ril/platformlib/include \
+ $(TOP)/$(MTK_PATH_SOURCE)/hardware/ril/platformlib/include/utils \
+ $(TOP)/$(MTK_PATH_SOURCE)/hardware/ril/platformlib/include/config \
+
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../include
+
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE:= mtkfusionrild
+LOCAL_PROPRIETARY_MODULE := true
+LOCAL_MODULE_OWNER := mtk
+LOCAL_MODULE_TAGS := optional
+LOCAL_INIT_RC := rild.rc
+
+LOCAL_MULTILIB := first
+
+include $(MTK_EXECUTABLE)
+endif
diff --git a/src/telephonyware/3.0/hardware/ril/fusion/rild/CMakeLists.txt b/src/telephonyware/3.0/hardware/ril/fusion/rild/CMakeLists.txt
new file mode 100644
index 0000000..60dbcdb
--- /dev/null
+++ b/src/telephonyware/3.0/hardware/ril/fusion/rild/CMakeLists.txt
@@ -0,0 +1,38 @@
+cmake_minimum_required(VERSION 2.6)
+project(mtkfusionrild)
+
+#add complie options
+set(CMAKE_COMMON_FLAGS " -D__unused= -Wall -DRIL_SHLIB -D_GNU_SOURCE \
+ -DMTK_TELEPHONYWARE_SUPPORT -DMTK_MUX_CHANNEL_64 \
+ -DMTK_IMS_CHANNEL_SUPPORT -DENABLE_TRM")
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_COMMON_FLAGS} -std=c99 -Wl,--no-undefined -D_LINUX")
+#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_COMMON_FLAGS} -std=gnu++14")
+
+#add header files (-I -L)
+include_directories("${MIPC_MSG_INCDIR}/msg")
+include_directories("${MIPC_MSG_INCDIR}/common")
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../include/")
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../include/")
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../fusion/libril/")
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../platformlib/include/log")
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../platformlib/include/property")
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../platformlib/include")
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../platformlib/include/utils")
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../platformlib/include/config")
+include_directories("${MIPC_MSG_INCDIR}/common")
+include_directories("${MIPC_MSG_INCDIR}/msg")
+include_directories("${MIPC_MSG_INCDIR}/external")
+
+#add source file
+set(src_fils rild.c)
+
+add_executable(mtkfusionrild ${src_fils})
+set(link_libs rilfusion mtkrilutils mtkconfigutils mtkcutils mtkproperty mipc_api dl)
+target_link_libraries(mtkfusionrild ${link_libs})
+
+#install
+install(TARGETS mtkfusionrild
+ RUNTIME DESTINATION sbin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
diff --git a/src/telephonyware/3.0/hardware/ril/fusion/rild/MODULE_LICENSE_APACHE2 b/src/telephonyware/3.0/hardware/ril/fusion/rild/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/telephonyware/3.0/hardware/ril/fusion/rild/MODULE_LICENSE_APACHE2
diff --git a/src/telephonyware/3.0/hardware/ril/fusion/rild/NOTICE b/src/telephonyware/3.0/hardware/ril/fusion/rild/NOTICE
new file mode 100644
index 0000000..73a4560
--- /dev/null
+++ b/src/telephonyware/3.0/hardware/ril/fusion/rild/NOTICE
@@ -0,0 +1,183 @@
+
+Copyright 2006 The Android Open Source Project
+Copyright 2006, The Android Open Source Project
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+
+
diff --git a/src/telephonyware/3.0/hardware/ril/fusion/rild/README b/src/telephonyware/3.0/hardware/ril/fusion/rild/README
new file mode 100644
index 0000000..4c5313a
--- /dev/null
+++ b/src/telephonyware/3.0/hardware/ril/fusion/rild/README
@@ -0,0 +1,13 @@
+WHAT IT DOES?
+=============
+MTK RIL Proxy process
+
+HOW IT WAS BUILT?
+==================
+This module is source code released.
+
+HOW TO USE IT?
+==============
+MTK ril proxy daemon is an executable process and is started by GSM rild process.
+
+All the source code of this folder were written by MediaTek co..
\ No newline at end of file
diff --git a/src/telephonyware/3.0/hardware/ril/fusion/rild/radiooptions.c b/src/telephonyware/3.0/hardware/ril/fusion/rild/radiooptions.c
new file mode 100644
index 0000000..2cf3511
--- /dev/null
+++ b/src/telephonyware/3.0/hardware/ril/fusion/rild/radiooptions.c
@@ -0,0 +1,149 @@
+/* //device/system/toolbox/resetradio.c
+**
+** Copyright 2006, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <cutils/sockets.h>
+
+#define SOCKET_NAME_RIL_DEBUG "rild-debug" /* from ril.cpp */
+#define SOCKET_NAME_RIL2_DEBUG "rild2-debug"
+
+enum options {
+ RADIO_RESET,
+ RADIO_OFF,
+ UNSOL_NETWORK_STATE_CHANGE,
+ QXDM_ENABLE,
+ QXDM_DISABLE,
+ RADIO_ON,
+ SETUP_PDP,
+ DEACTIVATE_PDP,
+ DIAL_CALL,
+ ANSWER_CALL,
+ END_CALL,
+};
+
+
+static void print_usage() {
+ perror("Usage: radiooptions [option] [extra_socket_args]\n\
+ 0 - RADIO_RESET, \n\
+ 1 - RADIO_OFF, \n\
+ 2 - UNSOL_NETWORK_STATE_CHANGE, \n\
+ 3 - QXDM_ENABLE, \n\
+ 4 - QXDM_DISABLE, \n\
+ 5 - RADIO_ON, \n\
+ 6 apn- SETUP_PDP apn, \n\
+ 7 - DEACTIVE_PDP, \n\
+ 8 number - DIAL_CALL number, \n\
+ 9 - ANSWER_CALL, \n\
+ 10 - END_CALL \n\
+ The argument before the last one must be SIM slot \n\
+ 0 - SIM1, \n\
+ 1 - SIM2, \n\
+ 2 - SIM3, \n\
+ 3 - SIM4, \n\
+ The last argument must be modem-socket style \n\
+ 0 - one modem for one debug-socket, \n\
+ 1 - one modem for multiple debug socket \n");
+}
+
+static int error_check(int argc, char * argv[]) {
+ if (argc < 2) {
+ return -1;
+ }
+ const int option = atoi(argv[1]);
+ if (option < 0 || option > 10) {
+ return 0;
+ } else if ((option == DIAL_CALL || option == SETUP_PDP) && argc == 5) {
+ return 0;
+ } else if ((option != DIAL_CALL && option != SETUP_PDP) && argc == 4) {
+ return 0;
+ }
+ return -1;
+}
+
+static int get_number_args(char *argv[]) {
+ const int option = atoi(argv[1]);
+ if (option != DIAL_CALL && option != SETUP_PDP) {
+ return 3;
+ } else {
+ return 4;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int fd;
+ int num_socket_args = 0;
+ int i = 0;
+ int modem_socket_type = 0;
+ int sim_id = 0;
+ char socket_name[20];
+
+ if(error_check(argc, argv)) {
+ print_usage();
+ exit(-1);
+ }
+
+ num_socket_args = get_number_args(argv);
+ modem_socket_type = atoi(argv[(num_socket_args-1)]);
+ sim_id = atoi(argv[(num_socket_args-2)]);
+ memset(socket_name, 0, sizeof(char)*20);
+ if (sim_id == 0 || modem_socket_type == 1) {
+ strncpy(socket_name, SOCKET_NAME_RIL_DEBUG, 19);
+ } else if (sim_id == 1) {
+ strncpy(socket_name, SOCKET_NAME_RIL2_DEBUG, 19);
+ }
+
+ fd = socket_local_client(socket_name,
+ ANDROID_SOCKET_NAMESPACE_RESERVED,
+ SOCK_STREAM);
+ if (fd < 0) {
+ perror ("opening radio debug socket");
+ exit(-1);
+ }
+
+
+ /* It is not necessacry to pass the argument "modem-socket style" to rild */
+ num_socket_args--;
+ int ret = send(fd, (const void *)&num_socket_args, sizeof(int), 0);
+ if(ret != sizeof(int)) {
+ perror ("Socket write error when sending num args");
+ close(fd);
+ exit(-1);
+ }
+
+ for (i = 0; i < num_socket_args; i++) {
+ // Send length of the arg, followed by the arg.
+ int len = strlen(argv[1 + i]);
+ ret = send(fd, &len, sizeof(int), 0);
+ if (ret != sizeof(int)) {
+ perror("Socket write Error: when sending arg length");
+ close(fd);
+ exit(-1);
+ }
+ ret = send(fd, argv[1 + i], sizeof(char) * len, 0);
+ if (ret != len * sizeof(char)) {
+ perror ("Socket write Error: When sending arg");
+ close(fd);
+ exit(-1);
+ }
+ }
+
+ close(fd);
+ return 0;
+}
diff --git a/src/telephonyware/3.0/hardware/ril/fusion/rild/rild.c b/src/telephonyware/3.0/hardware/ril/fusion/rild/rild.c
new file mode 100644
index 0000000..26cccb8
--- /dev/null
+++ b/src/telephonyware/3.0/hardware/ril/fusion/rild/rild.c
@@ -0,0 +1,362 @@
+/* //device/system/rild/rild.c
+**
+** Copyright 2006 The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include "mipc_msg_host.h"
+
+
+#include <telephony/mtk_ril.h>
+#define LOG_TAG "RILD"
+#include <cutils/sockets.h>
+#ifdef __ANDROID__
+ #include <sys/capability.h>
+ #include <cutils/android_filesystem_config.h>
+#else
+ #include <linux/capability.h>
+#endif
+#include <sys/prctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <librilmtk/ril_ex.h>
+#ifdef MTK_SYSENV_SUPPORT
+ #include "sysenv_utils.h"
+#endif
+#include <mtk_log.h>
+#include <mtk_properties.h>
+#include <mtkconfigutils.h>
+#include <mipc_trm.h>
+
+#if defined(PRODUCT_COMPATIBLE_PROPERTY)
+#define LIB_PATH_PROPERTY "vendor.rild.libpath"
+#define LIB_ARGS_PROPERTY "vendor.rild.libargs"
+#else
+#define LIB_PATH_PROPERTY "rild.libpath"
+#define LIB_ARGS_PROPERTY "rild.libargs"
+#endif
+#define MAX_LIB_ARGS 16
+
+static void usage(const char *argv0) {
+ fprintf(stderr, "Usage: %s -l <ril impl library> [-- <args for impl library>]\n", argv0);
+ exit(EXIT_FAILURE);
+}
+
+//extern char ril_service_name_base[MAX_SERVICE_NAME_LENGTH];
+//extern char ril_service_name[MAX_SERVICE_NAME_LENGTH];
+
+extern void RIL_register (const RIL_RadioFunctions *callbacks);
+
+extern const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc __unused,
+ char **argv __unused);
+
+extern void RIL_onRequestComplete(RIL_Token t, RIL_Errno e,
+ void *response, size_t responselen);
+
+extern void RIL_onRequestAck(RIL_Token t);
+
+#if defined(ANDROID_MULTI_SIM)
+extern void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
+ size_t datalen, RIL_SOCKET_ID socket_id);
+#else
+extern void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
+ size_t datalen);
+#endif
+
+extern void RIL_requestTimedCallback (RIL_TimedCallback callback,
+ void *param, const struct timeval *relativeTime);
+
+extern void RIL_onIssueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id);
+
+static struct RIL_Env s_rilEnv = {
+ RIL_onRequestComplete,
+ RIL_onUnsolicitedResponse,
+ RIL_requestTimedCallback,
+ RIL_onRequestAck,
+ NULL,
+ NULL,
+ NULL,
+ /// MTK_RIL_ADAPTER @{
+ RIL_onIssueLocalRequest,
+ /// @}
+};
+
+extern void RIL_startEventLoop();
+
+extern RIL_startNetagent(void);
+
+
+static int isReseted = 0;
+
+int isUserLoad() {
+ int isUserLoad = 0;
+ char property_value_emulation[MTK_PROPERTY_VALUE_MAX] = { 0 };
+ char property_value[MTK_PROPERTY_VALUE_MAX] = { 0 };
+ mtk_property_get("vendor.ril.emulation.userload", property_value_emulation, "0");
+ if(strcmp("1", property_value_emulation) == 0) {
+ return 1;
+ }
+ mtk_property_get("ro.build.type", property_value, "");
+ isUserLoad = (strcmp("user", property_value) == 0);
+ //mtkLogD(LOG_TAG, "isUserLoad: %d", isUserLoad);
+ return isUserLoad;
+}
+
+int isInternalLoad() {
+ #ifdef __PRODUCTION_RELEASE__
+ return 0;
+ #else
+ char property_value[MTK_PROPERTY_VALUE_MAX] = { 0 };
+ mtk_property_get("vendor.ril.emulation.production", property_value, "0");
+ return (strcmp("1", property_value) != 0);
+ #endif /* __PRODUCTION_RELEASE__ */
+}
+
+/*
+* Purpose: Function responsible by all signal handlers treatment any new signal must be added here
+* Input: param - signal ID
+* Return: -
+*/
+void signal_treatment(int param)
+{
+ mtkLogD(LOG_TAG, "signal_no=%d", param);
+ switch (param) {
+ case SIGUSR1:
+ mtkLogD(LOG_TAG, "SIGUSR1");
+ break;
+ case SIGUSR2:
+ mtkLogD(LOG_TAG, "SIGUSR2");
+ break;
+ case SIGSEGV:
+ case SIGPIPE:
+ if (!isReseted) {
+ mtkLogD(LOG_TAG, "SIGSEGV or SIGPIPE");
+ mtk_property_set("vendor.ril.mux.report.case","2");
+ mtk_property_set("vendor.ril.muxreport", "1");
+ mipc_reset();
+ isReseted = 1;
+ } else {
+ mtkLogD(LOG_TAG, "already reset");
+ }
+ break;
+ default:
+ exit(2);
+ break;
+ }
+}
+
+void mtkInit() {
+ //signals treatment
+ signal(SIGPIPE, signal_treatment);
+ signal(SIGUSR1, signal_treatment);
+ signal(SIGUSR2, signal_treatment);
+
+ if ((isInternalLoad() == 0) && (isUserLoad() == 1)) {
+ mtkLogD(LOG_TAG, "Setup SIGSEGV signal handling");
+ signal(SIGSEGV, signal_treatment);
+ }
+}
+
+static int make_argv(char * args, char ** argv) {
+ // Note: reserve argv[0]
+ int count = 1;
+ char * tok;
+ char * s = args;
+
+ while ((tok = strtok(s, " \0"))) {
+ argv[count] = tok;
+ s = NULL;
+ count++;
+ }
+ return count;
+}
+
+void setDynamicMsimConfig() {
+ char prop_value[MTK_PROPERTY_VALUE_MAX] = { 0 };
+ // update dynamic multisim config
+#ifdef MTK_SYSENV_SUPPORT
+ const char *pSysenv = sysenv_get_static("msim_config");
+#else
+ const char *pSysenv = NULL;
+#endif
+
+ mtkLogD(LOG_TAG, "sysenv_get_static: %s\n", pSysenv);
+ if (pSysenv != NULL) {
+ // for META tool
+ FeatureValue featurevalue;
+ if (strcmp(pSysenv, "dsds") == 0) {
+ strncpy(featurevalue.value, "dsds", 10);
+ mtkSetFeature(CONFIG_SIM_MODE, &featurevalue);
+ mtk_property_set("persist.vendor.radio.msimmode", "dsds");
+ mtk_property_set("persist.vendor.radio.multisimslot", "2");
+ } else if (strcmp(pSysenv, "ss") == 0) {
+ strncpy(featurevalue.value, "ss", 10);
+ mtkSetFeature(CONFIG_SIM_MODE, &featurevalue);
+ mtk_property_set("persist.vendor.radio.msimmode", "ss");
+ mtk_property_set("persist.vendor.radio.multisimslot", "1");
+ }
+ } else {
+ // for EM
+ FeatureValue featurevalue;
+ memset(featurevalue.value, 0, sizeof(featurevalue.value));
+ mtkGetFeature(CONFIG_SIM_MODE, &featurevalue);
+ if (strcmp(featurevalue.value, "dsda") != 0) {
+ mtk_property_get("persist.vendor.radio.multisimslot", prop_value, "0");
+ if (prop_value[0] == '1') {
+ strncpy(featurevalue.value, "ss", 10);
+ mtkSetFeature(CONFIG_SIM_MODE, &featurevalue);
+ mtk_property_set("persist.vendor.radio.msimmode", "ss");
+ } else if (prop_value[0] == '2') {
+ strncpy(featurevalue.value, "dsds", 10);
+ mtkSetFeature(CONFIG_SIM_MODE, &featurevalue);
+ mtk_property_set("persist.vendor.radio.msimmode", "dsds");
+ } else if (prop_value[0] == '3') {
+ strncpy(featurevalue.value, "tsts", 10);
+ mtkSetFeature(CONFIG_SIM_MODE, &featurevalue);
+ mtk_property_set("persist.vendor.radio.msimmode", "tsts");
+ } else if (prop_value[0] == '4') {
+ strncpy(featurevalue.value, "qsqs", 10);
+ mtkSetFeature(CONFIG_SIM_MODE, &featurevalue);
+ mtk_property_set("persist.vendor.radio.msimmode", "qsqs");
+ }
+ }
+ }
+}
+
+void sleep_wait_md_ready(void *cb_priv) {
+ sleep(0.1);
+}
+
+int main(int argc, char **argv) {
+ // vendor ril lib path either passed in as -l parameter, or read from rild.libpath property
+ const char *rilLibPath = NULL;
+ // ril arguments either passed in as -- parameter, or read from rild.libargs property
+ char **rilArgv;
+ // handle for vendor ril lib
+ void *dlHandle;
+ // Pointer to ril init function in vendor ril
+ const RIL_RadioFunctions *(*rilInit)(const struct RIL_Env *, int, char **);
+ // Pointer to sap init function in vendor ril
+ const RIL_RadioFunctions *(*rilUimInit)(const struct RIL_Env *, int, char **);
+ const char *err_str = NULL;
+
+ // functions returned by ril init function in vendor ril
+ const RIL_RadioFunctions *funcs;
+ // lib path from rild.libpath property (if it's read)
+ char libPath[MTK_PROPERTY_VALUE_MAX];
+ // flat to indicate if -- parameters are present
+ unsigned char hasLibArgs = 0;
+
+ int i;
+ // ril/socket id received as -c parameter, otherwise set to 0
+ const char *clientId = NULL;
+
+ //mallopt(M_TOP_PAD, 0);
+ // mallopt(M_TRIM_THRESHOLD, 32*1024);
+ //mallopt(M_MMAP_THRESHOLD, 8*1024);
+ //mallopt(M_MXFAST, 0);
+
+ mtkLogI(LOG_TAG, "**RIL Proxy Started**");
+ mtkLogD(LOG_TAG, "**RILd param count=%d**", argc);
+
+ setDynamicMsimConfig();
+ mtkInit();
+
+#if 0//for colgin test
+ mtk_property_set("persist.radio.default.sim","0");
+ mtk_property_set("ro.telephony.sim.count","2");
+ mtk_property_set("persist.radio.dsss.sim.disable","2");
+ mtk_property_set("persist.ril.client.num","1");
+ mtk_property_set("persist.radio.multisim.config","dsss");
+#endif
+ umask(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH);
+ for (i = 1; i < argc ;) {
+ if (0 == strcmp(argv[i], "-l") && (argc - i > 1)) {
+ rilLibPath = argv[i + 1];
+ i += 2;
+ } else if (0 == strcmp(argv[i], "--")) {
+ i++;
+ hasLibArgs = 1;
+ break;
+ } else if (0 == strcmp(argv[i], "-c") && (argc - i > 1)) {
+ clientId = argv[i+1];
+ i += 2;
+ } else {
+ usage(argv[0]);
+ }
+ }
+ if (clientId == NULL) {
+ clientId = "0";
+ } else if (atoi(clientId) >= MAX_RILDS) {
+ mtkLogE(LOG_TAG, "Max Number of rild's supported is: %d", MAX_RILDS);
+ exit(0);
+ }
+
+ mtkLogD(LOG_TAG, "mipc init start");
+ WAIT_MD_READY_API(sleep_wait_md_ready,NULL);
+ SETCOM("/dev/ttyCMIPC7");
+ mipc_init("rild");//enable mipc log
+ mtkLogD(LOG_TAG, "mipc init done");
+
+
+ RIL_startEventLoop();
+
+
+ if (hasLibArgs) {
+ rilArgv = argv + i - 1;
+ argc = argc -i + 1;
+ } else {
+ static char * newArgv[MAX_LIB_ARGS];
+ static char args[MTK_PROPERTY_VALUE_MAX];
+ rilArgv = newArgv;
+ mtk_property_get(LIB_ARGS_PROPERTY, args, "");
+ argc = make_argv(args, rilArgv);
+ }
+
+ rilArgv[argc++] = "-c";
+ rilArgv[argc++] = (char*)clientId;
+ mtkLogD(LOG_TAG, "RIL_Init argc = %d clientId = %s", argc, rilArgv[argc-1]);
+
+ // Make sure there's a reasonable argv[0]
+ rilArgv[0] = argv[0];
+
+ funcs = RIL_Init(&s_rilEnv, argc, rilArgv);
+ mtkLogI(LOG_TAG, "RIL_Init completed %x",funcs);
+
+ RIL_register(funcs);
+
+ mtkLogI(LOG_TAG, "RIL_register completed");
+
+ mtkLogI(LOG_TAG, "start netagent");
+ RIL_startNetagent();
+ mtkLogI(LOG_TAG, "started netagent");
+
+done:
+
+ mtkLogD(LOG_TAG, "RIL_Init starting sleep loop");
+ while (true) {
+ sleep(UINT32_MAX);
+ }
+}
diff --git a/src/telephonyware/3.0/hardware/ril/fusion/rild/rild.rc b/src/telephonyware/3.0/hardware/ril/fusion/rild/rild.rc
new file mode 100644
index 0000000..b5dc073
--- /dev/null
+++ b/src/telephonyware/3.0/hardware/ril/fusion/rild/rild.rc
@@ -0,0 +1,18 @@
+on post-fs-data
+ # create ims db node
+ mkdir /data/vendor/radio 0771 radio radio
+
+service vendor.ril-daemon-mtk /vendor/bin/hw/mtkfusionrild
+ class core
+ socket sap_uim_socket1 stream 660 bluetooth bluetooth
+ socket rild-oem stream 660 radio system
+ socket volte_imsvt1 stream 660 root radio
+ socket rild-atci stream 660 root radio
+ user radio
+ group radio cache inet misc audio log readproc wakelock sdcard_r sdcard_rw system
+ capabilities BLOCK_SUSPEND NET_ADMIN NET_RAW
+ oneshot
+ disabled
+
+on property:vendor.ril.mtk=1
+ start vendor.ril-daemon-mtk