blob: 690cf3f96b8e91fc0e2f3567621a2990d060e3ef [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2* Copyright (C) 2014 MediaTek Inc.
3*
4* Modification based on code covered by the below mentioned copyright
5* and/or permission notice(s).
6*/
7
8/*
9**
10** Copyright 2006 The Android Open Source Project
11**
12** Licensed under the Apache License, Version 2.0 (the "License");
13** you may not use this file except in compliance with the License.
14** You may obtain a copy of the License at
15**
16** http://www.apache.org/licenses/LICENSE-2.0
17**
18** Unless required by applicable law or agreed to in writing, software
19** distributed under the License is distributed on an "AS IS" BASIS,
20** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21** See the License for the specific language governing permissions and
22** limitations under the License.
23*/
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <dlfcn.h>
28#include <string.h>
29#include <stdint.h>
30#include <unistd.h>
31#include <fcntl.h>
32#include <errno.h>
33#include <vendor-ril/telephony/ril.h>
34#include <log/log.h>
35#include <sys/file.h>
36#include <sys/stat.h>
37#include <sys/types.h>
38#include "stateManager/stateManager.h"
39#include "common.h"
40#include <lib_tele.h>
41#include <lynq_call.h>
42#include <lynq_sms.h>
43
44extern "C" void RIL_register (const RIL_RadioFunctions *callbacks);
45
46extern "C" void RIL_onRequestComplete(RIL_Token t, RIL_Errno e,
47 void *response, size_t responselen);
48
49
50#if defined(ANDROID_MULTI_SIM)
51extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
52 size_t datalen, RIL_SOCKET_ID socket_id);
53#else
54extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
55 size_t datalen);
56#endif
57
58#undef LOG_TAG
59#define LOG_TAG "DEMO_MAIN"
60//static const struct RIL_Cb *mRIL_Cb = NULL;
61requestResponse mRequestCb = NULL;
62unsolicitedResponse mUnsolicitedCb = NULL;
63static user_cb *lynq_Cb=NULL;
64static struct RIL_Env s_rilEnv = {
65 RIL_onRequestComplete,
66 RIL_onUnsolicitedResponse,
67 NULL
68};
69/*
70 void lynqRegisterRequestResponse(user_cb * cb){
71 lynq_cb = cb;
72 return ;
73}
74*/
75void lynqRegisterUnsolicitedResponse(user_cb * cb){
76 lynq_Cb = cb;
77 return ;
78}
79static void lynqOnUnsolicitedResponseCallback(int unsolResponse,char *response,int responselen) {
80}
81void lynq_ril_init()
82{
83 int lock_file = open("/tmp/tel_demo_single_proc.lock", O_CREAT|O_RDWR, 0666);
84 int rc = flock(lock_file,LOCK_EX|LOCK_NB);
85 if(rc) {
86 if(EWOULDBLOCK == errno) {
87 printf("Error: cannot restart the telephony app repeatedly\n");
88 RLOGD("Error: cannot restart the telephony app repeatedly");
89 exit(0);
90 }
91 }
92#ifdef BASELIB_DIR_LIB64
93 const char *rilLibPath = "/lib64/libvendor-ril.so";
94#else
95 const char *rilLibPath = "/lib/libvendor-ril.so";
96#endif
97 void *dlHandle;
98 const RIL_RadioFunctions *(*rilInit)(const struct RIL_Env *, int, char **);
99
100 const RIL_RadioFunctions *funcs;
101
102 RLOGD("**RIL Daemon Started**");
103 android::registerOnUnsolicitedResponse(lynq_Cb);
104 //prctl(PR_SET_NAME,(unsigned long)"demo_main_thread");
105 dlHandle = dlopen(rilLibPath, RTLD_NOW);
106
107 if (dlHandle == NULL) {
108 RLOGE("dlopen failed: %s", dlerror());
109 exit(EXIT_FAILURE);
110 }
111
112 android::RIL_startEventLoop();
113 //android::startATCILoop();
114 //android::startPMLoop();
115 //android::startWakupLoop();
116
117 rilInit =
118 (const RIL_RadioFunctions *(*)(const struct RIL_Env *, int, char **))
119 dlsym(dlHandle, "RIL_Init");
120
121 if (rilInit == NULL) {
122 RLOGE("RIL_Init not defined or exported in %s", rilLibPath);
123 exit(EXIT_FAILURE);
124 }
125
126 dlerror(); // Clear any previous dlerror
127 RLOGD("start rilInit");
128 funcs = rilInit(&s_rilEnv, 0, NULL);;
129 RLOGD("start RIL_register");
130 RIL_register(funcs);
131 if(lynqApiInit()!=0)
132 {
133 RLOGD("lynq api init fail");
134 exit(0);
135 }
136 // android::registerForAppResponse(lynqResponseCallback);
137 // android::registerOnUnsolicitedResponse(lynqOnUnsolicitedResponseCallback);
138 // android::startGdbusLoop();
139 RLOGD("RIL_Init RIL_register completed");
140 printf("DemoApp launch done!\n");
141 //while (true) {
142 //sleep(UINT32_MAX);
143 //}
144 close(lock_file);
145}
146int lynq_waitToRcvCmd(char **data, int lenth)
147{
148 printf("--------->[%s,%d] \n",__FUNCTION__,__LINE__);
149 android::getRequestData(data,lenth);
150
151 return 0;
152}