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