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