blob: db7d1296af7494cc5807e3d434aff11567e60df5 [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#ifdef LED_SUPPORT
4758 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: //add this for API-720
4759 ARspRequest(RIL_REQUEST_GET_CURRENT_CALLS, soc_id);
4760 break;
4761#endif
lh7b0674a2022-01-10 00:34:35 -08004762 case RIL_UNSOL_CALL_RING:
4763 callRing(soc_id);
4764 break;
4765 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
4766 updateIccCardState(soc_id);
4767 break;
4768 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
4769 getVoiceAndDataRegistrationState(soc_id);
4770 break;
4771 case RIL_UNSOL_RESPONSE_NEW_SMS:
lhf6eea122022-01-20 19:32:14 -08004772 responseNewSMS((const char*)data, datalen,soc_id,unsolResponse,p);
lh7b0674a2022-01-10 00:34:35 -08004773 unreadStatusWriteSMSToSim((const char*)data, datalen, soc_id);
4774 sendSMSACK(soc_id);
4775 break;
4776 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
4777 {
4778 RLOGD("Receive RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS data: %s, length: %d", (char*)data, datalen);
4779 break;
4780 }
4781 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
4782 sendSMSACK(soc_id);
4783 break;
4784 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
4785 updateRadioStatus(newState,soc_id);
4786 break;
4787 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
4788 {
4789 ARspRequest(RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE, soc_id);
4790 break;
4791 }
4792 case RIL_UNSOL_STK_PROACTIVE_COMMAND:
4793 {
4794 RLOGD("STk proactive command raw date: %s, length: %d", (char*)data, datalen);
4795 handleStkCommand((char*)data, datalen,soc_id);
4796 break;
4797 }
4798 case RIL_UNSOL_RIL_CONNECTED:
4799 {
4800 RLOGD("vendor-ril socket(%d) connect start", soc_id);
4801 pthread_mutex_lock(&s_InitMutex);
4802 s_isConnected[soc_id] = 1;
4803 if(utils::is_support_dsds()) {
4804 if (s_isConnected[0] == 1 && s_isConnected[1] == 1) {
4805 pthread_cond_broadcast(&s_InitCond);
4806 }
4807 } else {
4808 if (s_isConnected[0] == 1 || s_isConnected[1] == 1) {
4809 pthread_cond_broadcast(&s_InitCond);
4810 }
4811 }
4812 pthread_mutex_unlock(&s_InitMutex);
4813 RLOGD("vendor-ril socket(%d) connect end", soc_id);
4814 break;
4815 }
4816 case RIL_UNSOL_TX_POWER: {
4817 int *p_int = (int *) data;
4818 int numInts = datalen / sizeof(int);
4819 if (numInts > 1) {
4820 m_RfDesense->emOemHookRaw(p_int[1],soc_id);
4821 } else {
4822 m_RfDesense->emOemHookRaw(0, soc_id);
4823 }
4824 break;
4825 }
4826 case RIL_UNSOL_NETWORK_INFO: {
4827 if(networkCb){
4828 //TBD
4829 char **p_cur = (char **) data;
4830 char *ctype = (char*)p_cur[0];
4831 int type = atoi(ctype);
4832 char *data = (char*)p_cur[1];
4833 RLOGD("ctype %s type %d data %s\n",ctype,type,data);
4834 networkCb(type,data);
4835 }
4836 break;
4837 }
4838 case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
4839 {
4840 int num = datalen / sizeof(RIL_Data_Call_Response_v6);
4841 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) data;
4842 handleUnsolDataCalllistChange(num,p_cur);
4843 break;
4844 }
4845 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED:
4846 {
4847 update_voice_radio_tech(((int *) data)[0], soc_id);
4848 break;
4849 }
4850 case RIL_UNSOL_RADIO_CAPABILITY:
4851 {
4852 update_radio_capa((RIL_RadioCapability *) data, soc_id);
4853 //Proxy_controller::getInstance()->handle_message_notify((RIL_RadioCapability *) data, soc_id);
4854 break;
4855 }
4856 case RIL_UNSOL_CDMA_CALL_WAITING:
4857 {
4858 autoAnswerForCdma(soc_id);
4859 break;
4860 }
4861 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4862 {
4863 updateSystemTime(data, datalen);
4864 break;
4865 }
4866 case RIL_UNSOL_ECALL_INDICATIONS:
4867 {
4868 handleEcallIndication(data, datalen, soc_id);
4869 break;
4870 }
4871#ifdef KEEP_ALIVE
4872 case RIL_UNSOL_KEEPALIVE_STATUS_PRO:
4873 {
4874 handleKeepAliveResponse(unsolResponse, data, datalen, soc_id, false);
4875 break;
4876 }
4877#endif /*KEEP_ALIVE*/
4878 case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
4879 {
4880 setSimSmsStorageFullFlag(true);
4881 break;
4882 }
4883 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR:
4884 {
4885 handleUnsolSipCallProgressInd(data, datalen);
4886 break;
4887 }
4888 case RIL_UNSOL_ECC_NUM:
4889 {
4890 handleECCNumResponse(data, datalen,soc_id);
4891 break;
4892 }
4893 case RIL_UNSOL_CALL_INFO_INDICATION:
4894 {
4895 handleUnsolCallInfoInd(data, datalen, soc_id);
4896 break;
4897 }
4898 case RIL_UNSOL_RINGBACK_TONE:
4899 {
4900 handleRingbackTone(data, datalen, soc_id);
4901 break;
4902 }
4903 default:
4904 break;
4905 }
lhf6eea122022-01-20 19:32:14 -08004906 /*Warren add for t800 ril service 2021/12/16 start*/
q.huang036b6cf2023-01-10 14:29:20 +08004907 ret = LYNQ_RIL_urcBroadcast(p,unsolResponse);
lhf6eea122022-01-20 19:32:14 -08004908 /*Warren add for t800 ril service 2021/12/16 end*/
lh7b0674a2022-01-10 00:34:35 -08004909#if 0
4910 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4911
4912 // Unfortunately, NITZ time is not poll/update like everything
4913 // else in the system. So, if the upstream client isn't connected,
4914 // keep a copy of the last NITZ response (with receive time noted
4915 // above) around so we can deliver it when it is connected
4916
4917 if (s_lastNITZTimeData != NULL) {
4918 free (s_lastNITZTimeData);
4919 s_lastNITZTimeData = NULL;
4920 }
4921
4922 s_lastNITZTimeData = malloc(p.dataSize());
4923 s_lastNITZTimeDataSize = p.dataSize();
4924 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4925 }
4926
4927#endif
4928 // Normal exit
4929 return;
4930
4931error_exit:
4932 RLOGD("unsol handle fail");
4933#if 0
4934 if (shouldScheduleTimeout) {
4935 releaseWakeLock();
4936 }
4937#endif
4938}
4939
4940extern "C" void
4941RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4942 const struct timeval *relativeTime) {
4943}
4944
4945const char *
4946failCauseToString(RIL_Errno e) {
4947 switch(e) {
4948 case RIL_E_SUCCESS: return "E_SUCCESS";
4949 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
4950 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4951 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4952 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4953 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4954 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4955 case RIL_E_CANCELLED: return "E_CANCELLED";
4956 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4957 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4958 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
4959 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
4960 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
4961#ifdef FEATURE_MULTIMODE_ANDROID
4962 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4963 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4964#endif
4965 case RIL_E_SIM_MEM_FULL: return "E_SIM_MEM_FULL";
4966 default: return "<unknown error>";
4967 }
4968}
4969
4970const char *
4971callStateToString(RIL_CallState s) {
4972 switch(s) {
4973 case RIL_CALL_ACTIVE : return "ACTIVE";
4974 case RIL_CALL_HOLDING: return "HOLDING";
4975 case RIL_CALL_DIALING: return "DIALING";
4976 case RIL_CALL_ALERTING: return "ALERTING";
4977 case RIL_CALL_INCOMING: return "INCOMING";
4978 case RIL_CALL_WAITING: return "WAITING";
4979 default: return "<unknown state>";
4980 }
4981}
4982const char *lynq_requset_to_string(int request)
4983{
4984 switch(request) {
4985 case RIL_REQUEST_GET_SIM_STATUS: return "RIL_REQUEST_GET_SIM_STATUS";
4986 case RIL_REQUEST_ENTER_SIM_PIN: return "RIL_REQUEST_ENTER_SIM_PIN";
4987 case RIL_REQUEST_ENTER_SIM_PUK: return "RIL_REQUEST_ENTER_SIM_PUK";
4988 case RIL_REQUEST_ENTER_SIM_PIN2: return "RIL_REQUEST_ENTER_SIM_PIN2";
4989 case RIL_REQUEST_ENTER_SIM_PUK2: return "RIL_REQUEST_ENTER_SIM_PUK2";
4990 case RIL_REQUEST_CHANGE_SIM_PIN: return "RIL_REQUEST_CHANGE_SIM_PIN";
4991 case RIL_REQUEST_CHANGE_SIM_PIN2: return "RIL_REQUEST_CHANGE_SIM_PIN2";
4992 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION";
4993 case RIL_REQUEST_GET_CURRENT_CALLS: return "RIL_REQUEST_GET_CURRENT_CALLS";
4994 case RIL_REQUEST_DIAL: return "RIL_REQUEST_DIAL";
4995 case RIL_REQUEST_GET_IMSI: return "RIL_REQUEST_GET_IMSI";
4996 case RIL_REQUEST_HANGUP: return "RIL_REQUEST_HANGUP";
4997 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND";
4998 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND";
4999 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5000 case RIL_REQUEST_CONFERENCE: return "RIL_REQUEST_CONFERENCE";
5001 case RIL_REQUEST_UDUB: return "RIL_REQUEST_UDUB";
5002 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "RIL_REQUEST_LAST_CALL_FAIL_CAUSE";
5003 case RIL_REQUEST_SIGNAL_STRENGTH: return "RIL_REQUEST_SIGNAL_STRENGTH";
5004 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "RIL_REQUEST_VOICE_REGISTRATION_STATE";
5005 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "RIL_REQUEST_DATA_REGISTRATION_STATE";
5006 case RIL_REQUEST_OPERATOR: return "RIL_REQUEST_OPERATOR";
5007 case RIL_REQUEST_RADIO_POWER: return "RIL_REQUEST_RADIO_POWER";
5008 case RIL_REQUEST_DTMF: return "RIL_REQUEST_DTMF";
5009 case RIL_REQUEST_SEND_SMS: return "RIL_REQUEST_SEND_SMS";
5010 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "RIL_REQUEST_SEND_SMS_EXPECT_MORE";
5011 case RIL_REQUEST_SETUP_DATA_CALL: return "RIL_REQUEST_SETUP_DATA_CALL";
5012 case RIL_REQUEST_SIM_IO: return "RIL_REQUEST_SIM_IO";
5013 case RIL_REQUEST_SEND_USSD: return "RIL_REQUEST_SEND_USSD";
5014 case RIL_REQUEST_CANCEL_USSD: return "RIL_REQUEST_CANCEL_USSD";
5015 case RIL_REQUEST_GET_CLIR: return "RIL_REQUEST_GET_CLIR";
5016 case RIL_REQUEST_SET_CLIR: return "RIL_REQUEST_SET_CLIR";
5017 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "RIL_REQUEST_QUERY_CALL_FORWARD_STATUS";
5018 case RIL_REQUEST_SET_CALL_FORWARD: return "RIL_REQUEST_SET_CALL_FORWARD";
5019 case RIL_REQUEST_QUERY_CALL_WAITING: return "RIL_REQUEST_QUERY_CALL_WAITING";
5020 case RIL_REQUEST_SET_CALL_WAITING: return "RIL_REQUEST_SET_CALL_WAITING";
5021 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "RIL_REQUEST_SMS_ACKNOWLEDGE";
5022 case RIL_REQUEST_GET_IMEI: return "RIL_REQUEST_GET_IMEI";
5023 case RIL_REQUEST_GET_IMEISV: return "RIL_REQUEST_GET_IMEISV";
5024 case RIL_REQUEST_ANSWER: return "RIL_REQUEST_ANSWER";
5025 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "RIL_REQUEST_DEACTIVATE_DATA_CALL";
5026 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "RIL_REQUEST_QUERY_FACILITY_LOCK";
5027 case RIL_REQUEST_SET_FACILITY_LOCK: return "RIL_REQUEST_SET_FACILITY_LOCK";
5028 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "RIL_REQUEST_CHANGE_BARRING_PASSWORD";
5029 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE";
5030 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC";
5031 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL";
5032 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS";
5033 case RIL_REQUEST_DTMF_START: return "RIL_REQUEST_DTMF_START";
5034 case RIL_REQUEST_DTMF_STOP: return "RIL_REQUEST_DTMF_STOP";
5035 case RIL_REQUEST_BASEBAND_VERSION: return "RIL_REQUEST_BASEBAND_VERSION";
5036 case RIL_REQUEST_SEPARATE_CONNECTION: return "RIL_REQUEST_SEPARATE_CONNECTION";
5037 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE";
5038 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE";
5039 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "RIL_REQUEST_GET_NEIGHBORING_CELL_IDS";
5040 case RIL_REQUEST_SET_MUTE: return "RIL_REQUEST_SET_MUTE";
5041 case RIL_REQUEST_GET_MUTE: return "RIL_REQUEST_GET_MUTE";
5042 case RIL_REQUEST_QUERY_CLIP: return "RIL_REQUEST_QUERY_CLIP";
5043 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE";
5044 case RIL_REQUEST_DATA_CALL_LIST: return "RIL_REQUEST_DATA_CALL_LIST";
5045 case RIL_REQUEST_RESET_RADIO: return "RIL_REQUEST_RESET_RADIO";
5046 case RIL_REQUEST_OEM_HOOK_RAW: return "RIL_REQUEST_OEM_HOOK_RAW";
5047 case RIL_REQUEST_OEM_HOOK_STRINGS: return "RIL_REQUEST_OEM_HOOK_STRINGS";
5048 case RIL_REQUEST_SET_BAND_MODE: return "RIL_REQUEST_SET_BAND_MODE";
5049 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE";
5050 case RIL_REQUEST_STK_GET_PROFILE: return "RIL_REQUEST_STK_GET_PROFILE";
5051 case RIL_REQUEST_STK_SET_PROFILE: return "RIL_REQUEST_STK_SET_PROFILE";
5052 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND";
5053 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE";
5054 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5055 case RIL_REQUEST_SCREEN_STATE: return "RIL_REQUEST_SCREEN_STATE";
5056 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "RIL_REQUEST_EXPLICIT_CALL_TRANSFER";
5057 case RIL_REQUEST_SET_LOCATION_UPDATES: return "RIL_REQUEST_SET_LOCATION_UPDATES";
5058 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE";
5059 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE";
5060 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE";
5061 case RIL_REQUEST_SET_TTY_MODE:return"RIL_REQUEST_SET_TTY_MODE";
5062 case RIL_REQUEST_QUERY_TTY_MODE:return"RIL_REQUEST_QUERY_TTY_MODE";
5063 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5064 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5065 case RIL_REQUEST_CDMA_FLASH:return"RIL_REQUEST_CDMA_FLASH";
5066 case RIL_REQUEST_CDMA_BURST_DTMF:return"RIL_REQUEST_CDMA_BURST_DTMF";
5067 case RIL_REQUEST_CDMA_SEND_SMS:return"RIL_REQUEST_CDMA_SEND_SMS";
5068 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE";
5069 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG";
5070 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG";
5071 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION:return "RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION";
5072 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG";
5073 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG";
5074 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION";
5075 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY";
5076 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"RIL_REQUEST_CDMA_SUBSCRIPTION";
5077 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM";
5078 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM";
5079 case RIL_REQUEST_DEVICE_IDENTITY: return "RIL_REQUEST_DEVICE_IDENTITY";
5080 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE";
5081 case RIL_REQUEST_GET_SMSC_ADDRESS: return "RIL_REQUEST_GET_SMSC_ADDRESS";
5082 case RIL_REQUEST_SET_SMSC_ADDRESS: return "RIL_REQUEST_SET_SMSC_ADDRESS";
5083 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "RIL_REQUEST_REPORT_SMS_MEMORY_STATUS";
5084 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING";
5085 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE";
5086 case RIL_REQUEST_ISIM_AUTHENTICATION: return "RIL_REQUEST_ISIM_AUTHENTICATION";
5087 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5088 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5089 case RIL_REQUEST_VOICE_RADIO_TECH: return "RIL_REQUEST_VOICE_RADIO_TECH";
5090 case RIL_REQUEST_GET_CELL_INFO_LIST: return"RIL_REQUEST_GET_CELL_INFO_LIST";
5091 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE";
5092 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5093 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "RIL_REQUEST_IMS_REGISTRATION_STATE";
5094 case RIL_REQUEST_IMS_SEND_SMS: return "RIL_REQUEST_IMS_SEND_SMS";
5095 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC";
5096 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "RIL_REQUEST_SIM_OPEN_CHANNEL";
5097 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "RIL_REQUEST_SIM_CLOSE_CHANNEL";
5098 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL";
5099 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5100 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
5101 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "RIL_REQUEST_SET_UICC_SUBSCRIPTION";
5102 case RIL_REQUEST_ALLOW_DATA: return "RIL_REQUEST_ALLOW_DATA";
5103 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "RIL_REQUEST_GET_HARDWARE_CONFIG";
5104 case RIL_REQUEST_SIM_AUTHENTICATION: return "RIL_REQUEST_SIM_AUTHENTICATION";
5105 case RIL_REQUEST_GET_DC_RT_INFO: return "RIL_REQUEST_GET_DC_RT_INFO";
5106 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "RIL_REQUEST_SET_DC_RT_INFO_RATE";
5107 case RIL_REQUEST_SET_DATA_PROFILE: return "RIL_REQUEST_SET_DATA_PROFILE";
5108 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5109 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED";
5110 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5111 case RIL_UNSOL_RESPONSE_NEW_SMS: return "RIL_UNSOL_RESPONSE_NEW_SMS";
5112 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5113 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5114 case RIL_UNSOL_ON_USSD: return "RIL_UNSOL_ON_USSD";
5115 case RIL_UNSOL_ON_USSD_REQUEST: return "RIL_UNSOL_ON_USSD_REQUEST";
5116 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "RIL_UNSOL_NITZ_TIME_RECEIVED";
5117 case RIL_UNSOL_SIGNAL_STRENGTH: return "RIL_UNSOL_SIGNAL_STRENGTH";
5118 case RIL_UNSOL_STK_SESSION_END: return "RIL_UNSOL_STK_SESSION_END";
5119 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "RIL_UNSOL_STK_PROACTIVE_COMMAND";
5120 case RIL_UNSOL_STK_EVENT_NOTIFY: return "RIL_UNSOL_STK_EVENT_NOTIFY";
5121 case RIL_UNSOL_STK_CALL_SETUP: return "RIL_UNSOL_STK_CALL_SETUP";
5122 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "RIL_UNSOL_SIM_SMS_STORAGE_FULL";
5123 case RIL_UNSOL_SIM_REFRESH: return "RIL_UNSOL_SIM_REFRESH";
5124 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "RIL_UNSOL_DATA_CALL_LIST_CHANGED";
5125 case RIL_UNSOL_CALL_RING: return "RIL_UNSOL_CALL_RING";
5126 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5127 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "RIL_UNSOL_RESPONSE_CDMA_NEW_SMS";
5128 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS";
5129 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5130 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "RIL_UNSOL_RESTRICTED_STATE_CHANGED";
5131 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5132 case RIL_UNSOL_CDMA_CALL_WAITING: return "RIL_UNSOL_CDMA_CALL_WAITING";
5133 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "RIL_UNSOL_CDMA_OTA_PROVISION_STATUS";
5134 case RIL_UNSOL_CDMA_INFO_REC: return "RIL_UNSOL_CDMA_INFO_REC";
5135 case RIL_UNSOL_OEM_HOOK_RAW: return "RIL_UNSOL_OEM_HOOK_RAW";
5136 case RIL_UNSOL_RINGBACK_TONE: return "RIL_UNSOL_RINGBACK_TONE";
5137 case RIL_UNSOL_RESEND_INCALL_MUTE: return "RIL_UNSOL_RESEND_INCALL_MUTE";
5138 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5139 case RIL_UNSOL_CDMA_PRL_CHANGED: return "RIL_UNSOL_CDMA_PRL_CHANGED";
5140 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5141 case RIL_UNSOL_RIL_CONNECTED: return "RIL_UNSOL_RIL_CONNECTED";
5142 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "RIL_UNSOL_VOICE_RADIO_TECH_CHANGED";
5143 case RIL_UNSOL_CELL_INFO_LIST: return "RIL_UNSOL_CELL_INFO_LIST";
5144 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
5145 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5146 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "RIL_UNSOL_SRVCC_STATE_NOTIFY";
5147 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "RIL_UNSOL_HARDWARE_CONFIG_CHANGED";
5148 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "RIL_UNSOL_DC_RT_INFO_CHANGED";
5149 case RIL_REQUEST_SHUTDOWN: return "RIL_REQUEST_SHUTDOWN";
5150 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
5151 case RIL_REQUEST_SET_TRM: return "RIL_REQUEST_SET_TRM";
5152 case RIL_REQUEST_SET_IMS_ENABLE:return "RIL_REQUEST_SET_IMS_ENABLE";
5153 case RIL_REQUEST_SET_AUDIO_PATH: return "RIL_REQUEST_SET_AUDIO_PATH";
5154 case RIL_REQUEST_HANGUP_ALL: return "RIL_REQUEST_HANGUP_ALL";
5155 case RIL_REQUEST_FORCE_RELEASE_CALL: return "RIL_REQUEST_FORCE_RELEASE_CALL";
5156 case RIL_REQUEST_EMERGENCY_DIAL: return "RIL_REQUEST_EMERGENCY_DIAL";
5157 case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: return "RIL_REQUEST_SET_ECC_SERVICE_CATEGORY";
5158 case RIL_REQUEST_SET_ECC_LIST: return "RIL_REQUEST_SET_ECC_LIST";
5159 case RIL_REQUEST_AT_COMMAND_WITH_PROXY: return "RIL_REQUEST_AT_COMMAND_WITH_PROXY";
5160 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION";
5161 case RIL_REQUEST_SET_CLIP: return "RIL_REQUEST_SET_CLIP";
5162 case RIL_REQUEST_GET_COLP: return "RIL_REQUEST_GET_COLP";
5163 case RIL_REQUEST_SET_COLP: return "RIL_REQUEST_SET_COLP";
5164 case RIL_REQUEST_GET_COLR: return "RIL_REQUEST_GET_COLR";
5165 case RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER: return "RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER";
5166 case RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER: return "RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER";
5167 case RIL_REQUEST_CONFERENCE_DIAL: return "RIL_REQUEST_CONFERENCE_DIAL";
5168 case RIL_REQUEST_DIAL_WITH_SIP_URI: return "RIL_REQUEST_DIAL_WITH_SIP_URI";
5169 case RIL_REQUEST_HOLD_CALL: return "RIL_REQUEST_HOLD_CALL";
5170 case RIL_REQUEST_RESUME_CALL: return "RIL_REQUEST_RESUME_CALL";
5171 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return "RIL_UNSOL_ECONF_SRVCC_INDICATION";
5172 case RIL_UNSOL_ECONF_RESULT_INDICATION : return "RIL_UNSOL_ECONF_RESULT_INDICATION";
5173 case RIL_UNSOL_MAL_AT_INFO : return "RIL_UNSOL_MAL_AT_INFO";
5174 case RIL_REQUEST_MODEM_POWEROFF: return "RIL_REQUEST_MODEM_POWEROFF";
5175 case RIL_REQUEST_MODEM_POWERON: return "RIL_REQUEST_MODEM_POWERON";
5176 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "RIL_REQUEST_WRITE_SMS_TO_SIM";
5177 case RIL_REQUEST_QUERY_ICCID: return "RIL_REQUEST_QUERY_ICCID";
5178 case RIL_UNSOL_TX_POWER: return "RIL_UNSOL_TX_POWER";
5179 case RIL_UNSOL_NETWORK_INFO: return "RIL_UNSOL_NETWORK_INFO";
5180 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "RIL_REQUEST_DELETE_SMS_ON_SIM";
5181 case RIL_REQUEST_SET_IMSCFG: return "RIL_REQUEST_SET_IMSCFG";
5182#ifdef ECALL_SUPPORT
5183 case RIL_REQUEST_ECALL_FAST_MAKE_ECALL: return "RIL_REQUEST_ECALL_FAST_MAKE_ECALL";
5184 case RIL_REQUEST_ECALL_SET_IVS: return "RIL_REQUEST_ECALL_SET_IVS";
5185 case RIL_REQUEST_ECALL_SET_PSAP: return "RIL_REQUEST_ECALL_SET_PSAP";
5186 case RIL_REQUEST_ECALL_MAKE_ECALL: return "RIL_REQUEST_ECALL_MAKE_ECALL";
5187 case RIL_REQUEST_ECALL_IVS_PUSH_MSD: return "RIL_REQUEST_ECALL_IVS_PUSH_MSD";
5188 case RIL_REQUEST_ECALL_PSAP_PULL_MSD: return "RIL_REQUEST_ECALL_PSAP_PULL_MSD";
5189 case RIL_UNSOL_ECALL_MSDHACK : return "RIL_UNSOL_ECALL_MSDHACK";
5190 case RIL_REQUEST_ECALL_SET_MSD: return "RIL_REQUEST_ECALL_SET_MSD";
5191 case RIL_REQUEST_ECALL_CTRL_SEQUENCE: return "RIL_REQUEST_ECALL_CTRL_SEQUENCE";
5192 case RIL_UNSOL_ECALL_INDICATIONS : return "RIL_UNSOL_ECALL_INDICATIONS";
5193 case RIL_REQUEST_ECALL_RESET_IVS: return "RIL_REQUEST_ECALL_RESET_IVS";
5194 case RIL_REQUEST_ECALL_SET_PRI: return "RIL_REQUEST_ECALL_SET_PRI";
5195 case RIL_REQUEST_ECALL_SET_TEST_NUM: return "RIL_REQUEST_ECALL_SET_TEST_NUM";
5196 case RIL_REQUEST_ECALL_SET_RECONF_NUM: return "RIL_REQUEST_ECALL_SET_RECONF_NUM";
5197 case RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD: return "RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD";
5198 case RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME: return "RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME";
5199 case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: return "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE";
5200#endif /*ECALL_SUPPORT*/
5201#ifdef KEEP_ALIVE
5202 case RIL_REQUEST_START_KEEPALIVE_PRO: return "RIL_REQUEST_START_KEEPALIVE_PRO";
5203 case RIL_REQUEST_STOP_KEEPALIVE_PRO: return "RIL_REQUEST_STOP_KEEPALIVE_PRO";
5204 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return "RIL_UNSOL_KEEPALIVE_STATUS_PRO";
5205#endif /*KEEP_ALIVE*/
5206 case RIL_REQUEST_SEND_USSI: return "RIL_REQUEST_SEND_USSI";
5207 case RIL_REQUEST_CANCEL_USSI: return "RIL_REQUEST_CANCEL_USSI";
5208 case RIL_REQUEST_GET_SMS_SIM_MEM_STATUS: return "RIL_REQUEST_GET_SMS_SIM_MEM_STATUS";
5209 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return "RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR";
5210 case RIL_REQUEST_REPORT_AIRPLANE_MODE: return "RIL_REQUEST_REPORT_AIRPLANE_MODE";
5211 case RIL_REQUEST_SET_ECC_NUM: return "RIL_REQUEST_SET_ECC_NUM";
5212 case RIL_REQUEST_GET_ECC_NUM: return "RIL_REQUEST_GET_ECC_NUM";
5213 case RIL_UNSOL_ECC_NUM: return "RIL_UNSOL_ECC_NUM";
5214 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT: return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT";
5215 case RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE";
5216 case RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE";
5217 case RIL_UNSOL_CALL_INFO_INDICATION: return "RIL_UNSOL_CALL_INFO_INDICATION";
rjw20006d12022-04-21 16:29:04 +08005218/*Typethree add for t800 RIL Service 2022/04/14 start*/
5219//#ifdef TARGET_PLATFORM_MT2731
lh7b0674a2022-01-10 00:34:35 -08005220 case RIL_REQUEST_MODIFY_APN: return "RIL_REQUEST_MODIFY_APN";
5221 case RIL_REQUEST_RESET_APN: return "RIL_REQUEST_RESET_APN";
rjw20006d12022-04-21 16:29:04 +08005222//#endif
5223/*Typethree add for t800 RIL Service 2022/04/14 end*/
lh7b0674a2022-01-10 00:34:35 -08005224 case RIL_REQUEST_QUERY_SIM_RETRY_COUNT: return "RIL_REQUEST_QUERY_SIM_RETRY_COUNT";
5225 case RIL_REQUEST_QUERY_EID: return "RIL_REQUEST_QUERY_EID";
5226 /*LYNQ CMD*/
5227 case LYNQ_AUTO_ANSWER_CALL: return "LYNQ_AUTO_ANSWER_CALL";
5228 case LYNQ_REQUEST_SET_DTMF_VOLUME: return "RIL_REQUEST_SET_DTMF_VOLUME";
q.huangec88da92022-03-29 04:17:32 -04005229 case LYNQ_REQUEST_SET_SPEECH_VOLUME: return "RIL_REQUEST_SET_SPEECH_VOLUME";
5230 case LYNQ_REQUEST_GET_SPEECH_VOLUME: return "RIL_REQUEST_GET_SPEECH_VOLUME";
5231 case LYNQ_REQUEST_RECORD: return "RIL_REQUEST_RECORD";
lhf6eea122022-01-20 19:32:14 -08005232 case LYNQ_REQUEST_WRITE_SMS_TO_MEMORY: return "LYNQ_REQUEST_WRITE_SMS_TO_MEMORY";
5233 case LYNQ_REQUEST_READ_SMS_FROM_MEMORY: return "LYNQ_REQUEST_READ_SMS_FROM_MEMORY";
5234 case LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY: return "LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY";
5235 case LYNQ_REQUEST_LIST_SMS_FROM_MEMORY: return "LYNQ_REQUEST_LIST_SMS_FROM_MEMORY";
rjw5d2a50e2022-02-28 15:01:49 +08005236 case LYNQ_REQUEST_SET_DEFAULT_SIM_ALL:return "SET_DEFAULT_SIM_ALL";
jb.qi96449342022-09-19 22:14:41 -07005237 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 +08005238 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 -07005239 /*warren add for t800 ril service 2022/1/22 end*/
lh7b0674a2022-01-10 00:34:35 -08005240 default: return "<unknown request>";
5241 }
5242}
5243
5244const char *
5245requestToString(int request) {
5246/*
5247 cat libs/telephony/ril_commands.h \
5248 | egrep "^ *{RIL_" \
5249 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5250
5251
5252 cat libs/telephony/ril_unsol_commands.h \
5253 | egrep "^ *{RIL_" \
5254 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5255
5256*/
5257 switch(request) {
5258 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5259 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5260 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5261 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5262 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5263 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5264 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5265 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5266 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5267 case RIL_REQUEST_DIAL: return "DIAL";
5268 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5269 case RIL_REQUEST_HANGUP: return "HANGUP";
5270 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5271 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5272 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5273 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5274 case RIL_REQUEST_UDUB: return "UDUB";
5275 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5276 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5277 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5278 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5279 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5280 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5281 case RIL_REQUEST_DTMF: return "DTMF";
5282 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5283 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5284 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5285 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5286 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5287 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5288 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5289 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5290 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5291 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5292 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5293 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5294 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5295 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5296 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5297 case RIL_REQUEST_ANSWER: return "ANSWER";
5298 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5299 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5300 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5301 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5302 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5303 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5304 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5305 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5306 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5307 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5308 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5309 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5310 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5311 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5312 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5313 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5314 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5315 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5316 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5317 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5318 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5319 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5320 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5321 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5322 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5323 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5324 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5325 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5326 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5327 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5328 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5329 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5330 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
5331 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
5332 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5333 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5334 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5335 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5336 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5337 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5338 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5339 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5340 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5341 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5342 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5343 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5344 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION:return "GSM_SMS_BROADCAST_ACTIVATION";
5345 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5346 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5347 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
5348 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
5349 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5350 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5351 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5352 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5353 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5354 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5355 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5356 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5357 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5358 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5359 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5360 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5361 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5362 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
5363 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5364 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
5365 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5366 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5367 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
5368 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5369 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5370 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5371 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
5372 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5373 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
5374 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5375 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5376 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5377 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5378 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5379 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5380 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
5381 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5382 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5383 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
q.huang036b6cf2023-01-10 14:29:20 +08005384 case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
lh7b0674a2022-01-10 00:34:35 -08005385 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5386 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5387 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5388 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5389 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5390 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5391 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5392 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5393 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5394 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5395 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5396 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5397 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
5398 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5399 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5400 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5401 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5402 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5403 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5404 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5405 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5406 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5407 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5408 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5409 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5410 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5411 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5412 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5413 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5414 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5415 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5416 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
5417 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
5418 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
5419 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5420 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5421 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5422 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
5423 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
5424 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
5425 case RIL_REQUEST_SET_TRM: return "RIL_REQUEST_SET_TRM";
5426 case RIL_REQUEST_SET_IMS_ENABLE:return "RIL_REQUEST_SET_IMS_ENABLE";
5427 case RIL_REQUEST_SET_AUDIO_PATH: return "SET_AUDIO_PATH";
5428 case RIL_REQUEST_HANGUP_ALL: return "HANGUP_ALL";
5429 case RIL_REQUEST_FORCE_RELEASE_CALL: return "FORCE_RELEASE_CALL";
5430 case RIL_REQUEST_EMERGENCY_DIAL: return "RIL_REQUEST_EMERGENCY_DIAL";
5431 case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: return "RIL_REQUEST_SET_ECC_SERVICE_CATEGORY";
5432 case RIL_REQUEST_SET_ECC_LIST: return "RIL_REQUEST_SET_ECC_LIST";
5433 case RIL_REQUEST_AT_COMMAND_WITH_PROXY: return "AT_COMMAND_WITH_PROXY";
5434 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION";
5435 case RIL_REQUEST_SET_CLIP: return "RIL_REQUEST_SET_CLIP";
5436 case RIL_REQUEST_GET_COLP: return "RIL_REQUEST_GET_COLP";
5437 case RIL_REQUEST_SET_COLP: return "RIL_REQUEST_SET_COLP";
5438 case RIL_REQUEST_GET_COLR: return "RIL_REQUEST_GET_COLR";
5439 case RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER: return "ADD_IMS_CONFERENCE_CALL_MEMBER";
5440 case RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER: return "REMOVE_IMS_CONFERENCE_CALL_MEMBER";
5441 case RIL_REQUEST_CONFERENCE_DIAL: return "CONFERENCE_DIAL";
5442 case RIL_REQUEST_DIAL_WITH_SIP_URI: return "DIAL_WITH_SIP_URI";
5443 case RIL_REQUEST_HOLD_CALL: return "HOLD_CALL";
5444 case RIL_REQUEST_RESUME_CALL: return "RESUME_CALL";
5445 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return "ECONF_SRVCC_INDICATION";
5446 case RIL_UNSOL_ECONF_RESULT_INDICATION : return "ECONF_RESULT_INDICATION";
5447 case RIL_UNSOL_MAL_AT_INFO : return "UNSOL_MAL_AT_INFO";
5448 case RIL_REQUEST_MODEM_POWEROFF: return "MODEM_POWEROFF";
5449 case RIL_REQUEST_MODEM_POWERON: return "MODEM_POWERON";
5450 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
5451 case RIL_REQUEST_QUERY_ICCID: return "RIL_REQUEST_QUERY_ICCID";
5452 case RIL_UNSOL_TX_POWER: return "RIL_UNSOL_TX_POWER";
5453 case RIL_UNSOL_NETWORK_INFO: return "RIL_UNSOL_NETWORK_INFO";
5454 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
5455 case RIL_REQUEST_SET_IMSCFG: return "RIL_REQUEST_SET_IMSCFG";
5456#ifdef ECALL_SUPPORT
5457 case RIL_REQUEST_ECALL_FAST_MAKE_ECALL: return "ECALL_FAST_MAKE_ECALL";
5458 case RIL_REQUEST_ECALL_SET_IVS: return "RIL_REQUEST_ECALL_SET_IVS";
5459 case RIL_REQUEST_ECALL_SET_PSAP: return "RIL_REQUEST_ECALL_SET_PSAP";
5460 case RIL_REQUEST_ECALL_MAKE_ECALL: return "RIL_REQUEST_ECALL_MAKE_ECALL";
5461 case RIL_REQUEST_ECALL_IVS_PUSH_MSD: return "RIL_REQUEST_ECALL_IVS_PUSH_MSD";
5462 case RIL_REQUEST_ECALL_PSAP_PULL_MSD: return "RIL_REQUEST_ECALL_PSAP_PULL_MSD";
5463 case RIL_UNSOL_ECALL_MSDHACK : return "ECALL_MSDHACK";
5464 case RIL_REQUEST_ECALL_SET_MSD: return "RIL_REQUEST_ECALL_SET_MSD";
5465 case RIL_REQUEST_ECALL_CTRL_SEQUENCE: return "ECALL_SET_CTRL_SEQUENCE";
5466 case RIL_UNSOL_ECALL_INDICATIONS : return "ECALL_INDICATIONS";
5467 case RIL_REQUEST_ECALL_RESET_IVS: return "RIL_REQUEST_ECALL_RESET_IVS";
5468 case RIL_REQUEST_ECALL_SET_PRI: return "RIL_REQUEST_ECALL_SET_PRI";
5469 case RIL_REQUEST_ECALL_SET_TEST_NUM: return "RIL_REQUEST_ECALL_SET_TEST_NUM";
5470 case RIL_REQUEST_ECALL_SET_RECONF_NUM: return "RIL_REQUEST_ECALL_SET_RECONF_NUM";
5471 case RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD: return "RIL_REQUEST_SYNC_DATA_SETTINGS_TO_MD";
5472 case RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME: return "RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME";
5473 case RIL_REQUEST_ECALL_SET_REGISTRATION_STATE: return "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE";
5474#endif /*ECALL_SUPPORT*/
5475#ifdef KEEP_ALIVE
5476 case RIL_REQUEST_START_KEEPALIVE_PRO: return "RIL_REQUEST_START_KEEPALIVE_PRO";
5477 case RIL_REQUEST_STOP_KEEPALIVE_PRO: return "RIL_REQUEST_STOP_KEEPALIVE_PRO";
5478 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return "RIL_UNSOL_KEEPALIVE_STATUS_PRO";
5479#endif /*KEEP_ALIVE*/
5480 case RIL_REQUEST_SEND_USSI: return "SEND_USSI";
5481 case RIL_REQUEST_CANCEL_USSI: return "CANCEL_USSI";
5482 case RIL_REQUEST_GET_SMS_SIM_MEM_STATUS: return "GET_SMS_SIM_MEM_STATUS";
5483 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return "RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR";
5484 case RIL_REQUEST_REPORT_AIRPLANE_MODE: return "RIL_REQUEST_REPORT_AIRPLANE_MODE";
5485 case RIL_REQUEST_SET_ECC_NUM: return "RIL_REQUEST_SET_ECC_NUM";
5486 case RIL_REQUEST_GET_ECC_NUM: return "RIL_REQUEST_GET_ECC_NUM";
5487 case RIL_UNSOL_ECC_NUM: return "RIL_UNSOL_ECC_NUM";
5488 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT: return "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS_WITH_ACT";
5489 case RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_GET_BROADCAST_LANGUAGE";
5490 case RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE: return "RIL_REQUEST_GSM_SET_BROADCAST_LANGUAGE";
5491 case RIL_UNSOL_CALL_INFO_INDICATION: return "RIL_UNSOL_CALL_INFO_INDICATION";
5492 case RIL_REQUEST_MODIFY_APN: return "RIL_REQUEST_MODIFY_APN";
5493 case RIL_REQUEST_RESET_APN: return "RIL_REQUEST_RESET_APN";
5494 case RIL_REQUEST_QUERY_SIM_RETRY_COUNT: return "RIL_REQUEST_QUERY_SIM_RETRY_COUNT";
5495 case RIL_REQUEST_QUERY_EID: return "RIL_REQUEST_QUERY_EID";
5496 case LYNQ_REQUEST_SET_DTMF_VOLUME: return "RIL_REQUEST_SET_DTMF_VOLUME";
q.huangec88da92022-03-29 04:17:32 -04005497 case LYNQ_REQUEST_SET_SPEECH_VOLUME: return "RIL_REQUEST_SET_SPEECH_VOLUME";
5498 case LYNQ_REQUEST_GET_SPEECH_VOLUME: return "RIL_REQUEST_GET_SPEECH_VOLUME";
5499 case LYNQ_REQUEST_RECORD: return "RIL_REQUEST_RECORD";
lhf6eea122022-01-20 19:32:14 -08005500 /*warren add for t800 ril service 2022/1/22 start*/
5501 case LYNQ_REQUEST_WRITE_SMS_TO_MEMORY: return "LYNQ_REQUEST_WRITE_SMS_TO_MEMORY";
5502 case LYNQ_REQUEST_READ_SMS_FROM_MEMORY: return "LYNQ_REQUEST_READ_SMS_FROM_MEMORY";
5503 case LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY: return "LYNQ_REQUEST_DELETE_SMS_FROM_MEMORY";
5504 case LYNQ_REQUEST_LIST_SMS_FROM_MEMORY: return "LYNQ_REQUEST_LIST_SMS_FROM_MEMORY";
rjw5d2a50e2022-02-28 15:01:49 +08005505 case LYNQ_REQUEST_SET_DEFAULT_SIM_ALL:return "SET_DEFAULT_SIM_ALL";
jb.qi96449342022-09-19 22:14:41 -07005506 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 +08005507 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 -07005508 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 -08005509 /*warren add for t800 ril service 2022/1/22 end*/
lh7b0674a2022-01-10 00:34:35 -08005510 default: return "<unknown request>";
5511 }
5512}
5513
5514static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
5515 printResponse;
5516 int type;
5517 if(enable_bt_resp){
5518 SendRespToClient(p.data(), p.dataSize());
5519 }
5520 p.setDataPosition(0);
5521 p.readInt32(&type);
5522 if(type == RESPONSE_UNSOLICITED){
5523 processUnsolicited(p,type);
5524 }else if (type == RESPONSE_SOLICITED){
5525 processSolicited(p,type);
5526 }
5527 return 0;
5528}
5529
5530static void speciaRequest_wait()
5531{
5532 struct timeval now;
5533 struct timespec timeout;
5534
5535 gettimeofday(&now,NULL);
5536 timeout.tv_sec = now.tv_sec+1200; //timeout is 2omin. maybe radio on/off need 10s to complete.
5537 timeout.tv_nsec = now.tv_usec*1000;
5538
5539 SPECIA_BLOCK_LOCK();
5540 while(!(requestOneByOne == 0)) {
5541 int ret = SPECIA_BLOCK_WAIT(&timeout);
5542 if(ret == ETIMEDOUT){
5543 RLOGD("special request wait timeout");
5544 break;
5545 }
5546 }
5547 requestOneByOne = 1;
5548 SPECIA_BLOCK_UNLOCK();
5549}
5550
5551static void speciaRequest_wakeup()
5552{
5553 SPECIA_BLOCK_LOCK();
5554 requestOneByOne = 0;
5555 SPECIA_BLOCK_WAKEUP();
5556 SPECIA_BLOCK_UNLOCK();
5557}
5558
5559static void updateIccCardState(RIL_SOCKET_ID soc_id)
5560{
5561 ARspRequest(RIL_REQUEST_GET_SIM_STATUS, soc_id);
5562}
5563
5564void sendRequestToMd(int request, int id) {
5565 RequestInfo* info = creatRILInfoAndInit(request, INIT, (RIL_SOCKET_ID) ((id)));
5566 switch(request){
5567 case RIL_REQUEST_DEVICE_IDENTITY:
5568 {
5569 getDeviceIdentity(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5570 break;
5571 }
5572 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE:
5573 {
5574 getPreferredNetworkType(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5575 break;
5576 }
5577 case RIL_REQUEST_GET_SIM_STATUS:
5578 {
5579 getIccCardStatus(1, NULL, (RIL_SOCKET_ID) (id), info);
5580 break;
5581 }
5582 case RIL_REQUEST_DATA_REGISTRATION_STATE:
5583 {
5584 getDataRegistrationState(1, NULL, (RIL_SOCKET_ID) (id), info);
5585 break;
5586 }
5587 case RIL_REQUEST_VOICE_REGISTRATION_STATE:
5588 {
5589 getVoiceRegistrationState(1, NULL, (RIL_SOCKET_ID) (id), info);
5590 break;
5591 }
5592 case RIL_REQUEST_VOICE_RADIO_TECH:
5593 {
5594 getVoiceRadioTechnology(1, NULL, (RIL_SOCKET_ID) (id), info);
5595 break;
5596 }
5597 case RIL_REQUEST_OEM_HOOK_RAW:
5598 {
5599 char* tmp[2] = {"RIL_REQUEST_OEM_HOOK_RAW", "AT+ECAL"};
5600 sendATCMD(2, tmp, (RIL_SOCKET_ID) (id), info);
5601 break;
5602 }
5603 case RIL_REQUEST_GET_RADIO_CAPABILITY:
5604 {
5605 getRadioCapability(1, NULL, (RIL_SOCKET_ID) ((id)), info);
5606 break;
5607 }
5608 default:
5609 RLOGE("don't support %d in init", id);
5610 if(info) {
5611 free(info);
5612 }
5613 }
5614}
5615
jb.qi96449342022-09-19 22:14:41 -07005616/**@brief pass the change screen state request to the executing function
5617*@param request type: [IN] requestID
5618*@param slot_id type: [IN] simID
5619*@param argv type: [IN] getScreenState's argv
5620*@author jb.qi
5621*@date 2022/09/19
5622*/
5623void lynq_sendRequestToMd(int request, int slot_id, char **argv, struct sockaddr_in lynqClient_addr, int utoken)
5624{
5625 RequestInfo* info = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID) ((slot_id)));
5626 info->uToken = utoken;
5627 info->lynqEvent = 2;
5628 info->uClient_addr.sin_family = lynqClient_addr.sin_family;
5629 info->uClient_addr.sin_addr.s_addr = lynqClient_addr.sin_addr.s_addr;
5630 info->uClient_addr.sin_port = lynqClient_addr.sin_port;
5631 switch(request){
5632 case RIL_REQUEST_SCREEN_STATE:
5633 {
5634 int waittoken = info->token;
5635 RLOGD("getScreenState\n");
5636 getScreenState(2, argv, (RIL_SOCKET_ID) ((slot_id)), info);
5637 waitResponse(waittoken);
5638 break;
5639 }
ll71a113b2022-10-21 18:07:25 +08005640 case RIL_REQUEST_RADIO_POWER:
5641 {
5642 int waittoken = info->token;
5643 RLOGD("LYNQ_REQUEST_CHANGE_RADIO\n");
5644 setRadioPower(2, argv, (RIL_SOCKET_ID) ((slot_id)), info);
5645 waitResponse(waittoken);
5646 break;
5647 }
jb.qi96449342022-09-19 22:14:41 -07005648 default:
5649 RLOGD("dont support %d in init", slot_id);
jb.qi6b23ed42022-09-22 00:30:55 -07005650 if(info)
5651 {
jb.qi96449342022-09-19 22:14:41 -07005652 free(info);
5653 }
5654 }
5655}
5656
lh7b0674a2022-01-10 00:34:35 -08005657static void init(int id) {
5658 int waittoken;
5659 RIL_RadioState radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5660 while (radioState == RADIO_STATE_UNAVAILABLE) {
5661 sleep(1);
5662 radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5663 RLOGD("init socket id: %d, %s", id, radioStateToString(radioState));
5664 }
5665 RLOGD("init socket id: %d, %s", id, radioStateToString(radioState));
xja1c30b82022-01-25 16:13:48 +08005666 updataDataConnectState(id, false);
lh7b0674a2022-01-10 00:34:35 -08005667 sendRequestToMd(RIL_REQUEST_GET_SIM_STATUS, id);
5668
5669#if 0
5670 if (radioState != RADIO_STATE_ON) {
5671 RequestInfo* radio = creatRILInfoAndInit(RIL_REQUEST_RADIO_POWER, INIT, (RIL_SOCKET_ID) (id));
5672 waittoken = radio->token;
5673 RLOGD("[%s-%d]:token is %x", __FUNCTION__, __LINE__, radio->token);
5674 char* tmp[2] = { "RIL_REQUEST_RADIO_POWER", "1" };
5675 setRadioPower(2, tmp, (RIL_SOCKET_ID) (id), radio);
5676 waitResponse(waittoken);
5677 sleep(2);
5678 radioState = CALL_ONSTATEREQUEST((RIL_SOCKET_ID )id);
5679 RLOGD("NOW radio status %s", radioStateToString(radioState));
5680 }
5681# endif
5682 sendRequestToMd(RIL_REQUEST_DATA_REGISTRATION_STATE, id);
5683 sendRequestToMd(RIL_REQUEST_VOICE_REGISTRATION_STATE, id);
5684 sendRequestToMd(RIL_REQUEST_VOICE_RADIO_TECH, id);
5685 sendRequestToMd(RIL_REQUEST_DEVICE_IDENTITY,id);
5686 sendRequestToMd(RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE, id);
5687 sendRequestToMd(RIL_REQUEST_OEM_HOOK_RAW, id);
5688 sendRequestToMd(RIL_REQUEST_GET_RADIO_CAPABILITY,id);
5689}
5690
5691static void initCoditions()
5692{
5693 mixer_init();
5694 if(utils::is_support_dsds()) {
5695 for(int i = 0; i < 2 ; i++) {
5696 init(i);
5697 }
5698 }
5699
5700 if(utils::is_suppport_dsss()) {
5701 int id = Phone_utils::get_enable_sim_for_dsss();
5702 init(id);
q.huang036b6cf2023-01-10 14:29:20 +08005703 }
lh7b0674a2022-01-10 00:34:35 -08005704}
5705
5706
5707//For UDP sokcet send response to client
5708static int SendRespToClient(const void *data, size_t dataSize)
5709{
5710 const uint8_t *toWrite;
5711 size_t writeOffset = 0;
5712
5713 toWrite = (const uint8_t *)data;
5714
5715 if (toWrite == NULL) {
5716 //buf is invaild
5717 return -1;
5718 }
5719
5720 while (writeOffset < dataSize) {
5721 ssize_t written;
5722 do {
5723 //written = write (fd, toWrite + writeOffset,dataSize - writeOffset);
5724 written = sendto(server_socket_fd, toWrite + writeOffset, dataSize - writeOffset,
5725 0, (struct sockaddr *)&client_addr, sizeof(client_addr));
5726 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
5727
5728 if (written >= 0) {
5729 writeOffset += written;
5730 } else { // written < 0
5731 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
5732 return -1;
5733 }
5734 }
5735
5736 return 0;
5737}
5738
5739static UnsolResponseInfo* find_mtk_unsol_command(int request)
5740{
5741 int i;
5742 for (i = 0; i < (int32_t)NUM_ELEMS(s_mtk_unsolResponses); i++)
5743 if (s_mtk_unsolResponses[i].requestNumber == request)
5744 return (&s_mtk_unsolResponses[i]);
5745 return ((UnsolResponseInfo *)NULL);
5746}
5747
5748static int
5749onSupports (int requestCode)
5750{
5751 switch(requestCode)
5752 {
5753 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return 1;
5754 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return 1;
5755 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return 1;
q.huangcdcdf922022-10-20 13:40:51 +08005756 case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED: return 1;
lh7b0674a2022-01-10 00:34:35 -08005757 case RIL_UNSOL_RESPONSE_NEW_SMS: return 1;
5758 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return 1;
5759 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return 1;
5760 case RIL_UNSOL_ON_USSD: return 1;
5761 case RIL_UNSOL_ON_USSD_REQUEST: return 1;
5762 case RIL_UNSOL_NITZ_TIME_RECEIVED: return 1;
5763 case RIL_UNSOL_SIGNAL_STRENGTH: return 1;
5764 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return 1;
5765 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return 1;
5766 case RIL_UNSOL_STK_SESSION_END: return 1;
5767 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return 1;
5768 case RIL_UNSOL_STK_EVENT_NOTIFY: return 1;
5769 case RIL_UNSOL_STK_CALL_SETUP: return 1;
5770 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return 1;
5771 case RIL_UNSOL_SIM_REFRESH: return 1;
5772 case RIL_UNSOL_CALL_RING: return 1;
5773 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return 1;
5774 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return 1;
5775 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return 1;
5776 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return 0;
5777 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return 1;
5778 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return 1;
5779 case RIL_UNSOL_CDMA_CALL_WAITING: return 1;
5780 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return 0;
5781 case RIL_UNSOL_CDMA_INFO_REC: return 0;
5782 case RIL_UNSOL_OEM_HOOK_RAW: return 1;
5783 case RIL_UNSOL_RINGBACK_TONE: return 1;
5784 case RIL_UNSOL_RESEND_INCALL_MUTE: return 0;
5785 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return 0;
5786 case RIL_UNSOL_CDMA_PRL_CHANGED: return 0;
5787 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return 1;
5788 case RIL_UNSOL_RIL_CONNECTED: return 1;
5789 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return 1;
5790 case RIL_UNSOL_CELL_INFO_LIST: return 1;
5791 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return 1;
5792 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return 1;
5793 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return 1;
5794 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return 0;
5795 case RIL_UNSOL_DC_RT_INFO_CHANGED: return 0;
5796 case RIL_UNSOL_RADIO_CAPABILITY : return 1;
5797 case RIL_UNSOL_MAL_RESTART : return 1;
5798 case RIL_UNSOL_CALL_INFO_INDICATION : return 1;
5799 case RIL_UNSOL_CRSS_NOTIFICATION : return 0;
5800 case RIL_UNSOL_ECONF_SRVCC_INDICATION : return 1;
5801 case RIL_UNSOL_ECONF_RESULT_INDICATION : return 1;
5802 case RIL_UNSOL_STK_BIP_PROACTIVE_COMMAND : return 0;
5803 case RIL_UNSOL_MAL_AT_INFO: return 1;
5804 case RIL_UNSOL_ECALL_MSDHACK: return 1;
5805 case RIL_UNSOL_TX_POWER: return 1;
5806 case RIL_UNSOL_NETWORK_INFO: return 1;
xy.hef5d74f12023-10-23 06:48:52 -07005807 case RIL_UNSOL_TELEPHONY_RESTART: return 1;
lh7b0674a2022-01-10 00:34:35 -08005808#ifdef ECALL_SUPPORT
5809 case RIL_UNSOL_ECALL_INDICATIONS: return 1;
5810#endif /*ECALL_SUPPORT*/
5811#ifdef KEEP_ALIVE
5812 case RIL_UNSOL_KEEPALIVE_STATUS_PRO: return 1;
5813#endif /*KEEP_ALIVE*/
5814 case RIL_UNSOL_ON_USSI: return 1;
5815 case RIL_UNSOL_ECC_NUM: return 1;
5816 case RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR: return 1;
5817 default: return 0;
5818 }
5819}
5820
5821int parse_param(char *cmd, char *argv[], int max_args)
5822{
5823 char *pos, *pos2;
5824 int argc = 0;
lxfdb3a24c2023-11-20 06:26:13 -08005825 printf("LYNQ_REQUEST cmd=%s\n",cmd);
lh7b0674a2022-01-10 00:34:35 -08005826 pos = cmd;
5827 while (1) {
5828 // Trim the space characters.
5829 while (*pos == ' ') {
5830 pos++;
5831 }
5832
5833 if (*pos == '\0') {
5834 break;
5835 }
5836
5837 // One token may start with '"' or other characters.
5838 if (*pos == '"' && (pos2 = strrchr(pos+1, '"'))) {
5839 argv[argc++] = pos + 1;
5840 *pos2 = '\0';
5841 pos = pos2 + 1;
5842 if(*pos == '\n'){
5843 *pos = '\0';
5844 pos = pos + 1;
5845 }
5846
5847 } else {
5848 argv[argc++] = pos;
5849 while (*pos != '\0' && *pos != ' '&& *pos != '\n') {
5850 pos++;
5851 }
5852 *pos++ = '\0';
5853
5854 if(argc == 1) {
5855 char* at_cmd = strstr(argv[0], "RIL_REQUEST_OEM_HOOK_RAW");
5856 if(at_cmd != NULL) {
5857 while (*pos == ' ') {
5858 pos++;
5859 }
5860 argv[argc++] = pos;
5861 while (*pos != '\0' && *pos != '\n') {
5862 pos++;
5863 }
5864 *pos++ = '\0';
5865 break;
5866 }
5867 }
5868
5869 }
5870
5871 // Check if the maximum of arguments is reached.
5872 if (argc == max_args) {
5873 break;
5874 }
5875 }
5876
5877 return argc;
5878}
5879
5880/* Look up NAME as the name of a command, and return a pointer to that
5881 command. Return a NULL pointer if NAME isn't a command name. */
5882COMMAND* find_command (char *name)
5883{
5884 register int i;
5885
5886 for (i = 0; commands[i].name; i++)
5887 if (strcmp (name, commands[i].name) == 0)
5888 return (&commands[i]);
5889
5890 return ((COMMAND *)NULL);
5891}
5892
5893CommandInfo* find_mtk_command (int request)
5894{
5895 int i;
5896 for (i = 0; i < (int32_t)NUM_ELEMS(mtk_s_command); i++)
5897 if (mtk_s_command[i].requestNumber == request)
5898 return (&mtk_s_command[i]);
5899 return ((CommandInfo *)NULL);
5900}
5901
5902/* The user wishes to quit using this program. Just set DONE non-zero. */
5903static int com_quit (int argc, char *argv[], RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5904{
5905 exit(EXIT_SUCCESS);
5906 return (0);
5907}
5908
5909static int enableSyslog(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5910{
5911 if(argc < 2)
5912 {
5913 RLOGE("[Error] enable syslog paramter is error\n");
5914 free(pRI);
5915 return -1;
5916 }
5917 enable_syslog = atoi(argv[1]);
5918 RLOGE("%s syslog\n",enable_syslog ? "enable" :"disable");
5919 free(pRI);
5920 return 0;
5921}
5922
5923static int enableBTResponse(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
5924{
5925 if(argc < 2)
5926 {
5927 RLOGE("[Error] enable BT response paramter is error\n");
5928 free(pRI);
5929 return -1;
5930 }
5931 enable_bt_resp = atoi(argv[1]);
5932 RLOGE("%s bt response!\n",enable_bt_resp ? "enable" :"disable");
5933 free(pRI);
5934 return 0;
5935
5936}
5937
5938char Time_buf[24];
5939void GetTimeString(char * buf)
5940{
5941 time_t timep;
5942 struct tm p;
5943
5944 if(buf == NULL){
5945 RLOGE("[Error] GetTimeString: buf is Null\n");
5946 return;
5947 }
5948 //memset(buf,0,sizeof(buf));
5949 time(&timep);
5950 localtime_r(&timep,&p);
5951 sprintf(buf,"%d_%d_%d %d:%d:%d",(1900+p.tm_year),(1+p.tm_mon),p.tm_mday,
5952 (p.tm_hour),p.tm_min,p.tm_sec);
5953// printf("data is %s\n",buf);
5954
5955 return;
5956}
5957/*Warren add for t800 RIL Service 2021/12/10 start*/
q.huangadbad2f2022-09-15 16:28:02 +08005958int lynqAssemblyParcelheader(Parcel &p,int slot,int utoken, int request,int respType,int error)
lh7b0674a2022-01-10 00:34:35 -08005959{
5960 p.writeInt32 (respType);
q.huangadbad2f2022-09-15 16:28:02 +08005961 p.writeInt32 (utoken);
lh7b0674a2022-01-10 00:34:35 -08005962 p.writeInt32 (request);
5963 /*warren add for t800 ril servie 2021/12/15 start*/
5964 p.writeInt32(slot);
5965 /*warren add for t800 ril servie 2021/12/15 end*/
5966 p.writeInt32 (error);
5967 return 0;
5968}
5969void LYNQ_RIL_urcClientInit()
5970{
lhced7d4a2023-03-28 09:50:52 +08005971 int len = 0;
5972 int on=1;
5973 int ret = 0;
5974 lynq_urc_socket_fd = socket(AF_INET,SOCK_DGRAM,0);
5975 if(lynq_urc_socket_fd < 0)
5976 {
5977 perror("creaet socket for udp fail");
5978 return;
5979 }
5980 /* 设置socket允许重复使用地址与端口,SO_REUSEADDR值为2 */
5981 //setsockopt(socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
5982 /* 使能广播功能,SO_BROADCAST值为6 */
5983 ret= setsockopt(lynq_urc_socket_fd,SOL_SOCKET,SO_BROADCAST,&on,sizeof(on));
5984 if(ret<0)
5985 {
5986 RLOGD("set broadcast fail!!!\n");
5987 exit(1);
5988 }
5989 urc_broadcast_addr.sin_family = AF_INET; //IPv4
5990 urc_broadcast_addr.sin_port = htons(LYNQ_BRODCAST_PORT);
5991 urc_broadcast_addr.sin_addr.s_addr = inet_addr("255.255.255.255" );//255.255.255.255 broadcast addrress.
5992 printf("LYNQ_RIL_urcClientInit success!!!\n");
lh7b0674a2022-01-10 00:34:35 -08005993 return;
5994 /*
5995 while(1)
5996 {
5997 len = sendto(lynq_urc_socket_fd,"hello world",11,0,(struct sockaddr *)&urc_broadcast_addr,sizeof(urc_broadcast_addr));
5998 if(len > 0)
5999 {
6000 printf("sendto success,len=%d\n",len);
6001 }
6002 else
6003 {
6004 printf("sendto fail\n");
6005 }
6006 sleep(1);
6007 }
6008 */
6009}
q.huang5bbadde2023-02-09 16:50:52 +08006010
6011//add by hq for bug 760 2023/02/09
6012static int setnonblocking(int sockfd) {
6013 int flag = fcntl(sockfd, F_GETFL, 0); //get current flag
6014 if (flag < 0) {
6015 RLOGE("fcntl F_GETFL fail");
6016 return -1;
6017 }
6018 if (fcntl(sockfd, F_SETFL, flag | O_NONBLOCK) < 0) { //add O_NONBLOCK
6019 RLOGE("fcntl F_SETFL fail");
6020 return -1;
6021 }
6022 return 0;
6023}
6024
lh7b0674a2022-01-10 00:34:35 -08006025void LYNQ_RIL_RecSocket()
6026{
6027 RLOGD("LYNQ_RIL_RecSocket start\n");
6028 char *argv[MAX_ARGS];
6029 int argc = 0;
6030 int ep_fd = 0;
6031 int en_fd = 0;
6032 struct epoll_event lynq_ev;
6033 struct epoll_event lynq_events[LYNQ_SOCKET_ENVNT_FD_MAX];
6034 //prctl(PR_SET_NAME,(unsigned long)"UDP_Thr");
6035
6036 /*listen UPD SOCKET port */
6037 struct sockaddr_in server_addr;
6038 struct sockaddr_in lynqClient_addr;
6039 bzero(&server_addr, sizeof(server_addr));
6040 server_addr.sin_family = AF_INET;
lh8d290112023-10-22 20:53:06 -07006041 server_addr.sin_addr.s_addr = inet_addr(LYNQ_RIL_FWK_IP);
lh7b0674a2022-01-10 00:34:35 -08006042 server_addr.sin_port = htons(LYNQ_SERVICE_PORT);
6043 /* create socket */
6044 //int server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
6045 server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
6046 if(server_socket_fd == -1)
6047 {
6048 RLOGE("Create Socket Failed:");
6049 exit(1);
6050 }
6051
6052 /* bind socket port*/
6053 if(-1 == (bind(server_socket_fd,(struct sockaddr*)&server_addr,sizeof(server_addr))))
6054 {
6055 RLOGE("Server Bind Failed:");
6056 exit(1);
6057 }
q.huang5bbadde2023-02-09 16:50:52 +08006058
6059 if(setnonblocking(server_socket_fd)!=0)
6060 {
6061 RLOGE("setnonblocking Failed");
6062 exit(1);
6063 }
6064
lh7b0674a2022-01-10 00:34:35 -08006065 /* create epoll fd,add socket to epoll */
6066 ep_fd = epoll_create(LYNQ_SOCKET_ENVNT_FD_MAX);
6067 //int len = sizeof(struct sockaddr_in);
6068 lynq_ev.events = EPOLLIN | EPOLLET;
6069 lynq_ev.data.fd = server_socket_fd;
6070 if(epoll_ctl(ep_fd, EPOLL_CTL_ADD, server_socket_fd, &lynq_ev) < 0)
6071 {
6072 fprintf(stderr, "epoll set insertion error: fd=%d\n", server_socket_fd);
6073 return;
6074 }
6075 else
6076 {
6077 printf("monitor socket add epoll success!!!\n");
6078 }
6079 char buffer[LYNQ_SOCKET_BUFFER];
6080 lynq_client_t *client_tmp = NULL;
6081 /* tranlate data */
6082 while(true)
6083 {
6084 if(!s_registerCalled)
6085 {
6086 sleep(1);
6087 continue;
6088 }
6089 en_fd = epoll_wait(ep_fd, lynq_events, 10000, -1);//###Check valid
6090 if(en_fd <=0 )
6091 {
6092 continue;
6093 }
6094 for (int n = 0; n < en_fd; ++n)
6095 {
6096 if (lynq_events[n].data.fd == server_socket_fd)
6097 {
6098 /* define address to catch the client addreess*/
6099 //struct sockaddr_in client_addr;
6100 socklen_t client_addr_length = sizeof(lynqClient_addr);
6101 /* receive the data */
6102 bzero(buffer, LYNQ_SOCKET_BUFFER);
q.huang5bbadde2023-02-09 16:50:52 +08006103 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 -08006104 {
q.huang5bbadde2023-02-09 16:50:52 +08006105 client_tmp = (lynq_client_t*)buffer;
6106 RLOGD("[LYNQ socketId] utoken=%d,request=%d,len=%d,param=%s",client_tmp->uToken,client_tmp->request,client_tmp->paramLen,client_tmp->param);
6107 //char test[36] = {};
6108 //sprintf(test,"test okay len = %d",client_tmp->paramLen);
6109 //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&client_addr,client_addr_length);
6110 argv[0] = (char *)lynq_requset_to_string(client_tmp->request);
6111 argc = 0;
6112 if(client_tmp->paramLen > 0)
lh7b0674a2022-01-10 00:34:35 -08006113 {
q.huang5bbadde2023-02-09 16:50:52 +08006114 /*transfer struct*/
6115 argc = parse_param(client_tmp->param, argv+1, MAX_ARGS);
6116 if(argc < 1)
6117 {
6118 RLOGE("%s: error input.", buffer);
6119 continue;
6120 }
6121 }
6122 printf("argc =%d\n",argc);
6123 argc = argc+1;
6124 for(int t = 0;t<argc;t++)
6125 {
lxfdb3a24c2023-11-20 06:26:13 -08006126 RLOGD("LYNQ_REQUEST argv[%d]=%s\n",t,argv[t]);
q.huang5bbadde2023-02-09 16:50:52 +08006127 }
6128 COMMAND *command = find_command(argv[0]);
6129 if(!command)
6130 {
6131 RLOGE("%s: No such command for DemoApp", argv[0]);
lh7b0674a2022-01-10 00:34:35 -08006132 continue;
6133 }
q.huang5bbadde2023-02-09 16:50:52 +08006134 int32_t request;
6135 request = command->request;
6136 RIL_SOCKET_ID id = RIL_SOCKET_1;
6137 if(utils::is_support_dsds()) {
6138 id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
6139 } else if(utils::is_suppport_dsss()) {
6140 id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
ll71a113b2022-10-21 18:07:25 +08006141 }
q.huang5bbadde2023-02-09 16:50:52 +08006142 if(request == -1)
ll71a113b2022-10-21 18:07:25 +08006143 {
q.huang5bbadde2023-02-09 16:50:52 +08006144 (*(command->func)) (argc, argv, id, NULL);
6145 continue;
jb.qi96449342022-09-19 22:14:41 -07006146 }
q.huang5bbadde2023-02-09 16:50:52 +08006147 if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
6148 RLOGW("unsupported request code %d token %d", request);
6149 // FIXME this should perhaps return a response
6150 continue;
6151 }
6152 /*jb.qi add for two sim suspend 2022/9/19 start lei modify for factory test of sleep*/
6153 if(request == LYNQ_REQUEST_CHANGE_SCREEN_STATE || request == LYNQ_REQUEST_CHANGE_RADIO)
6154 {
6155 int i;
6156 RLOGD("lynq_request_change_screen_state");
6157 if(request == LYNQ_REQUEST_CHANGE_SCREEN_STATE)
6158 {
6159 for(i=0;i<2;i++) //suspend sim0 and sim1
6160 {
6161 lynq_sendRequestToMd(RIL_REQUEST_SCREEN_STATE, i, argv, lynqClient_addr, client_tmp->uToken);
6162 }
6163 }
6164 /*lei modify for factory test of sleep*/
6165 if(request == LYNQ_REQUEST_CHANGE_RADIO)
6166 {
6167 for(i=0;i<2;i++) //both radio on/off
6168 {
6169 lynq_sendRequestToMd(RIL_REQUEST_RADIO_POWER, i, argv, lynqClient_addr, client_tmp->uToken);
6170 }
6171 }
6172 continue;
6173 }
6174 /*jb.qi add for two sim suspend 2022/9/19 end*/
6175 RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
6176 RequestInfo *pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
6177 pRI->uToken = client_tmp->uToken;
6178 pRI->lynqEvent = 2;
6179 pRI->uClient_addr.sin_family = lynqClient_addr.sin_family;
6180 pRI->uClient_addr.sin_addr.s_addr = lynqClient_addr.sin_addr.s_addr;
6181 pRI->uClient_addr.sin_port = lynqClient_addr.sin_port;
6182 //sendto(server_socket_fd,test,strlen(test),0,(struct sockaddr*)&pRI->uClient_addr,client_addr_length);
6183 //pRI->uClient_addr.sa_family = (struct sockaddr)client_addr.sa_family;
6184 //memcpy(pRI->uClient_addr.sa_data,&client_addr
6185 //Radio on/off only allow one thread operate.
6186 if(request == RIL_REQUEST_RADIO_POWER)
6187 {
6188 speciaRequest_wait();
6189 }
6190 #ifdef ECALL_SUPPORT
6191 else if(request == RIL_REQUEST_ECALL_FAST_MAKE_ECALL)
6192 {
6193 init_redial_flag();
6194 }
6195 #endif
6196 memset(Time_buf,0,sizeof(Time_buf));
6197 GetTimeString(Time_buf);
6198 //FUNCTION_CALLED(Time_buf,requestToString(request));
6199 int waittoken = pRI->token;
6200 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
6201 FUNCTION_CALLED(Time_buf,requestToString(request));
6202 waitResponse(waittoken);
6203 memset(Time_buf,0,sizeof(Time_buf));
6204 GetTimeString(Time_buf);
6205 FUNCTION_RETURN(Time_buf,requestToString(request));
6206 bzero(buffer, LYNQ_SOCKET_BUFFER);
6207
jb.qi96449342022-09-19 22:14:41 -07006208 }
q.huang5bbadde2023-02-09 16:50:52 +08006209 RLOGE("process Receive Data end");
6210 // continue;
lh7b0674a2022-01-10 00:34:35 -08006211 }
6212 }
6213 }
6214 RLOGD("close socket fd");
6215 close(server_socket_fd);
6216 return ;
6217}
6218int LYNQ_RIL_respSocket(Parcel &p,RIL_Token t)
6219{
6220 RLOGD("LYNQ_RIL_respSocket send start");
lh7b0674a2022-01-10 00:34:35 -08006221 ssize_t sent = 0;
lh7b0674a2022-01-10 00:34:35 -08006222 RequestInfo *pRI = (RequestInfo *)t;
ll90a255c2022-04-07 09:09:55 +00006223 if(pRI->lynqEvent!=2)
lh7b0674a2022-01-10 00:34:35 -08006224 {
6225 RLOGD("this is internal event!!!");
6226 return -1;
6227 }
6228 int dataSize = p.dataSize();
6229 const uint8_t* data = p.data();
6230 RLOGD("lynqSocketSend RESPONSE!!!! ");
lh7b0674a2022-01-10 00:34:35 -08006231 sent = sendto(server_socket_fd, data, dataSize, 0, (struct sockaddr *)&pRI->uClient_addr, sizeof(pRI->uClient_addr));
6232 if( sent < 0 )
6233 {
6234 RLOGE("lynqSocketSend send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
6235 sent,server_socket_fd, dataSize);
lh7b0674a2022-01-10 00:34:35 -08006236 return -1;
6237 }
6238 return 0;
6239}
6240int LYNQ_RIL_respSocket_sp(Parcel &p,RequestInfo *pRI)
6241{
6242 RLOGD("LYNQ_RIL_respSocket send start");
6243 int ret =0;
6244 bool sendResult =false;
6245 ssize_t sent = 0;
6246 uint8_t dataLength[4];
6247 int verify = 0x55aa;
6248 int dataSize = p.dataSize();
6249 const uint8_t* data = p.data();
ll90a255c2022-04-07 09:09:55 +00006250 if(pRI->lynqEvent!=2)
lh7b0674a2022-01-10 00:34:35 -08006251 {
6252 RLOGD("this is internal event!!!");
6253 return -1;
6254 }
6255 RLOGD("lynqSocketSend RESPONSE!!!! ");
lh7b0674a2022-01-10 00:34:35 -08006256
6257 sent = sendto(server_socket_fd, data, dataSize, 0, (struct sockaddr *)&pRI->uClient_addr, sizeof(pRI->uClient_addr));
6258 if( sent < 0 )
6259 {
6260 RLOGE("lynqSocketSend send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
6261 sent,server_socket_fd, dataSize);
lh7b0674a2022-01-10 00:34:35 -08006262 return -1;
6263 }
6264 return 0;
6265}
6266
q.huang036b6cf2023-01-10 14:29:20 +08006267bool is_need_use_shm(int dataSize, int urc_id)
6268{
6269 switch(urc_id)
6270 {
6271 /*network*/
6272 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
6273 case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
6274 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED:
6275 case RIL_UNSOL_SIGNAL_STRENGTH:
llcce1a812023-01-19 15:49:25 +08006276 /*sms*/
6277 case RIL_UNSOL_RESPONSE_NEW_SMS:
6278 /*sim*/
6279 //case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: Not supported at present
q.huang036b6cf2023-01-10 14:29:20 +08006280 /*call*/
6281 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
6282 case RIL_UNSOL_CALL_RING:
6283 case RIL_UNSOL_RINGBACK_TONE:
6284 case RIL_UNSOL_CALL_INFO_INDICATION:
6285#ifdef ECALL_SUPPORT
6286 case RIL_UNSOL_ECALL_INDICATIONS://9502
rjw7ee7bb42023-01-18 11:34:28 +08006287#endif
6288 /*Data*/
6289 case LYNQ_URC_DATA_CALL_STATUS_IND:
6290 case LYNQ_URC_MODIFY_APNDB:
6291 case LYNQ_URC_RESET_APNDB:
q.huang036b6cf2023-01-10 14:29:20 +08006292 break;
6293 default:
6294 return false;
6295 }
6296 if(dataSize>urc_broadcase_shm_size_limit && dataSize <= get_max_shem_buffer_size())
6297 {
6298 return true;
6299 }
6300 return false;
6301}
6302
6303int LYNQ_RIL_urcBroadcast(Parcel &p, int urc_id)
lh7b0674a2022-01-10 00:34:35 -08006304{
6305 RLOGD("LYNQ_RIL_urcBroadcast send start");
q.huang036b6cf2023-01-10 14:29:20 +08006306 int ret =0;
6307 ssize_t sent = 0;
6308 p.setDataPosition(0);
lh7b0674a2022-01-10 00:34:35 -08006309 int dataSize = p.dataSize();
6310 const uint8_t* data = p.data();
q.huang036b6cf2023-01-10 14:29:20 +08006311 RLOGD("LYNQ_RIL_urcBroadcast urc_id is %d, dataSize=%d, msg is %s", urc_id, dataSize, requestToString(urc_id));
6312 if(is_need_use_shm(dataSize,urc_id))
6313 {
6314 int index,level;
6315 if(get_cur_shem_buffer_index(dataSize,&level,&index))
6316 {
6317 char* p_shm_buffer=get_shem_buffer(level,index);
6318 memcpy(p_shm_buffer,data,dataSize);
6319 uint32_t* pFirstInt = (uint32_t*) const_cast<uint8_t*> (data);
6320 *pFirstInt=*pFirstInt+((index+1)<<SHM_BUFFER_INDEX_OFFSET)+((dataSize)<<SHM_BUFFER_SIZE_OFFSET);
6321 dataSize=sizeof(int32_t)*2;
q.huangf99a5a12023-02-14 18:07:50 +08006322 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 +08006323 }
6324 }
lhced7d4a2023-03-28 09:50:52 +08006325 sent = sendto(lynq_urc_socket_fd, data, dataSize, 0, (struct sockaddr *)&urc_broadcast_addr, sizeof(urc_broadcast_addr));
lh7b0674a2022-01-10 00:34:35 -08006326 if( sent < 0 )
6327 {
6328 RLOGE("LYNQ_RIL_urcBroadcast send datalen fail (sent=%d, sendFD=%d, dataSize=%d)",
lhced7d4a2023-03-28 09:50:52 +08006329 sent,lynq_urc_socket_fd, dataSize);
lh7b0674a2022-01-10 00:34:35 -08006330 return -1;
6331 }
q.huang036b6cf2023-01-10 14:29:20 +08006332
lh7b0674a2022-01-10 00:34:35 -08006333 return 0;
6334}
6335/*Warren add for t800 RIL Service 2021/12/10 end*/
6336
6337void
6338RIL_StartRevSocket()
6339{
6340 RLOGD("RIL_StartRevSocket start\n");
xja1c30b82022-01-25 16:13:48 +08006341 char *argv[MAX_ARGS] = {0};
lh7b0674a2022-01-10 00:34:35 -08006342 int argc = 0;
6343
6344 prctl(PR_SET_NAME,(unsigned long)"UDP_Thr");
6345
6346 /*listen UPD SOCKET port */
6347 struct sockaddr_in server_addr;
6348 bzero(&server_addr, sizeof(server_addr));
6349 server_addr.sin_family = AF_INET;
6350 server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
6351 server_addr.sin_port = htons(SERVER_PORT);
6352 /* create socket */
6353 //int server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
6354 server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
6355 if(server_socket_fd == -1)
6356 {
6357 RLOGE("Create Socket Failed:");
6358 exit(1);
6359 }
6360
6361 /* bind socket port*/
6362 if(-1 == (bind(server_socket_fd,(struct sockaddr*)&server_addr,sizeof(server_addr))))
6363 {
6364 RLOGE("Server Bind Failed:");
6365 exit(1);
6366 }
6367
6368 /* tranlate data */
6369 while(true)
6370 {
6371 if(!s_registerCalled)
6372 {
6373 sleep(1);
6374 continue;
6375 }
6376 /* define address to catch the client addreess*/
6377 //struct sockaddr_in client_addr;
6378 socklen_t client_addr_length = sizeof(client_addr);
6379
6380 /* receive the data */
6381 char buffer[BUFFER_SIZE];
6382 bzero(buffer, BUFFER_SIZE);
6383 if(recvfrom(server_socket_fd, buffer, BUFFER_SIZE,0,(struct sockaddr*)&client_addr, &client_addr_length) == -1)
6384 {
6385 RLOGE("Receive Data Failed:");
6386 continue;
6387 }
6388 RLOGD("DemoAPP:%s, receve: %s", inet_ntoa(client_addr.sin_addr), buffer);
6389 if(mtkItTest(buffer)) {
6390 RLOGD("mtkItTest() handle.");
6391 continue;
6392 }
6393 int argc = parse_param(buffer, argv, MAX_ARGS);
6394 if(argc < 1)
6395 {
6396 RLOGE("%s: error input.", buffer);
6397 continue;
6398 }
6399 COMMAND *command = find_command(argv[0]);
6400 if(!command)
6401 {
6402 RLOGE("%s: No such command for DemoApp", argv[0]);
6403 continue;
6404 }
6405
6406 int32_t request;
6407
6408 request = command->request;
6409
6410 RIL_SOCKET_ID id = RIL_SOCKET_1;
6411 if(utils::is_support_dsds()) {
6412 id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
6413 } else if(utils::is_suppport_dsss()) {
6414 id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
6415 }
lh7b0674a2022-01-10 00:34:35 -08006416 if(request == -1)
6417 {
6418 (*(command->func)) (argc, argv, id, NULL);
6419 continue;
6420 }
6421
6422 if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
6423 RLOGW("unsupported request code %d token %d", request);
6424 // FIXME this should perhaps return a response
6425 continue;
6426 }
6427
6428 RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
6429
6430
6431 RequestInfo *pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
6432 //Radio on/off only allow one thread operate.
6433 if(request == RIL_REQUEST_RADIO_POWER)
6434 {
6435 speciaRequest_wait();
6436 }
6437 memset(Time_buf,0,sizeof(Time_buf));
6438 GetTimeString(Time_buf);
6439 //FUNCTION_CALLED(Time_buf,requestToString(request));
6440 int waittoken = pRI->token;
6441 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
6442 FUNCTION_CALLED(Time_buf,requestToString(request));
6443 waitResponse(waittoken);
6444 memset(Time_buf,0,sizeof(Time_buf));
6445 GetTimeString(Time_buf);
6446 FUNCTION_RETURN(Time_buf,requestToString(request));
6447 }
6448
6449 RLOGD("close socket fd");
6450 close(server_socket_fd);
6451 return ;
6452}
6453
6454const int waitResponse(int token)
6455{
6456 int waitToken = token;
6457 struct timeval now;
6458 struct timespec timeout;
6459 if((token&BLOCK_MARK) != BLOCK_MARK){
6460 RLOGD("No need wait!,token is %x!",token);
6461 return 0;
6462 }
6463
6464 gettimeofday(&now,NULL);
6465 timeout.tv_sec = now.tv_sec+60; //timeout is 1min
6466 timeout.tv_nsec = now.tv_usec*1000;
6467
6468 RLOGD("Block Request, wait token is %x,",waitToken);
6469 BLOCK_LOCK();
6470 if(waitToken == wakeup_token)
6471 RLOGD("response early than return, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
6472 while(!(waitToken == wakeup_token)) {
6473 RLOGD("Wait Response, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
6474 int ret = BLOCK_WAIT(&timeout);
6475 if(ret == ETIMEDOUT){
6476 RLOGD("Wait Response timeout, wait token is %x, wakeup token is %x",waitToken, wakeup_token);
6477 goto out;
6478 }
6479 }
6480 RLOGD("Response wakeup,token is %x!",wakeup_token);
6481 wakeup_token = -1;
6482out:
6483 BLOCK_UNLOCK();
6484 return 0;
6485}
6486
lld164b022022-03-29 14:01:01 +08006487/**
6488 * @brief check at input in at_buffer
6489 * @param buf type:in at port input
6490 * @return int
6491 */
6492static int lynq_inside_at_buffer(char *buf)
6493{
6494 for(int i = 0; i < MAX_AT_CMD; i++)
6495 {
6496 if(at_buf_ext[i] == NULL)
6497 {
6498 break;
6499 }
6500 else
6501 {
llf4be54d2022-04-18 08:08:38 +00006502 if(strstr(buf, at_buf_ext[i]))
lld164b022022-03-29 14:01:01 +08006503 {
6504 return 1;
6505 }
6506 }
6507 }
6508 return 0;
6509}
6510
6511/**
6512 * @brief send input to client
6513 * @param buffer type:in buffer from at port
6514 * @param len_buf type:in strlen(buffer)
6515 * @param client type:in sockaddr client
6516 * @return int
6517 */
6518static int lynq_send_info(char *buffer, int len_buf, struct sockaddr* client)
6519{
6520 socklen_t len = sizeof(*client);
6521 int sent = sendto(sockfd,buffer,len_buf,0,client,len);
6522 if( sent < 0 )
6523 {
6524 RLOGE("lynq_send_info send fail (sent=%d, sendFD=%d, dataSize=%d)",
6525 sent,sockfd, len);
6526 return sent;
6527 }
6528 return 0;
6529}
6530
6531/**
6532 * @brief Fetch data from a one-dimensional array into a two-dimensional array
6533 *
6534 * @param cmd type:in buffer from client
6535 * @param argv type:in two-dimensional array
6536 * @param cnt type:in Two dimensional array subscript
6537 * @return int
6538 */
6539static int lynq_parse_at_cmd(char *cmd, char *argv[], int cnt)
6540{
6541 if(NULL == cmd || NULL == argv)
6542 {
6543 return -1;
6544 }
6545 if(cnt > MAX_AT_CMD)
6546 {
6547 return -1;
6548 }
6549 const char s[2] = ";";
6550 char *token;
6551 int argc = cnt;
6552 token = strtok(cmd, s);
6553 while( token != NULL ) {
6554 argv[argc++] = token;
6555 token = strtok(NULL, s);
6556 }
6557 return 0;
6558}
6559
6560/**
6561 * @brief count at cmd amount
6562 *
6563 * @param type:in buffer
6564 * @return int
6565 */
6566static int lynq_count_at(char *buffer)
6567{
6568 char *p = buffer;
6569 int count = 0;
6570 while(*p != '\0')
6571 {
6572 if(*p == ';')
6573 {
6574 count++;
6575 }
6576 *p++;
6577 }
6578 return count+1;
6579}
6580
6581/**
6582 * @brief receive registion and display on at port
6583 * @param parm type:in
6584 * @return void*
6585 */
6586void *receive_at(void *parm)
6587{
6588 RLOGE("receive_at thread start\n");
6589 struct sockaddr* cli = (struct sockaddr*)parm;
6590 socklen_t len;
6591 int recv = 0;
6592 char display[1024] = {0};
6593 /*For at extension to receive at buffer*/
llacba3662022-04-15 16:57:13 +08006594 bool flag = false;
lld164b022022-03-29 14:01:01 +08006595 int count_at_cmd = 0;
6596 len = sizeof(*cli);
6597 while(1)
6598 {
llacba3662022-04-15 16:57:13 +08006599 if(!flag)
lld164b022022-03-29 14:01:01 +08006600 {
6601 RLOGE("receive third at cmd\n");
6602 recv = recvfrom(sockfd, buffer_at, LYNQ_AT_SOCKET_BUFFER, 0, cli, &len);
6603 if(recv < 0)
6604 {
6605 RLOGE("recv fail\n");
6606 continue;
6607 }
6608 RLOGE("recvfrom from client\n");
6609 /*parse buffer for at command*/
6610 count_at_cmd = lynq_count_at(buffer_at);
6611 if(count_at_cmd > MAX_AT_CMD)
6612 {
6613 RLOGE("too many at cmd\n");
6614 continue;;
6615 }
6616 lynq_parse_at_cmd(buffer_at, at_buf_ext, 0);
llacba3662022-04-15 16:57:13 +08006617 flag = true;
lld164b022022-03-29 14:01:01 +08006618 }
6619 else
6620 {
6621 RLOGE("display output on at port\n");
6622 bzero(display, 1024);
6623 recv = recvfrom(sockfd, display, LYNQ_AT_SOCKET_BUFFER, 0, cli, &len);
6624 if(recv < 0)
6625 {
6626 RLOGE("recv fail\n");
6627 continue;
6628 }
6629 /*display on at port*/
6630 else
6631 {
6632 strcat(display, "\n");
6633 int n = write(ttyGS3_fd,display,strlen(display));
6634 if(n<0)
6635 {
6636 RLOGE("lynq resp write error");
6637 }
6638 }
6639 }
lld164b022022-03-29 14:01:01 +08006640 }
6641 return NULL;
6642}
6643
ll2f3fea22022-09-29 17:16:10 +08006644static void wait_reset_mipc_response(void)
6645{
6646 int outfd = open("/data/tp",O_RDONLY);
6647 if(outfd == -1){
6648 RLOGD("open error");
6649 return;
6650 }
6651 char rst[1024];
6652 char response[2048];
6653 int s;
6654 s = read(outfd,rst,sizeof(rst));
6655 if (s>0)
6656 {
6657 RLOGD("lei buf: %s \n", rst);
6658 /*respone ok or error*/
6659 if(rst[0] = '0')
6660 {
6661 sprintf(response,"%s%s","+LRSTMD:",rst);
6662 /*check fd can or can't write*/
6663 write(ttyGS3_fd,response,strlen(response));
6664 write(ttyGS3_fd,"\nOK\n",4);
6665 }
6666 else
6667 {
6668 sprintf(response,"%s%s","+CME ERROR:",rst);
6669 /*check fd can or can't write*/
6670 write(ttyGS3_fd,response,strlen(response));
6671 }
6672 }
6673 else
6674 {
6675 RLOGD("wait_reset_mipc_response unknow error\n");
6676 }
6677 usleep(1);
6678 close(outfd);
6679 return;
6680}
6681
llaaca09b2022-03-14 16:14:28 +08006682void startUsbLoop(void)
6683{
lld164b022022-03-29 14:01:01 +08006684 /*lei add*/
6685 //Create a network communication object
6686 struct sockaddr_in addr_serv;
6687 struct sockaddr_in addr_clie;
6688 //Creating a Socket object
6689 sockfd=socket(AF_INET,SOCK_DGRAM,0);
6690 memset(&addr_serv, 0, sizeof(addr_serv));
6691 addr_serv.sin_family =AF_INET;
6692 addr_serv.sin_port =htons(LYNQ_AT_SERVICE_PORT);
6693 addr_serv.sin_addr.s_addr=htonl(INADDR_ANY);
6694 bind(sockfd,(struct sockaddr*)&addr_serv,sizeof(addr_serv));
6695 //receive registion and display on at port
6696 pthread_t thid;
6697 if(pthread_create(&thid, NULL, receive_at, (struct sockaddr*)&addr_clie) != 0) {
6698 RLOGE("thread creation failed\n");
6699 exit(1);
6700 }
6701 RLOGE("thread creation\n");
6702 /*lei add*/
llaaca09b2022-03-14 16:14:28 +08006703 int nread=-1;
6704 int n = -1;
6705 int routeId = -1;
6706 char buffer[1024]={};
6707 char tempbuf[1024]={};
6708 char buf_parser[64] = {};
6709 int argc = 0;
6710 char *argv[MAX_ARGS];//argv[0]:at name,argv[1]:raw data,argv[2]:at type,argv[3]:paramter1,argv[4]:paramter2 ....
6711 char eBuf[1024];
lle71c13f2022-10-12 13:42:18 +08006712 if(ttyGS3_fd > 0)
6713 {
6714 close(ttyGS3_fd);
6715 RLOGE("reopen need close");
6716 }
llaaca09b2022-03-14 16:14:28 +08006717 ttyGS3_fd = open("/dev/ttyGS3",O_RDWR);
6718 if(ttyGS3_fd==-1)
6719 {
6720 RLOGE("open ttyGS3 failure!!!");
6721 printf("open ttyGS3 failure!!!\n");
6722 //printf("%s\n",strerr(errno));
6723 perror("--test--");
llf5512ed2022-09-15 19:04:43 +08006724 //kill(0, SIGKILL);
llaaca09b2022-03-14 16:14:28 +08006725 }
llf5512ed2022-09-15 19:04:43 +08006726 RLOGD("[%s]open %s successfully ttyGS3_d %d!!!\n",__FUNCTION__,ttyname(ttyGS3_fd), ttyGS3_fd);
llaaca09b2022-03-14 16:14:28 +08006727 while(1)
6728 {
6729 bzero(buffer, 1024);
6730 bzero(tempbuf, 1024);
6731 bzero(buf_parser, 64);
6732 if((nread=read(ttyGS3_fd,buffer,1024))>0)
6733 {
6734 if(nread<2)
6735 {
6736 //RLOGD("input is space!!!");
6737 continue;
6738 }
6739 buffer[nread-1] = '\0';
6740 //printf("buffer is %s\n",buffer);
6741 for(int i = 0 ; i < nread ; i++)
6742 {
6743 if(buffer[i]=='=')
6744 {
6745 break;
6746 }
6747 if(buffer[i]>='a'&&buffer[i]<='z')
6748 {
6749 buffer[i] = buffer[i]-32;
6750 }
6751 }
lld164b022022-03-29 14:01:01 +08006752 RLOGD("buffer is %s\n",buffer);
6753 /*lei add*/
6754 /*check third cmd in buffer*/
6755 if(lynq_inside_at_buffer(buffer))
llaaca09b2022-03-14 16:14:28 +08006756 {
lld164b022022-03-29 14:01:01 +08006757 lynq_send_info(buffer, nread, (struct sockaddr*)&addr_clie);
llaaca09b2022-03-14 16:14:28 +08006758 }
lld164b022022-03-29 14:01:01 +08006759 /*lei add*/
6760 else
llaaca09b2022-03-14 16:14:28 +08006761 {
lld164b022022-03-29 14:01:01 +08006762 argc = lynqParseUsbCommand(buffer,argv,tempbuf,buf_parser,MAX_ARGS);
6763 if(argc<0)
6764 {
6765 bzero(eBuf, 1024);
6766 sprintf(eBuf,"LYNQ:%s not support!!!\n",buffer);
6767 int n = write(ttyGS3_fd,eBuf,strlen(eBuf));
llaaca09b2022-03-14 16:14:28 +08006768 if(n<0)
6769 {
6770 perror("lynq resp write:");
6771 }
lld164b022022-03-29 14:01:01 +08006772 RLOGD("n = %d\n",n);
llaaca09b2022-03-14 16:14:28 +08006773 continue;
lld164b022022-03-29 14:01:01 +08006774 }
6775 usb_at_transfer_t *atCmd = lynqFindId(argv[0]);
6776 if(atCmd==NULL)
llaaca09b2022-03-14 16:14:28 +08006777 {
lld164b022022-03-29 14:01:01 +08006778 RLOGD("LYNQ send ATCMD:%s!!!",argv[1]);
llaaca09b2022-03-14 16:14:28 +08006779 lynqSendAt(argc,argv,1010);
ll2f3fea22022-09-29 17:16:10 +08006780 usleep(50*1000);
6781 if(!strcmp(buffer, "AT+LRSTMD"))
6782 {
6783 wait_reset_mipc_response();
6784 }
lld164b022022-03-29 14:01:01 +08006785 continue;
llaaca09b2022-03-14 16:14:28 +08006786 }
lld164b022022-03-29 14:01:01 +08006787 if(!((1<<atoi(argv[2])) & (atCmd->support)))
llaaca09b2022-03-14 16:14:28 +08006788 {
lld164b022022-03-29 14:01:01 +08006789 RLOGD("LYNQ %s not support!!!",atCmd->cmdName);
6790 int n = write(ttyGS3_fd,"\n+CME ERROR: 100\n",strlen("\n+CME ERROR: 100\n"));
6791 if(n<0)
llaaca09b2022-03-14 16:14:28 +08006792 {
lld164b022022-03-29 14:01:01 +08006793 perror("lynq resp write:");
llaaca09b2022-03-14 16:14:28 +08006794 }
lld164b022022-03-29 14:01:01 +08006795 continue;
llaaca09b2022-03-14 16:14:28 +08006796 }
lld164b022022-03-29 14:01:01 +08006797 routeId = routeCmd(atCmd->cmdId);
6798 //routeId = routeCmd(atcmd->cmdId);
6799 //routeId = LYNQ_GOTO_AT;
6800 switch(routeId)
llaaca09b2022-03-14 16:14:28 +08006801 {
lld164b022022-03-29 14:01:01 +08006802 case LYNQ_GOTO_AT:
llaaca09b2022-03-14 16:14:28 +08006803 {
lld164b022022-03-29 14:01:01 +08006804 lynqSendAt(argc,argv,1010);
6805 break;
llaaca09b2022-03-14 16:14:28 +08006806 }
lld164b022022-03-29 14:01:01 +08006807 case LYNQ_GOTO_TELE_REQ:
6808 {
6809 usb_cmd_t *atCmdEvn = lynqFindUsbEvent(argv[0]);
6810 if(!atCmdEvn)
6811 {
6812 RLOGD("can not find at cmd event!!!");
6813 continue;
6814 }
6815 atCmdEvn->fun(argc,argv,atCmdEvn->rilRequest,1011);
6816 break;
6817 }
6818 case LYNQ_GOTO_USER_REQ:
6819 {
6820 usb_cmd_t *atCmdEvn = lynqFindUsbEvent(argv[0]);
6821 if(!atCmdEvn)
6822 {
6823 RLOGD("can not find at cmd event!!!");
6824 continue;
6825 }
6826 atCmdEvn->ufun(argc,argv,1012);
6827 break;
6828 }
6829 case LYNQ_GOTO_LINFO_REQ:
6830 {
6831 lynqInfo(argv);
6832 break;
6833 }
6834 // case LYNQ_GOTO_PLAT_REQ:
6835 // {
6836 // lynq_deal_with_log_at(&argv[3]);
6837 // break;
6838 // }
6839 case LYNQ_GOTO_RNDIS_REQ:
6840 {
6841 lynq_get_rndis_data(buffer);
6842 break;
6843 }
6844 case LYNQ_GOTO_FACTORY:
6845 {
6846 lynq_get_factory_data(argc,argv);
6847 break;
6848 }
tao.liu68d6eeb2022-11-17 16:48:50 +08006849 case LYNQ_GOTO_FOTA:
6850 {
6851 lynq_atfota_test(argv);
6852 break;
6853 }
rita9c8cd862022-08-10 09:36:49 +08006854 /*rita add start*/
6855 case LYNQ_GOTO_TEMP:
6856 {
6857 //write(ttyGS3_fd,"\n+CME ERROR: 1\n",strlen("\n+CME ERROR: 1\n"));
6858 lynq_at_get_temp(argc, argv);
6859 break;
6860 }
lld164b022022-03-29 14:01:01 +08006861 default:
6862 break;
llaaca09b2022-03-14 16:14:28 +08006863 }
llaaca09b2022-03-14 16:14:28 +08006864 }
lld164b022022-03-29 14:01:01 +08006865
llaaca09b2022-03-14 16:14:28 +08006866 }
6867 }
6868 close(ttyGS3_fd);
6869 return;
6870}
6871
lh7b0674a2022-01-10 00:34:35 -08006872void *
6873eventLoop(void *param) {
6874 pthread_mutex_lock(&s_startupMutex);
6875 s_started = 1;
6876 pthread_cond_broadcast(&s_startupCond);
6877 pthread_mutex_unlock(&s_startupMutex);
6878 #ifdef ECALL_SUPPORT
6879 init_ecall_timer_all();
6880 #endif /**/ECALL_SUPPORT
6881 /*warren add for t800 ril service 2021/12/13 start*/
6882 //RIL_StartRevSocket();
6883 LYNQ_RIL_urcClientInit();
6884 LYNQ_RIL_RecSocket();
6885 /*warren add for t800 ril service 2021/12/13 end*/
6886 RLOGD("error in event_loop_base errno:%d", errno);
6887 // kill self to restart on error
6888 kill(0, SIGKILL);
6889
6890 return NULL;
6891}
6892
llaaca09b2022-03-14 16:14:28 +08006893
6894void *
6895eventLoop_at(void *param) {
6896 pthread_mutex_lock(&s_startupMutex);
6897 s_started = 1;
6898 pthread_cond_broadcast(&s_startupCond);
6899 pthread_mutex_unlock(&s_startupMutex);
6900 //RIL_StartRevSocket();
6901 startUsbLoop();
6902 //startUsbLoop_test();
6903 RLOGD("error in event_loop_base errno:%d", errno);
6904 // kill self to restart on error
6905 kill(0, SIGKILL);
6906
6907 return NULL;
6908}
6909
lld164b022022-03-29 14:01:01 +08006910
6911
lh7b0674a2022-01-10 00:34:35 -08006912const int RspDispFunction(int request,char* arg, RIL_SOCKET_ID socket_id)
6913{
6914 int waittoken;
6915 RequestInfo *pRI = creatRILInfoAndInit(request, RSPD, socket_id);
6916 if(pRI == NULL)
6917 return 0;
6918 waittoken = pRI->token;
6919 switch (request) {
6920 case RIL_REQUEST_GET_CURRENT_CALLS:
6921 {
6922 RLOGD("request Current list start!");
6923 Parcel p;
6924 pRI->pCI->dispatchFunction(p, pRI);
6925 waitResponse(waittoken);
6926 RLOGD("request Current list end!");
6927 }
6928 break;
6929
6930 case RIL_REQUEST_ANSWER:
6931 {
6932 RLOGD("request Answer a MT call start!");
6933 Parcel p;
6934 pRI->pCI->dispatchFunction(p, pRI);
6935 waitResponse(waittoken);
6936 RLOGD("request Answer a MT call end!");
6937 }
6938 break;
6939
6940 case RIL_REQUEST_GET_SIM_STATUS:
6941 {
6942 int ret=getIccCardStatus(1, NULL, socket_id, pRI);
6943 if(ret == 0)
6944 waitResponse(waittoken);
6945 }
6946 break;
6947
6948 case RIL_REQUEST_DATA_REGISTRATION_STATE:
6949 {
6950 int ret=getDataRegistrationState(1, NULL, socket_id,pRI);
6951 if(ret == 0)
6952 waitResponse(waittoken);
6953 }
6954 break;
6955
6956 case RIL_REQUEST_VOICE_REGISTRATION_STATE:
6957 {
6958 int ret=getVoiceRegistrationState(1, NULL, socket_id,pRI);
6959 if(ret == 0)
6960 waitResponse(waittoken);
6961 }
6962 break;
6963 case RIL_REQUEST_SMS_ACKNOWLEDGE:
6964 {
6965 char* tmp[3] = {"RIL_REQUEST_SMS_ACKNOWLEDGE", "1", "0"};
6966 acknowledgeIncomingGsmSmsWithPdu(3,tmp,socket_id,pRI);
6967 waitResponse(waittoken);
6968 RLOGD("acknowledge last Incoming Gsm Sms : RIL_REQUEST_SMS_ACKNOWLEDGE end!");
6969 }
6970 break;
6971 case RIL_REQUEST_OEM_HOOK_RAW:
6972 {
6973 if(arg != NULL)
6974 {
6975 RLOGD("request OEM HOOK RAW start!");
6976 pRI->token = pRI->token|BLOCK_MARK;
6977 int waittokenOEM = pRI->token;
6978 Parcel p;
6979
6980 size_t pos = p.dataPosition();
6981 int len = strlen(arg);
6982 p.writeInt32(len);
6983 p.write((const void*)arg,len);
6984
6985 p.setDataPosition(pos);
6986 RLOGD("emSendATCommand: %s %d\n",arg,strlen(arg));
6987 pRI->pCI->dispatchFunction(p, pRI);
6988 waitResponse(waittokenOEM);
6989 } else {
6990 if(pRI){
6991 free(pRI);
6992 }
6993 RLOGE("at command shouldn't null");
6994 }
6995 break;
6996 }
6997 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM:
6998 {
6999 char* tmp[2] = {"RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM", "no"};
7000 handleCallSetupRequestFromSim(2, tmp, socket_id,pRI);
7001 waitResponse(waittoken);
7002 RLOGD("timeout 1 minutes, response no by RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM");
7003 break;
7004 }
7005 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE:
7006 {
7007 char* tmp[2] ={"RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE", arg};
7008 RLOGD("tmp[0]=%s, tmp[1]=%s, arg=%s", tmp[0], tmp[1], arg);
7009 sendTerminalResponse(2, tmp, socket_id, pRI);
7010 waitResponse(waittoken);
7011 break;
7012 }
7013 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:
7014 {
7015 acknowledgeLastIncomingCdmaSms(1, NULL,socket_id,pRI);
7016 waitResponse(waittoken);
7017 break;
7018 }
7019 case RIL_REQUEST_RADIO_POWER:
7020 {
7021 RLOGD("response loop, RIL_REQUEST_RADIO_POWER: %s", (arg == NULL ? "nul": arg));
7022 if(arg != NULL) {
7023 char* tmp[2] = {"RIL_REQUEST_RADIO_POWER", arg};
7024 setRadioPower(2,tmp,socket_id,pRI);
7025 waitResponse(waittoken);
7026 } else {
7027 if(pRI){
7028 free(pRI);
7029 }
7030 RLOGE("response loop, RIL_REQUEST_RADIO_POWER fail");
7031 }
7032 break;
7033 }
7034 case RIL_REQUEST_ALLOW_DATA:
7035 {
7036 int default_id = get_default_sim_data();
7037 RLOGD("RspDispFunction: socket_id=%d switch_id=%d", socket_id, default_id);
7038 char* argv[2] = {"RIL_REQUEST_ALLOW_DATA","0"};
7039 if(socket_id == default_id) {
7040 utils::mtk_property_set(PROP_DEFAULT_DATA_SIM, std::to_string(socket_id + 1).c_str());
7041 argv[1] = "1";
7042 }
7043 while(!isRadioAvailable(socket_id)) {
7044 sleep(1);
7045 RLOGD("[SIM%d]RspDispFunction(RIL_REQUEST_ALLOW_DATA): wait radio available", socket_id);
7046 }
7047 setDataAllowed(2, argv, socket_id, pRI);
7048 waitResponse(waittoken);
7049 break;
7050 }
7051 case RIL_REQUEST_CDMA_FLASH:
7052 {
7053 sendCDMAFeatureCode(1, NULL, socket_id, pRI);
7054 waitResponse(waittoken);
7055 break;
7056 }
7057 default:
xja1c30b82022-01-25 16:13:48 +08007058 if(pRI) {
7059 free(pRI);
7060 pRI = NULL;
7061 }
lh7b0674a2022-01-10 00:34:35 -08007062 break;
7063 }
7064 return 0;
7065}
7066
7067void * responseLoop(void *param) {
7068 pthread_mutex_lock(&s_startupMutex);
7069 s_responseDispatch= 1;
7070 pthread_cond_broadcast(&s_startupCond);
7071 pthread_mutex_unlock(&s_startupMutex);
7072 responseDispatch();
7073 RLOGD("error in response_loop_base errno:%d", errno);
7074 // kill self to restart on error
7075 kill(0, SIGKILL);
7076
7077 return NULL;
7078}
7079
7080void ATCIRequest(int request,char* reqString, void* t,int argc,char**argv)
7081{
xja1c30b82022-01-25 16:13:48 +08007082 if(t == NULL) {
7083 RLOGE("ATCIRequest t is null");
7084 return;
7085 }
lh7b0674a2022-01-10 00:34:35 -08007086 RequestInfo *pRI = (RequestInfo *)t;
7087 int waittoken;
7088 if (request < RIL_REQUEST_VENDOR_BASE) {
7089 pRI->pCI = &(s_commands[request]);
7090 } else {
7091 pRI->pCI = find_mtk_command(request);
7092 }
ll6e73f202022-12-28 14:59:46 +08007093 /*lei modify for Some requests that are not in the ril_commands.h and mtk_ril_commands.h but in commands.h*/
7094 COMMAND *command = find_command(reqString);
xja1c30b82022-01-25 16:13:48 +08007095 if(pRI->pCI == NULL){
ll6e73f202022-12-28 14:59:46 +08007096 if(command == NULL)
7097 {
7098 RLOGE("pCI command & command not found!");
7099 if(pRI) {
7100 free(pRI);
7101 }
7102 return;
xja1c30b82022-01-25 16:13:48 +08007103 }
xja1c30b82022-01-25 16:13:48 +08007104 }
ll6e73f202022-12-28 14:59:46 +08007105 /*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 +08007106
lh7b0674a2022-01-10 00:34:35 -08007107 if(utils::is_suppport_dsss()){
7108 pRI->socket_id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
7109 }
7110
7111 if(utils::is_support_dsds() && (request != RIL_REQUEST_RADIO_POWER)){
7112 pRI->socket_id = (RIL_SOCKET_ID)get_atci_sim();
7113 }
lh7b0674a2022-01-10 00:34:35 -08007114 pRI->p_next = NULL;
7115
ll6e73f202022-12-28 14:59:46 +08007116
7117 RLOGD("function %s line %d reqString %s", __FUNCTION__, __LINE__, reqString);
lh7b0674a2022-01-10 00:34:35 -08007118 if(command == NULL) {
7119 RLOGE("ATCI request command find error!");
xja1c30b82022-01-25 16:13:48 +08007120 if(pRI) {
7121 free(pRI);
7122 }
7123 return;
lh7b0674a2022-01-10 00:34:35 -08007124 } else {
7125 RLOGE("ATCI request name is %s!",command->name);
7126 }
7127
7128 pRI->token = GenerateToken(ATCI, request);
7129 waittoken = pRI->token;
7130 if(request == RIL_REQUEST_RADIO_POWER) {
7131 speciaRequest_wait();
7132 }
7133 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
7134 //need wait Ril_onRequestComplete return.
7135 waitResponse(waittoken);
7136 return;
7137}
7138
7139void startWakupLoop(void)
7140{
7141 pthread_t WakeupReasonThread;
7142
7143 RLOGD("startWakupLoop()");
7144 pthread_mutex_lock(&s_startupMutex);
7145
7146 pthread_attr_t attr;
7147 pthread_attr_init(&attr);
7148 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7149
7150 int result = pthread_create(&WakeupReasonThread, &attr, wakeup_reason_loop, NULL);
7151 if (result != 0) {
7152 RLOGW("Failed to create wakeup reason thread: %s", strerror(result));
7153 goto done;
7154 }
7155
7156done:
7157 pthread_mutex_unlock(&s_startupMutex);
7158}
llaaca09b2022-03-14 16:14:28 +08007159/*Warren add for FAW 2021/09/23 start
7160** use ttyGS0 port
7161*/
7162int lynqSendToRil(int argc,char *argv[],int uToken)
7163{
7164 if(argc < 1)
7165 {
7166 RLOGE("lynqSendToRil error input.");
7167 return 1;
7168 }
7169 for(int i =0;i<argc;i++)
7170 {
7171 printf("argv[%d]=%s\n",i,argv[i]);
7172 }
7173 COMMAND *command = find_command(argv[0]);
7174 if(!command)
7175 {
7176 RLOGE("%s: No such command for DemoApp", argv[0]);
7177 return 1;
7178 }
7179
7180 int32_t request;
7181
7182 request = command->request;
7183
7184 RIL_SOCKET_ID id = RIL_SOCKET_1;
7185 if(utils::is_support_dsds()) {
7186 id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
7187 } else if(utils::is_suppport_dsss()) {
7188 id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
7189 }
7190
7191 if(request == -1)
7192 {
7193 (*(command->func)) (argc, argv, id, NULL);
7194 return 1;
7195 }
7196
7197 if (request < 1 || (request >= (int32_t)NUM_ELEMS(s_commands) && request < RIL_REQUEST_VENDOR_BASE)) {
7198 RLOGW("unsupported request code %d token %d", request);
7199 // FIXME this should perhaps return a response
7200 return 1;
7201 }
7202
7203 RLOGD("REQUEST: %s ParamterNum:%d", requestToString(request), argc);
7204
7205
7206 RequestInfo *pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
7207 pRI->lynqEvent = 1;
7208 //Radio on/off only allow one thread operate.
7209 if(request == RIL_REQUEST_RADIO_POWER)
7210 {
7211 speciaRequest_wait();
7212 }
7213 memset(Time_buf,0,sizeof(Time_buf));
7214 GetTimeString(Time_buf);
7215 //FUNCTION_CALLED(Time_buf,requestToString(request));
7216 int waittoken = pRI->token;
7217 (*(command->func)) (argc, argv, pRI->socket_id, pRI);
7218 FUNCTION_CALLED(Time_buf,requestToString(request));
7219 waitResponse(waittoken);
7220 memset(Time_buf,0,sizeof(Time_buf));
7221 GetTimeString(Time_buf);
7222 FUNCTION_RETURN(Time_buf,requestToString(request));
7223 return 0;
7224}
7225
7226int sendRespToUsb(char *cmd)
7227{
7228 return 0;
7229}
7230int sendUrcToUsb(char *cmd)
7231{
7232 return 0;
7233}
7234/*Warren add for FAW 2021/09/23 end*/
lh7b0674a2022-01-10 00:34:35 -08007235
7236void startPMLoop(void)
7237{
7238 pthread_t atciSocketThread;
7239
7240 RLOGD("startPMLoop()");
7241 pthread_mutex_lock(&s_startupMutex);
7242
7243 pthread_attr_t attr;
7244 pthread_attr_init(&attr);
7245 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7246
7247 int result = pthread_create(&atciSocketThread, &attr, StartPMSocket, NULL);
7248 if (result != 0) {
7249 RLOGW("Failed to create PM thread: %s", strerror(result));
7250 goto done;
7251 }
7252
7253done:
7254 pthread_mutex_unlock(&s_startupMutex);
7255}
7256
7257void startGdbusLoop(void)
7258{
7259 pthread_t atciSocketThread;
7260
7261 RLOGD("startGdbusLoop()");
7262 pthread_mutex_lock(&s_startupMutex);
7263
7264 pthread_attr_t attr;
7265 pthread_attr_init(&attr);
7266 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7267
7268 int result = pthread_create(&atciSocketThread, &attr, init_data_gdbus_cb, NULL);
7269 if (result != 0) {
7270 RLOGW("Failed to create gdbus thread: %s", strerror(result));
7271 goto done;
7272 }
7273
7274done:
7275 pthread_mutex_unlock(&s_startupMutex);
7276}
7277
7278void startATCILoop(void)
7279{
7280 pthread_t atciSocketThread;
7281
7282 RLOGD("startATCILoop()");
7283 pthread_mutex_lock(&s_startupMutex);
7284
7285 pthread_attr_t attr;
7286 pthread_attr_init(&attr);
7287 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7288
7289 int result = pthread_create(&atciSocketThread, &attr, StartATCISocket, NULL);
7290 if (result != 0) {
7291 RLOGW("Failed to create ATCI thread: %s", strerror(result));
7292 goto done;
7293 }
7294
7295done:
7296 pthread_mutex_unlock(&s_startupMutex);
7297}
7298
7299void RIL_startEventLoop(void)
7300{
7301 RLOGD("RIL_startEventLoop()");
lhf6eea122022-01-20 19:32:14 -08007302 lynq_init_sms_manager();
lh7b0674a2022-01-10 00:34:35 -08007303 /* spin up eventLoop thread and wait for it to get started */
7304 s_started = 0;
7305 pthread_mutex_lock(&s_startupMutex);
7306
7307 pthread_attr_t attr;
7308 pthread_attr_init(&attr);
7309 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
7310
7311 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
7312 if (result != 0) {
7313 RLOGW("Failed to create dispatch thread: %s", strerror(result));
7314 goto done;
7315 }
llaaca09b2022-03-14 16:14:28 +08007316
7317 while (s_started == 0) {
7318 pthread_cond_wait(&s_startupCond, &s_startupMutex);
7319 }
Hong_Liu2b7b17c2022-12-14 03:03:56 -08007320 //warren delete,beacuse of update at fwk.
7321 /*mobiletek add*
llaaca09b2022-03-14 16:14:28 +08007322 s_started = 0;
7323 result = pthread_create(&s_tid_dispatch, &attr, eventLoop_at, NULL);
7324 if (result != 0) {
7325 RLOGW("Failed to create dispatch thread: %s", strerror(result));
7326 goto done;
7327 }
lh7b0674a2022-01-10 00:34:35 -08007328
7329 while (s_started == 0) {
7330 pthread_cond_wait(&s_startupCond, &s_startupMutex);
7331 }
Hong_Liu2b7b17c2022-12-14 03:03:56 -08007332 *mobiletek add*/
lh7b0674a2022-01-10 00:34:35 -08007333 result = pthread_create(&s_tid_dispatch, &attr, responseLoop, NULL);
7334 if (result != 0) {
7335 RLOGW("Failed to create response dispatch thread: %s", strerror(result));
7336 goto done;
7337 }
7338
7339 while (s_responseDispatch == 0) {
7340 pthread_cond_wait(&s_startupCond, &s_startupMutex);
7341 }
7342done:
7343 pthread_mutex_unlock(&s_startupMutex);
7344}
7345
7346void printInputArgs(int argc, char** argv)
7347{
7348 int i=0;
7349
7350 for(i=0; i<argc; i++)
7351 {
7352 RLOGD("%s", argv[i]);
7353 }
7354}
7355
7356void initRequestInfo(RequestInfo *pRI, int request, int mode, RIL_SOCKET_ID soc_id)
7357{
7358 pRI->token = GenerateToken(mode, request);
7359 if (request < RIL_REQUEST_VENDOR_BASE) {
7360 pRI->pCI = &(s_commands[request]);
7361 } else {
7362 pRI->pCI = find_mtk_command(request);
7363 }
7364 pRI->socket_id = soc_id;
7365
7366 pRI->p_next = NULL;
7367}
7368
7369void getVoiceAndDataRegistrationState(RIL_SOCKET_ID soc_id)
7370{
7371 ARspRequest(RIL_REQUEST_DATA_REGISTRATION_STATE,soc_id);
7372 ARspRequest(RIL_REQUEST_VOICE_REGISTRATION_STATE,soc_id);
7373}
7374
7375void requestAnswer(RIL_SOCKET_ID soc_id)
7376{
7377 ARspRequest(RIL_REQUEST_ANSWER,soc_id);
7378 return;
7379}
7380void requestSMSACKNOWLEDGE(RIL_SOCKET_ID soc_id)
7381{
7382 ARspRequest(RIL_REQUEST_SMS_ACKNOWLEDGE,soc_id);
7383 return;
7384}
7385
7386#if EM_MODE_SUPPORT
7387void registerForNetworkInfo(netwokInfoNotify cb)
7388{
7389 networkCb = cb;
7390 return ;
7391}
7392void unregisterNetwork()
7393{
7394 networkCb = NULL;
7395 //AT+EINFO= flag & 0xFFFFFFF7
7396}
7397void registerForATcmdResponse(atCmdResponse cb)
7398{
7399 atResponseCb = cb;
7400 return ;
7401}
7402
7403void unregisterATcmd()
7404{
7405 atResponseCb = NULL;
7406}
7407
7408#endif
7409int emResultNotify(const char *str)
7410{
7411 RLOGD("emResultNotify %s",str);
7412 int len_s = sendto(server_socket_fd,str,strlen(str),0,(struct sockaddr *)&client_addr,sizeof(client_addr));
7413
7414 sendto(server_socket_fd,"stopemdone",strlen("stopemdone"),0,(struct sockaddr *)&client_addr,sizeof(client_addr));
7415 return len_s;
7416}
7417
7418void processUnsolicited (Parcel &p, int type)
7419{
xja1c30b82022-01-25 16:13:48 +08007420 int32_t response = -1;
lh7b0674a2022-01-10 00:34:35 -08007421 p.readInt32(&response);
7422 switch(response){
7423 case RIL_UNSOL_MAL_AT_INFO:
7424 {
7425#if EM_MODE_SUPPORT
7426 char *stringresponse = strdupReadString(p);
7427 if(strstr(stringresponse,"+ENWINFO") != NULL){
7428 RLOGD("processUnsolicited ENWINFO \n");
7429 char *start = strstr(stringresponse,":");
7430 char *end = strstr(stringresponse,",");
7431 if(start == NULL ||end == NULL ){
7432 break;
7433 }
7434 if(networkCb){
7435 //parse type & data, notify to registrants
7436 char ctype[5] = {0};
7437 int type = 0;
7438 memcpy(ctype,start+1, end - start -1);
7439 type = atoi(ctype);
7440 char *data = end+1;
7441 RLOGD("ctype %s type %d data %s\n",ctype,type,data);
7442 //parse response
7443 networkCb(type,data);
7444 }
7445 }
7446 if(stringresponse){
7447 free(stringresponse);
7448 }
7449#endif
7450 break;
7451 }
7452 default:
7453 break;
7454 }
7455}
7456void processSolicited(Parcel &p, int type) {
7457 int32_t serial, error;
xja1c30b82022-01-25 16:13:48 +08007458 serial = 0;
lh7b0674a2022-01-10 00:34:35 -08007459 p.readInt32(&serial); //telematic it is the same as ril request num
7460 p.readInt32(&error);
7461 RLOGD("processSolicited serial %d\n", serial);
7462 switch (serial) {
7463 case RIL_REQUEST_OEM_HOOK_RAW: {
7464 if (error != RIL_E_SUCCESS) {
7465 RLOGW("RIL_E_fail");
7466 if (atResponseCb) {
7467 atResponseCb(NULL, 0);
7468 }
7469 if(m_RfDesense){
7470 m_RfDesense->handle_request("", 0, 0, (RIL_Errno)error);
7471 }
7472 return;
7473 }
7474 int len;
7475 status_t status = 0;
7476 status = p.readInt32(&len);
7477 if (status != 0) {
7478 RLOGW("read int32 fail");
7479 return;
7480 }
7481 char *stringresponse = (char*) calloc(len, sizeof(char));
7482 status = p.read((void*) stringresponse, len);
7483 if (status != 0) {
7484 if (stringresponse) {
7485 free(stringresponse);
7486 }
7487 RLOGW("read int32 fail");
7488 return;
7489 }
7490 parseAtCmd(stringresponse);
7491 RLOGD("processSolicited AT string %s %d\n", stringresponse, len);
7492#if EM_MODE_SUPPORT
7493 if (atResponseCb) {
7494 if (stringresponse) {
7495
7496 atResponseCb(stringresponse, len);
7497 } else {
7498 atResponseCb(stringresponse, 0);
7499 }
7500 }
7501 if(m_RfDesense){
7502 if(stringresponse && (!isFinalResponseErrorEx(stringresponse))) {
7503 m_RfDesense->handle_request(stringresponse,len,0, (RIL_Errno)RIL_E_SUCCESS);
7504 } else {
7505 RLOGD("isFinalResponseErrorEx error or response is null");
7506 m_RfDesense->handle_request(stringresponse, 0, 0, (RIL_Errno)RIL_E_GENERIC_FAILURE);
7507 }
7508 }
7509#endif
7510 if (stringresponse) {
7511 free(stringresponse);
7512 }
7513 break;
7514 }
7515 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: {
7516#if EM_MODE_SUPPORT
7517 if (atResponseCb) {
7518 if (error != RIL_E_SUCCESS) {
7519 atResponseCb(NULL, 0);
7520 } else {
7521 atResponseCb("OK", 2);
7522 }
7523 }
7524#endif
7525 break;
7526 }
7527 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: {
7528#if EM_MODE_SUPPORT
7529 int nums = 0;
7530 int prefertype = 0;
7531 p.readInt32(&nums);
7532 if (nums != 1) {
7533 RLOGD("getpreferrednetworktype nums > 1");
7534 }
7535 p.readInt32(&prefertype);
7536 char prefertype_str[3] = { 0 };
7537 sprintf(prefertype_str, "%d", prefertype);
7538 if (atResponseCb) {
7539 if (error != RIL_E_SUCCESS) {
7540 atResponseCb(NULL, 0);
7541 } else {
7542 atResponseCb(prefertype_str, strlen(prefertype_str));
7543 }
7544 }
7545#endif
7546 break;
7547 }
7548 case RIL_REQUEST_GET_IMSI: {
7549 if (error != RIL_E_SUCCESS) {
7550 RLOGD("RIL_REQUEST_GET_IMSI error %d\n", error);
7551 }
7552 break;
7553 }
7554 }
7555}
7556
7557#ifdef ECALL_SUPPORT
7558static int responseEcallStatus(Parcel &p, void *response, size_t responselen) {
7559 if (response == NULL || responselen != sizeof(RIL_Ecall_Unsol_Indications)) {
7560 if (response == NULL) {
7561 RLOGE("invalid response: NULL");
7562 }
7563 else {
7564 RLOGE("responseEcallStatus: invalid response length %d expecting len: %d",
7565 sizeof(RIL_Ecall_Unsol_Indications), responselen);
7566 }
7567 return RIL_ERRNO_INVALID_RESPONSE;
7568 }
7569
7570 RIL_Ecall_Unsol_Indications *p_cur = (RIL_Ecall_Unsol_Indications *)response;
7571 p.writeInt32(p_cur->ind);
7572 p.writeInt32(p_cur->call_id);
7573
7574 startResponse;
7575 appendPrintBuf("ECall Status: %d, call_id: %d",
7576 p_cur->ind, p_cur->call_id);
7577 closeResponse;
7578
7579 return 0;
7580}
7581
7582/**
7583 * Callee expects const RIL_ECallReqMsg *
7584 * Payload is:
7585 * RIL_ECall_Category ecall_cat
7586 * RIL_ECall_Variant ecall_variant
7587 * String address
7588 * String msd_data
7589 */
7590static void dispatchFastEcall (Parcel &p, RequestInfo *pRI) {
7591 RIL_ECallReqMsg eCallReqMsg;
7592
xja1c30b82022-01-25 16:13:48 +08007593 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08007594 int size;
7595 status_t status;
7596 int digitCount;
7597 int digitLimit;
7598 uint8_t uct;
7599
7600 memset(&eCallReqMsg, 0, sizeof(eCallReqMsg));
7601
7602 status = p.readInt32(&t);
7603 eCallReqMsg.ecall_cat= (RIL_ECall_Category)t;
7604
7605 status = p.readInt32(&t);
7606 eCallReqMsg.ecall_variant = (RIL_ECall_Variant)t;
7607
7608 eCallReqMsg.address = strdupReadString(p);
7609
7610 status = p.readInt32(&t);
7611 eCallReqMsg.length = (uint8_t) t;
7612
7613 digitLimit= MIN((eCallReqMsg.length), MSD_MAX_LENGTH);
7614 eCallReqMsg.msd_data = (unsigned char *)alloca(digitLimit);
7615
7616 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
7617 status = p.read(&uct, sizeof(uint8_t));
7618 eCallReqMsg.msd_data[digitCount] = (uint8_t) uct;
7619 }
7620
7621 startRequest;
7622 appendPrintBuf("%secall_cat=%d,ecall_variant=%d, address=%s", printBuf,
7623 eCallReqMsg.ecall_cat, eCallReqMsg.ecall_variant, (char*)eCallReqMsg.address);
7624 closeRequest;
7625 printRequest(pRI->token, pRI->pCI->requestNumber);
7626
7627 if (status != NO_ERROR) {
7628 goto invalid;
7629 }
7630
7631 size = sizeof(eCallReqMsg);
7632 CALL_ONREQUEST(pRI->pCI->requestNumber, &eCallReqMsg, size, pRI, pRI->socket_id);
7633
7634#ifdef MEMSET_FREED
7635 memsetString(eCallReqMsg.address);
lhb07f4e12022-02-17 22:08:54 -08007636 memset(eCallReqMsg.msd_data, 0, digitLimit);
lh7b0674a2022-01-10 00:34:35 -08007637#endif
7638
7639 free(eCallReqMsg.address);
7640
7641#ifdef MEMSET_FREED
7642 memset(&eCallReqMsg, 0, sizeof(eCallReqMsg));
7643#endif
7644
7645 return;
7646invalid:
7647 invalidCommandBlock(pRI);
7648 return;
7649}
7650
7651/**
7652 * Callee expects const RIL_ECallSetMSD *
7653 * Payload is:
7654 * int call_id
7655 * String msd_data
7656 */
7657static void dispatchSetMsd (Parcel &p, RequestInfo *pRI) {
7658 RIL_ECallSetMSD eCallSetMsd;
7659
xja1c30b82022-01-25 16:13:48 +08007660 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08007661 int size;
7662 status_t status;
7663 int digitCount;
7664 int digitLimit;
7665 uint8_t uct;
7666
7667 memset(&eCallSetMsd, 0, sizeof(eCallSetMsd));
7668
7669 status = p.readInt32(&t);
7670 eCallSetMsd.call_id = (int)t;
7671
7672 status = p.readInt32(&t);
7673 eCallSetMsd.length = (uint8_t) t;
7674
7675 digitLimit= MIN((eCallSetMsd.length), MSD_MAX_LENGTH);
7676 eCallSetMsd.msd_data = (unsigned char *)alloca(digitLimit);
7677
7678 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
7679 status = p.read(&uct, sizeof(uint8_t));
7680 eCallSetMsd.msd_data[digitCount] = (uint8_t) uct;
7681 }
7682
7683 startRequest;
7684 appendPrintBuf("%scall_id=%d,msd_data=%s", printBuf, eCallSetMsd.call_id, (char*)eCallSetMsd.msd_data);
7685 closeRequest;
7686 printRequest(pRI->token, pRI->pCI->requestNumber);
7687
7688 if (status != NO_ERROR) {
7689 goto invalid;
7690 }
7691
7692 size = sizeof(eCallSetMsd);
7693 CALL_ONREQUEST(pRI->pCI->requestNumber, &eCallSetMsd, size, pRI, pRI->socket_id);
7694
7695#ifdef MEMSET_FREED
7696 memset(eCallSetMsd.msd_data, 0, eCallSetMsd.length);
7697#endif
7698
7699#ifdef MEMSET_FREED
7700 memset(&eCallSetMsd, 0, sizeof(eCallSetMsd));
7701#endif
7702
7703 return;
7704invalid:
7705 invalidCommandBlock(pRI);
7706 return;
7707}
7708
7709/**
7710 * Callee expects const RIL_ECallSetNum *
7711 * Payload is:
7712 * int arg_num;
7713 * int type
7714 * char* address
7715 */
7716static void dispatchEcallRecord (Parcel &p, RequestInfo *pRI) {
7717 RIL_ECallSetNum args;
xja1c30b82022-01-25 16:13:48 +08007718 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08007719 status_t status;
7720
7721 RLOGD("dispatchSmsWrite");
7722 memset (&args, 0, sizeof(args));
7723
7724 status = p.readInt32(&t);
7725 args.arg_num = (int)t;
7726
7727 status = p.readInt32(&t);
7728 args.type = (int)t;
7729
7730 args.address = strdupReadString(p);
7731
7732 if (status != NO_ERROR || args.address == NULL) {
7733 goto invalid;
7734 }
7735
7736 startRequest;
7737 appendPrintBuf("%s%d,%s,%d", printBuf, args.type, args.address,args.arg_num);
7738 closeRequest;
7739 printRequest(pRI->token, pRI->pCI->requestNumber);
7740
7741 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
7742
7743#ifdef MEMSET_FREED
7744 memsetString (args.address);
7745#endif
7746
7747 free (args.address);
7748#ifdef MEMSET_FREED
7749 memset(&args, 0, sizeof(args));
7750#endif
7751 return;
7752invalid:
7753 invalidCommandBlock(pRI);
7754 return;
7755}
7756#endif /*ECALL_SUPPORT*/
7757
7758#ifdef KEEP_ALIVE
7759static void dispatchStartKeepalivePro(Parcel &p, RequestInfo *pRI){
7760 RIL_RequestKeepalive_Pro kp;
xja1c30b82022-01-25 16:13:48 +08007761 int32_t t = -1;
lh7b0674a2022-01-10 00:34:35 -08007762 status_t status;
7763 std::vector<uint8_t> sadr;
7764 std::vector<uint8_t> dadr;
7765
7766 memset (&kp, 0, sizeof(RIL_RequestKeepalive_Pro));
7767
7768 status = p.readInt32(&t);
7769 kp.type = (RIL_PacketType)t;
7770 if (status != NO_ERROR) {
7771 goto invalid;
7772 }
7773
7774
7775 status = p.readByteVector(&sadr);
7776 if (status != NO_ERROR) {
7777 goto invalid;
7778 } else {
7779 for(int i = 0; i < sadr.size(); i++) {
7780 kp.sourceAddress[i] = sadr[i];
7781 }
7782 }
7783
7784 status = p.readInt32(&t);
7785 kp.sourcePort= (int)t;
7786 if (status != NO_ERROR) {
7787 goto invalid;
7788 }
7789
7790 status = p.readByteVector(&dadr);
7791 if (status != NO_ERROR) {
7792 goto invalid;
7793 } else {
7794 for(int i = 0; i < dadr.size(); i++) {
7795 kp.destinationAddress[i] = dadr[i];
7796 }
7797 }
7798
7799 status = p.readInt32(&t);
7800 kp.destinationPort= (int)t;
7801 if (status != NO_ERROR) {
7802 goto invalid;
7803 }
7804
7805 status = p.readInt32(&t);
7806 kp.netif_id = (int)t;
7807 if (status != NO_ERROR) {
7808 goto invalid;
7809 }
7810
7811 status = p.readInt32(&t);
7812 kp.keepIdleTime = (int)t;
7813 if (status != NO_ERROR) {
7814 goto invalid;
7815 }
7816
7817 status = p.readInt32(&t);
7818 kp.keepIntervalTime = (int)t;
7819 if (status != NO_ERROR) {
7820 goto invalid;
7821 }
7822
7823 status = p.readInt32(&t);
7824 kp.retryCount = (int)t;
7825 if (status != NO_ERROR) {
7826 goto invalid;
7827 }
7828 startRequest;
7829 appendPrintBuf("%s [type:%d, sourceAddress:",printBuf, kp.type);
7830
7831 for(auto v: sadr) {
7832 appendPrintBuf("%s %d",printBuf,v);
7833 }
7834 appendPrintBuf("%s, sourcePort:%d, destinationAddress:",printBuf, kp.sourcePort);
7835
7836 for(auto v: dadr) {
7837 appendPrintBuf("%s %d",printBuf,v);
7838 }
7839 appendPrintBuf("%s, destinationPort:%d, netif_id:%d, keepIdleTime:%d,, keepIntervalTime:%d, retryCount:%d",
7840 printBuf, kp.destinationPort, kp.netif_id, kp.keepIdleTime, kp.keepIntervalTime, kp.retryCount);
7841
7842 closeRequest;
7843 printRequest(pRI->token, pRI->pCI->requestNumber);
7844
7845 CALL_ONREQUEST(pRI->pCI->requestNumber,&kp,sizeof(RIL_RequestKeepalive_Pro),pRI, pRI->socket_id);
7846 return;
7847invalid:
7848 invalidCommandBlock(pRI);
7849 return;
7850}
7851#endif /* KEEP_ALIVE*/
7852} /* namespace android */
7853
7854#if 0
7855void rilEventAddWakeup_helper(struct ril_event *ev) {
7856 android::rilEventAddWakeup(ev);
7857}
7858
7859void listenCallback_helper(int fd, short flags, void *param) {
7860 android::listenCallback(fd, flags, param);
7861}
7862
7863int blockingWrite_helper(int fd, void *buffer, size_t len) {
7864 return android::blockingWrite(fd, buffer, len);
7865}
7866#endif