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