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