blob: ef41d333cfa2abd47568f88533ea256cb2512302 [file] [log] [blame]
lhb07f4e12022-02-17 22:08:54 -08001//SPDX-License-Identifier: MediaTekProprietary
lh7b0674a2022-01-10 00:34:35 -08002/*
3**
4** Copyright 2006, The Android Open Source Project
5**
6** Licensed under the Apache License, Version 2.0 (the "License");
7** you may not use this file except in compliance with the License.
8** You may obtain a copy of the License at
9**
10** http://www.apache.org/licenses/LICENSE-2.0
11**
12** Unless required by applicable law or agreed to in writing, software
13** distributed under the License is distributed on an "AS IS" BASIS,
14** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15** See the License for the specific language governing permissions and
16** limitations under the License.
17*/
18#include<sys/types.h>
19#include<sys/socket.h>
20#include<unistd.h>
21#include<netinet/in.h>
22#include<arpa/inet.h>
23#include<netdb.h>
24#include<signal.h>
25#include <log/log.h>
26#include <hardware_legacy/power.h>
27#include <vendor-ril/telephony/ril.h>
28#include <telephony/ril_cdma_sms.h>
xy.hef5d74f12023-10-23 06:48:52 -070029#include <telephony/mtk_ril_sp.h>
lh7b0674a2022-01-10 00:34:35 -080030#include <cutils/jstring.h>
31#include <telephony/record_stream.h>
32#include <utils/SystemClock.h>
33#include <pthread.h>
34#include <binder/Parcel.h>
35#include <cutils/jstring.h>
36#include <sys/types.h>
37#include <limits.h>
38#include <pwd.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <stdarg.h>
42#include <string.h>
43#include <unistd.h>
44#include <fcntl.h>
45#include <time.h>
46#include <errno.h>
47#include <assert.h>
48#include <ctype.h>
49#include <alloca.h>
50#include <sys/un.h>
51#include <assert.h>
52#include <netinet/in.h>
53#include <atomic>
54
55#include "utils/String8.h"
56#include "ss.h"
57#include "sim.h"
58#include "common.h"
59#include "cc.h"
60#include "network.h"
61#include "stk.h"
62#include "utils.h"
63
64#include "atci/ATCI.h"
65#include "data/data.h"
66#include "data/data_gdbus.h"
67#include "ecall/eCall.h"
68#include "em/em.h"
69#include "sms/sms.h"
70#include "sms/cdma/sms_pdu_cdma.h"
71#include "stateManager/stateManager.h"
72#include "Phone_utils.h"
73#include "utils.h"
74#include "Radio_capability_switch_util.h"
75/*Warren add for t800 RIL service 2021_12_10 start*/
76#include <sys/epoll.h>
77#include "lynq_interface.h"
lhf6eea122022-01-20 19:32:14 -080078#include "lynq_common.h"
79#include "lynq_sms_manager.h"
llaaca09b2022-03-14 16:14:28 +080080/*lei add*/
llacba3662022-04-15 16:57:13 +080081#include <stdbool.h>
llaaca09b2022-03-14 16:14:28 +080082#include "lynq_at.h"
83#include "lynq_user.h"
84#include "lynq_rndis.h"
85#include "lynq_factory.h"
ll2f3fea22022-09-29 17:16:10 +080086#include <sys/stat.h>
llaaca09b2022-03-14 16:14:28 +080087/*lei add*/
rita9c8cd862022-08-10 09:36:49 +080088/*rita add start*/
89#include "lynq_at_temp.h"
90/*rita add end*/
tao.liu68d6eeb2022-11-17 16:48:50 +080091/*lt add start*/
92#include "lynq_fota.h"
93/*lt add end*/
lh7b0674a2022-01-10 00:34:35 -080094/*Warren add for t800 RIL service 2021_12_10 end*/
q.huang036b6cf2023-01-10 14:29:20 +080095#ifdef LED_SUPPORT
96#include "led.h"
97#endif
98#include "lynq_shm.h"
q.huang1c03f752023-12-14 14:11:58 +080099#include "call_rtp.h"
lh7b0674a2022-01-10 00:34:35 -0800100
101#define LOG_TAG "DEMO_RIL"
xja1c30b82022-01-25 16:13:48 +0800102#define WAIT_TIME_FOR_SIM_SWITCH 30
lh7b0674a2022-01-10 00:34:35 -0800103
104extern void ARspRequest (int request, RIL_SOCKET_ID socket_id);
105extern void responseDispatch();
106
107namespace android {
108extern "C" void
109RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
110
111#define SERVER_PORT 8000
112#define BUFFER_SIZE 8192
113#define MAX_ARGS 101
114#define BLOCK_LOCK() pthread_mutex_lock(&s_BlockMutex)
115#define BLOCK_UNLOCK() pthread_mutex_unlock(&s_BlockMutex)
116#define BLOCK_WAIT(a) pthread_cond_timedwait(&s_BlockCond, &s_BlockMutex,(a))
117#define BLOCK_WAKEUP() pthread_cond_broadcast(&s_BlockCond)
118#define SPECIA_BLOCK_LOCK() pthread_mutex_lock(&s_SpecialBlock)
119#define SPECIA_BLOCK_UNLOCK() pthread_mutex_unlock(&s_SpecialBlock)
120#define SPECIA_BLOCK_WAIT(a) pthread_cond_timedwait(&s_SpeciaBlockCond, &s_SpecialBlock,(a))
121#define SPECIA_BLOCK_WAKEUP() pthread_cond_signal(&s_SpeciaBlockCond)
122
123static int s_started = 0;
124static int s_responseDispatch = 0;
125static int s_isConnected[2] = {0,0}; //connect to modem;
126static pthread_mutex_t s_InitMutex = PTHREAD_MUTEX_INITIALIZER;
127static pthread_cond_t s_InitCond = PTHREAD_COND_INITIALIZER;
128
129static pthread_mutex_t s_BlockMutex = PTHREAD_MUTEX_INITIALIZER;
130static pthread_cond_t s_BlockCond = PTHREAD_COND_INITIALIZER;
131static pthread_mutex_t s_SpecialBlock = PTHREAD_MUTEX_INITIALIZER;
132static pthread_cond_t s_SpeciaBlockCond = PTHREAD_COND_INITIALIZER;
133
134int requestOneByOne = 0;
135int server_socket_fd;
136int enable_syslog = 1;
137int enable_bt_resp = 0;
138int wakeup_token = -1;
139struct sockaddr_in client_addr;
140
141#define ANDROID_WAKE_LOCK_NAME "radio-interface"
142
143// Basically: memset buffers that the client library
144// shouldn't be using anymore in an attempt to find
145// memory usage issues sooner.
146#define MEMSET_FREED 1
147
148#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
149
150#define MIN(a,b) ((a)<(b) ? (a) : (b))
151
152/* Constants for response types */
153#define RESPONSE_SOLICITED 0
154#define RESPONSE_UNSOLICITED 1
155
156/* Negative values for private RIL errno's */
157#define RIL_ERRNO_INVALID_RESPONSE -1
158
159// request, response, and unsolicited msg print macro
160#define PRINTBUF_SIZE 8096
161
162// Enable verbose logging
163#define VDBG 0
164
165// Enable RILC log
166#define RILC_LOG 1
167/*Warren add for t800 RIL service 2021_12_10 start*/
lh8d290112023-10-22 20:53:06 -0700168#define LYNQ_RIL_FWK_IP "127.0.0.1"
lh7b0674a2022-01-10 00:34:35 -0800169#define LYNQ_SOCKET_ENVNT_FD_MAX 100
170#define LYNQ_SERVICE_PORT 8088
lld164b022022-03-29 14:01:01 +0800171#define LYNQ_AT_SERVICE_PORT 8087
lhced7d4a2023-03-28 09:50:52 +0800172#define LYNQ_BRODCAST_PORT 8086
lh7b0674a2022-01-10 00:34:35 -0800173#define LYNQ_SOCKET_BUFFER (1024*8+sizeof(int)*3+10)
lld164b022022-03-29 14:01:01 +0800174/*lei add*/
175#define LYNQ_AT_SOCKET_BUFFER 1024
176#define MAX_AT_CMD 50
177/*lei add*/
lh7b0674a2022-01-10 00:34:35 -0800178//int LYNQ_RIL_respSocket(Parcel &p,RIL_Token t);
179//int LYNQ_RIL_urcBroadcast(Parcel &p);
180
q.huang036b6cf2023-01-10 14:29:20 +0800181/*hq add for urc broadcast opti 2023/01/06 */
182#define SHM_BUFFER_INDEX_OFFSET 1
183#define SHM_BUFFER_SIZE_OFFSET 16
184#define urc_broadcase_shm_size_limit 20
185
lhced7d4a2023-03-28 09:50:52 +0800186int lynq_urc_socket_fd = 0;
lh7b0674a2022-01-10 00:34:35 -0800187struct sockaddr_in urc_broadcast_addr;
188/*Warren add for t800 RIL service 2021_12_10 end*/
189
190
lld164b022022-03-29 14:01:01 +0800191/*lei add*/
192char buffer_at[LYNQ_AT_SOCKET_BUFFER] = {0};
193/*For at extension to receive at buffer*/
194char *at_buf_ext[MAX_AT_CMD];
195int sockfd = 0;
ll1d2ce042022-08-04 01:53:01 -0700196int imei_cnt = 0;
lld9be9b72022-08-18 03:23:36 -0700197bool sdk_ready = true;
lld164b022022-03-29 14:01:01 +0800198/*lei add*/
lh7b0674a2022-01-10 00:34:35 -0800199#if RILC_LOG
200 static char printBuf[PRINTBUF_SIZE];
201 static char tempPrintBuf[PRINTBUF_SIZE];
202 #define startRequest sprintf(printBuf, "(")
203 #define closeRequest sprintf(printBuf, "%s)", printBuf)
204 #define printRequest(token, req) if(enable_syslog) { \
205 RLOGD("[%x]> %s %s", token, requestToString(req), printBuf);} else {\
206 printf("[%x]> %s %s\n", token, requestToString(req), printBuf);}
207
208 #define startResponse sprintf(printBuf, "%s {", printBuf)
209 #define closeResponse sprintf(printBuf, "%s}", printBuf)
210 #define printResponse if(enable_syslog) { \
211 RLOGD("%s", printBuf); } else { \
212 printf("%s\n", printBuf);}
213
214 #define clearPrintBuf printBuf[0] = 0
215 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
216 #define appendPrintBuf(x...) snprintf(tempPrintBuf, PRINTBUF_SIZE, x); \
217 snprintf(printBuf, PRINTBUF_SIZE, "%s", tempPrintBuf)
218#endif
219
220enum WakeType {DONT_WAKE, WAKE_PARTIAL};
221
222#if 0
223typedef struct {
224 int requestNumber;
225 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
226 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
227} CommandInfo;
228#endif
229
230typedef struct {
231 int requestNumber;
232 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
233 WakeType wakeType;
234} UnsolResponseInfo;
235
236#if 0
237typedef struct RequestInfo {
238 int32_t token; //this is not RIL_Token
239 CommandInfo *pCI;
240 struct RequestInfo *p_next;
241 char cancelled;
242 char local; // responses to local commands do not go back to command process
243 RIL_SOCKET_ID socket_id;
244} RequestInfo;
245
246typedef struct UserCallbackInfo {
247 RIL_TimedCallback p_callback;
248 void *userParam;
249 struct ril_event event;
250 struct UserCallbackInfo *p_next;
251} UserCallbackInfo;
252#endif
253
254const char *requestToString(int request);
255const char * failCauseToString(RIL_Errno);
256const char * callStateToString(RIL_CallState);
257
258RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
259int s_registerCalled = 0;
260
261static pthread_t s_tid_dispatch;
262
263static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
264
265#if EM_MODE_SUPPORT
266netwokInfoNotify networkCb = NULL;
267atCmdResponse atResponseCb = NULL;
268#endif
269
270static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
271static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
272static void *s_lastNITZTimeData = NULL;
273static size_t s_lastNITZTimeDataSize;
274
275/*******************************************************************/
276static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
277
278static void dispatchVoid (Parcel& p, RequestInfo *pRI);
279static void dispatchString (Parcel& p, RequestInfo *pRI);
280static void dispatchStrings (Parcel& p, RequestInfo *pRI);
281static void dispatchInts (Parcel& p, RequestInfo *pRI);
282static void dispatchDial (Parcel& p, RequestInfo *pRI);
283static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
284static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
285static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
286static void dispatchRaw(Parcel& p, RequestInfo *pRI);
287static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
288static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
289static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);;
290static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
291static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
292static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
293static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
294static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
295static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
296static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
297static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
298static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
299static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
300static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
301static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
302static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
303static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
304static int responseInts(Parcel &p, void *response, size_t responselen);
305static int responseFailCause(Parcel &p, void *response, size_t responselen);
306static int responseStrings(Parcel &p, void *response, size_t responselen);
307static int responseString(Parcel &p, void *response, size_t responselen);
lxfdb3a24c2023-11-20 06:26:13 -0800308//xf.li@20231120 modify for T8TSK-291 start
309static int responseStringNoLog(Parcel &p, void *response, size_t responselen);
lxf2d6e8ae2023-12-05 00:32:26 -0800310static int responseStringsNoLog(Parcel &p, void *response, size_t responselen);
lxfdb3a24c2023-11-20 06:26:13 -0800311//xf.li@20231120 modify for T8TSK-291 end
lh7b0674a2022-01-10 00:34:35 -0800312static int responseVoid(Parcel &p, void *response, size_t responselen);
313static int responseCallList(Parcel &p, void *response, size_t responselen);
314static int responseSMS(Parcel &p, void *response, size_t responselen);
315static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
316static int responseCallForwards(Parcel &p, void *response, size_t responselen);
317static int responseDataCallList(Parcel &p, void *response, size_t responselen);
318static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
319static int responseRaw(Parcel &p, void *response, size_t responselen);
320static int responseSsn(Parcel &p, void *response, size_t responselen);
321static int responseSimStatus(Parcel &p, void *response, size_t responselen);
322static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
323static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
324static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
325static int responseCellList(Parcel &p, void *response, size_t responselen);
326static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
327static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
328static int responseCallRing(Parcel &p, void *response, size_t responselen);
329static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
330static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
331static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
332static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
333static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
334static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
335static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
336static int responseSSData(Parcel &p, void *response, size_t responselen);
337static int responseLceStatus(Parcel &p, void *response, size_t responselen);
338static int responseLceData(Parcel &p, void *response, size_t responselen);
339static int responseActivityData(Parcel &p, void *response, size_t responselen);
340static int responseSmsSimMemStatus(Parcel &p, void *response, size_t responselen);
341#ifdef ECALL_SUPPORT
342static void dispatchFastEcall (Parcel& p, RequestInfo *pRI);
343static int responseEcallStatus(Parcel &p, void *response, size_t responselen);
344static void dispatchSetMsd (Parcel &p, RequestInfo *pRI);
345static void dispatchEcallRecord (Parcel &p, RequestInfo *pRI);
346#endif /*ECALL_SUPPORT*/
347#ifdef KEEP_ALIVE
348static void dispatchStartKeepalivePro(Parcel &p, RequestInfo *pRI);
349#endif /*KEEP_ALIVE*/
350static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
351static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
352static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
353
354static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
355
356static int onSupports (int requestCode);
357static UnsolResponseInfo* find_mtk_unsol_command(int request);
358static int com_quit(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
359static int enableSyslog(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
360static int enableBTResponse(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
361static void updateIccCardState(RIL_SOCKET_ID soc_id);
362static void initCoditions();
363
364static int SendRespToClient(const void *data, size_t dataSize);
365static void speciaRequest_wakeup();
366static void speciaRequest_wait();
367void processUnsolicited (Parcel &p, int type);
368void processSolicited (Parcel &p, int type);
369
370void printInputArgs(int argc, char** argv) ;
371void initRequestInfo(RequestInfo *pRI, int request, int mode, RIL_SOCKET_ID soc_id);
lh7b0674a2022-01-10 00:34:35 -0800372const int waitResponse(int token);
lxfdb3a24c2023-11-20 06:26:13 -0800373//xf.li@20231120 modify for T8TSK-291 start
374static void encode_log(char str[], int n);
375static void decode_log(char str[], int n);
376//xf.li@20231120 modify for T8TSK-291 end
lh7b0674a2022-01-10 00:34:35 -0800377#ifdef RIL_SHLIB
378#if defined(ANDROID_MULTI_SIM)
379extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
380 size_t datalen, RIL_SOCKET_ID socket_id);
381#else
382extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
383 size_t datalen);
384#endif
385#endif
386
387#if defined(ANDROID_MULTI_SIM)
388#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
389#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
390#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
391#else
392#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
393#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
394#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
395#endif
396
397
398/** Index == requestNumber */
399static CommandInfo s_commands[] = {
400#include "ril_commands.h"
401};
402
403static UnsolResponseInfo s_unsolResponses[] = {
404#include "ril_unsol_commands.h"
405};
406
407COMMAND commands[] = {
408#include "commands.h"
409};
410
411static CommandInfo mtk_s_command[] = {
412#include "mtk_ril_commands.h"
413};
414
415static UnsolResponseInfo s_mtk_unsolResponses[] = {
416#include "mtk_ril_unsol_commands.h"
417};
418
419char respStr[PRINTBUF_SIZE]={0};
420
421/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
422 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
423 radio state message and store it. Every time there is a change in Radio State
424 check to see if voice radio tech changes and notify telephony
425 */
426int voiceRadioTech = -1;
427
428/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
429 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
430 source from radio state and store it. Every time there is a change in Radio State
431 check to see if subscription source changed and notify telephony
432 */
433int cdmaSubscriptionSource = -1;
434
435/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
436 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
437 check to see if SIM/RUIM status changed and notify telephony
438 */
439int simRuimStatus = -1;
440
441
442static char *
443strdupReadString(Parcel &p) {
444 size_t stringlen;
445 const char16_t *s16;
446
447 s16 = p.readString16Inplace(&stringlen);
448
449 return strndup16to8(s16, stringlen);
450}
451
452static status_t
453readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
454 size_t s16Len;
455 const char16_t *s16;
456
457 s16 = p.readString16Inplace(&s16Len);
458 if (s16 == NULL) {
459 return NO_MEMORY;
460 }
461 size_t strLen = strnlen16to8(s16, s16Len);
462 if ((strLen + 1) > maxLen) {
463 return NO_MEMORY;
464 }
465 if (strncpy16to8(str, s16, strLen) == NULL) {
466 return NO_MEMORY;
467 } else {
468 return NO_ERROR;
469 }
470}
471
472/*static*/ void writeStringToParcel(Parcel &p, const char *s) {
473 char16_t *s16;
474 size_t s16_len;
475 s16 = strdup8to16(s, &s16_len);
476 p.writeString16(s16, s16_len);
477 free(s16);
478}
479
480
481static void
482memsetString (char *s) {
483 if (s != NULL) {
484 memset (s, 0, strlen(s));
485 }
486}
487
488
489static void
490invalidCommandBlock (RequestInfo *pRI) {
491 RLOGE("invalid command block for token %d request %s",
492 pRI->token, requestToString(pRI->pCI->requestNumber));
493}
494
495/** Callee expects NULL */
496static void
497dispatchVoid (Parcel& p, RequestInfo *pRI) {
498 clearPrintBuf;
499 printRequest(pRI->token, pRI->pCI->requestNumber);
500 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
501}
502
503/** Callee expects const char * */
504static void
505dispatchString (Parcel& p, RequestInfo *pRI) {
506 status_t status;
507 size_t datalen;
508 size_t stringlen;
509 char *string8 = NULL;
510
511 string8 = strdupReadString(p);
512
513 startRequest;
514 appendPrintBuf("%s%s", printBuf, string8);
515 closeRequest;
516 printRequest(pRI->token, pRI->pCI->requestNumber);
517
518 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
519 sizeof(char *), pRI, pRI->socket_id);
520
521#ifdef MEMSET_FREED
522 memsetString(string8);
523#endif
524
525 free(string8);
526 return;
527invalid:
528 invalidCommandBlock(pRI);
529 return;
530}
531
532/** Callee expects const char ** */
533static void
534dispatchStrings (Parcel &p, RequestInfo *pRI) {
535 int32_t countStrings;
536 status_t status;
537 size_t datalen;
538 char **pStrings;
539
540 status = p.readInt32 (&countStrings);
541
542 if (status != NO_ERROR) {
543 goto invalid;
544 }
545
546 startRequest;
547 if (countStrings == 0) {
548 // just some non-null pointer
549 pStrings = (char **)alloca(sizeof(char *));
550 datalen = 0;
551 } else if (((int)countStrings) == -1) {
552 pStrings = NULL;
553 datalen = 0;
554 } else {
555 datalen = sizeof(char *) * countStrings;
556
557 pStrings = (char **)alloca(datalen);
558
559 for (int i = 0 ; i < countStrings ; i++) {
560 pStrings[i] = strdupReadString(p);
561 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
562 }
563 }
564 removeLastChar;
565 closeRequest;
566 printRequest(pRI->token, pRI->pCI->requestNumber);
567
568 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
569
570 if (pStrings != NULL) {
571 for (int i = 0 ; i < countStrings ; i++) {
572#ifdef MEMSET_FREED
573 memsetString (pStrings[i]);
574#endif
575 free(pStrings[i]);
576 }
577
578#ifdef MEMSET_FREED
579 memset(pStrings, 0, datalen);
580#endif
581 }
582
583 return;
584invalid:
585 invalidCommandBlock(pRI);
586 return;
587}
588
589/** Callee expects const int * */
590static void
591dispatchInts (Parcel &p, RequestInfo *pRI) {
592 int32_t count;
593 status_t status;
594 size_t datalen;
595 int *pInts;
596
597 status = p.readInt32 (&count);
598
599 if (status != NO_ERROR || count == 0) {
600 goto invalid;
601 }
602
603 datalen = sizeof(int) * count;
604 pInts = (int *)alloca(datalen);
605
606 startRequest;
607 for (int i = 0 ; i < count ; i++) {
xja1c30b82022-01-25 16:13:48 +0800608 int32_t t = 0;
lh7b0674a2022-01-10 00:34:35 -0800609
610 status = p.readInt32(&t);
611 pInts[i] = (int)t;
612 appendPrintBuf("%s%d,", printBuf, t);
613
614 if (status != NO_ERROR) {
615 goto invalid;
616 }
617 }
618 removeLastChar;
619 closeRequest;
620 printRequest(pRI->token, pRI->pCI->requestNumber);
621
622 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
623 datalen, pRI, pRI->socket_id);
624
625#ifdef MEMSET_FREED
626 memset(pInts, 0, datalen);
627#endif
628
629 return;
630invalid:
631 invalidCommandBlock(pRI);
632 return;
633}
634
635
636/**
637 * Callee expects const RIL_SMS_WriteArgs *
638 * Payload is:
639 * int32_t status
640 * String pdu
641 */
642static void
643dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
644 RIL_SMS_WriteArgs args;
xja1c30b82022-01-25 16:13:48 +0800645 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800646 status_t status;
647
648 RLOGD("dispatchSmsWrite");
649 memset (&args, 0, sizeof(args));
650
651 status = p.readInt32(&t);
652 args.status = (int)t;
653
654 args.pdu = strdupReadString(p);
655
656 if (status != NO_ERROR || args.pdu == NULL) {
657 goto invalid;
658 }
659
660 args.smsc = strdupReadString(p);
661
662 startRequest;
663 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
664 (char*)args.pdu, (char*)args.smsc);
665 closeRequest;
666 printRequest(pRI->token, pRI->pCI->requestNumber);
667
668 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
669
670#ifdef MEMSET_FREED
671 memsetString (args.pdu);
672#endif
673
674 free (args.pdu);
675 free (args.smsc);
676#ifdef MEMSET_FREED
677 memset(&args, 0, sizeof(args));
678#endif
679
680 return;
681invalid:
682 invalidCommandBlock(pRI);
683 return;
684}
685
686/**
687 * Callee expects const RIL_Dial *
688 * Payload is:
689 * String address
690 * int32_t clir
691 */
692static void
693dispatchDial (Parcel &p, RequestInfo *pRI) {
694 RIL_Dial dial;
695 RIL_UUS_Info uusInfo;
696 int32_t sizeOfDial;
xja1c30b82022-01-25 16:13:48 +0800697 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800698 int32_t uusPresent;
699 status_t status;
700
701 RLOGD("dispatchDial");
702 memset (&dial, 0, sizeof(dial));
703
704 dial.address = strdupReadString(p);
705
706 status = p.readInt32(&t);
707 dial.clir = (int)t;
708
709 if (status != NO_ERROR || dial.address == NULL) {
710 goto invalid;
711 }
712
713 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
714 uusPresent = 0;
715 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
716 } else {
717 status = p.readInt32(&uusPresent);
718
719 if (status != NO_ERROR) {
720 goto invalid;
721 }
722
723 if (uusPresent == 0) {
724 dial.uusInfo = NULL;
725 } else {
726 int32_t len;
727
728 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
729
730 status = p.readInt32(&t);
731 uusInfo.uusType = (RIL_UUS_Type) t;
732
733 status = p.readInt32(&t);
734 uusInfo.uusDcs = (RIL_UUS_DCS) t;
735
736 status = p.readInt32(&len);
737 if (status != NO_ERROR) {
738 goto invalid;
739 }
740
741 // The java code writes -1 for null arrays
742 if (((int) len) == -1) {
743 uusInfo.uusData = NULL;
744 len = 0;
745 } else {
746 uusInfo.uusData = (char*) p.readInplace(len);
747 }
748
749 uusInfo.uusLength = len;
750 dial.uusInfo = &uusInfo;
751 }
752 sizeOfDial = sizeof(dial);
753 }
754
755 startRequest;
756 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
757 if (uusPresent) {
758 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
759 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
760 dial.uusInfo->uusLength);
761 }
762
763 closeRequest;
764 printRequest(pRI->token, pRI->pCI->requestNumber);
765
766 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
767
768#ifdef MEMSET_FREED
769 memsetString (dial.address);
770#endif
771
772 free (dial.address);
773
774#ifdef MEMSET_FREED
775 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
776 memset(&dial, 0, sizeof(dial));
777#endif
778
779 return;
780invalid:
781 invalidCommandBlock(pRI);
782 return;
783}
784
785/**
786 * Callee expects const RIL_SIM_IO *
787 * Payload is:
788 * int32_t command
789 * int32_t fileid
790 * String path
791 * int32_t p1, p2, p3
792 * String data
793 * String pin2
794 * String aidPtr
795 */
796static void
797dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
798 union RIL_SIM_IO {
799 RIL_SIM_IO_v6 v6;
800 RIL_SIM_IO_v5 v5;
801 } simIO;
802
xja1c30b82022-01-25 16:13:48 +0800803 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800804 int size;
805 status_t status;
806
807#if VDBG
808 RLOGD("dispatchSIM_IO");
809#endif
810 memset (&simIO, 0, sizeof(simIO));
811
812 // note we only check status at the end
813
814 status = p.readInt32(&t);
815 simIO.v6.command = (int)t;
816
817 status = p.readInt32(&t);
818 simIO.v6.fileid = (int)t;
819
820 simIO.v6.path = strdupReadString(p);
821
822 status = p.readInt32(&t);
823 simIO.v6.p1 = (int)t;
824
825 status = p.readInt32(&t);
826 simIO.v6.p2 = (int)t;
827
828 status = p.readInt32(&t);
829 simIO.v6.p3 = (int)t;
830
831 simIO.v6.data = strdupReadString(p);
832 simIO.v6.pin2 = strdupReadString(p);
833 simIO.v6.aidPtr = strdupReadString(p);
834
835 startRequest;
836 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
837 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
838 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
839 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
840 closeRequest;
841 printRequest(pRI->token, pRI->pCI->requestNumber);
842
843 if (status != NO_ERROR) {
844 goto invalid;
845 }
846
847 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
848 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
849
850#ifdef MEMSET_FREED
851 memsetString (simIO.v6.path);
852 memsetString (simIO.v6.data);
853 memsetString (simIO.v6.pin2);
854 memsetString (simIO.v6.aidPtr);
855#endif
856
857 free (simIO.v6.path);
858 free (simIO.v6.data);
859 free (simIO.v6.pin2);
860 free (simIO.v6.aidPtr);
861
862#ifdef MEMSET_FREED
863 memset(&simIO, 0, sizeof(simIO));
864#endif
865
866 return;
867invalid:
868 invalidCommandBlock(pRI);
869 return;
870}
871
872/**
873 * Callee expects const RIL_SIM_APDU *
874 * Payload is:
875 * int32_t sessionid
876 * int32_t cla
877 * int32_t instruction
878 * int32_t p1, p2, p3
879 * String data
880 */
881static void
882dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
xja1c30b82022-01-25 16:13:48 +0800883 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800884 status_t status;
885 RIL_SIM_APDU apdu;
886
887#if VDBG
888 RLOGD("dispatchSIM_APDU");
889#endif
890 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
891
892 // Note we only check status at the end. Any single failure leads to
893 // subsequent reads filing.
894 status = p.readInt32(&t);
895 apdu.sessionid = (int)t;
896
897 status = p.readInt32(&t);
898 apdu.cla = (int)t;
899
900 status = p.readInt32(&t);
901 apdu.instruction = (int)t;
902
903 status = p.readInt32(&t);
904 apdu.p1 = (int)t;
905
906 status = p.readInt32(&t);
907 apdu.p2 = (int)t;
908
909 status = p.readInt32(&t);
910 apdu.p3 = (int)t;
911
912 apdu.data = strdupReadString(p);
913
914 startRequest;
915 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
916 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
917 apdu.p3, (char*)apdu.data);
918 closeRequest;
919 printRequest(pRI->token, pRI->pCI->requestNumber);
920
921 if (status != NO_ERROR) {
922 goto invalid;
923 }
924
925 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
926
927#ifdef MEMSET_FREED
928 memsetString(apdu.data);
929#endif
930 free(apdu.data);
931
932#ifdef MEMSET_FREED
933 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
934#endif
935
936 return;
937invalid:
938 invalidCommandBlock(pRI);
939 return;
940}
941
942
943/**
944 * Callee expects const RIL_CallForwardInfo *
945 * Payload is:
946 * int32_t status/action
947 * int32_t reason
948 * int32_t serviceCode
949 * int32_t toa
950 * String number (0 length -> null)
951 * int32_t timeSeconds
952 */
953static void
954dispatchCallForward(Parcel &p, RequestInfo *pRI) {
955 RIL_CallForwardInfo cff;
xja1c30b82022-01-25 16:13:48 +0800956 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800957 status_t status;
958
959 RLOGD("dispatchCallForward");
960 memset (&cff, 0, sizeof(cff));
961
962 // note we only check status at the end
963
964 status = p.readInt32(&t);
965 cff.status = (int)t;
966
967 status = p.readInt32(&t);
968 cff.reason = (int)t;
969
970 status = p.readInt32(&t);
971 cff.serviceClass = (int)t;
972
973 status = p.readInt32(&t);
974 cff.toa = (int)t;
975
976 cff.number = strdupReadString(p);
977
978 status = p.readInt32(&t);
979 cff.timeSeconds = (int)t;
980
981 if (status != NO_ERROR) {
982 goto invalid;
983 }
984
985 // special case: number 0-length fields is null
986
987 if (cff.number != NULL && strlen (cff.number) == 0) {
988 cff.number = NULL;
989 }
990
991 startRequest;
992 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
993 cff.status, cff.reason, cff.serviceClass, cff.toa,
994 (char*)cff.number, cff.timeSeconds);
995 closeRequest;
996 printRequest(pRI->token, pRI->pCI->requestNumber);
997
998 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
999
1000#ifdef MEMSET_FREED
1001 memsetString(cff.number);
1002#endif
1003
1004 free (cff.number);
1005
1006#ifdef MEMSET_FREED
1007 memset(&cff, 0, sizeof(cff));
1008#endif
1009
1010 return;
1011invalid:
1012 invalidCommandBlock(pRI);
1013 return;
1014}
1015
1016
1017static void
1018dispatchRaw(Parcel &p, RequestInfo *pRI) {
1019 int32_t len;
1020 status_t status;
1021 const void *data;
1022
1023 status = p.readInt32(&len);
1024
1025 if (status != NO_ERROR) {
1026 goto invalid;
1027 }
1028
1029 // The java code writes -1 for null arrays
1030 if (((int)len) == -1) {
1031 data = NULL;
1032 len = 0;
1033 }
1034
1035 data = p.readInplace(len);
1036
1037 startRequest;
1038 appendPrintBuf("%sraw_size=%d", printBuf, len);
1039 closeRequest;
1040 printRequest(pRI->token, pRI->pCI->requestNumber);
1041
1042 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
1043
1044 return;
1045invalid:
1046 invalidCommandBlock(pRI);
1047 return;
1048}
1049
1050static status_t
1051constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
xja1c30b82022-01-25 16:13:48 +08001052 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001053 uint8_t ut;
1054 status_t status;
1055 int32_t digitCount;
1056 int digitLimit;
1057
1058 memset(&rcsm, 0, sizeof(rcsm));
1059
1060 status = p.readInt32(&t);
1061 rcsm.uTeleserviceID = (int) t;
1062
1063 status = p.read(&ut,sizeof(ut));
1064 rcsm.bIsServicePresent = (uint8_t) ut;
1065
1066 status = p.readInt32(&t);
1067 rcsm.uServicecategory = (int) t;
1068
1069 status = p.readInt32(&t);
1070 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1071
1072 status = p.readInt32(&t);
1073 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1074
1075 status = p.readInt32(&t);
1076 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1077
1078 status = p.readInt32(&t);
1079 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1080
1081 status = p.read(&ut,sizeof(ut));
1082 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1083
1084 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1085 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1086 status = p.read(&ut,sizeof(ut));
1087 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1088 }
1089
1090 status = p.readInt32(&t);
1091 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1092
1093 status = p.read(&ut,sizeof(ut));
1094 rcsm.sSubAddress.odd = (uint8_t) ut;
1095
1096 status = p.read(&ut,sizeof(ut));
1097 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1098
1099 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1100 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1101 status = p.read(&ut,sizeof(ut));
1102 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1103 }
1104
1105 status = p.readInt32(&t);
1106 rcsm.uBearerDataLen = (int) t;
1107
1108 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1109 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1110 status = p.read(&ut, sizeof(ut));
1111 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1112 }
1113
1114 if (status != NO_ERROR) {
1115 return status;
1116 }
1117
1118 startRequest;
1119 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1120 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1121 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1122 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1123 closeRequest;
1124
1125 printRequest(pRI->token, pRI->pCI->requestNumber);
1126
1127 return status;
1128}
1129
1130static void
1131dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1132 RIL_CDMA_SMS_Message rcsm;
1133
1134 RLOGD("dispatchCdmaSms");
1135 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1136 goto invalid;
1137 }
1138
1139 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
1140
1141#ifdef MEMSET_FREED
1142 memset(&rcsm, 0, sizeof(rcsm));
1143#endif
1144
1145 return;
1146
1147invalid:
1148 invalidCommandBlock(pRI);
1149 return;
1150}
1151
1152static void
1153dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1154 RIL_IMS_SMS_Message rism;
1155 RIL_CDMA_SMS_Message rcsm;
1156
1157 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1158
1159 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1160 goto invalid;
1161 }
1162 memset(&rism, 0, sizeof(rism));
1163 rism.tech = RADIO_TECH_3GPP2;
1164 rism.retry = retry;
1165 rism.messageRef = messageRef;
1166 rism.message.cdmaMessage = &rcsm;
1167
1168 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
1169 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1170 +sizeof(rcsm),pRI, pRI->socket_id);
1171
1172#ifdef MEMSET_FREED
1173 memset(&rcsm, 0, sizeof(rcsm));
1174 memset(&rism, 0, sizeof(rism));
1175#endif
1176
1177 return;
1178
1179invalid:
1180 invalidCommandBlock(pRI);
1181 return;
1182}
1183
1184static void
1185dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1186 RIL_IMS_SMS_Message rism;
1187 int32_t countStrings;
1188 status_t status;
1189 size_t datalen;
1190 char **pStrings;
1191 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1192
1193 status = p.readInt32 (&countStrings);
1194
1195 if (status != NO_ERROR) {
1196 goto invalid;
1197 }
1198
1199 memset(&rism, 0, sizeof(rism));
1200 rism.tech = RADIO_TECH_3GPP;
1201 rism.retry = retry;
1202 rism.messageRef = messageRef;
1203
1204 startRequest;
1205 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1206 (int)rism.tech, (int)rism.retry, rism.messageRef);
1207 if (countStrings == 0) {
1208 // just some non-null pointer
1209 pStrings = (char **)alloca(sizeof(char *));
1210 datalen = 0;
1211 } else if (((int)countStrings) == -1) {
1212 pStrings = NULL;
1213 datalen = 0;
1214 } else {
1215 datalen = sizeof(char *) * countStrings;
1216
1217 pStrings = (char **)alloca(datalen);
1218
1219 for (int i = 0 ; i < countStrings ; i++) {
1220 pStrings[i] = strdupReadString(p);
1221 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1222 }
1223 }
1224 removeLastChar;
1225 closeRequest;
1226 printRequest(pRI->token, pRI->pCI->requestNumber);
1227
1228 rism.message.gsmMessage = pStrings;
1229 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
1230 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1231 +datalen, pRI, pRI->socket_id);
1232
1233 if (pStrings != NULL) {
1234 for (int i = 0 ; i < countStrings ; i++) {
1235#ifdef MEMSET_FREED
1236 memsetString (pStrings[i]);
1237#endif
1238 free(pStrings[i]);
1239 }
1240
1241#ifdef MEMSET_FREED
1242 memset(pStrings, 0, datalen);
1243#endif
1244 }
1245
1246#ifdef MEMSET_FREED
1247 memset(&rism, 0, sizeof(rism));
1248#endif
1249 return;
1250invalid:
1251 ALOGE("dispatchImsGsmSms invalid block");
1252 invalidCommandBlock(pRI);
1253 return;
1254}
1255
1256static void
1257dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1258 int32_t t;
1259 status_t status = p.readInt32(&t);
1260 RIL_RadioTechnologyFamily format;
1261 uint8_t retry;
1262 int32_t messageRef;
1263
1264 RLOGD("dispatchImsSms");
1265 if (status != NO_ERROR) {
1266 goto invalid;
1267 }
1268 format = (RIL_RadioTechnologyFamily) t;
1269
1270 // read retry field
1271 status = p.read(&retry,sizeof(retry));
1272 if (status != NO_ERROR) {
1273 goto invalid;
1274 }
1275 // read messageRef field
1276 status = p.read(&messageRef,sizeof(messageRef));
1277 if (status != NO_ERROR) {
1278 goto invalid;
1279 }
1280
1281 if (RADIO_TECH_3GPP == format) {
1282 dispatchImsGsmSms(p, pRI, retry, messageRef);
1283 } else if (RADIO_TECH_3GPP2 == format) {
1284 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1285 } else {
1286 ALOGE("requestImsSendSMS invalid format value =%d", format);
1287 }
1288
1289 return;
1290
1291invalid:
1292 invalidCommandBlock(pRI);
1293 return;
1294}
1295
1296static void
1297dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1298 RIL_CDMA_SMS_Ack rcsa;
xja1c30b82022-01-25 16:13:48 +08001299 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001300 status_t status;
1301 int32_t digitCount;
1302
1303 RLOGD("dispatchCdmaSmsAck");
1304 memset(&rcsa, 0, sizeof(rcsa));
1305
1306 status = p.readInt32(&t);
1307 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1308
1309 status = p.readInt32(&t);
1310 rcsa.uSMSCauseCode = (int) t;
1311
1312 if (status != NO_ERROR) {
1313 goto invalid;
1314 }
1315
1316 startRequest;
1317 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1318 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1319 closeRequest;
1320
1321 printRequest(pRI->token, pRI->pCI->requestNumber);
1322
1323 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
1324
1325#ifdef MEMSET_FREED
1326 memset(&rcsa, 0, sizeof(rcsa));
1327#endif
1328
1329 return;
1330
1331invalid:
1332 invalidCommandBlock(pRI);
1333 return;
1334}
1335
1336static void
1337dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1338 int32_t t;
1339 status_t status;
1340 int32_t num;
1341
1342 status = p.readInt32(&num);
1343 if (status != NO_ERROR) {
1344 goto invalid;
1345 }
1346
1347 {
1348 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1349 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
1350
1351 startRequest;
1352 for (int i = 0 ; i < num ; i++ ) {
1353 gsmBciPtrs[i] = &gsmBci[i];
1354
1355 status = p.readInt32(&t);
1356 gsmBci[i].fromServiceId = (int) t;
1357
1358 status = p.readInt32(&t);
1359 gsmBci[i].toServiceId = (int) t;
1360
1361 status = p.readInt32(&t);
1362 gsmBci[i].fromCodeScheme = (int) t;
1363
1364 status = p.readInt32(&t);
1365 gsmBci[i].toCodeScheme = (int) t;
1366
1367 status = p.readInt32(&t);
1368 gsmBci[i].selected = (uint8_t) t;
1369
1370 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1371 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1372 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1373 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1374 gsmBci[i].selected);
1375 }
1376 closeRequest;
1377
1378 if (status != NO_ERROR) {
1379 goto invalid;
1380 }
1381
1382 printRequest(pRI->token, pRI->pCI->requestNumber);
1383
1384 CALL_ONREQUEST(pRI->pCI->requestNumber,
1385 gsmBciPtrs,
1386 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1387 pRI, pRI->socket_id);
1388
1389#ifdef MEMSET_FREED
1390 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1391 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
1392#endif
1393 }
1394
1395 return;
1396
1397invalid:
1398 invalidCommandBlock(pRI);
1399 return;
1400}
1401
1402static void
1403dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1404 int32_t t;
1405 status_t status;
1406 int32_t num;
1407
1408 status = p.readInt32(&num);
1409 if (status != NO_ERROR) {
1410 goto invalid;
1411 }
1412
1413 {
1414 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1415 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
1416
1417 startRequest;
1418 for (int i = 0 ; i < num ; i++ ) {
1419 cdmaBciPtrs[i] = &cdmaBci[i];
1420
1421 status = p.readInt32(&t);
1422 cdmaBci[i].service_category = (int) t;
1423
1424 status = p.readInt32(&t);
1425 cdmaBci[i].language = (int) t;
1426
1427 status = p.readInt32(&t);
1428 cdmaBci[i].selected = (uint8_t) t;
1429
1430 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1431 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1432 cdmaBci[i].language, cdmaBci[i].selected);
1433 }
1434 closeRequest;
1435
1436 if (status != NO_ERROR) {
1437 goto invalid;
1438 }
1439 printRequest(pRI->token, pRI->pCI->requestNumber);
1440 CALL_ONREQUEST(pRI->pCI->requestNumber,
1441 cdmaBciPtrs,
1442 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1443 pRI, pRI->socket_id);
1444
1445#ifdef MEMSET_FREED
1446 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1447 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
1448#endif
1449 }
1450
1451 return;
1452
1453invalid:
1454 invalidCommandBlock(pRI);
1455 return;
1456}
1457
1458static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1459 RIL_CDMA_SMS_WriteArgs rcsw;
xja1c30b82022-01-25 16:13:48 +08001460 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001461 uint32_t ut;
xja1c30b82022-01-25 16:13:48 +08001462 uint8_t uct = 0;
lh7b0674a2022-01-10 00:34:35 -08001463 status_t status;
1464 int32_t digitCount;
1465 int32_t digitLimit;
1466
1467 memset(&rcsw, 0, sizeof(rcsw));
1468
1469 status = p.readInt32(&t);
1470 rcsw.status = t;
1471
1472 status = p.readInt32(&t);
1473 rcsw.message.uTeleserviceID = (int) t;
1474
1475 status = p.read(&uct,sizeof(uct));
1476 rcsw.message.bIsServicePresent = (uint8_t) uct;
1477
1478 status = p.readInt32(&t);
1479 rcsw.message.uServicecategory = (int) t;
1480
1481 status = p.readInt32(&t);
1482 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1483
1484 status = p.readInt32(&t);
1485 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1486
1487 status = p.readInt32(&t);
1488 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1489
1490 status = p.readInt32(&t);
1491 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1492
1493 status = p.read(&uct,sizeof(uct));
1494 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1495
1496 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1497
1498 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1499 status = p.read(&uct,sizeof(uct));
1500 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1501 }
1502
1503 status = p.readInt32(&t);
1504 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1505
1506 status = p.read(&uct,sizeof(uct));
1507 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1508
1509 status = p.read(&uct,sizeof(uct));
1510 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1511
1512 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1513
1514 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1515 status = p.read(&uct,sizeof(uct));
1516 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1517 }
1518
1519 status = p.readInt32(&t);
1520 rcsw.message.uBearerDataLen = (int) t;
1521
1522 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1523
1524 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1525 status = p.read(&uct, sizeof(uct));
1526 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1527 }
1528
1529 if (status != NO_ERROR) {
1530 goto invalid;
1531 }
1532
1533 startRequest;
1534 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1535 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1536 message.sAddress.number_mode=%d, \
1537 message.sAddress.number_type=%d, ",
1538 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1539 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1540 rcsw.message.sAddress.number_mode,
1541 rcsw.message.sAddress.number_type);
1542 closeRequest;
1543
1544 printRequest(pRI->token, pRI->pCI->requestNumber);
1545
1546 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
1547
1548#ifdef MEMSET_FREED
1549 memset(&rcsw, 0, sizeof(rcsw));
1550#endif
1551
1552 return;
1553
1554invalid:
1555 invalidCommandBlock(pRI);
1556 return;
1557
1558}
1559
1560// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1561// Version 4 of the RIL interface adds a new PDP type parameter to support
1562// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1563// RIL, remove the parameter from the request.
1564static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1565 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1566 const int numParamsRilV3 = 6;
1567
1568 // The first bytes of the RIL parcel contain the request number and the
1569 // serial number - see processCommandBuffer(). Copy them over too.
1570 int pos = p.dataPosition();
1571
1572 int numParams = p.readInt32();
1573 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1574/* Parcel p2;
1575 p2.appendFrom(&p, 0, pos);
1576 p2.writeInt32(numParamsRilV3);
1577 for(int i = 0; i < numParamsRilV3; i++) {
1578 p2.writeString16(p.readString16());
1579 }
1580 p2.setDataPosition(pos);
1581 dispatchStrings(p2, pRI);*/
1582 } else {
1583 p.setDataPosition(pos);
1584 dispatchStrings(p, pRI);
1585 }
1586}
1587
1588static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1589{
1590 RIL_InitialAttachApn pf;
xja1c30b82022-01-25 16:13:48 +08001591 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001592 status_t status;
1593
1594 memset(&pf, 0, sizeof(pf));
1595
1596 pf.apn = strdupReadString(p);
1597 pf.protocol = strdupReadString(p);
1598
1599 status = p.readInt32(&t);
1600 pf.authtype = (int) t;
1601
1602 pf.username = strdupReadString(p);
1603 pf.password = strdupReadString(p);
1604
1605 startRequest;
1606 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1607 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
1608 closeRequest;
1609 printRequest(pRI->token, pRI->pCI->requestNumber);
1610
1611 if (status != NO_ERROR) {
1612 goto invalid;
1613 }
1614 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1615
1616#ifdef MEMSET_FREED
1617 memsetString(pf.apn);
1618 memsetString(pf.protocol);
1619 memsetString(pf.username);
1620 memsetString(pf.password);
1621#endif
1622
1623 free(pf.apn);
1624 free(pf.protocol);
1625 free(pf.username);
1626 free(pf.password);
1627
1628#ifdef MEMSET_FREED
1629 memset(&pf, 0, sizeof(pf));
1630#endif
1631
1632 return;
1633invalid:
1634 invalidCommandBlock(pRI);
1635 return;
1636}
1637
1638static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1639 RIL_NV_ReadItem nvri;
xja1c30b82022-01-25 16:13:48 +08001640 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001641 status_t status;
1642
1643 memset(&nvri, 0, sizeof(nvri));
1644
1645 status = p.readInt32(&t);
1646 nvri.itemID = (RIL_NV_Item) t;
1647
1648 if (status != NO_ERROR) {
1649 goto invalid;
1650 }
1651
1652 startRequest;
1653 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1654 closeRequest;
1655
1656 printRequest(pRI->token, pRI->pCI->requestNumber);
1657
1658 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1659
1660#ifdef MEMSET_FREED
1661 memset(&nvri, 0, sizeof(nvri));
1662#endif
1663
1664 return;
1665
1666invalid:
1667 invalidCommandBlock(pRI);
1668 return;
1669}
1670
1671static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1672 RIL_NV_WriteItem nvwi;
xja1c30b82022-01-25 16:13:48 +08001673 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001674 status_t status;
1675
1676 memset(&nvwi, 0, sizeof(nvwi));
1677
1678 status = p.readInt32(&t);
1679 nvwi.itemID = (RIL_NV_Item) t;
1680
1681 nvwi.value = strdupReadString(p);
1682
1683 if (status != NO_ERROR || nvwi.value == NULL) {
1684 goto invalid;
1685 }
1686
1687 startRequest;
1688 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1689 nvwi.value);
1690 closeRequest;
1691
1692 printRequest(pRI->token, pRI->pCI->requestNumber);
1693
1694 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1695
1696#ifdef MEMSET_FREED
1697 memsetString(nvwi.value);
1698#endif
1699
1700 free(nvwi.value);
1701
1702#ifdef MEMSET_FREED
1703 memset(&nvwi, 0, sizeof(nvwi));
1704#endif
1705
1706 return;
1707
1708invalid:
1709 invalidCommandBlock(pRI);
1710 return;
1711}
1712
1713
1714static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1715 RIL_SelectUiccSub uicc_sub;
1716 status_t status;
1717 int32_t t;
1718 memset(&uicc_sub, 0, sizeof(uicc_sub));
1719
1720 status = p.readInt32(&t);
1721 if (status != NO_ERROR) {
1722 goto invalid;
1723 }
1724 uicc_sub.slot = (int) t;
1725
1726 status = p.readInt32(&t);
1727 if (status != NO_ERROR) {
1728 goto invalid;
1729 }
1730 uicc_sub.app_index = (int) t;
1731
1732 status = p.readInt32(&t);
1733 if (status != NO_ERROR) {
1734 goto invalid;
1735 }
1736 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1737
1738 status = p.readInt32(&t);
1739 if (status != NO_ERROR) {
1740 goto invalid;
1741 }
1742 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1743
1744 startRequest;
1745 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1746 uicc_sub.act_status);
1747 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1748 uicc_sub.app_index, uicc_sub.act_status);
1749 closeRequest;
1750 printRequest(pRI->token, pRI->pCI->requestNumber);
1751
1752 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1753
1754#ifdef MEMSET_FREED
1755 memset(&uicc_sub, 0, sizeof(uicc_sub));
1756#endif
1757 return;
1758
1759invalid:
1760 invalidCommandBlock(pRI);
1761 return;
1762}
1763
1764static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1765{
1766 RIL_SimAuthentication pf;
xja1c30b82022-01-25 16:13:48 +08001767 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001768 status_t status;
1769
1770 memset(&pf, 0, sizeof(pf));
1771
1772 status = p.readInt32(&t);
1773 pf.authContext = (int) t;
1774 pf.authData = strdupReadString(p);
1775 pf.aid = strdupReadString(p);
1776
1777 startRequest;
1778 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1779 closeRequest;
1780 printRequest(pRI->token, pRI->pCI->requestNumber);
1781
1782 if (status != NO_ERROR) {
1783 goto invalid;
1784 }
1785 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1786
1787#ifdef MEMSET_FREED
1788 memsetString(pf.authData);
1789 memsetString(pf.aid);
1790#endif
1791
1792 free(pf.authData);
1793 free(pf.aid);
1794
1795#ifdef MEMSET_FREED
1796 memset(&pf, 0, sizeof(pf));
1797#endif
1798
1799 return;
1800invalid:
1801 invalidCommandBlock(pRI);
1802 return;
1803}
1804
1805static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1806 int32_t t;
1807 status_t status;
1808 int32_t num;
1809
1810 status = p.readInt32(&num);
1811 if (status != NO_ERROR) {
1812 goto invalid;
1813 }
1814
1815 {
1816 RIL_DataProfileInfo dataProfiles[num];
1817 RIL_DataProfileInfo *dataProfilePtrs[num];
1818
1819 startRequest;
1820 for (int i = 0 ; i < num ; i++ ) {
1821 dataProfilePtrs[i] = &dataProfiles[i];
1822
1823 status = p.readInt32(&t);
1824 dataProfiles[i].profileId = (int) t;
1825
1826 dataProfiles[i].apn = strdupReadString(p);
1827 dataProfiles[i].protocol = strdupReadString(p);
1828 status = p.readInt32(&t);
1829 dataProfiles[i].authType = (int) t;
1830
1831 dataProfiles[i].user = strdupReadString(p);
1832 dataProfiles[i].password = strdupReadString(p);
1833
1834 status = p.readInt32(&t);
1835 dataProfiles[i].type = (int) t;
1836
1837 status = p.readInt32(&t);
1838 dataProfiles[i].maxConnsTime = (int) t;
1839 status = p.readInt32(&t);
1840 dataProfiles[i].maxConns = (int) t;
1841 status = p.readInt32(&t);
1842 dataProfiles[i].waitTime = (int) t;
1843
1844 status = p.readInt32(&t);
1845 dataProfiles[i].enabled = (int) t;
1846
1847 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1848 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1849 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1850 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1851 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1852 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1853 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1854 RLOGD("[%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1855user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1856waitTime =%d, enabled =%d]", i, dataProfiles[i].profileId,
1857 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1858 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1859 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1860 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1861 }
1862 closeRequest;
1863 printRequest(pRI->token, pRI->pCI->requestNumber);
1864
1865 if (status != NO_ERROR) {
1866 goto invalid;
1867 }
1868 CALL_ONREQUEST(pRI->pCI->requestNumber,
1869 dataProfilePtrs,
1870 num * sizeof(RIL_DataProfileInfo *),
1871 pRI, pRI->socket_id);
1872 for(int i = 0; i< num; i++) {
1873 free(dataProfiles[i].apn);
1874 free(dataProfiles[i].protocol);
1875 free(dataProfiles[i].user);
1876 free(dataProfiles[i].password);
1877 }
1878#ifdef MEMSET_FREED
1879 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1880 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1881#endif
1882 }
1883
1884 return;
1885
1886invalid:
1887 invalidCommandBlock(pRI);
1888 return;
1889}
1890
1891static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1892 RIL_RadioCapability rc;
xja1c30b82022-01-25 16:13:48 +08001893 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001894 status_t status;
1895
1896 memset (&rc, 0, sizeof(RIL_RadioCapability));
1897
1898 status = p.readInt32(&t);
1899 rc.version = (int)t;
1900 if (status != NO_ERROR) {
1901 goto invalid;
1902 }
1903
1904 status = p.readInt32(&t);
1905 rc.session= (int)t;
1906 if (status != NO_ERROR) {
1907 goto invalid;
1908 }
1909
1910 status = p.readInt32(&t);
1911 rc.phase= (int)t;
1912 if (status != NO_ERROR) {
1913 goto invalid;
1914 }
1915
1916 status = p.readInt32(&t);
1917 rc.rat = (int)t;
1918 if (status != NO_ERROR) {
1919 goto invalid;
1920 }
1921
1922 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
1923 if (status != NO_ERROR) {
1924 goto invalid;
1925 }
1926
1927 status = p.readInt32(&t);
1928 rc.status = (int)t;
1929
1930 if (status != NO_ERROR) {
1931 goto invalid;
1932 }
1933
1934 startRequest;
1935 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, logicalModemUuid:%s, status:%d",
1936 printBuf, rc.version, rc.session, rc.phase, rc.rat, rc.logicalModemUuid, rc.status);
1937
1938 closeRequest;
1939 printRequest(pRI->token, pRI->pCI->requestNumber);
1940
1941 CALL_ONREQUEST(pRI->pCI->requestNumber,
1942 &rc,
1943 sizeof(RIL_RadioCapability),
1944 pRI, pRI->socket_id);
1945 return;
1946invalid:
1947 invalidCommandBlock(pRI);
1948 return;
1949}
1950
1951#if 0
1952static int
1953blockingWrite(int fd, const void *buffer, size_t len) {
1954 size_t writeOffset = 0;
1955 const uint8_t *toWrite;
1956
1957 toWrite = (const uint8_t *)buffer;
1958
1959 while (writeOffset < len) {
1960 ssize_t written;
1961 do {
1962 written = write (fd, toWrite + writeOffset,
1963 len - writeOffset);
1964 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
1965
1966 if (written >= 0) {
1967 writeOffset += written;
1968 } else { // written < 0
1969 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
1970 close(fd);
1971 return -1;
1972 }
1973 }
1974#if VDBG
1975 RLOGE("RIL Response bytes written:%d", writeOffset);
1976#endif
1977 return 0;
1978}
1979
1980static int
1981sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
1982 int fd = s_ril_param_socket.fdCommand;
1983 int ret;
1984 uint32_t header;
1985 pthread_mutex_t * writeMutexHook = &s_writeMutex;
1986
1987#if VDBG
1988 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
1989#endif
1990
1991#if (SIM_COUNT >= 2)
1992 if (socket_id == RIL_SOCKET_2) {
1993 fd = s_ril_param_socket2.fdCommand;
1994 writeMutexHook = &s_writeMutex_socket2;
1995 }
1996#if (SIM_COUNT >= 3)
1997 else if (socket_id == RIL_SOCKET_3) {
1998 fd = s_ril_param_socket3.fdCommand;
1999 writeMutexHook = &s_writeMutex_socket3;
2000 }
2001#endif
2002#if (SIM_COUNT >= 4)
2003 else if (socket_id == RIL_SOCKET_4) {
2004 fd = s_ril_param_socket4.fdCommand;
2005 writeMutexHook = &s_writeMutex_socket4;
2006 }
2007#endif
2008#endif
2009 if (fd < 0) {
2010 return -1;
2011 }
2012
2013 if (dataSize > MAX_COMMAND_BYTES) {
2014 RLOGE("RIL: packet larger than %u (%u)",
2015 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2016
2017 return -1;
2018 }
2019
2020 pthread_mutex_lock(writeMutexHook);
2021
2022 header = htonl(dataSize);
2023
2024 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2025
2026 if (ret < 0) {
2027 pthread_mutex_unlock(writeMutexHook);
2028 return ret;
2029 }
2030
2031 ret = blockingWrite(fd, data, dataSize);
2032
2033 if (ret < 0) {
2034 pthread_mutex_unlock(writeMutexHook);
2035 return ret;
2036 }
2037
2038 pthread_mutex_unlock(writeMutexHook);
2039
2040 return 0;
2041}
2042
2043static int
2044sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
2045 printResponse;
2046 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
2047}
2048#endif
2049
2050/** response is an int* pointing to an array of ints */
2051
2052static int
2053responseInts(Parcel &p, void *response, size_t responselen) {
2054 int numInts;
2055
2056 if (response == NULL && responselen != 0) {
2057 RLOGE("invalid response: NULL");
2058 return RIL_ERRNO_INVALID_RESPONSE;
2059 }
2060 if (responselen % sizeof(int) != 0) {
2061 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2062 (int)responselen, (int)sizeof(int));
2063 return RIL_ERRNO_INVALID_RESPONSE;
2064 }
2065
2066 int *p_int = (int *) response;
2067
2068 numInts = responselen / sizeof(int);
2069 p.writeInt32 (numInts);
2070
2071 /* each int*/
2072 startResponse;
2073 for (int i = 0 ; i < numInts ; i++) {
2074 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2075 p.writeInt32(p_int[i]);
2076 }
2077 removeLastChar;
2078 closeResponse;
2079
2080 return 0;
2081}
2082
2083// Response is an int or RIL_LastCallFailCauseInfo.
2084// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2085// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2086static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2087 if (response == NULL && responselen != 0) {
2088 RLOGE("invalid response: NULL");
2089 return RIL_ERRNO_INVALID_RESPONSE;
2090 }
2091
2092 if (responselen == sizeof(int)) {
2093 startResponse;
2094 int *p_int = (int *) response;
2095 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2096 p.writeInt32(p_int[0]);
2097 removeLastChar;
2098 closeResponse;
2099 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2100 startResponse;
2101 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2102 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2103 p_fail_cause_info->vendor_cause);
2104 p.writeInt32(p_fail_cause_info->cause_code);
2105 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2106 removeLastChar;
2107 closeResponse;
2108 } else {
2109 RLOGE("responseFailCause: invalid response length %d expected an int or "
2110 "RIL_LastCallFailCauseInfo", (int)responselen);
2111 return RIL_ERRNO_INVALID_RESPONSE;
2112 }
2113
2114 return 0;
2115}
2116
2117/** response is a char **, pointing to an array of char *'s
2118 The parcel will begin with the version */
2119static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2120 p.writeInt32(version);
2121 return responseStrings(p, response, responselen);
2122}
2123
2124/** response is a char **, pointing to an array of char *'s */
2125static int responseStrings(Parcel &p, void *response, size_t responselen) {
2126 int numStrings;
2127
2128 if (response == NULL && responselen != 0) {
2129 RLOGE("invalid response: NULL");
2130 return RIL_ERRNO_INVALID_RESPONSE;
2131 }
2132 if (responselen % sizeof(char *) != 0) {
2133 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
2134 (int)responselen, (int)sizeof(char *));
2135 return RIL_ERRNO_INVALID_RESPONSE;
2136 }
2137
2138 if (response == NULL) {
2139 p.writeInt32 (0);
2140 } else {
2141 char **p_cur = (char **) response;
2142
2143 numStrings = responselen / sizeof(char *);
2144 p.writeInt32 (numStrings);
2145
2146 /* each string*/
2147 startResponse;
2148 for (int i = 0 ; i < numStrings ; i++) {
2149 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2150 writeStringToParcel (p, p_cur[i]);
2151 }
2152 removeLastChar;
2153 closeResponse;
2154 }
2155 return 0;
2156}
2157
2158
2159/**
2160 * NULL strings are accepted
2161 * FIXME currently ignores responselen
2162 */
2163static int responseString(Parcel &p, void *response, size_t responselen) {
2164 /* one string only */
2165 startResponse;
2166 appendPrintBuf("%s%s", printBuf, (char*)response);
2167 closeResponse;
2168
2169 writeStringToParcel(p, (const char *)response);
2170 return 0;
2171}
lxfdb3a24c2023-11-20 06:26:13 -08002172//xf.li@20231120 modify for T8TSK-291 start
2173static int responseStringNoLog(Parcel &p, void *response, size_t responselen) {
2174 /* one string only */
2175 startResponse;
2176 char log_buf[512] = {0};
2177 snprintf(log_buf, sizeof(log_buf), "%s", (char*)response);
2178 encode_log(log_buf, 6);
2179// appendPrintBuf("%s%s", printBuf, "(has got)");
2180 closeResponse;
lh7b0674a2022-01-10 00:34:35 -08002181
lxfdb3a24c2023-11-20 06:26:13 -08002182 writeStringToParcel(p, (const char *)response);
2183 return 0;
2184}
lxf2d6e8ae2023-12-05 00:32:26 -08002185
2186static int responseStringsNoLog(Parcel &p, void *response, size_t responselen) {
2187 int numStrings;
2188 char log_buf[512] = {0};
2189
2190 if (response == NULL && responselen != 0) {
2191 RLOGE("invalid response: NULL");
2192 return RIL_ERRNO_INVALID_RESPONSE;
2193 }
2194 if (responselen % sizeof(char *) != 0) {
2195 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
2196 (int)responselen, (int)sizeof(char *));
2197 return RIL_ERRNO_INVALID_RESPONSE;
2198 }
2199
2200 if (response == NULL) {
2201 p.writeInt32 (0);
2202 } else {
2203 char **p_cur = (char **) response;
2204
2205 numStrings = responselen / sizeof(char *);
2206 p.writeInt32 (numStrings);
2207
2208 /* each string*/
2209 startResponse;
2210 for (int i = 0 ; i < numStrings ; i++) {
2211 //appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2212 memset(log_buf, 0, sizeof(log_buf));
2213 snprintf(log_buf, sizeof(log_buf), "%s,", (char*)p_cur[i]);
2214 encode_log(log_buf, 6);
2215 writeStringToParcel (p, p_cur[i]);
2216 }
2217 removeLastChar;
2218 closeResponse;
2219 }
2220 return 0;
2221}
lxfdb3a24c2023-11-20 06:26:13 -08002222//xf.li@20231120 modify for T8TSK-291 end
lh7b0674a2022-01-10 00:34:35 -08002223static int responseVoid(Parcel &p, void *response, size_t responselen) {
2224 startResponse;
2225 removeLastChar;
2226 return 0;
2227}
2228
2229static int responseCallList(Parcel &p, void *response, size_t responselen) {
2230 int num;
2231
2232 if (response == NULL && responselen != 0) {
2233 RLOGE("invalid response: NULL");
2234 return RIL_ERRNO_INVALID_RESPONSE;
2235 }
2236
2237 if (responselen % sizeof (RIL_Call *) != 0) {
2238 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
2239 (int)responselen, (int)sizeof (RIL_Call *));
2240 return RIL_ERRNO_INVALID_RESPONSE;
2241 }
2242
2243 startResponse;
2244 /* number of call info's */
2245 num = responselen / sizeof(RIL_Call *);
2246 p.writeInt32(num);
2247 for (int i = 0 ; i < num ; i++) {
2248 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2249 /* each call info */
2250 p.writeInt32(p_cur->state);
2251 p.writeInt32(p_cur->index);
2252 p.writeInt32(p_cur->toa);
2253 p.writeInt32(p_cur->isMpty);
2254 p.writeInt32(p_cur->isMT);
2255 p.writeInt32(p_cur->als);
2256 p.writeInt32(p_cur->isVoice);
2257 p.writeInt32(p_cur->isVoicePrivacy);
2258 writeStringToParcel(p, p_cur->number);
2259 p.writeInt32(p_cur->numberPresentation);
2260 writeStringToParcel(p, p_cur->name);
2261 p.writeInt32(p_cur->namePresentation);
2262 // Remove when partners upgrade to version 3
2263 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2264 p.writeInt32(0); /* UUS Information is absent */
2265 } else {
2266 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2267 p.writeInt32(1); /* UUS Information is present */
2268 p.writeInt32(uusInfo->uusType);
2269 p.writeInt32(uusInfo->uusDcs);
2270 p.writeInt32(uusInfo->uusLength);
2271 p.write(uusInfo->uusData, uusInfo->uusLength);
2272 }
2273 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2274 printBuf,
2275 p_cur->index,
2276 callStateToString(p_cur->state),
2277 p_cur->toa);
2278 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2279 printBuf,
2280 (p_cur->isMpty)?"conf":"norm",
2281 (p_cur->isMT)?"mt":"mo",
2282 p_cur->als,
2283 (p_cur->isVoice)?"voc":"nonvoc",
2284 (p_cur->isVoicePrivacy)?"evp":"noevp");
2285 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2286 printBuf,
2287 p_cur->number,
2288 p_cur->numberPresentation,
2289 p_cur->name,
2290 p_cur->namePresentation);
2291 if(p_cur->isMT) {
2292 printf("[EVENT][MT_CALL] phone number is %s\n",p_cur->number);
2293 }
2294 }
2295 removeLastChar;
2296 closeResponse;
2297
2298 return 0;
2299}
2300
2301static int responseSMS(Parcel &p, void *response, size_t responselen) {
2302 if (response == NULL) {
2303 RLOGE("invalid response: NULL");
2304 return RIL_ERRNO_INVALID_RESPONSE;
2305 }
2306
2307 if (responselen != sizeof (RIL_SMS_Response) ) {
2308 RLOGE("invalid response length %d expected %d",
2309 (int)responselen, (int)sizeof (RIL_SMS_Response));
2310 return RIL_ERRNO_INVALID_RESPONSE;
2311 }
2312
2313 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2314
2315 p.writeInt32(p_cur->messageRef);
2316 writeStringToParcel(p, p_cur->ackPDU);
2317 p.writeInt32(p_cur->errorCode);
2318
2319 startResponse;
2320 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2321 (char*)p_cur->ackPDU, p_cur->errorCode);
2322 closeResponse;
2323 bool ifResend;
2324 if(isGostEcall())
2325 {
2326 if(p_cur->errorCode == 0)
2327 {
2328 //delete MSD
2329 gostDelSaveSmsData();
2330 //no resend
2331 ifResend = false;
2332 }
2333 else
2334 {
2335 //resend MSD
2336 ifResend = true;
2337 }
2338 gostEcallResendMsd(ifResend);
2339 }
2340 return 0;
2341}
2342
2343static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2344{
2345 if (response == NULL && responselen != 0) {
2346 RLOGE("invalid response: NULL");
2347 return RIL_ERRNO_INVALID_RESPONSE;
2348 }
2349
2350 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
2351 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
2352 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2353 return RIL_ERRNO_INVALID_RESPONSE;
2354 }
2355
2356 // Write version
2357 p.writeInt32(4);
2358
2359 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2360 p.writeInt32(num);
2361
2362 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2363 startResponse;
2364 int i;
2365 for (i = 0; i < num; i++) {
2366 p.writeInt32(p_cur[i].cid);
2367 p.writeInt32(p_cur[i].active);
2368 writeStringToParcel(p, p_cur[i].type);
2369 // apn is not used, so don't send.
2370 writeStringToParcel(p, p_cur[i].address);
2371 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2372 p_cur[i].cid,
2373 (p_cur[i].active==0)?"down":"up",
2374 (char*)p_cur[i].type,
2375 (char*)p_cur[i].address);
2376 }
2377 removeLastChar;
2378 closeResponse;
2379
2380 return 0;
2381}
2382
2383static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2384{
2385 if (response == NULL && responselen != 0) {
2386 RLOGE("invalid response: NULL");
2387 return RIL_ERRNO_INVALID_RESPONSE;
2388 }
2389
2390 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2391 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2392 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2393 return RIL_ERRNO_INVALID_RESPONSE;
2394 }
2395
2396 // Write version
2397 p.writeInt32(6);
2398
2399 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2400 p.writeInt32(num);
2401
2402 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2403 startResponse;
2404 int i;
2405 for (i = 0; i < num; i++) {
2406 p.writeInt32((int)p_cur[i].status);
2407 p.writeInt32(p_cur[i].suggestedRetryTime);
2408 p.writeInt32(p_cur[i].cid);
2409 p.writeInt32(p_cur[i].active);
2410 writeStringToParcel(p, p_cur[i].type);
2411 writeStringToParcel(p, p_cur[i].ifname);
2412 writeStringToParcel(p, p_cur[i].addresses);
2413 writeStringToParcel(p, p_cur[i].dnses);
2414 writeStringToParcel(p, p_cur[i].gateways);
2415 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2416 p_cur[i].status,
2417 p_cur[i].suggestedRetryTime,
2418 p_cur[i].cid,
2419 (p_cur[i].active==0)?"down":"up",
2420 (char*)p_cur[i].type,
2421 (char*)p_cur[i].ifname,
2422 (char*)p_cur[i].addresses,
2423 (char*)p_cur[i].dnses,
2424 (char*)p_cur[i].gateways);
2425 }
2426 removeLastChar;
2427 closeResponse;
2428 return 0;
2429}
2430
2431static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2432{
2433 if (response == NULL && responselen != 0) {
2434 RLOGE("invalid response: NULL");
2435 return RIL_ERRNO_INVALID_RESPONSE;
2436 }
2437
2438 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2439 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2440 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2441 return RIL_ERRNO_INVALID_RESPONSE;
2442 }
2443
2444 // Write version
2445 p.writeInt32(10);
2446
2447 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2448 p.writeInt32(num);
2449
2450 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2451 startResponse;
2452 int i;
2453 for (i = 0; i < num; i++) {
2454 p.writeInt32((int)p_cur[i].status);
2455 p.writeInt32(p_cur[i].suggestedRetryTime);
2456 p.writeInt32(p_cur[i].cid);
2457 p.writeInt32(p_cur[i].active);
2458 writeStringToParcel(p, p_cur[i].type);
2459 writeStringToParcel(p, p_cur[i].ifname);
2460 writeStringToParcel(p, p_cur[i].addresses);
2461 writeStringToParcel(p, p_cur[i].dnses);
2462 writeStringToParcel(p, p_cur[i].gateways);
2463 writeStringToParcel(p, p_cur[i].pcscf);
2464 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2465 p_cur[i].status,
2466 p_cur[i].suggestedRetryTime,
2467 p_cur[i].cid,
2468 (p_cur[i].active==0)?"down":"up",
2469 (char*)p_cur[i].type,
2470 (char*)p_cur[i].ifname,
2471 (char*)p_cur[i].addresses,
2472 (char*)p_cur[i].dnses,
2473 (char*)p_cur[i].gateways,
2474 (char*)p_cur[i].pcscf);
2475 }
2476 removeLastChar;
2477 closeResponse;
2478
2479 return 0;
2480}
2481
2482
2483static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2484{
2485 if (s_callbacks.version < 5) {
2486 RLOGD("responseDataCallList: v4");
2487 return responseDataCallListV4(p, response, responselen);
2488 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2489 return responseDataCallListV6(p, response, responselen);
2490 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2491 return responseDataCallListV9(p, response, responselen);
2492 } else {
2493 if (response == NULL && responselen != 0) {
2494 RLOGE("invalid response: NULL");
2495 return RIL_ERRNO_INVALID_RESPONSE;
2496 }
2497
2498 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2499 RLOGE("invalid response length %d expected multiple of %d",
2500 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2501 return RIL_ERRNO_INVALID_RESPONSE;
2502 }
2503
2504 // Write version
2505 p.writeInt32(11);
2506
2507 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2508 p.writeInt32(num);
2509
2510 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2511 startResponse;
2512 int i;
2513 for (i = 0; i < num; i++) {
2514 p.writeInt32((int)p_cur[i].status);
2515 p.writeInt32(p_cur[i].suggestedRetryTime);
2516 p.writeInt32(p_cur[i].cid);
2517 p.writeInt32(p_cur[i].active);
2518 writeStringToParcel(p, p_cur[i].type);
2519 writeStringToParcel(p, p_cur[i].ifname);
2520 writeStringToParcel(p, p_cur[i].addresses);
2521 writeStringToParcel(p, p_cur[i].dnses);
2522 writeStringToParcel(p, p_cur[i].gateways);
2523 writeStringToParcel(p, p_cur[i].pcscf);
2524 p.writeInt32(p_cur[i].mtu);
2525 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2526 p_cur[i].status,
2527 p_cur[i].suggestedRetryTime,
2528 p_cur[i].cid,
2529 (p_cur[i].active==0)?"down":"up",
2530 (char*)p_cur[i].type,
2531 (char*)p_cur[i].ifname,
2532 (char*)p_cur[i].addresses,
2533 (char*)p_cur[i].dnses,
2534 (char*)p_cur[i].gateways,
2535 (char*)p_cur[i].pcscf,
2536 p_cur[i].mtu);
2537 }
2538 removeLastChar;
2539 closeResponse;
2540 }
2541
2542 return 0;
2543}
2544
2545static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2546{
2547 if (s_callbacks.version < 5) {
2548 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2549 } else {
2550 return responseDataCallList(p, response, responselen);
2551 }
2552}
2553
2554static int responseRaw(Parcel &p, void *response, size_t responselen) {
2555 if (response == NULL && responselen != 0) {
2556 RLOGE("invalid response: NULL with responselen != 0");
2557 return RIL_ERRNO_INVALID_RESPONSE;
2558 }
2559
2560 // The java code reads -1 size as null byte array
2561 if (response == NULL) {
2562 p.writeInt32(-1);
2563 } else {
2564 p.writeInt32(responselen);
2565 p.write(response, responselen);
2566 }
2567
2568 startResponse;
lxfdb3a24c2023-11-20 06:26:13 -08002569 //xf.li@20231120 modify for T8TSK-291 start
2570 char log_buf[512] = {0};
2571 if(strncmp("+CNUM:", (char*)response, strlen("+CNUM:")) == 0)
2572 {
2573 snprintf(log_buf, sizeof(log_buf), "len=%d,%s", responselen, (char*)response);
2574 encode_log(log_buf, 6);
2575 }
2576 else
2577 {
2578 appendPrintBuf("%slen=%d,%s", printBuf, responselen, (char*)response);
2579 }
2580 //xf.li@20231120 modify for T8TSK-291 end
lh7b0674a2022-01-10 00:34:35 -08002581 closeResponse;
2582 return 0;
2583}
lxfdb3a24c2023-11-20 06:26:13 -08002584//xf.li@20231120 modify for T8TSK-291 start
2585static void string_to_hex(unsigned char *Buff, unsigned int BuffLen, char *OutputStr)
2586{
2587 int i = 0;
2588 char TempBuff[512*2 + 1] = {0};
2589 char strBuff[512*2 + 1] = {0};
lh7b0674a2022-01-10 00:34:35 -08002590
lxfdb3a24c2023-11-20 06:26:13 -08002591 if(BuffLen > 512)
2592 {
2593 RLOGD("string_to_hex error!");
2594 return;
2595 }
2596 for(i = 0; i<BuffLen;i++)
2597 {
2598 sprintf(TempBuff,"%02x",(unsigned char)Buff[i]);
2599 strncat(strBuff,TempBuff,BuffLen*2);
2600 }
2601 strncpy(OutputStr, strBuff, BuffLen*2);
2602 return;
2603}
2604
2605static void encode_log(char input_str[], int n)
2606{
2607 char c;
2608 int i;
2609 char str[512*2 + 1] = {0};
2610 string_to_hex((unsigned char *)input_str, strlen(input_str), str);
2611 for( i=0; i<strlen(str); i++)
2612 {
2613 c = str[i];
2614 if(c>=' ' && c <= 'z')
2615 {
2616 if(c + n%90 <= 'z')
2617 {
2618 str[i] = (char)(c + n%90); //encode
2619 }
2620 else
2621 { //After encoding, the space beyond the end reaches ‘z’, and the cycle starts from the beginning.
2622 str[i] = (char)(c + n%90 - 90);//encode
2623 }
2624 }
2625 else
2626 {
2627 str[i]=c;
2628 }
2629 }
2630
2631 appendPrintBuf("%s%s", printBuf, str);
2632}
2633//decode() only for analysis log
2634static void decode_log(char str[], int n)
2635{
2636 char c;
2637 int i;
2638
2639 for(i=0; i<strlen(str); i++)
2640 {
2641 c=str[i];
2642
2643 if(c >= ' ' && c <= 'z')
2644 {
2645 if(c - n%90 >= ' ')
2646 {
2647 str[i] = (char)(c - n%90); //decode
2648 }
2649 else
2650 {
2651 //After decoding, there are over spaces until ‘z’, and the lowercase letters are processed into printable information by looping
2652 str[i] = (char)(c - n%90 + 90); //decode
2653 }
2654 }
2655 else
2656 {
2657 str[i]=c;
2658 }
2659 }
2660}
2661//xf.li@20231120 modify for T8TSK-291 end
lh7b0674a2022-01-10 00:34:35 -08002662
2663static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2664 if (response == NULL) {
2665 RLOGE("invalid response: NULL");
2666 return RIL_ERRNO_INVALID_RESPONSE;
2667 }
2668
2669 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
2670 RLOGE("invalid response length was %d expected %d",
2671 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2672 return RIL_ERRNO_INVALID_RESPONSE;
2673 }
2674
2675 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2676 p.writeInt32(p_cur->sw1);
2677 p.writeInt32(p_cur->sw2);
2678 writeStringToParcel(p, p_cur->simResponse);
2679
2680 startResponse;
2681 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2682 (char*)p_cur->simResponse);
2683 closeResponse;
2684
2685
2686 return 0;
2687}
2688
2689static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2690 int num;
2691
2692 if (response == NULL && responselen != 0) {
2693 RLOGE("invalid response: NULL");
2694 return RIL_ERRNO_INVALID_RESPONSE;
2695 }
2696
2697 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
2698 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
2699 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2700 return RIL_ERRNO_INVALID_RESPONSE;
2701 }
2702
2703 /* number of call info's */
2704 num = responselen / sizeof(RIL_CallForwardInfo *);
2705 p.writeInt32(num);
2706
2707 startResponse;
2708 for (int i = 0 ; i < num ; i++) {
2709 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2710
2711 p.writeInt32(p_cur->status);
2712 p.writeInt32(p_cur->reason);
2713 p.writeInt32(p_cur->serviceClass);
2714 p.writeInt32(p_cur->toa);
2715 writeStringToParcel(p, p_cur->number);
2716 p.writeInt32(p_cur->timeSeconds);
2717 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2718 (p_cur->status==1)?"enable":"disable",
2719 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2720 (char*)p_cur->number,
2721 p_cur->timeSeconds);
2722 }
2723 removeLastChar;
2724 closeResponse;
2725
2726 return 0;
2727}
2728
2729static int responseSsn(Parcel &p, void *response, size_t responselen) {
2730 if (response == NULL) {
2731 RLOGE("invalid response: NULL");
2732 return RIL_ERRNO_INVALID_RESPONSE;
2733 }
2734
2735 if (responselen != sizeof(RIL_SuppSvcNotification)) {
2736 RLOGE("invalid response length was %d expected %d",
2737 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2738 return RIL_ERRNO_INVALID_RESPONSE;
2739 }
2740
2741 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2742 p.writeInt32(p_cur->notificationType);
2743 p.writeInt32(p_cur->code);
2744 p.writeInt32(p_cur->index);
2745 p.writeInt32(p_cur->type);
2746 writeStringToParcel(p, p_cur->number);
2747
2748 startResponse;
2749 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2750 (p_cur->notificationType==0)?"mo":"mt",
2751 p_cur->code, p_cur->index, p_cur->type,
2752 (char*)p_cur->number);
2753 closeResponse;
2754
2755 return 0;
2756}
2757
2758static int responseCellList(Parcel &p, void *response, size_t responselen) {
2759 int num;
2760
2761 if (response == NULL && responselen != 0) {
2762 RLOGE("invalid response: NULL");
2763 return RIL_ERRNO_INVALID_RESPONSE;
2764 }
2765
2766 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
2767 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
2768 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2769 return RIL_ERRNO_INVALID_RESPONSE;
2770 }
2771
2772 startResponse;
2773 /* number of records */
2774 num = responselen / sizeof(RIL_NeighboringCell *);
2775 p.writeInt32(num);
2776
2777 for (int i = 0 ; i < num ; i++) {
2778 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2779
2780 p.writeInt32(p_cur->rssi);
2781 writeStringToParcel (p, p_cur->cid);
2782
2783 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2784 p_cur->cid, p_cur->rssi);
2785 }
2786 removeLastChar;
2787 closeResponse;
2788
2789 return 0;
2790}
2791
2792/**
2793 * Marshall the signalInfoRecord into the parcel if it exists.
2794 */
2795static void marshallSignalInfoRecord(Parcel &p,
2796 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2797 p.writeInt32(p_signalInfoRecord.isPresent);
2798 p.writeInt32(p_signalInfoRecord.signalType);
2799 p.writeInt32(p_signalInfoRecord.alertPitch);
2800 p.writeInt32(p_signalInfoRecord.signal);
2801}
2802
2803static int responseCdmaInformationRecords(Parcel &p,
2804 void *response, size_t responselen) {
2805 int num;
2806 char* string8 = NULL;
2807 int buffer_lenght;
2808 RIL_CDMA_InformationRecord *infoRec;
2809
2810 if (response == NULL && responselen != 0) {
2811 RLOGE("invalid response: NULL");
2812 return RIL_ERRNO_INVALID_RESPONSE;
2813 }
2814
2815 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
2816 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
2817 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2818 return RIL_ERRNO_INVALID_RESPONSE;
2819 }
2820
2821 RIL_CDMA_InformationRecords *p_cur =
2822 (RIL_CDMA_InformationRecords *) response;
2823 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2824
2825 startResponse;
2826 p.writeInt32(num);
2827
2828 for (int i = 0 ; i < num ; i++) {
2829 infoRec = &p_cur->infoRec[i];
2830 p.writeInt32(infoRec->name);
2831 switch (infoRec->name) {
2832 case RIL_CDMA_DISPLAY_INFO_REC:
2833 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2834 if (infoRec->rec.display.alpha_len >
2835 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
2836 RLOGE("invalid display info response length %d \
2837 expected not more than %d\n",
2838 (int)infoRec->rec.display.alpha_len,
2839 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2840 return RIL_ERRNO_INVALID_RESPONSE;
2841 }
2842 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2843 * sizeof(char) );
2844 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2845 string8[i] = infoRec->rec.display.alpha_buf[i];
2846 }
2847 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2848 writeStringToParcel(p, (const char*)string8);
2849 free(string8);
2850 string8 = NULL;
2851 break;
2852 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2853 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2854 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2855 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
2856 RLOGE("invalid display info response length %d \
2857 expected not more than %d\n",
2858 (int)infoRec->rec.number.len,
2859 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2860 return RIL_ERRNO_INVALID_RESPONSE;
2861 }
2862 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2863 * sizeof(char) );
2864 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2865 string8[i] = infoRec->rec.number.buf[i];
2866 }
2867 string8[(int)infoRec->rec.number.len] = '\0';
2868 writeStringToParcel(p, (const char*)string8);
2869 free(string8);
2870 string8 = NULL;
2871 p.writeInt32(infoRec->rec.number.number_type);
2872 p.writeInt32(infoRec->rec.number.number_plan);
2873 p.writeInt32(infoRec->rec.number.pi);
2874 p.writeInt32(infoRec->rec.number.si);
2875 break;
2876 case RIL_CDMA_SIGNAL_INFO_REC:
2877 p.writeInt32(infoRec->rec.signal.isPresent);
2878 p.writeInt32(infoRec->rec.signal.signalType);
2879 p.writeInt32(infoRec->rec.signal.alertPitch);
2880 p.writeInt32(infoRec->rec.signal.signal);
2881
2882 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2883 alertPitch=%X, signal=%X, ",
2884 printBuf, (int)infoRec->rec.signal.isPresent,
2885 (int)infoRec->rec.signal.signalType,
2886 (int)infoRec->rec.signal.alertPitch,
2887 (int)infoRec->rec.signal.signal);
2888 removeLastChar;
2889 break;
2890 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2891 if (infoRec->rec.redir.redirectingNumber.len >
2892 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
2893 RLOGE("invalid display info response length %d \
2894 expected not more than %d\n",
2895 (int)infoRec->rec.redir.redirectingNumber.len,
2896 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2897 return RIL_ERRNO_INVALID_RESPONSE;
2898 }
2899 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2900 .len + 1) * sizeof(char) );
2901 for (int i = 0;
2902 i < infoRec->rec.redir.redirectingNumber.len;
2903 i++) {
2904 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2905 }
2906 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2907 writeStringToParcel(p, (const char*)string8);
2908 free(string8);
2909 string8 = NULL;
2910 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2911 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2912 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2913 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2914 p.writeInt32(infoRec->rec.redir.redirectingReason);
2915 break;
2916 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2917 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2918 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2919 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2920 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2921
2922 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2923 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2924 lineCtrlPowerDenial=%d, ", printBuf,
2925 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2926 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2927 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2928 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2929 removeLastChar;
2930 break;
2931 case RIL_CDMA_T53_CLIR_INFO_REC:
2932 p.writeInt32((int)(infoRec->rec.clir.cause));
2933
2934 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2935 removeLastChar;
2936 break;
2937 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2938 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2939 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2940
2941 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2942 infoRec->rec.audioCtrl.upLink,
2943 infoRec->rec.audioCtrl.downLink);
2944 removeLastChar;
2945 break;
2946 case RIL_CDMA_T53_RELEASE_INFO_REC:
2947 // TODO(Moto): See David Krause, he has the answer:)
2948 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
2949 return RIL_ERRNO_INVALID_RESPONSE;
2950 default:
2951 RLOGE("Incorrect name value");
2952 return RIL_ERRNO_INVALID_RESPONSE;
2953 }
2954 }
2955 closeResponse;
2956
2957 return 0;
2958}
2959
2960static int responseRilSignalStrength(Parcel &p,
2961 void *response, size_t responselen) {
2962 if (response == NULL && responselen != 0) {
2963 RLOGE("invalid response: NULL");
2964 return RIL_ERRNO_INVALID_RESPONSE;
2965 }
2966
2967 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2968#ifdef TELEMATIC_5G_SUPPORT
2969 RIL_SignalStrength_v14 *p_cur = ((RIL_SignalStrength_v14 *) response);
2970#else
2971 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
2972#endif
2973 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2974 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2975 p.writeInt32(p_cur->GW_SignalStrength.timingAdvance);
2976 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2977 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2978 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2979 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2980 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2981 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2982 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2983 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2984 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2985 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2986 p.writeInt32(p_cur->LTE_SignalStrength.timingAdvance);
2987 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.signalStrength);
2988 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.bitErrorRate);
2989 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2990 p.writeInt32(p_cur->WCDMA_SignalStrength.signalStrength);
2991 p.writeInt32(p_cur->WCDMA_SignalStrength.bitErrorRate);
2992 p.writeInt32(p_cur->WCDMA_SignalStrength.rscp);
2993 p.writeInt32(p_cur->WCDMA_SignalStrength.ecno);
2994#ifdef TELEMATIC_5G_SUPPORT
2995 p.writeInt32(p_cur->NR_SignalStrength.ssRsrp);
2996 p.writeInt32(p_cur->NR_SignalStrength.ssRsrq);
2997 p.writeInt32(p_cur->NR_SignalStrength.ssSinr);
2998 p.writeInt32(p_cur->NR_SignalStrength.csiRsrp);
2999 p.writeInt32(p_cur->NR_SignalStrength.csiRsrq);
3000 p.writeInt32(p_cur->NR_SignalStrength.csiSinr);
3001#endif
3002 startResponse;
3003
3004#ifdef TELEMATIC_5G_SUPPORT
3005 appendPrintBuf("%s[GW_SS.signalStrength=%d,GW_SS.bitErrorRate=%d,GW_SS.timingAdvance=%d,\
3006 CDMA_SS.dbm=%d,CDMA_SS.ecio=%d,\
3007 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,EVDO_SS.signalNoiseRatio=%d,\
3008 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,LTE_SS.rssnr=%d,LTE_SS.cqi=%d,LTE_SS.timingAdvance=%d,\
3009 TDSCDMA_SS.signalStrength=%d,TDSCDMA_SS.bitErrorRate=%d,TDSCDMA_SS.rscp=%d,\
3010 WCDMA_SS.signalStrength=%d,WCDMA_SS.bitErrorRate=%d,WCDMA_SS.rscp=%d,WCDMA_SS.ecno=%d,\
3011 NR_SignalStrength.ssRsrp=%d,NR_SignalStrength.ssRsrq=%d,NR_SignalStrength.ssSinr=%d,\
3012 NR_SignalStrength.csiRsrp=%d,NR_SignalStrength.csiRsrq=%d,NR_SignalStrength.csiSinr=%d]",
3013 printBuf,
3014 p_cur->GW_SignalStrength.signalStrength,
3015 p_cur->GW_SignalStrength.bitErrorRate,
3016 p_cur->GW_SignalStrength.timingAdvance,
3017 p_cur->CDMA_SignalStrength.dbm,
3018 p_cur->CDMA_SignalStrength.ecio,
3019 p_cur->EVDO_SignalStrength.dbm,
3020 p_cur->EVDO_SignalStrength.ecio,
3021 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3022 p_cur->LTE_SignalStrength.signalStrength,
3023 p_cur->LTE_SignalStrength.rsrp,
3024 p_cur->LTE_SignalStrength.rsrq,
3025 p_cur->LTE_SignalStrength.rssnr,
3026 p_cur->LTE_SignalStrength.cqi,
3027 p_cur->LTE_SignalStrength.timingAdvance,
3028 p_cur->TD_SCDMA_SignalStrength.signalStrength,
3029 p_cur->TD_SCDMA_SignalStrength.bitErrorRate,
3030 p_cur->TD_SCDMA_SignalStrength.rscp,
3031 p_cur->WCDMA_SignalStrength.signalStrength,
3032 p_cur->WCDMA_SignalStrength.bitErrorRate,
3033 p_cur->WCDMA_SignalStrength.rscp,
3034 p_cur->WCDMA_SignalStrength.ecno,
3035 p_cur->NR_SignalStrength.ssRsrp,
3036 p_cur->NR_SignalStrength.ssRsrq,
3037 p_cur->NR_SignalStrength.ssSinr,
3038 p_cur->NR_SignalStrength.csiRsrp,
3039 p_cur->NR_SignalStrength.csiRsrq,
3040 p_cur->NR_SignalStrength.csiSinr);
3041#else
3042 appendPrintBuf("%s[GW_SS.signalStrength=%d,GW_SS.bitErrorRate=%d,GW_SS.timingAdvance=%d,\
3043 CDMA_SS.dbm=%d,CDMA_SS.ecio=%d,\
3044 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,EVDO_SS.signalNoiseRatio=%d,\
3045 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,LTE_SS.rssnr=%d,LTE_SS.cqi=%d,LTE_SS.timingAdvance=%d,\
3046 TDSCDMA_SS.signalStrength=%d,TDSCDMA_SS.bitErrorRate=%d,TDSCDMA_SS.rscp=%d,\
3047 WCDMA_SS.signalStrength=%d,WCDMA_SS.bitErrorRate=%d,WCDMA_SS.rscp=%d,WCDMA_SS.ecno=%d]",
3048 printBuf,
3049 p_cur->GW_SignalStrength.signalStrength,
3050 p_cur->GW_SignalStrength.bitErrorRate,
3051 p_cur->GW_SignalStrength.timingAdvance,
3052 p_cur->CDMA_SignalStrength.dbm,
3053 p_cur->CDMA_SignalStrength.ecio,
3054 p_cur->EVDO_SignalStrength.dbm,
3055 p_cur->EVDO_SignalStrength.ecio,
3056 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3057 p_cur->LTE_SignalStrength.signalStrength,
3058 p_cur->LTE_SignalStrength.rsrp,
3059 p_cur->LTE_SignalStrength.rsrq,
3060 p_cur->LTE_SignalStrength.rssnr,
3061 p_cur->LTE_SignalStrength.cqi,
3062 p_cur->LTE_SignalStrength.timingAdvance,
3063 p_cur->TD_SCDMA_SignalStrength.signalStrength,
3064 p_cur->TD_SCDMA_SignalStrength.bitErrorRate,
3065 p_cur->TD_SCDMA_SignalStrength.rscp,
3066 p_cur->WCDMA_SignalStrength.signalStrength,
3067 p_cur->WCDMA_SignalStrength.bitErrorRate,
3068 p_cur->WCDMA_SignalStrength.rscp,
3069 p_cur->WCDMA_SignalStrength.ecno);
3070#endif
3071 closeResponse;
3072
3073 if (signal_strength_printf != 0) {
3074 printf(
3075 "\n\n[QUERY][SIGNAL]\nsignalStrength=%d,\nbitErrorRate=%d,\nLTE_SS.signalStrength=%d,\n"
3076 "LTE_SS.rsrp=%d,\nLTE_SS.rsrq=%d,\nLTE_SS.rssnr=%d,\nLTE_SS.cqi=%d\n\n",
3077 p_cur->GW_SignalStrength.signalStrength,
3078 p_cur->GW_SignalStrength.bitErrorRate,
3079 p_cur->LTE_SignalStrength.signalStrength,
3080 p_cur->LTE_SignalStrength.rsrp,
3081 p_cur->LTE_SignalStrength.rsrq,
3082 p_cur->LTE_SignalStrength.rssnr,
3083 p_cur->LTE_SignalStrength.cqi);
3084 }
3085 } else {
3086 RLOGE("invalid response length");
3087 return RIL_ERRNO_INVALID_RESPONSE;
3088 }
3089
3090 return 0;
3091}
3092
3093static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3094 if ((response == NULL) || (responselen == 0)) {
3095 return responseVoid(p, response, responselen);
3096 } else {
3097 return responseCdmaSignalInfoRecord(p, response, responselen);
3098 }
3099}
3100
3101static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3102 if (response == NULL || responselen == 0) {
3103 RLOGE("invalid response: NULL");
3104 return RIL_ERRNO_INVALID_RESPONSE;
3105 }
3106
3107 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
3108 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
3109 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3110 return RIL_ERRNO_INVALID_RESPONSE;
3111 }
3112
3113 startResponse;
3114
3115 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3116 marshallSignalInfoRecord(p, *p_cur);
3117
3118 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3119 signal=%d]",
3120 printBuf,
3121 p_cur->isPresent,
3122 p_cur->signalType,
3123 p_cur->alertPitch,
3124 p_cur->signal);
3125
3126 closeResponse;
3127 return 0;
3128}
3129
3130static int responseCdmaCallWaiting(Parcel &p, void *response,
3131 size_t responselen) {
3132 if (response == NULL && responselen != 0) {
3133 RLOGE("invalid response: NULL");
3134 return RIL_ERRNO_INVALID_RESPONSE;
3135 }
3136
3137 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
3138 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
3139 }
3140
3141 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3142
3143 writeStringToParcel(p, p_cur->number);
3144 p.writeInt32(p_cur->numberPresentation);
3145 writeStringToParcel(p, p_cur->name);
3146 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3147
3148 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3149 p.writeInt32(p_cur->number_type);
3150 p.writeInt32(p_cur->number_plan);
3151 } else {
3152 p.writeInt32(0);
3153 p.writeInt32(0);
3154 }
3155
3156 printf("[EVENT][MT_CALL] phone number is %s\n",p_cur->number);
3157 startResponse;
3158 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3159 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3160 signal=%d,number_type=%d,number_plan=%d]",
3161 printBuf,
3162 p_cur->number,
3163 p_cur->numberPresentation,
3164 p_cur->name,
3165 p_cur->signalInfoRecord.isPresent,
3166 p_cur->signalInfoRecord.signalType,
3167 p_cur->signalInfoRecord.alertPitch,
3168 p_cur->signalInfoRecord.signal,
3169 p_cur->number_type,
3170 p_cur->number_plan);
3171 closeResponse;
3172
3173 return 0;
3174}
3175
3176static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3177 if (response == NULL && responselen != 0) {
3178 RLOGE("responseSimRefresh: invalid response: NULL");
3179 return RIL_ERRNO_INVALID_RESPONSE;
3180 }
3181
3182 startResponse;
3183 if (s_callbacks.version == 7) {
3184 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3185 p.writeInt32(p_cur->result);
3186 p.writeInt32(p_cur->ef_id);
3187 writeStringToParcel(p, p_cur->aid);
3188
3189 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3190 printBuf,
3191 p_cur->result,
3192 p_cur->ef_id,
3193 p_cur->aid);
3194 } else {
3195 int *p_cur = ((int *) response);
3196 p.writeInt32(p_cur[0]);
3197 p.writeInt32(p_cur[1]);
3198 writeStringToParcel(p, NULL);
3199
3200 appendPrintBuf("%sresult=%d, ef_id=%d",
3201 printBuf,
3202 p_cur[0],
3203 p_cur[1]);
3204 }
3205 closeResponse;
3206
3207 return 0;
3208}
3209
3210static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3211{
3212 if (response == NULL && responselen != 0) {
3213 RLOGE("invalid response: NULL");
3214 return RIL_ERRNO_INVALID_RESPONSE;
3215 }
3216
3217 if (responselen % sizeof(RIL_CellInfo) != 0) {
3218 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3219 (int)responselen, (int)sizeof(RIL_CellInfo));
3220 return RIL_ERRNO_INVALID_RESPONSE;
3221 }
3222
3223 int num = responselen / sizeof(RIL_CellInfo);
3224 p.writeInt32(num);
3225
3226 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3227 startResponse;
3228 int i;
3229 for (i = 0; i < num; i++) {
3230 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3231 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3232 p.writeInt32((int)p_cur->cellInfoType);
3233 p.writeInt32(p_cur->registered);
3234 p.writeInt32(p_cur->timeStampType);
3235 p.writeInt64(p_cur->timeStamp);
3236 switch(p_cur->cellInfoType) {
3237 case RIL_CELL_INFO_TYPE_GSM: {
3238 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3239 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3240 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3241 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3242 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3243 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3244 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3245 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3246
3247 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3248 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3249 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3250 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3251 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3252 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3253 break;
3254 }
3255 case RIL_CELL_INFO_TYPE_WCDMA: {
3256 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3257 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3258 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3259 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3260 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3261 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3262 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3263 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3264 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3265
3266 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3267 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3268 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3269 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3270 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3271 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3272 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3273 break;
3274 }
3275 case RIL_CELL_INFO_TYPE_CDMA: {
3276 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3277 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3278 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3279 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3280 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3281 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3282
3283 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3284 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3285 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3286 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3287 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3288
3289 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3290 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3291 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3292 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3293 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3294 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3295
3296 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3297 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3298 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3299 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3300 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3301 break;
3302 }
3303 case RIL_CELL_INFO_TYPE_LTE: {
rjw62a60152022-06-09 17:43:01 +08003304 /*Typethree add for T800 earfcn 2022/06/09 start*/
rjwc5401bb2022-06-08 15:37:23 +08003305 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf,
lh7b0674a2022-01-10 00:34:35 -08003306 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3307 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3308 p_cur->CellInfo.lte.cellIdentityLte.ci,
3309 p_cur->CellInfo.lte.cellIdentityLte.pci,
rjwc5401bb2022-06-08 15:37:23 +08003310 p_cur->CellInfo.lte.cellIdentityLte.tac,
3311 p_cur->CellInfo.lte.cellIdentityLte.earfcn);
lh7b0674a2022-01-10 00:34:35 -08003312
3313 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3314 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3315 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3316 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3317 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
rjwc5401bb2022-06-08 15:37:23 +08003318 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
rjw62a60152022-06-09 17:43:01 +08003319 /*Typethree add for T800 earfcn 2022/06/09 end*/
lh7b0674a2022-01-10 00:34:35 -08003320 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3321 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3322 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3323 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3324 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3325 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3326 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3327 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3328 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3329 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3330 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3331 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3332 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3333 break;
3334 }
3335 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3336 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3337 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3338 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3339 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3340 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3341 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3342 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3343 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3344
3345 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3346 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3347 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3348 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3349 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3350 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3351 break;
3352 }
3353#ifdef TELEMATIC_5G_SUPPORT
3354 case RIL_CELL_INFO_TYPE_NR: {
rjw62a60152022-06-09 17:43:01 +08003355 /*Typethree add for T800 5G cid 2022/06/09 start*/
3356 appendPrintBuf("%s NR id: mcc=%d,mnc=%d,nci=%llu,pci=%d,tac=%d", printBuf,
lh7b0674a2022-01-10 00:34:35 -08003357 p_cur->CellInfo.nr.cellidentity.mcc,
3358 p_cur->CellInfo.nr.cellidentity.mnc,
3359 p_cur->CellInfo.nr.cellidentity.nci,
3360 p_cur->CellInfo.nr.cellidentity.pci,
3361 p_cur->CellInfo.nr.cellidentity.tac,
3362 p_cur->CellInfo.nr.cellidentity.nrarfcn);
3363
3364 p.writeInt32(p_cur->CellInfo.nr.cellidentity.mcc);
3365 p.writeInt32(p_cur->CellInfo.nr.cellidentity.mnc);
rjw62a60152022-06-09 17:43:01 +08003366 p.writeUint64(p_cur->CellInfo.nr.cellidentity.nci);
lh7b0674a2022-01-10 00:34:35 -08003367 p.writeInt32(p_cur->CellInfo.nr.cellidentity.pci);
3368 p.writeInt32(p_cur->CellInfo.nr.cellidentity.tac);
3369 p.writeInt32(p_cur->CellInfo.nr.cellidentity.nrarfcn);
rjw62a60152022-06-09 17:43:01 +08003370 /*Typethree add for T800 5G cid 2022/06/09 end*/
lh7b0674a2022-01-10 00:34:35 -08003371 appendPrintBuf("%s NRSS: ssRsrp=%d,ssRsrq=%d,ssSinr=%d,csiRsrp=%d,csiRsrq=%d,csiSinr=%d", printBuf,
3372 p_cur->CellInfo.nr.signalStrength.ssRsrp,
3373 p_cur->CellInfo.nr.signalStrength.ssRsrq,
3374 p_cur->CellInfo.nr.signalStrength.ssSinr,
3375 p_cur->CellInfo.nr.signalStrength.csiRsrp,
3376 p_cur->CellInfo.nr.signalStrength.csiRsrq,
3377 p_cur->CellInfo.nr.signalStrength.csiSinr);
3378 p.writeInt32(p_cur->CellInfo.nr.signalStrength.ssRsrp);
3379 p.writeInt32(p_cur->CellInfo.nr.signalStrength.ssRsrq);
3380 p.writeInt32(p_cur->CellInfo.nr.signalStrength.ssSinr);
3381 p.writeInt32(p_cur->CellInfo.nr.signalStrength.csiRsrp);
3382 p.writeInt32(p_cur->CellInfo.nr.signalStrength.csiRsrq);
3383 p.writeInt32(p_cur->CellInfo.nr.signalStrength.csiSinr);
3384 break;
3385 }
3386#endif
3387 }
3388 p_cur += 1;
3389 }
3390 removeLastChar;
3391 closeResponse;
3392
3393 return 0;
3394}
3395
3396static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3397{
3398 if (response == NULL && responselen != 0) {
3399 RLOGE("invalid response: NULL");
3400 return RIL_ERRNO_INVALID_RESPONSE;
3401 }
3402
3403 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3404 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3405 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3406 return RIL_ERRNO_INVALID_RESPONSE;
3407 }
3408
3409 int num = responselen / sizeof(RIL_HardwareConfig);
3410 int i;
3411 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3412
3413 p.writeInt32(num);
3414
3415 startResponse;
3416 for (i = 0; i < num; i++) {
3417 switch (p_cur[i].type) {
3418 case RIL_HARDWARE_CONFIG_MODEM: {
3419 writeStringToParcel(p, p_cur[i].uuid);
3420 p.writeInt32((int)p_cur[i].state);
3421 p.writeInt32(p_cur[i].cfg.modem.rat);
3422 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3423 p.writeInt32(p_cur[i].cfg.modem.maxData);
3424 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3425
3426 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3427 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3428 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3429 break;
3430 }
3431 case RIL_HARDWARE_CONFIG_SIM: {
3432 writeStringToParcel(p, p_cur[i].uuid);
3433 p.writeInt32((int)p_cur[i].state);
3434 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3435
3436 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3437 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3438 break;
3439 }
3440 }
3441 }
3442 removeLastChar;
3443 closeResponse;
3444 return 0;
3445}
3446
3447static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3448 if (response == NULL) {
3449 RLOGE("invalid response: NULL");
3450 return RIL_ERRNO_INVALID_RESPONSE;
3451 }
3452
3453 if (responselen != sizeof (RIL_RadioCapability) ) {
3454 RLOGE("invalid response length was %d expected %d",
3455 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3456 return RIL_ERRNO_INVALID_RESPONSE;
3457 }
3458
3459 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3460 p.writeInt32(p_cur->version);
3461 p.writeInt32(p_cur->session);
3462 p.writeInt32(p_cur->phase);
3463 p.writeInt32(p_cur->rat);
3464 writeStringToParcel(p, p_cur->logicalModemUuid);
3465 p.writeInt32(p_cur->status);
3466
3467 startResponse;
3468 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
3469 rat=%d,logicalModemUuid=%s,status=%d]",
3470 printBuf,
3471 p_cur->version,
3472 p_cur->session,
3473 p_cur->phase,
3474 p_cur->rat,
3475 p_cur->logicalModemUuid,
3476 p_cur->status);
3477 closeResponse;
3478 return 0;
3479}
3480
3481static int responseSSData(Parcel &p, void *response, size_t responselen) {
3482 RLOGD("In responseSSData");
3483 int num;
3484
3485 if (response == NULL && responselen != 0) {
3486 RLOGE("invalid response length was %d expected %d",
3487 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3488 return RIL_ERRNO_INVALID_RESPONSE;
3489 }
3490
3491 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3492 RLOGE("invalid response length %d, expected %d",
3493 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3494 return RIL_ERRNO_INVALID_RESPONSE;
3495 }
3496
3497 startResponse;
3498 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3499 p.writeInt32(p_cur->serviceType);
3500 p.writeInt32(p_cur->requestType);
3501 p.writeInt32(p_cur->teleserviceType);
3502 p.writeInt32(p_cur->serviceClass);
3503 p.writeInt32(p_cur->result);
3504
3505 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3506 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3507 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3508 RLOGE("numValidIndexes is greater than max value %d, "
3509 "truncating it to max value", NUM_SERVICE_CLASSES);
3510 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3511 }
3512 /* number of call info's */
3513 p.writeInt32(p_cur->cfData.numValidIndexes);
3514
3515 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3516 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3517
3518 p.writeInt32(cf.status);
3519 p.writeInt32(cf.reason);
3520 p.writeInt32(cf.serviceClass);
3521 p.writeInt32(cf.toa);
3522 writeStringToParcel(p, cf.number);
3523 p.writeInt32(cf.timeSeconds);
3524 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3525 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3526 (char*)cf.number, cf.timeSeconds);
3527 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3528 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3529 }
3530 } else {
3531 p.writeInt32 (SS_INFO_MAX);
3532
3533 /* each int*/
3534 for (int i = 0; i < SS_INFO_MAX; i++) {
3535 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3536 RLOGD("Data: %d",p_cur->ssInfo[i]);
3537 p.writeInt32(p_cur->ssInfo[i]);
3538 }
3539 }
3540 removeLastChar;
3541 closeResponse;
3542
3543 return 0;
3544}
3545
3546static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3547 if ((reqType == SS_INTERROGATION) &&
3548 (serType == SS_CFU ||
3549 serType == SS_CF_BUSY ||
3550 serType == SS_CF_NO_REPLY ||
3551 serType == SS_CF_NOT_REACHABLE ||
3552 serType == SS_CF_ALL ||
3553 serType == SS_CF_ALL_CONDITIONAL)) {
3554 return true;
3555 }
3556 return false;
3557}
3558
3559static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3560 p.writeInt32(num_apps);
3561 startResponse;
3562 for (int i = 0; i < num_apps; i++) {
3563 p.writeInt32(appStatus[i].app_type);
3564 p.writeInt32(appStatus[i].app_state);
3565 p.writeInt32(appStatus[i].perso_substate);
3566 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3567 writeStringToParcel(p, (const char*)
3568 (appStatus[i].app_label_ptr));
3569 p.writeInt32(appStatus[i].pin1_replaced);
3570 p.writeInt32(appStatus[i].pin1);
3571 p.writeInt32(appStatus[i].pin2);
3572 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3573 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3574 printBuf,
3575 appStatus[i].app_type,
3576 appStatus[i].app_state,
3577 appStatus[i].perso_substate,
3578 appStatus[i].aid_ptr,
3579 appStatus[i].app_label_ptr,
3580 appStatus[i].pin1_replaced,
3581 appStatus[i].pin1,
3582 appStatus[i].pin2);
3583 }
3584 closeResponse;
3585}
3586
3587static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3588 int i;
3589
3590 if (response == NULL && responselen != 0) {
3591 RLOGE("invalid response: NULL");
3592 return RIL_ERRNO_INVALID_RESPONSE;
3593 }
3594
3595 RLOGD("responselen: %d, v6: %d, v5: %d", responselen, sizeof (RIL_CardStatus_v6),sizeof (RIL_CardStatus_v5));
3596 if (responselen == sizeof (RIL_CardStatus_v6)) {
3597 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3598 p.writeInt32(p_cur->card_state);
3599 p.writeInt32(p_cur->universal_pin_state);
3600 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3601 p.writeInt32(p_cur->cdma_subscription_app_index);
3602 p.writeInt32(p_cur->ims_subscription_app_index);
3603
3604 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3605 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3606 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3607
3608 p.writeInt32(p_cur->card_state);
3609 p.writeInt32(p_cur->universal_pin_state);
3610 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3611 p.writeInt32(p_cur->cdma_subscription_app_index);
3612 p.writeInt32(-1);
3613
3614 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3615 } else {
3616 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3617 return RIL_ERRNO_INVALID_RESPONSE;
3618 }
3619
3620 return 0;
3621}
3622
3623static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3624 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3625 p.writeInt32(num);
3626
3627 startResponse;
3628 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3629 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3630 for (int i = 0; i < num; i++) {
3631 p.writeInt32(p_cur[i]->fromServiceId);
3632 p.writeInt32(p_cur[i]->toServiceId);
3633 p.writeInt32(p_cur[i]->fromCodeScheme);
3634 p.writeInt32(p_cur[i]->toCodeScheme);
3635 p.writeInt32(p_cur[i]->selected);
3636
3637 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3638 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3639 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3640 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3641 p_cur[i]->selected);
3642 }
3643 closeResponse;
3644
3645 return 0;
3646}
3647
3648static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3649 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3650 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3651
3652 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3653 p.writeInt32(num);
3654
3655 startResponse;
3656 for (int i = 0 ; i < num ; i++ ) {
3657 p.writeInt32(p_cur[i]->service_category);
3658 p.writeInt32(p_cur[i]->language);
3659 p.writeInt32(p_cur[i]->selected);
3660
3661 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3662 selected =%d], ",
3663 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3664 p_cur[i]->selected);
3665 }
3666 closeResponse;
3667
3668 return 0;
3669}
3670
3671static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3672 int num;
3673 int digitCount;
3674 int digitLimit;
3675 uint8_t uct;
3676 void* dest;
3677
3678 RLOGD("Inside responseCdmaSms");
3679
3680 if (response == NULL && responselen != 0) {
3681 RLOGE("invalid response: NULL");
3682 return RIL_ERRNO_INVALID_RESPONSE;
3683 }
3684
3685 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
3686 RLOGE("invalid response length was %d expected %d",
3687 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3688 return RIL_ERRNO_INVALID_RESPONSE;
3689 }
3690
3691 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3692 p.writeInt32(p_cur->uTeleserviceID);
3693 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3694 p.writeInt32(p_cur->uServicecategory);
3695 p.writeInt32(p_cur->sAddress.digit_mode);
3696 p.writeInt32(p_cur->sAddress.number_mode);
3697 p.writeInt32(p_cur->sAddress.number_type);
3698 p.writeInt32(p_cur->sAddress.number_plan);
3699 RLOGD("MT CDMA SMS: sAddress.number_plan = %d", p_cur->sAddress.number_plan);
3700 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3701 RLOGD("MT CDMA SMS: sAddress.number_of_digits = %d", p_cur->sAddress.number_of_digits);
3702 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3703 String8 str(""), temp;
3704 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3705 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3706 temp = String8::format("%d,", p_cur->sAddress.digits[digitCount]);
3707 str.append(temp);
3708 }
3709 RLOGD("MT CDMA SMS: sAddress.digits: {%s}", str.isEmpty()? "" : str.string());
3710
3711 p.writeInt32(p_cur->sSubAddress.subaddressType);
3712 RLOGD("MT CDMA SMS: sSubAddress.subaddressType = %d", p_cur->sSubAddress.subaddressType);
3713 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3714 RLOGD("MT CDMA SMS: sSubAddress.odd = %d", p_cur->sSubAddress.odd);
3715 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3716 RLOGD("MT CDMA SMS: sSubAddress.number_of_digits = %d", p_cur->sSubAddress.number_of_digits);
3717 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3718 str.clear();
3719 temp.clear();
3720 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3721 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3722 temp = String8::format("%d,", p_cur->sSubAddress.digits[digitCount]);
3723 str.append(temp);
3724 }
3725 RLOGD("MT CDMA SMS: sSubAddress.digits: {%s}", str.isEmpty() ? "" : str.string());
3726
3727 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3728 RLOGD("MT CDMA SMS: uBearerDataLen = %d", p_cur->uBearerDataLen);
3729 p.writeInt32(p_cur->uBearerDataLen);
3730 str.clear();
3731 temp.clear();
3732 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3733 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3734 temp = String8::format("%d,", p_cur->aBearerData[digitCount]);
3735 str.append(temp);
3736 }
3737 RLOGD("MT CDMA SMS: aBearerData: {%s}", str.isEmpty() ? "" : str.string());
3738
3739 startResponse;
3740 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3741 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3742 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3743 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3744 closeResponse;
3745 resposeCdmaSms(p_cur);
3746 return 0;
3747}
3748
3749static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3750{
3751 int num = responselen / sizeof(RIL_DcRtInfo);
3752 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3753 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3754 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3755 return RIL_ERRNO_INVALID_RESPONSE;
3756 }
3757
3758 startResponse;
3759 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3760 p.writeInt64(pDcRtInfo->time);
3761 p.writeInt32(pDcRtInfo->powerState);
3762 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3763 pDcRtInfo->time,
3764 pDcRtInfo->powerState);
3765 closeResponse;
3766
3767 return 0;
3768}
3769
3770static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3771 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3772 if (response == NULL) {
3773 RLOGE("invalid response: NULL");
3774 }
3775 else {
3776 RLOGE("responseLceStatus: invalid response length %d expecting len: %d",
3777 sizeof(RIL_LceStatusInfo), responselen);
3778 }
3779 return RIL_ERRNO_INVALID_RESPONSE;
3780 }
3781
3782 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3783 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3784 p.writeInt32(p_cur->actual_interval_ms);
3785
3786 startResponse;
3787 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3788 p_cur->lce_status, p_cur->actual_interval_ms);
3789 closeResponse;
3790
3791 return 0;
3792}
3793
3794static int responseLceData(Parcel &p, void *response, size_t responselen) {
3795 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3796 if (response == NULL) {
3797 RLOGE("invalid response: NULL");
3798 }
3799 else {
3800 RLOGE("responseLceData: invalid response length %d expecting len: %d",
3801 sizeof(RIL_LceDataInfo), responselen);
3802 }
3803 return RIL_ERRNO_INVALID_RESPONSE;
3804 }
3805
3806 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3807 p.writeInt32(p_cur->last_hop_capacity_kbps);
3808
3809 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3810 p.write((void *)&(p_cur->confidence_level), 1);
3811 p.write((void *)&(p_cur->lce_suspended), 1);
3812
3813 startResponse;
3814 appendPrintBuf("LCE info received: capacity %d confidence level %d and suspended %d",
3815 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3816 p_cur->lce_suspended);
3817 closeResponse;
3818
3819 return 0;
3820}
3821
3822static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3823 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3824 if (response == NULL) {
3825 RLOGE("invalid response: NULL");
3826 }
3827 else {
3828 RLOGE("responseActivityData: invalid response length %d expecting len: %d",
3829 sizeof(RIL_ActivityStatsInfo), responselen);
3830 }
3831 return RIL_ERRNO_INVALID_RESPONSE;
3832 }
3833
3834 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3835 p.writeInt32(p_cur->sleep_mode_time_ms);
3836 p.writeInt32(p_cur->idle_mode_time_ms);
3837 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3838 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3839 }
3840 p.writeInt32(p_cur->rx_mode_time_ms);
3841
3842 startResponse;
3843 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3844 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3845 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3846 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3847 closeResponse;
3848
3849 return 0;
3850}
3851
3852static int responseSmsSimMemStatus(Parcel &p, void *response, size_t responselen) {
3853 printf("=============%s\n", __FUNCTION__);
3854 if (response == NULL) {
3855 RLOGE("invalid response: NULL");
3856 return RIL_ERRNO_INVALID_RESPONSE;
3857 }
3858
3859 if (responselen != sizeof (RIL_SMS_Memory_Status) ) {
3860 RLOGE("invalid response length %d expected %d",
3861 (int)responselen, (int)sizeof (RIL_SMS_Memory_Status));
3862 return RIL_ERRNO_INVALID_RESPONSE;
3863 }
3864
3865 RIL_SMS_Memory_Status *p_cur = (RIL_SMS_Memory_Status *) response;
3866
3867 p.writeInt32(p_cur->used);
3868 p.writeInt32(p_cur->total);
3869
3870 startResponse;
3871 appendPrintBuf("%s%d,%d", printBuf, p_cur->used, p_cur->total);
3872 closeResponse;
3873
3874 printf("%s%d,%d\n", printBuf, p_cur->used, p_cur->total);
3875 RLOGE("===========================%s%d,%d", printBuf, p_cur->used, p_cur->total);
3876 return 0;
3877}
3878
3879void RIL_startEventLoop(void);
3880extern "C" void
3881RIL_register (const RIL_RadioFunctions *callbacks) {
3882 if (callbacks == NULL) {
3883 RLOGE("RIL_register: RIL_RadioFunctions * null");
3884 return;
3885 }
3886#if 0
3887 if (callbacks->version < RIL_VERSION_MIN) {
3888 RLOGE("RIL_register: version %d is to old, min version is %d",
3889 callbacks->version, RIL_VERSION_MIN);
3890 return;
3891 }
3892 if (callbacks->version > RIL_VERSION) {
3893 RLOGE("RIL_register: version %d is too new, max version is %d",
3894 callbacks->version, RIL_VERSION);
3895 return;
3896 }
3897#endif
3898 RLOGE("RIL_register: RIL version %d", callbacks->version);
3899
3900 if (s_registerCalled > 0) {
3901 RLOGE("RIL_register has been called more than once. "
3902 "Subsequent call ignored");
3903 return;
3904 }
3905
3906 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3907
3908 s_registerCalled = 1;
3909
3910 pthread_mutex_lock(&s_InitMutex);
3911 if(utils::is_support_dsds()) {
3912 while (s_isConnected[0] == 0 || s_isConnected[1] == 0) {
3913 pthread_cond_wait(&s_InitCond, &s_InitMutex);
3914 }
3915 } else {
3916 while (s_isConnected[0] == 0 && s_isConnected[1] == 0) {
3917 pthread_cond_wait(&s_InitCond, &s_InitMutex);
3918 }
3919 }
3920 pthread_mutex_unlock(&s_InitMutex);
3921 initCoditions();
3922 // New rild impl calls RIL_startEventLoop() first
3923 // old standalone impl wants it here.
3924
3925 if (s_started == 0) {
3926 RIL_startEventLoop();
3927 }
3928
3929}
3930
3931#if 0
3932static int
3933checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
3934 int ret = 0;
3935 /* Hook for current context
3936 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3937 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
3938 /* pendingRequestsHook refer to &s_pendingRequests */
3939 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
3940
3941 if (pRI == NULL) {
3942 return 0;
3943 }
3944
3945#if (SIM_COUNT >= 2)
3946 if (pRI->socket_id == RIL_SOCKET_2) {
3947 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3948 pendingRequestsHook = &s_pendingRequests_socket2;
3949 }
3950#if (SIM_COUNT >= 3)
3951 if (pRI->socket_id == RIL_SOCKET_3) {
3952 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3953 pendingRequestsHook = &s_pendingRequests_socket3;
3954 }
3955#endif
3956#if (SIM_COUNT >= 4)
3957 if (pRI->socket_id == RIL_SOCKET_4) {
3958 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3959 pendingRequestsHook = &s_pendingRequests_socket4;
3960 }
3961#endif
3962#endif
3963 pthread_mutex_lock(pendingRequestsMutexHook);
3964
3965 for(RequestInfo **ppCur = pendingRequestsHook
3966 ; *ppCur != NULL
3967 ; ppCur = &((*ppCur)->p_next)
3968 ) {
3969 if (pRI == *ppCur) {
3970 ret = 1;
3971
3972 *ppCur = (*ppCur)->p_next;
3973 break;
3974 }
3975 }
3976
3977 pthread_mutex_unlock(pendingRequestsMutexHook);
3978
3979 return ret;
3980}
3981
3982#endif
3983
llaaca09b2022-03-14 16:14:28 +08003984static void parse_version_buf(char *buf){
3985 char *p = buf;
3986 int flag = 0;
3987 int recv = 0;
3988 int tmp = -1;
3989 while (*p != '\0')
3990 {
3991 recv++;
3992 if(*p == '"'){
3993 tmp = recv;
3994 }
3995 if(tmp >= 0){
3996 buf[flag++] = buf[tmp++];
3997 if(buf[flag-1] == '\"'){
3998 buf[flag-1] = '\0';
3999 }
4000 }
4001 *p++;
4002 }
4003 return;
4004}
4005
4006static int lynq_get_version(){
4007 FILE *fp;
4008 char buf[128] = {0};
4009 char cgmr[128] = {0};
4010 sprintf(buf, "uci get lynq_uci_ro.lynq_version.LYNQ_SW_VERSION 2>&1");
4011 fp=popen(buf, "r");
4012 int n;
llacba3662022-04-15 16:57:13 +08004013 while(fgets(buf, sizeof(buf), fp) != NULL)
4014 {
llaaca09b2022-03-14 16:14:28 +08004015 }
4016 //parse_version_buf(buf);
llacba3662022-04-15 16:57:13 +08004017 sprintf(cgmr, "%s %s", "+CGMR:", buf);
llaaca09b2022-03-14 16:14:28 +08004018 n = write(ttyGS3_fd,cgmr,strlen(cgmr));
4019 if(n<0)
4020 {
4021 perror("lynq resp write:");
4022 }
4023 pclose(fp);
4024 return 0;
4025}
4026
ll2d5dbd12022-05-19 14:48:44 +08004027static int lynq_get_inside_version(){
4028 FILE *fp;
4029 char buf[128] = {0};
4030 char cgmr[128] = {0};
4031 sprintf(buf, "uci get lynq_uci_ro.lynq_version.LYNQ_SW_INSIDE_VERSION 2>&1");
4032 fp=popen(buf, "r");
4033 int n;
4034 while(fgets(buf, sizeof(buf), fp) != NULL)
4035 {
4036 }
4037 //parse_version_buf(buf);
4038 sprintf(cgmr, "%s %s", "+CGIR:", buf);
4039 n = write(ttyGS3_fd,cgmr,strlen(cgmr));
4040 if(n<0)
4041 {
4042 perror("lynq resp write:");
4043 }
4044 pclose(fp);
4045 return 0;
4046}
4047
4048/**
4049 * @brief cgmr ---> cgir
4050 *
4051 * @param response
4052 */
4053static void parse_inside_version(void *response)
4054{
4055 char *p = (char *)response;
4056 while (*p != 0)
4057 {
4058 if(*p == 'M')
4059 {
4060 *p = 'I';
4061 break;
4062 }
4063 else
4064 {
4065 *p ++;
4066 }
4067 }
4068 return;
4069}
4070
ll1d2ce042022-08-04 01:53:01 -07004071/**
4072 * @brief To handle comma-separated strings, take the character before the first comma eg:123456,78 ->123456
4073 *
4074 * @param buf Type:[IN]
4075 */
4076static void parse_imei(char buf[])
4077{
4078 if(NULL == buf)
4079 {
4080 return;
4081 }
4082 const char s[2] = ",";
4083 char *token;
4084 token = strtok(buf, s);
4085 return;
4086}
4087
4088static char * lynqStrdupReadString(Parcel &p) {
4089 size_t stringlen;
4090 const char16_t *s16;
4091
4092 s16 = p.readString16Inplace(&stringlen);
4093 return strndup16to8(s16, stringlen);
4094}
4095
ll6bdd7702022-12-02 15:15:56 +08004096static void lynq_get_mccmnc(Parcel &p, char *mccmnc)
4097{
4098 p.setDataPosition(0);
4099 if(p.dataAvail() > 0)
4100 {
4101 int resp_type;
4102 int token;
4103 int request;
4104 int slot_id;
4105 int error1;
4106 int num;
4107 char *resp[128];
4108 p.readInt32(&resp_type);
4109 p.readInt32(&token);
4110 p.readInt32(&request);
4111 p.readInt32(&slot_id);
4112 p.readInt32(&error1);
4113 if(!error1)
4114 {
4115 p.readInt32(&num);
4116 if(num == 0 || num > 128)
4117 {
4118 LYERRLOG("no paramters or num %d too great",num);
4119 }
4120 else
4121 {
4122 int i;
4123 for(i = 0; i<num;i++)
4124 {
4125 resp[i] = lynqStrdupReadString(p);
4126 }
4127 if(NULL != resp[2])
4128 {
4129 strcpy(mccmnc,resp[2]);
4130 printf("mcc mnc %s\n", mccmnc);
4131 }
4132 for(i = 0; i<num;i++)
4133 {
4134 if(resp[i]!=NULL)
4135 {
4136 free(resp[i]);
4137 }
4138 }
4139 }
4140 }
4141 else
4142 {
4143 LYERRLOG("lynq_get_mccmnc error");
4144 }
4145 }
4146}
4147
ll2bba45a2023-01-12 22:04:37 +08004148static void lynq_sdk_ready(Parcel &p)
4149{
4150 int resp_type;
4151 int token;
4152 int request;
4153 int slot_id;
4154 int error1;
4155 int num;
4156 char imei[32] = {0};
4157 if(sdk_ready == true)
4158 {
4159 p.setDataPosition(0);
4160 if(p.dataAvail() > 0)
4161 {
4162 p.readInt32(&resp_type);
4163 p.readInt32(&token);
4164 p.readInt32(&request);
4165 p.readInt32(&slot_id);
4166 p.readInt32(&error1);
4167 if(!error1)
4168 {
4169 system("uci set lynq_uci.sdk_ready=0");
4170 }
4171 else
4172 {
4173 system("uci set lynq_uci.sdk_ready=2");
4174 }
4175 }
4176 sdk_ready = false;
4177 }
4178}
4179
you.chene1d75e92024-01-02 14:26:51 +08004180static void lynq_get_sim_state(RIL_CardStatus_v6 *card_status)
4181{
4182 g_lynq_sim_state = card_status->card_state;
4183}
4184
lh7b0674a2022-01-10 00:34:35 -08004185extern "C" void
4186RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4187 RequestInfo *pRI;
4188 int ret;
4189 //int fd = s_ril_param_socket.fdCommand;
4190 size_t errorOffset;
4191 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4192
4193 pRI = (RequestInfo *)t;
4194#if 0
4195 if (!checkAndDequeueRequestInfo(pRI)) {
4196 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4197 return;
4198 }
4199#endif
4200
4201 socket_id = pRI->socket_id;
4202#if 0
4203#if (SIM_COUNT >= 2)
4204 if (socket_id == RIL_SOCKET_2) {
4205 fd = s_ril_param_socket2.fdCommand;
4206 }
4207#if (SIM_COUNT >= 3)
4208 if (socket_id == RIL_SOCKET_3) {
4209 fd = s_ril_param_socket3.fdCommand;
4210 }
4211#endif
4212#if (SIM_COUNT >= 4)
4213 if (socket_id == RIL_SOCKET_4) {
4214 fd = s_ril_param_socket4.fdCommand;
4215 }
4216#endif
4217#endif
4218#endif
4219#if VDBG
4220 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4221#endif
4222
4223 if (pRI->local > 0) {
4224 // Locally issued command...void only!
4225 // response does not go back up the command socket
4226 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
4227
4228 goto done;
4229 }
4230
4231 appendPrintBuf("[%x][SIM%d]< %s", pRI->token,socket_id,requestToString(pRI->pCI->requestNumber));
4232
4233 if (pRI->cancelled == 0) {
4234 Parcel p;
4235
4236 p.writeInt32 (RESPONSE_SOLICITED);
q.huang7de1d662022-09-13 14:19:24 +08004237 p.writeInt32 (pRI->uToken);
lh7b0674a2022-01-10 00:34:35 -08004238 p.writeInt32 (pRI->pCI->requestNumber);
4239 /*warren add for t800 ril servie 2021/12/15 start*/
4240 p.writeInt32(socket_id);
4241 /*warren add for t800 ril servie 2021/12/15 end*/
4242 errorOffset = p.dataPosition();
4243
4244 p.writeInt32 (e);
4245
4246 if (response != NULL) {
4247 // there is a response payload, no matter success or not.
4248 ret = pRI->pCI->responseFunction(p, response, responselen);
4249
4250 /* if an error occurred, rewind and mark it */
4251 if (ret != 0) {
4252 RLOGE ("responseFunction error, ret %d", ret);
4253 p.setDataPosition(errorOffset);
4254 p.writeInt32 (ret);
4255 }
4256 switch (pRI->pCI->requestNumber) {
4257 case RIL_REQUEST_QUERY_FACILITY_LOCK:
4258 {
4259 int numInts = responselen / sizeof(int);
4260 if(numInts > 0) {
4261 int *p_int = (int *) response;
4262 RLOGD("RIL_REQUEST_QUERY_FACILITY_LOCK: %s", (p_int[0] != 0 ? "PIN enable" : "PIN1 disable"));
4263 } else {
4264 RLOGD("RIL_REQUEST_QUERY_FACILITY_LOCK response numInts: %d", numInts);
4265 }
4266 break;
4267 }
4268 case RIL_REQUEST_IMS_REGISTRATION_STATE:
4269 {
4270 int numInts = responselen / sizeof(int);
4271 if(numInts > 0) {
4272 int *p_int = (int *) response;
4273 printf("[SIM%d][QUERY][REG_STATUS] IMS is %s\n", socket_id, (p_int[0] == 0 ? "Not registered" : "Registered"));
4274 } else {
4275 RLOGD("RIL_REQUEST_IMS_REGISTRATION_STATE response numInts: %d", numInts);
4276 }
4277 break;
4278 }
4279 case RIL_REQUEST_VOICE_REGISTRATION_STATE:
4280 {
4281 char **p_cur = (char **) response;
4282 int numStrings = responselen / sizeof(char *);
4283 update_reg_voice_service_state(RIL_REQUEST_VOICE_REGISTRATION_STATE, (char *)p_cur[0], socket_id, pRI->token);
4284 int tempVal=0;
4285 memset(respStr,0,sizeof(respStr));
4286 tempVal = atoi((char *)p_cur[0]);
4287 if(tempVal == 1 || tempVal==5){
4288 sprintf(respStr,"[SIM%d]%s register is in service!",socket_id +1, respStr);
4289 }else{
4290 sprintf(respStr,"[SIM%d]%s register is not in service!",socket_id +1, respStr);
4291 }
4292 if(numStrings >=4 && p_cur[3] != NULL)
4293 {
4294 update_reg_voice_radio_tech(RIL_REQUEST_VOICE_REGISTRATION_STATE, atoi((char *)p_cur[3]), socket_id, pRI->token);
4295 tempVal = atoi((char *)p_cur[3]);
4296 if(tempVal == RADIO_TECH_LTE){//4G
4297 sprintf(respStr,"%s radioTech is 4G!",respStr);
4298 } else if( tempVal == RADIO_TECH_GSM ||
4299 tempVal == RADIO_TECH_GPRS ||
4300 tempVal == RADIO_TECH_EDGE ||
4301 tempVal == RADIO_TECH_IS95A ||
4302 tempVal == RADIO_TECH_IS95B ||
4303 tempVal == RADIO_TECH_1xRTT) { //2G
4304 sprintf(respStr,"%s radioTech is 2G!",respStr);
4305 } else if( tempVal == RADIO_TECH_UMTS ||
4306 tempVal == RADIO_TECH_HSDPA ||
4307 tempVal == RADIO_TECH_HSUPA ||
4308 tempVal == RADIO_TECH_HSPA ||
4309 tempVal == RADIO_TECH_EHRPD ||
4310 tempVal == RADIO_TECH_HSPAP ||
4311 tempVal == RADIO_TECH_TD_SCDMA ||
4312 tempVal == RADIO_TECH_EVDO_0 ||
4313 tempVal == RADIO_TECH_EVDO_A ||
4314 tempVal == RADIO_TECH_EVDO_B) { //3G
4315 sprintf(respStr,"%s radioTech is 3G!",respStr);
4316#ifdef TELEMATIC_5G_SUPPORT
4317 } else if(tempVal == RADIO_TECH_NR) { //5G
4318 sprintf(respStr,"%s radioTech is 5G!",respStr);
4319#endif
4320 } else { //unknown
4321 sprintf(respStr,"%s radioTech is unkown!",respStr);
4322 }
4323 }
4324 sprintf(respStr,"%s\n",respStr);
4325 break;
4326 }
4327 case RIL_REQUEST_DATA_REGISTRATION_STATE:
4328 {
4329 char **p_cur = (char **) response;
4330 int numStrings = responselen / sizeof(char *);
4331 update_reg_data_service_state(RIL_REQUEST_DATA_REGISTRATION_STATE, (char *)p_cur[0], socket_id, pRI->token);
4332 if(numStrings >=4 && p_cur[3] != NULL)
4333 {
4334 update_reg_data_radio_tech(RIL_REQUEST_DATA_REGISTRATION_STATE, atoi((char *)p_cur[3]), socket_id, pRI->token);
4335 }
llaaca09b2022-03-14 16:14:28 +08004336 /*Warren add for SZZT 2021/11/14 start*/
4337 lynqAtRespWatingEvent();
4338 /*Warren add for SZZT 2021/11/14 end*/
lh7b0674a2022-01-10 00:34:35 -08004339 break;
4340 }
4341 case RIL_REQUEST_GET_CURRENT_CALLS:
4342 {
4343 update_call_state(response,responselen, socket_id);
4344 int num = responselen / sizeof(RIL_Call *);
4345 speechonoff(num);
4346 printf("%s\n", printBuf);
4347 break;
4348 }
4349 case RIL_REQUEST_SETUP_DATA_CALL:
4350 {
4351 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
4352 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
4353 updateRILDataCallResponsev6(num,p_cur);
4354 break;
4355 }
q.huang3c4b3252022-04-28 18:24:48 +08004356 case RIL_REQUEST_ANSWER:
4357 {
4358 if(e==RIL_E_SUCCESS)
4359 {
4360 resetMute();
4361 }
4362 break;
4363 }
lh7b0674a2022-01-10 00:34:35 -08004364 case RIL_REQUEST_GET_SIM_STATUS:
4365 {
4366 if (responselen == sizeof (RIL_CardStatus_v6)) {
4367 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
4368 updateCardStatusV6(p_cur, socket_id);
you.chene1d75e92024-01-02 14:26:51 +08004369 lynq_get_sim_state(p_cur);
lh7b0674a2022-01-10 00:34:35 -08004370 }
you.chene1d75e92024-01-02 14:26:51 +08004371 lynq_send_result_already();
lh7b0674a2022-01-10 00:34:35 -08004372 break;
4373 }
4374 case RIL_REQUEST_VOICE_RADIO_TECH:
4375 {
4376 update_voice_radio_tech(((int *) response)[0], socket_id);
4377 break;
4378 }
4379 case RIL_REQUEST_GET_RADIO_CAPABILITY:
4380 {
4381 update_radio_capa((RIL_RadioCapability *) response, socket_id);
4382 break;
4383 }
4384 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE:
4385 {
4386 update_preferred_network_type(((int *) response)[0], socket_id);
4387 break;
4388 }
4389 case RIL_REQUEST_DELETE_SMS_ON_SIM:
4390 {
4391 setSimSmsStorageFullFlag(false);
4392 break;
4393 }
4394 case RIL_REQUEST_SEND_SMS:
4395 case RIL_REQUEST_SEND_SMS_EXPECT_MORE:
4396 case RIL_REQUEST_IMS_SEND_SMS:
4397 {
4398 //for auto save sms to sim
4399 sendStatusWriteSmsToSim(socket_id);
4400 break;
4401 }
4402 case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE:
4403 {
4404 int numInts = responselen / sizeof(int);
4405 if(numInts > 0) {
4406 int *p_int = (int *) response;
4407 RLOGD("RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: %d", p_int[0]);
4408 if(p_int[0] == ECALL_DEREGISTRATION)
4409 {
4410 gostSetInNeedRegister(true);
4411 }
4412
4413 } else {
4414 RLOGD("RIL_REQUEST_ECALL_SET_REGISTRATION_STATE response numInts: %d", numInts);
4415 }
4416 break;
4417 }
Hong_Liu2b7b17c2022-12-14 03:03:56 -08004418 /*lei add for sdk ready 2022/8/17*/
ll1d2ce042022-08-04 01:53:01 -07004419 case RIL_REQUEST_DEVICE_IDENTITY:
4420 {
ll2bba45a2023-01-12 22:04:37 +08004421 lynq_sdk_ready(p);
ll1d2ce042022-08-04 01:53:01 -07004422 break;
4423 }
Hong_Liu2b7b17c2022-12-14 03:03:56 -08004424 /*lei add for sdk ready 2022/8/17*/
ll6bdd7702022-12-02 15:15:56 +08004425 case RIL_REQUEST_OPERATOR:
4426 {
4427 lynq_get_mccmnc(p, mccmnc);
ll112f8b82023-01-14 11:48:23 +08004428 lynq_send_result_already();
ll2bba45a2023-01-12 22:04:37 +08004429 break;
ll6bdd7702022-12-02 15:15:56 +08004430 }
lh7b0674a2022-01-10 00:34:35 -08004431 default:
4432 break;
4433 }
4434 }
lh7b0674a2022-01-10 00:34:35 -08004435 if (e != RIL_E_SUCCESS) {
4436 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4437 }
4438
4439 if ((pRI->token & RIL_TOKEN_MARK) == RIL_TOKEN_MARK) {
4440 printf("%s\n", printBuf ? printBuf : "unkonwn");
4441 } else if (((pRI->pCI->requestNumber == RIL_REQUEST_DEVICE_IDENTITY)
4442 || (pRI->pCI->requestNumber == RIL_REQUEST_OEM_HOOK_RAW))
4443 && (pRI->token & INIT_TOKEN_MARK) == INIT_TOKEN_MARK) {
4444 printf("%s\n", printBuf ? printBuf : "unkonwn");
4445 if (pRI->pCI->requestNumber == RIL_REQUEST_DEVICE_IDENTITY) {
4446 if (e != RIL_E_SUCCESS) {
4447 printf(
4448 "*******************************************\n*** NOTICE: IMEI don't wirite in slot%d ***\n*******************************************\n",
4449 socket_id);
4450 }
4451 }
4452 }
4453
4454#if 0
4455 if (fd < 0) {
4456 RLOGD ("RIL onRequestComplete: Command channel closed");
4457 }
4458#endif
4459 LYNQ_RIL_respSocket(p,t);
4460 sendResponse(p, socket_id);
4461 }
4462#if ATCI_ENABLE_RESPONSE
4463 if((pRI->token & ATCI_TOKEN_MARK) == ATCI_TOKEN_MARK) //ATCI_Rsp
4464 {
4465 int error;
4466 memset(Respose_buf, 0, sizeof(Respose_buf));
4467 if(e != RIL_E_SUCCESS)
4468 error = 1; //fail
4469 else
4470 error = 0; //ok
4471 ATCIResponse(pRI->token,error,Respose_buf, pRI->pCI->requestNumber);
4472 }
4473#endif
4474 if(pRI->pCI->requestNumber == RIL_REQUEST_VOICE_REGISTRATION_STATE && (pRI->token & RIL_TOKEN_MARK) == RIL_TOKEN_MARK){
4475 int len_s = sendto(server_socket_fd,respStr,strlen(respStr),0,(struct sockaddr *)&client_addr,sizeof(client_addr));
4476 }
4477 RLOGW("RIL_onRequestComplete %s end!",requestToString(pRI->pCI->requestNumber));
4478 if((pRI->token&BLOCK_MARK) == BLOCK_MARK) {
4479 //need wakeup dispatch function
4480 BLOCK_LOCK();
4481 wakeup_token = pRI->token;
4482 RLOGW("RIL_onRequestComplete wakeup, token is %x!",wakeup_token);
4483 BLOCK_WAKEUP();
4484 BLOCK_UNLOCK();
4485 }
4486 switch (pRI->pCI->requestNumber) {
4487 case RIL_REQUEST_RADIO_POWER:
4488 speciaRequest_wakeup();
4489 break;
4490 case RIL_REQUEST_SET_RADIO_CAPABILITY:
4491 {
4492 if(utils::is_support_dsds()) {
4493 for (int id = 0; id < SIM_COUNT; id++) {
4494 ARspRequest(RIL_REQUEST_ALLOW_DATA, (RIL_SOCKET_ID)id);
4495 }
4496 }
4497 break;
4498 }
4499 case RIL_REQUEST_ALLOW_DATA:
4500 {
4501 if(utils::is_support_dsds() && isNeedConnect() && get_default_sim_data() == socket_id) {
xja1c30b82022-01-25 16:13:48 +08004502 RLOGD("wait and recreate PDN with sim switch");
lh7b0674a2022-01-10 00:34:35 -08004503 resetConnect();
xja1c30b82022-01-25 16:13:48 +08004504 sleep(WAIT_TIME_FOR_SIM_SWITCH);
lh7b0674a2022-01-10 00:34:35 -08004505 setupDataCall(0, NULL, (RIL_SOCKET_ID)0, NULL);
4506 }
4507 break;
4508 }
4509#ifdef KEEP_ALIVE
4510 case RIL_REQUEST_START_KEEPALIVE_PRO:
4511 case RIL_REQUEST_STOP_KEEPALIVE_PRO:
4512 {
4513 handleKeepAliveResponse(pRI->pCI->requestNumber, response, responselen, socket_id, (e != RIL_E_SUCCESS));
4514 break;
4515 }
4516#endif /*KEEP_ALIVE*/
4517 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC:
4518 {
4519 if(e == RIL_E_SUCCESS)
4520 {
4521 gostSetInNeedRegister(false);
4522 gostFastEcallFlgSet(false);
4523 }
4524 else
4525 {
4526 gostNetworkSelectionSet(socket_id);
4527 }
4528 break;
4529 }
4530 default:
4531 break;
4532 }
4533done:
4534 free(pRI);
4535}
4536
4537
4538static void
4539grabPartialWakeLock() {
4540 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4541}
4542
4543static void
4544releaseWakeLock() {
4545 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4546}
4547
4548
4549static int
4550decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4551 switch (radioState) {
4552 case RADIO_STATE_SIM_NOT_READY:
4553 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4554 case RADIO_STATE_SIM_READY:
4555 return RADIO_TECH_UMTS;
4556
4557 case RADIO_STATE_RUIM_NOT_READY:
4558 case RADIO_STATE_RUIM_READY:
4559 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4560 case RADIO_STATE_NV_NOT_READY:
4561 case RADIO_STATE_NV_READY:
4562 return RADIO_TECH_1xRTT;
4563
4564 default:
4565 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
4566 return -1;
4567 }
4568}
4569
4570static int
4571decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4572 switch (radioState) {
4573 case RADIO_STATE_SIM_NOT_READY:
4574 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4575 case RADIO_STATE_SIM_READY:
4576 case RADIO_STATE_RUIM_NOT_READY:
4577 case RADIO_STATE_RUIM_READY:
4578 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4579 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4580
4581 case RADIO_STATE_NV_NOT_READY:
4582 case RADIO_STATE_NV_READY:
4583 return CDMA_SUBSCRIPTION_SOURCE_NV;
4584
4585 default:
4586 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
4587 return -1;
4588 }
4589}
4590
4591static int
4592decodeSimStatus (RIL_RadioState radioState) {
4593 switch (radioState) {
4594 case RADIO_STATE_SIM_NOT_READY:
4595 case RADIO_STATE_RUIM_NOT_READY:
4596 case RADIO_STATE_NV_NOT_READY:
4597 case RADIO_STATE_NV_READY:
4598 return -1;
4599 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4600 case RADIO_STATE_SIM_READY:
4601 case RADIO_STATE_RUIM_READY:
4602 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4603 return radioState;
4604 default:
4605 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
4606 return -1;
4607 }
4608}
4609
4610static bool is3gpp2(int radioTech) {
4611 switch (radioTech) {
4612 case RADIO_TECH_IS95A:
4613 case RADIO_TECH_IS95B:
4614 case RADIO_TECH_1xRTT:
4615 case RADIO_TECH_EVDO_0:
4616 case RADIO_TECH_EVDO_A:
4617 case RADIO_TECH_EVDO_B:
4618 case RADIO_TECH_EHRPD:
4619 return true;
4620 default:
4621 return false;
4622 }
4623}
4624
4625/* If RIL sends SIM states or RUIM states, store the voice radio
4626 * technology and subscription source information so that they can be
4627 * returned when telephony framework requests them
4628 */
4629static RIL_RadioState
4630processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
4631
4632 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4633 int newVoiceRadioTech;
4634 int newCdmaSubscriptionSource;
4635 int newSimStatus;
4636
4637 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4638 from Radio State and send change notifications if there has been a change */
4639 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4640 if(newVoiceRadioTech != voiceRadioTech) {
4641 voiceRadioTech = newVoiceRadioTech;
4642 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4643 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
4644 }
4645 if(is3gpp2(newVoiceRadioTech)) {
4646 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4647 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4648 cdmaSubscriptionSource = newCdmaSubscriptionSource;
4649 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4650 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
4651 }
4652 }
4653 newSimStatus = decodeSimStatus(newRadioState);
4654 if(newSimStatus != simRuimStatus) {
4655 simRuimStatus = newSimStatus;
4656 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
4657 }
4658
4659 /* Send RADIO_ON to telephony */
4660 newRadioState = RADIO_STATE_ON;
4661 }
4662
4663 return newRadioState;
4664}
4665
4666
4667#if defined(ANDROID_MULTI_SIM)
4668extern "C"
4669void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
4670 size_t datalen, RIL_SOCKET_ID socket_id)
4671#else
4672extern "C"
4673void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
4674 size_t datalen)
4675#endif
4676{
4677 int unsolResponseIndex;
4678 int ret;
4679 int64_t timeReceived = 0;
4680 bool shouldScheduleTimeout = false;
4681 RIL_RadioState newState;
lhf6eea122022-01-20 19:32:14 -08004682 int temp = 0;
4683 char *tempChar=NULL;
lh7b0674a2022-01-10 00:34:35 -08004684 RIL_SOCKET_ID soc_id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
4685
4686#if defined(ANDROID_MULTI_SIM)
4687 soc_id = socket_id;
4688#endif
4689
4690 handle_wakeup_reason(unsolResponse);
4691
4692 if (s_registerCalled == 0) {
4693 // Ignore RIL_onUnsolicitedResponse before RIL_register
4694 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
4695 return;
4696 }
4697 if(onSupports(unsolResponse) == 0)
4698 {
4699 RLOGE("unsupported unsolicited response code %d", unsolResponse);
4700 return;
4701 }
4702
4703#ifdef TARGET_PLATFORM_MT2635
4704 //Reset modem, exit DemoApp.
4705 if(unsolResponse==RIL_UNSOL_MAL_RESTART ) {
4706 RLOGD("Modem Reset, Exit DemoApp!");
4707 printf("Modem Reset, Exit DemoApp!\n");
4708 speechonoff(0);
4709 mixer_reset_set(1);
4710 com_quit(0,NULL,soc_id,NULL);
4711 }
4712#endif
4713 if (unsolResponse < RIL_UNSOL_VENDOR_BASE) {
4714 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4715 }
4716#if 0
4717 WakeType wakeType;
4718 if (unsolResponse >= RIL_UNSOL_VENDOR_BASE) {
4719 //unsolResponseIndex = unsolResponse - RIL_UNSOL_VENDOR_BASE;
4720 wakeType = WAKE_PARTIAL;
4721 } else {
4722 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4723 wakeType = s_unsolResponses[unsolResponseIndex].wakeType;
4724 }
4725
4726 // Grab a wake lock if needed for this reponse,
4727 // as we exit we'll either release it immediately
4728 // or set a timer to release it later.
4729 switch (wakeType) {
4730 case WAKE_PARTIAL:
4731 grabPartialWakeLock();
4732 shouldScheduleTimeout = false;
4733 break;
4734
4735 case DONT_WAKE:
4736 default:
4737 // No wake lock is grabed so don't set timeout
4738 shouldScheduleTimeout = false;
4739 break;
4740 }
4741
4742 // Mark the time this was received, doing this
4743 // after grabing the wakelock incase getting
4744 // the elapsedRealTime might cause us to goto
4745 // sleep.
4746 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4747 timeReceived = elapsedRealtime();
4748 }
4749#endif
4750 appendPrintBuf("[UNSL][SIM%d]< %s", soc_id, requestToString(unsolResponse));
4751
4752 Parcel p;
lh7b0674a2022-01-10 00:34:35 -08004753 p.writeInt32 (RESPONSE_UNSOLICITED);
4754 p.writeInt32 (unsolResponse);
4755 /*Warren add for t800 ril service 2021/12/16 start*/
4756 p.writeInt32 (soc_id);
4757 /*Warren add for t800 ril service 2021/12/16 end*/
4758 if (unsolResponse >= RIL_UNSOL_VENDOR_BASE) {
4759 UnsolResponseInfo* unsolRspInof = find_mtk_unsol_command(unsolResponse);
4760 if(unsolRspInof == NULL){
4761 RLOGE("no unsolicited response function -- %d", unsolResponse);
4762 return;
4763 } else {
4764 ret = unsolRspInof->responseFunction(p,const_cast<void*>(data),datalen);
4765 }
4766 } else {
4767 ret = s_unsolResponses[unsolResponseIndex].responseFunction(p, const_cast<void*>(data), datalen);
4768 }
4769 if (ret != 0) {
4770 // Problem with the response. Don't continue;
4771 goto error_exit;
4772 }
4773
4774 // some things get more payload
4775 switch(unsolResponse) {
4776 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
4777 newState = CALL_ONSTATEREQUEST(soc_id);
4778 p.writeInt32(newState);
4779 appendPrintBuf("%s {%s}", printBuf,
4780 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
4781 break;
4782
4783#if 0
4784 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4785 // Store the time that this was received so the
4786 // handler of this message can account for
4787 // the time it takes to arrive and process. In
4788 // particular the system has been known to sleep
4789 // before this message can be processed.
4790 p.writeInt64(timeReceived);
4791 break;
4792#endif
4793 }
4794
4795#if VDBG
4796 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4797#endif
lhf6eea122022-01-20 19:32:14 -08004798 //ret = sendResponse(p, soc_id);
lh7b0674a2022-01-10 00:34:35 -08004799
4800//unsol trigger other things.
4801 switch(unsolResponse) {
q.huangc8261a62022-12-30 19:01:34 +08004802 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: //add this for API-720
4803 ARspRequest(RIL_REQUEST_GET_CURRENT_CALLS, soc_id);
4804 break;
lh7b0674a2022-01-10 00:34:35 -08004805 case RIL_UNSOL_CALL_RING:
4806 callRing(soc_id);
4807 break;
4808 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
4809 updateIccCardState(soc_id);
4810 break;
4811 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
q.huang1c03f752023-12-14 14:11:58 +08004812 ARspRequest(RIL_REQUEST_VOICE_REGISTRATION_STATE,soc_id);
4813 break;
4814 case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
4815 ARspRequest(RIL_REQUEST_DATA_REGISTRATION_STATE,soc_id);
lh7b0674a2022-01-10 00:34:35 -08004816 break;
4817 case RIL_UNSOL_RESPONSE_NEW_SMS:
lhf6eea122022-01-20 19:32:14 -08004818 responseNewSMS((const char*)data, datalen,soc_id,unsolResponse,p);
lh7b0674a2022-01-10 00:34:35 -08004819 unreadStatusWriteSMSToSim((const char*)data, datalen, soc_id);
4820 sendSMSACK(soc_id);
4821 break;
4822 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
4823 {
4824 RLOGD("Receive RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS data: %s, length: %d", (char*)data, datalen);
4825 break;
4826 }
4827 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
4828 sendSMSACK(soc_id);
4829 break;
4830 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
4831 updateRadioStatus(newState,soc_id);
4832 break;
4833 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
4834 {
4835 ARspRequest(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, soc_id);
4836 break;
4837 }
4838 case RIL_UNSOL_STK_PROACTIVE_COMMAND:
4839 {
4840 RLOGD("STk proactive command raw date: %s, length: %d", (char*)data, datalen);
4841 handleStkCommand((char*)data, datalen,soc_id);
4842 break;
4843 }
4844 case RIL_UNSOL_RIL_CONNECTED:
4845 {
4846 RLOGD("vendor-ril socket(%d) connect start", soc_id);
4847 pthread_mutex_lock(&s_InitMutex);
4848 s_isConnected[soc_id] = 1;
4849 if(utils::is_support_dsds()) {
4850 if (s_isConnected[0] == 1 && s_isConnected[1] == 1) {
4851 pthread_cond_broadcast(&s_InitCond);
4852 }
4853 } else {
4854 if (s_isConnected[0] == 1 || s_isConnected[1] == 1) {
4855 pthread_cond_broadcast(&s_InitCond);
4856 }
4857 }
4858 pthread_mutex_unlock(&s_InitMutex);
4859 RLOGD("vendor-ril socket(%d) connect end", soc_id);
4860 break;
4861 }
4862 case RIL_UNSOL_TX_POWER: {
4863 int *p_int = (int *) data;
4864 int numInts = datalen / sizeof(int);
4865 if (numInts > 1) {
4866 m_RfDesense->emOemHookRaw(p_int[1],soc_id);
4867 } else {
4868 m_RfDesense->emOemHookRaw(0, soc_id);
4869 }
4870 break;
4871 }
4872 case RIL_UNSOL_NETWORK_INFO: {
4873 if(networkCb){
4874 //TBD
4875 char **p_cur = (char **) data;
4876 char *ctype = (char*)p_cur[0];
4877 int type = atoi(ctype);
4878 char *data = (char*)p_cur[1];
4879 RLOGD("ctype %s type %d data %s\n",ctype,type,data);
4880 networkCb(type,data);
4881 }
4882 break;
4883 }
4884 case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
4885 {
4886 int num = datalen / sizeof(RIL_Data_Call_Response_v6);
4887 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) data;
4888 handleUnsolDataCalllistChange(num,p_cur);
4889 break;
4890 }
4891 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED:
4892 {
4893 update_voice_radio_tech(((int *) data)[0], soc_id);
4894 break;
4895 }
4896 case RIL_UNSOL_RADIO_CAPABILITY:
4897 {
4898 update_radio_capa((RIL_RadioCapability *) data, soc_id);
4899 //Proxy_controller::getInstance()->handle_message_notify((RIL_RadioCapability *) data, soc_id);
4900 break;
4901 }
4902 case RIL_UNSOL_CDMA_CALL_WAITING:
4903 {
4904 autoAnswerForCdma(soc_id);
4905 break;
4906 }
4907 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4908 {
4909 updateSystemTime(data, datalen);
4910 break;
4911 }
4912 case RIL_UNSOL_ECALL_INDICATIONS:
4913 {
4914 handleEcallIndication(data, datalen, soc_id);
4915 break;
4916 }
4917#ifdef KEEP_ALIVE
4918 case RIL_UNSOL_KEEPALIVE_STATUS_PRO:
4919 {
4920 handleKeepAliveResponse(unsolResponse, data, datalen, soc_id, false);
4921 break;
4922 }
4923#endif /*KEEP_ALIVE*/
4924 case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
4925 {
4926 setSimSmsStorageFullFlag(true);
4927 break;
4928 }
4929 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR:
4930 {
4931 handleUnsolSipCallProgressInd(data, datalen);
4932 break;
4933 }
4934 case RIL_UNSOL_ECC_NUM:
4935 {
4936 handleECCNumResponse(data, datalen,soc_id);
4937 break;
4938 }
4939 case RIL_UNSOL_CALL_INFO_INDICATION:
4940 {
4941 handleUnsolCallInfoInd(data, datalen, soc_id);
4942 break;
4943 }
4944 case RIL_UNSOL_RINGBACK_TONE:
4945 {
4946 handleRingbackTone(data, datalen, soc_id);
4947 break;
4948 }
4949 default:
4950 break;
4951 }
lhf6eea122022-01-20 19:32:14 -08004952 /*Warren add for t800 ril service 2021/12/16 start*/
q.huang036b6cf2023-01-10 14:29:20 +08004953 ret = LYNQ_RIL_urcBroadcast(p,unsolResponse);
lhf6eea122022-01-20 19:32:14 -08004954 /*Warren add for t800 ril service 2021/12/16 end*/
lh7b0674a2022-01-10 00:34:35 -08004955#if 0
4956 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4957
4958 // Unfortunately, NITZ time is not poll/update like everything
4959 // else in the system. So, if the upstream client isn't connected,
4960 // keep a copy of the last NITZ response (with receive time noted
4961 // above) around so we can deliver it when it is connected
4962
4963 if (s_lastNITZTimeData != NULL) {
4964 free (s_lastNITZTimeData);
4965 s_lastNITZTimeData = NULL;
4966 }
4967
4968 s_lastNITZTimeData = malloc(p.dataSize());
4969 s_lastNITZTimeDataSize = p.dataSize();
4970 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4971 }
4972
4973#endif
4974 // Normal exit
4975 return;
4976
4977error_exit:
4978 RLOGD("unsol handle fail");
4979#if 0
4980 if (shouldScheduleTimeout) {
4981 releaseWakeLock();
4982 }
4983#endif
4984}
4985
4986extern "C" void
4987RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4988 const struct timeval *relativeTime) {
4989}
4990
4991const char *
4992failCauseToString(RIL_Errno e) {
4993 switch(e) {
4994 case RIL_E_SUCCESS: return "E_SUCCESS";
4995 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
4996 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4997 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4998 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4999 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5000 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5001 case RIL_E_CANCELLED: return "E_CANCELLED";
5002 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5003 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5004 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5005 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5006 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5007#ifdef FEATURE_MULTIMODE_ANDROID
5008 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5009 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5010#endif
5011 case RIL_E_SIM_MEM_FULL: return "E_SIM_MEM_FULL";
5012 default: return "<unknown error>";
5013 }
5014}
5015
5016const char *
5017callStateToString(RIL_CallState s) {
5018 switch(s) {
5019 case RIL_CALL_ACTIVE : return "ACTIVE";
5020 case RIL_CALL_HOLDING: return "HOLDING";
5021 case RIL_CALL_DIALING: return "DIALING";
5022 case RIL_CALL_ALERTING: return "ALERTING";
5023 case RIL_CALL_INCOMING: return "INCOMING";
5024 case RIL_CALL_WAITING: return "WAITING";
5025 default: return "<unknown state>";
5026 }
5027}
5028const char *lynq_requset_to_string(int request)
5029{
5030 switch(request) {
5031 case RIL_REQUEST_GET_SIM_STATUS: return "RIL_REQUEST_GET_SIM_STATUS";
5032 case RIL_REQUEST_ENTER_SIM_PIN: return "RIL_REQUEST_ENTER_SIM_PIN";
5033 case RIL_REQUEST_ENTER_SIM_PUK: return "RIL_REQUEST_ENTER_SIM_PUK";
5034 case RIL_REQUEST_ENTER_SIM_PIN2: return "RIL_REQUEST_ENTER_SIM_PIN2";
5035 case RIL_REQUEST_ENTER_SIM_PUK2: return "RIL_REQUEST_ENTER_SIM_PUK2";
5036 case RIL_REQUEST_CHANGE_SIM_PIN: return "RIL_REQUEST_CHANGE_SIM_PIN";
5037 case RIL_REQUEST_CHANGE_SIM_PIN2: return "RIL_REQUEST_CHANGE_SIM_PIN2";
5038 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION";
5039 case RIL_REQUEST_GET_CURRENT_CALLS: return "RIL_REQUEST_GET_CURRENT_CALLS";
5040 case RIL_REQUEST_DIAL: return "RIL_REQUEST_DIAL";
5041 case RIL_REQUEST_GET_IMSI: return "RIL_REQUEST_GET_IMSI";
5042 case RIL_REQUEST_HANGUP: return "RIL_REQUEST_HANGUP";
5043 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND";
5044 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND";
5045 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5046 case RIL_REQUEST_CONFERENCE: return "RIL_REQUEST_CONFERENCE";
5047 case RIL_REQUEST_UDUB: return "RIL_REQUEST_UDUB";
5048 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "RIL_REQUEST_LAST_CALL_FAIL_CAUSE";
5049 case RIL_REQUEST_SIGNAL_STRENGTH: return "RIL_REQUEST_SIGNAL_STRENGTH";
5050 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "RIL_REQUEST_VOICE_REGISTRATION_STATE";
5051 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "RIL_REQUEST_DATA_REGISTRATION_STATE";
5052 case RIL_REQUEST_OPERATOR: return "RIL_REQUEST_OPERATOR";
5053 case RIL_REQUEST_RADIO_POWER: return "RIL_REQUEST_RADIO_POWER";
5054 case RIL_REQUEST_DTMF: return "RIL_REQUEST_DTMF";
5055 case RIL_REQUEST_SEND_SMS: return "RIL_REQUEST_SEND_SMS";
5056 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "RIL_REQUEST_SEND_SMS_EXPECT_MORE";
5057 case RIL_REQUEST_SETUP_DATA_CALL: return "RIL_REQUEST_SETUP_DATA_CALL";
5058 case RIL_REQUEST_SIM_IO: return "RIL_REQUEST_SIM_IO";
5059 case RIL_REQUEST_SEND_USSD: return "RIL_REQUEST_SEND_USSD";
5060 case RIL_REQUEST_CANCEL_USSD: return "RIL_REQUEST_CANCEL_USSD";
5061 case RIL_REQUEST_GET_CLIR: return "RIL_REQUEST_GET_CLIR";
5062 case RIL_REQUEST_SET_CLIR: return "RIL_REQUEST_SET_CLIR";
5063 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "RIL_REQUEST_QUERY_CALL_FORWARD_STATUS";
5064 case RIL_REQUEST_SET_CALL_FORWARD: return "RIL_REQUEST_SET_CALL_FORWARD";
5065 case RIL_REQUEST_QUERY_CALL_WAITING: return "RIL_REQUEST_QUERY_CALL_WAITING";
5066 case RIL_REQUEST_SET_CALL_WAITING: return "RIL_REQUEST_SET_CALL_WAITING";
5067 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "RIL_REQUEST_SMS_ACKNOWLEDGE";
5068 case RIL_REQUEST_GET_IMEI: return "RIL_REQUEST_GET_IMEI";
5069 case RIL_REQUEST_GET_IMEISV: return "RIL_REQUEST_GET_IMEISV";
5070 case RIL_REQUEST_ANSWER: return "RIL_REQUEST_ANSWER";
5071 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "RIL_REQUEST_DEACTIVATE_DATA_CALL";
5072 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "RIL_REQUEST_QUERY_FACILITY_LOCK";
5073 case RIL_REQUEST_SET_FACILITY_LOCK: return "RIL_REQUEST_SET_FACILITY_LOCK";
5074 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "RIL_REQUEST_CHANGE_BARRING_PASSWORD";
5075 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE";
5076 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC";
5077 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL";
5078 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS";
5079 case RIL_REQUEST_DTMF_START: return "RIL_REQUEST_DTMF_START";
5080 case RIL_REQUEST_DTMF_STOP: return "RIL_REQUEST_DTMF_STOP";
5081 case RIL_REQUEST_BASEBAND_VERSION: return "RIL_REQUEST_BASEBAND_VERSION";
5082 case RIL_REQUEST_SEPARATE_CONNECTION: return "RIL_REQUEST_SEPARATE_CONNECTION";
5083 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE";
5084 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE";
5085 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "RIL_REQUEST_GET_NEIGHBORING_CELL_IDS";
5086 case RIL_REQUEST_SET_MUTE: return "RIL_REQUEST_SET_MUTE";
5087 case RIL_REQUEST_GET_MUTE: return "RIL_REQUEST_GET_MUTE";
5088 case RIL_REQUEST_QUERY_CLIP: return "RIL_REQUEST_QUERY_CLIP";
5089 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE";
5090 case RIL_REQUEST_DATA_CALL_LIST: return "RIL_REQUEST_DATA_CALL_LIST";
5091 case RIL_REQUEST_RESET_RADIO: return "RIL_REQUEST_RESET_RADIO";
5092 case RIL_REQUEST_OEM_HOOK_RAW: return "RIL_REQUEST_OEM_HOOK_RAW";
5093 case RIL_REQUEST_OEM_HOOK_STRINGS: return "RIL_REQUEST_OEM_HOOK_STRINGS";
5094 case RIL_REQUEST_SET_BAND_MODE: return "RIL_REQUEST_SET_BAND_MODE";
5095 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE";
5096 case RIL_REQUEST_STK_GET_PROFILE: return "RIL_REQUEST_STK_GET_PROFILE";
5097 case RIL_REQUEST_STK_SET_PROFILE: return "RIL_REQUEST_STK_SET_PROFILE";
5098 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND";
5099 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE";
5100 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5101 case RIL_REQUEST_SCREEN_STATE: return "RIL_REQUEST_SCREEN_STATE";
5102 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "RIL_REQUEST_EXPLICIT_CALL_TRANSFER";
5103 case RIL_REQUEST_SET_LOCATION_UPDATES: return "RIL_REQUEST_SET_LOCATION_UPDATES";
5104 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE";
5105 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE";
5106 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE";
5107 case RIL_REQUEST_SET_TTY_MODE:return"RIL_REQUEST_SET_TTY_MODE";
5108 case RIL_REQUEST_QUERY_TTY_MODE:return"RIL_REQUEST_QUERY_TTY_MODE";
5109 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5110 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5111 case RIL_REQUEST_CDMA_FLASH:return"RIL_REQUEST_CDMA_FLASH";
5112 case RIL_REQUEST_CDMA_BURST_DTMF:return"RIL_REQUEST_CDMA_BURST_DTMF";
5113 case RIL_REQUEST_CDMA_SEND_SMS:return"RIL_REQUEST_CDMA_SEND_SMS";
5114 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE";
5115 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG";
5116 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG";
5117 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION:return "RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION";
5118 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG";
5119 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG";
5120 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION";
5121 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY";
5122 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"RIL_REQUEST_CDMA_SUBSCRIPTION";
5123 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM";
5124 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM";
5125 case RIL_REQUEST_DEVICE_IDENTITY: return "RIL_REQUEST_DEVICE_IDENTITY";
5126 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE";
5127 case RIL_REQUEST_GET_SMSC_ADDRESS: return "RIL_REQUEST_GET_SMSC_ADDRESS";
5128 case RIL_REQUEST_SET_SMSC_ADDRESS: return "RIL_REQUEST_SET_SMSC_ADDRESS";
5129 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "RIL_REQUEST_REPORT_SMS_MEMORY_STATUS";
5130 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING";
5131 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE";
5132 case RIL_REQUEST_ISIM_AUTHENTICATION: return "RIL_REQUEST_ISIM_AUTHENTICATION";
5133 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5134 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5135 case RIL_REQUEST_VOICE_RADIO_TECH: return "RIL_REQUEST_VOICE_RADIO_TECH";
5136 case RIL_REQUEST_GET_CELL_INFO_LIST: return"RIL_REQUEST_GET_CELL_INFO_LIST";
5137 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE";
5138 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5139 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "RIL_REQUEST_IMS_REGISTRATION_STATE";
5140 case RIL_REQUEST_IMS_SEND_SMS: return "RIL_REQUEST_IMS_SEND_SMS";
5141 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC";
5142 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "RIL_REQUEST_SIM_OPEN_CHANNEL";
5143 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "RIL_REQUEST_SIM_CLOSE_CHANNEL";
5144 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL";
5145 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5146 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
5147 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "RIL_REQUEST_SET_UICC_SUBSCRIPTION";
5148 case RIL_REQUEST_ALLOW_DATA: return "RIL_REQUEST_ALLOW_DATA";
5149 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "RIL_REQUEST_GET_HARDWARE_CONFIG";
5150 case RIL_REQUEST_SIM_AUTHENTICATION: return "RIL_REQUEST_SIM_AUTHENTICATION";
5151 case RIL_REQUEST_GET_DC_RT_INFO: return "RIL_REQUEST_GET_DC_RT_INFO";
5152 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "RIL_REQUEST_SET_DC_RT_INFO_RATE";
5153 case RIL_REQUEST_SET_DATA_PROFILE: return "RIL_REQUEST_SET_DATA_PROFILE";
5154 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5155 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED";
5156 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5157 case RIL_UNSOL_RESPONSE_NEW_SMS: return "RIL_UNSOL_RESPONSE_NEW_SMS";
5158 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5159 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5160 case RIL_UNSOL_ON_USSD: return "RIL_UNSOL_ON_USSD";
5161 case RIL_UNSOL_ON_USSD_REQUEST: return "RIL_UNSOL_ON_USSD_REQUEST";
5162 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "RIL_UNSOL_NITZ_TIME_RECEIVED";
5163 case RIL_UNSOL_SIGNAL_STRENGTH: return "RIL_UNSOL_SIGNAL_STRENGTH";
5164 case RIL_UNSOL_STK_SESSION_END: return "RIL_UNSOL_STK_SESSION_END";
5165 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "RIL_UNSOL_STK_PROACTIVE_COMMAND";
5166 case RIL_UNSOL_STK_EVENT_NOTIFY: return "RIL_UNSOL_STK_EVENT_NOTIFY";
5167 case RIL_UNSOL_STK_CALL_SETUP: return "RIL_UNSOL_STK_CALL_SETUP";
5168 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "RIL_UNSOL_SIM_SMS_STORAGE_FULL";
5169 case RIL_UNSOL_SIM_REFRESH: return "RIL_UNSOL_SIM_REFRESH";
5170 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "RIL_UNSOL_DATA_CALL_LIST_CHANGED";
5171 case RIL_UNSOL_CALL_RING: return "RIL_UNSOL_CALL_RING";
5172 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5173 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "RIL_UNSOL_RESPONSE_CDMA_NEW_SMS";
5174 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS";
5175 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5176 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "RIL_UNSOL_RESTRICTED_STATE_CHANGED";
5177 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5178 case RIL_UNSOL_CDMA_CALL_WAITING: return "RIL_UNSOL_CDMA_CALL_WAITING";
5179 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "RIL_UNSOL_CDMA_OTA_PROVISION_STATUS";
5180 case RIL_UNSOL_CDMA_INFO_REC: return "RIL_UNSOL_CDMA_INFO_REC";
5181 case RIL_UNSOL_OEM_HOOK_RAW: return "RIL_UNSOL_OEM_HOOK_RAW";
5182 case RIL_UNSOL_RINGBACK_TONE: return "RIL_UNSOL_RINGBACK_TONE";
5183 case RIL_UNSOL_RESEND_INCALL_MUTE: return "RIL_UNSOL_RESEND_INCALL_MUTE";
5184 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5185 case RIL_UNSOL_CDMA_PRL_CHANGED: return "RIL_UNSOL_CDMA_PRL_CHANGED";
5186 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5187 case RIL_UNSOL_RIL_CONNECTED: return "RIL_UNSOL_RIL_CONNECTED";
5188 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "RIL_UNSOL_VOICE_RADIO_TECH_CHANGED";
5189 case RIL_UNSOL_CELL_INFO_LIST: return "RIL_UNSOL_CELL_INFO_LIST";
5190 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
5191 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5192 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "RIL_UNSOL_SRVCC_STATE_NOTIFY";
5193 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "RIL_UNSOL_HARDWARE_CONFIG_CHANGED";
5194 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "RIL_UNSOL_DC_RT_INFO_CHANGED";
5195 case RIL_REQUEST_SHUTDOWN: return "RIL_REQUEST_SHUTDOWN";
5196 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
5197 case RIL_REQUEST_SET_TRM: return "RIL_REQUEST_SET_TRM";
5198 case RIL_REQUEST_SET_IMS_ENABLE:return "RIL_REQUEST_SET_IMS_ENABLE";
5199 case RIL_REQUEST_SET_AUDIO_PATH: return "RIL_REQUEST_SET_AUDIO_PATH";
5200 case RIL_REQUEST_HANGUP_ALL: return "RIL_REQUEST_HANGUP_ALL";
5201 case RIL_REQUEST_FORCE_RELEASE_CALL: return "RIL_REQUEST_FORCE_RELEASE_CALL";
5202 case RIL_REQUEST_EMERGENCY_DIAL: return "RIL_REQUEST_EMERGENCY_DIAL";
5203 case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: return "RIL_REQUEST_SET_ECC_SERVICE_CATEGORY";
5204 case RIL_REQUEST_SET_ECC_LIST: return "RIL_REQUEST_SET_ECC_LIST";
5205 case RIL_REQUEST_AT_COMMAND_WITH_PROXY: return "RIL_REQUEST_AT_COMMAND_WITH_PROXY";
5206 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION";
5207 case RIL_REQUEST_SET_CLIP: return "RIL_REQUEST_SET_CLIP";
5208 case RIL_REQUEST_GET_COLP: return "RIL_REQUEST_GET_COLP";
5209 case RIL_REQUEST_SET_COLP: return "RIL_REQUEST_SET_COLP";
5210 case RIL_REQUEST_GET_COLR: return "RIL_REQUEST_GET_COLR";
5211 case RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER: return "RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER";
5212 case RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER: return "RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER";
5213 case RIL_REQUEST_CONFERENCE_DIAL: return "RIL_REQUEST_CONFERENCE_DIAL";
5214 case RIL_REQUEST_DIAL_WITH_SIP_URI: return "RIL_REQUEST_DIAL_WITH_SIP_URI";
5215 case RIL_REQUEST_HOLD_CALL: return "RIL_REQUEST_HOLD_CALL";
5216 case RIL_REQUEST_RESUME_CALL: return "RIL_REQUEST_RESUME_CALL";
5217 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return "RIL_UNSOL_ECONF_SRVCC_INDICATION";
5218 case RIL_UNSOL_ECONF_RESULT_INDICATION : return "RIL_UNSOL_ECONF_RESULT_INDICATION";
5219 case RIL_UNSOL_MAL_AT_INFO : return "RIL_UNSOL_MAL_AT_INFO";
5220 case RIL_REQUEST_MODEM_POWEROFF: return "RIL_REQUEST_MODEM_POWEROFF";
5221 case RIL_REQUEST_MODEM_POWERON: return "RIL_REQUEST_MODEM_POWERON";
5222 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "RIL_REQUEST_WRITE_SMS_TO_SIM";
5223 case RIL_REQUEST_QUERY_ICCID: return "RIL_REQUEST_QUERY_ICCID";
5224 case RIL_UNSOL_TX_POWER: return "RIL_UNSOL_TX_POWER";
5225 case RIL_UNSOL_NETWORK_INFO: return "RIL_UNSOL_NETWORK_INFO";
5226 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "RIL_REQUEST_DELETE_SMS_ON_SIM";
5227 case RIL_REQUEST_SET_IMSCFG: return "RIL_REQUEST_SET_IMSCFG";
5228#ifdef ECALL_SUPPORT
5229 case RIL_REQUEST_ECALL_FAST_MAKE_ECALL: return "RIL_REQUEST_ECALL_FAST_MAKE_ECALL";
5230 case RIL_REQUEST_ECALL_SET_IVS: return "RIL_REQUEST_ECALL_SET_IVS";
5231 case RIL_REQUEST_ECALL_SET_PSAP: return "RIL_REQUEST_ECALL_SET_PSAP";
5232 case RIL_REQUEST_ECALL_MAKE_ECALL: return "RIL_REQUEST_ECALL_MAKE_ECALL";
5233 case RIL_REQUEST_ECALL_IVS_PUSH_MSD: return "RIL_REQUEST_ECALL_IVS_PUSH_MSD";
5234 case RIL_REQUEST_ECALL_PSAP_PULL_MSD: return "RIL_REQUEST_ECALL_PSAP_PULL_MSD";
5235 case RIL_UNSOL_ECALL_MSDHACK : return "RIL_UNSOL_ECALL_MSDHACK";
5236 case RIL_REQUEST_ECALL_SET_MSD: return "RIL_REQUEST_ECALL_SET_MSD";
5237 case RIL_REQUEST_ECALL_CTRL_SEQUENCE: return "RIL_REQUEST_ECALL_CTRL_SEQUENCE";
5238 case RIL_UNSOL_ECALL_INDICATIONS : return "RIL_UNSOL_ECALL_INDICATIONS";
5239 case RIL_REQUEST_ECALL_RESET_IVS: return "RIL_REQUEST_ECALL_RESET_IVS";
5240 case RIL_REQUEST_ECALL_SET_PRI: return "RIL_REQUEST_ECALL_SET_PRI";
5241 case RIL_REQUEST_ECALL_SET_TEST_NUM: return "RIL_REQUEST_ECALL_SET_TEST_NUM";
5242 case RIL_REQUEST_ECALL_SET_RECONF_NUM: return "RIL_REQUEST_ECALL_SET_RECONF_NUM";
5243 case RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD: return "RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD";
5244 case RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME: return "RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME";
5245 case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: return "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE";
5246#endif /*ECALL_SUPPORT*/
5247#ifdef KEEP_ALIVE
5248 case RIL_REQUEST_START_KEEPALIVE_PRO: return "RIL_REQUEST_START_KEEPALIVE_PRO";
5249 case RIL_REQUEST_STOP_KEEPALIVE_PRO: return "RIL_REQUEST_STOP_KEEPALIVE_PRO";
5250 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return "RIL_UNSOL_KEEPALIVE_STATUS_PRO";
5251#endif /*KEEP_ALIVE*/
5252 case RIL_REQUEST_SEND_USSI: return "RIL_REQUEST_SEND_USSI";
5253 case RIL_REQUEST_CANCEL_USSI: return "RIL_REQUEST_CANCEL_USSI";
5254 case RIL_REQUEST_GET_SMS_SIM_MEM_STATUS: return "RIL_REQUEST_GET_SMS_SIM_MEM_STATUS";
5255 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return "RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR";
5256 case RIL_REQUEST_REPORT_AIRPLANE_MODE: return "RIL_REQUEST_REPORT_AIRPLANE_MODE";
5257 case RIL_REQUEST_SET_ECC_NUM: return "RIL_REQUEST_SET_ECC_NUM";
5258 case RIL_REQUEST_GET_ECC_NUM: return "RIL_REQUEST_GET_ECC_NUM";
5259 case RIL_UNSOL_ECC_NUM: return "RIL_UNSOL_ECC_NUM";
5260 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT: return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT";
5261 case RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE";
5262 case RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE";
5263 case RIL_UNSOL_CALL_INFO_INDICATION: return "RIL_UNSOL_CALL_INFO_INDICATION";
rjw20006d12022-04-21 16:29:04 +08005264/*Typethree add for t800 RIL Service 2022/04/14 start*/
5265//#ifdef TARGET_PLATFORM_MT2731
lh7b0674a2022-01-10 00:34:35 -08005266 case RIL_REQUEST_MODIFY_APN: return "RIL_REQUEST_MODIFY_APN";
5267 case RIL_REQUEST_RESET_APN: return "RIL_REQUEST_RESET_APN";
rjw20006d12022-04-21 16:29:04 +08005268//#endif
5269/*Typethree add for t800 RIL Service 2022/04/14 end*/
lh7b0674a2022-01-10 00:34:35 -08005270 case RIL_REQUEST_QUERY_SIM_RETRY_COUNT: return "RIL_REQUEST_QUERY_SIM_RETRY_COUNT";
5271 case RIL_REQUEST_QUERY_EID: return "RIL_REQUEST_QUERY_EID";
5272 /*LYNQ CMD*/
5273 case LYNQ_AUTO_ANSWER_CALL: return "LYNQ_AUTO_ANSWER_CALL";
5274 case LYNQ_REQUEST_SET_DTMF_VOLUME: return "RIL_REQUEST_SET_DTMF_VOLUME";
q.huangec88da92022-03-29 04:17:32 -04005275 case LYNQ_REQUEST_SET_SPEECH_VOLUME: return "RIL_REQUEST_SET_SPEECH_VOLUME";
5276 case LYNQ_REQUEST_GET_SPEECH_VOLUME: return "RIL_REQUEST_GET_SPEECH_VOLUME";
5277 case LYNQ_REQUEST_RECORD: return "RIL_REQUEST_RECORD";
lhf6eea122022-01-20 19:32:14 -08005278 case LYNQ_REQUEST_WRITE_SMS_TO_MEMORY: return "LYNQ_REQUEST_WRITE_SMS_TO_MEMORY";
5279 case LYNQ_REQUEST_READ_SMS_FROM_MEMORY: return "LYNQ_REQUEST_READ_SMS_FROM_MEMORY";
5280 case LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY: return "LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY";
5281 case LYNQ_REQUEST_LIST_SMS_FROM_MEMORY: return "LYNQ_REQUEST_LIST_SMS_FROM_MEMORY";
rjw5d2a50e2022-02-28 15:01:49 +08005282 case LYNQ_REQUEST_SET_DEFAULT_SIM_ALL:return "SET_DEFAULT_SIM_ALL";
jb.qi96449342022-09-19 22:14:41 -07005283 case LYNQ_REQUEST_CHANGE_SCREEN_STATE:return "LYNQ_REQUEST_CHANGE_SCREEN_STATE";/*jb.qi add for two sim sleep 2022/9/19*/
ll71a113b2022-10-21 18:07:25 +08005284 case LYNQ_REQUEST_CHANGE_RADIO:return "LYNQ_REQUEST_CHANGE_RADIO";/*lei add for factory test of sleep 2022/9/19*/
q.huang1c03f752023-12-14 14:11:58 +08005285 case LYNQ_REQUEST_SET_VOICE_AUDIO_MODE:return "LYNQ_REQUEST_SET_VOICE_AUDIO_MODE";
5286 case LYNQ_REQUEST_SET_REMOTE_RTP_IP:return "LYNQ_REQUEST_SET_REMOTE_RTP_IP";
5287 case LYNQ_REQUEST_SET_VLAN_INFO:return "LYNQ_REQUEST_SET_VLAN_INFO";
5288 case LYNQ_REQUEST_SET_RTP_PORT:return "LYNQ_REQUEST_SET_RTP_PORT";
5289 case LYNQ_REQUEST_SET_RTP_PARAM:return "LYNQ_REQUEST_SET_RTP_PARAM";
5290 case LYNQ_REQUEST_GET_VOICE_AUDIO_MODE:return "LYNQ_REQUEST_GET_VOICE_AUDIO_MODE";
5291 case LYNQ_REQUEST_GET_REMOTE_RTP_IP:return "LYNQ_REQUEST_GET_REMOTE_RTP_IP";
5292 case LYNQ_REQUEST_GET_VLAN_INFO:return "LYNQ_REQUEST_GET_VLAN_INFO";
5293 case LYNQ_REQUEST_GET_RTP_PORT:return "LYNQ_REQUEST_GET_RTP_PORT";
5294 case LYNQ_REQUEST_GET_RTP_PARAM:return "LYNQ_REQUEST_GET_RTP_PARAM";
5295 case LYNQ_REQUEST_SET_CALL_RTP_SSRC:return "LYNQ_REQUEST_SET_CALL_RTP_SSRC";
5296 case LYNQ_REQUEST_GET_CALL_RTP_SSRC:return "LYNQ_REQUEST_GET_CALL_RTP_SSRC";
jb.qi96449342022-09-19 22:14:41 -07005297 /*warren add for t800 ril service 2022/1/22 end*/
lh7b0674a2022-01-10 00:34:35 -08005298 default: return "<unknown request>";
5299 }
5300}
5301
5302const char *
5303requestToString(int request) {
5304/*
5305 cat libs/telephony/ril_commands.h \
5306 | egrep "^ *{RIL_" \
5307 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5308
5309
5310 cat libs/telephony/ril_unsol_commands.h \
5311 | egrep "^ *{RIL_" \
5312 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5313
5314*/
5315 switch(request) {
5316 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5317 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5318 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5319 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5320 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5321 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5322 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5323 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5324 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5325 case RIL_REQUEST_DIAL: return "DIAL";
5326 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5327 case RIL_REQUEST_HANGUP: return "HANGUP";
5328 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5329 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5330 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5331 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5332 case RIL_REQUEST_UDUB: return "UDUB";
5333 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5334 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5335 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5336 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5337 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5338 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5339 case RIL_REQUEST_DTMF: return "DTMF";
5340 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5341 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5342 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5343 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5344 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5345 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5346 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5347 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5348 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5349 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5350 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5351 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5352 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5353 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5354 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5355 case RIL_REQUEST_ANSWER: return "ANSWER";
5356 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5357 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5358 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5359 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5360 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5361 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5362 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5363 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5364 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5365 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5366 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5367 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5368 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5369 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5370 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5371 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5372 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5373 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5374 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5375 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5376 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5377 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5378 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5379 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5380 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5381 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5382 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5383 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5384 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5385 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5386 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5387 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5388 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
5389 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
5390 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5391 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5392 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5393 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5394 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5395 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5396 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5397 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5398 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5399 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5400 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5401 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5402 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION:return "GSM_SMS_BROADCAST_ACTIVATION";
5403 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5404 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5405 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
5406 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
5407 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5408 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5409 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5410 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5411 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5412 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5413 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5414 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5415 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5416 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5417 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5418 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5419 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5420 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
5421 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5422 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
5423 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5424 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5425 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
5426 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5427 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5428 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5429 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
5430 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5431 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
5432 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5433 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5434 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5435 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5436 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5437 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5438 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
5439 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5440 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5441 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
q.huang036b6cf2023-01-10 14:29:20 +08005442 case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
lh7b0674a2022-01-10 00:34:35 -08005443 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5444 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5445 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5446 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5447 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5448 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5449 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5450 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5451 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5452 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5453 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5454 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5455 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
5456 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5457 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5458 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5459 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5460 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5461 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5462 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5463 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5464 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5465 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5466 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5467 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5468 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5469 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5470 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5471 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5472 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5473 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5474 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
5475 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
5476 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
5477 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5478 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5479 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5480 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
5481 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
5482 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
5483 case RIL_REQUEST_SET_TRM: return "RIL_REQUEST_SET_TRM";
5484 case RIL_REQUEST_SET_IMS_ENABLE:return "RIL_REQUEST_SET_IMS_ENABLE";
5485 case RIL_REQUEST_SET_AUDIO_PATH: return "SET_AUDIO_PATH";
5486 case RIL_REQUEST_HANGUP_ALL: return "HANGUP_ALL";
5487 case RIL_REQUEST_FORCE_RELEASE_CALL: return "FORCE_RELEASE_CALL";
5488 case RIL_REQUEST_EMERGENCY_DIAL: return "RIL_REQUEST_EMERGENCY_DIAL";
5489 case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: return "RIL_REQUEST_SET_ECC_SERVICE_CATEGORY";
5490 case RIL_REQUEST_SET_ECC_LIST: return "RIL_REQUEST_SET_ECC_LIST";
5491 case RIL_REQUEST_AT_COMMAND_WITH_PROXY: return "AT_COMMAND_WITH_PROXY";
5492 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION";
5493 case RIL_REQUEST_SET_CLIP: return "RIL_REQUEST_SET_CLIP";
5494 case RIL_REQUEST_GET_COLP: return "RIL_REQUEST_GET_COLP";
5495 case RIL_REQUEST_SET_COLP: return "RIL_REQUEST_SET_COLP";
5496 case RIL_REQUEST_GET_COLR: return "RIL_REQUEST_GET_COLR";
5497 case RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER: return "ADD_IMS_CONFERENCE_CALL_MEMBER";
5498 case RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER: return "REMOVE_IMS_CONFERENCE_CALL_MEMBER";
5499 case RIL_REQUEST_CONFERENCE_DIAL: return "CONFERENCE_DIAL";
5500 case RIL_REQUEST_DIAL_WITH_SIP_URI: return "DIAL_WITH_SIP_URI";
5501 case RIL_REQUEST_HOLD_CALL: return "HOLD_CALL";
5502 case RIL_REQUEST_RESUME_CALL: return "RESUME_CALL";
5503 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return "ECONF_SRVCC_INDICATION";
5504 case RIL_UNSOL_ECONF_RESULT_INDICATION : return "ECONF_RESULT_INDICATION";
5505 case RIL_UNSOL_MAL_AT_INFO : return "UNSOL_MAL_AT_INFO";
5506 case RIL_REQUEST_MODEM_POWEROFF: return "MODEM_POWEROFF";
5507 case RIL_REQUEST_MODEM_POWERON: return "MODEM_POWERON";
5508 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
5509 case RIL_REQUEST_QUERY_ICCID: return "RIL_REQUEST_QUERY_ICCID";
5510 case RIL_UNSOL_TX_POWER: return "RIL_UNSOL_TX_POWER";
5511 case RIL_UNSOL_NETWORK_INFO: return "RIL_UNSOL_NETWORK_INFO";
5512 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
5513 case RIL_REQUEST_SET_IMSCFG: return "RIL_REQUEST_SET_IMSCFG";
5514#ifdef ECALL_SUPPORT
5515 case RIL_REQUEST_ECALL_FAST_MAKE_ECALL: return "ECALL_FAST_MAKE_ECALL";
5516 case RIL_REQUEST_ECALL_SET_IVS: return "RIL_REQUEST_ECALL_SET_IVS";
5517 case RIL_REQUEST_ECALL_SET_PSAP: return "RIL_REQUEST_ECALL_SET_PSAP";
5518 case RIL_REQUEST_ECALL_MAKE_ECALL: return "RIL_REQUEST_ECALL_MAKE_ECALL";
5519 case RIL_REQUEST_ECALL_IVS_PUSH_MSD: return "RIL_REQUEST_ECALL_IVS_PUSH_MSD";
5520 case RIL_REQUEST_ECALL_PSAP_PULL_MSD: return "RIL_REQUEST_ECALL_PSAP_PULL_MSD";
5521 case RIL_UNSOL_ECALL_MSDHACK : return "ECALL_MSDHACK";
5522 case RIL_REQUEST_ECALL_SET_MSD: return "RIL_REQUEST_ECALL_SET_MSD";
5523 case RIL_REQUEST_ECALL_CTRL_SEQUENCE: return "ECALL_SET_CTRL_SEQUENCE";
5524 case RIL_UNSOL_ECALL_INDICATIONS : return "ECALL_INDICATIONS";
5525 case RIL_REQUEST_ECALL_RESET_IVS: return "RIL_REQUEST_ECALL_RESET_IVS";
5526 case RIL_REQUEST_ECALL_SET_PRI: return "RIL_REQUEST_ECALL_SET_PRI";
5527 case RIL_REQUEST_ECALL_SET_TEST_NUM: return "RIL_REQUEST_ECALL_SET_TEST_NUM";
5528 case RIL_REQUEST_ECALL_SET_RECONF_NUM: return "RIL_REQUEST_ECALL_SET_RECONF_NUM";
5529 case RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD: return "RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD";
5530 case RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME: return "RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME";
5531 case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: return "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE";
5532#endif /*ECALL_SUPPORT*/
5533#ifdef KEEP_ALIVE
5534 case RIL_REQUEST_START_KEEPALIVE_PRO: return "RIL_REQUEST_START_KEEPALIVE_PRO";
5535 case RIL_REQUEST_STOP_KEEPALIVE_PRO: return "RIL_REQUEST_STOP_KEEPALIVE_PRO";
5536 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return "RIL_UNSOL_KEEPALIVE_STATUS_PRO";
5537#endif /*KEEP_ALIVE*/
5538 case RIL_REQUEST_SEND_USSI: return "SEND_USSI";
5539 case RIL_REQUEST_CANCEL_USSI: return "CANCEL_USSI";
5540 case RIL_REQUEST_GET_SMS_SIM_MEM_STATUS: return "GET_SMS_SIM_MEM_STATUS";
5541 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return "RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR";
5542 case RIL_REQUEST_REPORT_AIRPLANE_MODE: return "RIL_REQUEST_REPORT_AIRPLANE_MODE";
5543 case RIL_REQUEST_SET_ECC_NUM: return "RIL_REQUEST_SET_ECC_NUM";
5544 case RIL_REQUEST_GET_ECC_NUM: return "RIL_REQUEST_GET_ECC_NUM";
5545 case RIL_UNSOL_ECC_NUM: return "RIL_UNSOL_ECC_NUM";
5546 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT: return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT";
5547 case RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE";
5548 case RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE";
5549 case RIL_UNSOL_CALL_INFO_INDICATION: return "RIL_UNSOL_CALL_INFO_INDICATION";
5550 case RIL_REQUEST_MODIFY_APN: return "RIL_REQUEST_MODIFY_APN";
5551 case RIL_REQUEST_RESET_APN: return "RIL_REQUEST_RESET_APN";
5552 case RIL_REQUEST_QUERY_SIM_RETRY_COUNT: return "RIL_REQUEST_QUERY_SIM_RETRY_COUNT";
5553 case RIL_REQUEST_QUERY_EID: return "RIL_REQUEST_QUERY_EID";
5554 case LYNQ_REQUEST_SET_DTMF_VOLUME: return "RIL_REQUEST_SET_DTMF_VOLUME";
q.huangec88da92022-03-29 04:17:32 -04005555 case LYNQ_REQUEST_SET_SPEECH_VOLUME: return "RIL_REQUEST_SET_SPEECH_VOLUME";
5556 case LYNQ_REQUEST_GET_SPEECH_VOLUME: return "RIL_REQUEST_GET_SPEECH_VOLUME";
5557 case LYNQ_REQUEST_RECORD: return "RIL_REQUEST_RECORD";
lhf6eea122022-01-20 19:32:14 -08005558 /*warren add for t800 ril service 2022/1/22 start*/
5559 case LYNQ_REQUEST_WRITE_SMS_TO_MEMORY: return "LYNQ_REQUEST_WRITE_SMS_TO_MEMORY";
5560 case LYNQ_REQUEST_READ_SMS_FROM_MEMORY: return "LYNQ_REQUEST_READ_SMS_FROM_MEMORY";
5561 case LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY: return "LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY";
5562 case LYNQ_REQUEST_LIST_SMS_FROM_MEMORY: return "LYNQ_REQUEST_LIST_SMS_FROM_MEMORY";
rjw5d2a50e2022-02-28 15:01:49 +08005563 case LYNQ_REQUEST_SET_DEFAULT_SIM_ALL:return "SET_DEFAULT_SIM_ALL";
jb.qi96449342022-09-19 22:14:41 -07005564 case LYNQ_REQUEST_CHANGE_SCREEN_STATE:return "LYNQ_REQUEST_CHANGE_SCREEN_STATE";/*jb.qi add for two sim sleep 2022/9/19*/
ll71a113b2022-10-21 18:07:25 +08005565 case LYNQ_REQUEST_CHANGE_RADIO:return "LYNQ_REQUEST_CHANGE_RADIO";/*lei add for factory test of sleep 2022/9/19*/
xy.hef5d74f12023-10-23 06:48:52 -07005566 case RIL_UNSOL_TELEPHONY_RESTART:return "RIL_UNSOL_TELEPHONY_RESTART";/*xy.he add for t800 ril service 2023/10/23*/
q.huang1c03f752023-12-14 14:11:58 +08005567 case LYNQ_REQUEST_SET_VOICE_AUDIO_MODE:return "LYNQ_REQUEST_SET_VOICE_AUDIO_MODE";
5568 case LYNQ_REQUEST_SET_REMOTE_RTP_IP:return "LYNQ_REQUEST_SET_REMOTE_RTP_IP";
5569 case LYNQ_REQUEST_SET_VLAN_INFO:return "LYNQ_REQUEST_SET_VLAN_INFO";
5570 case LYNQ_REQUEST_SET_RTP_PORT:return "LYNQ_REQUEST_SET_RTP_PORT";
5571 case LYNQ_REQUEST_SET_RTP_PARAM:return "LYNQ_REQUEST_SET_RTP_PARAM";
5572 case LYNQ_REQUEST_GET_VOICE_AUDIO_MODE:return "LYNQ_REQUEST_GET_VOICE_AUDIO_MODE";
5573 case LYNQ_REQUEST_GET_REMOTE_RTP_IP:return "LYNQ_REQUEST_GET_REMOTE_RTP_IP";
5574 case LYNQ_REQUEST_GET_VLAN_INFO:return "LYNQ_REQUEST_GET_VLAN_INFO";
5575 case LYNQ_REQUEST_GET_RTP_PORT:return "LYNQ_REQUEST_GET_RTP_PORT";
5576 case LYNQ_REQUEST_GET_RTP_PARAM:return "LYNQ_REQUEST_GET_RTP_PARAM";
5577 case LYNQ_REQUEST_SET_CALL_RTP_SSRC:return "LYNQ_REQUEST_SET_CALL_RTP_SSRC";
5578 case LYNQ_REQUEST_GET_CALL_RTP_SSRC:return "LYNQ_REQUEST_GET_CALL_RTP_SSRC";
lhf6eea122022-01-20 19:32:14 -08005579 /*warren add for t800 ril service 2022/1/22 end*/
lh7b0674a2022-01-10 00:34:35 -08005580 default: return "<unknown request>";
5581 }
5582}
5583
5584static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
5585 printResponse;
5586 int type;
5587 if(enable_bt_resp){
5588 SendRespToClient(p.data(), p.dataSize());
5589 }
5590 p.setDataPosition(0);
5591 p.readInt32(&type);
5592 if(type == RESPONSE_UNSOLICITED){
5593 processUnsolicited(p,type);
5594 }else if (type == RESPONSE_SOLICITED){
5595 processSolicited(p,type);
5596 }
5597 return 0;
5598}
5599
5600static void speciaRequest_wait()
5601{
5602 struct timeval now;
5603 struct timespec timeout;
5604
5605 gettimeofday(&now,NULL);
5606 timeout.tv_sec = now.tv_sec+1200; //timeout is 2omin. maybe radio on/off need 10s to complete.
5607 timeout.tv_nsec = now.tv_usec*1000;
5608
5609 SPECIA_BLOCK_LOCK();
5610 while(!(requestOneByOne == 0)) {
5611 int ret = SPECIA_BLOCK_WAIT(&timeout);
5612 if(ret == ETIMEDOUT){
5613 RLOGD("special request wait timeout");
5614 break;
5615 }
5616 }
5617 requestOneByOne = 1;
5618 SPECIA_BLOCK_UNLOCK();
5619}
5620
5621static void speciaRequest_wakeup()
5622{
5623 SPECIA_BLOCK_LOCK();
5624 requestOneByOne = 0;
5625 SPECIA_BLOCK_WAKEUP();
5626 SPECIA_BLOCK_UNLOCK();
5627}
5628
5629static void updateIccCardState(RIL_SOCKET_ID soc_id)
5630{
5631 ARspRequest(RIL_REQUEST_GET_SIM_STATUS, soc_id);
5632}
5633
5634void sendRequestToMd(int request, int id) {
5635 RequestInfo* info = creatRILInfoAndInit(request, INIT, (RIL_SOCKET_ID) ((id)));
5636 switch(request){
5637 case RIL_REQUEST_DEVICE_IDENTITY:
5638 {
5639 getDeviceIdentity(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5640 break;
5641 }
5642 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE:
5643 {
5644 getPreferredNetworkType(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5645 break;
5646 }
5647 case RIL_REQUEST_GET_SIM_STATUS:
5648 {
5649 getIccCardStatus(1, NULL, (RIL_SOCKET_ID) (id), info);
5650 break;
5651 }
5652 case RIL_REQUEST_DATA_REGISTRATION_STATE:
5653 {
5654 getDataRegistrationState(1, NULL, (RIL_SOCKET_ID) (id), info);
5655 break;
5656 }
5657 case RIL_REQUEST_VOICE_REGISTRATION_STATE:
5658 {
5659 getVoiceRegistrationState(1, NULL, (RIL_SOCKET_ID) (id), info);
5660 break;
5661 }
5662 case RIL_REQUEST_VOICE_RADIO_TECH:
5663 {
5664 getVoiceRadioTechnology(1, NULL, (RIL_SOCKET_ID) (id), info);
5665 break;
5666 }
5667 case RIL_REQUEST_OEM_HOOK_RAW:
5668 {
5669 char* tmp[2] = {"RIL_REQUEST_OEM_HOOK_RAW", "AT+ECAL"};
5670 sendATCMD(2, tmp, (RIL_SOCKET_ID) (id), info);
5671 break;
5672 }
5673 case RIL_REQUEST_GET_RADIO_CAPABILITY:
5674 {
5675 getRadioCapability(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5676 break;
5677 }
5678 default:
5679 RLOGE("don't support %d in init", id);
5680 if(info) {
5681 free(info);
5682 }
5683 }
5684}
5685
jb.qi96449342022-09-19 22:14:41 -07005686/**@brief pass the change screen state request to the executing function
5687*@param request type: [IN] requestID
5688*@param slot_id type: [IN] simID
5689*@param argv type: [IN] getScreenState's argv
5690*@author jb.qi
5691*@date 2022/09/19
5692*/
5693void lynq_sendRequestToMd(int request, int slot_id, char **argv, struct sockaddr_in lynqClient_addr, int utoken)
5694{
5695 RequestInfo* info = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID) ((slot_id)));
5696 info->uToken = utoken;
5697 info->lynqEvent = 2;
5698 info->uClient_addr.sin_family = lynqClient_addr.sin_family;
5699 info->uClient_addr.sin_addr.s_addr = lynqClient_addr.sin_addr.s_addr;
5700 info->uClient_addr.sin_port = lynqClient_addr.sin_port;
5701 switch(request){
5702 case RIL_REQUEST_SCREEN_STATE:
5703 {
5704 int waittoken = info->token;
5705 RLOGD("getScreenState\n");
5706 getScreenState(2, argv, (RIL_SOCKET_ID) ((slot_id)), info);
5707 waitResponse(waittoken);
5708 break;
5709 }
ll71a113b2022-10-21 18:07:25 +08005710 case RIL_REQUEST_RADIO_POWER:
5711 {
5712 int waittoken = info->token;
5713 RLOGD("LYNQ_REQUEST_CHANGE_RADIO\n");
5714 setRadioPower(2, argv, (RIL_SOCKET_ID) ((slot_id)), info);
5715 waitResponse(waittoken);
5716 break;
5717 }
jb.qi96449342022-09-19 22:14:41 -07005718 default:
5719 RLOGD("dont support %d in init", slot_id);
jb.qi6b23ed42022-09-22 00:30:55 -07005720 if(info)
5721 {
jb.qi96449342022-09-19 22:14:41 -07005722 free(info);
5723 }
5724 }
5725}
5726
lh7b0674a2022-01-10 00:34:35 -08005727static void init(int id) {
5728 int waittoken;
5729 RIL_RadioState radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5730 while (radioState == RADIO_STATE_UNAVAILABLE) {
5731 sleep(1);
5732 radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5733 RLOGD("init socket id: %d, %s", id, radioStateToString(radioState));
5734 }
5735 RLOGD("init socket id: %d, %s", id, radioStateToString(radioState));
xja1c30b82022-01-25 16:13:48 +08005736 updataDataConnectState(id, false);
lh7b0674a2022-01-10 00:34:35 -08005737 sendRequestToMd(RIL_REQUEST_GET_SIM_STATUS, id);
5738
5739#if 0
5740 if (radioState != RADIO_STATE_ON) {
5741 RequestInfo* radio = creatRILInfoAndInit(RIL_REQUEST_RADIO_POWER, INIT, (RIL_SOCKET_ID) (id));
5742 waittoken = radio->token;
5743 RLOGD("[%s-%d]:token is %x", __FUNCTION__, __LINE__, radio->token);
5744 char* tmp[2] = { "RIL_REQUEST_RADIO_POWER", "1" };
5745 setRadioPower(2, tmp, (RIL_SOCKET_ID) (id), radio);
5746 waitResponse(waittoken);
5747 sleep(2);
5748 radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5749 RLOGD("NOW radio status %s", radioStateToString(radioState));
5750 }
5751# endif
5752 sendRequestToMd(RIL_REQUEST_DATA_REGISTRATION_STATE, id);
5753 sendRequestToMd(RIL_REQUEST_VOICE_REGISTRATION_STATE, id);
5754 sendRequestToMd(RIL_REQUEST_VOICE_RADIO_TECH, id);
5755 sendRequestToMd(RIL_REQUEST_DEVICE_IDENTITY,id);
5756 sendRequestToMd(RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, id);
5757 sendRequestToMd(RIL_REQUEST_OEM_HOOK_RAW, id);
5758 sendRequestToMd(RIL_REQUEST_GET_RADIO_CAPABILITY,id);
5759}
5760
5761static void initCoditions()
5762{
you.chene1d75e92024-01-02 14:26:51 +08005763#ifdef LED_SUPPORT
5764 mbtk_netled_init();
5765#endif
lh7b0674a2022-01-10 00:34:35 -08005766 mixer_init();
q.huang1c03f752023-12-14 14:11:58 +08005767 lynq_init_rtp();
5768
lh7b0674a2022-01-10 00:34:35 -08005769 if(utils::is_support_dsds()) {
5770 for(int i = 0; i < 2 ; i++) {
5771 init(i);
5772 }
5773 }
5774
5775 if(utils::is_suppport_dsss()) {
5776 int id = Phone_utils::get_enable_sim_for_dsss();
5777 init(id);
q.huang036b6cf2023-01-10 14:29:20 +08005778 }
lh7b0674a2022-01-10 00:34:35 -08005779}
5780
5781
5782//For UDP sokcet send response to client
5783static int SendRespToClient(const void *data, size_t dataSize)
5784{
5785 const uint8_t *toWrite;
5786 size_t writeOffset = 0;
5787
5788 toWrite = (const uint8_t *)data;
5789
5790 if (toWrite == NULL) {
5791 //buf is invaild
5792 return -1;
5793 }
5794
5795 while (writeOffset < dataSize) {
5796 ssize_t written;
5797 do {
5798 //written = write (fd, toWrite + writeOffset,dataSize - writeOffset);
5799 written = sendto(server_socket_fd, toWrite + writeOffset, dataSize - writeOffset,
5800 0, (struct sockaddr *)&client_addr, sizeof(client_addr));
5801 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
5802
5803 if (written >= 0) {
5804 writeOffset += written;
5805 } else { // written < 0
5806 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
5807 return -1;
5808 }
5809 }
5810
5811 return 0;
5812}
5813
5814static UnsolResponseInfo* find_mtk_unsol_command(int request)
5815{
5816 int i;
5817 for (i = 0; i < (int32_t)NUM_ELEMS(s_mtk_unsolResponses); i++)
5818 if (s_mtk_unsolResponses[i].requestNumber == request)
5819 return (&s_mtk_unsolResponses[i]);
5820 return ((UnsolResponseInfo *)NULL);
5821}
5822
5823static int
5824onSupports (int requestCode)
5825{
5826 switch(requestCode)
5827 {
5828 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return 1;
5829 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return 1;
5830 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return 1;
q.huangcdcdf922022-10-20 13:40:51 +08005831 case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED: return 1;
lh7b0674a2022-01-10 00:34:35 -08005832 case RIL_UNSOL_RESPONSE_NEW_SMS: return 1;
5833 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return 1;
5834 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return 1;
5835 case RIL_UNSOL_ON_USSD: return 1;
5836 case RIL_UNSOL_ON_USSD_REQUEST: return 1;
5837 case RIL_UNSOL_NITZ_TIME_RECEIVED: return 1;
5838 case RIL_UNSOL_SIGNAL_STRENGTH: return 1;
5839 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return 1;
5840 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return 1;
5841 case RIL_UNSOL_STK_SESSION_END: return 1;
5842 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return 1;
5843 case RIL_UNSOL_STK_EVENT_NOTIFY: return 1;
5844 case RIL_UNSOL_STK_CALL_SETUP: return 1;
5845 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return 1;
5846 case RIL_UNSOL_SIM_REFRESH: return 1;
5847 case RIL_UNSOL_CALL_RING: return 1;
5848 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return 1;
5849 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return 1;
5850 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return 1;
5851 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return 0;
5852 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return 1;
5853 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return 1;
5854 case RIL_UNSOL_CDMA_CALL_WAITING: return 1;
5855 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return 0;
5856 case RIL_UNSOL_CDMA_INFO_REC: return 0;
5857 case RIL_UNSOL_OEM_HOOK_RAW: return 1;
5858 case RIL_UNSOL_RINGBACK_TONE: return 1;
5859 case RIL_UNSOL_RESEND_INCALL_MUTE: return 0;
5860 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return 0;
5861 case RIL_UNSOL_CDMA_PRL_CHANGED: return 0;
5862 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return 1;
5863 case RIL_UNSOL_RIL_CONNECTED: return 1;
5864 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return 1;
5865 case RIL_UNSOL_CELL_INFO_LIST: return 1;
5866 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return 1;
5867 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return 1;
5868 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return 1;
5869 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return 0;
5870 case RIL_UNSOL_DC_RT_INFO_CHANGED: return 0;
5871 case RIL_UNSOL_RADIO_CAPABILITY : return 1;
5872 case RIL_UNSOL_MAL_RESTART : return 1;
5873 case RIL_UNSOL_CALL_INFO_INDICATION : return 1;
5874 case RIL_UNSOL_CRSS_NOTIFICATION : return 0;
5875 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return 1;
5876 case RIL_UNSOL_ECONF_RESULT_INDICATION : return 1;
5877 case RIL_UNSOL_STK_BIP_PROACTIVE_COMMAND : return 0;
5878 case RIL_UNSOL_MAL_AT_INFO: return 1;
5879 case RIL_UNSOL_ECALL_MSDHACK: return 1;
5880 case RIL_UNSOL_TX_POWER: return 1;
5881 case RIL_UNSOL_NETWORK_INFO: return 1;
xy.hef5d74f12023-10-23 06:48:52 -07005882 case RIL_UNSOL_TELEPHONY_RESTART: return 1;
lh7b0674a2022-01-10 00:34:35 -08005883#ifdef ECALL_SUPPORT
5884 case RIL_UNSOL_ECALL_INDICATIONS: return 1;
5885#endif /*ECALL_SUPPORT*/
5886#ifdef KEEP_ALIVE
5887 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return 1;
5888#endif /*KEEP_ALIVE*/
5889 case RIL_UNSOL_ON_USSI: return 1;
5890 case RIL_UNSOL_ECC_NUM: return 1;
5891 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return 1;
5892 default: return 0;
5893 }
5894}
5895
5896int parse_param(char *cmd, char *argv[], int max_args)
5897{
5898 char *pos, *pos2;
5899 int argc = 0;
lxfdb3a24c2023-11-20 06:26:13 -08005900 printf("LYNQ_REQUEST cmd=%s\n",cmd);
lh7b0674a2022-01-10 00:34:35 -08005901 pos = cmd;
5902 while (1) {
5903 // Trim the space characters.
5904 while (*pos == ' ') {
5905 pos++;
5906 }
5907
5908 if (*pos == '\0') {
5909 break;
5910 }
5911
5912 // One token may start with '"' or other characters.
5913 if (*pos == '"' && (pos2 = strrchr(pos+1, '"'))) {
5914 argv[argc++] = pos + 1;
5915 *pos2 = '\0';
5916 pos = pos2 + 1;
5917 if(*pos == '\n'){
5918 *pos = '\0';
5919 pos = pos + 1;
5920 }
5921
5922 } else {
5923 argv[argc++] = pos;
5924 while (*pos != '\0' && *pos != ' '&& *pos != '\n') {
5925 pos++;
5926 }
5927 *pos++ = '\0';
5928
5929 if(argc == 1) {
5930 char* at_cmd = strstr(argv[0], "RIL_REQUEST_OEM_HOOK_RAW");
5931 if(at_cmd != NULL) {
5932 while (*pos == ' ') {
5933 pos++;
5934 }
5935 argv[argc++] = pos;
5936 while (*pos != '\0' && *pos != '\n') {
5937 pos++;
5938 }
5939 *pos++ = '\0';
5940 break;
5941 }
5942 }
5943
5944 }
5945
5946 // Check if the maximum of arguments is reached.
5947 if (argc == max_args) {
5948 break;
5949 }
5950 }
5951
5952 return argc;
5953}
5954
5955/* Look up NAME as the name of a command, and return a pointer to that
5956 command. Return a NULL pointer if NAME isn't a command name. */
5957COMMAND* find_command (char *name)
5958{
5959 register int i;
5960
5961 for (i = 0; commands[i].name; i++)
5962 if (strcmp (name, commands[i].name) == 0)
5963 return (&commands[i]);
5964
5965 return ((COMMAND *)NULL);
5966}
5967
5968CommandInfo* find_mtk_command (int request)
5969{
5970 int i;
5971 for (i = 0; i < (int32_t)NUM_ELEMS(mtk_s_command); i++)
5972 if (mtk_s_command[i].requestNumber == request)
5973 return (&mtk_s_command[i]);
5974 return ((CommandInfo *)NULL);
5975}
5976
5977/* The user wishes to quit using this program. Just set DONE non-zero. */
5978static int com_quit (int argc, char *argv[], RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5979{
5980 exit(EXIT_SUCCESS);
5981 return (0);
5982}
5983
5984static int enableSyslog(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5985{
5986 if(argc < 2)
5987 {
5988 RLOGE("[Error] enable syslog paramter is error\n");
5989 free(pRI);
5990 return -1;
5991 }
5992 enable_syslog = atoi(argv[1]);
5993 RLOGE("%s syslog\n",enable_syslog ? "enable" :"disable");
5994 free(pRI);
5995 return 0;
5996}
5997
5998static int enableBTResponse(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5999{
6000 if(argc < 2)
6001 {
6002 RLOGE("[Error] enable BT response paramter is error\n");
6003 free(pRI);
6004 return -1;
6005 }
6006 enable_bt_resp = atoi(argv[1]);
6007 RLOGE("%s bt response!\n",enable_bt_resp ? "enable" :"disable");
6008 free(pRI);
6009 return 0;
6010
6011}
6012
6013char Time_buf[24];
6014void GetTimeString(char * buf)
6015{
6016 time_t timep;
6017 struct tm p;
6018
6019 if(buf == NULL){
6020 RLOGE("[Error] GetTimeString: buf is Null\n");
6021 return;
6022 }
6023 //memset(buf,0,sizeof(buf));
6024 time(&timep);
6025 localtime_r(&timep,&p);
6026 sprintf(buf,"%d_%d_%d %d:%d:%d",(1900+p.tm_year),(1+p.tm_mon),p.tm_mday,
6027 (p.tm_hour),p.tm_min,p.tm_sec);
6028// printf("data is %s\n",buf);
6029
6030 return;
6031}
6032/*Warren add for t800 RIL Service 2021/12/10 start*/
q.huangadbad2f2022-09-15 16:28:02 +08006033int lynqAssemblyParcelheader(Parcel &p,int slot,int utoken, int request,int respType,int error)
lh7b0674a2022-01-10 00:34:35 -08006034{
6035 p.writeInt32 (respType);
q.huangadbad2f2022-09-15 16:28:02 +08006036 p.writeInt32 (utoken);
lh7b0674a2022-01-10 00:34:35 -08006037 p.writeInt32 (request);
6038 /*warren add for t800 ril servie 2021/12/15 start*/
6039 p.writeInt32(slot);
6040 /*warren add for t800 ril servie 2021/12/15 end*/
6041 p.writeInt32 (error);
6042 return 0;
6043}
6044void LYNQ_RIL_urcClientInit()
6045{
lhced7d4a2023-03-28 09:50:52 +08006046 int len = 0;
6047 int on=1;
6048 int ret = 0;
6049 lynq_urc_socket_fd = socket(AF_INET,SOCK_DGRAM,0);
6050 if(lynq_urc_socket_fd < 0)
6051 {
6052 perror("creaet socket for udp fail");
6053 return;
6054 }
6055 /* 设置socket允许重复使用地址与端口,SO_REUSEADDR值为2 */
6056 //setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
6057 /* 使能广播功能,SO_BROADCAST值为6 */
6058 ret= setsockopt(lynq_urc_socket_fd,SOL_SOCKET,SO_BROADCAST,&on,sizeof(on));
6059 if(ret<0)
6060 {
6061 RLOGD("set broadcast fail!!!\n");
6062 exit(1);
6063 }
xy.he290940a2023-12-07 13:43:21 +08006064
6065 struct sockaddr_in ril_lynq_urcCLient_socket;
6066 bzero(&ril_lynq_urcCLient_socket, sizeof(ril_lynq_urcCLient_socket));
6067
6068 ril_lynq_urcCLient_socket.sin_family = AF_INET;
6069 ril_lynq_urcCLient_socket.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
6070 ret = bind(lynq_urc_socket_fd, (struct sockaddr *)&ril_lynq_urcCLient_socket, sizeof(ril_lynq_urcCLient_socket));
6071 if (-1 == ret)
6072 {
6073 LYERRLOG("ril_lynq_urcCLient_socket bind fail,errno:%d",errno);
6074 exit(EXIT_FAILURE);
6075 }
6076
lhced7d4a2023-03-28 09:50:52 +08006077 urc_broadcast_addr.sin_family = AF_INET; //IPv4
6078 urc_broadcast_addr.sin_port = htons(LYNQ_BRODCAST_PORT);
6079 urc_broadcast_addr.sin_addr.s_addr = inet_addr("255.255.255.255" );//255.255.255.255 broadcast addrress.
6080 printf("LYNQ_RIL_urcClientInit success!!!\n");
lh7b0674a2022-01-10 00:34:35 -08006081 return;
lh7b0674a2022-01-10 00:34:35 -08006082}
q.huang5bbadde2023-02-09 16:50:52 +08006083
6084//add by hq for bug 760 2023/02/09
6085static int setnonblocking(int sockfd) {
6086 int flag = fcntl(sockfd, F_GETFL, 0); //get current flag
6087 if (flag < 0) {
6088 RLOGE("fcntl F_GETFL fail");
6089 return -1;
6090 }
6091 if (fcntl(sockfd, F_SETFL, flag | O_NONBLOCK) < 0) { //add O_NONBLOCK
6092 RLOGE("fcntl F_SETFL fail");
6093 return -1;
6094 }
6095 return 0;
6096}
6097
lh7b0674a2022-01-10 00:34:35 -08006098void LYNQ_RIL_RecSocket()
6099{
6100 RLOGD("LYNQ_RIL_RecSocket start\n");
6101 char *argv[MAX_ARGS];
6102 int argc = 0;
6103 int ep_fd = 0;
6104 int en_fd = 0;
6105 struct epoll_event lynq_ev;
6106 struct epoll_event lynq_events[LYNQ_SOCKET_ENVNT_FD_MAX];
6107 //prctl(PR_SET_NAME,(unsigned long)"UDP_Thr");
6108
6109 /*listen UPD SOCKET port */
6110 struct sockaddr_in server_addr;
6111 struct sockaddr_in lynqClient_addr;
6112 bzero(&server_addr, sizeof(server_addr));
6113 server_addr.sin_family = AF_INET;
lh8d290112023-10-22 20:53:06 -07006114 server_addr.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
lh7b0674a2022-01-10 00:34:35 -08006115 server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
6116 /* create socket */
6117 //int server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
6118 server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
6119 if(server_socket_fd == -1)
6120 {
6121 RLOGE("Create Socket Failed:");
6122 exit(1);
6123 }
6124
6125 /* bind socket port*/
6126 if(-1 == (bind(server_socket_fd,(struct sockaddr*)&server_addr,sizeof(server_addr))))
6127 {
6128 RLOGE("Server Bind Failed:");
6129 exit(1);
6130 }
q.huang5bbadde2023-02-09 16:50:52 +08006131
6132 if(setnonblocking(server_socket_fd)!=0)
6133 {
6134 RLOGE("setnonblocking Failed");
6135 exit(1);
6136 }
6137
lh7b0674a2022-01-10 00:34:35 -08006138 /* create epoll fd,add socket to epoll */
6139 ep_fd = epoll_create(LYNQ_SOCKET_ENVNT_FD_MAX);
6140 //int len = sizeof(struct sockaddr_in);
6141 lynq_ev.events = EPOLLIN | EPOLLET;
6142 lynq_ev.data.fd = server_socket_fd;
6143 if(epoll_ctl(ep_fd, EPOLL_CTL_ADD, server_socket_fd, &lynq_ev) < 0)
6144 {
6145 fprintf(stderr, "epoll set insertion error: fd=%d\n", server_socket_fd);
6146 return;
6147 }
6148 else
6149 {
6150 printf("monitor socket add epoll success!!!\n");
6151 }
6152 char buffer[LYNQ_SOCKET_BUFFER];
6153 lynq_client_t *client_tmp = NULL;
6154 /* tranlate data */
6155 while(true)
6156 {
6157 if(!s_registerCalled)
6158 {
6159 sleep(1);
6160 continue;
6161 }
6162 en_fd = epoll_wait(ep_fd, lynq_events, 10000, -1);//###Check valid
6163 if(en_fd <=0 )
6164 {
6165 continue;
6166 }
6167 for (int n = 0; n < en_fd; ++n)
6168 {
6169 if (lynq_events[n].data.fd == server_socket_fd)
6170 {
6171 /* define address to catch the client addreess*/
6172 //struct sockaddr_in client_addr;
6173 socklen_t client_addr_length = sizeof(lynqClient_addr);
6174 /* receive the data */
6175 bzero(buffer, LYNQ_SOCKET_BUFFER);
q.huang5bbadde2023-02-09 16:50:52 +08006176 while(recvfrom(server_socket_fd, buffer, LYNQ_SOCKET_BUFFER,0,(struct sockaddr*)&lynqClient_addr, &client_addr_length) != -1)//add while by hq for bug 760 2023/02/09
lh7b0674a2022-01-10 00:34:35 -08006177 {
q.huang5bbadde2023-02-09 16:50:52 +08006178 client_tmp = (lynq_client_t*)buffer;
6179 RLOGD("[LYNQ socketId] utoken=%d,request=%d,len=%d,param=%s",client_tmp->uToken,client_tmp->request,client_tmp->paramLen,client_tmp->param);
6180 //char test[36] = {};
6181 //sprintf(test,"test okay len = %d",client_tmp->paramLen);
6182 //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&client_addr,client_addr_length);
6183 argv[0] = (char *)lynq_requset_to_string(client_tmp->request);
6184 argc = 0;
6185 if(client_tmp->paramLen > 0)
lh7b0674a2022-01-10 00:34:35 -08006186 {
q.huang5bbadde2023-02-09 16:50:52 +08006187 /*transfer struct*/
6188 argc = parse_param(client_tmp->param, argv+1, MAX_ARGS);
6189 if(argc < 1)
6190 {
6191 RLOGE("%s: error input.", buffer);
6192 continue;
6193 }
6194 }
6195 printf("argc =%d\n",argc);
6196 argc = argc+1;
6197 for(int t = 0;t<argc;t++)
6198 {
lxfdb3a24c2023-11-20 06:26:13 -08006199 RLOGD("LYNQ_REQUEST argv[%d]=%s\n",t,argv[t]);
q.huang5bbadde2023-02-09 16:50:52 +08006200 }
6201 COMMAND *command = find_command(argv[0]);
6202 if(!command)
6203 {
6204 RLOGE("%s: No such command for DemoApp", argv[0]);
lh7b0674a2022-01-10 00:34:35 -08006205 continue;
6206 }
q.huang5bbadde2023-02-09 16:50:52 +08006207 int32_t request;
6208 request = command->request;
6209 RIL_SOCKET_ID id = RIL_SOCKET_1;
6210 if(utils::is_support_dsds()) {
6211 id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
6212 } else if(utils::is_suppport_dsss()) {
6213 id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
ll71a113b2022-10-21 18:07:25 +08006214 }
q.huang5bbadde2023-02-09 16:50:52 +08006215 if(request == -1)
ll71a113b2022-10-21 18:07:25 +08006216 {
q.huang5bbadde2023-02-09 16:50:52 +08006217 (*(command->func)) (argc, argv, id, NULL);
6218 continue;
jb.qi96449342022-09-19 22:14:41 -07006219 }
q.huang5bbadde2023-02-09 16:50:52 +08006220 if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
6221 RLOGW("unsupported request code %d token %d", request);
6222 // FIXME this should perhaps return a response
6223 continue;
6224 }
6225 /*jb.qi add for two sim suspend 2022/9/19 start lei modify for factory test of sleep*/
6226 if(request == LYNQ_REQUEST_CHANGE_SCREEN_STATE || request == LYNQ_REQUEST_CHANGE_RADIO)
6227 {
6228 int i;
6229 RLOGD("lynq_request_change_screen_state");
6230 if(request == LYNQ_REQUEST_CHANGE_SCREEN_STATE)
6231 {
6232 for(i=0;i<2;i++) //suspend sim0 and sim1
6233 {
6234 lynq_sendRequestToMd(RIL_REQUEST_SCREEN_STATE, i, argv, lynqClient_addr, client_tmp->uToken);
6235 }
6236 }
6237 /*lei modify for factory test of sleep*/
6238 if(request == LYNQ_REQUEST_CHANGE_RADIO)
6239 {
6240 for(i=0;i<2;i++) //both radio on/off
6241 {
6242 lynq_sendRequestToMd(RIL_REQUEST_RADIO_POWER, i, argv, lynqClient_addr, client_tmp->uToken);
6243 }
6244 }
6245 continue;
6246 }
6247 /*jb.qi add for two sim suspend 2022/9/19 end*/
6248 RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
6249 RequestInfo *pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
6250 pRI->uToken = client_tmp->uToken;
6251 pRI->lynqEvent = 2;
6252 pRI->uClient_addr.sin_family = lynqClient_addr.sin_family;
6253 pRI->uClient_addr.sin_addr.s_addr = lynqClient_addr.sin_addr.s_addr;
6254 pRI->uClient_addr.sin_port = lynqClient_addr.sin_port;
6255 //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&pRI->uClient_addr,client_addr_length);
6256 //pRI->uClient_addr.sa_family = (struct sockaddr)client_addr.sa_family;
6257 //memcpy(pRI->uClient_addr.sa_data,&client_addr
6258 //Radio on/off only allow one thread operate.
6259 if(request == RIL_REQUEST_RADIO_POWER)
6260 {
6261 speciaRequest_wait();
6262 }
6263 #ifdef ECALL_SUPPORT
6264 else if(request == RIL_REQUEST_ECALL_FAST_MAKE_ECALL)
6265 {
6266 init_redial_flag();
6267 }
6268 #endif
6269 memset(Time_buf,0,sizeof(Time_buf));
6270 GetTimeString(Time_buf);
6271 //FUNCTION_CALLED(Time_buf,requestToString(request));
6272 int waittoken = pRI->token;
6273 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
6274 FUNCTION_CALLED(Time_buf,requestToString(request));
6275 waitResponse(waittoken);
6276 memset(Time_buf,0,sizeof(Time_buf));
6277 GetTimeString(Time_buf);
6278 FUNCTION_RETURN(Time_buf,requestToString(request));
6279 bzero(buffer, LYNQ_SOCKET_BUFFER);
6280
jb.qi96449342022-09-19 22:14:41 -07006281 }
q.huang5bbadde2023-02-09 16:50:52 +08006282 RLOGE("process Receive Data end");
6283 // continue;
lh7b0674a2022-01-10 00:34:35 -08006284 }
6285 }
6286 }
6287 RLOGD("close socket fd");
6288 close(server_socket_fd);
you.chene1d75e92024-01-02 14:26:51 +08006289#ifdef LED_SUPPORT
6290 mbtk_netled_deinit();
6291#endif
lh7b0674a2022-01-10 00:34:35 -08006292 return ;
6293}
6294int LYNQ_RIL_respSocket(Parcel &p,RIL_Token t)
6295{
6296 RLOGD("LYNQ_RIL_respSocket send start");
lh7b0674a2022-01-10 00:34:35 -08006297 ssize_t sent = 0;
lh7b0674a2022-01-10 00:34:35 -08006298 RequestInfo *pRI = (RequestInfo *)t;
ll90a255c2022-04-07 09:09:55 +00006299 if(pRI->lynqEvent!=2)
lh7b0674a2022-01-10 00:34:35 -08006300 {
6301 RLOGD("this is internal event!!!");
6302 return -1;
6303 }
6304 int dataSize = p.dataSize();
6305 const uint8_t* data = p.data();
6306 RLOGD("lynqSocketSend RESPONSE!!!! ");
lh7b0674a2022-01-10 00:34:35 -08006307 sent = sendto(server_socket_fd, data, dataSize, 0, (struct sockaddr *)&pRI->uClient_addr, sizeof(pRI->uClient_addr));
6308 if( sent < 0 )
6309 {
6310 RLOGE("lynqSocketSend send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
6311 sent,server_socket_fd, dataSize);
lh7b0674a2022-01-10 00:34:35 -08006312 return -1;
6313 }
6314 return 0;
6315}
6316int LYNQ_RIL_respSocket_sp(Parcel &p,RequestInfo *pRI)
6317{
6318 RLOGD("LYNQ_RIL_respSocket send start");
6319 int ret =0;
6320 bool sendResult =false;
6321 ssize_t sent = 0;
6322 uint8_t dataLength[4];
6323 int verify = 0x55aa;
6324 int dataSize = p.dataSize();
6325 const uint8_t* data = p.data();
ll90a255c2022-04-07 09:09:55 +00006326 if(pRI->lynqEvent!=2)
lh7b0674a2022-01-10 00:34:35 -08006327 {
6328 RLOGD("this is internal event!!!");
6329 return -1;
6330 }
6331 RLOGD("lynqSocketSend RESPONSE!!!! ");
lh7b0674a2022-01-10 00:34:35 -08006332
6333 sent = sendto(server_socket_fd, data, dataSize, 0, (struct sockaddr *)&pRI->uClient_addr, sizeof(pRI->uClient_addr));
6334 if( sent < 0 )
6335 {
6336 RLOGE("lynqSocketSend send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
6337 sent,server_socket_fd, dataSize);
lh7b0674a2022-01-10 00:34:35 -08006338 return -1;
6339 }
6340 return 0;
6341}
6342
q.huang036b6cf2023-01-10 14:29:20 +08006343bool is_need_use_shm(int dataSize, int urc_id)
6344{
6345 switch(urc_id)
6346 {
6347 /*network*/
6348 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
6349 case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
6350 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
6351 case RIL_UNSOL_SIGNAL_STRENGTH:
llcce1a812023-01-19 15:49:25 +08006352 /*sms*/
6353 case RIL_UNSOL_RESPONSE_NEW_SMS:
6354 /*sim*/
6355 //case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: Not supported at present
q.huang036b6cf2023-01-10 14:29:20 +08006356 /*call*/
6357 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
6358 case RIL_UNSOL_CALL_RING:
6359 case RIL_UNSOL_RINGBACK_TONE:
6360 case RIL_UNSOL_CALL_INFO_INDICATION:
6361#ifdef ECALL_SUPPORT
6362 case RIL_UNSOL_ECALL_INDICATIONS://9502
rjw7ee7bb42023-01-18 11:34:28 +08006363#endif
6364 /*Data*/
6365 case LYNQ_URC_DATA_CALL_STATUS_IND:
6366 case LYNQ_URC_MODIFY_APNDB:
6367 case LYNQ_URC_RESET_APNDB:
q.huang036b6cf2023-01-10 14:29:20 +08006368 break;
6369 default:
6370 return false;
6371 }
6372 if(dataSize>urc_broadcase_shm_size_limit && dataSize <= get_max_shem_buffer_size())
6373 {
6374 return true;
6375 }
6376 return false;
6377}
6378
6379int LYNQ_RIL_urcBroadcast(Parcel &p, int urc_id)
lh7b0674a2022-01-10 00:34:35 -08006380{
6381 RLOGD("LYNQ_RIL_urcBroadcast send start");
q.huang036b6cf2023-01-10 14:29:20 +08006382 int ret =0;
6383 ssize_t sent = 0;
6384 p.setDataPosition(0);
lh7b0674a2022-01-10 00:34:35 -08006385 int dataSize = p.dataSize();
6386 const uint8_t* data = p.data();
q.huang036b6cf2023-01-10 14:29:20 +08006387 RLOGD("LYNQ_RIL_urcBroadcast urc_id is %d, dataSize=%d, msg is %s", urc_id, dataSize, requestToString(urc_id));
6388 if(is_need_use_shm(dataSize,urc_id))
6389 {
6390 int index,level;
6391 if(get_cur_shem_buffer_index(dataSize,&level,&index))
6392 {
6393 char* p_shm_buffer=get_shem_buffer(level,index);
6394 memcpy(p_shm_buffer,data,dataSize);
6395 uint32_t* pFirstInt = (uint32_t*) const_cast<uint8_t*> (data);
6396 *pFirstInt=*pFirstInt+((index+1)<<SHM_BUFFER_INDEX_OFFSET)+((dataSize)<<SHM_BUFFER_SIZE_OFFSET);
6397 dataSize=sizeof(int32_t)*2;
q.huangf99a5a12023-02-14 18:07:50 +08006398 RLOGD("LYNQ_RIL_urcBroadcast use share mem level is %d, index is %d,pointer is %p",level,index,p_shm_buffer);
q.huang036b6cf2023-01-10 14:29:20 +08006399 }
6400 }
lhced7d4a2023-03-28 09:50:52 +08006401 sent = sendto(lynq_urc_socket_fd, data, dataSize, 0, (struct sockaddr *)&urc_broadcast_addr, sizeof(urc_broadcast_addr));
lh7b0674a2022-01-10 00:34:35 -08006402 if( sent < 0 )
6403 {
6404 RLOGE("LYNQ_RIL_urcBroadcast send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
lhced7d4a2023-03-28 09:50:52 +08006405 sent,lynq_urc_socket_fd, dataSize);
lh7b0674a2022-01-10 00:34:35 -08006406 return -1;
6407 }
q.huang036b6cf2023-01-10 14:29:20 +08006408
lh7b0674a2022-01-10 00:34:35 -08006409 return 0;
6410}
6411/*Warren add for t800 RIL Service 2021/12/10 end*/
6412
6413void
6414RIL_StartRevSocket()
6415{
6416 RLOGD("RIL_StartRevSocket start\n");
xja1c30b82022-01-25 16:13:48 +08006417 char *argv[MAX_ARGS] = {0};
lh7b0674a2022-01-10 00:34:35 -08006418 int argc = 0;
6419
6420 prctl(PR_SET_NAME,(unsigned long)"UDP_Thr");
6421
6422 /*listen UPD SOCKET port */
6423 struct sockaddr_in server_addr;
6424 bzero(&server_addr, sizeof(server_addr));
6425 server_addr.sin_family = AF_INET;
6426 server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
6427 server_addr.sin_port = htons(SERVER_PORT);
6428 /* create socket */
6429 //int server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
6430 server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
6431 if(server_socket_fd == -1)
6432 {
6433 RLOGE("Create Socket Failed:");
6434 exit(1);
6435 }
6436
6437 /* bind socket port*/
6438 if(-1 == (bind(server_socket_fd,(struct sockaddr*)&server_addr,sizeof(server_addr))))
6439 {
6440 RLOGE("Server Bind Failed:");
6441 exit(1);
6442 }
6443
6444 /* tranlate data */
6445 while(true)
6446 {
6447 if(!s_registerCalled)
6448 {
6449 sleep(1);
6450 continue;
6451 }
6452 /* define address to catch the client addreess*/
6453 //struct sockaddr_in client_addr;
6454 socklen_t client_addr_length = sizeof(client_addr);
6455
6456 /* receive the data */
6457 char buffer[BUFFER_SIZE];
6458 bzero(buffer, BUFFER_SIZE);
6459 if(recvfrom(server_socket_fd, buffer, BUFFER_SIZE,0,(struct sockaddr*)&client_addr, &client_addr_length) == -1)
6460 {
6461 RLOGE("Receive Data Failed:");
6462 continue;
6463 }
6464 RLOGD("DemoAPP:%s, receve: %s", inet_ntoa(client_addr.sin_addr), buffer);
6465 if(mtkItTest(buffer)) {
6466 RLOGD("mtkItTest() handle.");
6467 continue;
6468 }
6469 int argc = parse_param(buffer, argv, MAX_ARGS);
6470 if(argc < 1)
6471 {
6472 RLOGE("%s: error input.", buffer);
6473 continue;
6474 }
6475 COMMAND *command = find_command(argv[0]);
6476 if(!command)
6477 {
6478 RLOGE("%s: No such command for DemoApp", argv[0]);
6479 continue;
6480 }
6481
6482 int32_t request;
6483
6484 request = command->request;
6485
6486 RIL_SOCKET_ID id = RIL_SOCKET_1;
6487 if(utils::is_support_dsds()) {
6488 id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
6489 } else if(utils::is_suppport_dsss()) {
6490 id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
6491 }
lh7b0674a2022-01-10 00:34:35 -08006492 if(request == -1)
6493 {
6494 (*(command->func)) (argc, argv, id, NULL);
6495 continue;
6496 }
6497
6498 if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
6499 RLOGW("unsupported request code %d token %d", request);
6500 // FIXME this should perhaps return a response
6501 continue;
6502 }
6503
6504 RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
6505
6506
6507 RequestInfo *pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
6508 //Radio on/off only allow one thread operate.
6509 if(request == RIL_REQUEST_RADIO_POWER)
6510 {
6511 speciaRequest_wait();
6512 }
6513 memset(Time_buf,0,sizeof(Time_buf));
6514 GetTimeString(Time_buf);
6515 //FUNCTION_CALLED(Time_buf,requestToString(request));
6516 int waittoken = pRI->token;
6517 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
6518 FUNCTION_CALLED(Time_buf,requestToString(request));
6519 waitResponse(waittoken);
6520 memset(Time_buf,0,sizeof(Time_buf));
6521 GetTimeString(Time_buf);
6522 FUNCTION_RETURN(Time_buf,requestToString(request));
6523 }
6524
6525 RLOGD("close socket fd");
6526 close(server_socket_fd);
6527 return ;
6528}
6529
6530const int waitResponse(int token)
6531{
6532 int waitToken = token;
6533 struct timeval now;
6534 struct timespec timeout;
6535 if((token&BLOCK_MARK) != BLOCK_MARK){
6536 RLOGD("No need wait!,token is %x!",token);
6537 return 0;
6538 }
6539
6540 gettimeofday(&now,NULL);
6541 timeout.tv_sec = now.tv_sec+60; //timeout is 1min
6542 timeout.tv_nsec = now.tv_usec*1000;
6543
6544 RLOGD("Block Request, wait token is %x,",waitToken);
6545 BLOCK_LOCK();
6546 if(waitToken == wakeup_token)
6547 RLOGD("response early than return, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
6548 while(!(waitToken == wakeup_token)) {
6549 RLOGD("Wait Response, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
6550 int ret = BLOCK_WAIT(&timeout);
6551 if(ret == ETIMEDOUT){
6552 RLOGD("Wait Response timeout, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
6553 goto out;
6554 }
6555 }
6556 RLOGD("Response wakeup,token is %x!",wakeup_token);
6557 wakeup_token = -1;
6558out:
6559 BLOCK_UNLOCK();
6560 return 0;
6561}
6562
lld164b022022-03-29 14:01:01 +08006563/**
6564 * @brief check at input in at_buffer
6565 * @param buf type:in at port input
6566 * @return int
6567 */
6568static int lynq_inside_at_buffer(char *buf)
6569{
6570 for(int i = 0; i < MAX_AT_CMD; i++)
6571 {
6572 if(at_buf_ext[i] == NULL)
6573 {
6574 break;
6575 }
6576 else
6577 {
llf4be54d2022-04-18 08:08:38 +00006578 if(strstr(buf, at_buf_ext[i]))
lld164b022022-03-29 14:01:01 +08006579 {
6580 return 1;
6581 }
6582 }
6583 }
6584 return 0;
6585}
6586
6587/**
6588 * @brief send input to client
6589 * @param buffer type:in buffer from at port
6590 * @param len_buf type:in strlen(buffer)
6591 * @param client type:in sockaddr client
6592 * @return int
6593 */
6594static int lynq_send_info(char *buffer, int len_buf, struct sockaddr* client)
6595{
6596 socklen_t len = sizeof(*client);
6597 int sent = sendto(sockfd,buffer,len_buf,0,client,len);
6598 if( sent < 0 )
6599 {
6600 RLOGE("lynq_send_info send fail (sent=%d, sendFD=%d, dataSize=%d)",
6601 sent,sockfd, len);
6602 return sent;
6603 }
6604 return 0;
6605}
6606
6607/**
6608 * @brief Fetch data from a one-dimensional array into a two-dimensional array
6609 *
6610 * @param cmd type:in buffer from client
6611 * @param argv type:in two-dimensional array
6612 * @param cnt type:in Two dimensional array subscript
6613 * @return int
6614 */
6615static int lynq_parse_at_cmd(char *cmd, char *argv[], int cnt)
6616{
6617 if(NULL == cmd || NULL == argv)
6618 {
6619 return -1;
6620 }
6621 if(cnt > MAX_AT_CMD)
6622 {
6623 return -1;
6624 }
6625 const char s[2] = ";";
6626 char *token;
6627 int argc = cnt;
6628 token = strtok(cmd, s);
6629 while( token != NULL ) {
6630 argv[argc++] = token;
6631 token = strtok(NULL, s);
6632 }
6633 return 0;
6634}
6635
6636/**
6637 * @brief count at cmd amount
6638 *
6639 * @param type:in buffer
6640 * @return int
6641 */
6642static int lynq_count_at(char *buffer)
6643{
6644 char *p = buffer;
6645 int count = 0;
6646 while(*p != '\0')
6647 {
6648 if(*p == ';')
6649 {
6650 count++;
6651 }
6652 *p++;
6653 }
6654 return count+1;
6655}
6656
6657/**
6658 * @brief receive registion and display on at port
6659 * @param parm type:in
6660 * @return void*
6661 */
6662void *receive_at(void *parm)
6663{
6664 RLOGE("receive_at thread start\n");
6665 struct sockaddr* cli = (struct sockaddr*)parm;
6666 socklen_t len;
6667 int recv = 0;
6668 char display[1024] = {0};
6669 /*For at extension to receive at buffer*/
llacba3662022-04-15 16:57:13 +08006670 bool flag = false;
lld164b022022-03-29 14:01:01 +08006671 int count_at_cmd = 0;
6672 len = sizeof(*cli);
6673 while(1)
6674 {
llacba3662022-04-15 16:57:13 +08006675 if(!flag)
lld164b022022-03-29 14:01:01 +08006676 {
6677 RLOGE("receive third at cmd\n");
6678 recv = recvfrom(sockfd, buffer_at, LYNQ_AT_SOCKET_BUFFER, 0, cli, &len);
6679 if(recv < 0)
6680 {
6681 RLOGE("recv fail\n");
6682 continue;
6683 }
6684 RLOGE("recvfrom from client\n");
6685 /*parse buffer for at command*/
6686 count_at_cmd = lynq_count_at(buffer_at);
6687 if(count_at_cmd > MAX_AT_CMD)
6688 {
6689 RLOGE("too many at cmd\n");
6690 continue;;
6691 }
6692 lynq_parse_at_cmd(buffer_at, at_buf_ext, 0);
llacba3662022-04-15 16:57:13 +08006693 flag = true;
lld164b022022-03-29 14:01:01 +08006694 }
6695 else
6696 {
6697 RLOGE("display output on at port\n");
6698 bzero(display, 1024);
6699 recv = recvfrom(sockfd, display, LYNQ_AT_SOCKET_BUFFER, 0, cli, &len);
6700 if(recv < 0)
6701 {
6702 RLOGE("recv fail\n");
6703 continue;
6704 }
6705 /*display on at port*/
6706 else
6707 {
6708 strcat(display, "\n");
6709 int n = write(ttyGS3_fd,display,strlen(display));
6710 if(n<0)
6711 {
6712 RLOGE("lynq resp write error");
6713 }
6714 }
6715 }
lld164b022022-03-29 14:01:01 +08006716 }
6717 return NULL;
6718}
6719
ll2f3fea22022-09-29 17:16:10 +08006720static void wait_reset_mipc_response(void)
6721{
6722 int outfd = open("/data/tp",O_RDONLY);
6723 if(outfd == -1){
6724 RLOGD("open error");
6725 return;
6726 }
6727 char rst[1024];
6728 char response[2048];
6729 int s;
6730 s = read(outfd,rst,sizeof(rst));
6731 if (s>0)
6732 {
6733 RLOGD("lei buf: %s \n", rst);
6734 /*respone ok or error*/
6735 if(rst[0] = '0')
6736 {
6737 sprintf(response,"%s%s","+LRSTMD:",rst);
6738 /*check fd can or can't write*/
6739 write(ttyGS3_fd,response,strlen(response));
6740 write(ttyGS3_fd,"\nOK\n",4);
6741 }
6742 else
6743 {
6744 sprintf(response,"%s%s","+CME ERROR:",rst);
6745 /*check fd can or can't write*/
6746 write(ttyGS3_fd,response,strlen(response));
6747 }
6748 }
6749 else
6750 {
6751 RLOGD("wait_reset_mipc_response unknow error\n");
6752 }
6753 usleep(1);
6754 close(outfd);
6755 return;
6756}
6757
llaaca09b2022-03-14 16:14:28 +08006758void startUsbLoop(void)
6759{
lld164b022022-03-29 14:01:01 +08006760 /*lei add*/
6761 //Create a network communication object
6762 struct sockaddr_in addr_serv;
6763 struct sockaddr_in addr_clie;
6764 //Creating a Socket object
6765 sockfd=socket(AF_INET,SOCK_DGRAM,0);
6766 memset(&addr_serv, 0, sizeof(addr_serv));
6767 addr_serv.sin_family =AF_INET;
6768 addr_serv.sin_port =htons(LYNQ_AT_SERVICE_PORT);
6769 addr_serv.sin_addr.s_addr=htonl(INADDR_ANY);
6770 bind(sockfd,(struct sockaddr*)&addr_serv,sizeof(addr_serv));
6771 //receive registion and display on at port
6772 pthread_t thid;
6773 if(pthread_create(&thid, NULL, receive_at, (struct sockaddr*)&addr_clie) != 0) {
6774 RLOGE("thread creation failed\n");
6775 exit(1);
6776 }
6777 RLOGE("thread creation\n");
6778 /*lei add*/
llaaca09b2022-03-14 16:14:28 +08006779 int nread=-1;
6780 int n = -1;
6781 int routeId = -1;
6782 char buffer[1024]={};
6783 char tempbuf[1024]={};
6784 char buf_parser[64] = {};
6785 int argc = 0;
6786 char *argv[MAX_ARGS];//argv[0]:at name,argv[1]:raw data,argv[2]:at type,argv[3]:paramter1,argv[4]:paramter2 ....
6787 char eBuf[1024];
lle71c13f2022-10-12 13:42:18 +08006788 if(ttyGS3_fd > 0)
6789 {
6790 close(ttyGS3_fd);
6791 RLOGE("reopen need close");
6792 }
llaaca09b2022-03-14 16:14:28 +08006793 ttyGS3_fd = open("/dev/ttyGS3",O_RDWR);
6794 if(ttyGS3_fd==-1)
6795 {
6796 RLOGE("open ttyGS3 failure!!!");
6797 printf("open ttyGS3 failure!!!\n");
6798 //printf("%s\n",strerr(errno));
6799 perror("--test--");
llf5512ed2022-09-15 19:04:43 +08006800 //kill(0, SIGKILL);
llaaca09b2022-03-14 16:14:28 +08006801 }
llf5512ed2022-09-15 19:04:43 +08006802 RLOGD("[%s]open %s successfully ttyGS3_d %d!!!\n",__FUNCTION__,ttyname(ttyGS3_fd), ttyGS3_fd);
llaaca09b2022-03-14 16:14:28 +08006803 while(1)
6804 {
6805 bzero(buffer, 1024);
6806 bzero(tempbuf, 1024);
6807 bzero(buf_parser, 64);
6808 if((nread=read(ttyGS3_fd,buffer,1024))>0)
6809 {
6810 if(nread<2)
6811 {
6812 //RLOGD("input is space!!!");
6813 continue;
6814 }
6815 buffer[nread-1] = '\0';
6816 //printf("buffer is %s\n",buffer);
6817 for(int i = 0 ; i < nread ; i++)
6818 {
6819 if(buffer[i]=='=')
6820 {
6821 break;
6822 }
6823 if(buffer[i]>='a'&&buffer[i]<='z')
6824 {
6825 buffer[i] = buffer[i]-32;
6826 }
6827 }
lld164b022022-03-29 14:01:01 +08006828 RLOGD("buffer is %s\n",buffer);
6829 /*lei add*/
6830 /*check third cmd in buffer*/
6831 if(lynq_inside_at_buffer(buffer))
llaaca09b2022-03-14 16:14:28 +08006832 {
lld164b022022-03-29 14:01:01 +08006833 lynq_send_info(buffer, nread, (struct sockaddr*)&addr_clie);
llaaca09b2022-03-14 16:14:28 +08006834 }
lld164b022022-03-29 14:01:01 +08006835 /*lei add*/
6836 else
llaaca09b2022-03-14 16:14:28 +08006837 {
lld164b022022-03-29 14:01:01 +08006838 argc = lynqParseUsbCommand(buffer,argv,tempbuf,buf_parser,MAX_ARGS);
6839 if(argc<0)
6840 {
6841 bzero(eBuf, 1024);
6842 sprintf(eBuf,"LYNQ:%s not support!!!\n",buffer);
6843 int n = write(ttyGS3_fd,eBuf,strlen(eBuf));
llaaca09b2022-03-14 16:14:28 +08006844 if(n<0)
6845 {
6846 perror("lynq resp write:");
6847 }
lld164b022022-03-29 14:01:01 +08006848 RLOGD("n = %d\n",n);
llaaca09b2022-03-14 16:14:28 +08006849 continue;
lld164b022022-03-29 14:01:01 +08006850 }
6851 usb_at_transfer_t *atCmd = lynqFindId(argv[0]);
6852 if(atCmd==NULL)
llaaca09b2022-03-14 16:14:28 +08006853 {
lld164b022022-03-29 14:01:01 +08006854 RLOGD("LYNQ send ATCMD:%s!!!",argv[1]);
llaaca09b2022-03-14 16:14:28 +08006855 lynqSendAt(argc,argv,1010);
ll2f3fea22022-09-29 17:16:10 +08006856 usleep(50*1000);
6857 if(!strcmp(buffer, "AT+LRSTMD"))
6858 {
6859 wait_reset_mipc_response();
6860 }
lld164b022022-03-29 14:01:01 +08006861 continue;
llaaca09b2022-03-14 16:14:28 +08006862 }
lld164b022022-03-29 14:01:01 +08006863 if(!((1<<atoi(argv[2])) & (atCmd->support)))
llaaca09b2022-03-14 16:14:28 +08006864 {
lld164b022022-03-29 14:01:01 +08006865 RLOGD("LYNQ %s not support!!!",atCmd->cmdName);
6866 int n = write(ttyGS3_fd,"\n+CME ERROR: 100\n",strlen("\n+CME ERROR: 100\n"));
6867 if(n<0)
llaaca09b2022-03-14 16:14:28 +08006868 {
lld164b022022-03-29 14:01:01 +08006869 perror("lynq resp write:");
llaaca09b2022-03-14 16:14:28 +08006870 }
lld164b022022-03-29 14:01:01 +08006871 continue;
llaaca09b2022-03-14 16:14:28 +08006872 }
lld164b022022-03-29 14:01:01 +08006873 routeId = routeCmd(atCmd->cmdId);
6874 //routeId = routeCmd(atcmd->cmdId);
6875 //routeId = LYNQ_GOTO_AT;
6876 switch(routeId)
llaaca09b2022-03-14 16:14:28 +08006877 {
lld164b022022-03-29 14:01:01 +08006878 case LYNQ_GOTO_AT:
llaaca09b2022-03-14 16:14:28 +08006879 {
lld164b022022-03-29 14:01:01 +08006880 lynqSendAt(argc,argv,1010);
6881 break;
llaaca09b2022-03-14 16:14:28 +08006882 }
lld164b022022-03-29 14:01:01 +08006883 case LYNQ_GOTO_TELE_REQ:
6884 {
6885 usb_cmd_t *atCmdEvn = lynqFindUsbEvent(argv[0]);
6886 if(!atCmdEvn)
6887 {
6888 RLOGD("can not find at cmd event!!!");
6889 continue;
6890 }
6891 atCmdEvn->fun(argc,argv,atCmdEvn->rilRequest,1011);
6892 break;
6893 }
6894 case LYNQ_GOTO_USER_REQ:
6895 {
6896 usb_cmd_t *atCmdEvn = lynqFindUsbEvent(argv[0]);
6897 if(!atCmdEvn)
6898 {
6899 RLOGD("can not find at cmd event!!!");
6900 continue;
6901 }
6902 atCmdEvn->ufun(argc,argv,1012);
6903 break;
6904 }
6905 case LYNQ_GOTO_LINFO_REQ:
6906 {
6907 lynqInfo(argv);
6908 break;
6909 }
6910 // case LYNQ_GOTO_PLAT_REQ:
6911 // {
6912 // lynq_deal_with_log_at(&argv[3]);
6913 // break;
6914 // }
6915 case LYNQ_GOTO_RNDIS_REQ:
6916 {
6917 lynq_get_rndis_data(buffer);
6918 break;
6919 }
6920 case LYNQ_GOTO_FACTORY:
6921 {
6922 lynq_get_factory_data(argc,argv);
6923 break;
6924 }
tao.liu68d6eeb2022-11-17 16:48:50 +08006925 case LYNQ_GOTO_FOTA:
6926 {
6927 lynq_atfota_test(argv);
6928 break;
6929 }
rita9c8cd862022-08-10 09:36:49 +08006930 /*rita add start*/
6931 case LYNQ_GOTO_TEMP:
6932 {
6933 //write(ttyGS3_fd,"\n+CME ERROR: 1\n",strlen("\n+CME ERROR: 1\n"));
6934 lynq_at_get_temp(argc, argv);
6935 break;
6936 }
lld164b022022-03-29 14:01:01 +08006937 default:
6938 break;
llaaca09b2022-03-14 16:14:28 +08006939 }
llaaca09b2022-03-14 16:14:28 +08006940 }
lld164b022022-03-29 14:01:01 +08006941
llaaca09b2022-03-14 16:14:28 +08006942 }
6943 }
6944 close(ttyGS3_fd);
6945 return;
6946}
6947
lh7b0674a2022-01-10 00:34:35 -08006948void *
6949eventLoop(void *param) {
6950 pthread_mutex_lock(&s_startupMutex);
6951 s_started = 1;
6952 pthread_cond_broadcast(&s_startupCond);
6953 pthread_mutex_unlock(&s_startupMutex);
6954 #ifdef ECALL_SUPPORT
6955 init_ecall_timer_all();
6956 #endif /**/ECALL_SUPPORT
6957 /*warren add for t800 ril service 2021/12/13 start*/
6958 //RIL_StartRevSocket();
6959 LYNQ_RIL_urcClientInit();
6960 LYNQ_RIL_RecSocket();
6961 /*warren add for t800 ril service 2021/12/13 end*/
6962 RLOGD("error in event_loop_base errno:%d", errno);
6963 // kill self to restart on error
6964 kill(0, SIGKILL);
6965
6966 return NULL;
6967}
6968
llaaca09b2022-03-14 16:14:28 +08006969
6970void *
6971eventLoop_at(void *param) {
6972 pthread_mutex_lock(&s_startupMutex);
6973 s_started = 1;
6974 pthread_cond_broadcast(&s_startupCond);
6975 pthread_mutex_unlock(&s_startupMutex);
6976 //RIL_StartRevSocket();
6977 startUsbLoop();
6978 //startUsbLoop_test();
6979 RLOGD("error in event_loop_base errno:%d", errno);
6980 // kill self to restart on error
6981 kill(0, SIGKILL);
6982
6983 return NULL;
6984}
6985
lld164b022022-03-29 14:01:01 +08006986
6987
lh7b0674a2022-01-10 00:34:35 -08006988const int RspDispFunction(int request,char* arg, RIL_SOCKET_ID socket_id)
6989{
6990 int waittoken;
6991 RequestInfo *pRI = creatRILInfoAndInit(request, RSPD, socket_id);
6992 if(pRI == NULL)
6993 return 0;
6994 waittoken = pRI->token;
6995 switch (request) {
6996 case RIL_REQUEST_GET_CURRENT_CALLS:
6997 {
6998 RLOGD("request Current list start!");
6999 Parcel p;
7000 pRI->pCI->dispatchFunction(p, pRI);
7001 waitResponse(waittoken);
7002 RLOGD("request Current list end!");
7003 }
7004 break;
7005
7006 case RIL_REQUEST_ANSWER:
7007 {
7008 RLOGD("request Answer a MT call start!");
7009 Parcel p;
7010 pRI->pCI->dispatchFunction(p, pRI);
7011 waitResponse(waittoken);
7012 RLOGD("request Answer a MT call end!");
7013 }
7014 break;
7015
7016 case RIL_REQUEST_GET_SIM_STATUS:
7017 {
7018 int ret=getIccCardStatus(1, NULL, socket_id, pRI);
7019 if(ret == 0)
7020 waitResponse(waittoken);
7021 }
7022 break;
7023
7024 case RIL_REQUEST_DATA_REGISTRATION_STATE:
7025 {
7026 int ret=getDataRegistrationState(1, NULL, socket_id,pRI);
7027 if(ret == 0)
7028 waitResponse(waittoken);
7029 }
7030 break;
7031
7032 case RIL_REQUEST_VOICE_REGISTRATION_STATE:
7033 {
7034 int ret=getVoiceRegistrationState(1, NULL, socket_id,pRI);
7035 if(ret == 0)
7036 waitResponse(waittoken);
7037 }
7038 break;
7039 case RIL_REQUEST_SMS_ACKNOWLEDGE:
7040 {
7041 char* tmp[3] = {"RIL_REQUEST_SMS_ACKNOWLEDGE", "1", "0"};
7042 acknowledgeIncomingGsmSmsWithPdu(3,tmp,socket_id,pRI);
7043 waitResponse(waittoken);
7044 RLOGD("acknowledge last Incoming Gsm Sms : RIL_REQUEST_SMS_ACKNOWLEDGE end!");
7045 }
7046 break;
7047 case RIL_REQUEST_OEM_HOOK_RAW:
7048 {
7049 if(arg != NULL)
7050 {
7051 RLOGD("request OEM HOOK RAW start!");
7052 pRI->token = pRI->token|BLOCK_MARK;
7053 int waittokenOEM = pRI->token;
7054 Parcel p;
7055
7056 size_t pos = p.dataPosition();
7057 int len = strlen(arg);
7058 p.writeInt32(len);
7059 p.write((const void*)arg,len);
7060
7061 p.setDataPosition(pos);
7062 RLOGD("emSendATCommand: %s %d\n",arg,strlen(arg));
7063 pRI->pCI->dispatchFunction(p, pRI);
7064 waitResponse(waittokenOEM);
7065 } else {
7066 if(pRI){
7067 free(pRI);
7068 }
7069 RLOGE("at command shouldn't null");
7070 }
7071 break;
7072 }
7073 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM:
7074 {
7075 char* tmp[2] = {"RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM", "no"};
7076 handleCallSetupRequestFromSim(2, tmp, socket_id,pRI);
7077 waitResponse(waittoken);
7078 RLOGD("timeout 1 minutes, response no by RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM");
7079 break;
7080 }
7081 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE:
7082 {
7083 char* tmp[2] ={"RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE", arg};
7084 RLOGD("tmp[0]=%s, tmp[1]=%s, arg=%s", tmp[0], tmp[1], arg);
7085 sendTerminalResponse(2, tmp, socket_id, pRI);
7086 waitResponse(waittoken);
7087 break;
7088 }
7089 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:
7090 {
7091 acknowledgeLastIncomingCdmaSms(1, NULL,socket_id,pRI);
7092 waitResponse(waittoken);
7093 break;
7094 }
7095 case RIL_REQUEST_RADIO_POWER:
7096 {
7097 RLOGD("response loop, RIL_REQUEST_RADIO_POWER: %s", (arg == NULL ? "nul": arg));
7098 if(arg != NULL) {
7099 char* tmp[2] = {"RIL_REQUEST_RADIO_POWER", arg};
7100 setRadioPower(2,tmp,socket_id,pRI);
7101 waitResponse(waittoken);
7102 } else {
7103 if(pRI){
7104 free(pRI);
7105 }
7106 RLOGE("response loop, RIL_REQUEST_RADIO_POWER fail");
7107 }
7108 break;
7109 }
7110 case RIL_REQUEST_ALLOW_DATA:
7111 {
7112 int default_id = get_default_sim_data();
7113 RLOGD("RspDispFunction: socket_id=%d switch_id=%d", socket_id, default_id);
7114 char* argv[2] = {"RIL_REQUEST_ALLOW_DATA","0"};
7115 if(socket_id == default_id) {
7116 utils::mtk_property_set(PROP_DEFAULT_DATA_SIM, std::to_string(socket_id + 1).c_str());
7117 argv[1] = "1";
7118 }
7119 while(!isRadioAvailable(socket_id)) {
7120 sleep(1);
7121 RLOGD("[SIM%d]RspDispFunction(RIL_REQUEST_ALLOW_DATA): wait radio available", socket_id);
7122 }
7123 setDataAllowed(2, argv, socket_id, pRI);
7124 waitResponse(waittoken);
7125 break;
7126 }
7127 case RIL_REQUEST_CDMA_FLASH:
7128 {
7129 sendCDMAFeatureCode(1, NULL, socket_id, pRI);
7130 waitResponse(waittoken);
7131 break;
7132 }
7133 default:
xja1c30b82022-01-25 16:13:48 +08007134 if(pRI) {
7135 free(pRI);
7136 pRI = NULL;
7137 }
lh7b0674a2022-01-10 00:34:35 -08007138 break;
7139 }
7140 return 0;
7141}
7142
7143void * responseLoop(void *param) {
7144 pthread_mutex_lock(&s_startupMutex);
7145 s_responseDispatch= 1;
7146 pthread_cond_broadcast(&s_startupCond);
7147 pthread_mutex_unlock(&s_startupMutex);
7148 responseDispatch();
7149 RLOGD("error in response_loop_base errno:%d", errno);
7150 // kill self to restart on error
7151 kill(0, SIGKILL);
7152
7153 return NULL;
7154}
7155
7156void ATCIRequest(int request,char* reqString, void* t,int argc,char**argv)
7157{
xja1c30b82022-01-25 16:13:48 +08007158 if(t == NULL) {
7159 RLOGE("ATCIRequest t is null");
7160 return;
7161 }
lh7b0674a2022-01-10 00:34:35 -08007162 RequestInfo *pRI = (RequestInfo *)t;
7163 int waittoken;
7164 if (request < RIL_REQUEST_VENDOR_BASE) {
7165 pRI->pCI = &(s_commands[request]);
7166 } else {
7167 pRI->pCI = find_mtk_command(request);
7168 }
ll6e73f202022-12-28 14:59:46 +08007169 /*lei modify for Some requests that are not in the ril_commands.h and mtk_ril_commands.h but in commands.h*/
7170 COMMAND *command = find_command(reqString);
xja1c30b82022-01-25 16:13:48 +08007171 if(pRI->pCI == NULL){
ll6e73f202022-12-28 14:59:46 +08007172 if(command == NULL)
7173 {
7174 RLOGE("pCI command & command not found!");
7175 if(pRI) {
7176 free(pRI);
7177 }
7178 return;
xja1c30b82022-01-25 16:13:48 +08007179 }
xja1c30b82022-01-25 16:13:48 +08007180 }
ll6e73f202022-12-28 14:59:46 +08007181 /*lei modify for Some requests that are not in the ril_commands.h and mtk_ril_commands.h but in commands.h*/
ll2bba45a2023-01-12 22:04:37 +08007182
lh7b0674a2022-01-10 00:34:35 -08007183 if(utils::is_suppport_dsss()){
7184 pRI->socket_id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
7185 }
7186
7187 if(utils::is_support_dsds() && (request != RIL_REQUEST_RADIO_POWER)){
7188 pRI->socket_id = (RIL_SOCKET_ID)get_atci_sim();
7189 }
lh7b0674a2022-01-10 00:34:35 -08007190 pRI->p_next = NULL;
7191
ll6e73f202022-12-28 14:59:46 +08007192
7193 RLOGD("function %s line %d reqString %s", __FUNCTION__, __LINE__, reqString);
lh7b0674a2022-01-10 00:34:35 -08007194 if(command == NULL) {
7195 RLOGE("ATCI request command find error!");
xja1c30b82022-01-25 16:13:48 +08007196 if(pRI) {
7197 free(pRI);
7198 }
7199 return;
lh7b0674a2022-01-10 00:34:35 -08007200 } else {
7201 RLOGE("ATCI request name is %s!",command->name);
7202 }
7203
7204 pRI->token = GenerateToken(ATCI, request);
7205 waittoken = pRI->token;
7206 if(request == RIL_REQUEST_RADIO_POWER) {
7207 speciaRequest_wait();
7208 }
7209 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
7210 //need wait Ril_onRequestComplete return.
7211 waitResponse(waittoken);
7212 return;
7213}
7214
7215void startWakupLoop(void)
7216{
7217 pthread_t WakeupReasonThread;
7218
7219 RLOGD("startWakupLoop()");
7220 pthread_mutex_lock(&s_startupMutex);
7221
7222 pthread_attr_t attr;
7223 pthread_attr_init(&attr);
7224 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7225
7226 int result = pthread_create(&WakeupReasonThread, &attr, wakeup_reason_loop, NULL);
7227 if (result != 0) {
7228 RLOGW("Failed to create wakeup reason thread: %s", strerror(result));
7229 goto done;
7230 }
7231
7232done:
7233 pthread_mutex_unlock(&s_startupMutex);
7234}
llaaca09b2022-03-14 16:14:28 +08007235/*Warren add for FAW 2021/09/23 start
7236** use ttyGS0 port
7237*/
7238int lynqSendToRil(int argc,char *argv[],int uToken)
7239{
7240 if(argc < 1)
7241 {
7242 RLOGE("lynqSendToRil error input.");
7243 return 1;
7244 }
7245 for(int i =0;i<argc;i++)
7246 {
7247 printf("argv[%d]=%s\n",i,argv[i]);
7248 }
7249 COMMAND *command = find_command(argv[0]);
7250 if(!command)
7251 {
7252 RLOGE("%s: No such command for DemoApp", argv[0]);
7253 return 1;
7254 }
7255
7256 int32_t request;
7257
7258 request = command->request;
7259
7260 RIL_SOCKET_ID id = RIL_SOCKET_1;
7261 if(utils::is_support_dsds()) {
7262 id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
7263 } else if(utils::is_suppport_dsss()) {
7264 id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
7265 }
7266
7267 if(request == -1)
7268 {
7269 (*(command->func)) (argc, argv, id, NULL);
7270 return 1;
7271 }
7272
7273 if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
7274 RLOGW("unsupported request code %d token %d", request);
7275 // FIXME this should perhaps return a response
7276 return 1;
7277 }
7278
7279 RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
7280
7281
7282 RequestInfo *pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
7283 pRI->lynqEvent = 1;
7284 //Radio on/off only allow one thread operate.
7285 if(request == RIL_REQUEST_RADIO_POWER)
7286 {
7287 speciaRequest_wait();
7288 }
7289 memset(Time_buf,0,sizeof(Time_buf));
7290 GetTimeString(Time_buf);
7291 //FUNCTION_CALLED(Time_buf,requestToString(request));
7292 int waittoken = pRI->token;
7293 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
7294 FUNCTION_CALLED(Time_buf,requestToString(request));
7295 waitResponse(waittoken);
7296 memset(Time_buf,0,sizeof(Time_buf));
7297 GetTimeString(Time_buf);
7298 FUNCTION_RETURN(Time_buf,requestToString(request));
7299 return 0;
7300}
7301
7302int sendRespToUsb(char *cmd)
7303{
7304 return 0;
7305}
7306int sendUrcToUsb(char *cmd)
7307{
7308 return 0;
7309}
7310/*Warren add for FAW 2021/09/23 end*/
lh7b0674a2022-01-10 00:34:35 -08007311
7312void startPMLoop(void)
7313{
7314 pthread_t atciSocketThread;
7315
7316 RLOGD("startPMLoop()");
7317 pthread_mutex_lock(&s_startupMutex);
7318
7319 pthread_attr_t attr;
7320 pthread_attr_init(&attr);
7321 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7322
7323 int result = pthread_create(&atciSocketThread, &attr, StartPMSocket, NULL);
7324 if (result != 0) {
7325 RLOGW("Failed to create PM thread: %s", strerror(result));
7326 goto done;
7327 }
7328
7329done:
7330 pthread_mutex_unlock(&s_startupMutex);
7331}
7332
7333void startGdbusLoop(void)
7334{
7335 pthread_t atciSocketThread;
7336
7337 RLOGD("startGdbusLoop()");
7338 pthread_mutex_lock(&s_startupMutex);
7339
7340 pthread_attr_t attr;
7341 pthread_attr_init(&attr);
7342 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7343
7344 int result = pthread_create(&atciSocketThread, &attr, init_data_gdbus_cb, NULL);
7345 if (result != 0) {
7346 RLOGW("Failed to create gdbus thread: %s", strerror(result));
7347 goto done;
7348 }
7349
7350done:
7351 pthread_mutex_unlock(&s_startupMutex);
7352}
7353
7354void startATCILoop(void)
7355{
7356 pthread_t atciSocketThread;
7357
7358 RLOGD("startATCILoop()");
7359 pthread_mutex_lock(&s_startupMutex);
7360
7361 pthread_attr_t attr;
7362 pthread_attr_init(&attr);
7363 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7364
7365 int result = pthread_create(&atciSocketThread, &attr, StartATCISocket, NULL);
7366 if (result != 0) {
7367 RLOGW("Failed to create ATCI thread: %s", strerror(result));
7368 goto done;
7369 }
7370
7371done:
7372 pthread_mutex_unlock(&s_startupMutex);
7373}
7374
7375void RIL_startEventLoop(void)
7376{
7377 RLOGD("RIL_startEventLoop()");
lhf6eea122022-01-20 19:32:14 -08007378 lynq_init_sms_manager();
lh7b0674a2022-01-10 00:34:35 -08007379 /* spin up eventLoop thread and wait for it to get started */
7380 s_started = 0;
7381 pthread_mutex_lock(&s_startupMutex);
7382
7383 pthread_attr_t attr;
7384 pthread_attr_init(&attr);
7385 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7386
7387 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
7388 if (result != 0) {
7389 RLOGW("Failed to create dispatch thread: %s", strerror(result));
7390 goto done;
7391 }
llaaca09b2022-03-14 16:14:28 +08007392
7393 while (s_started == 0) {
7394 pthread_cond_wait(&s_startupCond, &s_startupMutex);
7395 }
Hong_Liu2b7b17c2022-12-14 03:03:56 -08007396 //warren delete,beacuse of update at fwk.
7397 /*mobiletek add*
llaaca09b2022-03-14 16:14:28 +08007398 s_started = 0;
7399 result = pthread_create(&s_tid_dispatch, &attr, eventLoop_at, NULL);
7400 if (result != 0) {
7401 RLOGW("Failed to create dispatch thread: %s", strerror(result));
7402 goto done;
7403 }
lh7b0674a2022-01-10 00:34:35 -08007404
7405 while (s_started == 0) {
7406 pthread_cond_wait(&s_startupCond, &s_startupMutex);
7407 }
Hong_Liu2b7b17c2022-12-14 03:03:56 -08007408 *mobiletek add*/
lh7b0674a2022-01-10 00:34:35 -08007409 result = pthread_create(&s_tid_dispatch, &attr, responseLoop, NULL);
7410 if (result != 0) {
7411 RLOGW("Failed to create response dispatch thread: %s", strerror(result));
7412 goto done;
7413 }
7414
7415 while (s_responseDispatch == 0) {
7416 pthread_cond_wait(&s_startupCond, &s_startupMutex);
7417 }
7418done:
7419 pthread_mutex_unlock(&s_startupMutex);
7420}
7421
7422void printInputArgs(int argc, char** argv)
7423{
7424 int i=0;
7425
7426 for(i=0; i<argc; i++)
7427 {
7428 RLOGD("%s", argv[i]);
7429 }
7430}
7431
7432void initRequestInfo(RequestInfo *pRI, int request, int mode, RIL_SOCKET_ID soc_id)
7433{
7434 pRI->token = GenerateToken(mode, request);
7435 if (request < RIL_REQUEST_VENDOR_BASE) {
7436 pRI->pCI = &(s_commands[request]);
7437 } else {
7438 pRI->pCI = find_mtk_command(request);
7439 }
7440 pRI->socket_id = soc_id;
7441
7442 pRI->p_next = NULL;
7443}
7444
7445void getVoiceAndDataRegistrationState(RIL_SOCKET_ID soc_id)
7446{
7447 ARspRequest(RIL_REQUEST_DATA_REGISTRATION_STATE,soc_id);
7448 ARspRequest(RIL_REQUEST_VOICE_REGISTRATION_STATE,soc_id);
7449}
7450
7451void requestAnswer(RIL_SOCKET_ID soc_id)
7452{
7453 ARspRequest(RIL_REQUEST_ANSWER,soc_id);
7454 return;
7455}
7456void requestSMSACKNOWLEDGE(RIL_SOCKET_ID soc_id)
7457{
7458 ARspRequest(RIL_REQUEST_SMS_ACKNOWLEDGE,soc_id);
7459 return;
7460}
7461
7462#if EM_MODE_SUPPORT
7463void registerForNetworkInfo(netwokInfoNotify cb)
7464{
7465 networkCb = cb;
7466 return ;
7467}
7468void unregisterNetwork()
7469{
7470 networkCb = NULL;
7471 //AT+EINFO= flag & 0xFFFFFFF7
7472}
7473void registerForATcmdResponse(atCmdResponse cb)
7474{
7475 atResponseCb = cb;
7476 return ;
7477}
7478
7479void unregisterATcmd()
7480{
7481 atResponseCb = NULL;
7482}
7483
7484#endif
7485int emResultNotify(const char *str)
7486{
7487 RLOGD("emResultNotify %s",str);
7488 int len_s = sendto(server_socket_fd,str,strlen(str),0,(struct sockaddr *)&client_addr,sizeof(client_addr));
7489
7490 sendto(server_socket_fd,"stopemdone",strlen("stopemdone"),0,(struct sockaddr *)&client_addr,sizeof(client_addr));
7491 return len_s;
7492}
7493
7494void processUnsolicited (Parcel &p, int type)
7495{
xja1c30b82022-01-25 16:13:48 +08007496 int32_t response = -1;
lh7b0674a2022-01-10 00:34:35 -08007497 p.readInt32(&response);
7498 switch(response){
7499 case RIL_UNSOL_MAL_AT_INFO:
7500 {
7501#if EM_MODE_SUPPORT
7502 char *stringresponse = strdupReadString(p);
7503 if(strstr(stringresponse,"+ENWINFO") != NULL){
7504 RLOGD("processUnsolicited ENWINFO \n");
7505 char *start = strstr(stringresponse,":");
7506 char *end = strstr(stringresponse,",");
7507 if(start == NULL ||end == NULL ){
7508 break;
7509 }
7510 if(networkCb){
7511 //parse type & data, notify to registrants
7512 char ctype[5] = {0};
7513 int type = 0;
7514 memcpy(ctype,start+1, end - start -1);
7515 type = atoi(ctype);
7516 char *data = end+1;
7517 RLOGD("ctype %s type %d data %s\n",ctype,type,data);
7518 //parse response
7519 networkCb(type,data);
7520 }
7521 }
7522 if(stringresponse){
7523 free(stringresponse);
7524 }
7525#endif
7526 break;
7527 }
7528 default:
7529 break;
7530 }
7531}
7532void processSolicited(Parcel &p, int type) {
7533 int32_t serial, error;
xja1c30b82022-01-25 16:13:48 +08007534 serial = 0;
lh7b0674a2022-01-10 00:34:35 -08007535 p.readInt32(&serial); //telematic it is the same as ril request num
7536 p.readInt32(&error);
7537 RLOGD("processSolicited serial %d\n", serial);
7538 switch (serial) {
7539 case RIL_REQUEST_OEM_HOOK_RAW: {
7540 if (error != RIL_E_SUCCESS) {
7541 RLOGW("RIL_E_fail");
7542 if (atResponseCb) {
7543 atResponseCb(NULL, 0);
7544 }
7545 if(m_RfDesense){
7546 m_RfDesense->handle_request("", 0, 0, (RIL_Errno)error);
7547 }
7548 return;
7549 }
7550 int len;
7551 status_t status = 0;
7552 status = p.readInt32(&len);
7553 if (status != 0) {
7554 RLOGW("read int32 fail");
7555 return;
7556 }
7557 char *stringresponse = (char*) calloc(len, sizeof(char));
7558 status = p.read((void*) stringresponse, len);
7559 if (status != 0) {
7560 if (stringresponse) {
7561 free(stringresponse);
7562 }
7563 RLOGW("read int32 fail");
7564 return;
7565 }
7566 parseAtCmd(stringresponse);
7567 RLOGD("processSolicited AT string %s %d\n", stringresponse, len);
7568#if EM_MODE_SUPPORT
7569 if (atResponseCb) {
7570 if (stringresponse) {
7571
7572 atResponseCb(stringresponse, len);
7573 } else {
7574 atResponseCb(stringresponse, 0);
7575 }
7576 }
7577 if(m_RfDesense){
7578 if(stringresponse && (!isFinalResponseErrorEx(stringresponse))) {
7579 m_RfDesense->handle_request(stringresponse,len,0, (RIL_Errno)RIL_E_SUCCESS);
7580 } else {
7581 RLOGD("isFinalResponseErrorEx error or response is null");
7582 m_RfDesense->handle_request(stringresponse, 0, 0, (RIL_Errno)RIL_E_GENERIC_FAILURE);
7583 }
7584 }
7585#endif
7586 if (stringresponse) {
7587 free(stringresponse);
7588 }
7589 break;
7590 }
7591 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: {
7592#if EM_MODE_SUPPORT
7593 if (atResponseCb) {
7594 if (error != RIL_E_SUCCESS) {
7595 atResponseCb(NULL, 0);
7596 } else {
7597 atResponseCb("OK", 2);
7598 }
7599 }
7600#endif
7601 break;
7602 }
7603 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: {
7604#if EM_MODE_SUPPORT
7605 int nums = 0;
7606 int prefertype = 0;
7607 p.readInt32(&nums);
7608 if (nums != 1) {
7609 RLOGD("getpreferrednetworktype nums > 1");
7610 }
7611 p.readInt32(&prefertype);
7612 char prefertype_str[3] = { 0 };
7613 sprintf(prefertype_str, "%d", prefertype);
7614 if (atResponseCb) {
7615 if (error != RIL_E_SUCCESS) {
7616 atResponseCb(NULL, 0);
7617 } else {
7618 atResponseCb(prefertype_str, strlen(prefertype_str));
7619 }
7620 }
7621#endif
7622 break;
7623 }
7624 case RIL_REQUEST_GET_IMSI: {
7625 if (error != RIL_E_SUCCESS) {
7626 RLOGD("RIL_REQUEST_GET_IMSI error %d\n", error);
7627 }
7628 break;
7629 }
7630 }
7631}
7632
7633#ifdef ECALL_SUPPORT
7634static int responseEcallStatus(Parcel &p, void *response, size_t responselen) {
7635 if (response == NULL || responselen != sizeof(RIL_Ecall_Unsol_Indications)) {
7636 if (response == NULL) {
7637 RLOGE("invalid response: NULL");
7638 }
7639 else {
7640 RLOGE("responseEcallStatus: invalid response length %d expecting len: %d",
7641 sizeof(RIL_Ecall_Unsol_Indications), responselen);
7642 }
7643 return RIL_ERRNO_INVALID_RESPONSE;
7644 }
7645
7646 RIL_Ecall_Unsol_Indications *p_cur = (RIL_Ecall_Unsol_Indications *)response;
7647 p.writeInt32(p_cur->ind);
7648 p.writeInt32(p_cur->call_id);
7649
7650 startResponse;
7651 appendPrintBuf("ECall Status: %d, call_id: %d",
7652 p_cur->ind, p_cur->call_id);
7653 closeResponse;
7654
7655 return 0;
7656}
7657
7658/**
7659 * Callee expects const RIL_ECallReqMsg *
7660 * Payload is:
7661 * RIL_ECall_Category ecall_cat
7662 * RIL_ECall_Variant ecall_variant
7663 * String address
7664 * String msd_data
7665 */
7666static void dispatchFastEcall (Parcel &p, RequestInfo *pRI) {
7667 RIL_ECallReqMsg eCallReqMsg;
7668
xja1c30b82022-01-25 16:13:48 +08007669 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08007670 int size;
7671 status_t status;
7672 int digitCount;
7673 int digitLimit;
7674 uint8_t uct;
7675
7676 memset(&eCallReqMsg, 0, sizeof(eCallReqMsg));
7677
7678 status = p.readInt32(&t);
7679 eCallReqMsg.ecall_cat= (RIL_ECall_Category)t;
7680
7681 status = p.readInt32(&t);
7682 eCallReqMsg.ecall_variant = (RIL_ECall_Variant)t;
7683
7684 eCallReqMsg.address = strdupReadString(p);
7685
7686 status = p.readInt32(&t);
7687 eCallReqMsg.length = (uint8_t) t;
7688
7689 digitLimit= MIN((eCallReqMsg.length), MSD_MAX_LENGTH);
7690 eCallReqMsg.msd_data = (unsigned char *)alloca(digitLimit);
7691
7692 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
7693 status = p.read(&uct, sizeof(uint8_t));
7694 eCallReqMsg.msd_data[digitCount] = (uint8_t) uct;
7695 }
7696
7697 startRequest;
7698 appendPrintBuf("%secall_cat=%d,ecall_variant=%d, address=%s", printBuf,
7699 eCallReqMsg.ecall_cat, eCallReqMsg.ecall_variant, (char*)eCallReqMsg.address);
7700 closeRequest;
7701 printRequest(pRI->token, pRI->pCI->requestNumber);
7702
7703 if (status != NO_ERROR) {
7704 goto invalid;
7705 }
7706
7707 size = sizeof(eCallReqMsg);
7708 CALL_ONREQUEST(pRI->pCI->requestNumber, &eCallReqMsg, size, pRI, pRI->socket_id);
7709
7710#ifdef MEMSET_FREED
7711 memsetString(eCallReqMsg.address);
lhb07f4e12022-02-17 22:08:54 -08007712 memset(eCallReqMsg.msd_data, 0, digitLimit);
lh7b0674a2022-01-10 00:34:35 -08007713#endif
7714
7715 free(eCallReqMsg.address);
7716
7717#ifdef MEMSET_FREED
7718 memset(&eCallReqMsg, 0, sizeof(eCallReqMsg));
7719#endif
7720
7721 return;
7722invalid:
7723 invalidCommandBlock(pRI);
7724 return;
7725}
7726
7727/**
7728 * Callee expects const RIL_ECallSetMSD *
7729 * Payload is:
7730 * int call_id
7731 * String msd_data
7732 */
7733static void dispatchSetMsd (Parcel &p, RequestInfo *pRI) {
7734 RIL_ECallSetMSD eCallSetMsd;
7735
xja1c30b82022-01-25 16:13:48 +08007736 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08007737 int size;
7738 status_t status;
7739 int digitCount;
7740 int digitLimit;
7741 uint8_t uct;
7742
7743 memset(&eCallSetMsd, 0, sizeof(eCallSetMsd));
7744
7745 status = p.readInt32(&t);
7746 eCallSetMsd.call_id = (int)t;
7747
7748 status = p.readInt32(&t);
7749 eCallSetMsd.length = (uint8_t) t;
7750
7751 digitLimit= MIN((eCallSetMsd.length), MSD_MAX_LENGTH);
7752 eCallSetMsd.msd_data = (unsigned char *)alloca(digitLimit);
7753
7754 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
7755 status = p.read(&uct, sizeof(uint8_t));
7756 eCallSetMsd.msd_data[digitCount] = (uint8_t) uct;
7757 }
7758
7759 startRequest;
7760 appendPrintBuf("%scall_id=%d,msd_data=%s", printBuf, eCallSetMsd.call_id, (char*)eCallSetMsd.msd_data);
7761 closeRequest;
7762 printRequest(pRI->token, pRI->pCI->requestNumber);
7763
7764 if (status != NO_ERROR) {
7765 goto invalid;
7766 }
7767
7768 size = sizeof(eCallSetMsd);
7769 CALL_ONREQUEST(pRI->pCI->requestNumber, &eCallSetMsd, size, pRI, pRI->socket_id);
7770
7771#ifdef MEMSET_FREED
7772 memset(eCallSetMsd.msd_data, 0, eCallSetMsd.length);
7773#endif
7774
7775#ifdef MEMSET_FREED
7776 memset(&eCallSetMsd, 0, sizeof(eCallSetMsd));
7777#endif
7778
7779 return;
7780invalid:
7781 invalidCommandBlock(pRI);
7782 return;
7783}
7784
7785/**
7786 * Callee expects const RIL_ECallSetNum *
7787 * Payload is:
7788 * int arg_num;
7789 * int type
7790 * char* address
7791 */
7792static void dispatchEcallRecord (Parcel &p, RequestInfo *pRI) {
7793 RIL_ECallSetNum args;
xja1c30b82022-01-25 16:13:48 +08007794 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08007795 status_t status;
7796
7797 RLOGD("dispatchSmsWrite");
7798 memset (&args, 0, sizeof(args));
7799
7800 status = p.readInt32(&t);
7801 args.arg_num = (int)t;
7802
7803 status = p.readInt32(&t);
7804 args.type = (int)t;
7805
7806 args.address = strdupReadString(p);
7807
7808 if (status != NO_ERROR || args.address == NULL) {
7809 goto invalid;
7810 }
7811
7812 startRequest;
7813 appendPrintBuf("%s%d,%s,%d", printBuf, args.type, args.address,args.arg_num);
7814 closeRequest;
7815 printRequest(pRI->token, pRI->pCI->requestNumber);
7816
7817 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
7818
7819#ifdef MEMSET_FREED
7820 memsetString (args.address);
7821#endif
7822
7823 free (args.address);
7824#ifdef MEMSET_FREED
7825 memset(&args, 0, sizeof(args));
7826#endif
7827 return;
7828invalid:
7829 invalidCommandBlock(pRI);
7830 return;
7831}
7832#endif /*ECALL_SUPPORT*/
7833
7834#ifdef KEEP_ALIVE
7835static void dispatchStartKeepalivePro(Parcel &p, RequestInfo *pRI){
7836 RIL_RequestKeepalive_Pro kp;
xja1c30b82022-01-25 16:13:48 +08007837 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08007838 status_t status;
7839 std::vector<uint8_t> sadr;
7840 std::vector<uint8_t> dadr;
7841
7842 memset (&kp, 0, sizeof(RIL_RequestKeepalive_Pro));
7843
7844 status = p.readInt32(&t);
7845 kp.type = (RIL_PacketType)t;
7846 if (status != NO_ERROR) {
7847 goto invalid;
7848 }
7849
7850
7851 status = p.readByteVector(&sadr);
7852 if (status != NO_ERROR) {
7853 goto invalid;
7854 } else {
7855 for(int i = 0; i < sadr.size(); i++) {
7856 kp.sourceAddress[i] = sadr[i];
7857 }
7858 }
7859
7860 status = p.readInt32(&t);
7861 kp.sourcePort= (int)t;
7862 if (status != NO_ERROR) {
7863 goto invalid;
7864 }
7865
7866 status = p.readByteVector(&dadr);
7867 if (status != NO_ERROR) {
7868 goto invalid;
7869 } else {
7870 for(int i = 0; i < dadr.size(); i++) {
7871 kp.destinationAddress[i] = dadr[i];
7872 }
7873 }
7874
7875 status = p.readInt32(&t);
7876 kp.destinationPort= (int)t;
7877 if (status != NO_ERROR) {
7878 goto invalid;
7879 }
7880
7881 status = p.readInt32(&t);
7882 kp.netif_id = (int)t;
7883 if (status != NO_ERROR) {
7884 goto invalid;
7885 }
7886
7887 status = p.readInt32(&t);
7888 kp.keepIdleTime = (int)t;
7889 if (status != NO_ERROR) {
7890 goto invalid;
7891 }
7892
7893 status = p.readInt32(&t);
7894 kp.keepIntervalTime = (int)t;
7895 if (status != NO_ERROR) {
7896 goto invalid;
7897 }
7898
7899 status = p.readInt32(&t);
7900 kp.retryCount = (int)t;
7901 if (status != NO_ERROR) {
7902 goto invalid;
7903 }
7904 startRequest;
7905 appendPrintBuf("%s [type:%d, sourceAddress:",printBuf, kp.type);
7906
7907 for(auto v: sadr) {
7908 appendPrintBuf("%s %d",printBuf,v);
7909 }
7910 appendPrintBuf("%s, sourcePort:%d, destinationAddress:",printBuf, kp.sourcePort);
7911
7912 for(auto v: dadr) {
7913 appendPrintBuf("%s %d",printBuf,v);
7914 }
7915 appendPrintBuf("%s, destinationPort:%d, netif_id:%d, keepIdleTime:%d,, keepIntervalTime:%d, retryCount:%d",
7916 printBuf, kp.destinationPort, kp.netif_id, kp.keepIdleTime, kp.keepIntervalTime, kp.retryCount);
7917
7918 closeRequest;
7919 printRequest(pRI->token, pRI->pCI->requestNumber);
7920
7921 CALL_ONREQUEST(pRI->pCI->requestNumber,&kp,sizeof(RIL_RequestKeepalive_Pro),pRI, pRI->socket_id);
7922 return;
7923invalid:
7924 invalidCommandBlock(pRI);
7925 return;
7926}
7927#endif /* KEEP_ALIVE*/
7928} /* namespace android */
7929
7930#if 0
7931void rilEventAddWakeup_helper(struct ril_event *ev) {
7932 android::rilEventAddWakeup(ev);
7933}
7934
7935void listenCallback_helper(int fd, short flags, void *param) {
7936 android::listenCallback(fd, flags, param);
7937}
7938
7939int blockingWrite_helper(int fd, void *buffer, size_t len) {
7940 return android::blockingWrite(fd, buffer, len);
7941}
7942#endif