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