blob: 268c8520610b2be23b053970de4e7dba6e7658fb [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>
29#include <cutils/jstring.h>
30#include <telephony/record_stream.h>
31#include <utils/SystemClock.h>
32#include <pthread.h>
33#include <binder/Parcel.h>
34#include <cutils/jstring.h>
35#include <sys/types.h>
36#include <limits.h>
37#include <pwd.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <stdarg.h>
41#include <string.h>
42#include <unistd.h>
43#include <fcntl.h>
44#include <time.h>
45#include <errno.h>
46#include <assert.h>
47#include <ctype.h>
48#include <alloca.h>
49#include <sys/un.h>
50#include <assert.h>
51#include <netinet/in.h>
52#include <atomic>
53
54#include "utils/String8.h"
55#include "ss.h"
56#include "sim.h"
57#include "common.h"
58#include "cc.h"
59#include "network.h"
60#include "stk.h"
61#include "utils.h"
62
63#include "atci/ATCI.h"
64#include "data/data.h"
65#include "data/data_gdbus.h"
66#include "ecall/eCall.h"
67#include "em/em.h"
68#include "sms/sms.h"
69#include "sms/cdma/sms_pdu_cdma.h"
70#include "stateManager/stateManager.h"
71#include "Phone_utils.h"
72#include "utils.h"
73#include "Radio_capability_switch_util.h"
74/*Warren add for t800 RIL service 2021_12_10 start*/
75#include <sys/epoll.h>
76#include "lynq_interface.h"
lhf6eea122022-01-20 19:32:14 -080077#include "lynq_common.h"
78#include "lynq_sms_manager.h"
lh7b0674a2022-01-10 00:34:35 -080079/*Warren add for t800 RIL service 2021_12_10 end*/
80
81#define LOG_TAG "DEMO_RIL"
xja1c30b82022-01-25 16:13:48 +080082#define WAIT_TIME_FOR_SIM_SWITCH 30
lh7b0674a2022-01-10 00:34:35 -080083
84extern void ARspRequest (int request, RIL_SOCKET_ID socket_id);
85extern void responseDispatch();
86
87namespace android {
88extern "C" void
89RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
90
91#define SERVER_PORT 8000
92#define BUFFER_SIZE 8192
93#define MAX_ARGS 101
94#define BLOCK_LOCK() pthread_mutex_lock(&s_BlockMutex)
95#define BLOCK_UNLOCK() pthread_mutex_unlock(&s_BlockMutex)
96#define BLOCK_WAIT(a) pthread_cond_timedwait(&s_BlockCond, &s_BlockMutex,(a))
97#define BLOCK_WAKEUP() pthread_cond_broadcast(&s_BlockCond)
98#define SPECIA_BLOCK_LOCK() pthread_mutex_lock(&s_SpecialBlock)
99#define SPECIA_BLOCK_UNLOCK() pthread_mutex_unlock(&s_SpecialBlock)
100#define SPECIA_BLOCK_WAIT(a) pthread_cond_timedwait(&s_SpeciaBlockCond, &s_SpecialBlock,(a))
101#define SPECIA_BLOCK_WAKEUP() pthread_cond_signal(&s_SpeciaBlockCond)
102
103static int s_started = 0;
104static int s_responseDispatch = 0;
105static int s_isConnected[2] = {0,0}; //connect to modem;
106static pthread_mutex_t s_InitMutex = PTHREAD_MUTEX_INITIALIZER;
107static pthread_cond_t s_InitCond = PTHREAD_COND_INITIALIZER;
108
109static pthread_mutex_t s_BlockMutex = PTHREAD_MUTEX_INITIALIZER;
110static pthread_cond_t s_BlockCond = PTHREAD_COND_INITIALIZER;
111static pthread_mutex_t s_SpecialBlock = PTHREAD_MUTEX_INITIALIZER;
112static pthread_cond_t s_SpeciaBlockCond = PTHREAD_COND_INITIALIZER;
113
114int requestOneByOne = 0;
115int server_socket_fd;
116int enable_syslog = 1;
117int enable_bt_resp = 0;
118int wakeup_token = -1;
119struct sockaddr_in client_addr;
120
121#define ANDROID_WAKE_LOCK_NAME "radio-interface"
122
123// Basically: memset buffers that the client library
124// shouldn't be using anymore in an attempt to find
125// memory usage issues sooner.
126#define MEMSET_FREED 1
127
128#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
129
130#define MIN(a,b) ((a)<(b) ? (a) : (b))
131
132/* Constants for response types */
133#define RESPONSE_SOLICITED 0
134#define RESPONSE_UNSOLICITED 1
135
136/* Negative values for private RIL errno's */
137#define RIL_ERRNO_INVALID_RESPONSE -1
138
139// request, response, and unsolicited msg print macro
140#define PRINTBUF_SIZE 8096
141
142// Enable verbose logging
143#define VDBG 0
144
145// Enable RILC log
146#define RILC_LOG 1
147/*Warren add for t800 RIL service 2021_12_10 start*/
148#define LYNQ_SOCKET_ENVNT_FD_MAX 100
149#define LYNQ_SERVICE_PORT 8088
150#define LYNQ_BRODCAST_PORT 8086
151#define LYNQ_SOCKET_BUFFER (1024*8+sizeof(int)*3+10)
152//int LYNQ_RIL_respSocket(Parcel &p,RIL_Token t);
153//int LYNQ_RIL_urcBroadcast(Parcel &p);
154
155int lynq_urc_socket_fd = 0;
156struct sockaddr_in urc_broadcast_addr;
157/*Warren add for t800 RIL service 2021_12_10 end*/
158
159
160#if RILC_LOG
161 static char printBuf[PRINTBUF_SIZE];
162 static char tempPrintBuf[PRINTBUF_SIZE];
163 #define startRequest sprintf(printBuf, "(")
164 #define closeRequest sprintf(printBuf, "%s)", printBuf)
165 #define printRequest(token, req) if(enable_syslog) { \
166 RLOGD("[%x]> %s %s", token, requestToString(req), printBuf);} else {\
167 printf("[%x]> %s %s\n", token, requestToString(req), printBuf);}
168
169 #define startResponse sprintf(printBuf, "%s {", printBuf)
170 #define closeResponse sprintf(printBuf, "%s}", printBuf)
171 #define printResponse if(enable_syslog) { \
172 RLOGD("%s", printBuf); } else { \
173 printf("%s\n", printBuf);}
174
175 #define clearPrintBuf printBuf[0] = 0
176 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
177 #define appendPrintBuf(x...) snprintf(tempPrintBuf, PRINTBUF_SIZE, x); \
178 snprintf(printBuf, PRINTBUF_SIZE, "%s", tempPrintBuf)
179#endif
180
181enum WakeType {DONT_WAKE, WAKE_PARTIAL};
182
183#if 0
184typedef struct {
185 int requestNumber;
186 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
187 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
188} CommandInfo;
189#endif
190
191typedef struct {
192 int requestNumber;
193 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
194 WakeType wakeType;
195} UnsolResponseInfo;
196
197#if 0
198typedef struct RequestInfo {
199 int32_t token; //this is not RIL_Token
200 CommandInfo *pCI;
201 struct RequestInfo *p_next;
202 char cancelled;
203 char local; // responses to local commands do not go back to command process
204 RIL_SOCKET_ID socket_id;
205} RequestInfo;
206
207typedef struct UserCallbackInfo {
208 RIL_TimedCallback p_callback;
209 void *userParam;
210 struct ril_event event;
211 struct UserCallbackInfo *p_next;
212} UserCallbackInfo;
213#endif
214
215const char *requestToString(int request);
216const char * failCauseToString(RIL_Errno);
217const char * callStateToString(RIL_CallState);
218
219RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
220int s_registerCalled = 0;
221
222static pthread_t s_tid_dispatch;
223
224static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
225
226#if EM_MODE_SUPPORT
227netwokInfoNotify networkCb = NULL;
228atCmdResponse atResponseCb = NULL;
229#endif
230
231static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
232static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
233static void *s_lastNITZTimeData = NULL;
234static size_t s_lastNITZTimeDataSize;
235
236/*******************************************************************/
237static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
238
239static void dispatchVoid (Parcel& p, RequestInfo *pRI);
240static void dispatchString (Parcel& p, RequestInfo *pRI);
241static void dispatchStrings (Parcel& p, RequestInfo *pRI);
242static void dispatchInts (Parcel& p, RequestInfo *pRI);
243static void dispatchDial (Parcel& p, RequestInfo *pRI);
244static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
245static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
246static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
247static void dispatchRaw(Parcel& p, RequestInfo *pRI);
248static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
249static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
250static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);;
251static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
252static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
253static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
254static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
255static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
256static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
257static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
258static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
259static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
260static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
261static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
262static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
263static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
264static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
265static int responseInts(Parcel &p, void *response, size_t responselen);
266static int responseFailCause(Parcel &p, void *response, size_t responselen);
267static int responseStrings(Parcel &p, void *response, size_t responselen);
268static int responseString(Parcel &p, void *response, size_t responselen);
269static int responseVoid(Parcel &p, void *response, size_t responselen);
270static int responseCallList(Parcel &p, void *response, size_t responselen);
271static int responseSMS(Parcel &p, void *response, size_t responselen);
272static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
273static int responseCallForwards(Parcel &p, void *response, size_t responselen);
274static int responseDataCallList(Parcel &p, void *response, size_t responselen);
275static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
276static int responseRaw(Parcel &p, void *response, size_t responselen);
277static int responseSsn(Parcel &p, void *response, size_t responselen);
278static int responseSimStatus(Parcel &p, void *response, size_t responselen);
279static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
280static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
281static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
282static int responseCellList(Parcel &p, void *response, size_t responselen);
283static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
284static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
285static int responseCallRing(Parcel &p, void *response, size_t responselen);
286static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
287static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
288static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
289static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
290static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
291static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
292static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
293static int responseSSData(Parcel &p, void *response, size_t responselen);
294static int responseLceStatus(Parcel &p, void *response, size_t responselen);
295static int responseLceData(Parcel &p, void *response, size_t responselen);
296static int responseActivityData(Parcel &p, void *response, size_t responselen);
297static int responseSmsSimMemStatus(Parcel &p, void *response, size_t responselen);
298#ifdef ECALL_SUPPORT
299static void dispatchFastEcall (Parcel& p, RequestInfo *pRI);
300static int responseEcallStatus(Parcel &p, void *response, size_t responselen);
301static void dispatchSetMsd (Parcel &p, RequestInfo *pRI);
302static void dispatchEcallRecord (Parcel &p, RequestInfo *pRI);
303#endif /*ECALL_SUPPORT*/
304#ifdef KEEP_ALIVE
305static void dispatchStartKeepalivePro(Parcel &p, RequestInfo *pRI);
306#endif /*KEEP_ALIVE*/
307static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
308static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
309static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
310
311static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
312
313static int onSupports (int requestCode);
314static UnsolResponseInfo* find_mtk_unsol_command(int request);
315static int com_quit(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
316static int enableSyslog(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
317static int enableBTResponse(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
318static void updateIccCardState(RIL_SOCKET_ID soc_id);
319static void initCoditions();
320
321static int SendRespToClient(const void *data, size_t dataSize);
322static void speciaRequest_wakeup();
323static void speciaRequest_wait();
324void processUnsolicited (Parcel &p, int type);
325void processSolicited (Parcel &p, int type);
326
327void printInputArgs(int argc, char** argv) ;
328void initRequestInfo(RequestInfo *pRI, int request, int mode, RIL_SOCKET_ID soc_id);
329void getVoiceAndDataRegistrationState(RIL_SOCKET_ID soc_id);
330const int waitResponse(int token);
331
332#ifdef RIL_SHLIB
333#if defined(ANDROID_MULTI_SIM)
334extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
335 size_t datalen, RIL_SOCKET_ID socket_id);
336#else
337extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
338 size_t datalen);
339#endif
340#endif
341
342#if defined(ANDROID_MULTI_SIM)
343#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
344#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
345#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
346#else
347#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
348#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
349#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
350#endif
351
352
353/** Index == requestNumber */
354static CommandInfo s_commands[] = {
355#include "ril_commands.h"
356};
357
358static UnsolResponseInfo s_unsolResponses[] = {
359#include "ril_unsol_commands.h"
360};
361
362COMMAND commands[] = {
363#include "commands.h"
364};
365
366static CommandInfo mtk_s_command[] = {
367#include "mtk_ril_commands.h"
368};
369
370static UnsolResponseInfo s_mtk_unsolResponses[] = {
371#include "mtk_ril_unsol_commands.h"
372};
373
374char respStr[PRINTBUF_SIZE]={0};
375
376/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
377 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
378 radio state message and store it. Every time there is a change in Radio State
379 check to see if voice radio tech changes and notify telephony
380 */
381int voiceRadioTech = -1;
382
383/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
384 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
385 source from radio state and store it. Every time there is a change in Radio State
386 check to see if subscription source changed and notify telephony
387 */
388int cdmaSubscriptionSource = -1;
389
390/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
391 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
392 check to see if SIM/RUIM status changed and notify telephony
393 */
394int simRuimStatus = -1;
395
396
397static char *
398strdupReadString(Parcel &p) {
399 size_t stringlen;
400 const char16_t *s16;
401
402 s16 = p.readString16Inplace(&stringlen);
403
404 return strndup16to8(s16, stringlen);
405}
406
407static status_t
408readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
409 size_t s16Len;
410 const char16_t *s16;
411
412 s16 = p.readString16Inplace(&s16Len);
413 if (s16 == NULL) {
414 return NO_MEMORY;
415 }
416 size_t strLen = strnlen16to8(s16, s16Len);
417 if ((strLen + 1) > maxLen) {
418 return NO_MEMORY;
419 }
420 if (strncpy16to8(str, s16, strLen) == NULL) {
421 return NO_MEMORY;
422 } else {
423 return NO_ERROR;
424 }
425}
426
427/*static*/ void writeStringToParcel(Parcel &p, const char *s) {
428 char16_t *s16;
429 size_t s16_len;
430 s16 = strdup8to16(s, &s16_len);
431 p.writeString16(s16, s16_len);
432 free(s16);
433}
434
435
436static void
437memsetString (char *s) {
438 if (s != NULL) {
439 memset (s, 0, strlen(s));
440 }
441}
442
443
444static void
445invalidCommandBlock (RequestInfo *pRI) {
446 RLOGE("invalid command block for token %d request %s",
447 pRI->token, requestToString(pRI->pCI->requestNumber));
448}
449
450/** Callee expects NULL */
451static void
452dispatchVoid (Parcel& p, RequestInfo *pRI) {
453 clearPrintBuf;
454 printRequest(pRI->token, pRI->pCI->requestNumber);
455 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
456}
457
458/** Callee expects const char * */
459static void
460dispatchString (Parcel& p, RequestInfo *pRI) {
461 status_t status;
462 size_t datalen;
463 size_t stringlen;
464 char *string8 = NULL;
465
466 string8 = strdupReadString(p);
467
468 startRequest;
469 appendPrintBuf("%s%s", printBuf, string8);
470 closeRequest;
471 printRequest(pRI->token, pRI->pCI->requestNumber);
472
473 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
474 sizeof(char *), pRI, pRI->socket_id);
475
476#ifdef MEMSET_FREED
477 memsetString(string8);
478#endif
479
480 free(string8);
481 return;
482invalid:
483 invalidCommandBlock(pRI);
484 return;
485}
486
487/** Callee expects const char ** */
488static void
489dispatchStrings (Parcel &p, RequestInfo *pRI) {
490 int32_t countStrings;
491 status_t status;
492 size_t datalen;
493 char **pStrings;
494
495 status = p.readInt32 (&countStrings);
496
497 if (status != NO_ERROR) {
498 goto invalid;
499 }
500
501 startRequest;
502 if (countStrings == 0) {
503 // just some non-null pointer
504 pStrings = (char **)alloca(sizeof(char *));
505 datalen = 0;
506 } else if (((int)countStrings) == -1) {
507 pStrings = NULL;
508 datalen = 0;
509 } else {
510 datalen = sizeof(char *) * countStrings;
511
512 pStrings = (char **)alloca(datalen);
513
514 for (int i = 0 ; i < countStrings ; i++) {
515 pStrings[i] = strdupReadString(p);
516 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
517 }
518 }
519 removeLastChar;
520 closeRequest;
521 printRequest(pRI->token, pRI->pCI->requestNumber);
522
523 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
524
525 if (pStrings != NULL) {
526 for (int i = 0 ; i < countStrings ; i++) {
527#ifdef MEMSET_FREED
528 memsetString (pStrings[i]);
529#endif
530 free(pStrings[i]);
531 }
532
533#ifdef MEMSET_FREED
534 memset(pStrings, 0, datalen);
535#endif
536 }
537
538 return;
539invalid:
540 invalidCommandBlock(pRI);
541 return;
542}
543
544/** Callee expects const int * */
545static void
546dispatchInts (Parcel &p, RequestInfo *pRI) {
547 int32_t count;
548 status_t status;
549 size_t datalen;
550 int *pInts;
551
552 status = p.readInt32 (&count);
553
554 if (status != NO_ERROR || count == 0) {
555 goto invalid;
556 }
557
558 datalen = sizeof(int) * count;
559 pInts = (int *)alloca(datalen);
560
561 startRequest;
562 for (int i = 0 ; i < count ; i++) {
xja1c30b82022-01-25 16:13:48 +0800563 int32_t t = 0;
lh7b0674a2022-01-10 00:34:35 -0800564
565 status = p.readInt32(&t);
566 pInts[i] = (int)t;
567 appendPrintBuf("%s%d,", printBuf, t);
568
569 if (status != NO_ERROR) {
570 goto invalid;
571 }
572 }
573 removeLastChar;
574 closeRequest;
575 printRequest(pRI->token, pRI->pCI->requestNumber);
576
577 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
578 datalen, pRI, pRI->socket_id);
579
580#ifdef MEMSET_FREED
581 memset(pInts, 0, datalen);
582#endif
583
584 return;
585invalid:
586 invalidCommandBlock(pRI);
587 return;
588}
589
590
591/**
592 * Callee expects const RIL_SMS_WriteArgs *
593 * Payload is:
594 * int32_t status
595 * String pdu
596 */
597static void
598dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
599 RIL_SMS_WriteArgs args;
xja1c30b82022-01-25 16:13:48 +0800600 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800601 status_t status;
602
603 RLOGD("dispatchSmsWrite");
604 memset (&args, 0, sizeof(args));
605
606 status = p.readInt32(&t);
607 args.status = (int)t;
608
609 args.pdu = strdupReadString(p);
610
611 if (status != NO_ERROR || args.pdu == NULL) {
612 goto invalid;
613 }
614
615 args.smsc = strdupReadString(p);
616
617 startRequest;
618 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
619 (char*)args.pdu, (char*)args.smsc);
620 closeRequest;
621 printRequest(pRI->token, pRI->pCI->requestNumber);
622
623 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
624
625#ifdef MEMSET_FREED
626 memsetString (args.pdu);
627#endif
628
629 free (args.pdu);
630 free (args.smsc);
631#ifdef MEMSET_FREED
632 memset(&args, 0, sizeof(args));
633#endif
634
635 return;
636invalid:
637 invalidCommandBlock(pRI);
638 return;
639}
640
641/**
642 * Callee expects const RIL_Dial *
643 * Payload is:
644 * String address
645 * int32_t clir
646 */
647static void
648dispatchDial (Parcel &p, RequestInfo *pRI) {
649 RIL_Dial dial;
650 RIL_UUS_Info uusInfo;
651 int32_t sizeOfDial;
xja1c30b82022-01-25 16:13:48 +0800652 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800653 int32_t uusPresent;
654 status_t status;
655
656 RLOGD("dispatchDial");
657 memset (&dial, 0, sizeof(dial));
658
659 dial.address = strdupReadString(p);
660
661 status = p.readInt32(&t);
662 dial.clir = (int)t;
663
664 if (status != NO_ERROR || dial.address == NULL) {
665 goto invalid;
666 }
667
668 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
669 uusPresent = 0;
670 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
671 } else {
672 status = p.readInt32(&uusPresent);
673
674 if (status != NO_ERROR) {
675 goto invalid;
676 }
677
678 if (uusPresent == 0) {
679 dial.uusInfo = NULL;
680 } else {
681 int32_t len;
682
683 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
684
685 status = p.readInt32(&t);
686 uusInfo.uusType = (RIL_UUS_Type) t;
687
688 status = p.readInt32(&t);
689 uusInfo.uusDcs = (RIL_UUS_DCS) t;
690
691 status = p.readInt32(&len);
692 if (status != NO_ERROR) {
693 goto invalid;
694 }
695
696 // The java code writes -1 for null arrays
697 if (((int) len) == -1) {
698 uusInfo.uusData = NULL;
699 len = 0;
700 } else {
701 uusInfo.uusData = (char*) p.readInplace(len);
702 }
703
704 uusInfo.uusLength = len;
705 dial.uusInfo = &uusInfo;
706 }
707 sizeOfDial = sizeof(dial);
708 }
709
710 startRequest;
711 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
712 if (uusPresent) {
713 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
714 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
715 dial.uusInfo->uusLength);
716 }
717
718 closeRequest;
719 printRequest(pRI->token, pRI->pCI->requestNumber);
720
721 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
722
723#ifdef MEMSET_FREED
724 memsetString (dial.address);
725#endif
726
727 free (dial.address);
728
729#ifdef MEMSET_FREED
730 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
731 memset(&dial, 0, sizeof(dial));
732#endif
733
734 return;
735invalid:
736 invalidCommandBlock(pRI);
737 return;
738}
739
740/**
741 * Callee expects const RIL_SIM_IO *
742 * Payload is:
743 * int32_t command
744 * int32_t fileid
745 * String path
746 * int32_t p1, p2, p3
747 * String data
748 * String pin2
749 * String aidPtr
750 */
751static void
752dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
753 union RIL_SIM_IO {
754 RIL_SIM_IO_v6 v6;
755 RIL_SIM_IO_v5 v5;
756 } simIO;
757
xja1c30b82022-01-25 16:13:48 +0800758 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800759 int size;
760 status_t status;
761
762#if VDBG
763 RLOGD("dispatchSIM_IO");
764#endif
765 memset (&simIO, 0, sizeof(simIO));
766
767 // note we only check status at the end
768
769 status = p.readInt32(&t);
770 simIO.v6.command = (int)t;
771
772 status = p.readInt32(&t);
773 simIO.v6.fileid = (int)t;
774
775 simIO.v6.path = strdupReadString(p);
776
777 status = p.readInt32(&t);
778 simIO.v6.p1 = (int)t;
779
780 status = p.readInt32(&t);
781 simIO.v6.p2 = (int)t;
782
783 status = p.readInt32(&t);
784 simIO.v6.p3 = (int)t;
785
786 simIO.v6.data = strdupReadString(p);
787 simIO.v6.pin2 = strdupReadString(p);
788 simIO.v6.aidPtr = strdupReadString(p);
789
790 startRequest;
791 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
792 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
793 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
794 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
795 closeRequest;
796 printRequest(pRI->token, pRI->pCI->requestNumber);
797
798 if (status != NO_ERROR) {
799 goto invalid;
800 }
801
802 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
803 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
804
805#ifdef MEMSET_FREED
806 memsetString (simIO.v6.path);
807 memsetString (simIO.v6.data);
808 memsetString (simIO.v6.pin2);
809 memsetString (simIO.v6.aidPtr);
810#endif
811
812 free (simIO.v6.path);
813 free (simIO.v6.data);
814 free (simIO.v6.pin2);
815 free (simIO.v6.aidPtr);
816
817#ifdef MEMSET_FREED
818 memset(&simIO, 0, sizeof(simIO));
819#endif
820
821 return;
822invalid:
823 invalidCommandBlock(pRI);
824 return;
825}
826
827/**
828 * Callee expects const RIL_SIM_APDU *
829 * Payload is:
830 * int32_t sessionid
831 * int32_t cla
832 * int32_t instruction
833 * int32_t p1, p2, p3
834 * String data
835 */
836static void
837dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
xja1c30b82022-01-25 16:13:48 +0800838 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800839 status_t status;
840 RIL_SIM_APDU apdu;
841
842#if VDBG
843 RLOGD("dispatchSIM_APDU");
844#endif
845 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
846
847 // Note we only check status at the end. Any single failure leads to
848 // subsequent reads filing.
849 status = p.readInt32(&t);
850 apdu.sessionid = (int)t;
851
852 status = p.readInt32(&t);
853 apdu.cla = (int)t;
854
855 status = p.readInt32(&t);
856 apdu.instruction = (int)t;
857
858 status = p.readInt32(&t);
859 apdu.p1 = (int)t;
860
861 status = p.readInt32(&t);
862 apdu.p2 = (int)t;
863
864 status = p.readInt32(&t);
865 apdu.p3 = (int)t;
866
867 apdu.data = strdupReadString(p);
868
869 startRequest;
870 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
871 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
872 apdu.p3, (char*)apdu.data);
873 closeRequest;
874 printRequest(pRI->token, pRI->pCI->requestNumber);
875
876 if (status != NO_ERROR) {
877 goto invalid;
878 }
879
880 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
881
882#ifdef MEMSET_FREED
883 memsetString(apdu.data);
884#endif
885 free(apdu.data);
886
887#ifdef MEMSET_FREED
888 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
889#endif
890
891 return;
892invalid:
893 invalidCommandBlock(pRI);
894 return;
895}
896
897
898/**
899 * Callee expects const RIL_CallForwardInfo *
900 * Payload is:
901 * int32_t status/action
902 * int32_t reason
903 * int32_t serviceCode
904 * int32_t toa
905 * String number (0 length -> null)
906 * int32_t timeSeconds
907 */
908static void
909dispatchCallForward(Parcel &p, RequestInfo *pRI) {
910 RIL_CallForwardInfo cff;
xja1c30b82022-01-25 16:13:48 +0800911 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -0800912 status_t status;
913
914 RLOGD("dispatchCallForward");
915 memset (&cff, 0, sizeof(cff));
916
917 // note we only check status at the end
918
919 status = p.readInt32(&t);
920 cff.status = (int)t;
921
922 status = p.readInt32(&t);
923 cff.reason = (int)t;
924
925 status = p.readInt32(&t);
926 cff.serviceClass = (int)t;
927
928 status = p.readInt32(&t);
929 cff.toa = (int)t;
930
931 cff.number = strdupReadString(p);
932
933 status = p.readInt32(&t);
934 cff.timeSeconds = (int)t;
935
936 if (status != NO_ERROR) {
937 goto invalid;
938 }
939
940 // special case: number 0-length fields is null
941
942 if (cff.number != NULL && strlen (cff.number) == 0) {
943 cff.number = NULL;
944 }
945
946 startRequest;
947 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
948 cff.status, cff.reason, cff.serviceClass, cff.toa,
949 (char*)cff.number, cff.timeSeconds);
950 closeRequest;
951 printRequest(pRI->token, pRI->pCI->requestNumber);
952
953 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
954
955#ifdef MEMSET_FREED
956 memsetString(cff.number);
957#endif
958
959 free (cff.number);
960
961#ifdef MEMSET_FREED
962 memset(&cff, 0, sizeof(cff));
963#endif
964
965 return;
966invalid:
967 invalidCommandBlock(pRI);
968 return;
969}
970
971
972static void
973dispatchRaw(Parcel &p, RequestInfo *pRI) {
974 int32_t len;
975 status_t status;
976 const void *data;
977
978 status = p.readInt32(&len);
979
980 if (status != NO_ERROR) {
981 goto invalid;
982 }
983
984 // The java code writes -1 for null arrays
985 if (((int)len) == -1) {
986 data = NULL;
987 len = 0;
988 }
989
990 data = p.readInplace(len);
991
992 startRequest;
993 appendPrintBuf("%sraw_size=%d", printBuf, len);
994 closeRequest;
995 printRequest(pRI->token, pRI->pCI->requestNumber);
996
997 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
998
999 return;
1000invalid:
1001 invalidCommandBlock(pRI);
1002 return;
1003}
1004
1005static status_t
1006constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
xja1c30b82022-01-25 16:13:48 +08001007 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001008 uint8_t ut;
1009 status_t status;
1010 int32_t digitCount;
1011 int digitLimit;
1012
1013 memset(&rcsm, 0, sizeof(rcsm));
1014
1015 status = p.readInt32(&t);
1016 rcsm.uTeleserviceID = (int) t;
1017
1018 status = p.read(&ut,sizeof(ut));
1019 rcsm.bIsServicePresent = (uint8_t) ut;
1020
1021 status = p.readInt32(&t);
1022 rcsm.uServicecategory = (int) t;
1023
1024 status = p.readInt32(&t);
1025 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1026
1027 status = p.readInt32(&t);
1028 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1029
1030 status = p.readInt32(&t);
1031 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1032
1033 status = p.readInt32(&t);
1034 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1035
1036 status = p.read(&ut,sizeof(ut));
1037 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1038
1039 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1040 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1041 status = p.read(&ut,sizeof(ut));
1042 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1043 }
1044
1045 status = p.readInt32(&t);
1046 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1047
1048 status = p.read(&ut,sizeof(ut));
1049 rcsm.sSubAddress.odd = (uint8_t) ut;
1050
1051 status = p.read(&ut,sizeof(ut));
1052 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1053
1054 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1055 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1056 status = p.read(&ut,sizeof(ut));
1057 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1058 }
1059
1060 status = p.readInt32(&t);
1061 rcsm.uBearerDataLen = (int) t;
1062
1063 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1064 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1065 status = p.read(&ut, sizeof(ut));
1066 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1067 }
1068
1069 if (status != NO_ERROR) {
1070 return status;
1071 }
1072
1073 startRequest;
1074 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1075 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1076 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1077 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1078 closeRequest;
1079
1080 printRequest(pRI->token, pRI->pCI->requestNumber);
1081
1082 return status;
1083}
1084
1085static void
1086dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1087 RIL_CDMA_SMS_Message rcsm;
1088
1089 RLOGD("dispatchCdmaSms");
1090 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1091 goto invalid;
1092 }
1093
1094 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
1095
1096#ifdef MEMSET_FREED
1097 memset(&rcsm, 0, sizeof(rcsm));
1098#endif
1099
1100 return;
1101
1102invalid:
1103 invalidCommandBlock(pRI);
1104 return;
1105}
1106
1107static void
1108dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1109 RIL_IMS_SMS_Message rism;
1110 RIL_CDMA_SMS_Message rcsm;
1111
1112 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1113
1114 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1115 goto invalid;
1116 }
1117 memset(&rism, 0, sizeof(rism));
1118 rism.tech = RADIO_TECH_3GPP2;
1119 rism.retry = retry;
1120 rism.messageRef = messageRef;
1121 rism.message.cdmaMessage = &rcsm;
1122
1123 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
1124 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1125 +sizeof(rcsm),pRI, pRI->socket_id);
1126
1127#ifdef MEMSET_FREED
1128 memset(&rcsm, 0, sizeof(rcsm));
1129 memset(&rism, 0, sizeof(rism));
1130#endif
1131
1132 return;
1133
1134invalid:
1135 invalidCommandBlock(pRI);
1136 return;
1137}
1138
1139static void
1140dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1141 RIL_IMS_SMS_Message rism;
1142 int32_t countStrings;
1143 status_t status;
1144 size_t datalen;
1145 char **pStrings;
1146 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1147
1148 status = p.readInt32 (&countStrings);
1149
1150 if (status != NO_ERROR) {
1151 goto invalid;
1152 }
1153
1154 memset(&rism, 0, sizeof(rism));
1155 rism.tech = RADIO_TECH_3GPP;
1156 rism.retry = retry;
1157 rism.messageRef = messageRef;
1158
1159 startRequest;
1160 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1161 (int)rism.tech, (int)rism.retry, rism.messageRef);
1162 if (countStrings == 0) {
1163 // just some non-null pointer
1164 pStrings = (char **)alloca(sizeof(char *));
1165 datalen = 0;
1166 } else if (((int)countStrings) == -1) {
1167 pStrings = NULL;
1168 datalen = 0;
1169 } else {
1170 datalen = sizeof(char *) * countStrings;
1171
1172 pStrings = (char **)alloca(datalen);
1173
1174 for (int i = 0 ; i < countStrings ; i++) {
1175 pStrings[i] = strdupReadString(p);
1176 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1177 }
1178 }
1179 removeLastChar;
1180 closeRequest;
1181 printRequest(pRI->token, pRI->pCI->requestNumber);
1182
1183 rism.message.gsmMessage = pStrings;
1184 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
1185 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1186 +datalen, pRI, pRI->socket_id);
1187
1188 if (pStrings != NULL) {
1189 for (int i = 0 ; i < countStrings ; i++) {
1190#ifdef MEMSET_FREED
1191 memsetString (pStrings[i]);
1192#endif
1193 free(pStrings[i]);
1194 }
1195
1196#ifdef MEMSET_FREED
1197 memset(pStrings, 0, datalen);
1198#endif
1199 }
1200
1201#ifdef MEMSET_FREED
1202 memset(&rism, 0, sizeof(rism));
1203#endif
1204 return;
1205invalid:
1206 ALOGE("dispatchImsGsmSms invalid block");
1207 invalidCommandBlock(pRI);
1208 return;
1209}
1210
1211static void
1212dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1213 int32_t t;
1214 status_t status = p.readInt32(&t);
1215 RIL_RadioTechnologyFamily format;
1216 uint8_t retry;
1217 int32_t messageRef;
1218
1219 RLOGD("dispatchImsSms");
1220 if (status != NO_ERROR) {
1221 goto invalid;
1222 }
1223 format = (RIL_RadioTechnologyFamily) t;
1224
1225 // read retry field
1226 status = p.read(&retry,sizeof(retry));
1227 if (status != NO_ERROR) {
1228 goto invalid;
1229 }
1230 // read messageRef field
1231 status = p.read(&messageRef,sizeof(messageRef));
1232 if (status != NO_ERROR) {
1233 goto invalid;
1234 }
1235
1236 if (RADIO_TECH_3GPP == format) {
1237 dispatchImsGsmSms(p, pRI, retry, messageRef);
1238 } else if (RADIO_TECH_3GPP2 == format) {
1239 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1240 } else {
1241 ALOGE("requestImsSendSMS invalid format value =%d", format);
1242 }
1243
1244 return;
1245
1246invalid:
1247 invalidCommandBlock(pRI);
1248 return;
1249}
1250
1251static void
1252dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1253 RIL_CDMA_SMS_Ack rcsa;
xja1c30b82022-01-25 16:13:48 +08001254 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001255 status_t status;
1256 int32_t digitCount;
1257
1258 RLOGD("dispatchCdmaSmsAck");
1259 memset(&rcsa, 0, sizeof(rcsa));
1260
1261 status = p.readInt32(&t);
1262 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1263
1264 status = p.readInt32(&t);
1265 rcsa.uSMSCauseCode = (int) t;
1266
1267 if (status != NO_ERROR) {
1268 goto invalid;
1269 }
1270
1271 startRequest;
1272 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1273 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1274 closeRequest;
1275
1276 printRequest(pRI->token, pRI->pCI->requestNumber);
1277
1278 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
1279
1280#ifdef MEMSET_FREED
1281 memset(&rcsa, 0, sizeof(rcsa));
1282#endif
1283
1284 return;
1285
1286invalid:
1287 invalidCommandBlock(pRI);
1288 return;
1289}
1290
1291static void
1292dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1293 int32_t t;
1294 status_t status;
1295 int32_t num;
1296
1297 status = p.readInt32(&num);
1298 if (status != NO_ERROR) {
1299 goto invalid;
1300 }
1301
1302 {
1303 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1304 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
1305
1306 startRequest;
1307 for (int i = 0 ; i < num ; i++ ) {
1308 gsmBciPtrs[i] = &gsmBci[i];
1309
1310 status = p.readInt32(&t);
1311 gsmBci[i].fromServiceId = (int) t;
1312
1313 status = p.readInt32(&t);
1314 gsmBci[i].toServiceId = (int) t;
1315
1316 status = p.readInt32(&t);
1317 gsmBci[i].fromCodeScheme = (int) t;
1318
1319 status = p.readInt32(&t);
1320 gsmBci[i].toCodeScheme = (int) t;
1321
1322 status = p.readInt32(&t);
1323 gsmBci[i].selected = (uint8_t) t;
1324
1325 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1326 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1327 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1328 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1329 gsmBci[i].selected);
1330 }
1331 closeRequest;
1332
1333 if (status != NO_ERROR) {
1334 goto invalid;
1335 }
1336
1337 printRequest(pRI->token, pRI->pCI->requestNumber);
1338
1339 CALL_ONREQUEST(pRI->pCI->requestNumber,
1340 gsmBciPtrs,
1341 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1342 pRI, pRI->socket_id);
1343
1344#ifdef MEMSET_FREED
1345 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1346 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
1347#endif
1348 }
1349
1350 return;
1351
1352invalid:
1353 invalidCommandBlock(pRI);
1354 return;
1355}
1356
1357static void
1358dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1359 int32_t t;
1360 status_t status;
1361 int32_t num;
1362
1363 status = p.readInt32(&num);
1364 if (status != NO_ERROR) {
1365 goto invalid;
1366 }
1367
1368 {
1369 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1370 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
1371
1372 startRequest;
1373 for (int i = 0 ; i < num ; i++ ) {
1374 cdmaBciPtrs[i] = &cdmaBci[i];
1375
1376 status = p.readInt32(&t);
1377 cdmaBci[i].service_category = (int) t;
1378
1379 status = p.readInt32(&t);
1380 cdmaBci[i].language = (int) t;
1381
1382 status = p.readInt32(&t);
1383 cdmaBci[i].selected = (uint8_t) t;
1384
1385 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1386 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1387 cdmaBci[i].language, cdmaBci[i].selected);
1388 }
1389 closeRequest;
1390
1391 if (status != NO_ERROR) {
1392 goto invalid;
1393 }
1394 printRequest(pRI->token, pRI->pCI->requestNumber);
1395 CALL_ONREQUEST(pRI->pCI->requestNumber,
1396 cdmaBciPtrs,
1397 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1398 pRI, pRI->socket_id);
1399
1400#ifdef MEMSET_FREED
1401 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1402 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
1403#endif
1404 }
1405
1406 return;
1407
1408invalid:
1409 invalidCommandBlock(pRI);
1410 return;
1411}
1412
1413static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1414 RIL_CDMA_SMS_WriteArgs rcsw;
xja1c30b82022-01-25 16:13:48 +08001415 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001416 uint32_t ut;
xja1c30b82022-01-25 16:13:48 +08001417 uint8_t uct = 0;
lh7b0674a2022-01-10 00:34:35 -08001418 status_t status;
1419 int32_t digitCount;
1420 int32_t digitLimit;
1421
1422 memset(&rcsw, 0, sizeof(rcsw));
1423
1424 status = p.readInt32(&t);
1425 rcsw.status = t;
1426
1427 status = p.readInt32(&t);
1428 rcsw.message.uTeleserviceID = (int) t;
1429
1430 status = p.read(&uct,sizeof(uct));
1431 rcsw.message.bIsServicePresent = (uint8_t) uct;
1432
1433 status = p.readInt32(&t);
1434 rcsw.message.uServicecategory = (int) t;
1435
1436 status = p.readInt32(&t);
1437 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1438
1439 status = p.readInt32(&t);
1440 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1441
1442 status = p.readInt32(&t);
1443 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1444
1445 status = p.readInt32(&t);
1446 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1447
1448 status = p.read(&uct,sizeof(uct));
1449 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1450
1451 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1452
1453 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1454 status = p.read(&uct,sizeof(uct));
1455 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1456 }
1457
1458 status = p.readInt32(&t);
1459 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1460
1461 status = p.read(&uct,sizeof(uct));
1462 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1463
1464 status = p.read(&uct,sizeof(uct));
1465 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1466
1467 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1468
1469 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1470 status = p.read(&uct,sizeof(uct));
1471 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1472 }
1473
1474 status = p.readInt32(&t);
1475 rcsw.message.uBearerDataLen = (int) t;
1476
1477 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1478
1479 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1480 status = p.read(&uct, sizeof(uct));
1481 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1482 }
1483
1484 if (status != NO_ERROR) {
1485 goto invalid;
1486 }
1487
1488 startRequest;
1489 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1490 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1491 message.sAddress.number_mode=%d, \
1492 message.sAddress.number_type=%d, ",
1493 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1494 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1495 rcsw.message.sAddress.number_mode,
1496 rcsw.message.sAddress.number_type);
1497 closeRequest;
1498
1499 printRequest(pRI->token, pRI->pCI->requestNumber);
1500
1501 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
1502
1503#ifdef MEMSET_FREED
1504 memset(&rcsw, 0, sizeof(rcsw));
1505#endif
1506
1507 return;
1508
1509invalid:
1510 invalidCommandBlock(pRI);
1511 return;
1512
1513}
1514
1515// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1516// Version 4 of the RIL interface adds a new PDP type parameter to support
1517// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1518// RIL, remove the parameter from the request.
1519static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1520 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1521 const int numParamsRilV3 = 6;
1522
1523 // The first bytes of the RIL parcel contain the request number and the
1524 // serial number - see processCommandBuffer(). Copy them over too.
1525 int pos = p.dataPosition();
1526
1527 int numParams = p.readInt32();
1528 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1529/* Parcel p2;
1530 p2.appendFrom(&p, 0, pos);
1531 p2.writeInt32(numParamsRilV3);
1532 for(int i = 0; i < numParamsRilV3; i++) {
1533 p2.writeString16(p.readString16());
1534 }
1535 p2.setDataPosition(pos);
1536 dispatchStrings(p2, pRI);*/
1537 } else {
1538 p.setDataPosition(pos);
1539 dispatchStrings(p, pRI);
1540 }
1541}
1542
1543static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1544{
1545 RIL_InitialAttachApn pf;
xja1c30b82022-01-25 16:13:48 +08001546 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001547 status_t status;
1548
1549 memset(&pf, 0, sizeof(pf));
1550
1551 pf.apn = strdupReadString(p);
1552 pf.protocol = strdupReadString(p);
1553
1554 status = p.readInt32(&t);
1555 pf.authtype = (int) t;
1556
1557 pf.username = strdupReadString(p);
1558 pf.password = strdupReadString(p);
1559
1560 startRequest;
1561 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1562 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
1563 closeRequest;
1564 printRequest(pRI->token, pRI->pCI->requestNumber);
1565
1566 if (status != NO_ERROR) {
1567 goto invalid;
1568 }
1569 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1570
1571#ifdef MEMSET_FREED
1572 memsetString(pf.apn);
1573 memsetString(pf.protocol);
1574 memsetString(pf.username);
1575 memsetString(pf.password);
1576#endif
1577
1578 free(pf.apn);
1579 free(pf.protocol);
1580 free(pf.username);
1581 free(pf.password);
1582
1583#ifdef MEMSET_FREED
1584 memset(&pf, 0, sizeof(pf));
1585#endif
1586
1587 return;
1588invalid:
1589 invalidCommandBlock(pRI);
1590 return;
1591}
1592
1593static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1594 RIL_NV_ReadItem nvri;
xja1c30b82022-01-25 16:13:48 +08001595 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001596 status_t status;
1597
1598 memset(&nvri, 0, sizeof(nvri));
1599
1600 status = p.readInt32(&t);
1601 nvri.itemID = (RIL_NV_Item) t;
1602
1603 if (status != NO_ERROR) {
1604 goto invalid;
1605 }
1606
1607 startRequest;
1608 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1609 closeRequest;
1610
1611 printRequest(pRI->token, pRI->pCI->requestNumber);
1612
1613 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1614
1615#ifdef MEMSET_FREED
1616 memset(&nvri, 0, sizeof(nvri));
1617#endif
1618
1619 return;
1620
1621invalid:
1622 invalidCommandBlock(pRI);
1623 return;
1624}
1625
1626static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1627 RIL_NV_WriteItem nvwi;
xja1c30b82022-01-25 16:13:48 +08001628 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001629 status_t status;
1630
1631 memset(&nvwi, 0, sizeof(nvwi));
1632
1633 status = p.readInt32(&t);
1634 nvwi.itemID = (RIL_NV_Item) t;
1635
1636 nvwi.value = strdupReadString(p);
1637
1638 if (status != NO_ERROR || nvwi.value == NULL) {
1639 goto invalid;
1640 }
1641
1642 startRequest;
1643 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1644 nvwi.value);
1645 closeRequest;
1646
1647 printRequest(pRI->token, pRI->pCI->requestNumber);
1648
1649 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1650
1651#ifdef MEMSET_FREED
1652 memsetString(nvwi.value);
1653#endif
1654
1655 free(nvwi.value);
1656
1657#ifdef MEMSET_FREED
1658 memset(&nvwi, 0, sizeof(nvwi));
1659#endif
1660
1661 return;
1662
1663invalid:
1664 invalidCommandBlock(pRI);
1665 return;
1666}
1667
1668
1669static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1670 RIL_SelectUiccSub uicc_sub;
1671 status_t status;
1672 int32_t t;
1673 memset(&uicc_sub, 0, sizeof(uicc_sub));
1674
1675 status = p.readInt32(&t);
1676 if (status != NO_ERROR) {
1677 goto invalid;
1678 }
1679 uicc_sub.slot = (int) t;
1680
1681 status = p.readInt32(&t);
1682 if (status != NO_ERROR) {
1683 goto invalid;
1684 }
1685 uicc_sub.app_index = (int) t;
1686
1687 status = p.readInt32(&t);
1688 if (status != NO_ERROR) {
1689 goto invalid;
1690 }
1691 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1692
1693 status = p.readInt32(&t);
1694 if (status != NO_ERROR) {
1695 goto invalid;
1696 }
1697 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1698
1699 startRequest;
1700 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1701 uicc_sub.act_status);
1702 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1703 uicc_sub.app_index, uicc_sub.act_status);
1704 closeRequest;
1705 printRequest(pRI->token, pRI->pCI->requestNumber);
1706
1707 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1708
1709#ifdef MEMSET_FREED
1710 memset(&uicc_sub, 0, sizeof(uicc_sub));
1711#endif
1712 return;
1713
1714invalid:
1715 invalidCommandBlock(pRI);
1716 return;
1717}
1718
1719static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1720{
1721 RIL_SimAuthentication pf;
xja1c30b82022-01-25 16:13:48 +08001722 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001723 status_t status;
1724
1725 memset(&pf, 0, sizeof(pf));
1726
1727 status = p.readInt32(&t);
1728 pf.authContext = (int) t;
1729 pf.authData = strdupReadString(p);
1730 pf.aid = strdupReadString(p);
1731
1732 startRequest;
1733 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1734 closeRequest;
1735 printRequest(pRI->token, pRI->pCI->requestNumber);
1736
1737 if (status != NO_ERROR) {
1738 goto invalid;
1739 }
1740 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1741
1742#ifdef MEMSET_FREED
1743 memsetString(pf.authData);
1744 memsetString(pf.aid);
1745#endif
1746
1747 free(pf.authData);
1748 free(pf.aid);
1749
1750#ifdef MEMSET_FREED
1751 memset(&pf, 0, sizeof(pf));
1752#endif
1753
1754 return;
1755invalid:
1756 invalidCommandBlock(pRI);
1757 return;
1758}
1759
1760static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1761 int32_t t;
1762 status_t status;
1763 int32_t num;
1764
1765 status = p.readInt32(&num);
1766 if (status != NO_ERROR) {
1767 goto invalid;
1768 }
1769
1770 {
1771 RIL_DataProfileInfo dataProfiles[num];
1772 RIL_DataProfileInfo *dataProfilePtrs[num];
1773
1774 startRequest;
1775 for (int i = 0 ; i < num ; i++ ) {
1776 dataProfilePtrs[i] = &dataProfiles[i];
1777
1778 status = p.readInt32(&t);
1779 dataProfiles[i].profileId = (int) t;
1780
1781 dataProfiles[i].apn = strdupReadString(p);
1782 dataProfiles[i].protocol = strdupReadString(p);
1783 status = p.readInt32(&t);
1784 dataProfiles[i].authType = (int) t;
1785
1786 dataProfiles[i].user = strdupReadString(p);
1787 dataProfiles[i].password = strdupReadString(p);
1788
1789 status = p.readInt32(&t);
1790 dataProfiles[i].type = (int) t;
1791
1792 status = p.readInt32(&t);
1793 dataProfiles[i].maxConnsTime = (int) t;
1794 status = p.readInt32(&t);
1795 dataProfiles[i].maxConns = (int) t;
1796 status = p.readInt32(&t);
1797 dataProfiles[i].waitTime = (int) t;
1798
1799 status = p.readInt32(&t);
1800 dataProfiles[i].enabled = (int) t;
1801
1802 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1803 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1804 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1805 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1806 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1807 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1808 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1809 RLOGD("[%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1810user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1811waitTime =%d, enabled =%d]", i, dataProfiles[i].profileId,
1812 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1813 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1814 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1815 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1816 }
1817 closeRequest;
1818 printRequest(pRI->token, pRI->pCI->requestNumber);
1819
1820 if (status != NO_ERROR) {
1821 goto invalid;
1822 }
1823 CALL_ONREQUEST(pRI->pCI->requestNumber,
1824 dataProfilePtrs,
1825 num * sizeof(RIL_DataProfileInfo *),
1826 pRI, pRI->socket_id);
1827 for(int i = 0; i< num; i++) {
1828 free(dataProfiles[i].apn);
1829 free(dataProfiles[i].protocol);
1830 free(dataProfiles[i].user);
1831 free(dataProfiles[i].password);
1832 }
1833#ifdef MEMSET_FREED
1834 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1835 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1836#endif
1837 }
1838
1839 return;
1840
1841invalid:
1842 invalidCommandBlock(pRI);
1843 return;
1844}
1845
1846static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1847 RIL_RadioCapability rc;
xja1c30b82022-01-25 16:13:48 +08001848 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08001849 status_t status;
1850
1851 memset (&rc, 0, sizeof(RIL_RadioCapability));
1852
1853 status = p.readInt32(&t);
1854 rc.version = (int)t;
1855 if (status != NO_ERROR) {
1856 goto invalid;
1857 }
1858
1859 status = p.readInt32(&t);
1860 rc.session= (int)t;
1861 if (status != NO_ERROR) {
1862 goto invalid;
1863 }
1864
1865 status = p.readInt32(&t);
1866 rc.phase= (int)t;
1867 if (status != NO_ERROR) {
1868 goto invalid;
1869 }
1870
1871 status = p.readInt32(&t);
1872 rc.rat = (int)t;
1873 if (status != NO_ERROR) {
1874 goto invalid;
1875 }
1876
1877 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
1878 if (status != NO_ERROR) {
1879 goto invalid;
1880 }
1881
1882 status = p.readInt32(&t);
1883 rc.status = (int)t;
1884
1885 if (status != NO_ERROR) {
1886 goto invalid;
1887 }
1888
1889 startRequest;
1890 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, logicalModemUuid:%s, status:%d",
1891 printBuf, rc.version, rc.session, rc.phase, rc.rat, rc.logicalModemUuid, rc.status);
1892
1893 closeRequest;
1894 printRequest(pRI->token, pRI->pCI->requestNumber);
1895
1896 CALL_ONREQUEST(pRI->pCI->requestNumber,
1897 &rc,
1898 sizeof(RIL_RadioCapability),
1899 pRI, pRI->socket_id);
1900 return;
1901invalid:
1902 invalidCommandBlock(pRI);
1903 return;
1904}
1905
1906#if 0
1907static int
1908blockingWrite(int fd, const void *buffer, size_t len) {
1909 size_t writeOffset = 0;
1910 const uint8_t *toWrite;
1911
1912 toWrite = (const uint8_t *)buffer;
1913
1914 while (writeOffset < len) {
1915 ssize_t written;
1916 do {
1917 written = write (fd, toWrite + writeOffset,
1918 len - writeOffset);
1919 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
1920
1921 if (written >= 0) {
1922 writeOffset += written;
1923 } else { // written < 0
1924 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
1925 close(fd);
1926 return -1;
1927 }
1928 }
1929#if VDBG
1930 RLOGE("RIL Response bytes written:%d", writeOffset);
1931#endif
1932 return 0;
1933}
1934
1935static int
1936sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
1937 int fd = s_ril_param_socket.fdCommand;
1938 int ret;
1939 uint32_t header;
1940 pthread_mutex_t * writeMutexHook = &s_writeMutex;
1941
1942#if VDBG
1943 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
1944#endif
1945
1946#if (SIM_COUNT >= 2)
1947 if (socket_id == RIL_SOCKET_2) {
1948 fd = s_ril_param_socket2.fdCommand;
1949 writeMutexHook = &s_writeMutex_socket2;
1950 }
1951#if (SIM_COUNT >= 3)
1952 else if (socket_id == RIL_SOCKET_3) {
1953 fd = s_ril_param_socket3.fdCommand;
1954 writeMutexHook = &s_writeMutex_socket3;
1955 }
1956#endif
1957#if (SIM_COUNT >= 4)
1958 else if (socket_id == RIL_SOCKET_4) {
1959 fd = s_ril_param_socket4.fdCommand;
1960 writeMutexHook = &s_writeMutex_socket4;
1961 }
1962#endif
1963#endif
1964 if (fd < 0) {
1965 return -1;
1966 }
1967
1968 if (dataSize > MAX_COMMAND_BYTES) {
1969 RLOGE("RIL: packet larger than %u (%u)",
1970 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1971
1972 return -1;
1973 }
1974
1975 pthread_mutex_lock(writeMutexHook);
1976
1977 header = htonl(dataSize);
1978
1979 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1980
1981 if (ret < 0) {
1982 pthread_mutex_unlock(writeMutexHook);
1983 return ret;
1984 }
1985
1986 ret = blockingWrite(fd, data, dataSize);
1987
1988 if (ret < 0) {
1989 pthread_mutex_unlock(writeMutexHook);
1990 return ret;
1991 }
1992
1993 pthread_mutex_unlock(writeMutexHook);
1994
1995 return 0;
1996}
1997
1998static int
1999sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
2000 printResponse;
2001 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
2002}
2003#endif
2004
2005/** response is an int* pointing to an array of ints */
2006
2007static int
2008responseInts(Parcel &p, void *response, size_t responselen) {
2009 int numInts;
2010
2011 if (response == NULL && responselen != 0) {
2012 RLOGE("invalid response: NULL");
2013 return RIL_ERRNO_INVALID_RESPONSE;
2014 }
2015 if (responselen % sizeof(int) != 0) {
2016 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2017 (int)responselen, (int)sizeof(int));
2018 return RIL_ERRNO_INVALID_RESPONSE;
2019 }
2020
2021 int *p_int = (int *) response;
2022
2023 numInts = responselen / sizeof(int);
2024 p.writeInt32 (numInts);
2025
2026 /* each int*/
2027 startResponse;
2028 for (int i = 0 ; i < numInts ; i++) {
2029 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2030 p.writeInt32(p_int[i]);
2031 }
2032 removeLastChar;
2033 closeResponse;
2034
2035 return 0;
2036}
2037
2038// Response is an int or RIL_LastCallFailCauseInfo.
2039// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2040// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2041static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2042 if (response == NULL && responselen != 0) {
2043 RLOGE("invalid response: NULL");
2044 return RIL_ERRNO_INVALID_RESPONSE;
2045 }
2046
2047 if (responselen == sizeof(int)) {
2048 startResponse;
2049 int *p_int = (int *) response;
2050 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2051 p.writeInt32(p_int[0]);
2052 removeLastChar;
2053 closeResponse;
2054 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2055 startResponse;
2056 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2057 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2058 p_fail_cause_info->vendor_cause);
2059 p.writeInt32(p_fail_cause_info->cause_code);
2060 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2061 removeLastChar;
2062 closeResponse;
2063 } else {
2064 RLOGE("responseFailCause: invalid response length %d expected an int or "
2065 "RIL_LastCallFailCauseInfo", (int)responselen);
2066 return RIL_ERRNO_INVALID_RESPONSE;
2067 }
2068
2069 return 0;
2070}
2071
2072/** response is a char **, pointing to an array of char *'s
2073 The parcel will begin with the version */
2074static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2075 p.writeInt32(version);
2076 return responseStrings(p, response, responselen);
2077}
2078
2079/** response is a char **, pointing to an array of char *'s */
2080static int responseStrings(Parcel &p, void *response, size_t responselen) {
2081 int numStrings;
2082
2083 if (response == NULL && responselen != 0) {
2084 RLOGE("invalid response: NULL");
2085 return RIL_ERRNO_INVALID_RESPONSE;
2086 }
2087 if (responselen % sizeof(char *) != 0) {
2088 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
2089 (int)responselen, (int)sizeof(char *));
2090 return RIL_ERRNO_INVALID_RESPONSE;
2091 }
2092
2093 if (response == NULL) {
2094 p.writeInt32 (0);
2095 } else {
2096 char **p_cur = (char **) response;
2097
2098 numStrings = responselen / sizeof(char *);
2099 p.writeInt32 (numStrings);
2100
2101 /* each string*/
2102 startResponse;
2103 for (int i = 0 ; i < numStrings ; i++) {
2104 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2105 writeStringToParcel (p, p_cur[i]);
2106 }
2107 removeLastChar;
2108 closeResponse;
2109 }
2110 return 0;
2111}
2112
2113
2114/**
2115 * NULL strings are accepted
2116 * FIXME currently ignores responselen
2117 */
2118static int responseString(Parcel &p, void *response, size_t responselen) {
2119 /* one string only */
2120 startResponse;
2121 appendPrintBuf("%s%s", printBuf, (char*)response);
2122 closeResponse;
2123
2124 writeStringToParcel(p, (const char *)response);
2125 return 0;
2126}
2127
2128static int responseVoid(Parcel &p, void *response, size_t responselen) {
2129 startResponse;
2130 removeLastChar;
2131 return 0;
2132}
2133
2134static int responseCallList(Parcel &p, void *response, size_t responselen) {
2135 int num;
2136
2137 if (response == NULL && responselen != 0) {
2138 RLOGE("invalid response: NULL");
2139 return RIL_ERRNO_INVALID_RESPONSE;
2140 }
2141
2142 if (responselen % sizeof (RIL_Call *) != 0) {
2143 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
2144 (int)responselen, (int)sizeof (RIL_Call *));
2145 return RIL_ERRNO_INVALID_RESPONSE;
2146 }
2147
2148 startResponse;
2149 /* number of call info's */
2150 num = responselen / sizeof(RIL_Call *);
2151 p.writeInt32(num);
2152 for (int i = 0 ; i < num ; i++) {
2153 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2154 /* each call info */
2155 p.writeInt32(p_cur->state);
2156 p.writeInt32(p_cur->index);
2157 p.writeInt32(p_cur->toa);
2158 p.writeInt32(p_cur->isMpty);
2159 p.writeInt32(p_cur->isMT);
2160 p.writeInt32(p_cur->als);
2161 p.writeInt32(p_cur->isVoice);
2162 p.writeInt32(p_cur->isVoicePrivacy);
2163 writeStringToParcel(p, p_cur->number);
2164 p.writeInt32(p_cur->numberPresentation);
2165 writeStringToParcel(p, p_cur->name);
2166 p.writeInt32(p_cur->namePresentation);
2167 // Remove when partners upgrade to version 3
2168 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2169 p.writeInt32(0); /* UUS Information is absent */
2170 } else {
2171 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2172 p.writeInt32(1); /* UUS Information is present */
2173 p.writeInt32(uusInfo->uusType);
2174 p.writeInt32(uusInfo->uusDcs);
2175 p.writeInt32(uusInfo->uusLength);
2176 p.write(uusInfo->uusData, uusInfo->uusLength);
2177 }
2178 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2179 printBuf,
2180 p_cur->index,
2181 callStateToString(p_cur->state),
2182 p_cur->toa);
2183 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2184 printBuf,
2185 (p_cur->isMpty)?"conf":"norm",
2186 (p_cur->isMT)?"mt":"mo",
2187 p_cur->als,
2188 (p_cur->isVoice)?"voc":"nonvoc",
2189 (p_cur->isVoicePrivacy)?"evp":"noevp");
2190 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2191 printBuf,
2192 p_cur->number,
2193 p_cur->numberPresentation,
2194 p_cur->name,
2195 p_cur->namePresentation);
2196 if(p_cur->isMT) {
2197 printf("[EVENT][MT_CALL] phone number is %s\n",p_cur->number);
2198 }
2199 }
2200 removeLastChar;
2201 closeResponse;
2202
2203 return 0;
2204}
2205
2206static int responseSMS(Parcel &p, void *response, size_t responselen) {
2207 if (response == NULL) {
2208 RLOGE("invalid response: NULL");
2209 return RIL_ERRNO_INVALID_RESPONSE;
2210 }
2211
2212 if (responselen != sizeof (RIL_SMS_Response) ) {
2213 RLOGE("invalid response length %d expected %d",
2214 (int)responselen, (int)sizeof (RIL_SMS_Response));
2215 return RIL_ERRNO_INVALID_RESPONSE;
2216 }
2217
2218 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2219
2220 p.writeInt32(p_cur->messageRef);
2221 writeStringToParcel(p, p_cur->ackPDU);
2222 p.writeInt32(p_cur->errorCode);
2223
2224 startResponse;
2225 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2226 (char*)p_cur->ackPDU, p_cur->errorCode);
2227 closeResponse;
2228 bool ifResend;
2229 if(isGostEcall())
2230 {
2231 if(p_cur->errorCode == 0)
2232 {
2233 //delete MSD
2234 gostDelSaveSmsData();
2235 //no resend
2236 ifResend = false;
2237 }
2238 else
2239 {
2240 //resend MSD
2241 ifResend = true;
2242 }
2243 gostEcallResendMsd(ifResend);
2244 }
2245 return 0;
2246}
2247
2248static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2249{
2250 if (response == NULL && responselen != 0) {
2251 RLOGE("invalid response: NULL");
2252 return RIL_ERRNO_INVALID_RESPONSE;
2253 }
2254
2255 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
2256 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
2257 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2258 return RIL_ERRNO_INVALID_RESPONSE;
2259 }
2260
2261 // Write version
2262 p.writeInt32(4);
2263
2264 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2265 p.writeInt32(num);
2266
2267 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2268 startResponse;
2269 int i;
2270 for (i = 0; i < num; i++) {
2271 p.writeInt32(p_cur[i].cid);
2272 p.writeInt32(p_cur[i].active);
2273 writeStringToParcel(p, p_cur[i].type);
2274 // apn is not used, so don't send.
2275 writeStringToParcel(p, p_cur[i].address);
2276 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2277 p_cur[i].cid,
2278 (p_cur[i].active==0)?"down":"up",
2279 (char*)p_cur[i].type,
2280 (char*)p_cur[i].address);
2281 }
2282 removeLastChar;
2283 closeResponse;
2284
2285 return 0;
2286}
2287
2288static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2289{
2290 if (response == NULL && responselen != 0) {
2291 RLOGE("invalid response: NULL");
2292 return RIL_ERRNO_INVALID_RESPONSE;
2293 }
2294
2295 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2296 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2297 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2298 return RIL_ERRNO_INVALID_RESPONSE;
2299 }
2300
2301 // Write version
2302 p.writeInt32(6);
2303
2304 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2305 p.writeInt32(num);
2306
2307 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2308 startResponse;
2309 int i;
2310 for (i = 0; i < num; i++) {
2311 p.writeInt32((int)p_cur[i].status);
2312 p.writeInt32(p_cur[i].suggestedRetryTime);
2313 p.writeInt32(p_cur[i].cid);
2314 p.writeInt32(p_cur[i].active);
2315 writeStringToParcel(p, p_cur[i].type);
2316 writeStringToParcel(p, p_cur[i].ifname);
2317 writeStringToParcel(p, p_cur[i].addresses);
2318 writeStringToParcel(p, p_cur[i].dnses);
2319 writeStringToParcel(p, p_cur[i].gateways);
2320 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2321 p_cur[i].status,
2322 p_cur[i].suggestedRetryTime,
2323 p_cur[i].cid,
2324 (p_cur[i].active==0)?"down":"up",
2325 (char*)p_cur[i].type,
2326 (char*)p_cur[i].ifname,
2327 (char*)p_cur[i].addresses,
2328 (char*)p_cur[i].dnses,
2329 (char*)p_cur[i].gateways);
2330 }
2331 removeLastChar;
2332 closeResponse;
2333 return 0;
2334}
2335
2336static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2337{
2338 if (response == NULL && responselen != 0) {
2339 RLOGE("invalid response: NULL");
2340 return RIL_ERRNO_INVALID_RESPONSE;
2341 }
2342
2343 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2344 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2345 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2346 return RIL_ERRNO_INVALID_RESPONSE;
2347 }
2348
2349 // Write version
2350 p.writeInt32(10);
2351
2352 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2353 p.writeInt32(num);
2354
2355 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2356 startResponse;
2357 int i;
2358 for (i = 0; i < num; i++) {
2359 p.writeInt32((int)p_cur[i].status);
2360 p.writeInt32(p_cur[i].suggestedRetryTime);
2361 p.writeInt32(p_cur[i].cid);
2362 p.writeInt32(p_cur[i].active);
2363 writeStringToParcel(p, p_cur[i].type);
2364 writeStringToParcel(p, p_cur[i].ifname);
2365 writeStringToParcel(p, p_cur[i].addresses);
2366 writeStringToParcel(p, p_cur[i].dnses);
2367 writeStringToParcel(p, p_cur[i].gateways);
2368 writeStringToParcel(p, p_cur[i].pcscf);
2369 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2370 p_cur[i].status,
2371 p_cur[i].suggestedRetryTime,
2372 p_cur[i].cid,
2373 (p_cur[i].active==0)?"down":"up",
2374 (char*)p_cur[i].type,
2375 (char*)p_cur[i].ifname,
2376 (char*)p_cur[i].addresses,
2377 (char*)p_cur[i].dnses,
2378 (char*)p_cur[i].gateways,
2379 (char*)p_cur[i].pcscf);
2380 }
2381 removeLastChar;
2382 closeResponse;
2383
2384 return 0;
2385}
2386
2387
2388static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2389{
2390 if (s_callbacks.version < 5) {
2391 RLOGD("responseDataCallList: v4");
2392 return responseDataCallListV4(p, response, responselen);
2393 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2394 return responseDataCallListV6(p, response, responselen);
2395 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2396 return responseDataCallListV9(p, response, responselen);
2397 } else {
2398 if (response == NULL && responselen != 0) {
2399 RLOGE("invalid response: NULL");
2400 return RIL_ERRNO_INVALID_RESPONSE;
2401 }
2402
2403 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2404 RLOGE("invalid response length %d expected multiple of %d",
2405 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2406 return RIL_ERRNO_INVALID_RESPONSE;
2407 }
2408
2409 // Write version
2410 p.writeInt32(11);
2411
2412 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2413 p.writeInt32(num);
2414
2415 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2416 startResponse;
2417 int i;
2418 for (i = 0; i < num; i++) {
2419 p.writeInt32((int)p_cur[i].status);
2420 p.writeInt32(p_cur[i].suggestedRetryTime);
2421 p.writeInt32(p_cur[i].cid);
2422 p.writeInt32(p_cur[i].active);
2423 writeStringToParcel(p, p_cur[i].type);
2424 writeStringToParcel(p, p_cur[i].ifname);
2425 writeStringToParcel(p, p_cur[i].addresses);
2426 writeStringToParcel(p, p_cur[i].dnses);
2427 writeStringToParcel(p, p_cur[i].gateways);
2428 writeStringToParcel(p, p_cur[i].pcscf);
2429 p.writeInt32(p_cur[i].mtu);
2430 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2431 p_cur[i].status,
2432 p_cur[i].suggestedRetryTime,
2433 p_cur[i].cid,
2434 (p_cur[i].active==0)?"down":"up",
2435 (char*)p_cur[i].type,
2436 (char*)p_cur[i].ifname,
2437 (char*)p_cur[i].addresses,
2438 (char*)p_cur[i].dnses,
2439 (char*)p_cur[i].gateways,
2440 (char*)p_cur[i].pcscf,
2441 p_cur[i].mtu);
2442 }
2443 removeLastChar;
2444 closeResponse;
2445 }
2446
2447 return 0;
2448}
2449
2450static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2451{
2452 if (s_callbacks.version < 5) {
2453 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2454 } else {
2455 return responseDataCallList(p, response, responselen);
2456 }
2457}
2458
2459static int responseRaw(Parcel &p, void *response, size_t responselen) {
2460 if (response == NULL && responselen != 0) {
2461 RLOGE("invalid response: NULL with responselen != 0");
2462 return RIL_ERRNO_INVALID_RESPONSE;
2463 }
2464
2465 // The java code reads -1 size as null byte array
2466 if (response == NULL) {
2467 p.writeInt32(-1);
2468 } else {
2469 p.writeInt32(responselen);
2470 p.write(response, responselen);
2471 }
2472
2473 startResponse;
2474 appendPrintBuf("%slen=%d,%s", printBuf, responselen, (char*)response);
2475 closeResponse;
2476 return 0;
2477}
2478
2479
2480static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2481 if (response == NULL) {
2482 RLOGE("invalid response: NULL");
2483 return RIL_ERRNO_INVALID_RESPONSE;
2484 }
2485
2486 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
2487 RLOGE("invalid response length was %d expected %d",
2488 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2489 return RIL_ERRNO_INVALID_RESPONSE;
2490 }
2491
2492 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2493 p.writeInt32(p_cur->sw1);
2494 p.writeInt32(p_cur->sw2);
2495 writeStringToParcel(p, p_cur->simResponse);
2496
2497 startResponse;
2498 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2499 (char*)p_cur->simResponse);
2500 closeResponse;
2501
2502
2503 return 0;
2504}
2505
2506static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2507 int num;
2508
2509 if (response == NULL && responselen != 0) {
2510 RLOGE("invalid response: NULL");
2511 return RIL_ERRNO_INVALID_RESPONSE;
2512 }
2513
2514 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
2515 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
2516 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2517 return RIL_ERRNO_INVALID_RESPONSE;
2518 }
2519
2520 /* number of call info's */
2521 num = responselen / sizeof(RIL_CallForwardInfo *);
2522 p.writeInt32(num);
2523
2524 startResponse;
2525 for (int i = 0 ; i < num ; i++) {
2526 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2527
2528 p.writeInt32(p_cur->status);
2529 p.writeInt32(p_cur->reason);
2530 p.writeInt32(p_cur->serviceClass);
2531 p.writeInt32(p_cur->toa);
2532 writeStringToParcel(p, p_cur->number);
2533 p.writeInt32(p_cur->timeSeconds);
2534 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2535 (p_cur->status==1)?"enable":"disable",
2536 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2537 (char*)p_cur->number,
2538 p_cur->timeSeconds);
2539 }
2540 removeLastChar;
2541 closeResponse;
2542
2543 return 0;
2544}
2545
2546static int responseSsn(Parcel &p, void *response, size_t responselen) {
2547 if (response == NULL) {
2548 RLOGE("invalid response: NULL");
2549 return RIL_ERRNO_INVALID_RESPONSE;
2550 }
2551
2552 if (responselen != sizeof(RIL_SuppSvcNotification)) {
2553 RLOGE("invalid response length was %d expected %d",
2554 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2555 return RIL_ERRNO_INVALID_RESPONSE;
2556 }
2557
2558 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2559 p.writeInt32(p_cur->notificationType);
2560 p.writeInt32(p_cur->code);
2561 p.writeInt32(p_cur->index);
2562 p.writeInt32(p_cur->type);
2563 writeStringToParcel(p, p_cur->number);
2564
2565 startResponse;
2566 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2567 (p_cur->notificationType==0)?"mo":"mt",
2568 p_cur->code, p_cur->index, p_cur->type,
2569 (char*)p_cur->number);
2570 closeResponse;
2571
2572 return 0;
2573}
2574
2575static int responseCellList(Parcel &p, void *response, size_t responselen) {
2576 int num;
2577
2578 if (response == NULL && responselen != 0) {
2579 RLOGE("invalid response: NULL");
2580 return RIL_ERRNO_INVALID_RESPONSE;
2581 }
2582
2583 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
2584 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
2585 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2586 return RIL_ERRNO_INVALID_RESPONSE;
2587 }
2588
2589 startResponse;
2590 /* number of records */
2591 num = responselen / sizeof(RIL_NeighboringCell *);
2592 p.writeInt32(num);
2593
2594 for (int i = 0 ; i < num ; i++) {
2595 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2596
2597 p.writeInt32(p_cur->rssi);
2598 writeStringToParcel (p, p_cur->cid);
2599
2600 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2601 p_cur->cid, p_cur->rssi);
2602 }
2603 removeLastChar;
2604 closeResponse;
2605
2606 return 0;
2607}
2608
2609/**
2610 * Marshall the signalInfoRecord into the parcel if it exists.
2611 */
2612static void marshallSignalInfoRecord(Parcel &p,
2613 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2614 p.writeInt32(p_signalInfoRecord.isPresent);
2615 p.writeInt32(p_signalInfoRecord.signalType);
2616 p.writeInt32(p_signalInfoRecord.alertPitch);
2617 p.writeInt32(p_signalInfoRecord.signal);
2618}
2619
2620static int responseCdmaInformationRecords(Parcel &p,
2621 void *response, size_t responselen) {
2622 int num;
2623 char* string8 = NULL;
2624 int buffer_lenght;
2625 RIL_CDMA_InformationRecord *infoRec;
2626
2627 if (response == NULL && responselen != 0) {
2628 RLOGE("invalid response: NULL");
2629 return RIL_ERRNO_INVALID_RESPONSE;
2630 }
2631
2632 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
2633 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
2634 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2635 return RIL_ERRNO_INVALID_RESPONSE;
2636 }
2637
2638 RIL_CDMA_InformationRecords *p_cur =
2639 (RIL_CDMA_InformationRecords *) response;
2640 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2641
2642 startResponse;
2643 p.writeInt32(num);
2644
2645 for (int i = 0 ; i < num ; i++) {
2646 infoRec = &p_cur->infoRec[i];
2647 p.writeInt32(infoRec->name);
2648 switch (infoRec->name) {
2649 case RIL_CDMA_DISPLAY_INFO_REC:
2650 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2651 if (infoRec->rec.display.alpha_len >
2652 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
2653 RLOGE("invalid display info response length %d \
2654 expected not more than %d\n",
2655 (int)infoRec->rec.display.alpha_len,
2656 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2657 return RIL_ERRNO_INVALID_RESPONSE;
2658 }
2659 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2660 * sizeof(char) );
2661 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2662 string8[i] = infoRec->rec.display.alpha_buf[i];
2663 }
2664 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2665 writeStringToParcel(p, (const char*)string8);
2666 free(string8);
2667 string8 = NULL;
2668 break;
2669 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2670 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2671 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2672 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
2673 RLOGE("invalid display info response length %d \
2674 expected not more than %d\n",
2675 (int)infoRec->rec.number.len,
2676 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2677 return RIL_ERRNO_INVALID_RESPONSE;
2678 }
2679 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2680 * sizeof(char) );
2681 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2682 string8[i] = infoRec->rec.number.buf[i];
2683 }
2684 string8[(int)infoRec->rec.number.len] = '\0';
2685 writeStringToParcel(p, (const char*)string8);
2686 free(string8);
2687 string8 = NULL;
2688 p.writeInt32(infoRec->rec.number.number_type);
2689 p.writeInt32(infoRec->rec.number.number_plan);
2690 p.writeInt32(infoRec->rec.number.pi);
2691 p.writeInt32(infoRec->rec.number.si);
2692 break;
2693 case RIL_CDMA_SIGNAL_INFO_REC:
2694 p.writeInt32(infoRec->rec.signal.isPresent);
2695 p.writeInt32(infoRec->rec.signal.signalType);
2696 p.writeInt32(infoRec->rec.signal.alertPitch);
2697 p.writeInt32(infoRec->rec.signal.signal);
2698
2699 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2700 alertPitch=%X, signal=%X, ",
2701 printBuf, (int)infoRec->rec.signal.isPresent,
2702 (int)infoRec->rec.signal.signalType,
2703 (int)infoRec->rec.signal.alertPitch,
2704 (int)infoRec->rec.signal.signal);
2705 removeLastChar;
2706 break;
2707 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2708 if (infoRec->rec.redir.redirectingNumber.len >
2709 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
2710 RLOGE("invalid display info response length %d \
2711 expected not more than %d\n",
2712 (int)infoRec->rec.redir.redirectingNumber.len,
2713 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2714 return RIL_ERRNO_INVALID_RESPONSE;
2715 }
2716 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2717 .len + 1) * sizeof(char) );
2718 for (int i = 0;
2719 i < infoRec->rec.redir.redirectingNumber.len;
2720 i++) {
2721 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2722 }
2723 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2724 writeStringToParcel(p, (const char*)string8);
2725 free(string8);
2726 string8 = NULL;
2727 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2728 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2729 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2730 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2731 p.writeInt32(infoRec->rec.redir.redirectingReason);
2732 break;
2733 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2734 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2735 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2736 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2737 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2738
2739 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2740 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2741 lineCtrlPowerDenial=%d, ", printBuf,
2742 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2743 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2744 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2745 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2746 removeLastChar;
2747 break;
2748 case RIL_CDMA_T53_CLIR_INFO_REC:
2749 p.writeInt32((int)(infoRec->rec.clir.cause));
2750
2751 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2752 removeLastChar;
2753 break;
2754 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2755 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2756 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2757
2758 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2759 infoRec->rec.audioCtrl.upLink,
2760 infoRec->rec.audioCtrl.downLink);
2761 removeLastChar;
2762 break;
2763 case RIL_CDMA_T53_RELEASE_INFO_REC:
2764 // TODO(Moto): See David Krause, he has the answer:)
2765 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
2766 return RIL_ERRNO_INVALID_RESPONSE;
2767 default:
2768 RLOGE("Incorrect name value");
2769 return RIL_ERRNO_INVALID_RESPONSE;
2770 }
2771 }
2772 closeResponse;
2773
2774 return 0;
2775}
2776
2777static int responseRilSignalStrength(Parcel &p,
2778 void *response, size_t responselen) {
2779 if (response == NULL && responselen != 0) {
2780 RLOGE("invalid response: NULL");
2781 return RIL_ERRNO_INVALID_RESPONSE;
2782 }
2783
2784 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2785#ifdef TELEMATIC_5G_SUPPORT
2786 RIL_SignalStrength_v14 *p_cur = ((RIL_SignalStrength_v14 *) response);
2787#else
2788 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
2789#endif
2790 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2791 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2792 p.writeInt32(p_cur->GW_SignalStrength.timingAdvance);
2793 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2794 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2795 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2796 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2797 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2798 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2799 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2800 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2801 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2802 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2803 p.writeInt32(p_cur->LTE_SignalStrength.timingAdvance);
2804 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.signalStrength);
2805 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.bitErrorRate);
2806 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2807 p.writeInt32(p_cur->WCDMA_SignalStrength.signalStrength);
2808 p.writeInt32(p_cur->WCDMA_SignalStrength.bitErrorRate);
2809 p.writeInt32(p_cur->WCDMA_SignalStrength.rscp);
2810 p.writeInt32(p_cur->WCDMA_SignalStrength.ecno);
2811#ifdef TELEMATIC_5G_SUPPORT
2812 p.writeInt32(p_cur->NR_SignalStrength.ssRsrp);
2813 p.writeInt32(p_cur->NR_SignalStrength.ssRsrq);
2814 p.writeInt32(p_cur->NR_SignalStrength.ssSinr);
2815 p.writeInt32(p_cur->NR_SignalStrength.csiRsrp);
2816 p.writeInt32(p_cur->NR_SignalStrength.csiRsrq);
2817 p.writeInt32(p_cur->NR_SignalStrength.csiSinr);
2818#endif
2819 startResponse;
2820
2821#ifdef TELEMATIC_5G_SUPPORT
2822 appendPrintBuf("%s[GW_SS.signalStrength=%d,GW_SS.bitErrorRate=%d,GW_SS.timingAdvance=%d,\
2823 CDMA_SS.dbm=%d,CDMA_SS.ecio=%d,\
2824 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,EVDO_SS.signalNoiseRatio=%d,\
2825 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,LTE_SS.rssnr=%d,LTE_SS.cqi=%d,LTE_SS.timingAdvance=%d,\
2826 TDSCDMA_SS.signalStrength=%d,TDSCDMA_SS.bitErrorRate=%d,TDSCDMA_SS.rscp=%d,\
2827 WCDMA_SS.signalStrength=%d,WCDMA_SS.bitErrorRate=%d,WCDMA_SS.rscp=%d,WCDMA_SS.ecno=%d,\
2828 NR_SignalStrength.ssRsrp=%d,NR_SignalStrength.ssRsrq=%d,NR_SignalStrength.ssSinr=%d,\
2829 NR_SignalStrength.csiRsrp=%d,NR_SignalStrength.csiRsrq=%d,NR_SignalStrength.csiSinr=%d]",
2830 printBuf,
2831 p_cur->GW_SignalStrength.signalStrength,
2832 p_cur->GW_SignalStrength.bitErrorRate,
2833 p_cur->GW_SignalStrength.timingAdvance,
2834 p_cur->CDMA_SignalStrength.dbm,
2835 p_cur->CDMA_SignalStrength.ecio,
2836 p_cur->EVDO_SignalStrength.dbm,
2837 p_cur->EVDO_SignalStrength.ecio,
2838 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2839 p_cur->LTE_SignalStrength.signalStrength,
2840 p_cur->LTE_SignalStrength.rsrp,
2841 p_cur->LTE_SignalStrength.rsrq,
2842 p_cur->LTE_SignalStrength.rssnr,
2843 p_cur->LTE_SignalStrength.cqi,
2844 p_cur->LTE_SignalStrength.timingAdvance,
2845 p_cur->TD_SCDMA_SignalStrength.signalStrength,
2846 p_cur->TD_SCDMA_SignalStrength.bitErrorRate,
2847 p_cur->TD_SCDMA_SignalStrength.rscp,
2848 p_cur->WCDMA_SignalStrength.signalStrength,
2849 p_cur->WCDMA_SignalStrength.bitErrorRate,
2850 p_cur->WCDMA_SignalStrength.rscp,
2851 p_cur->WCDMA_SignalStrength.ecno,
2852 p_cur->NR_SignalStrength.ssRsrp,
2853 p_cur->NR_SignalStrength.ssRsrq,
2854 p_cur->NR_SignalStrength.ssSinr,
2855 p_cur->NR_SignalStrength.csiRsrp,
2856 p_cur->NR_SignalStrength.csiRsrq,
2857 p_cur->NR_SignalStrength.csiSinr);
2858#else
2859 appendPrintBuf("%s[GW_SS.signalStrength=%d,GW_SS.bitErrorRate=%d,GW_SS.timingAdvance=%d,\
2860 CDMA_SS.dbm=%d,CDMA_SS.ecio=%d,\
2861 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,EVDO_SS.signalNoiseRatio=%d,\
2862 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,LTE_SS.rssnr=%d,LTE_SS.cqi=%d,LTE_SS.timingAdvance=%d,\
2863 TDSCDMA_SS.signalStrength=%d,TDSCDMA_SS.bitErrorRate=%d,TDSCDMA_SS.rscp=%d,\
2864 WCDMA_SS.signalStrength=%d,WCDMA_SS.bitErrorRate=%d,WCDMA_SS.rscp=%d,WCDMA_SS.ecno=%d]",
2865 printBuf,
2866 p_cur->GW_SignalStrength.signalStrength,
2867 p_cur->GW_SignalStrength.bitErrorRate,
2868 p_cur->GW_SignalStrength.timingAdvance,
2869 p_cur->CDMA_SignalStrength.dbm,
2870 p_cur->CDMA_SignalStrength.ecio,
2871 p_cur->EVDO_SignalStrength.dbm,
2872 p_cur->EVDO_SignalStrength.ecio,
2873 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2874 p_cur->LTE_SignalStrength.signalStrength,
2875 p_cur->LTE_SignalStrength.rsrp,
2876 p_cur->LTE_SignalStrength.rsrq,
2877 p_cur->LTE_SignalStrength.rssnr,
2878 p_cur->LTE_SignalStrength.cqi,
2879 p_cur->LTE_SignalStrength.timingAdvance,
2880 p_cur->TD_SCDMA_SignalStrength.signalStrength,
2881 p_cur->TD_SCDMA_SignalStrength.bitErrorRate,
2882 p_cur->TD_SCDMA_SignalStrength.rscp,
2883 p_cur->WCDMA_SignalStrength.signalStrength,
2884 p_cur->WCDMA_SignalStrength.bitErrorRate,
2885 p_cur->WCDMA_SignalStrength.rscp,
2886 p_cur->WCDMA_SignalStrength.ecno);
2887#endif
2888 closeResponse;
2889
2890 if (signal_strength_printf != 0) {
2891 printf(
2892 "\n\n[QUERY][SIGNAL]\nsignalStrength=%d,\nbitErrorRate=%d,\nLTE_SS.signalStrength=%d,\n"
2893 "LTE_SS.rsrp=%d,\nLTE_SS.rsrq=%d,\nLTE_SS.rssnr=%d,\nLTE_SS.cqi=%d\n\n",
2894 p_cur->GW_SignalStrength.signalStrength,
2895 p_cur->GW_SignalStrength.bitErrorRate,
2896 p_cur->LTE_SignalStrength.signalStrength,
2897 p_cur->LTE_SignalStrength.rsrp,
2898 p_cur->LTE_SignalStrength.rsrq,
2899 p_cur->LTE_SignalStrength.rssnr,
2900 p_cur->LTE_SignalStrength.cqi);
2901 }
2902 } else {
2903 RLOGE("invalid response length");
2904 return RIL_ERRNO_INVALID_RESPONSE;
2905 }
2906
2907 return 0;
2908}
2909
2910static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2911 if ((response == NULL) || (responselen == 0)) {
2912 return responseVoid(p, response, responselen);
2913 } else {
2914 return responseCdmaSignalInfoRecord(p, response, responselen);
2915 }
2916}
2917
2918static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2919 if (response == NULL || responselen == 0) {
2920 RLOGE("invalid response: NULL");
2921 return RIL_ERRNO_INVALID_RESPONSE;
2922 }
2923
2924 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
2925 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
2926 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2927 return RIL_ERRNO_INVALID_RESPONSE;
2928 }
2929
2930 startResponse;
2931
2932 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2933 marshallSignalInfoRecord(p, *p_cur);
2934
2935 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2936 signal=%d]",
2937 printBuf,
2938 p_cur->isPresent,
2939 p_cur->signalType,
2940 p_cur->alertPitch,
2941 p_cur->signal);
2942
2943 closeResponse;
2944 return 0;
2945}
2946
2947static int responseCdmaCallWaiting(Parcel &p, void *response,
2948 size_t responselen) {
2949 if (response == NULL && responselen != 0) {
2950 RLOGE("invalid response: NULL");
2951 return RIL_ERRNO_INVALID_RESPONSE;
2952 }
2953
2954 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
2955 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
2956 }
2957
2958 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2959
2960 writeStringToParcel(p, p_cur->number);
2961 p.writeInt32(p_cur->numberPresentation);
2962 writeStringToParcel(p, p_cur->name);
2963 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2964
2965 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2966 p.writeInt32(p_cur->number_type);
2967 p.writeInt32(p_cur->number_plan);
2968 } else {
2969 p.writeInt32(0);
2970 p.writeInt32(0);
2971 }
2972
2973 printf("[EVENT][MT_CALL] phone number is %s\n",p_cur->number);
2974 startResponse;
2975 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2976 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2977 signal=%d,number_type=%d,number_plan=%d]",
2978 printBuf,
2979 p_cur->number,
2980 p_cur->numberPresentation,
2981 p_cur->name,
2982 p_cur->signalInfoRecord.isPresent,
2983 p_cur->signalInfoRecord.signalType,
2984 p_cur->signalInfoRecord.alertPitch,
2985 p_cur->signalInfoRecord.signal,
2986 p_cur->number_type,
2987 p_cur->number_plan);
2988 closeResponse;
2989
2990 return 0;
2991}
2992
2993static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2994 if (response == NULL && responselen != 0) {
2995 RLOGE("responseSimRefresh: invalid response: NULL");
2996 return RIL_ERRNO_INVALID_RESPONSE;
2997 }
2998
2999 startResponse;
3000 if (s_callbacks.version == 7) {
3001 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3002 p.writeInt32(p_cur->result);
3003 p.writeInt32(p_cur->ef_id);
3004 writeStringToParcel(p, p_cur->aid);
3005
3006 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3007 printBuf,
3008 p_cur->result,
3009 p_cur->ef_id,
3010 p_cur->aid);
3011 } else {
3012 int *p_cur = ((int *) response);
3013 p.writeInt32(p_cur[0]);
3014 p.writeInt32(p_cur[1]);
3015 writeStringToParcel(p, NULL);
3016
3017 appendPrintBuf("%sresult=%d, ef_id=%d",
3018 printBuf,
3019 p_cur[0],
3020 p_cur[1]);
3021 }
3022 closeResponse;
3023
3024 return 0;
3025}
3026
3027static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3028{
3029 if (response == NULL && responselen != 0) {
3030 RLOGE("invalid response: NULL");
3031 return RIL_ERRNO_INVALID_RESPONSE;
3032 }
3033
3034 if (responselen % sizeof(RIL_CellInfo) != 0) {
3035 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3036 (int)responselen, (int)sizeof(RIL_CellInfo));
3037 return RIL_ERRNO_INVALID_RESPONSE;
3038 }
3039
3040 int num = responselen / sizeof(RIL_CellInfo);
3041 p.writeInt32(num);
3042
3043 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3044 startResponse;
3045 int i;
3046 for (i = 0; i < num; i++) {
3047 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3048 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3049 p.writeInt32((int)p_cur->cellInfoType);
3050 p.writeInt32(p_cur->registered);
3051 p.writeInt32(p_cur->timeStampType);
3052 p.writeInt64(p_cur->timeStamp);
3053 switch(p_cur->cellInfoType) {
3054 case RIL_CELL_INFO_TYPE_GSM: {
3055 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3056 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3057 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3058 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3059 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3060 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3061 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3062 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3063
3064 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3065 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3066 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3067 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3068 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3069 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3070 break;
3071 }
3072 case RIL_CELL_INFO_TYPE_WCDMA: {
3073 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3074 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3075 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3076 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3077 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3078 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3079 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3080 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3081 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3082
3083 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3084 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3085 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3086 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3087 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3088 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3089 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3090 break;
3091 }
3092 case RIL_CELL_INFO_TYPE_CDMA: {
3093 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3094 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3095 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3096 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3097 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3098 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3099
3100 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3101 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3102 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3103 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3104 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3105
3106 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3107 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3108 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3109 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3110 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3111 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3112
3113 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3114 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3115 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3116 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3117 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3118 break;
3119 }
3120 case RIL_CELL_INFO_TYPE_LTE: {
3121 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3122 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3123 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3124 p_cur->CellInfo.lte.cellIdentityLte.ci,
3125 p_cur->CellInfo.lte.cellIdentityLte.pci,
3126 p_cur->CellInfo.lte.cellIdentityLte.tac);
3127
3128 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3129 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3130 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3131 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3132 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3133
3134 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3135 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3136 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3137 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3138 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3139 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3140 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3141 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3142 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3143 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3144 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3145 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3146 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3147 break;
3148 }
3149 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3150 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3151 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3152 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3153 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3154 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3155 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3156 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3157 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3158
3159 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3160 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3161 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3162 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3163 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3164 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3165 break;
3166 }
3167#ifdef TELEMATIC_5G_SUPPORT
3168 case RIL_CELL_INFO_TYPE_NR: {
3169 appendPrintBuf("%s NR id: mcc=%d,mnc=%d,nci=%d,pci=%d,tac=%d", printBuf,
3170 p_cur->CellInfo.nr.cellidentity.mcc,
3171 p_cur->CellInfo.nr.cellidentity.mnc,
3172 p_cur->CellInfo.nr.cellidentity.nci,
3173 p_cur->CellInfo.nr.cellidentity.pci,
3174 p_cur->CellInfo.nr.cellidentity.tac,
3175 p_cur->CellInfo.nr.cellidentity.nrarfcn);
3176
3177 p.writeInt32(p_cur->CellInfo.nr.cellidentity.mcc);
3178 p.writeInt32(p_cur->CellInfo.nr.cellidentity.mnc);
3179 p.writeInt32(p_cur->CellInfo.nr.cellidentity.nci);
3180 p.writeInt32(p_cur->CellInfo.nr.cellidentity.pci);
3181 p.writeInt32(p_cur->CellInfo.nr.cellidentity.tac);
3182 p.writeInt32(p_cur->CellInfo.nr.cellidentity.nrarfcn);
3183
3184 appendPrintBuf("%s NRSS: ssRsrp=%d,ssRsrq=%d,ssSinr=%d,csiRsrp=%d,csiRsrq=%d,csiSinr=%d", printBuf,
3185 p_cur->CellInfo.nr.signalStrength.ssRsrp,
3186 p_cur->CellInfo.nr.signalStrength.ssRsrq,
3187 p_cur->CellInfo.nr.signalStrength.ssSinr,
3188 p_cur->CellInfo.nr.signalStrength.csiRsrp,
3189 p_cur->CellInfo.nr.signalStrength.csiRsrq,
3190 p_cur->CellInfo.nr.signalStrength.csiSinr);
3191 p.writeInt32(p_cur->CellInfo.nr.signalStrength.ssRsrp);
3192 p.writeInt32(p_cur->CellInfo.nr.signalStrength.ssRsrq);
3193 p.writeInt32(p_cur->CellInfo.nr.signalStrength.ssSinr);
3194 p.writeInt32(p_cur->CellInfo.nr.signalStrength.csiRsrp);
3195 p.writeInt32(p_cur->CellInfo.nr.signalStrength.csiRsrq);
3196 p.writeInt32(p_cur->CellInfo.nr.signalStrength.csiSinr);
3197 break;
3198 }
3199#endif
3200 }
3201 p_cur += 1;
3202 }
3203 removeLastChar;
3204 closeResponse;
3205
3206 return 0;
3207}
3208
3209static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3210{
3211 if (response == NULL && responselen != 0) {
3212 RLOGE("invalid response: NULL");
3213 return RIL_ERRNO_INVALID_RESPONSE;
3214 }
3215
3216 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3217 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3218 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3219 return RIL_ERRNO_INVALID_RESPONSE;
3220 }
3221
3222 int num = responselen / sizeof(RIL_HardwareConfig);
3223 int i;
3224 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3225
3226 p.writeInt32(num);
3227
3228 startResponse;
3229 for (i = 0; i < num; i++) {
3230 switch (p_cur[i].type) {
3231 case RIL_HARDWARE_CONFIG_MODEM: {
3232 writeStringToParcel(p, p_cur[i].uuid);
3233 p.writeInt32((int)p_cur[i].state);
3234 p.writeInt32(p_cur[i].cfg.modem.rat);
3235 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3236 p.writeInt32(p_cur[i].cfg.modem.maxData);
3237 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3238
3239 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3240 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3241 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3242 break;
3243 }
3244 case RIL_HARDWARE_CONFIG_SIM: {
3245 writeStringToParcel(p, p_cur[i].uuid);
3246 p.writeInt32((int)p_cur[i].state);
3247 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3248
3249 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3250 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3251 break;
3252 }
3253 }
3254 }
3255 removeLastChar;
3256 closeResponse;
3257 return 0;
3258}
3259
3260static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3261 if (response == NULL) {
3262 RLOGE("invalid response: NULL");
3263 return RIL_ERRNO_INVALID_RESPONSE;
3264 }
3265
3266 if (responselen != sizeof (RIL_RadioCapability) ) {
3267 RLOGE("invalid response length was %d expected %d",
3268 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3269 return RIL_ERRNO_INVALID_RESPONSE;
3270 }
3271
3272 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3273 p.writeInt32(p_cur->version);
3274 p.writeInt32(p_cur->session);
3275 p.writeInt32(p_cur->phase);
3276 p.writeInt32(p_cur->rat);
3277 writeStringToParcel(p, p_cur->logicalModemUuid);
3278 p.writeInt32(p_cur->status);
3279
3280 startResponse;
3281 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
3282 rat=%d,logicalModemUuid=%s,status=%d]",
3283 printBuf,
3284 p_cur->version,
3285 p_cur->session,
3286 p_cur->phase,
3287 p_cur->rat,
3288 p_cur->logicalModemUuid,
3289 p_cur->status);
3290 closeResponse;
3291 return 0;
3292}
3293
3294static int responseSSData(Parcel &p, void *response, size_t responselen) {
3295 RLOGD("In responseSSData");
3296 int num;
3297
3298 if (response == NULL && responselen != 0) {
3299 RLOGE("invalid response length was %d expected %d",
3300 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3301 return RIL_ERRNO_INVALID_RESPONSE;
3302 }
3303
3304 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3305 RLOGE("invalid response length %d, expected %d",
3306 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3307 return RIL_ERRNO_INVALID_RESPONSE;
3308 }
3309
3310 startResponse;
3311 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3312 p.writeInt32(p_cur->serviceType);
3313 p.writeInt32(p_cur->requestType);
3314 p.writeInt32(p_cur->teleserviceType);
3315 p.writeInt32(p_cur->serviceClass);
3316 p.writeInt32(p_cur->result);
3317
3318 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3319 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3320 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3321 RLOGE("numValidIndexes is greater than max value %d, "
3322 "truncating it to max value", NUM_SERVICE_CLASSES);
3323 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3324 }
3325 /* number of call info's */
3326 p.writeInt32(p_cur->cfData.numValidIndexes);
3327
3328 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3329 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3330
3331 p.writeInt32(cf.status);
3332 p.writeInt32(cf.reason);
3333 p.writeInt32(cf.serviceClass);
3334 p.writeInt32(cf.toa);
3335 writeStringToParcel(p, cf.number);
3336 p.writeInt32(cf.timeSeconds);
3337 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3338 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3339 (char*)cf.number, cf.timeSeconds);
3340 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3341 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3342 }
3343 } else {
3344 p.writeInt32 (SS_INFO_MAX);
3345
3346 /* each int*/
3347 for (int i = 0; i < SS_INFO_MAX; i++) {
3348 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3349 RLOGD("Data: %d",p_cur->ssInfo[i]);
3350 p.writeInt32(p_cur->ssInfo[i]);
3351 }
3352 }
3353 removeLastChar;
3354 closeResponse;
3355
3356 return 0;
3357}
3358
3359static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3360 if ((reqType == SS_INTERROGATION) &&
3361 (serType == SS_CFU ||
3362 serType == SS_CF_BUSY ||
3363 serType == SS_CF_NO_REPLY ||
3364 serType == SS_CF_NOT_REACHABLE ||
3365 serType == SS_CF_ALL ||
3366 serType == SS_CF_ALL_CONDITIONAL)) {
3367 return true;
3368 }
3369 return false;
3370}
3371
3372static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3373 p.writeInt32(num_apps);
3374 startResponse;
3375 for (int i = 0; i < num_apps; i++) {
3376 p.writeInt32(appStatus[i].app_type);
3377 p.writeInt32(appStatus[i].app_state);
3378 p.writeInt32(appStatus[i].perso_substate);
3379 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3380 writeStringToParcel(p, (const char*)
3381 (appStatus[i].app_label_ptr));
3382 p.writeInt32(appStatus[i].pin1_replaced);
3383 p.writeInt32(appStatus[i].pin1);
3384 p.writeInt32(appStatus[i].pin2);
3385 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3386 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3387 printBuf,
3388 appStatus[i].app_type,
3389 appStatus[i].app_state,
3390 appStatus[i].perso_substate,
3391 appStatus[i].aid_ptr,
3392 appStatus[i].app_label_ptr,
3393 appStatus[i].pin1_replaced,
3394 appStatus[i].pin1,
3395 appStatus[i].pin2);
3396 }
3397 closeResponse;
3398}
3399
3400static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3401 int i;
3402
3403 if (response == NULL && responselen != 0) {
3404 RLOGE("invalid response: NULL");
3405 return RIL_ERRNO_INVALID_RESPONSE;
3406 }
3407
3408 RLOGD("responselen: %d, v6: %d, v5: %d", responselen, sizeof (RIL_CardStatus_v6),sizeof (RIL_CardStatus_v5));
3409 if (responselen == sizeof (RIL_CardStatus_v6)) {
3410 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3411 p.writeInt32(p_cur->card_state);
3412 p.writeInt32(p_cur->universal_pin_state);
3413 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3414 p.writeInt32(p_cur->cdma_subscription_app_index);
3415 p.writeInt32(p_cur->ims_subscription_app_index);
3416
3417 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3418 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3419 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3420
3421 p.writeInt32(p_cur->card_state);
3422 p.writeInt32(p_cur->universal_pin_state);
3423 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3424 p.writeInt32(p_cur->cdma_subscription_app_index);
3425 p.writeInt32(-1);
3426
3427 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3428 } else {
3429 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3430 return RIL_ERRNO_INVALID_RESPONSE;
3431 }
3432
3433 return 0;
3434}
3435
3436static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3437 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3438 p.writeInt32(num);
3439
3440 startResponse;
3441 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3442 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3443 for (int i = 0; i < num; i++) {
3444 p.writeInt32(p_cur[i]->fromServiceId);
3445 p.writeInt32(p_cur[i]->toServiceId);
3446 p.writeInt32(p_cur[i]->fromCodeScheme);
3447 p.writeInt32(p_cur[i]->toCodeScheme);
3448 p.writeInt32(p_cur[i]->selected);
3449
3450 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3451 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3452 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3453 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3454 p_cur[i]->selected);
3455 }
3456 closeResponse;
3457
3458 return 0;
3459}
3460
3461static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3462 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3463 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3464
3465 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3466 p.writeInt32(num);
3467
3468 startResponse;
3469 for (int i = 0 ; i < num ; i++ ) {
3470 p.writeInt32(p_cur[i]->service_category);
3471 p.writeInt32(p_cur[i]->language);
3472 p.writeInt32(p_cur[i]->selected);
3473
3474 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3475 selected =%d], ",
3476 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3477 p_cur[i]->selected);
3478 }
3479 closeResponse;
3480
3481 return 0;
3482}
3483
3484static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3485 int num;
3486 int digitCount;
3487 int digitLimit;
3488 uint8_t uct;
3489 void* dest;
3490
3491 RLOGD("Inside responseCdmaSms");
3492
3493 if (response == NULL && responselen != 0) {
3494 RLOGE("invalid response: NULL");
3495 return RIL_ERRNO_INVALID_RESPONSE;
3496 }
3497
3498 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
3499 RLOGE("invalid response length was %d expected %d",
3500 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3501 return RIL_ERRNO_INVALID_RESPONSE;
3502 }
3503
3504 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3505 p.writeInt32(p_cur->uTeleserviceID);
3506 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3507 p.writeInt32(p_cur->uServicecategory);
3508 p.writeInt32(p_cur->sAddress.digit_mode);
3509 p.writeInt32(p_cur->sAddress.number_mode);
3510 p.writeInt32(p_cur->sAddress.number_type);
3511 p.writeInt32(p_cur->sAddress.number_plan);
3512 RLOGD("MT CDMA SMS: sAddress.number_plan = %d", p_cur->sAddress.number_plan);
3513 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3514 RLOGD("MT CDMA SMS: sAddress.number_of_digits = %d", p_cur->sAddress.number_of_digits);
3515 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3516 String8 str(""), temp;
3517 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3518 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3519 temp = String8::format("%d,", p_cur->sAddress.digits[digitCount]);
3520 str.append(temp);
3521 }
3522 RLOGD("MT CDMA SMS: sAddress.digits: {%s}", str.isEmpty()? "" : str.string());
3523
3524 p.writeInt32(p_cur->sSubAddress.subaddressType);
3525 RLOGD("MT CDMA SMS: sSubAddress.subaddressType = %d", p_cur->sSubAddress.subaddressType);
3526 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3527 RLOGD("MT CDMA SMS: sSubAddress.odd = %d", p_cur->sSubAddress.odd);
3528 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3529 RLOGD("MT CDMA SMS: sSubAddress.number_of_digits = %d", p_cur->sSubAddress.number_of_digits);
3530 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3531 str.clear();
3532 temp.clear();
3533 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3534 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3535 temp = String8::format("%d,", p_cur->sSubAddress.digits[digitCount]);
3536 str.append(temp);
3537 }
3538 RLOGD("MT CDMA SMS: sSubAddress.digits: {%s}", str.isEmpty() ? "" : str.string());
3539
3540 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3541 RLOGD("MT CDMA SMS: uBearerDataLen = %d", p_cur->uBearerDataLen);
3542 p.writeInt32(p_cur->uBearerDataLen);
3543 str.clear();
3544 temp.clear();
3545 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3546 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3547 temp = String8::format("%d,", p_cur->aBearerData[digitCount]);
3548 str.append(temp);
3549 }
3550 RLOGD("MT CDMA SMS: aBearerData: {%s}", str.isEmpty() ? "" : str.string());
3551
3552 startResponse;
3553 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3554 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3555 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3556 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3557 closeResponse;
3558 resposeCdmaSms(p_cur);
3559 return 0;
3560}
3561
3562static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3563{
3564 int num = responselen / sizeof(RIL_DcRtInfo);
3565 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3566 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3567 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3568 return RIL_ERRNO_INVALID_RESPONSE;
3569 }
3570
3571 startResponse;
3572 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3573 p.writeInt64(pDcRtInfo->time);
3574 p.writeInt32(pDcRtInfo->powerState);
3575 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3576 pDcRtInfo->time,
3577 pDcRtInfo->powerState);
3578 closeResponse;
3579
3580 return 0;
3581}
3582
3583static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3584 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3585 if (response == NULL) {
3586 RLOGE("invalid response: NULL");
3587 }
3588 else {
3589 RLOGE("responseLceStatus: invalid response length %d expecting len: %d",
3590 sizeof(RIL_LceStatusInfo), responselen);
3591 }
3592 return RIL_ERRNO_INVALID_RESPONSE;
3593 }
3594
3595 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3596 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3597 p.writeInt32(p_cur->actual_interval_ms);
3598
3599 startResponse;
3600 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3601 p_cur->lce_status, p_cur->actual_interval_ms);
3602 closeResponse;
3603
3604 return 0;
3605}
3606
3607static int responseLceData(Parcel &p, void *response, size_t responselen) {
3608 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3609 if (response == NULL) {
3610 RLOGE("invalid response: NULL");
3611 }
3612 else {
3613 RLOGE("responseLceData: invalid response length %d expecting len: %d",
3614 sizeof(RIL_LceDataInfo), responselen);
3615 }
3616 return RIL_ERRNO_INVALID_RESPONSE;
3617 }
3618
3619 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3620 p.writeInt32(p_cur->last_hop_capacity_kbps);
3621
3622 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3623 p.write((void *)&(p_cur->confidence_level), 1);
3624 p.write((void *)&(p_cur->lce_suspended), 1);
3625
3626 startResponse;
3627 appendPrintBuf("LCE info received: capacity %d confidence level %d and suspended %d",
3628 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3629 p_cur->lce_suspended);
3630 closeResponse;
3631
3632 return 0;
3633}
3634
3635static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3636 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3637 if (response == NULL) {
3638 RLOGE("invalid response: NULL");
3639 }
3640 else {
3641 RLOGE("responseActivityData: invalid response length %d expecting len: %d",
3642 sizeof(RIL_ActivityStatsInfo), responselen);
3643 }
3644 return RIL_ERRNO_INVALID_RESPONSE;
3645 }
3646
3647 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3648 p.writeInt32(p_cur->sleep_mode_time_ms);
3649 p.writeInt32(p_cur->idle_mode_time_ms);
3650 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3651 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3652 }
3653 p.writeInt32(p_cur->rx_mode_time_ms);
3654
3655 startResponse;
3656 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",
3657 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3658 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3659 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3660 closeResponse;
3661
3662 return 0;
3663}
3664
3665static int responseSmsSimMemStatus(Parcel &p, void *response, size_t responselen) {
3666 printf("=============%s\n", __FUNCTION__);
3667 if (response == NULL) {
3668 RLOGE("invalid response: NULL");
3669 return RIL_ERRNO_INVALID_RESPONSE;
3670 }
3671
3672 if (responselen != sizeof (RIL_SMS_Memory_Status) ) {
3673 RLOGE("invalid response length %d expected %d",
3674 (int)responselen, (int)sizeof (RIL_SMS_Memory_Status));
3675 return RIL_ERRNO_INVALID_RESPONSE;
3676 }
3677
3678 RIL_SMS_Memory_Status *p_cur = (RIL_SMS_Memory_Status *) response;
3679
3680 p.writeInt32(p_cur->used);
3681 p.writeInt32(p_cur->total);
3682
3683 startResponse;
3684 appendPrintBuf("%s%d,%d", printBuf, p_cur->used, p_cur->total);
3685 closeResponse;
3686
3687 printf("%s%d,%d\n", printBuf, p_cur->used, p_cur->total);
3688 RLOGE("===========================%s%d,%d", printBuf, p_cur->used, p_cur->total);
3689 return 0;
3690}
3691
3692void RIL_startEventLoop(void);
3693extern "C" void
3694RIL_register (const RIL_RadioFunctions *callbacks) {
3695 if (callbacks == NULL) {
3696 RLOGE("RIL_register: RIL_RadioFunctions * null");
3697 return;
3698 }
3699#if 0
3700 if (callbacks->version < RIL_VERSION_MIN) {
3701 RLOGE("RIL_register: version %d is to old, min version is %d",
3702 callbacks->version, RIL_VERSION_MIN);
3703 return;
3704 }
3705 if (callbacks->version > RIL_VERSION) {
3706 RLOGE("RIL_register: version %d is too new, max version is %d",
3707 callbacks->version, RIL_VERSION);
3708 return;
3709 }
3710#endif
3711 RLOGE("RIL_register: RIL version %d", callbacks->version);
3712
3713 if (s_registerCalled > 0) {
3714 RLOGE("RIL_register has been called more than once. "
3715 "Subsequent call ignored");
3716 return;
3717 }
3718
3719 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3720
3721 s_registerCalled = 1;
3722
3723 pthread_mutex_lock(&s_InitMutex);
3724 if(utils::is_support_dsds()) {
3725 while (s_isConnected[0] == 0 || s_isConnected[1] == 0) {
3726 pthread_cond_wait(&s_InitCond, &s_InitMutex);
3727 }
3728 } else {
3729 while (s_isConnected[0] == 0 && s_isConnected[1] == 0) {
3730 pthread_cond_wait(&s_InitCond, &s_InitMutex);
3731 }
3732 }
3733 pthread_mutex_unlock(&s_InitMutex);
3734 initCoditions();
3735 // New rild impl calls RIL_startEventLoop() first
3736 // old standalone impl wants it here.
3737
3738 if (s_started == 0) {
3739 RIL_startEventLoop();
3740 }
3741
3742}
3743
3744#if 0
3745static int
3746checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
3747 int ret = 0;
3748 /* Hook for current context
3749 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3750 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
3751 /* pendingRequestsHook refer to &s_pendingRequests */
3752 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
3753
3754 if (pRI == NULL) {
3755 return 0;
3756 }
3757
3758#if (SIM_COUNT >= 2)
3759 if (pRI->socket_id == RIL_SOCKET_2) {
3760 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3761 pendingRequestsHook = &s_pendingRequests_socket2;
3762 }
3763#if (SIM_COUNT >= 3)
3764 if (pRI->socket_id == RIL_SOCKET_3) {
3765 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3766 pendingRequestsHook = &s_pendingRequests_socket3;
3767 }
3768#endif
3769#if (SIM_COUNT >= 4)
3770 if (pRI->socket_id == RIL_SOCKET_4) {
3771 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3772 pendingRequestsHook = &s_pendingRequests_socket4;
3773 }
3774#endif
3775#endif
3776 pthread_mutex_lock(pendingRequestsMutexHook);
3777
3778 for(RequestInfo **ppCur = pendingRequestsHook
3779 ; *ppCur != NULL
3780 ; ppCur = &((*ppCur)->p_next)
3781 ) {
3782 if (pRI == *ppCur) {
3783 ret = 1;
3784
3785 *ppCur = (*ppCur)->p_next;
3786 break;
3787 }
3788 }
3789
3790 pthread_mutex_unlock(pendingRequestsMutexHook);
3791
3792 return ret;
3793}
3794
3795#endif
3796
3797extern "C" void
3798RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
3799 RequestInfo *pRI;
3800 int ret;
3801 //int fd = s_ril_param_socket.fdCommand;
3802 size_t errorOffset;
3803 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3804
3805 pRI = (RequestInfo *)t;
3806#if 0
3807 if (!checkAndDequeueRequestInfo(pRI)) {
3808 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
3809 return;
3810 }
3811#endif
3812
3813 socket_id = pRI->socket_id;
3814#if 0
3815#if (SIM_COUNT >= 2)
3816 if (socket_id == RIL_SOCKET_2) {
3817 fd = s_ril_param_socket2.fdCommand;
3818 }
3819#if (SIM_COUNT >= 3)
3820 if (socket_id == RIL_SOCKET_3) {
3821 fd = s_ril_param_socket3.fdCommand;
3822 }
3823#endif
3824#if (SIM_COUNT >= 4)
3825 if (socket_id == RIL_SOCKET_4) {
3826 fd = s_ril_param_socket4.fdCommand;
3827 }
3828#endif
3829#endif
3830#endif
3831#if VDBG
3832 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
3833#endif
3834
3835 if (pRI->local > 0) {
3836 // Locally issued command...void only!
3837 // response does not go back up the command socket
3838 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
3839
3840 goto done;
3841 }
3842
3843 appendPrintBuf("[%x][SIM%d]< %s", pRI->token,socket_id,requestToString(pRI->pCI->requestNumber));
3844
3845 if (pRI->cancelled == 0) {
3846 Parcel p;
3847
3848 p.writeInt32 (RESPONSE_SOLICITED);
3849 p.writeInt32 (pRI->pCI->requestNumber);
3850 /*warren add for t800 ril servie 2021/12/15 start*/
3851 p.writeInt32(socket_id);
3852 /*warren add for t800 ril servie 2021/12/15 end*/
3853 errorOffset = p.dataPosition();
3854
3855 p.writeInt32 (e);
3856
3857 if (response != NULL) {
3858 // there is a response payload, no matter success or not.
3859 ret = pRI->pCI->responseFunction(p, response, responselen);
3860
3861 /* if an error occurred, rewind and mark it */
3862 if (ret != 0) {
3863 RLOGE ("responseFunction error, ret %d", ret);
3864 p.setDataPosition(errorOffset);
3865 p.writeInt32 (ret);
3866 }
3867 switch (pRI->pCI->requestNumber) {
3868 case RIL_REQUEST_QUERY_FACILITY_LOCK:
3869 {
3870 int numInts = responselen / sizeof(int);
3871 if(numInts > 0) {
3872 int *p_int = (int *) response;
3873 RLOGD("RIL_REQUEST_QUERY_FACILITY_LOCK: %s", (p_int[0] != 0 ? "PIN enable" : "PIN1 disable"));
3874 } else {
3875 RLOGD("RIL_REQUEST_QUERY_FACILITY_LOCK response numInts: %d", numInts);
3876 }
3877 break;
3878 }
3879 case RIL_REQUEST_IMS_REGISTRATION_STATE:
3880 {
3881 int numInts = responselen / sizeof(int);
3882 if(numInts > 0) {
3883 int *p_int = (int *) response;
3884 printf("[SIM%d][QUERY][REG_STATUS] IMS is %s\n", socket_id, (p_int[0] == 0 ? "Not registered" : "Registered"));
3885 } else {
3886 RLOGD("RIL_REQUEST_IMS_REGISTRATION_STATE response numInts: %d", numInts);
3887 }
3888 break;
3889 }
3890 case RIL_REQUEST_VOICE_REGISTRATION_STATE:
3891 {
3892 char **p_cur = (char **) response;
3893 int numStrings = responselen / sizeof(char *);
3894 update_reg_voice_service_state(RIL_REQUEST_VOICE_REGISTRATION_STATE, (char *)p_cur[0], socket_id, pRI->token);
3895 int tempVal=0;
3896 memset(respStr,0,sizeof(respStr));
3897 tempVal = atoi((char *)p_cur[0]);
3898 if(tempVal == 1 || tempVal==5){
3899 sprintf(respStr,"[SIM%d]%s register is in service!",socket_id +1, respStr);
3900 }else{
3901 sprintf(respStr,"[SIM%d]%s register is not in service!",socket_id +1, respStr);
3902 }
3903 if(numStrings >=4 && p_cur[3] != NULL)
3904 {
3905 update_reg_voice_radio_tech(RIL_REQUEST_VOICE_REGISTRATION_STATE, atoi((char *)p_cur[3]), socket_id, pRI->token);
3906 tempVal = atoi((char *)p_cur[3]);
3907 if(tempVal == RADIO_TECH_LTE){//4G
3908 sprintf(respStr,"%s radioTech is 4G!",respStr);
3909 } else if( tempVal == RADIO_TECH_GSM ||
3910 tempVal == RADIO_TECH_GPRS ||
3911 tempVal == RADIO_TECH_EDGE ||
3912 tempVal == RADIO_TECH_IS95A ||
3913 tempVal == RADIO_TECH_IS95B ||
3914 tempVal == RADIO_TECH_1xRTT) { //2G
3915 sprintf(respStr,"%s radioTech is 2G!",respStr);
3916 } else if( tempVal == RADIO_TECH_UMTS ||
3917 tempVal == RADIO_TECH_HSDPA ||
3918 tempVal == RADIO_TECH_HSUPA ||
3919 tempVal == RADIO_TECH_HSPA ||
3920 tempVal == RADIO_TECH_EHRPD ||
3921 tempVal == RADIO_TECH_HSPAP ||
3922 tempVal == RADIO_TECH_TD_SCDMA ||
3923 tempVal == RADIO_TECH_EVDO_0 ||
3924 tempVal == RADIO_TECH_EVDO_A ||
3925 tempVal == RADIO_TECH_EVDO_B) { //3G
3926 sprintf(respStr,"%s radioTech is 3G!",respStr);
3927#ifdef TELEMATIC_5G_SUPPORT
3928 } else if(tempVal == RADIO_TECH_NR) { //5G
3929 sprintf(respStr,"%s radioTech is 5G!",respStr);
3930#endif
3931 } else { //unknown
3932 sprintf(respStr,"%s radioTech is unkown!",respStr);
3933 }
3934 }
3935 sprintf(respStr,"%s\n",respStr);
3936 break;
3937 }
3938 case RIL_REQUEST_DATA_REGISTRATION_STATE:
3939 {
3940 char **p_cur = (char **) response;
3941 int numStrings = responselen / sizeof(char *);
3942 update_reg_data_service_state(RIL_REQUEST_DATA_REGISTRATION_STATE, (char *)p_cur[0], socket_id, pRI->token);
3943 if(numStrings >=4 && p_cur[3] != NULL)
3944 {
3945 update_reg_data_radio_tech(RIL_REQUEST_DATA_REGISTRATION_STATE, atoi((char *)p_cur[3]), socket_id, pRI->token);
3946 }
3947 break;
3948 }
3949 case RIL_REQUEST_GET_CURRENT_CALLS:
3950 {
3951 update_call_state(response,responselen, socket_id);
3952 int num = responselen / sizeof(RIL_Call *);
3953 speechonoff(num);
3954 printf("%s\n", printBuf);
3955 break;
3956 }
3957 case RIL_REQUEST_SETUP_DATA_CALL:
3958 {
3959 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
3960 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
3961 updateRILDataCallResponsev6(num,p_cur);
3962 break;
3963 }
3964 case RIL_REQUEST_GET_SIM_STATUS:
3965 {
3966 if (responselen == sizeof (RIL_CardStatus_v6)) {
3967 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3968 updateCardStatusV6(p_cur, socket_id);
3969 }
3970 break;
3971 }
3972 case RIL_REQUEST_VOICE_RADIO_TECH:
3973 {
3974 update_voice_radio_tech(((int *) response)[0], socket_id);
3975 break;
3976 }
3977 case RIL_REQUEST_GET_RADIO_CAPABILITY:
3978 {
3979 update_radio_capa((RIL_RadioCapability *) response, socket_id);
3980 break;
3981 }
3982 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE:
3983 {
3984 update_preferred_network_type(((int *) response)[0], socket_id);
3985 break;
3986 }
3987 case RIL_REQUEST_DELETE_SMS_ON_SIM:
3988 {
3989 setSimSmsStorageFullFlag(false);
3990 break;
3991 }
3992 case RIL_REQUEST_SEND_SMS:
3993 case RIL_REQUEST_SEND_SMS_EXPECT_MORE:
3994 case RIL_REQUEST_IMS_SEND_SMS:
3995 {
3996 //for auto save sms to sim
3997 sendStatusWriteSmsToSim(socket_id);
3998 break;
3999 }
4000 case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE:
4001 {
4002 int numInts = responselen / sizeof(int);
4003 if(numInts > 0) {
4004 int *p_int = (int *) response;
4005 RLOGD("RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: %d", p_int[0]);
4006 if(p_int[0] == ECALL_DEREGISTRATION)
4007 {
4008 gostSetInNeedRegister(true);
4009 }
4010
4011 } else {
4012 RLOGD("RIL_REQUEST_ECALL_SET_REGISTRATION_STATE response numInts: %d", numInts);
4013 }
4014 break;
4015 }
4016 default:
4017 break;
4018 }
4019 }
4020
4021 if (e != RIL_E_SUCCESS) {
4022 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4023 }
4024
4025 if ((pRI->token & RIL_TOKEN_MARK) == RIL_TOKEN_MARK) {
4026 printf("%s\n", printBuf ? printBuf : "unkonwn");
4027 } else if (((pRI->pCI->requestNumber == RIL_REQUEST_DEVICE_IDENTITY)
4028 || (pRI->pCI->requestNumber == RIL_REQUEST_OEM_HOOK_RAW))
4029 && (pRI->token & INIT_TOKEN_MARK) == INIT_TOKEN_MARK) {
4030 printf("%s\n", printBuf ? printBuf : "unkonwn");
4031 if (pRI->pCI->requestNumber == RIL_REQUEST_DEVICE_IDENTITY) {
4032 if (e != RIL_E_SUCCESS) {
4033 printf(
4034 "*******************************************\n*** NOTICE: IMEI don't wirite in slot%d ***\n*******************************************\n",
4035 socket_id);
4036 }
4037 }
4038 }
4039
4040#if 0
4041 if (fd < 0) {
4042 RLOGD ("RIL onRequestComplete: Command channel closed");
4043 }
4044#endif
4045 LYNQ_RIL_respSocket(p,t);
4046 sendResponse(p, socket_id);
4047 }
4048#if ATCI_ENABLE_RESPONSE
4049 if((pRI->token & ATCI_TOKEN_MARK) == ATCI_TOKEN_MARK) //ATCI_Rsp
4050 {
4051 int error;
4052 memset(Respose_buf, 0, sizeof(Respose_buf));
4053 if(e != RIL_E_SUCCESS)
4054 error = 1; //fail
4055 else
4056 error = 0; //ok
4057 ATCIResponse(pRI->token,error,Respose_buf, pRI->pCI->requestNumber);
4058 }
4059#endif
4060 if(pRI->pCI->requestNumber == RIL_REQUEST_VOICE_REGISTRATION_STATE && (pRI->token & RIL_TOKEN_MARK) == RIL_TOKEN_MARK){
4061 int len_s = sendto(server_socket_fd,respStr,strlen(respStr),0,(struct sockaddr *)&client_addr,sizeof(client_addr));
4062 }
4063 RLOGW("RIL_onRequestComplete %s end!",requestToString(pRI->pCI->requestNumber));
4064 if((pRI->token&BLOCK_MARK) == BLOCK_MARK) {
4065 //need wakeup dispatch function
4066 BLOCK_LOCK();
4067 wakeup_token = pRI->token;
4068 RLOGW("RIL_onRequestComplete wakeup, token is %x!",wakeup_token);
4069 BLOCK_WAKEUP();
4070 BLOCK_UNLOCK();
4071 }
4072 switch (pRI->pCI->requestNumber) {
4073 case RIL_REQUEST_RADIO_POWER:
4074 speciaRequest_wakeup();
4075 break;
4076 case RIL_REQUEST_SET_RADIO_CAPABILITY:
4077 {
4078 if(utils::is_support_dsds()) {
4079 for (int id = 0; id < SIM_COUNT; id++) {
4080 ARspRequest(RIL_REQUEST_ALLOW_DATA, (RIL_SOCKET_ID)id);
4081 }
4082 }
4083 break;
4084 }
4085 case RIL_REQUEST_ALLOW_DATA:
4086 {
4087 if(utils::is_support_dsds() && isNeedConnect() && get_default_sim_data() == socket_id) {
xja1c30b82022-01-25 16:13:48 +08004088 RLOGD("wait and recreate PDN with sim switch");
lh7b0674a2022-01-10 00:34:35 -08004089 resetConnect();
xja1c30b82022-01-25 16:13:48 +08004090 sleep(WAIT_TIME_FOR_SIM_SWITCH);
lh7b0674a2022-01-10 00:34:35 -08004091 setupDataCall(0, NULL, (RIL_SOCKET_ID)0, NULL);
4092 }
4093 break;
4094 }
4095#ifdef KEEP_ALIVE
4096 case RIL_REQUEST_START_KEEPALIVE_PRO:
4097 case RIL_REQUEST_STOP_KEEPALIVE_PRO:
4098 {
4099 handleKeepAliveResponse(pRI->pCI->requestNumber, response, responselen, socket_id, (e != RIL_E_SUCCESS));
4100 break;
4101 }
4102#endif /*KEEP_ALIVE*/
4103 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC:
4104 {
4105 if(e == RIL_E_SUCCESS)
4106 {
4107 gostSetInNeedRegister(false);
4108 gostFastEcallFlgSet(false);
4109 }
4110 else
4111 {
4112 gostNetworkSelectionSet(socket_id);
4113 }
4114 break;
4115 }
4116 default:
4117 break;
4118 }
4119done:
4120 free(pRI);
4121}
4122
4123
4124static void
4125grabPartialWakeLock() {
4126 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4127}
4128
4129static void
4130releaseWakeLock() {
4131 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4132}
4133
4134
4135static int
4136decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4137 switch (radioState) {
4138 case RADIO_STATE_SIM_NOT_READY:
4139 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4140 case RADIO_STATE_SIM_READY:
4141 return RADIO_TECH_UMTS;
4142
4143 case RADIO_STATE_RUIM_NOT_READY:
4144 case RADIO_STATE_RUIM_READY:
4145 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4146 case RADIO_STATE_NV_NOT_READY:
4147 case RADIO_STATE_NV_READY:
4148 return RADIO_TECH_1xRTT;
4149
4150 default:
4151 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
4152 return -1;
4153 }
4154}
4155
4156static int
4157decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4158 switch (radioState) {
4159 case RADIO_STATE_SIM_NOT_READY:
4160 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4161 case RADIO_STATE_SIM_READY:
4162 case RADIO_STATE_RUIM_NOT_READY:
4163 case RADIO_STATE_RUIM_READY:
4164 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4165 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4166
4167 case RADIO_STATE_NV_NOT_READY:
4168 case RADIO_STATE_NV_READY:
4169 return CDMA_SUBSCRIPTION_SOURCE_NV;
4170
4171 default:
4172 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
4173 return -1;
4174 }
4175}
4176
4177static int
4178decodeSimStatus (RIL_RadioState radioState) {
4179 switch (radioState) {
4180 case RADIO_STATE_SIM_NOT_READY:
4181 case RADIO_STATE_RUIM_NOT_READY:
4182 case RADIO_STATE_NV_NOT_READY:
4183 case RADIO_STATE_NV_READY:
4184 return -1;
4185 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4186 case RADIO_STATE_SIM_READY:
4187 case RADIO_STATE_RUIM_READY:
4188 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4189 return radioState;
4190 default:
4191 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
4192 return -1;
4193 }
4194}
4195
4196static bool is3gpp2(int radioTech) {
4197 switch (radioTech) {
4198 case RADIO_TECH_IS95A:
4199 case RADIO_TECH_IS95B:
4200 case RADIO_TECH_1xRTT:
4201 case RADIO_TECH_EVDO_0:
4202 case RADIO_TECH_EVDO_A:
4203 case RADIO_TECH_EVDO_B:
4204 case RADIO_TECH_EHRPD:
4205 return true;
4206 default:
4207 return false;
4208 }
4209}
4210
4211/* If RIL sends SIM states or RUIM states, store the voice radio
4212 * technology and subscription source information so that they can be
4213 * returned when telephony framework requests them
4214 */
4215static RIL_RadioState
4216processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
4217
4218 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4219 int newVoiceRadioTech;
4220 int newCdmaSubscriptionSource;
4221 int newSimStatus;
4222
4223 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4224 from Radio State and send change notifications if there has been a change */
4225 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4226 if(newVoiceRadioTech != voiceRadioTech) {
4227 voiceRadioTech = newVoiceRadioTech;
4228 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4229 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
4230 }
4231 if(is3gpp2(newVoiceRadioTech)) {
4232 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4233 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4234 cdmaSubscriptionSource = newCdmaSubscriptionSource;
4235 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4236 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
4237 }
4238 }
4239 newSimStatus = decodeSimStatus(newRadioState);
4240 if(newSimStatus != simRuimStatus) {
4241 simRuimStatus = newSimStatus;
4242 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
4243 }
4244
4245 /* Send RADIO_ON to telephony */
4246 newRadioState = RADIO_STATE_ON;
4247 }
4248
4249 return newRadioState;
4250}
4251
4252
4253#if defined(ANDROID_MULTI_SIM)
4254extern "C"
4255void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
4256 size_t datalen, RIL_SOCKET_ID socket_id)
4257#else
4258extern "C"
4259void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
4260 size_t datalen)
4261#endif
4262{
4263 int unsolResponseIndex;
4264 int ret;
4265 int64_t timeReceived = 0;
4266 bool shouldScheduleTimeout = false;
4267 RIL_RadioState newState;
lhf6eea122022-01-20 19:32:14 -08004268 int temp = 0;
4269 char *tempChar=NULL;
lh7b0674a2022-01-10 00:34:35 -08004270 RIL_SOCKET_ID soc_id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
4271
4272#if defined(ANDROID_MULTI_SIM)
4273 soc_id = socket_id;
4274#endif
4275
4276 handle_wakeup_reason(unsolResponse);
4277
4278 if (s_registerCalled == 0) {
4279 // Ignore RIL_onUnsolicitedResponse before RIL_register
4280 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
4281 return;
4282 }
4283 if(onSupports(unsolResponse) == 0)
4284 {
4285 RLOGE("unsupported unsolicited response code %d", unsolResponse);
4286 return;
4287 }
4288
4289#ifdef TARGET_PLATFORM_MT2635
4290 //Reset modem, exit DemoApp.
4291 if(unsolResponse==RIL_UNSOL_MAL_RESTART ) {
4292 RLOGD("Modem Reset, Exit DemoApp!");
4293 printf("Modem Reset, Exit DemoApp!\n");
4294 speechonoff(0);
4295 mixer_reset_set(1);
4296 com_quit(0,NULL,soc_id,NULL);
4297 }
4298#endif
4299 if (unsolResponse < RIL_UNSOL_VENDOR_BASE) {
4300 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4301 }
4302#if 0
4303 WakeType wakeType;
4304 if (unsolResponse >= RIL_UNSOL_VENDOR_BASE) {
4305 //unsolResponseIndex = unsolResponse - RIL_UNSOL_VENDOR_BASE;
4306 wakeType = WAKE_PARTIAL;
4307 } else {
4308 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4309 wakeType = s_unsolResponses[unsolResponseIndex].wakeType;
4310 }
4311
4312 // Grab a wake lock if needed for this reponse,
4313 // as we exit we'll either release it immediately
4314 // or set a timer to release it later.
4315 switch (wakeType) {
4316 case WAKE_PARTIAL:
4317 grabPartialWakeLock();
4318 shouldScheduleTimeout = false;
4319 break;
4320
4321 case DONT_WAKE:
4322 default:
4323 // No wake lock is grabed so don't set timeout
4324 shouldScheduleTimeout = false;
4325 break;
4326 }
4327
4328 // Mark the time this was received, doing this
4329 // after grabing the wakelock incase getting
4330 // the elapsedRealTime might cause us to goto
4331 // sleep.
4332 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4333 timeReceived = elapsedRealtime();
4334 }
4335#endif
4336 appendPrintBuf("[UNSL][SIM%d]< %s", soc_id, requestToString(unsolResponse));
4337
4338 Parcel p;
lh7b0674a2022-01-10 00:34:35 -08004339 p.writeInt32 (RESPONSE_UNSOLICITED);
4340 p.writeInt32 (unsolResponse);
4341 /*Warren add for t800 ril service 2021/12/16 start*/
4342 p.writeInt32 (soc_id);
4343 /*Warren add for t800 ril service 2021/12/16 end*/
4344 if (unsolResponse >= RIL_UNSOL_VENDOR_BASE) {
4345 UnsolResponseInfo* unsolRspInof = find_mtk_unsol_command(unsolResponse);
4346 if(unsolRspInof == NULL){
4347 RLOGE("no unsolicited response function -- %d", unsolResponse);
4348 return;
4349 } else {
4350 ret = unsolRspInof->responseFunction(p,const_cast<void*>(data),datalen);
4351 }
4352 } else {
4353 ret = s_unsolResponses[unsolResponseIndex].responseFunction(p, const_cast<void*>(data), datalen);
4354 }
4355 if (ret != 0) {
4356 // Problem with the response. Don't continue;
4357 goto error_exit;
4358 }
4359
4360 // some things get more payload
4361 switch(unsolResponse) {
4362 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
4363 newState = CALL_ONSTATEREQUEST(soc_id);
4364 p.writeInt32(newState);
4365 appendPrintBuf("%s {%s}", printBuf,
4366 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
4367 break;
4368
4369#if 0
4370 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4371 // Store the time that this was received so the
4372 // handler of this message can account for
4373 // the time it takes to arrive and process. In
4374 // particular the system has been known to sleep
4375 // before this message can be processed.
4376 p.writeInt64(timeReceived);
4377 break;
4378#endif
4379 }
4380
4381#if VDBG
4382 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4383#endif
lhf6eea122022-01-20 19:32:14 -08004384 //ret = sendResponse(p, soc_id);
lh7b0674a2022-01-10 00:34:35 -08004385
4386//unsol trigger other things.
4387 switch(unsolResponse) {
4388 //case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
4389 //ARspRequest(RIL_REQUEST_GET_CURRENT_CALLS, soc_id);
4390 //break;
4391 case RIL_UNSOL_CALL_RING:
4392 callRing(soc_id);
4393 break;
4394 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
4395 updateIccCardState(soc_id);
4396 break;
4397 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
4398 getVoiceAndDataRegistrationState(soc_id);
4399 break;
4400 case RIL_UNSOL_RESPONSE_NEW_SMS:
lhf6eea122022-01-20 19:32:14 -08004401 responseNewSMS((const char*)data, datalen,soc_id,unsolResponse,p);
lh7b0674a2022-01-10 00:34:35 -08004402 unreadStatusWriteSMSToSim((const char*)data, datalen, soc_id);
4403 sendSMSACK(soc_id);
4404 break;
4405 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
4406 {
4407 RLOGD("Receive RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS data: %s, length: %d", (char*)data, datalen);
4408 break;
4409 }
4410 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
4411 sendSMSACK(soc_id);
4412 break;
4413 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
4414 updateRadioStatus(newState,soc_id);
4415 break;
4416 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
4417 {
4418 ARspRequest(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, soc_id);
4419 break;
4420 }
4421 case RIL_UNSOL_STK_PROACTIVE_COMMAND:
4422 {
4423 RLOGD("STk proactive command raw date: %s, length: %d", (char*)data, datalen);
4424 handleStkCommand((char*)data, datalen,soc_id);
4425 break;
4426 }
4427 case RIL_UNSOL_RIL_CONNECTED:
4428 {
4429 RLOGD("vendor-ril socket(%d) connect start", soc_id);
4430 pthread_mutex_lock(&s_InitMutex);
4431 s_isConnected[soc_id] = 1;
4432 if(utils::is_support_dsds()) {
4433 if (s_isConnected[0] == 1 && s_isConnected[1] == 1) {
4434 pthread_cond_broadcast(&s_InitCond);
4435 }
4436 } else {
4437 if (s_isConnected[0] == 1 || s_isConnected[1] == 1) {
4438 pthread_cond_broadcast(&s_InitCond);
4439 }
4440 }
4441 pthread_mutex_unlock(&s_InitMutex);
4442 RLOGD("vendor-ril socket(%d) connect end", soc_id);
4443 break;
4444 }
4445 case RIL_UNSOL_TX_POWER: {
4446 int *p_int = (int *) data;
4447 int numInts = datalen / sizeof(int);
4448 if (numInts > 1) {
4449 m_RfDesense->emOemHookRaw(p_int[1],soc_id);
4450 } else {
4451 m_RfDesense->emOemHookRaw(0, soc_id);
4452 }
4453 break;
4454 }
4455 case RIL_UNSOL_NETWORK_INFO: {
4456 if(networkCb){
4457 //TBD
4458 char **p_cur = (char **) data;
4459 char *ctype = (char*)p_cur[0];
4460 int type = atoi(ctype);
4461 char *data = (char*)p_cur[1];
4462 RLOGD("ctype %s type %d data %s\n",ctype,type,data);
4463 networkCb(type,data);
4464 }
4465 break;
4466 }
4467 case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
4468 {
4469 int num = datalen / sizeof(RIL_Data_Call_Response_v6);
4470 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) data;
4471 handleUnsolDataCalllistChange(num,p_cur);
4472 break;
4473 }
4474 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED:
4475 {
4476 update_voice_radio_tech(((int *) data)[0], soc_id);
4477 break;
4478 }
4479 case RIL_UNSOL_RADIO_CAPABILITY:
4480 {
4481 update_radio_capa((RIL_RadioCapability *) data, soc_id);
4482 //Proxy_controller::getInstance()->handle_message_notify((RIL_RadioCapability *) data, soc_id);
4483 break;
4484 }
4485 case RIL_UNSOL_CDMA_CALL_WAITING:
4486 {
4487 autoAnswerForCdma(soc_id);
4488 break;
4489 }
4490 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4491 {
4492 updateSystemTime(data, datalen);
4493 break;
4494 }
4495 case RIL_UNSOL_ECALL_INDICATIONS:
4496 {
4497 handleEcallIndication(data, datalen, soc_id);
4498 break;
4499 }
4500#ifdef KEEP_ALIVE
4501 case RIL_UNSOL_KEEPALIVE_STATUS_PRO:
4502 {
4503 handleKeepAliveResponse(unsolResponse, data, datalen, soc_id, false);
4504 break;
4505 }
4506#endif /*KEEP_ALIVE*/
4507 case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
4508 {
4509 setSimSmsStorageFullFlag(true);
4510 break;
4511 }
4512 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR:
4513 {
4514 handleUnsolSipCallProgressInd(data, datalen);
4515 break;
4516 }
4517 case RIL_UNSOL_ECC_NUM:
4518 {
4519 handleECCNumResponse(data, datalen,soc_id);
4520 break;
4521 }
4522 case RIL_UNSOL_CALL_INFO_INDICATION:
4523 {
4524 handleUnsolCallInfoInd(data, datalen, soc_id);
4525 break;
4526 }
4527 case RIL_UNSOL_RINGBACK_TONE:
4528 {
4529 handleRingbackTone(data, datalen, soc_id);
4530 break;
4531 }
4532 default:
4533 break;
4534 }
lhf6eea122022-01-20 19:32:14 -08004535 /*Warren add for t800 ril service 2021/12/16 start*/
4536 ret = LYNQ_RIL_urcBroadcast(p);
4537 /*Warren add for t800 ril service 2021/12/16 end*/
lh7b0674a2022-01-10 00:34:35 -08004538#if 0
4539 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4540
4541 // Unfortunately, NITZ time is not poll/update like everything
4542 // else in the system. So, if the upstream client isn't connected,
4543 // keep a copy of the last NITZ response (with receive time noted
4544 // above) around so we can deliver it when it is connected
4545
4546 if (s_lastNITZTimeData != NULL) {
4547 free (s_lastNITZTimeData);
4548 s_lastNITZTimeData = NULL;
4549 }
4550
4551 s_lastNITZTimeData = malloc(p.dataSize());
4552 s_lastNITZTimeDataSize = p.dataSize();
4553 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4554 }
4555
4556#endif
4557 // Normal exit
4558 return;
4559
4560error_exit:
4561 RLOGD("unsol handle fail");
4562#if 0
4563 if (shouldScheduleTimeout) {
4564 releaseWakeLock();
4565 }
4566#endif
4567}
4568
4569extern "C" void
4570RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4571 const struct timeval *relativeTime) {
4572}
4573
4574const char *
4575failCauseToString(RIL_Errno e) {
4576 switch(e) {
4577 case RIL_E_SUCCESS: return "E_SUCCESS";
4578 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
4579 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4580 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4581 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4582 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4583 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4584 case RIL_E_CANCELLED: return "E_CANCELLED";
4585 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4586 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4587 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
4588 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
4589 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
4590#ifdef FEATURE_MULTIMODE_ANDROID
4591 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4592 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4593#endif
4594 case RIL_E_SIM_MEM_FULL: return "E_SIM_MEM_FULL";
4595 default: return "<unknown error>";
4596 }
4597}
4598
4599const char *
4600callStateToString(RIL_CallState s) {
4601 switch(s) {
4602 case RIL_CALL_ACTIVE : return "ACTIVE";
4603 case RIL_CALL_HOLDING: return "HOLDING";
4604 case RIL_CALL_DIALING: return "DIALING";
4605 case RIL_CALL_ALERTING: return "ALERTING";
4606 case RIL_CALL_INCOMING: return "INCOMING";
4607 case RIL_CALL_WAITING: return "WAITING";
4608 default: return "<unknown state>";
4609 }
4610}
4611const char *lynq_requset_to_string(int request)
4612{
4613 switch(request) {
4614 case RIL_REQUEST_GET_SIM_STATUS: return "RIL_REQUEST_GET_SIM_STATUS";
4615 case RIL_REQUEST_ENTER_SIM_PIN: return "RIL_REQUEST_ENTER_SIM_PIN";
4616 case RIL_REQUEST_ENTER_SIM_PUK: return "RIL_REQUEST_ENTER_SIM_PUK";
4617 case RIL_REQUEST_ENTER_SIM_PIN2: return "RIL_REQUEST_ENTER_SIM_PIN2";
4618 case RIL_REQUEST_ENTER_SIM_PUK2: return "RIL_REQUEST_ENTER_SIM_PUK2";
4619 case RIL_REQUEST_CHANGE_SIM_PIN: return "RIL_REQUEST_CHANGE_SIM_PIN";
4620 case RIL_REQUEST_CHANGE_SIM_PIN2: return "RIL_REQUEST_CHANGE_SIM_PIN2";
4621 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION";
4622 case RIL_REQUEST_GET_CURRENT_CALLS: return "RIL_REQUEST_GET_CURRENT_CALLS";
4623 case RIL_REQUEST_DIAL: return "RIL_REQUEST_DIAL";
4624 case RIL_REQUEST_GET_IMSI: return "RIL_REQUEST_GET_IMSI";
4625 case RIL_REQUEST_HANGUP: return "RIL_REQUEST_HANGUP";
4626 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND";
4627 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND";
4628 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4629 case RIL_REQUEST_CONFERENCE: return "RIL_REQUEST_CONFERENCE";
4630 case RIL_REQUEST_UDUB: return "RIL_REQUEST_UDUB";
4631 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "RIL_REQUEST_LAST_CALL_FAIL_CAUSE";
4632 case RIL_REQUEST_SIGNAL_STRENGTH: return "RIL_REQUEST_SIGNAL_STRENGTH";
4633 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "RIL_REQUEST_VOICE_REGISTRATION_STATE";
4634 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "RIL_REQUEST_DATA_REGISTRATION_STATE";
4635 case RIL_REQUEST_OPERATOR: return "RIL_REQUEST_OPERATOR";
4636 case RIL_REQUEST_RADIO_POWER: return "RIL_REQUEST_RADIO_POWER";
4637 case RIL_REQUEST_DTMF: return "RIL_REQUEST_DTMF";
4638 case RIL_REQUEST_SEND_SMS: return "RIL_REQUEST_SEND_SMS";
4639 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "RIL_REQUEST_SEND_SMS_EXPECT_MORE";
4640 case RIL_REQUEST_SETUP_DATA_CALL: return "RIL_REQUEST_SETUP_DATA_CALL";
4641 case RIL_REQUEST_SIM_IO: return "RIL_REQUEST_SIM_IO";
4642 case RIL_REQUEST_SEND_USSD: return "RIL_REQUEST_SEND_USSD";
4643 case RIL_REQUEST_CANCEL_USSD: return "RIL_REQUEST_CANCEL_USSD";
4644 case RIL_REQUEST_GET_CLIR: return "RIL_REQUEST_GET_CLIR";
4645 case RIL_REQUEST_SET_CLIR: return "RIL_REQUEST_SET_CLIR";
4646 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "RIL_REQUEST_QUERY_CALL_FORWARD_STATUS";
4647 case RIL_REQUEST_SET_CALL_FORWARD: return "RIL_REQUEST_SET_CALL_FORWARD";
4648 case RIL_REQUEST_QUERY_CALL_WAITING: return "RIL_REQUEST_QUERY_CALL_WAITING";
4649 case RIL_REQUEST_SET_CALL_WAITING: return "RIL_REQUEST_SET_CALL_WAITING";
4650 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "RIL_REQUEST_SMS_ACKNOWLEDGE";
4651 case RIL_REQUEST_GET_IMEI: return "RIL_REQUEST_GET_IMEI";
4652 case RIL_REQUEST_GET_IMEISV: return "RIL_REQUEST_GET_IMEISV";
4653 case RIL_REQUEST_ANSWER: return "RIL_REQUEST_ANSWER";
4654 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "RIL_REQUEST_DEACTIVATE_DATA_CALL";
4655 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "RIL_REQUEST_QUERY_FACILITY_LOCK";
4656 case RIL_REQUEST_SET_FACILITY_LOCK: return "RIL_REQUEST_SET_FACILITY_LOCK";
4657 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "RIL_REQUEST_CHANGE_BARRING_PASSWORD";
4658 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE";
4659 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC";
4660 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL";
4661 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS";
4662 case RIL_REQUEST_DTMF_START: return "RIL_REQUEST_DTMF_START";
4663 case RIL_REQUEST_DTMF_STOP: return "RIL_REQUEST_DTMF_STOP";
4664 case RIL_REQUEST_BASEBAND_VERSION: return "RIL_REQUEST_BASEBAND_VERSION";
4665 case RIL_REQUEST_SEPARATE_CONNECTION: return "RIL_REQUEST_SEPARATE_CONNECTION";
4666 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE";
4667 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE";
4668 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "RIL_REQUEST_GET_NEIGHBORING_CELL_IDS";
4669 case RIL_REQUEST_SET_MUTE: return "RIL_REQUEST_SET_MUTE";
4670 case RIL_REQUEST_GET_MUTE: return "RIL_REQUEST_GET_MUTE";
4671 case RIL_REQUEST_QUERY_CLIP: return "RIL_REQUEST_QUERY_CLIP";
4672 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE";
4673 case RIL_REQUEST_DATA_CALL_LIST: return "RIL_REQUEST_DATA_CALL_LIST";
4674 case RIL_REQUEST_RESET_RADIO: return "RIL_REQUEST_RESET_RADIO";
4675 case RIL_REQUEST_OEM_HOOK_RAW: return "RIL_REQUEST_OEM_HOOK_RAW";
4676 case RIL_REQUEST_OEM_HOOK_STRINGS: return "RIL_REQUEST_OEM_HOOK_STRINGS";
4677 case RIL_REQUEST_SET_BAND_MODE: return "RIL_REQUEST_SET_BAND_MODE";
4678 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE";
4679 case RIL_REQUEST_STK_GET_PROFILE: return "RIL_REQUEST_STK_GET_PROFILE";
4680 case RIL_REQUEST_STK_SET_PROFILE: return "RIL_REQUEST_STK_SET_PROFILE";
4681 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND";
4682 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE";
4683 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4684 case RIL_REQUEST_SCREEN_STATE: return "RIL_REQUEST_SCREEN_STATE";
4685 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "RIL_REQUEST_EXPLICIT_CALL_TRANSFER";
4686 case RIL_REQUEST_SET_LOCATION_UPDATES: return "RIL_REQUEST_SET_LOCATION_UPDATES";
4687 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE";
4688 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE";
4689 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE";
4690 case RIL_REQUEST_SET_TTY_MODE:return"RIL_REQUEST_SET_TTY_MODE";
4691 case RIL_REQUEST_QUERY_TTY_MODE:return"RIL_REQUEST_QUERY_TTY_MODE";
4692 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4693 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4694 case RIL_REQUEST_CDMA_FLASH:return"RIL_REQUEST_CDMA_FLASH";
4695 case RIL_REQUEST_CDMA_BURST_DTMF:return"RIL_REQUEST_CDMA_BURST_DTMF";
4696 case RIL_REQUEST_CDMA_SEND_SMS:return"RIL_REQUEST_CDMA_SEND_SMS";
4697 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE";
4698 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG";
4699 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG";
4700 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION:return "RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION";
4701 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG";
4702 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG";
4703 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION";
4704 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY";
4705 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"RIL_REQUEST_CDMA_SUBSCRIPTION";
4706 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM";
4707 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM";
4708 case RIL_REQUEST_DEVICE_IDENTITY: return "RIL_REQUEST_DEVICE_IDENTITY";
4709 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE";
4710 case RIL_REQUEST_GET_SMSC_ADDRESS: return "RIL_REQUEST_GET_SMSC_ADDRESS";
4711 case RIL_REQUEST_SET_SMSC_ADDRESS: return "RIL_REQUEST_SET_SMSC_ADDRESS";
4712 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "RIL_REQUEST_REPORT_SMS_MEMORY_STATUS";
4713 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING";
4714 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE";
4715 case RIL_REQUEST_ISIM_AUTHENTICATION: return "RIL_REQUEST_ISIM_AUTHENTICATION";
4716 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4717 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
4718 case RIL_REQUEST_VOICE_RADIO_TECH: return "RIL_REQUEST_VOICE_RADIO_TECH";
4719 case RIL_REQUEST_GET_CELL_INFO_LIST: return"RIL_REQUEST_GET_CELL_INFO_LIST";
4720 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE";
4721 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
4722 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "RIL_REQUEST_IMS_REGISTRATION_STATE";
4723 case RIL_REQUEST_IMS_SEND_SMS: return "RIL_REQUEST_IMS_SEND_SMS";
4724 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC";
4725 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "RIL_REQUEST_SIM_OPEN_CHANNEL";
4726 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "RIL_REQUEST_SIM_CLOSE_CHANNEL";
4727 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL";
4728 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4729 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
4730 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "RIL_REQUEST_SET_UICC_SUBSCRIPTION";
4731 case RIL_REQUEST_ALLOW_DATA: return "RIL_REQUEST_ALLOW_DATA";
4732 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "RIL_REQUEST_GET_HARDWARE_CONFIG";
4733 case RIL_REQUEST_SIM_AUTHENTICATION: return "RIL_REQUEST_SIM_AUTHENTICATION";
4734 case RIL_REQUEST_GET_DC_RT_INFO: return "RIL_REQUEST_GET_DC_RT_INFO";
4735 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "RIL_REQUEST_SET_DC_RT_INFO_RATE";
4736 case RIL_REQUEST_SET_DATA_PROFILE: return "RIL_REQUEST_SET_DATA_PROFILE";
4737 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4738 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED";
4739 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
4740 case RIL_UNSOL_RESPONSE_NEW_SMS: return "RIL_UNSOL_RESPONSE_NEW_SMS";
4741 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4742 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4743 case RIL_UNSOL_ON_USSD: return "RIL_UNSOL_ON_USSD";
4744 case RIL_UNSOL_ON_USSD_REQUEST: return "RIL_UNSOL_ON_USSD_REQUEST";
4745 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "RIL_UNSOL_NITZ_TIME_RECEIVED";
4746 case RIL_UNSOL_SIGNAL_STRENGTH: return "RIL_UNSOL_SIGNAL_STRENGTH";
4747 case RIL_UNSOL_STK_SESSION_END: return "RIL_UNSOL_STK_SESSION_END";
4748 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "RIL_UNSOL_STK_PROACTIVE_COMMAND";
4749 case RIL_UNSOL_STK_EVENT_NOTIFY: return "RIL_UNSOL_STK_EVENT_NOTIFY";
4750 case RIL_UNSOL_STK_CALL_SETUP: return "RIL_UNSOL_STK_CALL_SETUP";
4751 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "RIL_UNSOL_SIM_SMS_STORAGE_FULL";
4752 case RIL_UNSOL_SIM_REFRESH: return "RIL_UNSOL_SIM_REFRESH";
4753 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "RIL_UNSOL_DATA_CALL_LIST_CHANGED";
4754 case RIL_UNSOL_CALL_RING: return "RIL_UNSOL_CALL_RING";
4755 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4756 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "RIL_UNSOL_RESPONSE_CDMA_NEW_SMS";
4757 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS";
4758 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
4759 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "RIL_UNSOL_RESTRICTED_STATE_CHANGED";
4760 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4761 case RIL_UNSOL_CDMA_CALL_WAITING: return "RIL_UNSOL_CDMA_CALL_WAITING";
4762 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "RIL_UNSOL_CDMA_OTA_PROVISION_STATUS";
4763 case RIL_UNSOL_CDMA_INFO_REC: return "RIL_UNSOL_CDMA_INFO_REC";
4764 case RIL_UNSOL_OEM_HOOK_RAW: return "RIL_UNSOL_OEM_HOOK_RAW";
4765 case RIL_UNSOL_RINGBACK_TONE: return "RIL_UNSOL_RINGBACK_TONE";
4766 case RIL_UNSOL_RESEND_INCALL_MUTE: return "RIL_UNSOL_RESEND_INCALL_MUTE";
4767 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
4768 case RIL_UNSOL_CDMA_PRL_CHANGED: return "RIL_UNSOL_CDMA_PRL_CHANGED";
4769 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
4770 case RIL_UNSOL_RIL_CONNECTED: return "RIL_UNSOL_RIL_CONNECTED";
4771 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "RIL_UNSOL_VOICE_RADIO_TECH_CHANGED";
4772 case RIL_UNSOL_CELL_INFO_LIST: return "RIL_UNSOL_CELL_INFO_LIST";
4773 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
4774 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4775 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "RIL_UNSOL_SRVCC_STATE_NOTIFY";
4776 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "RIL_UNSOL_HARDWARE_CONFIG_CHANGED";
4777 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "RIL_UNSOL_DC_RT_INFO_CHANGED";
4778 case RIL_REQUEST_SHUTDOWN: return "RIL_REQUEST_SHUTDOWN";
4779 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
4780 case RIL_REQUEST_SET_TRM: return "RIL_REQUEST_SET_TRM";
4781 case RIL_REQUEST_SET_IMS_ENABLE:return "RIL_REQUEST_SET_IMS_ENABLE";
4782 case RIL_REQUEST_SET_AUDIO_PATH: return "RIL_REQUEST_SET_AUDIO_PATH";
4783 case RIL_REQUEST_HANGUP_ALL: return "RIL_REQUEST_HANGUP_ALL";
4784 case RIL_REQUEST_FORCE_RELEASE_CALL: return "RIL_REQUEST_FORCE_RELEASE_CALL";
4785 case RIL_REQUEST_EMERGENCY_DIAL: return "RIL_REQUEST_EMERGENCY_DIAL";
4786 case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: return "RIL_REQUEST_SET_ECC_SERVICE_CATEGORY";
4787 case RIL_REQUEST_SET_ECC_LIST: return "RIL_REQUEST_SET_ECC_LIST";
4788 case RIL_REQUEST_AT_COMMAND_WITH_PROXY: return "RIL_REQUEST_AT_COMMAND_WITH_PROXY";
4789 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION";
4790 case RIL_REQUEST_SET_CLIP: return "RIL_REQUEST_SET_CLIP";
4791 case RIL_REQUEST_GET_COLP: return "RIL_REQUEST_GET_COLP";
4792 case RIL_REQUEST_SET_COLP: return "RIL_REQUEST_SET_COLP";
4793 case RIL_REQUEST_GET_COLR: return "RIL_REQUEST_GET_COLR";
4794 case RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER: return "RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER";
4795 case RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER: return "RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER";
4796 case RIL_REQUEST_CONFERENCE_DIAL: return "RIL_REQUEST_CONFERENCE_DIAL";
4797 case RIL_REQUEST_DIAL_WITH_SIP_URI: return "RIL_REQUEST_DIAL_WITH_SIP_URI";
4798 case RIL_REQUEST_HOLD_CALL: return "RIL_REQUEST_HOLD_CALL";
4799 case RIL_REQUEST_RESUME_CALL: return "RIL_REQUEST_RESUME_CALL";
4800 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return "RIL_UNSOL_ECONF_SRVCC_INDICATION";
4801 case RIL_UNSOL_ECONF_RESULT_INDICATION : return "RIL_UNSOL_ECONF_RESULT_INDICATION";
4802 case RIL_UNSOL_MAL_AT_INFO : return "RIL_UNSOL_MAL_AT_INFO";
4803 case RIL_REQUEST_MODEM_POWEROFF: return "RIL_REQUEST_MODEM_POWEROFF";
4804 case RIL_REQUEST_MODEM_POWERON: return "RIL_REQUEST_MODEM_POWERON";
4805 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "RIL_REQUEST_WRITE_SMS_TO_SIM";
4806 case RIL_REQUEST_QUERY_ICCID: return "RIL_REQUEST_QUERY_ICCID";
4807 case RIL_UNSOL_TX_POWER: return "RIL_UNSOL_TX_POWER";
4808 case RIL_UNSOL_NETWORK_INFO: return "RIL_UNSOL_NETWORK_INFO";
4809 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "RIL_REQUEST_DELETE_SMS_ON_SIM";
4810 case RIL_REQUEST_SET_IMSCFG: return "RIL_REQUEST_SET_IMSCFG";
4811#ifdef ECALL_SUPPORT
4812 case RIL_REQUEST_ECALL_FAST_MAKE_ECALL: return "RIL_REQUEST_ECALL_FAST_MAKE_ECALL";
4813 case RIL_REQUEST_ECALL_SET_IVS: return "RIL_REQUEST_ECALL_SET_IVS";
4814 case RIL_REQUEST_ECALL_SET_PSAP: return "RIL_REQUEST_ECALL_SET_PSAP";
4815 case RIL_REQUEST_ECALL_MAKE_ECALL: return "RIL_REQUEST_ECALL_MAKE_ECALL";
4816 case RIL_REQUEST_ECALL_IVS_PUSH_MSD: return "RIL_REQUEST_ECALL_IVS_PUSH_MSD";
4817 case RIL_REQUEST_ECALL_PSAP_PULL_MSD: return "RIL_REQUEST_ECALL_PSAP_PULL_MSD";
4818 case RIL_UNSOL_ECALL_MSDHACK : return "RIL_UNSOL_ECALL_MSDHACK";
4819 case RIL_REQUEST_ECALL_SET_MSD: return "RIL_REQUEST_ECALL_SET_MSD";
4820 case RIL_REQUEST_ECALL_CTRL_SEQUENCE: return "RIL_REQUEST_ECALL_CTRL_SEQUENCE";
4821 case RIL_UNSOL_ECALL_INDICATIONS : return "RIL_UNSOL_ECALL_INDICATIONS";
4822 case RIL_REQUEST_ECALL_RESET_IVS: return "RIL_REQUEST_ECALL_RESET_IVS";
4823 case RIL_REQUEST_ECALL_SET_PRI: return "RIL_REQUEST_ECALL_SET_PRI";
4824 case RIL_REQUEST_ECALL_SET_TEST_NUM: return "RIL_REQUEST_ECALL_SET_TEST_NUM";
4825 case RIL_REQUEST_ECALL_SET_RECONF_NUM: return "RIL_REQUEST_ECALL_SET_RECONF_NUM";
4826 case RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD: return "RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD";
4827 case RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME: return "RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME";
4828 case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: return "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE";
4829#endif /*ECALL_SUPPORT*/
4830#ifdef KEEP_ALIVE
4831 case RIL_REQUEST_START_KEEPALIVE_PRO: return "RIL_REQUEST_START_KEEPALIVE_PRO";
4832 case RIL_REQUEST_STOP_KEEPALIVE_PRO: return "RIL_REQUEST_STOP_KEEPALIVE_PRO";
4833 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return "RIL_UNSOL_KEEPALIVE_STATUS_PRO";
4834#endif /*KEEP_ALIVE*/
4835 case RIL_REQUEST_SEND_USSI: return "RIL_REQUEST_SEND_USSI";
4836 case RIL_REQUEST_CANCEL_USSI: return "RIL_REQUEST_CANCEL_USSI";
4837 case RIL_REQUEST_GET_SMS_SIM_MEM_STATUS: return "RIL_REQUEST_GET_SMS_SIM_MEM_STATUS";
4838 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return "RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR";
4839 case RIL_REQUEST_REPORT_AIRPLANE_MODE: return "RIL_REQUEST_REPORT_AIRPLANE_MODE";
4840 case RIL_REQUEST_SET_ECC_NUM: return "RIL_REQUEST_SET_ECC_NUM";
4841 case RIL_REQUEST_GET_ECC_NUM: return "RIL_REQUEST_GET_ECC_NUM";
4842 case RIL_UNSOL_ECC_NUM: return "RIL_UNSOL_ECC_NUM";
4843 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT: return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT";
4844 case RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE";
4845 case RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE";
4846 case RIL_UNSOL_CALL_INFO_INDICATION: return "RIL_UNSOL_CALL_INFO_INDICATION";
4847#ifdef TARGET_PLATFORM_MT2731
4848 case RIL_REQUEST_MODIFY_APN: return "RIL_REQUEST_MODIFY_APN";
4849 case RIL_REQUEST_RESET_APN: return "RIL_REQUEST_RESET_APN";
4850#endif
4851 case RIL_REQUEST_QUERY_SIM_RETRY_COUNT: return "RIL_REQUEST_QUERY_SIM_RETRY_COUNT";
4852 case RIL_REQUEST_QUERY_EID: return "RIL_REQUEST_QUERY_EID";
4853 /*LYNQ CMD*/
4854 case LYNQ_AUTO_ANSWER_CALL: return "LYNQ_AUTO_ANSWER_CALL";
4855 case LYNQ_REQUEST_SET_DTMF_VOLUME: return "RIL_REQUEST_SET_DTMF_VOLUME";
lhf6eea122022-01-20 19:32:14 -08004856 case LYNQ_REQUEST_WRITE_SMS_TO_MEMORY: return "LYNQ_REQUEST_WRITE_SMS_TO_MEMORY";
4857 case LYNQ_REQUEST_READ_SMS_FROM_MEMORY: return "LYNQ_REQUEST_READ_SMS_FROM_MEMORY";
4858 case LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY: return "LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY";
4859 case LYNQ_REQUEST_LIST_SMS_FROM_MEMORY: return "LYNQ_REQUEST_LIST_SMS_FROM_MEMORY";
lh7b0674a2022-01-10 00:34:35 -08004860 default: return "<unknown request>";
4861 }
4862}
4863
4864const char *
4865requestToString(int request) {
4866/*
4867 cat libs/telephony/ril_commands.h \
4868 | egrep "^ *{RIL_" \
4869 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4870
4871
4872 cat libs/telephony/ril_unsol_commands.h \
4873 | egrep "^ *{RIL_" \
4874 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4875
4876*/
4877 switch(request) {
4878 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4879 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4880 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4881 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4882 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4883 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4884 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4885 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4886 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4887 case RIL_REQUEST_DIAL: return "DIAL";
4888 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4889 case RIL_REQUEST_HANGUP: return "HANGUP";
4890 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4891 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4892 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4893 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4894 case RIL_REQUEST_UDUB: return "UDUB";
4895 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4896 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
4897 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4898 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
4899 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4900 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4901 case RIL_REQUEST_DTMF: return "DTMF";
4902 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4903 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
4904 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
4905 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4906 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4907 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4908 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4909 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4910 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4911 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4912 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4913 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4914 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4915 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4916 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4917 case RIL_REQUEST_ANSWER: return "ANSWER";
4918 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
4919 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4920 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4921 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4922 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4923 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4924 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4925 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4926 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4927 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4928 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4929 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4930 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4931 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4932 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4933 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4934 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4935 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
4936 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4937 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
4938 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4939 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4940 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
4941 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4942 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
4943 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4944 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4945 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4946 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4947 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4948 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4949 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4950 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
4951 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
4952 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4953 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4954 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4955 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4956 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4957 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4958 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4959 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4960 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4961 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
4962 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4963 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4964 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION:return "GSM_SMS_BROADCAST_ACTIVATION";
4965 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4966 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4967 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
4968 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
4969 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4970 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4971 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4972 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
4973 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4974 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4975 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
4976 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
4977 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
4978 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
4979 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
4980 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4981 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
4982 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
4983 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4984 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
4985 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
4986 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4987 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
4988 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4989 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4990 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4991 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
4992 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4993 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
4994 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4995 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
4996 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4997 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
4998 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4999 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5000 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
5001 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5002 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5003 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5004 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5005 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5006 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5007 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5008 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5009 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5010 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5011 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5012 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5013 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5014 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5015 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5016 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
5017 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5018 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5019 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5020 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5021 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5022 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5023 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5024 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5025 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5026 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5027 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5028 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5029 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5030 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5031 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5032 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5033 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5034 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5035 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
5036 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
5037 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
5038 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5039 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5040 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5041 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
5042 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
5043 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
5044 case RIL_REQUEST_SET_TRM: return "RIL_REQUEST_SET_TRM";
5045 case RIL_REQUEST_SET_IMS_ENABLE:return "RIL_REQUEST_SET_IMS_ENABLE";
5046 case RIL_REQUEST_SET_AUDIO_PATH: return "SET_AUDIO_PATH";
5047 case RIL_REQUEST_HANGUP_ALL: return "HANGUP_ALL";
5048 case RIL_REQUEST_FORCE_RELEASE_CALL: return "FORCE_RELEASE_CALL";
5049 case RIL_REQUEST_EMERGENCY_DIAL: return "RIL_REQUEST_EMERGENCY_DIAL";
5050 case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: return "RIL_REQUEST_SET_ECC_SERVICE_CATEGORY";
5051 case RIL_REQUEST_SET_ECC_LIST: return "RIL_REQUEST_SET_ECC_LIST";
5052 case RIL_REQUEST_AT_COMMAND_WITH_PROXY: return "AT_COMMAND_WITH_PROXY";
5053 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION";
5054 case RIL_REQUEST_SET_CLIP: return "RIL_REQUEST_SET_CLIP";
5055 case RIL_REQUEST_GET_COLP: return "RIL_REQUEST_GET_COLP";
5056 case RIL_REQUEST_SET_COLP: return "RIL_REQUEST_SET_COLP";
5057 case RIL_REQUEST_GET_COLR: return "RIL_REQUEST_GET_COLR";
5058 case RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER: return "ADD_IMS_CONFERENCE_CALL_MEMBER";
5059 case RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER: return "REMOVE_IMS_CONFERENCE_CALL_MEMBER";
5060 case RIL_REQUEST_CONFERENCE_DIAL: return "CONFERENCE_DIAL";
5061 case RIL_REQUEST_DIAL_WITH_SIP_URI: return "DIAL_WITH_SIP_URI";
5062 case RIL_REQUEST_HOLD_CALL: return "HOLD_CALL";
5063 case RIL_REQUEST_RESUME_CALL: return "RESUME_CALL";
5064 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return "ECONF_SRVCC_INDICATION";
5065 case RIL_UNSOL_ECONF_RESULT_INDICATION : return "ECONF_RESULT_INDICATION";
5066 case RIL_UNSOL_MAL_AT_INFO : return "UNSOL_MAL_AT_INFO";
5067 case RIL_REQUEST_MODEM_POWEROFF: return "MODEM_POWEROFF";
5068 case RIL_REQUEST_MODEM_POWERON: return "MODEM_POWERON";
5069 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
5070 case RIL_REQUEST_QUERY_ICCID: return "RIL_REQUEST_QUERY_ICCID";
5071 case RIL_UNSOL_TX_POWER: return "RIL_UNSOL_TX_POWER";
5072 case RIL_UNSOL_NETWORK_INFO: return "RIL_UNSOL_NETWORK_INFO";
5073 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
5074 case RIL_REQUEST_SET_IMSCFG: return "RIL_REQUEST_SET_IMSCFG";
5075#ifdef ECALL_SUPPORT
5076 case RIL_REQUEST_ECALL_FAST_MAKE_ECALL: return "ECALL_FAST_MAKE_ECALL";
5077 case RIL_REQUEST_ECALL_SET_IVS: return "RIL_REQUEST_ECALL_SET_IVS";
5078 case RIL_REQUEST_ECALL_SET_PSAP: return "RIL_REQUEST_ECALL_SET_PSAP";
5079 case RIL_REQUEST_ECALL_MAKE_ECALL: return "RIL_REQUEST_ECALL_MAKE_ECALL";
5080 case RIL_REQUEST_ECALL_IVS_PUSH_MSD: return "RIL_REQUEST_ECALL_IVS_PUSH_MSD";
5081 case RIL_REQUEST_ECALL_PSAP_PULL_MSD: return "RIL_REQUEST_ECALL_PSAP_PULL_MSD";
5082 case RIL_UNSOL_ECALL_MSDHACK : return "ECALL_MSDHACK";
5083 case RIL_REQUEST_ECALL_SET_MSD: return "RIL_REQUEST_ECALL_SET_MSD";
5084 case RIL_REQUEST_ECALL_CTRL_SEQUENCE: return "ECALL_SET_CTRL_SEQUENCE";
5085 case RIL_UNSOL_ECALL_INDICATIONS : return "ECALL_INDICATIONS";
5086 case RIL_REQUEST_ECALL_RESET_IVS: return "RIL_REQUEST_ECALL_RESET_IVS";
5087 case RIL_REQUEST_ECALL_SET_PRI: return "RIL_REQUEST_ECALL_SET_PRI";
5088 case RIL_REQUEST_ECALL_SET_TEST_NUM: return "RIL_REQUEST_ECALL_SET_TEST_NUM";
5089 case RIL_REQUEST_ECALL_SET_RECONF_NUM: return "RIL_REQUEST_ECALL_SET_RECONF_NUM";
5090 case RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD: return "RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD";
5091 case RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME: return "RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME";
5092 case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: return "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE";
5093#endif /*ECALL_SUPPORT*/
5094#ifdef KEEP_ALIVE
5095 case RIL_REQUEST_START_KEEPALIVE_PRO: return "RIL_REQUEST_START_KEEPALIVE_PRO";
5096 case RIL_REQUEST_STOP_KEEPALIVE_PRO: return "RIL_REQUEST_STOP_KEEPALIVE_PRO";
5097 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return "RIL_UNSOL_KEEPALIVE_STATUS_PRO";
5098#endif /*KEEP_ALIVE*/
5099 case RIL_REQUEST_SEND_USSI: return "SEND_USSI";
5100 case RIL_REQUEST_CANCEL_USSI: return "CANCEL_USSI";
5101 case RIL_REQUEST_GET_SMS_SIM_MEM_STATUS: return "GET_SMS_SIM_MEM_STATUS";
5102 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return "RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR";
5103 case RIL_REQUEST_REPORT_AIRPLANE_MODE: return "RIL_REQUEST_REPORT_AIRPLANE_MODE";
5104 case RIL_REQUEST_SET_ECC_NUM: return "RIL_REQUEST_SET_ECC_NUM";
5105 case RIL_REQUEST_GET_ECC_NUM: return "RIL_REQUEST_GET_ECC_NUM";
5106 case RIL_UNSOL_ECC_NUM: return "RIL_UNSOL_ECC_NUM";
5107 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT: return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT";
5108 case RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE";
5109 case RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE";
5110 case RIL_UNSOL_CALL_INFO_INDICATION: return "RIL_UNSOL_CALL_INFO_INDICATION";
5111 case RIL_REQUEST_MODIFY_APN: return "RIL_REQUEST_MODIFY_APN";
5112 case RIL_REQUEST_RESET_APN: return "RIL_REQUEST_RESET_APN";
5113 case RIL_REQUEST_QUERY_SIM_RETRY_COUNT: return "RIL_REQUEST_QUERY_SIM_RETRY_COUNT";
5114 case RIL_REQUEST_QUERY_EID: return "RIL_REQUEST_QUERY_EID";
5115 case LYNQ_REQUEST_SET_DTMF_VOLUME: return "RIL_REQUEST_SET_DTMF_VOLUME";
lhf6eea122022-01-20 19:32:14 -08005116 /*warren add for t800 ril service 2022/1/22 start*/
5117 case LYNQ_REQUEST_WRITE_SMS_TO_MEMORY: return "LYNQ_REQUEST_WRITE_SMS_TO_MEMORY";
5118 case LYNQ_REQUEST_READ_SMS_FROM_MEMORY: return "LYNQ_REQUEST_READ_SMS_FROM_MEMORY";
5119 case LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY: return "LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY";
5120 case LYNQ_REQUEST_LIST_SMS_FROM_MEMORY: return "LYNQ_REQUEST_LIST_SMS_FROM_MEMORY";
5121 /*warren add for t800 ril service 2022/1/22 end*/
lh7b0674a2022-01-10 00:34:35 -08005122 default: return "<unknown request>";
5123 }
5124}
5125
5126static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
5127 printResponse;
5128 int type;
5129 if(enable_bt_resp){
5130 SendRespToClient(p.data(), p.dataSize());
5131 }
5132 p.setDataPosition(0);
5133 p.readInt32(&type);
5134 if(type == RESPONSE_UNSOLICITED){
5135 processUnsolicited(p,type);
5136 }else if (type == RESPONSE_SOLICITED){
5137 processSolicited(p,type);
5138 }
5139 return 0;
5140}
5141
5142static void speciaRequest_wait()
5143{
5144 struct timeval now;
5145 struct timespec timeout;
5146
5147 gettimeofday(&now,NULL);
5148 timeout.tv_sec = now.tv_sec+1200; //timeout is 2omin. maybe radio on/off need 10s to complete.
5149 timeout.tv_nsec = now.tv_usec*1000;
5150
5151 SPECIA_BLOCK_LOCK();
5152 while(!(requestOneByOne == 0)) {
5153 int ret = SPECIA_BLOCK_WAIT(&timeout);
5154 if(ret == ETIMEDOUT){
5155 RLOGD("special request wait timeout");
5156 break;
5157 }
5158 }
5159 requestOneByOne = 1;
5160 SPECIA_BLOCK_UNLOCK();
5161}
5162
5163static void speciaRequest_wakeup()
5164{
5165 SPECIA_BLOCK_LOCK();
5166 requestOneByOne = 0;
5167 SPECIA_BLOCK_WAKEUP();
5168 SPECIA_BLOCK_UNLOCK();
5169}
5170
5171static void updateIccCardState(RIL_SOCKET_ID soc_id)
5172{
5173 ARspRequest(RIL_REQUEST_GET_SIM_STATUS, soc_id);
5174}
5175
5176void sendRequestToMd(int request, int id) {
5177 RequestInfo* info = creatRILInfoAndInit(request, INIT, (RIL_SOCKET_ID) ((id)));
5178 switch(request){
5179 case RIL_REQUEST_DEVICE_IDENTITY:
5180 {
5181 getDeviceIdentity(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5182 break;
5183 }
5184 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE:
5185 {
5186 getPreferredNetworkType(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5187 break;
5188 }
5189 case RIL_REQUEST_GET_SIM_STATUS:
5190 {
5191 getIccCardStatus(1, NULL, (RIL_SOCKET_ID) (id), info);
5192 break;
5193 }
5194 case RIL_REQUEST_DATA_REGISTRATION_STATE:
5195 {
5196 getDataRegistrationState(1, NULL, (RIL_SOCKET_ID) (id), info);
5197 break;
5198 }
5199 case RIL_REQUEST_VOICE_REGISTRATION_STATE:
5200 {
5201 getVoiceRegistrationState(1, NULL, (RIL_SOCKET_ID) (id), info);
5202 break;
5203 }
5204 case RIL_REQUEST_VOICE_RADIO_TECH:
5205 {
5206 getVoiceRadioTechnology(1, NULL, (RIL_SOCKET_ID) (id), info);
5207 break;
5208 }
5209 case RIL_REQUEST_OEM_HOOK_RAW:
5210 {
5211 char* tmp[2] = {"RIL_REQUEST_OEM_HOOK_RAW", "AT+ECAL"};
5212 sendATCMD(2, tmp, (RIL_SOCKET_ID) (id), info);
5213 break;
5214 }
5215 case RIL_REQUEST_GET_RADIO_CAPABILITY:
5216 {
5217 getRadioCapability(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5218 break;
5219 }
5220 default:
5221 RLOGE("don't support %d in init", id);
5222 if(info) {
5223 free(info);
5224 }
5225 }
5226}
5227
5228static void init(int id) {
5229 int waittoken;
5230 RIL_RadioState radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5231 while (radioState == RADIO_STATE_UNAVAILABLE) {
5232 sleep(1);
5233 radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5234 RLOGD("init socket id: %d, %s", id, radioStateToString(radioState));
5235 }
5236 RLOGD("init socket id: %d, %s", id, radioStateToString(radioState));
xja1c30b82022-01-25 16:13:48 +08005237 updataDataConnectState(id, false);
lh7b0674a2022-01-10 00:34:35 -08005238 sendRequestToMd(RIL_REQUEST_GET_SIM_STATUS, id);
5239
5240#if 0
5241 if (radioState != RADIO_STATE_ON) {
5242 RequestInfo* radio = creatRILInfoAndInit(RIL_REQUEST_RADIO_POWER, INIT, (RIL_SOCKET_ID) (id));
5243 waittoken = radio->token;
5244 RLOGD("[%s-%d]:token is %x", __FUNCTION__, __LINE__, radio->token);
5245 char* tmp[2] = { "RIL_REQUEST_RADIO_POWER", "1" };
5246 setRadioPower(2, tmp, (RIL_SOCKET_ID) (id), radio);
5247 waitResponse(waittoken);
5248 sleep(2);
5249 radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5250 RLOGD("NOW radio status %s", radioStateToString(radioState));
5251 }
5252# endif
5253 sendRequestToMd(RIL_REQUEST_DATA_REGISTRATION_STATE, id);
5254 sendRequestToMd(RIL_REQUEST_VOICE_REGISTRATION_STATE, id);
5255 sendRequestToMd(RIL_REQUEST_VOICE_RADIO_TECH, id);
5256 sendRequestToMd(RIL_REQUEST_DEVICE_IDENTITY,id);
5257 sendRequestToMd(RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, id);
5258 sendRequestToMd(RIL_REQUEST_OEM_HOOK_RAW, id);
5259 sendRequestToMd(RIL_REQUEST_GET_RADIO_CAPABILITY,id);
5260}
5261
5262static void initCoditions()
5263{
5264 mixer_init();
5265 if(utils::is_support_dsds()) {
5266 for(int i = 0; i < 2 ; i++) {
5267 init(i);
5268 }
5269 }
5270
5271 if(utils::is_suppport_dsss()) {
5272 int id = Phone_utils::get_enable_sim_for_dsss();
5273 init(id);
5274 }
5275}
5276
5277
5278//For UDP sokcet send response to client
5279static int SendRespToClient(const void *data, size_t dataSize)
5280{
5281 const uint8_t *toWrite;
5282 size_t writeOffset = 0;
5283
5284 toWrite = (const uint8_t *)data;
5285
5286 if (toWrite == NULL) {
5287 //buf is invaild
5288 return -1;
5289 }
5290
5291 while (writeOffset < dataSize) {
5292 ssize_t written;
5293 do {
5294 //written = write (fd, toWrite + writeOffset,dataSize - writeOffset);
5295 written = sendto(server_socket_fd, toWrite + writeOffset, dataSize - writeOffset,
5296 0, (struct sockaddr *)&client_addr, sizeof(client_addr));
5297 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
5298
5299 if (written >= 0) {
5300 writeOffset += written;
5301 } else { // written < 0
5302 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
5303 return -1;
5304 }
5305 }
5306
5307 return 0;
5308}
5309
5310static UnsolResponseInfo* find_mtk_unsol_command(int request)
5311{
5312 int i;
5313 for (i = 0; i < (int32_t)NUM_ELEMS(s_mtk_unsolResponses); i++)
5314 if (s_mtk_unsolResponses[i].requestNumber == request)
5315 return (&s_mtk_unsolResponses[i]);
5316 return ((UnsolResponseInfo *)NULL);
5317}
5318
5319static int
5320onSupports (int requestCode)
5321{
5322 switch(requestCode)
5323 {
5324 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return 1;
5325 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return 1;
5326 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return 1;
5327 case RIL_UNSOL_RESPONSE_NEW_SMS: return 1;
5328 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return 1;
5329 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return 1;
5330 case RIL_UNSOL_ON_USSD: return 1;
5331 case RIL_UNSOL_ON_USSD_REQUEST: return 1;
5332 case RIL_UNSOL_NITZ_TIME_RECEIVED: return 1;
5333 case RIL_UNSOL_SIGNAL_STRENGTH: return 1;
5334 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return 1;
5335 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return 1;
5336 case RIL_UNSOL_STK_SESSION_END: return 1;
5337 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return 1;
5338 case RIL_UNSOL_STK_EVENT_NOTIFY: return 1;
5339 case RIL_UNSOL_STK_CALL_SETUP: return 1;
5340 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return 1;
5341 case RIL_UNSOL_SIM_REFRESH: return 1;
5342 case RIL_UNSOL_CALL_RING: return 1;
5343 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return 1;
5344 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return 1;
5345 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return 1;
5346 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return 0;
5347 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return 1;
5348 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return 1;
5349 case RIL_UNSOL_CDMA_CALL_WAITING: return 1;
5350 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return 0;
5351 case RIL_UNSOL_CDMA_INFO_REC: return 0;
5352 case RIL_UNSOL_OEM_HOOK_RAW: return 1;
5353 case RIL_UNSOL_RINGBACK_TONE: return 1;
5354 case RIL_UNSOL_RESEND_INCALL_MUTE: return 0;
5355 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return 0;
5356 case RIL_UNSOL_CDMA_PRL_CHANGED: return 0;
5357 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return 1;
5358 case RIL_UNSOL_RIL_CONNECTED: return 1;
5359 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return 1;
5360 case RIL_UNSOL_CELL_INFO_LIST: return 1;
5361 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return 1;
5362 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return 1;
5363 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return 1;
5364 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return 0;
5365 case RIL_UNSOL_DC_RT_INFO_CHANGED: return 0;
5366 case RIL_UNSOL_RADIO_CAPABILITY : return 1;
5367 case RIL_UNSOL_MAL_RESTART : return 1;
5368 case RIL_UNSOL_CALL_INFO_INDICATION : return 1;
5369 case RIL_UNSOL_CRSS_NOTIFICATION : return 0;
5370 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return 1;
5371 case RIL_UNSOL_ECONF_RESULT_INDICATION : return 1;
5372 case RIL_UNSOL_STK_BIP_PROACTIVE_COMMAND : return 0;
5373 case RIL_UNSOL_MAL_AT_INFO: return 1;
5374 case RIL_UNSOL_ECALL_MSDHACK: return 1;
5375 case RIL_UNSOL_TX_POWER: return 1;
5376 case RIL_UNSOL_NETWORK_INFO: return 1;
5377#ifdef ECALL_SUPPORT
5378 case RIL_UNSOL_ECALL_INDICATIONS: return 1;
5379#endif /*ECALL_SUPPORT*/
5380#ifdef KEEP_ALIVE
5381 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return 1;
5382#endif /*KEEP_ALIVE*/
5383 case RIL_UNSOL_ON_USSI: return 1;
5384 case RIL_UNSOL_ECC_NUM: return 1;
5385 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return 1;
5386 default: return 0;
5387 }
5388}
5389
5390int parse_param(char *cmd, char *argv[], int max_args)
5391{
5392 char *pos, *pos2;
5393 int argc = 0;
5394 printf("warren test cmd=%s\n",cmd);
5395 pos = cmd;
5396 while (1) {
5397 // Trim the space characters.
5398 while (*pos == ' ') {
5399 pos++;
5400 }
5401
5402 if (*pos == '\0') {
5403 break;
5404 }
5405
5406 // One token may start with '"' or other characters.
5407 if (*pos == '"' && (pos2 = strrchr(pos+1, '"'))) {
5408 argv[argc++] = pos + 1;
5409 *pos2 = '\0';
5410 pos = pos2 + 1;
5411 if(*pos == '\n'){
5412 *pos = '\0';
5413 pos = pos + 1;
5414 }
5415
5416 } else {
5417 argv[argc++] = pos;
5418 while (*pos != '\0' && *pos != ' '&& *pos != '\n') {
5419 pos++;
5420 }
5421 *pos++ = '\0';
5422
5423 if(argc == 1) {
5424 char* at_cmd = strstr(argv[0], "RIL_REQUEST_OEM_HOOK_RAW");
5425 if(at_cmd != NULL) {
5426 while (*pos == ' ') {
5427 pos++;
5428 }
5429 argv[argc++] = pos;
5430 while (*pos != '\0' && *pos != '\n') {
5431 pos++;
5432 }
5433 *pos++ = '\0';
5434 break;
5435 }
5436 }
5437
5438 }
5439
5440 // Check if the maximum of arguments is reached.
5441 if (argc == max_args) {
5442 break;
5443 }
5444 }
5445
5446 return argc;
5447}
5448
5449/* Look up NAME as the name of a command, and return a pointer to that
5450 command. Return a NULL pointer if NAME isn't a command name. */
5451COMMAND* find_command (char *name)
5452{
5453 register int i;
5454
5455 for (i = 0; commands[i].name; i++)
5456 if (strcmp (name, commands[i].name) == 0)
5457 return (&commands[i]);
5458
5459 return ((COMMAND *)NULL);
5460}
5461
5462CommandInfo* find_mtk_command (int request)
5463{
5464 int i;
5465 for (i = 0; i < (int32_t)NUM_ELEMS(mtk_s_command); i++)
5466 if (mtk_s_command[i].requestNumber == request)
5467 return (&mtk_s_command[i]);
5468 return ((CommandInfo *)NULL);
5469}
5470
5471/* The user wishes to quit using this program. Just set DONE non-zero. */
5472static int com_quit (int argc, char *argv[], RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5473{
5474 exit(EXIT_SUCCESS);
5475 return (0);
5476}
5477
5478static int enableSyslog(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5479{
5480 if(argc < 2)
5481 {
5482 RLOGE("[Error] enable syslog paramter is error\n");
5483 free(pRI);
5484 return -1;
5485 }
5486 enable_syslog = atoi(argv[1]);
5487 RLOGE("%s syslog\n",enable_syslog ? "enable" :"disable");
5488 free(pRI);
5489 return 0;
5490}
5491
5492static int enableBTResponse(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5493{
5494 if(argc < 2)
5495 {
5496 RLOGE("[Error] enable BT response paramter is error\n");
5497 free(pRI);
5498 return -1;
5499 }
5500 enable_bt_resp = atoi(argv[1]);
5501 RLOGE("%s bt response!\n",enable_bt_resp ? "enable" :"disable");
5502 free(pRI);
5503 return 0;
5504
5505}
5506
5507char Time_buf[24];
5508void GetTimeString(char * buf)
5509{
5510 time_t timep;
5511 struct tm p;
5512
5513 if(buf == NULL){
5514 RLOGE("[Error] GetTimeString: buf is Null\n");
5515 return;
5516 }
5517 //memset(buf,0,sizeof(buf));
5518 time(&timep);
5519 localtime_r(&timep,&p);
5520 sprintf(buf,"%d_%d_%d %d:%d:%d",(1900+p.tm_year),(1+p.tm_mon),p.tm_mday,
5521 (p.tm_hour),p.tm_min,p.tm_sec);
5522// printf("data is %s\n",buf);
5523
5524 return;
5525}
5526/*Warren add for t800 RIL Service 2021/12/10 start*/
5527int lynqAssemblyParcelheader(Parcel &p,int slot,int request,int respType,int error)
5528{
5529 p.writeInt32 (respType);
5530 p.writeInt32 (request);
5531 /*warren add for t800 ril servie 2021/12/15 start*/
5532 p.writeInt32(slot);
5533 /*warren add for t800 ril servie 2021/12/15 end*/
5534 p.writeInt32 (error);
5535 return 0;
5536}
5537void LYNQ_RIL_urcClientInit()
5538{
5539 int len = 0;
5540 int on=1;
5541 int ret = 0;
5542 lynq_urc_socket_fd = socket(AF_INET,SOCK_DGRAM,0);
5543 if(lynq_urc_socket_fd < 0)
5544 {
5545 perror("creaet socket for udp fail");
5546 return;
5547 }
5548 /* 设置socket允许重复使用地址与端口,SO_REUSEADDR值为2 */
5549 //setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
5550 /* 使能广播功能,SO_BROADCAST值为6 */
5551 ret= setsockopt(lynq_urc_socket_fd,SOL_SOCKET,SO_BROADCAST,&on,sizeof(on));
5552 if(ret<0)
5553 {
5554 RLOGD("set broadcast fail!!!\n");
5555 exit(1);
5556 }
5557 urc_broadcast_addr.sin_family = AF_INET; //IPv4
5558 urc_broadcast_addr.sin_port = htons(LYNQ_BRODCAST_PORT);
5559 urc_broadcast_addr.sin_addr.s_addr = inet_addr("255.255.255.255" );//255.255.255.255 broadcast addrress.
5560 printf("LYNQ_RIL_urcClientInit success!!!\n");
5561 return;
5562 /*
5563 while(1)
5564 {
5565 len = sendto(lynq_urc_socket_fd,"hello world",11,0,(struct sockaddr *)&urc_broadcast_addr,sizeof(urc_broadcast_addr));
5566 if(len > 0)
5567 {
5568 printf("sendto success,len=%d\n",len);
5569 }
5570 else
5571 {
5572 printf("sendto fail\n");
5573 }
5574 sleep(1);
5575 }
5576 */
5577}
5578void LYNQ_RIL_RecSocket()
5579{
5580 RLOGD("LYNQ_RIL_RecSocket start\n");
5581 char *argv[MAX_ARGS];
5582 int argc = 0;
5583 int ep_fd = 0;
5584 int en_fd = 0;
5585 struct epoll_event lynq_ev;
5586 struct epoll_event lynq_events[LYNQ_SOCKET_ENVNT_FD_MAX];
5587 //prctl(PR_SET_NAME,(unsigned long)"UDP_Thr");
5588
5589 /*listen UPD SOCKET port */
5590 struct sockaddr_in server_addr;
5591 struct sockaddr_in lynqClient_addr;
5592 bzero(&server_addr, sizeof(server_addr));
5593 server_addr.sin_family = AF_INET;
5594 server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
5595 server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
5596 /* create socket */
5597 //int server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
5598 server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
5599 if(server_socket_fd == -1)
5600 {
5601 RLOGE("Create Socket Failed:");
5602 exit(1);
5603 }
5604
5605 /* bind socket port*/
5606 if(-1 == (bind(server_socket_fd,(struct sockaddr*)&server_addr,sizeof(server_addr))))
5607 {
5608 RLOGE("Server Bind Failed:");
5609 exit(1);
5610 }
5611 /* create epoll fd,add socket to epoll */
5612 ep_fd = epoll_create(LYNQ_SOCKET_ENVNT_FD_MAX);
5613 //int len = sizeof(struct sockaddr_in);
5614 lynq_ev.events = EPOLLIN | EPOLLET;
5615 lynq_ev.data.fd = server_socket_fd;
5616 if(epoll_ctl(ep_fd, EPOLL_CTL_ADD, server_socket_fd, &lynq_ev) < 0)
5617 {
5618 fprintf(stderr, "epoll set insertion error: fd=%d\n", server_socket_fd);
5619 return;
5620 }
5621 else
5622 {
5623 printf("monitor socket add epoll success!!!\n");
5624 }
5625 char buffer[LYNQ_SOCKET_BUFFER];
5626 lynq_client_t *client_tmp = NULL;
5627 /* tranlate data */
5628 while(true)
5629 {
5630 if(!s_registerCalled)
5631 {
5632 sleep(1);
5633 continue;
5634 }
5635 en_fd = epoll_wait(ep_fd, lynq_events, 10000, -1);//###Check valid
5636 if(en_fd <=0 )
5637 {
5638 continue;
5639 }
5640 for (int n = 0; n < en_fd; ++n)
5641 {
5642 if (lynq_events[n].data.fd == server_socket_fd)
5643 {
5644 /* define address to catch the client addreess*/
5645 //struct sockaddr_in client_addr;
5646 socklen_t client_addr_length = sizeof(lynqClient_addr);
5647 /* receive the data */
5648 bzero(buffer, LYNQ_SOCKET_BUFFER);
5649 if(recvfrom(server_socket_fd, buffer, LYNQ_SOCKET_BUFFER,0,(struct sockaddr*)&lynqClient_addr, &client_addr_length) == -1)
5650 {
5651 RLOGE("Receive Data Failed:");
5652 continue;
5653 }
5654 client_tmp = (lynq_client_t*)buffer;
5655 RLOGD("[LYNQ socketId] utoken=%d,request=%d,len=%d,param=%s",client_tmp->uToken,client_tmp->request,client_tmp->paramLen,client_tmp->param);
5656 //char test[36] = {};
5657 //sprintf(test,"test okay len = %d",client_tmp->paramLen);
5658 //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&client_addr,client_addr_length);
5659 argv[0] = (char *)lynq_requset_to_string(client_tmp->request);
5660 argc = 0;
5661 if(client_tmp->paramLen > 0)
5662 {
5663 /*transfer struct*/
5664 argc = parse_param(client_tmp->param, argv+1, MAX_ARGS);
5665 if(argc < 1)
5666 {
5667 RLOGE("%s: error input.", buffer);
5668 continue;
5669 }
5670 }
5671 printf("argc =%d\n",argc);
5672 argc = argc+1;
5673 for(int t = 0;t<argc;t++)
5674 {
5675 RLOGD("warren test argv[%d]=%s\n",t,argv[t]);
5676 }
5677 COMMAND *command = find_command(argv[0]);
5678 if(!command)
5679 {
5680 RLOGE("%s: No such command for DemoApp", argv[0]);
5681 continue;
5682 }
5683 int32_t request;
5684 request = command->request;
5685 RIL_SOCKET_ID id = RIL_SOCKET_1;
5686 if(utils::is_support_dsds()) {
5687 id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
5688 } else if(utils::is_suppport_dsss()) {
5689 id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
5690 }
5691 if(request == -1)
5692 {
5693 (*(command->func)) (argc, argv, id, NULL);
5694 continue;
5695 }
5696 if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
5697 RLOGW("unsupported request code %d token %d", request);
5698 // FIXME this should perhaps return a response
5699 continue;
5700 }
5701 RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
5702 RequestInfo *pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
5703 pRI->uToken = client_tmp->uToken;
5704 pRI->lynqEvent = 1;
5705 pRI->uClient_addr.sin_family = lynqClient_addr.sin_family;
5706 pRI->uClient_addr.sin_addr.s_addr = lynqClient_addr.sin_addr.s_addr;
5707 pRI->uClient_addr.sin_port = lynqClient_addr.sin_port;
5708 //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&pRI->uClient_addr,client_addr_length);
5709 //pRI->uClient_addr.sa_family = (struct sockaddr)client_addr.sa_family;
5710 //memcpy(pRI->uClient_addr.sa_data,&client_addr
5711 //Radio on/off only allow one thread operate.
5712 if(request == RIL_REQUEST_RADIO_POWER)
5713 {
5714 speciaRequest_wait();
5715 }
5716 memset(Time_buf,0,sizeof(Time_buf));
5717 GetTimeString(Time_buf);
5718 //FUNCTION_CALLED(Time_buf,requestToString(request));
5719 int waittoken = pRI->token;
5720 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
5721 FUNCTION_CALLED(Time_buf,requestToString(request));
5722 waitResponse(waittoken);
5723 memset(Time_buf,0,sizeof(Time_buf));
5724 GetTimeString(Time_buf);
5725 FUNCTION_RETURN(Time_buf,requestToString(request));
5726 }
5727 }
5728 }
5729 RLOGD("close socket fd");
5730 close(server_socket_fd);
5731 return ;
5732}
5733int LYNQ_RIL_respSocket(Parcel &p,RIL_Token t)
5734{
5735 RLOGD("LYNQ_RIL_respSocket send start");
5736 int ret =0;
5737 bool sendResult =false;
5738 ssize_t sent = 0;
5739 uint8_t dataLength[4];
5740 int verify = 0x55aa;
5741 RequestInfo *pRI = (RequestInfo *)t;
5742 if(pRI->lynqEvent!=1)
5743 {
5744 RLOGD("this is internal event!!!");
5745 return -1;
5746 }
5747 int dataSize = p.dataSize();
5748 const uint8_t* data = p.data();
5749 RLOGD("lynqSocketSend RESPONSE!!!! ");
lh7b0674a2022-01-10 00:34:35 -08005750 sent = sendto(server_socket_fd, data, dataSize, 0, (struct sockaddr *)&pRI->uClient_addr, sizeof(pRI->uClient_addr));
5751 if( sent < 0 )
5752 {
5753 RLOGE("lynqSocketSend send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
5754 sent,server_socket_fd, dataSize);
lh7b0674a2022-01-10 00:34:35 -08005755 return -1;
5756 }
5757 return 0;
5758}
5759int LYNQ_RIL_respSocket_sp(Parcel &p,RequestInfo *pRI)
5760{
5761 RLOGD("LYNQ_RIL_respSocket send start");
5762 int ret =0;
5763 bool sendResult =false;
5764 ssize_t sent = 0;
5765 uint8_t dataLength[4];
5766 int verify = 0x55aa;
5767 int dataSize = p.dataSize();
5768 const uint8_t* data = p.data();
5769 if(pRI->lynqEvent!=1)
5770 {
5771 RLOGD("this is internal event!!!");
5772 return -1;
5773 }
5774 RLOGD("lynqSocketSend RESPONSE!!!! ");
lh7b0674a2022-01-10 00:34:35 -08005775
5776 sent = sendto(server_socket_fd, data, dataSize, 0, (struct sockaddr *)&pRI->uClient_addr, sizeof(pRI->uClient_addr));
5777 if( sent < 0 )
5778 {
5779 RLOGE("lynqSocketSend send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
5780 sent,server_socket_fd, dataSize);
lh7b0674a2022-01-10 00:34:35 -08005781 return -1;
5782 }
5783 return 0;
5784}
5785
5786int LYNQ_RIL_urcBroadcast(Parcel &p)
5787{
5788 RLOGD("LYNQ_RIL_urcBroadcast send start");
5789 int ret =0;
5790 bool sendResult =false;
5791 ssize_t sent = 0;
5792 uint8_t dataLength[4];
5793 int verify = 0x55aa;
lhf6eea122022-01-20 19:32:14 -08005794 p.setDataPosition(0);
lh7b0674a2022-01-10 00:34:35 -08005795 int dataSize = p.dataSize();
5796 const uint8_t* data = p.data();
5797 sent = sendto(lynq_urc_socket_fd, data, dataSize, 0, (struct sockaddr *)&urc_broadcast_addr, sizeof(urc_broadcast_addr));
5798 if( sent < 0 )
5799 {
5800 RLOGE("LYNQ_RIL_urcBroadcast send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
5801 sent,lynq_urc_socket_fd, dataSize);
5802 return -1;
5803 }
5804 return 0;
5805}
5806/*Warren add for t800 RIL Service 2021/12/10 end*/
5807
5808void
5809RIL_StartRevSocket()
5810{
5811 RLOGD("RIL_StartRevSocket start\n");
xja1c30b82022-01-25 16:13:48 +08005812 char *argv[MAX_ARGS] = {0};
lh7b0674a2022-01-10 00:34:35 -08005813 int argc = 0;
5814
5815 prctl(PR_SET_NAME,(unsigned long)"UDP_Thr");
5816
5817 /*listen UPD SOCKET port */
5818 struct sockaddr_in server_addr;
5819 bzero(&server_addr, sizeof(server_addr));
5820 server_addr.sin_family = AF_INET;
5821 server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
5822 server_addr.sin_port = htons(SERVER_PORT);
5823 /* create socket */
5824 //int server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
5825 server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
5826 if(server_socket_fd == -1)
5827 {
5828 RLOGE("Create Socket Failed:");
5829 exit(1);
5830 }
5831
5832 /* bind socket port*/
5833 if(-1 == (bind(server_socket_fd,(struct sockaddr*)&server_addr,sizeof(server_addr))))
5834 {
5835 RLOGE("Server Bind Failed:");
5836 exit(1);
5837 }
5838
5839 /* tranlate data */
5840 while(true)
5841 {
5842 if(!s_registerCalled)
5843 {
5844 sleep(1);
5845 continue;
5846 }
5847 /* define address to catch the client addreess*/
5848 //struct sockaddr_in client_addr;
5849 socklen_t client_addr_length = sizeof(client_addr);
5850
5851 /* receive the data */
5852 char buffer[BUFFER_SIZE];
5853 bzero(buffer, BUFFER_SIZE);
5854 if(recvfrom(server_socket_fd, buffer, BUFFER_SIZE,0,(struct sockaddr*)&client_addr, &client_addr_length) == -1)
5855 {
5856 RLOGE("Receive Data Failed:");
5857 continue;
5858 }
5859 RLOGD("DemoAPP:%s, receve: %s", inet_ntoa(client_addr.sin_addr), buffer);
5860 if(mtkItTest(buffer)) {
5861 RLOGD("mtkItTest() handle.");
5862 continue;
5863 }
5864 int argc = parse_param(buffer, argv, MAX_ARGS);
5865 if(argc < 1)
5866 {
5867 RLOGE("%s: error input.", buffer);
5868 continue;
5869 }
5870 COMMAND *command = find_command(argv[0]);
5871 if(!command)
5872 {
5873 RLOGE("%s: No such command for DemoApp", argv[0]);
5874 continue;
5875 }
5876
5877 int32_t request;
5878
5879 request = command->request;
5880
5881 RIL_SOCKET_ID id = RIL_SOCKET_1;
5882 if(utils::is_support_dsds()) {
5883 id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
5884 } else if(utils::is_suppport_dsss()) {
5885 id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
5886 }
5887
5888 if(request == -1)
5889 {
5890 (*(command->func)) (argc, argv, id, NULL);
5891 continue;
5892 }
5893
5894 if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
5895 RLOGW("unsupported request code %d token %d", request);
5896 // FIXME this should perhaps return a response
5897 continue;
5898 }
5899
5900 RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
5901
5902
5903 RequestInfo *pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
5904 //Radio on/off only allow one thread operate.
5905 if(request == RIL_REQUEST_RADIO_POWER)
5906 {
5907 speciaRequest_wait();
5908 }
5909 memset(Time_buf,0,sizeof(Time_buf));
5910 GetTimeString(Time_buf);
5911 //FUNCTION_CALLED(Time_buf,requestToString(request));
5912 int waittoken = pRI->token;
5913 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
5914 FUNCTION_CALLED(Time_buf,requestToString(request));
5915 waitResponse(waittoken);
5916 memset(Time_buf,0,sizeof(Time_buf));
5917 GetTimeString(Time_buf);
5918 FUNCTION_RETURN(Time_buf,requestToString(request));
5919 }
5920
5921 RLOGD("close socket fd");
5922 close(server_socket_fd);
5923 return ;
5924}
5925
5926const int waitResponse(int token)
5927{
5928 int waitToken = token;
5929 struct timeval now;
5930 struct timespec timeout;
5931 if((token&BLOCK_MARK) != BLOCK_MARK){
5932 RLOGD("No need wait!,token is %x!",token);
5933 return 0;
5934 }
5935
5936 gettimeofday(&now,NULL);
5937 timeout.tv_sec = now.tv_sec+60; //timeout is 1min
5938 timeout.tv_nsec = now.tv_usec*1000;
5939
5940 RLOGD("Block Request, wait token is %x,",waitToken);
5941 BLOCK_LOCK();
5942 if(waitToken == wakeup_token)
5943 RLOGD("response early than return, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
5944 while(!(waitToken == wakeup_token)) {
5945 RLOGD("Wait Response, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
5946 int ret = BLOCK_WAIT(&timeout);
5947 if(ret == ETIMEDOUT){
5948 RLOGD("Wait Response timeout, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
5949 goto out;
5950 }
5951 }
5952 RLOGD("Response wakeup,token is %x!",wakeup_token);
5953 wakeup_token = -1;
5954out:
5955 BLOCK_UNLOCK();
5956 return 0;
5957}
5958
5959void *
5960eventLoop(void *param) {
5961 pthread_mutex_lock(&s_startupMutex);
5962 s_started = 1;
5963 pthread_cond_broadcast(&s_startupCond);
5964 pthread_mutex_unlock(&s_startupMutex);
5965 #ifdef ECALL_SUPPORT
5966 init_ecall_timer_all();
5967 #endif /**/ECALL_SUPPORT
5968 /*warren add for t800 ril service 2021/12/13 start*/
5969 //RIL_StartRevSocket();
5970 LYNQ_RIL_urcClientInit();
5971 LYNQ_RIL_RecSocket();
5972 /*warren add for t800 ril service 2021/12/13 end*/
5973 RLOGD("error in event_loop_base errno:%d", errno);
5974 // kill self to restart on error
5975 kill(0, SIGKILL);
5976
5977 return NULL;
5978}
5979
5980const int RspDispFunction(int request,char* arg, RIL_SOCKET_ID socket_id)
5981{
5982 int waittoken;
5983 RequestInfo *pRI = creatRILInfoAndInit(request, RSPD, socket_id);
5984 if(pRI == NULL)
5985 return 0;
5986 waittoken = pRI->token;
5987 switch (request) {
5988 case RIL_REQUEST_GET_CURRENT_CALLS:
5989 {
5990 RLOGD("request Current list start!");
5991 Parcel p;
5992 pRI->pCI->dispatchFunction(p, pRI);
5993 waitResponse(waittoken);
5994 RLOGD("request Current list end!");
5995 }
5996 break;
5997
5998 case RIL_REQUEST_ANSWER:
5999 {
6000 RLOGD("request Answer a MT call start!");
6001 Parcel p;
6002 pRI->pCI->dispatchFunction(p, pRI);
6003 waitResponse(waittoken);
6004 RLOGD("request Answer a MT call end!");
6005 }
6006 break;
6007
6008 case RIL_REQUEST_GET_SIM_STATUS:
6009 {
6010 int ret=getIccCardStatus(1, NULL, socket_id, pRI);
6011 if(ret == 0)
6012 waitResponse(waittoken);
6013 }
6014 break;
6015
6016 case RIL_REQUEST_DATA_REGISTRATION_STATE:
6017 {
6018 int ret=getDataRegistrationState(1, NULL, socket_id,pRI);
6019 if(ret == 0)
6020 waitResponse(waittoken);
6021 }
6022 break;
6023
6024 case RIL_REQUEST_VOICE_REGISTRATION_STATE:
6025 {
6026 int ret=getVoiceRegistrationState(1, NULL, socket_id,pRI);
6027 if(ret == 0)
6028 waitResponse(waittoken);
6029 }
6030 break;
6031 case RIL_REQUEST_SMS_ACKNOWLEDGE:
6032 {
6033 char* tmp[3] = {"RIL_REQUEST_SMS_ACKNOWLEDGE", "1", "0"};
6034 acknowledgeIncomingGsmSmsWithPdu(3,tmp,socket_id,pRI);
6035 waitResponse(waittoken);
6036 RLOGD("acknowledge last Incoming Gsm Sms : RIL_REQUEST_SMS_ACKNOWLEDGE end!");
6037 }
6038 break;
6039 case RIL_REQUEST_OEM_HOOK_RAW:
6040 {
6041 if(arg != NULL)
6042 {
6043 RLOGD("request OEM HOOK RAW start!");
6044 pRI->token = pRI->token|BLOCK_MARK;
6045 int waittokenOEM = pRI->token;
6046 Parcel p;
6047
6048 size_t pos = p.dataPosition();
6049 int len = strlen(arg);
6050 p.writeInt32(len);
6051 p.write((const void*)arg,len);
6052
6053 p.setDataPosition(pos);
6054 RLOGD("emSendATCommand: %s %d\n",arg,strlen(arg));
6055 pRI->pCI->dispatchFunction(p, pRI);
6056 waitResponse(waittokenOEM);
6057 } else {
6058 if(pRI){
6059 free(pRI);
6060 }
6061 RLOGE("at command shouldn't null");
6062 }
6063 break;
6064 }
6065 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM:
6066 {
6067 char* tmp[2] = {"RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM", "no"};
6068 handleCallSetupRequestFromSim(2, tmp, socket_id,pRI);
6069 waitResponse(waittoken);
6070 RLOGD("timeout 1 minutes, response no by RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM");
6071 break;
6072 }
6073 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE:
6074 {
6075 char* tmp[2] ={"RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE", arg};
6076 RLOGD("tmp[0]=%s, tmp[1]=%s, arg=%s", tmp[0], tmp[1], arg);
6077 sendTerminalResponse(2, tmp, socket_id, pRI);
6078 waitResponse(waittoken);
6079 break;
6080 }
6081 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:
6082 {
6083 acknowledgeLastIncomingCdmaSms(1, NULL,socket_id,pRI);
6084 waitResponse(waittoken);
6085 break;
6086 }
6087 case RIL_REQUEST_RADIO_POWER:
6088 {
6089 RLOGD("response loop, RIL_REQUEST_RADIO_POWER: %s", (arg == NULL ? "nul": arg));
6090 if(arg != NULL) {
6091 char* tmp[2] = {"RIL_REQUEST_RADIO_POWER", arg};
6092 setRadioPower(2,tmp,socket_id,pRI);
6093 waitResponse(waittoken);
6094 } else {
6095 if(pRI){
6096 free(pRI);
6097 }
6098 RLOGE("response loop, RIL_REQUEST_RADIO_POWER fail");
6099 }
6100 break;
6101 }
6102 case RIL_REQUEST_ALLOW_DATA:
6103 {
6104 int default_id = get_default_sim_data();
6105 RLOGD("RspDispFunction: socket_id=%d switch_id=%d", socket_id, default_id);
6106 char* argv[2] = {"RIL_REQUEST_ALLOW_DATA","0"};
6107 if(socket_id == default_id) {
6108 utils::mtk_property_set(PROP_DEFAULT_DATA_SIM, std::to_string(socket_id + 1).c_str());
6109 argv[1] = "1";
6110 }
6111 while(!isRadioAvailable(socket_id)) {
6112 sleep(1);
6113 RLOGD("[SIM%d]RspDispFunction(RIL_REQUEST_ALLOW_DATA): wait radio available", socket_id);
6114 }
6115 setDataAllowed(2, argv, socket_id, pRI);
6116 waitResponse(waittoken);
6117 break;
6118 }
6119 case RIL_REQUEST_CDMA_FLASH:
6120 {
6121 sendCDMAFeatureCode(1, NULL, socket_id, pRI);
6122 waitResponse(waittoken);
6123 break;
6124 }
6125 default:
xja1c30b82022-01-25 16:13:48 +08006126 if(pRI) {
6127 free(pRI);
6128 pRI = NULL;
6129 }
lh7b0674a2022-01-10 00:34:35 -08006130 break;
6131 }
6132 return 0;
6133}
6134
6135void * responseLoop(void *param) {
6136 pthread_mutex_lock(&s_startupMutex);
6137 s_responseDispatch= 1;
6138 pthread_cond_broadcast(&s_startupCond);
6139 pthread_mutex_unlock(&s_startupMutex);
6140 responseDispatch();
6141 RLOGD("error in response_loop_base errno:%d", errno);
6142 // kill self to restart on error
6143 kill(0, SIGKILL);
6144
6145 return NULL;
6146}
6147
6148void ATCIRequest(int request,char* reqString, void* t,int argc,char**argv)
6149{
xja1c30b82022-01-25 16:13:48 +08006150 if(t == NULL) {
6151 RLOGE("ATCIRequest t is null");
6152 return;
6153 }
lh7b0674a2022-01-10 00:34:35 -08006154 RequestInfo *pRI = (RequestInfo *)t;
6155 int waittoken;
6156 if (request < RIL_REQUEST_VENDOR_BASE) {
6157 pRI->pCI = &(s_commands[request]);
6158 } else {
6159 pRI->pCI = find_mtk_command(request);
6160 }
xja1c30b82022-01-25 16:13:48 +08006161 if(pRI->pCI == NULL){
lh7b0674a2022-01-10 00:34:35 -08006162 RLOGE("pCI command not found!");
xja1c30b82022-01-25 16:13:48 +08006163 if(pRI) {
6164 free(pRI);
6165 }
6166 return;
6167 }
lh7b0674a2022-01-10 00:34:35 -08006168
6169 if(utils::is_suppport_dsss()){
6170 pRI->socket_id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
6171 }
6172
6173 if(utils::is_support_dsds() && (request != RIL_REQUEST_RADIO_POWER)){
6174 pRI->socket_id = (RIL_SOCKET_ID)get_atci_sim();
6175 }
6176
6177 pRI->p_next = NULL;
6178
6179 COMMAND *command = find_command(reqString);
6180
6181 if(command == NULL) {
6182 RLOGE("ATCI request command find error!");
xja1c30b82022-01-25 16:13:48 +08006183 if(pRI) {
6184 free(pRI);
6185 }
6186 return;
lh7b0674a2022-01-10 00:34:35 -08006187 } else {
6188 RLOGE("ATCI request name is %s!",command->name);
6189 }
6190
6191 pRI->token = GenerateToken(ATCI, request);
6192 waittoken = pRI->token;
6193 if(request == RIL_REQUEST_RADIO_POWER) {
6194 speciaRequest_wait();
6195 }
6196 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
6197 //need wait Ril_onRequestComplete return.
6198 waitResponse(waittoken);
6199 return;
6200}
6201
6202void startWakupLoop(void)
6203{
6204 pthread_t WakeupReasonThread;
6205
6206 RLOGD("startWakupLoop()");
6207 pthread_mutex_lock(&s_startupMutex);
6208
6209 pthread_attr_t attr;
6210 pthread_attr_init(&attr);
6211 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
6212
6213 int result = pthread_create(&WakeupReasonThread, &attr, wakeup_reason_loop, NULL);
6214 if (result != 0) {
6215 RLOGW("Failed to create wakeup reason thread: %s", strerror(result));
6216 goto done;
6217 }
6218
6219done:
6220 pthread_mutex_unlock(&s_startupMutex);
6221}
6222
6223void startPMLoop(void)
6224{
6225 pthread_t atciSocketThread;
6226
6227 RLOGD("startPMLoop()");
6228 pthread_mutex_lock(&s_startupMutex);
6229
6230 pthread_attr_t attr;
6231 pthread_attr_init(&attr);
6232 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
6233
6234 int result = pthread_create(&atciSocketThread, &attr, StartPMSocket, NULL);
6235 if (result != 0) {
6236 RLOGW("Failed to create PM thread: %s", strerror(result));
6237 goto done;
6238 }
6239
6240done:
6241 pthread_mutex_unlock(&s_startupMutex);
6242}
6243
6244void startGdbusLoop(void)
6245{
6246 pthread_t atciSocketThread;
6247
6248 RLOGD("startGdbusLoop()");
6249 pthread_mutex_lock(&s_startupMutex);
6250
6251 pthread_attr_t attr;
6252 pthread_attr_init(&attr);
6253 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
6254
6255 int result = pthread_create(&atciSocketThread, &attr, init_data_gdbus_cb, NULL);
6256 if (result != 0) {
6257 RLOGW("Failed to create gdbus thread: %s", strerror(result));
6258 goto done;
6259 }
6260
6261done:
6262 pthread_mutex_unlock(&s_startupMutex);
6263}
6264
6265void startATCILoop(void)
6266{
6267 pthread_t atciSocketThread;
6268
6269 RLOGD("startATCILoop()");
6270 pthread_mutex_lock(&s_startupMutex);
6271
6272 pthread_attr_t attr;
6273 pthread_attr_init(&attr);
6274 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
6275
6276 int result = pthread_create(&atciSocketThread, &attr, StartATCISocket, NULL);
6277 if (result != 0) {
6278 RLOGW("Failed to create ATCI thread: %s", strerror(result));
6279 goto done;
6280 }
6281
6282done:
6283 pthread_mutex_unlock(&s_startupMutex);
6284}
6285
6286void RIL_startEventLoop(void)
6287{
6288 RLOGD("RIL_startEventLoop()");
lhf6eea122022-01-20 19:32:14 -08006289 lynq_init_sms_manager();
lh7b0674a2022-01-10 00:34:35 -08006290 /* spin up eventLoop thread and wait for it to get started */
6291 s_started = 0;
6292 pthread_mutex_lock(&s_startupMutex);
6293
6294 pthread_attr_t attr;
6295 pthread_attr_init(&attr);
6296 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
6297
6298 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
6299 if (result != 0) {
6300 RLOGW("Failed to create dispatch thread: %s", strerror(result));
6301 goto done;
6302 }
6303
6304 while (s_started == 0) {
6305 pthread_cond_wait(&s_startupCond, &s_startupMutex);
6306 }
6307
6308 result = pthread_create(&s_tid_dispatch, &attr, responseLoop, NULL);
6309 if (result != 0) {
6310 RLOGW("Failed to create response dispatch thread: %s", strerror(result));
6311 goto done;
6312 }
6313
6314 while (s_responseDispatch == 0) {
6315 pthread_cond_wait(&s_startupCond, &s_startupMutex);
6316 }
6317done:
6318 pthread_mutex_unlock(&s_startupMutex);
6319}
6320
6321void printInputArgs(int argc, char** argv)
6322{
6323 int i=0;
6324
6325 for(i=0; i<argc; i++)
6326 {
6327 RLOGD("%s", argv[i]);
6328 }
6329}
6330
6331void initRequestInfo(RequestInfo *pRI, int request, int mode, RIL_SOCKET_ID soc_id)
6332{
6333 pRI->token = GenerateToken(mode, request);
6334 if (request < RIL_REQUEST_VENDOR_BASE) {
6335 pRI->pCI = &(s_commands[request]);
6336 } else {
6337 pRI->pCI = find_mtk_command(request);
6338 }
6339 pRI->socket_id = soc_id;
6340
6341 pRI->p_next = NULL;
6342}
6343
6344void getVoiceAndDataRegistrationState(RIL_SOCKET_ID soc_id)
6345{
6346 ARspRequest(RIL_REQUEST_DATA_REGISTRATION_STATE,soc_id);
6347 ARspRequest(RIL_REQUEST_VOICE_REGISTRATION_STATE,soc_id);
6348}
6349
6350void requestAnswer(RIL_SOCKET_ID soc_id)
6351{
6352 ARspRequest(RIL_REQUEST_ANSWER,soc_id);
6353 return;
6354}
6355void requestSMSACKNOWLEDGE(RIL_SOCKET_ID soc_id)
6356{
6357 ARspRequest(RIL_REQUEST_SMS_ACKNOWLEDGE,soc_id);
6358 return;
6359}
6360
6361#if EM_MODE_SUPPORT
6362void registerForNetworkInfo(netwokInfoNotify cb)
6363{
6364 networkCb = cb;
6365 return ;
6366}
6367void unregisterNetwork()
6368{
6369 networkCb = NULL;
6370 //AT+EINFO= flag & 0xFFFFFFF7
6371}
6372void registerForATcmdResponse(atCmdResponse cb)
6373{
6374 atResponseCb = cb;
6375 return ;
6376}
6377
6378void unregisterATcmd()
6379{
6380 atResponseCb = NULL;
6381}
6382
6383#endif
6384int emResultNotify(const char *str)
6385{
6386 RLOGD("emResultNotify %s",str);
6387 int len_s = sendto(server_socket_fd,str,strlen(str),0,(struct sockaddr *)&client_addr,sizeof(client_addr));
6388
6389 sendto(server_socket_fd,"stopemdone",strlen("stopemdone"),0,(struct sockaddr *)&client_addr,sizeof(client_addr));
6390 return len_s;
6391}
6392
6393void processUnsolicited (Parcel &p, int type)
6394{
xja1c30b82022-01-25 16:13:48 +08006395 int32_t response = -1;
lh7b0674a2022-01-10 00:34:35 -08006396 p.readInt32(&response);
6397 switch(response){
6398 case RIL_UNSOL_MAL_AT_INFO:
6399 {
6400#if EM_MODE_SUPPORT
6401 char *stringresponse = strdupReadString(p);
6402 if(strstr(stringresponse,"+ENWINFO") != NULL){
6403 RLOGD("processUnsolicited ENWINFO \n");
6404 char *start = strstr(stringresponse,":");
6405 char *end = strstr(stringresponse,",");
6406 if(start == NULL ||end == NULL ){
6407 break;
6408 }
6409 if(networkCb){
6410 //parse type & data, notify to registrants
6411 char ctype[5] = {0};
6412 int type = 0;
6413 memcpy(ctype,start+1, end - start -1);
6414 type = atoi(ctype);
6415 char *data = end+1;
6416 RLOGD("ctype %s type %d data %s\n",ctype,type,data);
6417 //parse response
6418 networkCb(type,data);
6419 }
6420 }
6421 if(stringresponse){
6422 free(stringresponse);
6423 }
6424#endif
6425 break;
6426 }
6427 default:
6428 break;
6429 }
6430}
6431void processSolicited(Parcel &p, int type) {
6432 int32_t serial, error;
xja1c30b82022-01-25 16:13:48 +08006433 serial = 0;
lh7b0674a2022-01-10 00:34:35 -08006434 p.readInt32(&serial); //telematic it is the same as ril request num
6435 p.readInt32(&error);
6436 RLOGD("processSolicited serial %d\n", serial);
6437 switch (serial) {
6438 case RIL_REQUEST_OEM_HOOK_RAW: {
6439 if (error != RIL_E_SUCCESS) {
6440 RLOGW("RIL_E_fail");
6441 if (atResponseCb) {
6442 atResponseCb(NULL, 0);
6443 }
6444 if(m_RfDesense){
6445 m_RfDesense->handle_request("", 0, 0, (RIL_Errno)error);
6446 }
6447 return;
6448 }
6449 int len;
6450 status_t status = 0;
6451 status = p.readInt32(&len);
6452 if (status != 0) {
6453 RLOGW("read int32 fail");
6454 return;
6455 }
6456 char *stringresponse = (char*) calloc(len, sizeof(char));
6457 status = p.read((void*) stringresponse, len);
6458 if (status != 0) {
6459 if (stringresponse) {
6460 free(stringresponse);
6461 }
6462 RLOGW("read int32 fail");
6463 return;
6464 }
6465 parseAtCmd(stringresponse);
6466 RLOGD("processSolicited AT string %s %d\n", stringresponse, len);
6467#if EM_MODE_SUPPORT
6468 if (atResponseCb) {
6469 if (stringresponse) {
6470
6471 atResponseCb(stringresponse, len);
6472 } else {
6473 atResponseCb(stringresponse, 0);
6474 }
6475 }
6476 if(m_RfDesense){
6477 if(stringresponse && (!isFinalResponseErrorEx(stringresponse))) {
6478 m_RfDesense->handle_request(stringresponse,len,0, (RIL_Errno)RIL_E_SUCCESS);
6479 } else {
6480 RLOGD("isFinalResponseErrorEx error or response is null");
6481 m_RfDesense->handle_request(stringresponse, 0, 0, (RIL_Errno)RIL_E_GENERIC_FAILURE);
6482 }
6483 }
6484#endif
6485 if (stringresponse) {
6486 free(stringresponse);
6487 }
6488 break;
6489 }
6490 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: {
6491#if EM_MODE_SUPPORT
6492 if (atResponseCb) {
6493 if (error != RIL_E_SUCCESS) {
6494 atResponseCb(NULL, 0);
6495 } else {
6496 atResponseCb("OK", 2);
6497 }
6498 }
6499#endif
6500 break;
6501 }
6502 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: {
6503#if EM_MODE_SUPPORT
6504 int nums = 0;
6505 int prefertype = 0;
6506 p.readInt32(&nums);
6507 if (nums != 1) {
6508 RLOGD("getpreferrednetworktype nums > 1");
6509 }
6510 p.readInt32(&prefertype);
6511 char prefertype_str[3] = { 0 };
6512 sprintf(prefertype_str, "%d", prefertype);
6513 if (atResponseCb) {
6514 if (error != RIL_E_SUCCESS) {
6515 atResponseCb(NULL, 0);
6516 } else {
6517 atResponseCb(prefertype_str, strlen(prefertype_str));
6518 }
6519 }
6520#endif
6521 break;
6522 }
6523 case RIL_REQUEST_GET_IMSI: {
6524 if (error != RIL_E_SUCCESS) {
6525 RLOGD("RIL_REQUEST_GET_IMSI error %d\n", error);
6526 }
6527 break;
6528 }
6529 }
6530}
6531
6532#ifdef ECALL_SUPPORT
6533static int responseEcallStatus(Parcel &p, void *response, size_t responselen) {
6534 if (response == NULL || responselen != sizeof(RIL_Ecall_Unsol_Indications)) {
6535 if (response == NULL) {
6536 RLOGE("invalid response: NULL");
6537 }
6538 else {
6539 RLOGE("responseEcallStatus: invalid response length %d expecting len: %d",
6540 sizeof(RIL_Ecall_Unsol_Indications), responselen);
6541 }
6542 return RIL_ERRNO_INVALID_RESPONSE;
6543 }
6544
6545 RIL_Ecall_Unsol_Indications *p_cur = (RIL_Ecall_Unsol_Indications *)response;
6546 p.writeInt32(p_cur->ind);
6547 p.writeInt32(p_cur->call_id);
6548
6549 startResponse;
6550 appendPrintBuf("ECall Status: %d, call_id: %d",
6551 p_cur->ind, p_cur->call_id);
6552 closeResponse;
6553
6554 return 0;
6555}
6556
6557/**
6558 * Callee expects const RIL_ECallReqMsg *
6559 * Payload is:
6560 * RIL_ECall_Category ecall_cat
6561 * RIL_ECall_Variant ecall_variant
6562 * String address
6563 * String msd_data
6564 */
6565static void dispatchFastEcall (Parcel &p, RequestInfo *pRI) {
6566 RIL_ECallReqMsg eCallReqMsg;
6567
xja1c30b82022-01-25 16:13:48 +08006568 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08006569 int size;
6570 status_t status;
6571 int digitCount;
6572 int digitLimit;
6573 uint8_t uct;
6574
6575 memset(&eCallReqMsg, 0, sizeof(eCallReqMsg));
6576
6577 status = p.readInt32(&t);
6578 eCallReqMsg.ecall_cat= (RIL_ECall_Category)t;
6579
6580 status = p.readInt32(&t);
6581 eCallReqMsg.ecall_variant = (RIL_ECall_Variant)t;
6582
6583 eCallReqMsg.address = strdupReadString(p);
6584
6585 status = p.readInt32(&t);
6586 eCallReqMsg.length = (uint8_t) t;
6587
6588 digitLimit= MIN((eCallReqMsg.length), MSD_MAX_LENGTH);
6589 eCallReqMsg.msd_data = (unsigned char *)alloca(digitLimit);
6590
6591 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
6592 status = p.read(&uct, sizeof(uint8_t));
6593 eCallReqMsg.msd_data[digitCount] = (uint8_t) uct;
6594 }
6595
6596 startRequest;
6597 appendPrintBuf("%secall_cat=%d,ecall_variant=%d, address=%s", printBuf,
6598 eCallReqMsg.ecall_cat, eCallReqMsg.ecall_variant, (char*)eCallReqMsg.address);
6599 closeRequest;
6600 printRequest(pRI->token, pRI->pCI->requestNumber);
6601
6602 if (status != NO_ERROR) {
6603 goto invalid;
6604 }
6605
6606 size = sizeof(eCallReqMsg);
6607 CALL_ONREQUEST(pRI->pCI->requestNumber, &eCallReqMsg, size, pRI, pRI->socket_id);
6608
6609#ifdef MEMSET_FREED
6610 memsetString(eCallReqMsg.address);
lhb07f4e12022-02-17 22:08:54 -08006611 memset(eCallReqMsg.msd_data, 0, digitLimit);
lh7b0674a2022-01-10 00:34:35 -08006612#endif
6613
6614 free(eCallReqMsg.address);
6615
6616#ifdef MEMSET_FREED
6617 memset(&eCallReqMsg, 0, sizeof(eCallReqMsg));
6618#endif
6619
6620 return;
6621invalid:
6622 invalidCommandBlock(pRI);
6623 return;
6624}
6625
6626/**
6627 * Callee expects const RIL_ECallSetMSD *
6628 * Payload is:
6629 * int call_id
6630 * String msd_data
6631 */
6632static void dispatchSetMsd (Parcel &p, RequestInfo *pRI) {
6633 RIL_ECallSetMSD eCallSetMsd;
6634
xja1c30b82022-01-25 16:13:48 +08006635 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08006636 int size;
6637 status_t status;
6638 int digitCount;
6639 int digitLimit;
6640 uint8_t uct;
6641
6642 memset(&eCallSetMsd, 0, sizeof(eCallSetMsd));
6643
6644 status = p.readInt32(&t);
6645 eCallSetMsd.call_id = (int)t;
6646
6647 status = p.readInt32(&t);
6648 eCallSetMsd.length = (uint8_t) t;
6649
6650 digitLimit= MIN((eCallSetMsd.length), MSD_MAX_LENGTH);
6651 eCallSetMsd.msd_data = (unsigned char *)alloca(digitLimit);
6652
6653 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
6654 status = p.read(&uct, sizeof(uint8_t));
6655 eCallSetMsd.msd_data[digitCount] = (uint8_t) uct;
6656 }
6657
6658 startRequest;
6659 appendPrintBuf("%scall_id=%d,msd_data=%s", printBuf, eCallSetMsd.call_id, (char*)eCallSetMsd.msd_data);
6660 closeRequest;
6661 printRequest(pRI->token, pRI->pCI->requestNumber);
6662
6663 if (status != NO_ERROR) {
6664 goto invalid;
6665 }
6666
6667 size = sizeof(eCallSetMsd);
6668 CALL_ONREQUEST(pRI->pCI->requestNumber, &eCallSetMsd, size, pRI, pRI->socket_id);
6669
6670#ifdef MEMSET_FREED
6671 memset(eCallSetMsd.msd_data, 0, eCallSetMsd.length);
6672#endif
6673
6674#ifdef MEMSET_FREED
6675 memset(&eCallSetMsd, 0, sizeof(eCallSetMsd));
6676#endif
6677
6678 return;
6679invalid:
6680 invalidCommandBlock(pRI);
6681 return;
6682}
6683
6684/**
6685 * Callee expects const RIL_ECallSetNum *
6686 * Payload is:
6687 * int arg_num;
6688 * int type
6689 * char* address
6690 */
6691static void dispatchEcallRecord (Parcel &p, RequestInfo *pRI) {
6692 RIL_ECallSetNum args;
xja1c30b82022-01-25 16:13:48 +08006693 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08006694 status_t status;
6695
6696 RLOGD("dispatchSmsWrite");
6697 memset (&args, 0, sizeof(args));
6698
6699 status = p.readInt32(&t);
6700 args.arg_num = (int)t;
6701
6702 status = p.readInt32(&t);
6703 args.type = (int)t;
6704
6705 args.address = strdupReadString(p);
6706
6707 if (status != NO_ERROR || args.address == NULL) {
6708 goto invalid;
6709 }
6710
6711 startRequest;
6712 appendPrintBuf("%s%d,%s,%d", printBuf, args.type, args.address,args.arg_num);
6713 closeRequest;
6714 printRequest(pRI->token, pRI->pCI->requestNumber);
6715
6716 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
6717
6718#ifdef MEMSET_FREED
6719 memsetString (args.address);
6720#endif
6721
6722 free (args.address);
6723#ifdef MEMSET_FREED
6724 memset(&args, 0, sizeof(args));
6725#endif
6726 return;
6727invalid:
6728 invalidCommandBlock(pRI);
6729 return;
6730}
6731#endif /*ECALL_SUPPORT*/
6732
6733#ifdef KEEP_ALIVE
6734static void dispatchStartKeepalivePro(Parcel &p, RequestInfo *pRI){
6735 RIL_RequestKeepalive_Pro kp;
xja1c30b82022-01-25 16:13:48 +08006736 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08006737 status_t status;
6738 std::vector<uint8_t> sadr;
6739 std::vector<uint8_t> dadr;
6740
6741 memset (&kp, 0, sizeof(RIL_RequestKeepalive_Pro));
6742
6743 status = p.readInt32(&t);
6744 kp.type = (RIL_PacketType)t;
6745 if (status != NO_ERROR) {
6746 goto invalid;
6747 }
6748
6749
6750 status = p.readByteVector(&sadr);
6751 if (status != NO_ERROR) {
6752 goto invalid;
6753 } else {
6754 for(int i = 0; i < sadr.size(); i++) {
6755 kp.sourceAddress[i] = sadr[i];
6756 }
6757 }
6758
6759 status = p.readInt32(&t);
6760 kp.sourcePort= (int)t;
6761 if (status != NO_ERROR) {
6762 goto invalid;
6763 }
6764
6765 status = p.readByteVector(&dadr);
6766 if (status != NO_ERROR) {
6767 goto invalid;
6768 } else {
6769 for(int i = 0; i < dadr.size(); i++) {
6770 kp.destinationAddress[i] = dadr[i];
6771 }
6772 }
6773
6774 status = p.readInt32(&t);
6775 kp.destinationPort= (int)t;
6776 if (status != NO_ERROR) {
6777 goto invalid;
6778 }
6779
6780 status = p.readInt32(&t);
6781 kp.netif_id = (int)t;
6782 if (status != NO_ERROR) {
6783 goto invalid;
6784 }
6785
6786 status = p.readInt32(&t);
6787 kp.keepIdleTime = (int)t;
6788 if (status != NO_ERROR) {
6789 goto invalid;
6790 }
6791
6792 status = p.readInt32(&t);
6793 kp.keepIntervalTime = (int)t;
6794 if (status != NO_ERROR) {
6795 goto invalid;
6796 }
6797
6798 status = p.readInt32(&t);
6799 kp.retryCount = (int)t;
6800 if (status != NO_ERROR) {
6801 goto invalid;
6802 }
6803 startRequest;
6804 appendPrintBuf("%s [type:%d, sourceAddress:",printBuf, kp.type);
6805
6806 for(auto v: sadr) {
6807 appendPrintBuf("%s %d",printBuf,v);
6808 }
6809 appendPrintBuf("%s, sourcePort:%d, destinationAddress:",printBuf, kp.sourcePort);
6810
6811 for(auto v: dadr) {
6812 appendPrintBuf("%s %d",printBuf,v);
6813 }
6814 appendPrintBuf("%s, destinationPort:%d, netif_id:%d, keepIdleTime:%d,, keepIntervalTime:%d, retryCount:%d",
6815 printBuf, kp.destinationPort, kp.netif_id, kp.keepIdleTime, kp.keepIntervalTime, kp.retryCount);
6816
6817 closeRequest;
6818 printRequest(pRI->token, pRI->pCI->requestNumber);
6819
6820 CALL_ONREQUEST(pRI->pCI->requestNumber,&kp,sizeof(RIL_RequestKeepalive_Pro),pRI, pRI->socket_id);
6821 return;
6822invalid:
6823 invalidCommandBlock(pRI);
6824 return;
6825}
6826#endif /* KEEP_ALIVE*/
6827} /* namespace android */
6828
6829#if 0
6830void rilEventAddWakeup_helper(struct ril_event *ev) {
6831 android::rilEventAddWakeup(ev);
6832}
6833
6834void listenCallback_helper(int fd, short flags, void *param) {
6835 android::listenCallback(fd, flags, param);
6836}
6837
6838int blockingWrite_helper(int fd, void *buffer, size_t len) {
6839 return android::blockingWrite(fd, buffer, len);
6840}
6841#endif