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