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