1 /* //device/libs/telephony/ril.cpp
3 ** Copyright 2006, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
18 #define LOG_TAG "RILC"
20 #include <hardware_legacy/power.h>
21 #include <telephony/ril.h>
22 #include <telephony/ril_cdma_sms.h>
23 #include <cutils/sockets.h>
24 #include <cutils/jstring.h>
25 #include <telephony/record_stream.h>
26 #include <utils/Log.h>
27 #include <utils/SystemClock.h>
29 #include <binder/Parcel.h>
30 #include <cutils/jstring.h>
31 #include <sys/types.h>
32 #include <sys/limits.h>
33 #include <sys/system_properties.h>
47 #include <netinet/in.h>
48 #include <cutils/properties.h>
49 #include <RilSapSocket.h>
52 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
55 RIL_onRequestAck(RIL_Token t);
58 #define PHONE_PROCESS "radio"
59 #define BLUETOOTH_PROCESS "bluetooth"
61 #define SOCKET_NAME_RIL "rild"
62 #define SOCKET2_NAME_RIL "rild2"
63 #define SOCKET3_NAME_RIL "rild3"
64 #define SOCKET4_NAME_RIL "rild4"
66 #define SOCKET_NAME_RIL_DEBUG "rild-debug"
68 #define ANDROID_WAKE_LOCK_NAME "radio-interface"
70 #define ANDROID_WAKE_LOCK_SECS 0
71 #define ANDROID_WAKE_LOCK_USECS 200000
73 #define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
75 // match with constant in RIL.java
76 #define MAX_COMMAND_BYTES (8 * 1024)
78 // Basically: memset buffers that the client library
79 // shouldn't be using anymore in an attempt to find
80 // memory usage issues sooner.
81 #define MEMSET_FREED 1
83 #define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
85 #define MIN(a,b) ((a)<(b) ? (a) : (b))
87 /* Constants for response types */
88 #define RESPONSE_SOLICITED 0
89 #define RESPONSE_UNSOLICITED 1
90 #define RESPONSE_SOLICITED_ACK 2
91 #define RESPONSE_SOLICITED_ACK_EXP 3
92 #define RESPONSE_UNSOLICITED_ACK_EXP 4
94 /* Negative values for private RIL errno's */
95 #define RIL_ERRNO_INVALID_RESPONSE -1
96 #define RIL_ERRNO_NO_MEMORY -12
98 // request, response, and unsolicited msg print macro
99 #define PRINTBUF_SIZE 8096
101 // Enable verbose logging
108 #define startRequest sprintf(printBuf, "(")
109 #define closeRequest sprintf(printBuf, "%s)", printBuf)
110 #define printRequest(token, req) \
111 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
113 #define startResponse sprintf(printBuf, "%s {", printBuf)
114 #define closeResponse sprintf(printBuf, "%s}", printBuf)
115 #define printResponse RLOGD("%s", printBuf)
117 #define clearPrintBuf printBuf[0] = 0
118 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
119 #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x)
123 #define printRequest(token, req)
124 #define startResponse
125 #define closeResponse
126 #define printResponse
127 #define clearPrintBuf
128 #define removeLastChar
129 #define appendPrintBuf(x...)
132 enum WakeType {DONT_WAKE, WAKE_PARTIAL};
136 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
137 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
142 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
146 typedef struct RequestInfo {
147 int32_t token; //this is not RIL_Token
149 struct RequestInfo *p_next;
151 char local; // responses to local commands do not go back to command process
152 RIL_SOCKET_ID socket_id;
153 int wasAckSent; // Indicates whether an ack was sent earlier
156 typedef struct UserCallbackInfo {
157 RIL_TimedCallback p_callback;
159 struct ril_event event;
160 struct UserCallbackInfo *p_next;
163 extern "C" const char * requestToString(int request);
164 extern "C" const char * failCauseToString(RIL_Errno);
165 extern "C" const char * callStateToString(RIL_CallState);
166 extern "C" const char * radioStateToString(RIL_RadioState);
167 extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
170 char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
171 /*******************************************************************/
173 RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
174 static int s_registerCalled = 0;
176 static pthread_t s_tid_dispatch;
177 static pthread_t s_tid_reader;
178 static int s_started = 0;
180 static int s_fdDebug = -1;
181 static int s_fdDebug_socket2 = -1;
183 static int s_fdWakeupRead;
184 static int s_fdWakeupWrite;
186 int s_wakelock_count = 0;
188 static struct ril_event s_commands_event;
189 static struct ril_event s_wakeupfd_event;
190 static struct ril_event s_listen_event;
191 static SocketListenParam s_ril_param_socket;
193 static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
194 static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
195 static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
196 static RequestInfo *s_pendingRequests = NULL;
199 static struct ril_event s_commands_event_socket2;
200 static struct ril_event s_listen_event_socket2;
201 static SocketListenParam s_ril_param_socket2;
203 static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
204 static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
205 static RequestInfo *s_pendingRequests_socket2 = NULL;
209 static struct ril_event s_commands_event_socket3;
210 static struct ril_event s_listen_event_socket3;
211 static SocketListenParam s_ril_param_socket3;
213 static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
214 static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
215 static RequestInfo *s_pendingRequests_socket3 = NULL;
219 static struct ril_event s_commands_event_socket4;
220 static struct ril_event s_listen_event_socket4;
221 static SocketListenParam s_ril_param_socket4;
223 static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
224 static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
225 static RequestInfo *s_pendingRequests_socket4 = NULL;
228 static struct ril_event s_wake_timeout_event;
229 static struct ril_event s_debug_event;
232 static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
235 static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
236 static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
238 static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
239 static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
241 static RequestInfo *s_toDispatchHead = NULL;
242 static RequestInfo *s_toDispatchTail = NULL;
244 static UserCallbackInfo *s_last_wake_timeout_info = NULL;
246 static void *s_lastNITZTimeData = NULL;
247 static size_t s_lastNITZTimeDataSize;
250 static char printBuf[PRINTBUF_SIZE];
253 /*******************************************************************/
254 static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
256 static void dispatchVoid (Parcel& p, RequestInfo *pRI);
257 static void dispatchString (Parcel& p, RequestInfo *pRI);
258 static void dispatchStrings (Parcel& p, RequestInfo *pRI);
259 static void dispatchInts (Parcel& p, RequestInfo *pRI);
260 static void dispatchDial (Parcel& p, RequestInfo *pRI);
261 static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
262 static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
263 static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
264 static void dispatchRaw(Parcel& p, RequestInfo *pRI);
265 static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
266 static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
267 static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
268 static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
269 static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
271 static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
272 static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
273 static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
274 static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
275 static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
276 static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
277 static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
278 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
279 static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
280 static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
281 static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
282 static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
283 static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
284 static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
285 static int responseInts(Parcel &p, void *response, size_t responselen);
286 static int responseFailCause(Parcel &p, void *response, size_t responselen);
287 static int responseStrings(Parcel &p, void *response, size_t responselen);
288 static int responseString(Parcel &p, void *response, size_t responselen);
289 static int responseVoid(Parcel &p, void *response, size_t responselen);
290 static int responseCallList(Parcel &p, void *response, size_t responselen);
291 static int responseSMS(Parcel &p, void *response, size_t responselen);
292 static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
293 static int responseCallForwards(Parcel &p, void *response, size_t responselen);
294 static int responseDataCallList(Parcel &p, void *response, size_t responselen);
295 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
296 static int responseRaw(Parcel &p, void *response, size_t responselen);
297 static int responseSsn(Parcel &p, void *response, size_t responselen);
298 static int responseSimStatus(Parcel &p, void *response, size_t responselen);
299 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
300 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
301 static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
302 static int responseCellList(Parcel &p, void *response, size_t responselen);
303 static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
304 static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
305 static int responseCallRing(Parcel &p, void *response, size_t responselen);
306 static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
307 static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
308 static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
309 static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
310 static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
311 static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
312 static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
313 static int responseSSData(Parcel &p, void *response, size_t responselen);
314 static int responseLceStatus(Parcel &p, void *response, size_t responselen);
315 static int responseLceData(Parcel &p, void *response, size_t responselen);
316 static int responseActivityData(Parcel &p, void *response, size_t responselen);
318 static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
319 static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
320 static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
321 static void grabPartialWakeLock();
322 static void releaseWakeLock();
323 static void wakeTimeoutCallback(void *);
325 static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
327 static bool isDebuggable();
330 #if defined(ANDROID_MULTI_SIM)
331 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
332 size_t datalen, RIL_SOCKET_ID socket_id);
334 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
339 #if defined(ANDROID_MULTI_SIM)
340 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
341 #define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
342 #define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
344 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
345 #define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
346 #define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
349 static UserCallbackInfo * internalRequestTimedCallback
350 (RIL_TimedCallback callback, void *param,
351 const struct timeval *relativeTime);
353 /** Index == requestNumber */
354 static CommandInfo s_commands[] = {
355 #include "ril_commands.h"
358 static UnsolResponseInfo s_unsolResponses[] = {
359 #include "ril_unsol_commands.h"
362 /* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
363 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
364 radio state message and store it. Every time there is a change in Radio State
365 check to see if voice radio tech changes and notify telephony
367 int voiceRadioTech = -1;
369 /* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
370 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
371 source from radio state and store it. Every time there is a change in Radio State
372 check to see if subscription source changed and notify telephony
374 int cdmaSubscriptionSource = -1;
376 /* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
377 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
378 check to see if SIM/RUIM status changed and notify telephony
380 int simRuimStatus = -1;
382 static char * RIL_getRilSocketName() {
387 void RIL_setRilSocketName(const char * s) {
388 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
392 strdupReadString(Parcel &p) {
396 s16 = p.readString16Inplace(&stringlen);
398 return strndup16to8(s16, stringlen);
402 readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
406 s16 = p.readString16Inplace(&s16Len);
410 size_t strLen = strnlen16to8(s16, s16Len);
411 if ((strLen + 1) > maxLen) {
414 if (strncpy16to8(str, s16, strLen) == NULL) {
421 static void writeStringToParcel(Parcel &p, const char *s) {
424 s16 = strdup8to16(s, &s16_len);
425 p.writeString16(s16, s16_len);
431 memsetString (char *s) {
433 memset (s, 0, strlen(s));
437 void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
438 const size_t* objects, size_t objectsSize,
440 // do nothing -- the data reference lives longer than the Parcel object
444 * To be called from dispatch thread
445 * Issue a single local request, ensuring that the response
446 * is not sent back up to the command process
449 issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
452 /* Hook for current context */
453 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
454 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
455 /* pendingRequestsHook refer to &s_pendingRequests */
456 RequestInfo** pendingRequestsHook = &s_pendingRequests;
459 if (socket_id == RIL_SOCKET_2) {
460 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
461 pendingRequestsHook = &s_pendingRequests_socket2;
465 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
467 RLOGE("Memory allocation failed for request %s", requestToString(request));
472 pRI->token = 0xffffffff; // token is not used in this context
473 pRI->pCI = &(s_commands[request]);
474 pRI->socket_id = socket_id;
476 ret = pthread_mutex_lock(pendingRequestsMutexHook);
479 pRI->p_next = *pendingRequestsHook;
480 *pendingRequestsHook = pRI;
482 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
485 RLOGD("C[locl]> %s", requestToString(request));
487 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
493 processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
500 /* Hook for current context */
501 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
502 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
503 /* pendingRequestsHook refer to &s_pendingRequests */
504 RequestInfo** pendingRequestsHook = &s_pendingRequests;
506 p.setData((uint8_t *) buffer, buflen);
508 // status checked at end
509 status = p.readInt32(&request);
510 status = p.readInt32 (&token);
513 if (socket_id == RIL_SOCKET_2) {
514 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
515 pendingRequestsHook = &s_pendingRequests_socket2;
518 else if (socket_id == RIL_SOCKET_3) {
519 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
520 pendingRequestsHook = &s_pendingRequests_socket3;
524 else if (socket_id == RIL_SOCKET_4) {
525 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
526 pendingRequestsHook = &s_pendingRequests_socket4;
531 if (status != NO_ERROR) {
532 RLOGE("invalid request block");
536 // Received an Ack for the previous result sent to RIL.java,
537 // so release wakelock and exit
538 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
543 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
545 RLOGE("unsupported request code %d token %d", request, token);
546 // FIXME this should perhaps return a response
547 pErr.writeInt32 (RESPONSE_SOLICITED);
548 pErr.writeInt32 (token);
549 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
551 sendResponse(pErr, socket_id);
555 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
557 RLOGE("Memory allocation failed for request %s", requestToString(request));
562 pRI->pCI = &(s_commands[request]);
563 pRI->socket_id = socket_id;
565 ret = pthread_mutex_lock(pendingRequestsMutexHook);
568 pRI->p_next = *pendingRequestsHook;
569 *pendingRequestsHook = pRI;
571 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
574 /* sLastDispatchedToken = token; */
576 pRI->pCI->dispatchFunction(p, pRI);
582 invalidCommandBlock (RequestInfo *pRI) {
583 RLOGE("invalid command block for token %d request %s",
584 pRI->token, requestToString(pRI->pCI->requestNumber));
587 /** Callee expects NULL */
589 dispatchVoid (Parcel& p, RequestInfo *pRI) {
591 printRequest(pRI->token, pRI->pCI->requestNumber);
592 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
595 /** Callee expects const char * */
597 dispatchString (Parcel& p, RequestInfo *pRI) {
601 char *string8 = NULL;
603 string8 = strdupReadString(p);
606 appendPrintBuf("%s%s", printBuf, string8);
608 printRequest(pRI->token, pRI->pCI->requestNumber);
610 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
611 sizeof(char *), pRI, pRI->socket_id);
614 memsetString(string8);
620 invalidCommandBlock(pRI);
624 /** Callee expects const char ** */
626 dispatchStrings (Parcel &p, RequestInfo *pRI) {
627 int32_t countStrings;
632 status = p.readInt32 (&countStrings);
634 if (status != NO_ERROR) {
639 if (countStrings == 0) {
640 // just some non-null pointer
641 pStrings = (char **)calloc(1, sizeof(char *));
642 if (pStrings == NULL) {
643 RLOGE("Memory allocation failed for request %s",
644 requestToString(pRI->pCI->requestNumber));
650 } else if (countStrings < 0) {
654 datalen = sizeof(char *) * countStrings;
656 pStrings = (char **)calloc(countStrings, sizeof(char *));
657 if (pStrings == NULL) {
658 RLOGE("Memory allocation failed for request %s",
659 requestToString(pRI->pCI->requestNumber));
664 for (int i = 0 ; i < countStrings ; i++) {
665 pStrings[i] = strdupReadString(p);
666 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
671 printRequest(pRI->token, pRI->pCI->requestNumber);
673 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
675 if (pStrings != NULL) {
676 for (int i = 0 ; i < countStrings ; i++) {
678 memsetString (pStrings[i]);
684 memset(pStrings, 0, datalen);
691 invalidCommandBlock(pRI);
695 /** Callee expects const int * */
697 dispatchInts (Parcel &p, RequestInfo *pRI) {
703 status = p.readInt32 (&count);
705 if (status != NO_ERROR || count <= 0) {
709 datalen = sizeof(int) * count;
710 pInts = (int *)calloc(count, sizeof(int));
712 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
717 for (int i = 0 ; i < count ; i++) {
720 status = p.readInt32(&t);
722 appendPrintBuf("%s%d,", printBuf, t);
724 if (status != NO_ERROR) {
731 printRequest(pRI->token, pRI->pCI->requestNumber);
733 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
734 datalen, pRI, pRI->socket_id);
737 memset(pInts, 0, datalen);
742 invalidCommandBlock(pRI);
748 * Callee expects const RIL_SMS_WriteArgs *
754 dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
755 RIL_SMS_WriteArgs args;
759 RLOGD("dispatchSmsWrite");
760 memset (&args, 0, sizeof(args));
762 status = p.readInt32(&t);
763 args.status = (int)t;
765 args.pdu = strdupReadString(p);
767 if (status != NO_ERROR || args.pdu == NULL) {
771 args.smsc = strdupReadString(p);
774 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
775 (char*)args.pdu, (char*)args.smsc);
777 printRequest(pRI->token, pRI->pCI->requestNumber);
779 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
782 memsetString (args.pdu);
788 memset(&args, 0, sizeof(args));
793 invalidCommandBlock(pRI);
798 * Callee expects const RIL_Dial *
804 dispatchDial (Parcel &p, RequestInfo *pRI) {
806 RIL_UUS_Info uusInfo;
812 RLOGD("dispatchDial");
813 memset (&dial, 0, sizeof(dial));
815 dial.address = strdupReadString(p);
817 status = p.readInt32(&t);
820 if (status != NO_ERROR || dial.address == NULL) {
824 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
826 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
828 status = p.readInt32(&uusPresent);
830 if (status != NO_ERROR) {
834 if (uusPresent == 0) {
839 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
841 status = p.readInt32(&t);
842 uusInfo.uusType = (RIL_UUS_Type) t;
844 status = p.readInt32(&t);
845 uusInfo.uusDcs = (RIL_UUS_DCS) t;
847 status = p.readInt32(&len);
848 if (status != NO_ERROR) {
852 // The java code writes -1 for null arrays
853 if (((int) len) == -1) {
854 uusInfo.uusData = NULL;
857 uusInfo.uusData = (char*) p.readInplace(len);
860 uusInfo.uusLength = len;
861 dial.uusInfo = &uusInfo;
863 sizeOfDial = sizeof(dial);
867 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
869 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
870 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
871 dial.uusInfo->uusLength);
874 printRequest(pRI->token, pRI->pCI->requestNumber);
876 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
879 memsetString (dial.address);
885 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
886 memset(&dial, 0, sizeof(dial));
891 invalidCommandBlock(pRI);
896 * Callee expects const RIL_SIM_IO *
907 dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
918 RLOGD("dispatchSIM_IO");
920 memset (&simIO, 0, sizeof(simIO));
922 // note we only check status at the end
924 status = p.readInt32(&t);
925 simIO.v6.command = (int)t;
927 status = p.readInt32(&t);
928 simIO.v6.fileid = (int)t;
930 simIO.v6.path = strdupReadString(p);
932 status = p.readInt32(&t);
933 simIO.v6.p1 = (int)t;
935 status = p.readInt32(&t);
936 simIO.v6.p2 = (int)t;
938 status = p.readInt32(&t);
939 simIO.v6.p3 = (int)t;
941 simIO.v6.data = strdupReadString(p);
942 simIO.v6.pin2 = strdupReadString(p);
943 simIO.v6.aidPtr = strdupReadString(p);
946 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
947 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
948 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
949 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
951 printRequest(pRI->token, pRI->pCI->requestNumber);
953 if (status != NO_ERROR) {
957 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
958 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
961 memsetString (simIO.v6.path);
962 memsetString (simIO.v6.data);
963 memsetString (simIO.v6.pin2);
964 memsetString (simIO.v6.aidPtr);
967 free (simIO.v6.path);
968 free (simIO.v6.data);
969 free (simIO.v6.pin2);
970 free (simIO.v6.aidPtr);
973 memset(&simIO, 0, sizeof(simIO));
978 invalidCommandBlock(pRI);
983 * Callee expects const RIL_SIM_APDU *
987 * int32_t instruction
992 dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
998 RLOGD("dispatchSIM_APDU");
1000 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1002 // Note we only check status at the end. Any single failure leads to
1003 // subsequent reads filing.
1004 status = p.readInt32(&t);
1005 apdu.sessionid = (int)t;
1007 status = p.readInt32(&t);
1010 status = p.readInt32(&t);
1011 apdu.instruction = (int)t;
1013 status = p.readInt32(&t);
1016 status = p.readInt32(&t);
1019 status = p.readInt32(&t);
1022 apdu.data = strdupReadString(p);
1025 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1026 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1027 apdu.p3, (char*)apdu.data);
1029 printRequest(pRI->token, pRI->pCI->requestNumber);
1031 if (status != NO_ERROR) {
1035 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1038 memsetString(apdu.data);
1043 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1048 invalidCommandBlock(pRI);
1054 * Callee expects const RIL_CallForwardInfo *
1056 * int32_t status/action
1058 * int32_t serviceCode
1060 * String number (0 length -> null)
1061 * int32_t timeSeconds
1064 dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1065 RIL_CallForwardInfo cff;
1069 RLOGD("dispatchCallForward");
1070 memset (&cff, 0, sizeof(cff));
1072 // note we only check status at the end
1074 status = p.readInt32(&t);
1075 cff.status = (int)t;
1077 status = p.readInt32(&t);
1078 cff.reason = (int)t;
1080 status = p.readInt32(&t);
1081 cff.serviceClass = (int)t;
1083 status = p.readInt32(&t);
1086 cff.number = strdupReadString(p);
1088 status = p.readInt32(&t);
1089 cff.timeSeconds = (int)t;
1091 if (status != NO_ERROR) {
1095 // special case: number 0-length fields is null
1097 if (cff.number != NULL && strlen (cff.number) == 0) {
1102 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1103 cff.status, cff.reason, cff.serviceClass, cff.toa,
1104 (char*)cff.number, cff.timeSeconds);
1106 printRequest(pRI->token, pRI->pCI->requestNumber);
1108 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
1111 memsetString(cff.number);
1117 memset(&cff, 0, sizeof(cff));
1122 invalidCommandBlock(pRI);
1128 dispatchRaw(Parcel &p, RequestInfo *pRI) {
1133 status = p.readInt32(&len);
1135 if (status != NO_ERROR) {
1139 // The java code writes -1 for null arrays
1140 if (((int)len) == -1) {
1145 data = p.readInplace(len);
1148 appendPrintBuf("%sraw_size=%d", printBuf, len);
1150 printRequest(pRI->token, pRI->pCI->requestNumber);
1152 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
1156 invalidCommandBlock(pRI);
1161 constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
1168 memset(&rcsm, 0, sizeof(rcsm));
1170 status = p.readInt32(&t);
1171 rcsm.uTeleserviceID = (int) t;
1173 status = p.read(&ut,sizeof(ut));
1174 rcsm.bIsServicePresent = (uint8_t) ut;
1176 status = p.readInt32(&t);
1177 rcsm.uServicecategory = (int) t;
1179 status = p.readInt32(&t);
1180 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1182 status = p.readInt32(&t);
1183 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1185 status = p.readInt32(&t);
1186 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1188 status = p.readInt32(&t);
1189 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1191 status = p.read(&ut,sizeof(ut));
1192 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1194 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1195 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1196 status = p.read(&ut,sizeof(ut));
1197 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1200 status = p.readInt32(&t);
1201 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1203 status = p.read(&ut,sizeof(ut));
1204 rcsm.sSubAddress.odd = (uint8_t) ut;
1206 status = p.read(&ut,sizeof(ut));
1207 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1209 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1210 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1211 status = p.read(&ut,sizeof(ut));
1212 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1215 status = p.readInt32(&t);
1216 rcsm.uBearerDataLen = (int) t;
1218 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1219 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1220 status = p.read(&ut, sizeof(ut));
1221 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1224 if (status != NO_ERROR) {
1229 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1230 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1231 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1232 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1235 printRequest(pRI->token, pRI->pCI->requestNumber);
1241 dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1242 RIL_CDMA_SMS_Message rcsm;
1244 RLOGD("dispatchCdmaSms");
1245 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1249 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
1252 memset(&rcsm, 0, sizeof(rcsm));
1258 invalidCommandBlock(pRI);
1263 dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1264 RIL_IMS_SMS_Message rism;
1265 RIL_CDMA_SMS_Message rcsm;
1267 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1269 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1272 memset(&rism, 0, sizeof(rism));
1273 rism.tech = RADIO_TECH_3GPP2;
1275 rism.messageRef = messageRef;
1276 rism.message.cdmaMessage = &rcsm;
1278 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
1279 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1280 +sizeof(rcsm),pRI, pRI->socket_id);
1283 memset(&rcsm, 0, sizeof(rcsm));
1284 memset(&rism, 0, sizeof(rism));
1290 invalidCommandBlock(pRI);
1295 dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1296 RIL_IMS_SMS_Message rism;
1297 int32_t countStrings;
1301 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1303 status = p.readInt32 (&countStrings);
1305 if (status != NO_ERROR) {
1309 memset(&rism, 0, sizeof(rism));
1310 rism.tech = RADIO_TECH_3GPP;
1312 rism.messageRef = messageRef;
1315 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1316 (int)rism.tech, (int)rism.retry, rism.messageRef);
1317 if (countStrings == 0) {
1318 // just some non-null pointer
1319 pStrings = (char **)calloc(1, sizeof(char *));
1320 if (pStrings == NULL) {
1321 RLOGE("Memory allocation failed for request %s",
1322 requestToString(pRI->pCI->requestNumber));
1328 } else if (countStrings < 0) {
1332 if (countStrings > (INT_MAX/sizeof(char *))) {
1333 RLOGE("Invalid value of countStrings: \n");
1337 datalen = sizeof(char *) * countStrings;
1339 pStrings = (char **)calloc(countStrings, sizeof(char *));
1340 if (pStrings == NULL) {
1341 RLOGE("Memory allocation failed for request %s",
1342 requestToString(pRI->pCI->requestNumber));
1347 for (int i = 0 ; i < countStrings ; i++) {
1348 pStrings[i] = strdupReadString(p);
1349 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1354 printRequest(pRI->token, pRI->pCI->requestNumber);
1356 rism.message.gsmMessage = pStrings;
1357 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
1358 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1359 +datalen, pRI, pRI->socket_id);
1361 if (pStrings != NULL) {
1362 for (int i = 0 ; i < countStrings ; i++) {
1364 memsetString (pStrings[i]);
1370 memset(pStrings, 0, datalen);
1376 memset(&rism, 0, sizeof(rism));
1380 ALOGE("dispatchImsGsmSms invalid block");
1381 invalidCommandBlock(pRI);
1386 dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1388 status_t status = p.readInt32(&t);
1389 RIL_RadioTechnologyFamily format;
1393 RLOGD("dispatchImsSms");
1394 if (status != NO_ERROR) {
1397 format = (RIL_RadioTechnologyFamily) t;
1400 status = p.read(&retry,sizeof(retry));
1401 if (status != NO_ERROR) {
1404 // read messageRef field
1405 status = p.read(&messageRef,sizeof(messageRef));
1406 if (status != NO_ERROR) {
1410 if (RADIO_TECH_3GPP == format) {
1411 dispatchImsGsmSms(p, pRI, retry, messageRef);
1412 } else if (RADIO_TECH_3GPP2 == format) {
1413 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1415 ALOGE("requestImsSendSMS invalid format value =%d", format);
1421 invalidCommandBlock(pRI);
1426 dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1427 RIL_CDMA_SMS_Ack rcsa;
1432 RLOGD("dispatchCdmaSmsAck");
1433 memset(&rcsa, 0, sizeof(rcsa));
1435 status = p.readInt32(&t);
1436 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1438 status = p.readInt32(&t);
1439 rcsa.uSMSCauseCode = (int) t;
1441 if (status != NO_ERROR) {
1446 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1447 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1450 printRequest(pRI->token, pRI->pCI->requestNumber);
1452 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
1455 memset(&rcsa, 0, sizeof(rcsa));
1461 invalidCommandBlock(pRI);
1466 dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1471 status = p.readInt32(&num);
1472 if (status != NO_ERROR) {
1477 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1478 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
1481 for (int i = 0 ; i < num ; i++ ) {
1482 gsmBciPtrs[i] = &gsmBci[i];
1484 status = p.readInt32(&t);
1485 gsmBci[i].fromServiceId = (int) t;
1487 status = p.readInt32(&t);
1488 gsmBci[i].toServiceId = (int) t;
1490 status = p.readInt32(&t);
1491 gsmBci[i].fromCodeScheme = (int) t;
1493 status = p.readInt32(&t);
1494 gsmBci[i].toCodeScheme = (int) t;
1496 status = p.readInt32(&t);
1497 gsmBci[i].selected = (uint8_t) t;
1499 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1500 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1501 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1502 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1503 gsmBci[i].selected);
1507 if (status != NO_ERROR) {
1511 CALL_ONREQUEST(pRI->pCI->requestNumber,
1513 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1514 pRI, pRI->socket_id);
1517 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1518 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
1525 invalidCommandBlock(pRI);
1530 dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1535 status = p.readInt32(&num);
1536 if (status != NO_ERROR) {
1541 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1542 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
1545 for (int i = 0 ; i < num ; i++ ) {
1546 cdmaBciPtrs[i] = &cdmaBci[i];
1548 status = p.readInt32(&t);
1549 cdmaBci[i].service_category = (int) t;
1551 status = p.readInt32(&t);
1552 cdmaBci[i].language = (int) t;
1554 status = p.readInt32(&t);
1555 cdmaBci[i].selected = (uint8_t) t;
1557 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1558 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1559 cdmaBci[i].language, cdmaBci[i].selected);
1563 if (status != NO_ERROR) {
1567 CALL_ONREQUEST(pRI->pCI->requestNumber,
1569 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1570 pRI, pRI->socket_id);
1573 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1574 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
1581 invalidCommandBlock(pRI);
1585 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1586 RIL_CDMA_SMS_WriteArgs rcsw;
1594 memset(&rcsw, 0, sizeof(rcsw));
1596 status = p.readInt32(&t);
1599 status = p.readInt32(&t);
1600 rcsw.message.uTeleserviceID = (int) t;
1602 status = p.read(&uct,sizeof(uct));
1603 rcsw.message.bIsServicePresent = (uint8_t) uct;
1605 status = p.readInt32(&t);
1606 rcsw.message.uServicecategory = (int) t;
1608 status = p.readInt32(&t);
1609 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1611 status = p.readInt32(&t);
1612 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1614 status = p.readInt32(&t);
1615 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1617 status = p.readInt32(&t);
1618 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1620 status = p.read(&uct,sizeof(uct));
1621 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1623 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1625 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1626 status = p.read(&uct,sizeof(uct));
1627 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1630 status = p.readInt32(&t);
1631 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1633 status = p.read(&uct,sizeof(uct));
1634 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1636 status = p.read(&uct,sizeof(uct));
1637 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1639 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1641 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1642 status = p.read(&uct,sizeof(uct));
1643 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1646 status = p.readInt32(&t);
1647 rcsw.message.uBearerDataLen = (int) t;
1649 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1651 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1652 status = p.read(&uct, sizeof(uct));
1653 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1656 if (status != NO_ERROR) {
1661 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1662 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1663 message.sAddress.number_mode=%d, \
1664 message.sAddress.number_type=%d, ",
1665 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1666 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1667 rcsw.message.sAddress.number_mode,
1668 rcsw.message.sAddress.number_type);
1671 printRequest(pRI->token, pRI->pCI->requestNumber);
1673 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
1676 memset(&rcsw, 0, sizeof(rcsw));
1682 invalidCommandBlock(pRI);
1687 // For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1688 // Version 4 of the RIL interface adds a new PDP type parameter to support
1689 // IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1690 // RIL, remove the parameter from the request.
1691 static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1692 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1693 const int numParamsRilV3 = 6;
1695 // The first bytes of the RIL parcel contain the request number and the
1696 // serial number - see processCommandBuffer(). Copy them over too.
1697 int pos = p.dataPosition();
1699 int numParams = p.readInt32();
1700 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1702 p2.appendFrom(&p, 0, pos);
1703 p2.writeInt32(numParamsRilV3);
1704 for(int i = 0; i < numParamsRilV3; i++) {
1705 p2.writeString16(p.readString16());
1707 p2.setDataPosition(pos);
1708 dispatchStrings(p2, pRI);
1710 p.setDataPosition(pos);
1711 dispatchStrings(p, pRI);
1715 // For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1716 // When all RILs handle this request, this function can be removed and
1717 // the request can be sent directly to the RIL using dispatchVoid.
1718 static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
1719 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
1721 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1722 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1725 // RILs that support RADIO_STATE_ON should support this request.
1726 if (RADIO_STATE_ON == state) {
1727 dispatchVoid(p, pRI);
1731 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1732 // will not support this new request either and decode Voice Radio Technology
1734 voiceRadioTech = decodeVoiceRadioTechnology(state);
1736 if (voiceRadioTech < 0)
1737 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1739 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1742 // For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1743 // When all RILs handle this request, this function can be removed and
1744 // the request can be sent directly to the RIL using dispatchVoid.
1745 static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
1746 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
1748 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1749 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1752 // RILs that support RADIO_STATE_ON should support this request.
1753 if (RADIO_STATE_ON == state) {
1754 dispatchVoid(p, pRI);
1758 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1759 // will not support this new request either and decode CDMA Subscription Source
1761 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1763 if (cdmaSubscriptionSource < 0)
1764 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1766 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1769 static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1771 RIL_InitialAttachApn pf;
1775 memset(&pf, 0, sizeof(pf));
1777 pf.apn = strdupReadString(p);
1778 pf.protocol = strdupReadString(p);
1780 status = p.readInt32(&t);
1781 pf.authtype = (int) t;
1783 pf.username = strdupReadString(p);
1784 pf.password = strdupReadString(p);
1787 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1788 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
1790 printRequest(pRI->token, pRI->pCI->requestNumber);
1792 if (status != NO_ERROR) {
1795 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1798 memsetString(pf.apn);
1799 memsetString(pf.protocol);
1800 memsetString(pf.username);
1801 memsetString(pf.password);
1810 memset(&pf, 0, sizeof(pf));
1815 invalidCommandBlock(pRI);
1819 static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1820 RIL_NV_ReadItem nvri;
1824 memset(&nvri, 0, sizeof(nvri));
1826 status = p.readInt32(&t);
1827 nvri.itemID = (RIL_NV_Item) t;
1829 if (status != NO_ERROR) {
1834 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1837 printRequest(pRI->token, pRI->pCI->requestNumber);
1839 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1842 memset(&nvri, 0, sizeof(nvri));
1848 invalidCommandBlock(pRI);
1852 static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1853 RIL_NV_WriteItem nvwi;
1857 memset(&nvwi, 0, sizeof(nvwi));
1859 status = p.readInt32(&t);
1860 nvwi.itemID = (RIL_NV_Item) t;
1862 nvwi.value = strdupReadString(p);
1864 if (status != NO_ERROR || nvwi.value == NULL) {
1869 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1873 printRequest(pRI->token, pRI->pCI->requestNumber);
1875 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1878 memsetString(nvwi.value);
1884 memset(&nvwi, 0, sizeof(nvwi));
1890 invalidCommandBlock(pRI);
1895 static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1896 RIL_SelectUiccSub uicc_sub;
1899 memset(&uicc_sub, 0, sizeof(uicc_sub));
1901 status = p.readInt32(&t);
1902 if (status != NO_ERROR) {
1905 uicc_sub.slot = (int) t;
1907 status = p.readInt32(&t);
1908 if (status != NO_ERROR) {
1911 uicc_sub.app_index = (int) t;
1913 status = p.readInt32(&t);
1914 if (status != NO_ERROR) {
1917 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1919 status = p.readInt32(&t);
1920 if (status != NO_ERROR) {
1923 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1926 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1927 uicc_sub.act_status);
1928 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1929 uicc_sub.app_index, uicc_sub.act_status);
1931 printRequest(pRI->token, pRI->pCI->requestNumber);
1933 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1936 memset(&uicc_sub, 0, sizeof(uicc_sub));
1941 invalidCommandBlock(pRI);
1945 static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1947 RIL_SimAuthentication pf;
1951 memset(&pf, 0, sizeof(pf));
1953 status = p.readInt32(&t);
1954 pf.authContext = (int) t;
1955 pf.authData = strdupReadString(p);
1956 pf.aid = strdupReadString(p);
1959 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1961 printRequest(pRI->token, pRI->pCI->requestNumber);
1963 if (status != NO_ERROR) {
1966 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1969 memsetString(pf.authData);
1970 memsetString(pf.aid);
1977 memset(&pf, 0, sizeof(pf));
1982 invalidCommandBlock(pRI);
1986 static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1991 status = p.readInt32(&num);
1992 if (status != NO_ERROR || num < 0) {
1997 RIL_DataProfileInfo *dataProfiles =
1998 (RIL_DataProfileInfo *)calloc(num, sizeof(RIL_DataProfileInfo));
1999 if (dataProfiles == NULL) {
2000 RLOGE("Memory allocation failed for request %s",
2001 requestToString(pRI->pCI->requestNumber));
2004 RIL_DataProfileInfo **dataProfilePtrs =
2005 (RIL_DataProfileInfo **)calloc(num, sizeof(RIL_DataProfileInfo *));
2006 if (dataProfilePtrs == NULL) {
2007 RLOGE("Memory allocation failed for request %s",
2008 requestToString(pRI->pCI->requestNumber));
2014 for (int i = 0 ; i < num ; i++ ) {
2015 dataProfilePtrs[i] = &dataProfiles[i];
2017 status = p.readInt32(&t);
2018 dataProfiles[i].profileId = (int) t;
2020 dataProfiles[i].apn = strdupReadString(p);
2021 dataProfiles[i].protocol = strdupReadString(p);
2022 status = p.readInt32(&t);
2023 dataProfiles[i].authType = (int) t;
2025 dataProfiles[i].user = strdupReadString(p);
2026 dataProfiles[i].password = strdupReadString(p);
2028 status = p.readInt32(&t);
2029 dataProfiles[i].type = (int) t;
2031 status = p.readInt32(&t);
2032 dataProfiles[i].maxConnsTime = (int) t;
2033 status = p.readInt32(&t);
2034 dataProfiles[i].maxConns = (int) t;
2035 status = p.readInt32(&t);
2036 dataProfiles[i].waitTime = (int) t;
2038 status = p.readInt32(&t);
2039 dataProfiles[i].enabled = (int) t;
2041 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2042 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2043 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2044 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2045 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2046 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2047 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2050 printRequest(pRI->token, pRI->pCI->requestNumber);
2052 if (status != NO_ERROR) {
2054 free(dataProfilePtrs);
2057 CALL_ONREQUEST(pRI->pCI->requestNumber,
2059 num * sizeof(RIL_DataProfileInfo *),
2060 pRI, pRI->socket_id);
2063 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2064 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2067 free(dataProfilePtrs);
2073 invalidCommandBlock(pRI);
2077 static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2078 RIL_RadioCapability rc;
2082 memset (&rc, 0, sizeof(RIL_RadioCapability));
2084 status = p.readInt32(&t);
2085 rc.version = (int)t;
2086 if (status != NO_ERROR) {
2090 status = p.readInt32(&t);
2092 if (status != NO_ERROR) {
2096 status = p.readInt32(&t);
2098 if (status != NO_ERROR) {
2102 status = p.readInt32(&t);
2104 if (status != NO_ERROR) {
2108 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2109 if (status != NO_ERROR) {
2113 status = p.readInt32(&t);
2116 if (status != NO_ERROR) {
2121 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
2122 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
2123 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
2126 printRequest(pRI->token, pRI->pCI->requestNumber);
2128 CALL_ONREQUEST(pRI->pCI->requestNumber,
2130 sizeof(RIL_RadioCapability),
2131 pRI, pRI->socket_id);
2134 invalidCommandBlock(pRI);
2139 blockingWrite(int fd, const void *buffer, size_t len) {
2140 size_t writeOffset = 0;
2141 const uint8_t *toWrite;
2143 toWrite = (const uint8_t *)buffer;
2145 while (writeOffset < len) {
2148 written = write (fd, toWrite + writeOffset,
2150 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
2153 writeOffset += written;
2154 } else { // written < 0
2155 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
2161 RLOGE("RIL Response bytes written:%d", writeOffset);
2167 sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2168 int fd = s_ril_param_socket.fdCommand;
2171 pthread_mutex_t * writeMutexHook = &s_writeMutex;
2174 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2177 #if (SIM_COUNT >= 2)
2178 if (socket_id == RIL_SOCKET_2) {
2179 fd = s_ril_param_socket2.fdCommand;
2180 writeMutexHook = &s_writeMutex_socket2;
2182 #if (SIM_COUNT >= 3)
2183 else if (socket_id == RIL_SOCKET_3) {
2184 fd = s_ril_param_socket3.fdCommand;
2185 writeMutexHook = &s_writeMutex_socket3;
2188 #if (SIM_COUNT >= 4)
2189 else if (socket_id == RIL_SOCKET_4) {
2190 fd = s_ril_param_socket4.fdCommand;
2191 writeMutexHook = &s_writeMutex_socket4;
2199 if (dataSize > MAX_COMMAND_BYTES) {
2200 RLOGE("RIL: packet larger than %u (%u)",
2201 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2206 pthread_mutex_lock(writeMutexHook);
2208 header = htonl(dataSize);
2210 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2213 pthread_mutex_unlock(writeMutexHook);
2217 ret = blockingWrite(fd, data, dataSize);
2220 pthread_mutex_unlock(writeMutexHook);
2224 pthread_mutex_unlock(writeMutexHook);
2230 sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
2232 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
2235 /** response is an int* pointing to an array of ints */
2238 responseInts(Parcel &p, void *response, size_t responselen) {
2241 if (response == NULL && responselen != 0) {
2242 RLOGE("invalid response: NULL");
2243 return RIL_ERRNO_INVALID_RESPONSE;
2245 if (responselen % sizeof(int) != 0) {
2246 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2247 (int)responselen, (int)sizeof(int));
2248 return RIL_ERRNO_INVALID_RESPONSE;
2251 int *p_int = (int *) response;
2253 numInts = responselen / sizeof(int);
2254 p.writeInt32 (numInts);
2258 for (int i = 0 ; i < numInts ; i++) {
2259 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2260 p.writeInt32(p_int[i]);
2268 // Response is an int or RIL_LastCallFailCauseInfo.
2269 // Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2270 // TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2271 static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2272 if (response == NULL && responselen != 0) {
2273 RLOGE("invalid response: NULL");
2274 return RIL_ERRNO_INVALID_RESPONSE;
2277 if (responselen == sizeof(int)) {
2279 int *p_int = (int *) response;
2280 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2281 p.writeInt32(p_int[0]);
2284 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2286 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2287 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2288 p_fail_cause_info->vendor_cause);
2289 p.writeInt32(p_fail_cause_info->cause_code);
2290 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2294 RLOGE("responseFailCause: invalid response length %d expected an int or "
2295 "RIL_LastCallFailCauseInfo", (int)responselen);
2296 return RIL_ERRNO_INVALID_RESPONSE;
2302 /** response is a char **, pointing to an array of char *'s
2303 The parcel will begin with the version */
2304 static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2305 p.writeInt32(version);
2306 return responseStrings(p, response, responselen);
2309 /** response is a char **, pointing to an array of char *'s */
2310 static int responseStrings(Parcel &p, void *response, size_t responselen) {
2313 if (response == NULL && responselen != 0) {
2314 RLOGE("invalid response: NULL");
2315 return RIL_ERRNO_INVALID_RESPONSE;
2317 if (responselen % sizeof(char *) != 0) {
2318 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
2319 (int)responselen, (int)sizeof(char *));
2320 return RIL_ERRNO_INVALID_RESPONSE;
2323 if (response == NULL) {
2326 char **p_cur = (char **) response;
2328 numStrings = responselen / sizeof(char *);
2329 p.writeInt32 (numStrings);
2333 for (int i = 0 ; i < numStrings ; i++) {
2334 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2335 writeStringToParcel (p, p_cur[i]);
2345 * NULL strings are accepted
2346 * FIXME currently ignores responselen
2348 static int responseString(Parcel &p, void *response, size_t responselen) {
2349 /* one string only */
2351 appendPrintBuf("%s%s", printBuf, (char*)response);
2354 writeStringToParcel(p, (const char *)response);
2359 static int responseVoid(Parcel &p, void *response, size_t responselen) {
2365 static int responseCallList(Parcel &p, void *response, size_t responselen) {
2368 if (response == NULL && responselen != 0) {
2369 RLOGE("invalid response: NULL");
2370 return RIL_ERRNO_INVALID_RESPONSE;
2373 if (responselen % sizeof (RIL_Call *) != 0) {
2374 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
2375 (int)responselen, (int)sizeof (RIL_Call *));
2376 return RIL_ERRNO_INVALID_RESPONSE;
2380 /* number of call info's */
2381 num = responselen / sizeof(RIL_Call *);
2384 for (int i = 0 ; i < num ; i++) {
2385 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2386 /* each call info */
2387 p.writeInt32(p_cur->state);
2388 p.writeInt32(p_cur->index);
2389 p.writeInt32(p_cur->toa);
2390 p.writeInt32(p_cur->isMpty);
2391 p.writeInt32(p_cur->isMT);
2392 p.writeInt32(p_cur->als);
2393 p.writeInt32(p_cur->isVoice);
2394 p.writeInt32(p_cur->isVoicePrivacy);
2395 writeStringToParcel(p, p_cur->number);
2396 p.writeInt32(p_cur->numberPresentation);
2397 writeStringToParcel(p, p_cur->name);
2398 p.writeInt32(p_cur->namePresentation);
2399 // Remove when partners upgrade to version 3
2400 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2401 p.writeInt32(0); /* UUS Information is absent */
2403 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2404 p.writeInt32(1); /* UUS Information is present */
2405 p.writeInt32(uusInfo->uusType);
2406 p.writeInt32(uusInfo->uusDcs);
2407 p.writeInt32(uusInfo->uusLength);
2408 p.write(uusInfo->uusData, uusInfo->uusLength);
2410 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2413 callStateToString(p_cur->state),
2415 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2417 (p_cur->isMpty)?"conf":"norm",
2418 (p_cur->isMT)?"mt":"mo",
2420 (p_cur->isVoice)?"voc":"nonvoc",
2421 (p_cur->isVoicePrivacy)?"evp":"noevp");
2422 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2425 p_cur->numberPresentation,
2427 p_cur->namePresentation);
2435 static int responseSMS(Parcel &p, void *response, size_t responselen) {
2436 if (response == NULL) {
2437 RLOGE("invalid response: NULL");
2438 return RIL_ERRNO_INVALID_RESPONSE;
2441 if (responselen != sizeof (RIL_SMS_Response) ) {
2442 RLOGE("invalid response length %d expected %d",
2443 (int)responselen, (int)sizeof (RIL_SMS_Response));
2444 return RIL_ERRNO_INVALID_RESPONSE;
2447 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2449 p.writeInt32(p_cur->messageRef);
2450 writeStringToParcel(p, p_cur->ackPDU);
2451 p.writeInt32(p_cur->errorCode);
2454 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2455 (char*)p_cur->ackPDU, p_cur->errorCode);
2461 static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2463 if (response == NULL && responselen != 0) {
2464 RLOGE("invalid response: NULL");
2465 return RIL_ERRNO_INVALID_RESPONSE;
2468 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
2469 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
2470 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2471 return RIL_ERRNO_INVALID_RESPONSE;
2477 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2480 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2483 for (i = 0; i < num; i++) {
2484 p.writeInt32(p_cur[i].cid);
2485 p.writeInt32(p_cur[i].active);
2486 writeStringToParcel(p, p_cur[i].type);
2487 // apn is not used, so don't send.
2488 writeStringToParcel(p, p_cur[i].address);
2489 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2491 (p_cur[i].active==0)?"down":"up",
2492 (char*)p_cur[i].type,
2493 (char*)p_cur[i].address);
2501 static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2503 if (response == NULL && responselen != 0) {
2504 RLOGE("invalid response: NULL");
2505 return RIL_ERRNO_INVALID_RESPONSE;
2508 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2509 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2510 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2511 return RIL_ERRNO_INVALID_RESPONSE;
2517 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2520 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2523 for (i = 0; i < num; i++) {
2524 p.writeInt32((int)p_cur[i].status);
2525 p.writeInt32(p_cur[i].suggestedRetryTime);
2526 p.writeInt32(p_cur[i].cid);
2527 p.writeInt32(p_cur[i].active);
2528 writeStringToParcel(p, p_cur[i].type);
2529 writeStringToParcel(p, p_cur[i].ifname);
2530 writeStringToParcel(p, p_cur[i].addresses);
2531 writeStringToParcel(p, p_cur[i].dnses);
2532 writeStringToParcel(p, p_cur[i].gateways);
2533 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2535 p_cur[i].suggestedRetryTime,
2537 (p_cur[i].active==0)?"down":"up",
2538 (char*)p_cur[i].type,
2539 (char*)p_cur[i].ifname,
2540 (char*)p_cur[i].addresses,
2541 (char*)p_cur[i].dnses,
2542 (char*)p_cur[i].gateways);
2550 static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2552 if (response == NULL && responselen != 0) {
2553 RLOGE("invalid response: NULL");
2554 return RIL_ERRNO_INVALID_RESPONSE;
2557 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2558 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2559 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2560 return RIL_ERRNO_INVALID_RESPONSE;
2566 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2569 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2572 for (i = 0; i < num; i++) {
2573 p.writeInt32((int)p_cur[i].status);
2574 p.writeInt32(p_cur[i].suggestedRetryTime);
2575 p.writeInt32(p_cur[i].cid);
2576 p.writeInt32(p_cur[i].active);
2577 writeStringToParcel(p, p_cur[i].type);
2578 writeStringToParcel(p, p_cur[i].ifname);
2579 writeStringToParcel(p, p_cur[i].addresses);
2580 writeStringToParcel(p, p_cur[i].dnses);
2581 writeStringToParcel(p, p_cur[i].gateways);
2582 writeStringToParcel(p, p_cur[i].pcscf);
2583 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2585 p_cur[i].suggestedRetryTime,
2587 (p_cur[i].active==0)?"down":"up",
2588 (char*)p_cur[i].type,
2589 (char*)p_cur[i].ifname,
2590 (char*)p_cur[i].addresses,
2591 (char*)p_cur[i].dnses,
2592 (char*)p_cur[i].gateways,
2593 (char*)p_cur[i].pcscf);
2601 static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2602 if (response == NULL && responselen != 0) {
2603 RLOGE("invalid response: NULL");
2604 return RIL_ERRNO_INVALID_RESPONSE;
2607 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2608 RLOGE("invalid response length %d expected multiple of %d",
2609 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2610 return RIL_ERRNO_INVALID_RESPONSE;
2616 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2619 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2622 for (i = 0; i < num; i++) {
2623 p.writeInt32((int)p_cur[i].status);
2624 p.writeInt32(p_cur[i].suggestedRetryTime);
2625 p.writeInt32(p_cur[i].cid);
2626 p.writeInt32(p_cur[i].active);
2627 writeStringToParcel(p, p_cur[i].type);
2628 writeStringToParcel(p, p_cur[i].ifname);
2629 writeStringToParcel(p, p_cur[i].addresses);
2630 writeStringToParcel(p, p_cur[i].dnses);
2631 writeStringToParcel(p, p_cur[i].gateways);
2632 writeStringToParcel(p, p_cur[i].pcscf);
2633 p.writeInt32(p_cur[i].mtu);
2634 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2636 p_cur[i].suggestedRetryTime,
2638 (p_cur[i].active==0)?"down":"up",
2639 (char*)p_cur[i].type,
2640 (char*)p_cur[i].ifname,
2641 (char*)p_cur[i].addresses,
2642 (char*)p_cur[i].dnses,
2643 (char*)p_cur[i].gateways,
2644 (char*)p_cur[i].pcscf,
2653 static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2655 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2656 if (s_callbacks.version < 5) {
2657 RLOGD("responseDataCallList: v4");
2658 return responseDataCallListV4(p, response, responselen);
2659 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2660 return responseDataCallListV6(p, response, responselen);
2661 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2662 return responseDataCallListV9(p, response, responselen);
2664 return responseDataCallListV11(p, response, responselen);
2666 } else { // RIL version >= 13
2667 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2668 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2669 if (!isDebuggable()) {
2670 return RIL_ERRNO_INVALID_RESPONSE;
2675 return responseDataCallListV11(p, response, responselen);
2679 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2681 if (s_callbacks.version < 5) {
2682 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2684 return responseDataCallList(p, response, responselen);
2688 static int responseRaw(Parcel &p, void *response, size_t responselen) {
2689 if (response == NULL && responselen != 0) {
2690 RLOGE("invalid response: NULL with responselen != 0");
2691 return RIL_ERRNO_INVALID_RESPONSE;
2694 // The java code reads -1 size as null byte array
2695 if (response == NULL) {
2698 p.writeInt32(responselen);
2699 p.write(response, responselen);
2706 static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2707 if (response == NULL) {
2708 RLOGE("invalid response: NULL");
2709 return RIL_ERRNO_INVALID_RESPONSE;
2712 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
2713 RLOGE("invalid response length was %d expected %d",
2714 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2715 return RIL_ERRNO_INVALID_RESPONSE;
2718 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2719 p.writeInt32(p_cur->sw1);
2720 p.writeInt32(p_cur->sw2);
2721 writeStringToParcel(p, p_cur->simResponse);
2724 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2725 (char*)p_cur->simResponse);
2732 static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2735 if (response == NULL && responselen != 0) {
2736 RLOGE("invalid response: NULL");
2737 return RIL_ERRNO_INVALID_RESPONSE;
2740 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
2741 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
2742 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2743 return RIL_ERRNO_INVALID_RESPONSE;
2746 /* number of call info's */
2747 num = responselen / sizeof(RIL_CallForwardInfo *);
2751 for (int i = 0 ; i < num ; i++) {
2752 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2754 p.writeInt32(p_cur->status);
2755 p.writeInt32(p_cur->reason);
2756 p.writeInt32(p_cur->serviceClass);
2757 p.writeInt32(p_cur->toa);
2758 writeStringToParcel(p, p_cur->number);
2759 p.writeInt32(p_cur->timeSeconds);
2760 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2761 (p_cur->status==1)?"enable":"disable",
2762 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2763 (char*)p_cur->number,
2764 p_cur->timeSeconds);
2772 static int responseSsn(Parcel &p, void *response, size_t responselen) {
2773 if (response == NULL) {
2774 RLOGE("invalid response: NULL");
2775 return RIL_ERRNO_INVALID_RESPONSE;
2778 if (responselen != sizeof(RIL_SuppSvcNotification)) {
2779 RLOGE("invalid response length was %d expected %d",
2780 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2781 return RIL_ERRNO_INVALID_RESPONSE;
2784 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2785 p.writeInt32(p_cur->notificationType);
2786 p.writeInt32(p_cur->code);
2787 p.writeInt32(p_cur->index);
2788 p.writeInt32(p_cur->type);
2789 writeStringToParcel(p, p_cur->number);
2792 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2793 (p_cur->notificationType==0)?"mo":"mt",
2794 p_cur->code, p_cur->index, p_cur->type,
2795 (char*)p_cur->number);
2801 static int responseCellList(Parcel &p, void *response, size_t responselen) {
2804 if (response == NULL && responselen != 0) {
2805 RLOGE("invalid response: NULL");
2806 return RIL_ERRNO_INVALID_RESPONSE;
2809 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
2810 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
2811 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2812 return RIL_ERRNO_INVALID_RESPONSE;
2816 /* number of records */
2817 num = responselen / sizeof(RIL_NeighboringCell *);
2820 for (int i = 0 ; i < num ; i++) {
2821 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2823 p.writeInt32(p_cur->rssi);
2824 writeStringToParcel (p, p_cur->cid);
2826 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2827 p_cur->cid, p_cur->rssi);
2836 * Marshall the signalInfoRecord into the parcel if it exists.
2838 static void marshallSignalInfoRecord(Parcel &p,
2839 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2840 p.writeInt32(p_signalInfoRecord.isPresent);
2841 p.writeInt32(p_signalInfoRecord.signalType);
2842 p.writeInt32(p_signalInfoRecord.alertPitch);
2843 p.writeInt32(p_signalInfoRecord.signal);
2846 static int responseCdmaInformationRecords(Parcel &p,
2847 void *response, size_t responselen) {
2849 char* string8 = NULL;
2851 RIL_CDMA_InformationRecord *infoRec;
2853 if (response == NULL && responselen != 0) {
2854 RLOGE("invalid response: NULL");
2855 return RIL_ERRNO_INVALID_RESPONSE;
2858 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
2859 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
2860 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2861 return RIL_ERRNO_INVALID_RESPONSE;
2864 RIL_CDMA_InformationRecords *p_cur =
2865 (RIL_CDMA_InformationRecords *) response;
2866 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2871 for (int i = 0 ; i < num ; i++) {
2872 infoRec = &p_cur->infoRec[i];
2873 p.writeInt32(infoRec->name);
2874 switch (infoRec->name) {
2875 case RIL_CDMA_DISPLAY_INFO_REC:
2876 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2877 if (infoRec->rec.display.alpha_len >
2878 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
2879 RLOGE("invalid display info response length %d \
2880 expected not more than %d\n",
2881 (int)infoRec->rec.display.alpha_len,
2882 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2883 return RIL_ERRNO_INVALID_RESPONSE;
2885 string8 = (char*) calloc(infoRec->rec.display.alpha_len + 1, sizeof(char));
2886 if (string8 == NULL) {
2887 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2889 return RIL_ERRNO_NO_MEMORY;
2891 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2892 string8[i] = infoRec->rec.display.alpha_buf[i];
2894 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2895 writeStringToParcel(p, (const char*)string8);
2899 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2900 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2901 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2902 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
2903 RLOGE("invalid display info response length %d \
2904 expected not more than %d\n",
2905 (int)infoRec->rec.number.len,
2906 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2907 return RIL_ERRNO_INVALID_RESPONSE;
2909 string8 = (char*) calloc(infoRec->rec.number.len + 1, sizeof(char));
2910 if (string8 == NULL) {
2911 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2913 return RIL_ERRNO_NO_MEMORY;
2915 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2916 string8[i] = infoRec->rec.number.buf[i];
2918 string8[(int)infoRec->rec.number.len] = '\0';
2919 writeStringToParcel(p, (const char*)string8);
2922 p.writeInt32(infoRec->rec.number.number_type);
2923 p.writeInt32(infoRec->rec.number.number_plan);
2924 p.writeInt32(infoRec->rec.number.pi);
2925 p.writeInt32(infoRec->rec.number.si);
2927 case RIL_CDMA_SIGNAL_INFO_REC:
2928 p.writeInt32(infoRec->rec.signal.isPresent);
2929 p.writeInt32(infoRec->rec.signal.signalType);
2930 p.writeInt32(infoRec->rec.signal.alertPitch);
2931 p.writeInt32(infoRec->rec.signal.signal);
2933 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2934 alertPitch=%X, signal=%X, ",
2935 printBuf, (int)infoRec->rec.signal.isPresent,
2936 (int)infoRec->rec.signal.signalType,
2937 (int)infoRec->rec.signal.alertPitch,
2938 (int)infoRec->rec.signal.signal);
2941 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2942 if (infoRec->rec.redir.redirectingNumber.len >
2943 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
2944 RLOGE("invalid display info response length %d \
2945 expected not more than %d\n",
2946 (int)infoRec->rec.redir.redirectingNumber.len,
2947 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2948 return RIL_ERRNO_INVALID_RESPONSE;
2950 string8 = (char*) calloc(infoRec->rec.redir.redirectingNumber.len + 1,
2952 if (string8 == NULL) {
2953 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2955 return RIL_ERRNO_NO_MEMORY;
2958 i < infoRec->rec.redir.redirectingNumber.len;
2960 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2962 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2963 writeStringToParcel(p, (const char*)string8);
2966 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2967 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2968 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2969 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2970 p.writeInt32(infoRec->rec.redir.redirectingReason);
2972 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2973 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2974 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2975 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2976 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2978 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2979 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2980 lineCtrlPowerDenial=%d, ", printBuf,
2981 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2982 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2983 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2984 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2987 case RIL_CDMA_T53_CLIR_INFO_REC:
2988 p.writeInt32((int)(infoRec->rec.clir.cause));
2990 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2993 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2994 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2995 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2997 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2998 infoRec->rec.audioCtrl.upLink,
2999 infoRec->rec.audioCtrl.downLink);
3002 case RIL_CDMA_T53_RELEASE_INFO_REC:
3003 // TODO(Moto): See David Krause, he has the answer:)
3004 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
3005 return RIL_ERRNO_INVALID_RESPONSE;
3007 RLOGE("Incorrect name value");
3008 return RIL_ERRNO_INVALID_RESPONSE;
3016 static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3017 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
3018 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
3019 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
3020 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
3021 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
3022 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
3023 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
3026 static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3028 * Fixup LTE for backwards compatibility
3030 // signalStrength: -1 -> 99
3031 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3032 p_cur->LTE_SignalStrength.signalStrength = 99;
3034 // rsrp: -1 -> INT_MAX all other negative value to positive.
3036 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3037 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3038 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3039 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3041 // rsrq: -1 -> INT_MAX
3042 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3043 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3045 // Not remapping rssnr is already using INT_MAX
3047 // cqi: -1 -> INT_MAX
3048 if (p_cur->LTE_SignalStrength.cqi == -1) {
3049 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3052 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3053 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3054 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3055 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3056 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3059 static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3060 responseRilSignalStrengthV5(p, p_cur);
3061 responseRilSignalStrengthV6Extra(p, p_cur);
3062 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3065 static int responseRilSignalStrength(Parcel &p,
3066 void *response, size_t responselen) {
3067 if (response == NULL && responselen != 0) {
3068 RLOGE("invalid response: NULL");
3069 return RIL_ERRNO_INVALID_RESPONSE;
3072 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3073 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
3074 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3076 responseRilSignalStrengthV5(p, p_cur);
3078 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3079 responseRilSignalStrengthV6Extra(p, p_cur);
3080 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3081 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3083 p.writeInt32(INT_MAX);
3087 p.writeInt32(INT_MAX);
3088 p.writeInt32(INT_MAX);
3089 p.writeInt32(INT_MAX);
3090 p.writeInt32(INT_MAX);
3091 p.writeInt32(INT_MAX);
3094 RLOGE("invalid response length");
3095 return RIL_ERRNO_INVALID_RESPONSE;
3097 } else { // RIL version >= 13
3098 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3099 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3100 if (!isDebuggable()) {
3101 return RIL_ERRNO_INVALID_RESPONSE;
3106 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
3107 responseRilSignalStrengthV10(p, p_cur);
3110 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3111 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3112 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3113 EVDO_SS.signalNoiseRatio=%d,\
3114 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3115 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3117 p_cur->GW_SignalStrength.signalStrength,
3118 p_cur->GW_SignalStrength.bitErrorRate,
3119 p_cur->CDMA_SignalStrength.dbm,
3120 p_cur->CDMA_SignalStrength.ecio,
3121 p_cur->EVDO_SignalStrength.dbm,
3122 p_cur->EVDO_SignalStrength.ecio,
3123 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3124 p_cur->LTE_SignalStrength.signalStrength,
3125 p_cur->LTE_SignalStrength.rsrp,
3126 p_cur->LTE_SignalStrength.rsrq,
3127 p_cur->LTE_SignalStrength.rssnr,
3128 p_cur->LTE_SignalStrength.cqi,
3129 p_cur->TD_SCDMA_SignalStrength.rscp);
3134 static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3135 if ((response == NULL) || (responselen == 0)) {
3136 return responseVoid(p, response, responselen);
3138 return responseCdmaSignalInfoRecord(p, response, responselen);
3142 static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3143 if (response == NULL || responselen == 0) {
3144 RLOGE("invalid response: NULL");
3145 return RIL_ERRNO_INVALID_RESPONSE;
3148 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
3149 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
3150 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3151 return RIL_ERRNO_INVALID_RESPONSE;
3156 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3157 marshallSignalInfoRecord(p, *p_cur);
3159 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3171 static int responseCdmaCallWaiting(Parcel &p, void *response,
3172 size_t responselen) {
3173 if (response == NULL && responselen != 0) {
3174 RLOGE("invalid response: NULL");
3175 return RIL_ERRNO_INVALID_RESPONSE;
3178 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
3179 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
3182 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3184 writeStringToParcel(p, p_cur->number);
3185 p.writeInt32(p_cur->numberPresentation);
3186 writeStringToParcel(p, p_cur->name);
3187 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3189 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3190 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3191 p.writeInt32(p_cur->number_type);
3192 p.writeInt32(p_cur->number_plan);
3197 } else { // RIL version >= 13
3198 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3199 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3200 if (!isDebuggable()) {
3201 return RIL_ERRNO_INVALID_RESPONSE;
3206 p.writeInt32(p_cur->number_type);
3207 p.writeInt32(p_cur->number_plan);
3211 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3212 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3213 signal=%d,number_type=%d,number_plan=%d]",
3216 p_cur->numberPresentation,
3218 p_cur->signalInfoRecord.isPresent,
3219 p_cur->signalInfoRecord.signalType,
3220 p_cur->signalInfoRecord.alertPitch,
3221 p_cur->signalInfoRecord.signal,
3223 p_cur->number_plan);
3229 static void responseSimRefreshV7(Parcel &p, void *response) {
3230 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3231 p.writeInt32(p_cur->result);
3232 p.writeInt32(p_cur->ef_id);
3233 writeStringToParcel(p, p_cur->aid);
3235 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3243 static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3244 if (response == NULL && responselen != 0) {
3245 RLOGE("responseSimRefresh: invalid response: NULL");
3246 return RIL_ERRNO_INVALID_RESPONSE;
3250 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3251 if (s_callbacks.version >= 7) {
3252 responseSimRefreshV7(p, response);
3254 int *p_cur = ((int *) response);
3255 p.writeInt32(p_cur[0]);
3256 p.writeInt32(p_cur[1]);
3257 writeStringToParcel(p, NULL);
3259 appendPrintBuf("%sresult=%d, ef_id=%d",
3264 } else { // RIL version >= 13
3265 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3266 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3267 if (!isDebuggable()) {
3268 return RIL_ERRNO_INVALID_RESPONSE;
3273 responseSimRefreshV7(p, response);
3281 static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
3282 if (response == NULL && responselen != 0) {
3283 RLOGE("invalid response: NULL");
3284 return RIL_ERRNO_INVALID_RESPONSE;
3287 if (responselen % sizeof(RIL_CellInfo) != 0) {
3288 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3289 (int)responselen, (int)sizeof(RIL_CellInfo));
3290 return RIL_ERRNO_INVALID_RESPONSE;
3293 int num = responselen / sizeof(RIL_CellInfo);
3296 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3299 for (i = 0; i < num; i++) {
3300 p.writeInt32((int)p_cur->cellInfoType);
3301 p.writeInt32(p_cur->registered);
3302 p.writeInt32(p_cur->timeStampType);
3303 p.writeInt64(p_cur->timeStamp);
3304 switch(p_cur->cellInfoType) {
3305 case RIL_CELL_INFO_TYPE_GSM: {
3306 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3307 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3308 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3309 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3310 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3311 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3314 case RIL_CELL_INFO_TYPE_WCDMA: {
3315 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3316 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3317 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3318 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3319 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3320 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3321 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3324 case RIL_CELL_INFO_TYPE_CDMA: {
3325 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3326 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3327 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3328 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3329 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3331 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3332 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3333 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3334 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3335 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3338 case RIL_CELL_INFO_TYPE_LTE: {
3339 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3340 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3341 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3342 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3343 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3345 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3346 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3347 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3348 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3349 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3350 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3353 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3354 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3355 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3356 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3357 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3358 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3359 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3371 static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3372 if (response == NULL && responselen != 0) {
3373 RLOGE("invalid response: NULL");
3374 return RIL_ERRNO_INVALID_RESPONSE;
3377 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3378 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3379 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3380 return RIL_ERRNO_INVALID_RESPONSE;
3383 int num = responselen / sizeof(RIL_CellInfo_v12);
3386 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3389 for (i = 0; i < num; i++) {
3390 p.writeInt32((int)p_cur->cellInfoType);
3391 p.writeInt32(p_cur->registered);
3392 p.writeInt32(p_cur->timeStampType);
3393 p.writeInt64(p_cur->timeStamp);
3394 switch(p_cur->cellInfoType) {
3395 case RIL_CELL_INFO_TYPE_GSM: {
3396 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3397 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3398 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3399 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3400 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3401 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3402 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3403 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3404 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3407 case RIL_CELL_INFO_TYPE_WCDMA: {
3408 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3409 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3410 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3411 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3412 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3413 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3414 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3415 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3418 case RIL_CELL_INFO_TYPE_CDMA: {
3419 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3420 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3421 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3422 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3423 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3425 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3426 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3427 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3428 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3429 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3432 case RIL_CELL_INFO_TYPE_LTE: {
3433 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3434 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3435 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3436 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3437 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3438 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3440 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3441 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3442 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3443 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3444 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3445 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3448 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3449 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3450 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3451 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3452 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3453 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3454 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3465 static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3467 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3468 if (s_callbacks.version < 12) {
3469 RLOGD("responseCellInfoList: v6");
3470 return responseCellInfoListV6(p, response, responselen);
3472 RLOGD("responseCellInfoList: v12");
3473 return responseCellInfoListV12(p, response, responselen);
3475 } else { // RIL version >= 13
3476 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3477 RLOGE("Data structure expected is RIL_CellInfo_v12");
3478 if (!isDebuggable()) {
3479 return RIL_ERRNO_INVALID_RESPONSE;
3484 return responseCellInfoListV12(p, response, responselen);
3490 static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3492 if (response == NULL && responselen != 0) {
3493 RLOGE("invalid response: NULL");
3494 return RIL_ERRNO_INVALID_RESPONSE;
3497 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3498 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3499 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3500 return RIL_ERRNO_INVALID_RESPONSE;
3503 int num = responselen / sizeof(RIL_HardwareConfig);
3505 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3510 for (i = 0; i < num; i++) {
3511 switch (p_cur[i].type) {
3512 case RIL_HARDWARE_CONFIG_MODEM: {
3513 writeStringToParcel(p, p_cur[i].uuid);
3514 p.writeInt32((int)p_cur[i].state);
3515 p.writeInt32(p_cur[i].cfg.modem.rat);
3516 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3517 p.writeInt32(p_cur[i].cfg.modem.maxData);
3518 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3520 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3521 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3522 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3525 case RIL_HARDWARE_CONFIG_SIM: {
3526 writeStringToParcel(p, p_cur[i].uuid);
3527 p.writeInt32((int)p_cur[i].state);
3528 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3530 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3531 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3541 static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3542 if (response == NULL) {
3543 RLOGE("invalid response: NULL");
3544 return RIL_ERRNO_INVALID_RESPONSE;
3547 if (responselen != sizeof (RIL_RadioCapability) ) {
3548 RLOGE("invalid response length was %d expected %d",
3549 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3550 return RIL_ERRNO_INVALID_RESPONSE;
3553 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3554 p.writeInt32(p_cur->version);
3555 p.writeInt32(p_cur->session);
3556 p.writeInt32(p_cur->phase);
3557 p.writeInt32(p_cur->rat);
3558 writeStringToParcel(p, p_cur->logicalModemUuid);
3559 p.writeInt32(p_cur->status);
3562 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
3563 rat=%s,logicalModemUuid=%s,status=%d]",
3569 p_cur->logicalModemUuid,
3575 static int responseSSData(Parcel &p, void *response, size_t responselen) {
3576 RLOGD("In responseSSData");
3579 if (response == NULL && responselen != 0) {
3580 RLOGE("invalid response length was %d expected %d",
3581 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3582 return RIL_ERRNO_INVALID_RESPONSE;
3585 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3586 RLOGE("invalid response length %d, expected %d",
3587 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3588 return RIL_ERRNO_INVALID_RESPONSE;
3592 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3593 p.writeInt32(p_cur->serviceType);
3594 p.writeInt32(p_cur->requestType);
3595 p.writeInt32(p_cur->teleserviceType);
3596 p.writeInt32(p_cur->serviceClass);
3597 p.writeInt32(p_cur->result);
3599 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3600 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3601 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3602 RLOGE("numValidIndexes is greater than max value %d, "
3603 "truncating it to max value", NUM_SERVICE_CLASSES);
3604 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3606 /* number of call info's */
3607 p.writeInt32(p_cur->cfData.numValidIndexes);
3609 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3610 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3612 p.writeInt32(cf.status);
3613 p.writeInt32(cf.reason);
3614 p.writeInt32(cf.serviceClass);
3615 p.writeInt32(cf.toa);
3616 writeStringToParcel(p, cf.number);
3617 p.writeInt32(cf.timeSeconds);
3618 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3619 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3620 (char*)cf.number, cf.timeSeconds);
3621 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3622 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3625 p.writeInt32 (SS_INFO_MAX);
3628 for (int i = 0; i < SS_INFO_MAX; i++) {
3629 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3630 RLOGD("Data: %d",p_cur->ssInfo[i]);
3631 p.writeInt32(p_cur->ssInfo[i]);
3640 static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3641 if ((reqType == SS_INTERROGATION) &&
3642 (serType == SS_CFU ||
3643 serType == SS_CF_BUSY ||
3644 serType == SS_CF_NO_REPLY ||
3645 serType == SS_CF_NOT_REACHABLE ||
3646 serType == SS_CF_ALL ||
3647 serType == SS_CF_ALL_CONDITIONAL)) {
3653 static void triggerEvLoop() {
3655 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3656 /* trigger event loop to wakeup. No reason to do this,
3657 * if we're in the event loop thread */
3659 ret = write (s_fdWakeupWrite, " ", 1);
3660 } while (ret < 0 && errno == EINTR);
3664 static void rilEventAddWakeup(struct ril_event *ev) {
3669 static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3670 p.writeInt32(num_apps);
3672 for (int i = 0; i < num_apps; i++) {
3673 p.writeInt32(appStatus[i].app_type);
3674 p.writeInt32(appStatus[i].app_state);
3675 p.writeInt32(appStatus[i].perso_substate);
3676 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3677 writeStringToParcel(p, (const char*)
3678 (appStatus[i].app_label_ptr));
3679 p.writeInt32(appStatus[i].pin1_replaced);
3680 p.writeInt32(appStatus[i].pin1);
3681 p.writeInt32(appStatus[i].pin2);
3682 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3683 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3685 appStatus[i].app_type,
3686 appStatus[i].app_state,
3687 appStatus[i].perso_substate,
3688 appStatus[i].aid_ptr,
3689 appStatus[i].app_label_ptr,
3690 appStatus[i].pin1_replaced,
3697 static void responseSimStatusV5(Parcel &p, void *response) {
3698 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3700 p.writeInt32(p_cur->card_state);
3701 p.writeInt32(p_cur->universal_pin_state);
3702 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3703 p.writeInt32(p_cur->cdma_subscription_app_index);
3705 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3708 static void responseSimStatusV6(Parcel &p, void *response) {
3709 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3711 p.writeInt32(p_cur->card_state);
3712 p.writeInt32(p_cur->universal_pin_state);
3713 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3714 p.writeInt32(p_cur->cdma_subscription_app_index);
3715 p.writeInt32(p_cur->ims_subscription_app_index);
3717 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3720 static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3723 if (response == NULL && responselen != 0) {
3724 RLOGE("invalid response: NULL");
3725 return RIL_ERRNO_INVALID_RESPONSE;
3728 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3729 if (responselen == sizeof (RIL_CardStatus_v6)) {
3730 responseSimStatusV6(p, response);
3731 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3732 responseSimStatusV5(p, response);
3734 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3735 return RIL_ERRNO_INVALID_RESPONSE;
3737 } else { // RIL version >= 13
3738 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
3739 RLOGE("Data structure expected is RIL_CardStatus_v6");
3740 if (!isDebuggable()) {
3741 return RIL_ERRNO_INVALID_RESPONSE;
3746 responseSimStatusV6(p, response);
3752 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3753 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3757 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3758 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3759 for (int i = 0; i < num; i++) {
3760 p.writeInt32(p_cur[i]->fromServiceId);
3761 p.writeInt32(p_cur[i]->toServiceId);
3762 p.writeInt32(p_cur[i]->fromCodeScheme);
3763 p.writeInt32(p_cur[i]->toCodeScheme);
3764 p.writeInt32(p_cur[i]->selected);
3766 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3767 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3768 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3769 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3770 p_cur[i]->selected);
3777 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3778 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3779 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3781 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3785 for (int i = 0 ; i < num ; i++ ) {
3786 p.writeInt32(p_cur[i]->service_category);
3787 p.writeInt32(p_cur[i]->language);
3788 p.writeInt32(p_cur[i]->selected);
3790 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3792 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3793 p_cur[i]->selected);
3800 static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3807 RLOGD("Inside responseCdmaSms");
3809 if (response == NULL && responselen != 0) {
3810 RLOGE("invalid response: NULL");
3811 return RIL_ERRNO_INVALID_RESPONSE;
3814 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
3815 RLOGE("invalid response length was %d expected %d",
3816 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3817 return RIL_ERRNO_INVALID_RESPONSE;
3820 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3821 p.writeInt32(p_cur->uTeleserviceID);
3822 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3823 p.writeInt32(p_cur->uServicecategory);
3824 p.writeInt32(p_cur->sAddress.digit_mode);
3825 p.writeInt32(p_cur->sAddress.number_mode);
3826 p.writeInt32(p_cur->sAddress.number_type);
3827 p.writeInt32(p_cur->sAddress.number_plan);
3828 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3829 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3830 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3831 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3834 p.writeInt32(p_cur->sSubAddress.subaddressType);
3835 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3836 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3837 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3838 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3839 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3842 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3843 p.writeInt32(p_cur->uBearerDataLen);
3844 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3845 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3849 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3850 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3851 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3852 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3858 static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3860 int num = responselen / sizeof(RIL_DcRtInfo);
3861 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3862 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3863 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3864 return RIL_ERRNO_INVALID_RESPONSE;
3868 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3869 p.writeInt64(pDcRtInfo->time);
3870 p.writeInt32(pDcRtInfo->powerState);
3871 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3873 pDcRtInfo->powerState);
3879 static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3880 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3881 if (response == NULL) {
3882 RLOGE("invalid response: NULL");
3885 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3886 sizeof(RIL_LceStatusInfo), responselen);
3888 return RIL_ERRNO_INVALID_RESPONSE;
3891 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3892 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3893 p.writeInt32(p_cur->actual_interval_ms);
3896 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3897 p_cur->lce_status, p_cur->actual_interval_ms);
3903 static int responseLceData(Parcel &p, void *response, size_t responselen) {
3904 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3905 if (response == NULL) {
3906 RLOGE("invalid response: NULL");
3909 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3910 sizeof(RIL_LceDataInfo), responselen);
3912 return RIL_ERRNO_INVALID_RESPONSE;
3915 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3916 p.writeInt32(p_cur->last_hop_capacity_kbps);
3918 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3919 p.write((void *)&(p_cur->confidence_level), 1);
3920 p.write((void *)&(p_cur->lce_suspended), 1);
3923 appendPrintBuf("LCE info received: capacity %d confidence level %d \
3925 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3926 p_cur->lce_suspended);
3932 static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3933 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3934 if (response == NULL) {
3935 RLOGE("invalid response: NULL");
3938 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3939 sizeof(RIL_ActivityStatsInfo), responselen);
3941 return RIL_ERRNO_INVALID_RESPONSE;
3944 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3945 p.writeInt32(p_cur->sleep_mode_time_ms);
3946 p.writeInt32(p_cur->idle_mode_time_ms);
3947 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3948 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3950 p.writeInt32(p_cur->rx_mode_time_ms);
3953 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
3954 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3955 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3956 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3957 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3964 * A write on the wakeup fd is done just to pop us out of select()
3965 * We empty the buffer here and then ril_event will reset the timers on the
3968 static void processWakeupCallback(int fd, short flags, void *param) {
3972 RLOGV("processWakeupCallback");
3974 /* empty our wakeup socket out */
3976 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3977 } while (ret > 0 || (ret < 0 && errno == EINTR));
3980 static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
3983 /* Hook for current context
3984 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3985 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3986 /* pendingRequestsHook refer to &s_pendingRequests */
3987 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
3989 #if (SIM_COUNT >= 2)
3990 if (socket_id == RIL_SOCKET_2) {
3991 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3992 pendingRequestsHook = &s_pendingRequests_socket2;
3994 #if (SIM_COUNT >= 3)
3995 else if (socket_id == RIL_SOCKET_3) {
3996 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3997 pendingRequestsHook = &s_pendingRequests_socket3;
4000 #if (SIM_COUNT >= 4)
4001 else if (socket_id == RIL_SOCKET_4) {
4002 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4003 pendingRequestsHook = &s_pendingRequests_socket4;
4007 /* mark pending requests as "cancelled" so we dont report responses */
4008 ret = pthread_mutex_lock(pendingRequestsMutexHook);
4011 p_cur = *pendingRequestsHook;
4013 for (p_cur = *pendingRequestsHook
4015 ; p_cur = p_cur->p_next
4017 p_cur->cancelled = 1;
4020 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
4024 static void processCommandsCallback(int fd, short flags, void *param) {
4029 SocketListenParam *p_info = (SocketListenParam *)param;
4031 assert(fd == p_info->fdCommand);
4033 p_rs = p_info->p_rs;
4036 /* loop until EAGAIN/EINTR, end of stream, or other error */
4037 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4039 if (ret == 0 && p_record == NULL) {
4042 } else if (ret < 0) {
4044 } else if (ret == 0) { /* && p_record != NULL */
4045 processCommandBuffer(p_record, recordlen, p_info->socket_id);
4049 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4050 /* fatal error or end-of-stream */
4052 RLOGE("error on reading command socket errno:%d\n", errno);
4054 RLOGW("EOS. Closing command socket.");
4058 p_info->fdCommand = -1;
4060 ril_event_del(p_info->commands_event);
4062 record_stream_free(p_rs);
4064 /* start listening for new connections again */
4065 rilEventAddWakeup(&s_listen_event);
4067 onCommandsSocketClosed(p_info->socket_id);
4072 static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
4073 // Inform we are connected and the ril version
4074 int rilVer = s_callbacks.version;
4075 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4076 &rilVer, sizeof(rilVer), socket_id);
4078 // implicit radio state changed
4079 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4080 NULL, 0, socket_id);
4082 // Send last NITZ time data, in case it was missed
4083 if (s_lastNITZTimeData != NULL) {
4084 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
4086 free(s_lastNITZTimeData);
4087 s_lastNITZTimeData = NULL;
4090 // Get version string
4091 if (s_callbacks.getVersion != NULL) {
4092 const char *version;
4093 version = s_callbacks.getVersion();
4094 RLOGI("RIL Daemon version: %s\n", version);
4096 property_set(PROPERTY_RIL_IMPL, version);
4098 RLOGI("RIL Daemon version: unavailable\n");
4099 property_set(PROPERTY_RIL_IMPL, "unavailable");
4104 static void listenCallback (int fd, short flags, void *param) {
4107 int is_phone_socket;
4111 MySocketListenParam* listenParam;
4112 RilSocket *sapSocket = NULL;
4113 socketClient *sClient = NULL;
4115 SocketListenParam *p_info = (SocketListenParam *)param;
4117 if(RIL_SAP_SOCKET == p_info->type) {
4118 listenParam = (MySocketListenParam *)param;
4119 sapSocket = listenParam->socket;
4122 struct sockaddr_un peeraddr;
4123 socklen_t socklen = sizeof (peeraddr);
4126 socklen_t szCreds = sizeof(creds);
4128 struct passwd *pwd = NULL;
4130 if(NULL == sapSocket) {
4131 assert (*p_info->fdCommand < 0);
4132 assert (fd == *p_info->fdListen);
4133 processName = PHONE_PROCESS;
4135 assert (sapSocket->commandFd < 0);
4136 assert (fd == sapSocket->listenFd);
4137 processName = BLUETOOTH_PROCESS;
4141 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
4143 if (fdCommand < 0 ) {
4144 RLOGE("Error on accept() errno:%d", errno);
4145 /* start listening for new connections again */
4146 if(NULL == sapSocket) {
4147 rilEventAddWakeup(p_info->listen_event);
4149 rilEventAddWakeup(sapSocket->getListenEvent());
4154 /* check the credential of the other side and only accept socket from
4158 is_phone_socket = 0;
4160 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
4162 if (err == 0 && szCreds > 0) {
4164 pwd = getpwuid(creds.uid);
4166 if (strcmp(pwd->pw_name, processName) == 0) {
4167 is_phone_socket = 1;
4169 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
4172 RLOGE("Error on getpwuid() errno: %d", errno);
4175 RLOGD("Error on getsockopt() errno: %d", errno);
4178 if (!is_phone_socket) {
4179 RLOGE("RILD must accept socket from %s", processName);
4184 if(NULL == sapSocket) {
4185 onCommandsSocketClosed(p_info->socket_id);
4187 /* start listening for new connections again */
4188 rilEventAddWakeup(p_info->listen_event);
4190 sapSocket->onCommandsSocketClosed();
4192 /* start listening for new connections again */
4193 rilEventAddWakeup(sapSocket->getListenEvent());
4199 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
4202 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
4205 if(NULL == sapSocket) {
4206 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
4208 p_info->fdCommand = fdCommand;
4209 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4210 p_info->p_rs = p_rs;
4212 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
4213 p_info->processCommandsCallback, p_info);
4214 rilEventAddWakeup (p_info->commands_event);
4216 onNewCommandConnect(p_info->socket_id);
4218 RLOGI("libril: new connection");
4220 sapSocket->setCommandFd(fdCommand);
4221 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4222 sClient = new socketClient(sapSocket,p_rs);
4223 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4224 sapSocket->getCommandCb(), sClient);
4226 rilEventAddWakeup(sapSocket->getCallbackEvent());
4227 sapSocket->onNewCommandConnect();
4231 static void freeDebugCallbackArgs(int number, char **args) {
4232 for (int i = 0; i < number; i++) {
4233 if (args[i] != NULL) {
4240 static void debugCallback (int fd, short flags, void *param) {
4241 int acceptFD, option;
4242 struct sockaddr_un peeraddr;
4243 socklen_t socklen = sizeof (peeraddr);
4245 unsigned int qxdm_data[6];
4246 const char *deactData[1] = {"1"};
4249 int hangupData[1] = {1};
4252 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4255 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
4257 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4260 RLOGE ("error accepting on debug port: %d\n", errno);
4264 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
4265 RLOGE ("error reading on socket: number of Args: \n");
4271 RLOGE ("Invalid number of arguments: \n");
4276 args = (char **) calloc(number, sizeof(char*));
4278 RLOGE("Memory allocation failed for debug args");
4283 for (int i = 0; i < number; i++) {
4285 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
4286 RLOGE ("error reading on socket: Len of Args: \n");
4287 freeDebugCallbackArgs(i, args);
4291 if (len == INT_MAX || len < 0) {
4292 RLOGE("Invalid value of len: \n");
4293 freeDebugCallbackArgs(i, args);
4299 args[i] = (char *) calloc(len + 1, sizeof(char));
4300 if (args[i] == NULL) {
4301 RLOGE("Memory allocation failed for debug args");
4302 freeDebugCallbackArgs(i, args);
4306 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4307 != (int)sizeof(char) * len) {
4308 RLOGE ("error reading on socket: Args[%d] \n", i);
4309 freeDebugCallbackArgs(i, args);
4313 char * buf = args[i];
4315 if ((i+1) == number) {
4316 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4317 sim_id = atoi(args[i]);
4320 socket_id = RIL_SOCKET_1;
4322 #if (SIM_COUNT >= 2)
4324 socket_id = RIL_SOCKET_2;
4327 #if (SIM_COUNT >= 3)
4329 socket_id = RIL_SOCKET_3;
4332 #if (SIM_COUNT >= 4)
4334 socket_id = RIL_SOCKET_4;
4338 socket_id = RIL_SOCKET_1;
4344 switch (atoi(args[0])) {
4346 RLOGI ("Connection on debug port: issuing reset.");
4347 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
4350 RLOGI ("Connection on debug port: issuing radio power off.");
4352 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
4354 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4355 close(s_ril_param_socket.fdCommand);
4356 s_ril_param_socket.fdCommand = -1;
4358 #if (SIM_COUNT == 2)
4359 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4360 close(s_ril_param_socket2.fdCommand);
4361 s_ril_param_socket2.fdCommand = -1;
4366 RLOGI ("Debug port: issuing unsolicited voice network change.");
4367 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
4370 RLOGI ("Debug port: QXDM log enable.");
4371 qxdm_data[0] = 65536; // head.func_tag
4372 qxdm_data[1] = 16; // head.len
4373 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4374 qxdm_data[3] = 32; // log_file_size: 32megabytes
4375 qxdm_data[4] = 0; // log_mask
4376 qxdm_data[5] = 8; // log_max_fileindex
4377 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
4378 6 * sizeof(int), socket_id);
4381 RLOGI ("Debug port: QXDM log disable.");
4382 qxdm_data[0] = 65536;
4384 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4388 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
4389 6 * sizeof(int), socket_id);
4392 RLOGI("Debug port: Radio On");
4394 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
4396 // Set network selection automatic.
4397 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
4400 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
4401 actData[0] = args[1];
4402 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
4403 sizeof(actData), socket_id);
4406 RLOGI("Debug port: Deactivate Data Call");
4407 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
4408 sizeof(deactData), socket_id);
4411 RLOGI("Debug port: Dial Call");
4413 dialData.address = args[1];
4414 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
4417 RLOGI("Debug port: Answer Call");
4418 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
4421 RLOGI("Debug port: End Call");
4422 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
4423 sizeof(hangupData), socket_id);
4426 RLOGE ("Invalid request");
4429 freeDebugCallbackArgs(number, args);
4434 static void userTimerCallback (int fd, short flags, void *param) {
4435 UserCallbackInfo *p_info;
4437 p_info = (UserCallbackInfo *)param;
4439 p_info->p_callback(p_info->userParam);
4442 // FIXME generalize this...there should be a cancel mechanism
4443 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4444 s_last_wake_timeout_info = NULL;
4452 eventLoop(void *param) {
4458 pthread_mutex_lock(&s_startupMutex);
4461 pthread_cond_broadcast(&s_startupCond);
4463 pthread_mutex_unlock(&s_startupMutex);
4465 ret = pipe(filedes);
4468 RLOGE("Error in pipe() errno:%d", errno);
4472 s_fdWakeupRead = filedes[0];
4473 s_fdWakeupWrite = filedes[1];
4475 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4477 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4478 processWakeupCallback, NULL);
4480 rilEventAddWakeup (&s_wakeupfd_event);
4482 // Only returns on error
4484 RLOGE ("error in event_loop_base errno:%d", errno);
4485 // kill self to restart on error
4492 RIL_startEventLoop(void) {
4493 /* spin up eventLoop thread and wait for it to get started */
4495 pthread_mutex_lock(&s_startupMutex);
4497 pthread_attr_t attr;
4498 pthread_attr_init(&attr);
4499 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
4501 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4503 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4507 while (s_started == 0) {
4508 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4512 pthread_mutex_unlock(&s_startupMutex);
4515 // Used for testing purpose only.
4516 extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4517 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4520 static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4523 char socket_name[10];
4525 memset(socket_name, 0, sizeof(char)*10);
4529 strncpy(socket_name, RIL_getRilSocketName(), 9);
4531 #if (SIM_COUNT >= 2)
4533 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4536 #if (SIM_COUNT >= 3)
4538 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4541 #if (SIM_COUNT >= 4)
4543 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4547 RLOGE("Socket id is wrong!!");
4551 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4553 fdListen = android_get_control_socket(socket_name);
4555 RLOGE("Failed to get socket %s", socket_name);
4559 ret = listen(fdListen, 4);
4562 RLOGE("Failed to listen on control socket '%d': %s",
4563 fdListen, strerror(errno));
4566 socket_listen_p->fdListen = fdListen;
4568 /* note: non-persistent so we can accept only one connection at a time */
4569 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4570 listenCallback, socket_listen_p);
4572 rilEventAddWakeup (socket_listen_p->listen_event);
4576 RIL_register (const RIL_RadioFunctions *callbacks) {
4580 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4582 if (callbacks == NULL) {
4583 RLOGE("RIL_register: RIL_RadioFunctions * null");
4586 if (callbacks->version < RIL_VERSION_MIN) {
4587 RLOGE("RIL_register: version %d is to old, min version is %d",
4588 callbacks->version, RIL_VERSION_MIN);
4592 RLOGE("RIL_register: RIL version %d", callbacks->version);
4594 if (s_registerCalled > 0) {
4595 RLOGE("RIL_register has been called more than once. "
4596 "Subsequent call ignored");
4600 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4602 /* Initialize socket1 parameters */
4603 s_ril_param_socket = {
4604 RIL_SOCKET_1, /* socket_id */
4607 PHONE_PROCESS, /* processName */
4608 &s_commands_event, /* commands_event */
4609 &s_listen_event, /* listen_event */
4610 processCommandsCallback, /* processCommandsCallback */
4614 #if (SIM_COUNT >= 2)
4615 s_ril_param_socket2 = {
4616 RIL_SOCKET_2, /* socket_id */
4619 PHONE_PROCESS, /* processName */
4620 &s_commands_event_socket2, /* commands_event */
4621 &s_listen_event_socket2, /* listen_event */
4622 processCommandsCallback, /* processCommandsCallback */
4627 #if (SIM_COUNT >= 3)
4628 s_ril_param_socket3 = {
4629 RIL_SOCKET_3, /* socket_id */
4632 PHONE_PROCESS, /* processName */
4633 &s_commands_event_socket3, /* commands_event */
4634 &s_listen_event_socket3, /* listen_event */
4635 processCommandsCallback, /* processCommandsCallback */
4640 #if (SIM_COUNT >= 4)
4641 s_ril_param_socket4 = {
4642 RIL_SOCKET_4, /* socket_id */
4645 PHONE_PROCESS, /* processName */
4646 &s_commands_event_socket4, /* commands_event */
4647 &s_listen_event_socket4, /* listen_event */
4648 processCommandsCallback, /* processCommandsCallback */
4654 s_registerCalled = 1;
4656 RLOGI("s_registerCalled flag set, %d", s_started);
4657 // Little self-check
4659 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4660 assert(i == s_commands[i].requestNumber);
4663 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
4664 assert(i + RIL_UNSOL_RESPONSE_BASE
4665 == s_unsolResponses[i].requestNumber);
4668 // New rild impl calls RIL_startEventLoop() first
4669 // old standalone impl wants it here.
4671 if (s_started == 0) {
4672 RIL_startEventLoop();
4675 // start listen socket1
4676 startListen(RIL_SOCKET_1, &s_ril_param_socket);
4678 #if (SIM_COUNT >= 2)
4679 // start listen socket2
4680 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4681 #endif /* (SIM_COUNT == 2) */
4683 #if (SIM_COUNT >= 3)
4684 // start listen socket3
4685 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4686 #endif /* (SIM_COUNT == 3) */
4688 #if (SIM_COUNT >= 4)
4689 // start listen socket4
4690 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4691 #endif /* (SIM_COUNT == 4) */
4695 // start debug interface socket
4698 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4699 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4702 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4704 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4707 s_fdDebug = android_get_control_socket(rildebug);
4708 if (s_fdDebug < 0) {
4709 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
4713 ret = listen(s_fdDebug, 4);
4716 RLOGE("Failed to listen on ril debug socket '%d': %s",
4717 s_fdDebug, strerror(errno));
4721 ril_event_set (&s_debug_event, s_fdDebug, true,
4722 debugCallback, NULL);
4724 rilEventAddWakeup (&s_debug_event);
4730 RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4732 RIL_RadioFunctions* UimFuncs = NULL;
4735 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4737 switch(socketType) {
4738 case RIL_SAP_SOCKET:
4739 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4741 #if (SIM_COUNT >= 2)
4742 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4745 #if (SIM_COUNT >= 3)
4746 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4749 #if (SIM_COUNT >= 4)
4750 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4756 // Check and remove RequestInfo if its a response and not just ack sent back
4758 checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
4760 /* Hook for current context
4761 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4762 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4763 /* pendingRequestsHook refer to &s_pendingRequests */
4764 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
4770 #if (SIM_COUNT >= 2)
4771 if (pRI->socket_id == RIL_SOCKET_2) {
4772 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4773 pendingRequestsHook = &s_pendingRequests_socket2;
4775 #if (SIM_COUNT >= 3)
4776 if (pRI->socket_id == RIL_SOCKET_3) {
4777 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4778 pendingRequestsHook = &s_pendingRequests_socket3;
4781 #if (SIM_COUNT >= 4)
4782 if (pRI->socket_id == RIL_SOCKET_4) {
4783 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4784 pendingRequestsHook = &s_pendingRequests_socket4;
4788 pthread_mutex_lock(pendingRequestsMutexHook);
4790 for(RequestInfo **ppCur = pendingRequestsHook
4792 ; ppCur = &((*ppCur)->p_next)
4794 if (pRI == *ppCur) {
4796 if (isAck) { // Async ack
4797 if (pRI->wasAckSent == 1) {
4798 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4800 pRI->wasAckSent = 1;
4803 *ppCur = (*ppCur)->p_next;
4809 pthread_mutex_unlock(pendingRequestsMutexHook);
4814 static int findFd(int socket_id) {
4815 int fd = s_ril_param_socket.fdCommand;
4816 #if (SIM_COUNT >= 2)
4817 if (socket_id == RIL_SOCKET_2) {
4818 fd = s_ril_param_socket2.fdCommand;
4820 #if (SIM_COUNT >= 3)
4821 if (socket_id == RIL_SOCKET_3) {
4822 fd = s_ril_param_socket3.fdCommand;
4825 #if (SIM_COUNT >= 4)
4826 if (socket_id == RIL_SOCKET_4) {
4827 fd = s_ril_param_socket4.fdCommand;
4835 RIL_onRequestAck(RIL_Token t) {
4840 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4842 pRI = (RequestInfo *)t;
4844 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
4845 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
4849 socket_id = pRI->socket_id;
4850 fd = findFd(socket_id);
4853 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
4856 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
4858 if (pRI->cancelled == 0) {
4861 p.writeInt32 (RESPONSE_SOLICITED_ACK);
4862 p.writeInt32 (pRI->token);
4865 RLOGD ("RIL onRequestComplete: Command channel closed");
4868 sendResponse(p, socket_id);
4873 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4878 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4880 pRI = (RequestInfo *)t;
4882 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
4883 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4887 socket_id = pRI->socket_id;
4888 fd = findFd(socket_id);
4891 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4894 if (pRI->local > 0) {
4895 // Locally issued command...void only!
4896 // response does not go back up the command socket
4897 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
4902 appendPrintBuf("[%04d]< %s",
4903 pRI->token, requestToString(pRI->pCI->requestNumber));
4905 if (pRI->cancelled == 0) {
4908 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
4909 // If ack was already sent, then this call is an asynchronous response. So we need to
4910 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
4911 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
4912 grabPartialWakeLock();
4914 p.writeInt32 (RESPONSE_SOLICITED);
4916 p.writeInt32 (pRI->token);
4917 errorOffset = p.dataPosition();
4921 if (response != NULL) {
4922 // there is a response payload, no matter success or not.
4923 ret = pRI->pCI->responseFunction(p, response, responselen);
4925 /* if an error occurred, rewind and mark it */
4927 RLOGE ("responseFunction error, ret %d", ret);
4928 p.setDataPosition(errorOffset);
4933 if (e != RIL_E_SUCCESS) {
4934 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4938 RLOGD ("RIL onRequestComplete: Command channel closed");
4940 sendResponse(p, socket_id);
4948 grabPartialWakeLock() {
4949 if (s_callbacks.version >= 13) {
4951 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
4953 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4955 UserCallbackInfo *p_info =
4956 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
4957 if (p_info == NULL) {
4958 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4961 if (s_last_wake_timeout_info != NULL) {
4962 s_last_wake_timeout_info->userParam = (void *)1;
4964 s_last_wake_timeout_info = p_info;
4966 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
4969 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4975 if (s_callbacks.version >= 13) {
4977 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
4980 if (s_wakelock_count > 1) {
4983 s_wakelock_count = 0;
4984 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4985 if (s_last_wake_timeout_info != NULL) {
4986 s_last_wake_timeout_info->userParam = (void *)1;
4990 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
4993 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4998 * Timer callback to put us back to sleep before the default timeout
5001 wakeTimeoutCallback (void *param) {
5002 // We're using "param != NULL" as a cancellation mechanism
5003 if (s_callbacks.version >= 13) {
5004 if (param == NULL) {
5006 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5008 s_wakelock_count = 0;
5009 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5010 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5014 if (param == NULL) {
5021 decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5022 switch (radioState) {
5023 case RADIO_STATE_SIM_NOT_READY:
5024 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5025 case RADIO_STATE_SIM_READY:
5026 return RADIO_TECH_UMTS;
5028 case RADIO_STATE_RUIM_NOT_READY:
5029 case RADIO_STATE_RUIM_READY:
5030 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5031 case RADIO_STATE_NV_NOT_READY:
5032 case RADIO_STATE_NV_READY:
5033 return RADIO_TECH_1xRTT;
5036 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
5042 decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5043 switch (radioState) {
5044 case RADIO_STATE_SIM_NOT_READY:
5045 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5046 case RADIO_STATE_SIM_READY:
5047 case RADIO_STATE_RUIM_NOT_READY:
5048 case RADIO_STATE_RUIM_READY:
5049 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5050 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5052 case RADIO_STATE_NV_NOT_READY:
5053 case RADIO_STATE_NV_READY:
5054 return CDMA_SUBSCRIPTION_SOURCE_NV;
5057 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
5063 decodeSimStatus (RIL_RadioState radioState) {
5064 switch (radioState) {
5065 case RADIO_STATE_SIM_NOT_READY:
5066 case RADIO_STATE_RUIM_NOT_READY:
5067 case RADIO_STATE_NV_NOT_READY:
5068 case RADIO_STATE_NV_READY:
5070 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5071 case RADIO_STATE_SIM_READY:
5072 case RADIO_STATE_RUIM_READY:
5073 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5076 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
5081 static bool is3gpp2(int radioTech) {
5082 switch (radioTech) {
5083 case RADIO_TECH_IS95A:
5084 case RADIO_TECH_IS95B:
5085 case RADIO_TECH_1xRTT:
5086 case RADIO_TECH_EVDO_0:
5087 case RADIO_TECH_EVDO_A:
5088 case RADIO_TECH_EVDO_B:
5089 case RADIO_TECH_EHRPD:
5096 /* If RIL sends SIM states or RUIM states, store the voice radio
5097 * technology and subscription source information so that they can be
5098 * returned when telephony framework requests them
5100 static RIL_RadioState
5101 processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
5103 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5104 int newVoiceRadioTech;
5105 int newCdmaSubscriptionSource;
5108 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5109 from Radio State and send change notifications if there has been a change */
5110 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5111 if(newVoiceRadioTech != voiceRadioTech) {
5112 voiceRadioTech = newVoiceRadioTech;
5113 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5114 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
5116 if(is3gpp2(newVoiceRadioTech)) {
5117 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5118 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5119 cdmaSubscriptionSource = newCdmaSubscriptionSource;
5120 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5121 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
5124 newSimStatus = decodeSimStatus(newRadioState);
5125 if(newSimStatus != simRuimStatus) {
5126 simRuimStatus = newSimStatus;
5127 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
5130 /* Send RADIO_ON to telephony */
5131 newRadioState = RADIO_STATE_ON;
5134 return newRadioState;
5138 #if defined(ANDROID_MULTI_SIM)
5140 void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
5141 size_t datalen, RIL_SOCKET_ID socket_id)
5144 void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
5148 int unsolResponseIndex;
5150 int64_t timeReceived = 0;
5151 bool shouldScheduleTimeout = false;
5152 RIL_RadioState newState;
5153 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5155 #if defined(ANDROID_MULTI_SIM)
5160 if (s_registerCalled == 0) {
5161 // Ignore RIL_onUnsolicitedResponse before RIL_register
5162 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
5166 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5168 if ((unsolResponseIndex < 0)
5169 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
5170 RLOGE("unsupported unsolicited response code %d", unsolResponse);
5174 // Grab a wake lock if needed for this reponse,
5175 // as we exit we'll either release it immediately
5176 // or set a timer to release it later.
5177 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5179 grabPartialWakeLock();
5180 shouldScheduleTimeout = true;
5185 // No wake lock is grabed so don't set timeout
5186 shouldScheduleTimeout = false;
5190 // Mark the time this was received, doing this
5191 // after grabing the wakelock incase getting
5192 // the elapsedRealTime might cause us to goto
5194 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5195 timeReceived = elapsedRealtime();
5198 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5201 if (s_callbacks.version >= 13
5202 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
5203 p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
5205 p.writeInt32 (RESPONSE_UNSOLICITED);
5207 p.writeInt32 (unsolResponse);
5209 ret = s_unsolResponses[unsolResponseIndex]
5210 .responseFunction(p, const_cast<void*>(data), datalen);
5212 // Problem with the response. Don't continue;
5216 // some things get more payload
5217 switch(unsolResponse) {
5218 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
5219 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
5220 p.writeInt32(newState);
5221 appendPrintBuf("%s {%s}", printBuf,
5222 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
5226 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5227 // Store the time that this was received so the
5228 // handler of this message can account for
5229 // the time it takes to arrive and process. In
5230 // particular the system has been known to sleep
5231 // before this message can be processed.
5232 p.writeInt64(timeReceived);
5236 if (s_callbacks.version < 13) {
5237 if (shouldScheduleTimeout) {
5238 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5239 &TIMEVAL_WAKE_TIMEOUT);
5241 if (p_info == NULL) {
5244 // Cancel the previous request
5245 if (s_last_wake_timeout_info != NULL) {
5246 s_last_wake_timeout_info->userParam = (void *)1;
5248 s_last_wake_timeout_info = p_info;
5254 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
5256 ret = sendResponse(p, soc_id);
5257 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5259 // Unfortunately, NITZ time is not poll/update like everything
5260 // else in the system. So, if the upstream client isn't connected,
5261 // keep a copy of the last NITZ response (with receive time noted
5262 // above) around so we can deliver it when it is connected
5264 if (s_lastNITZTimeData != NULL) {
5265 free (s_lastNITZTimeData);
5266 s_lastNITZTimeData = NULL;
5269 s_lastNITZTimeData = calloc(p.dataSize(), 1);
5270 if (s_lastNITZTimeData == NULL) {
5271 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5274 s_lastNITZTimeDataSize = p.dataSize();
5275 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5282 if (shouldScheduleTimeout) {
5287 /** FIXME generalize this if you track UserCAllbackInfo, clear it
5288 when the callback occurs
5290 static UserCallbackInfo *
5291 internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5292 const struct timeval *relativeTime)
5294 struct timeval myRelativeTime;
5295 UserCallbackInfo *p_info;
5297 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
5298 if (p_info == NULL) {
5299 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5304 p_info->p_callback = callback;
5305 p_info->userParam = param;
5307 if (relativeTime == NULL) {
5308 /* treat null parameter as a 0 relative time */
5309 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5311 /* FIXME I think event_add's tv param is really const anyway */
5312 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5315 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5317 ril_timer_add(&(p_info->event), &myRelativeTime);
5325 RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5326 const struct timeval *relativeTime) {
5327 internalRequestTimedCallback (callback, param, relativeTime);
5331 failCauseToString(RIL_Errno e) {
5333 case RIL_E_SUCCESS: return "E_SUCCESS";
5334 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
5335 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5336 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5337 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5338 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5339 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5340 case RIL_E_CANCELLED: return "E_CANCELLED";
5341 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5342 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5343 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5344 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5345 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5346 #ifdef FEATURE_MULTIMODE_ANDROID
5347 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5348 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5350 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5351 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5352 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5353 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5354 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5355 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5356 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5357 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5358 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5359 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5360 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5361 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5362 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5363 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5364 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5365 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5366 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5367 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5368 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5369 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5370 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5371 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5372 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5373 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5374 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5375 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5376 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5377 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
5378 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5379 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5380 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5381 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5382 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
5383 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
5384 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
5385 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
5386 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
5387 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
5388 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
5389 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
5390 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
5391 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
5392 case RIL_E_ABORTED: return "E_ABORTED";
5393 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5394 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5395 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5396 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5397 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5398 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5399 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5400 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5401 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5402 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5403 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5404 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5405 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5406 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5407 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5408 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5409 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5410 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5411 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5412 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5413 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5414 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5415 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5416 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5417 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
5418 default: return "<unknown error>";
5423 radioStateToString(RIL_RadioState s) {
5425 case RADIO_STATE_OFF: return "RADIO_OFF";
5426 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5427 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5428 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5429 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5430 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5431 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5432 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5433 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5434 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5435 case RADIO_STATE_ON:return"RADIO_ON";
5436 default: return "<unknown state>";
5441 callStateToString(RIL_CallState s) {
5443 case RIL_CALL_ACTIVE : return "ACTIVE";
5444 case RIL_CALL_HOLDING: return "HOLDING";
5445 case RIL_CALL_DIALING: return "DIALING";
5446 case RIL_CALL_ALERTING: return "ALERTING";
5447 case RIL_CALL_INCOMING: return "INCOMING";
5448 case RIL_CALL_WAITING: return "WAITING";
5449 default: return "<unknown state>";
5454 requestToString(int request) {
5456 cat libs/telephony/ril_commands.h \
5457 | egrep "^ *{RIL_" \
5458 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5461 cat libs/telephony/ril_unsol_commands.h \
5462 | egrep "^ *{RIL_" \
5463 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5467 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5468 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5469 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5470 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5471 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5472 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5473 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5474 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5475 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5476 case RIL_REQUEST_DIAL: return "DIAL";
5477 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5478 case RIL_REQUEST_HANGUP: return "HANGUP";
5479 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5480 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5481 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5482 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5483 case RIL_REQUEST_UDUB: return "UDUB";
5484 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5485 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5486 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5487 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5488 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5489 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5490 case RIL_REQUEST_DTMF: return "DTMF";
5491 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5492 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5493 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5494 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5495 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5496 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5497 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5498 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5499 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5500 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5501 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5502 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5503 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5504 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5505 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5506 case RIL_REQUEST_ANSWER: return "ANSWER";
5507 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5508 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5509 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5510 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5511 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5512 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5513 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5514 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5515 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5516 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5517 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5518 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5519 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5520 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5521 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5522 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5523 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5524 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5525 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5526 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5527 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
5528 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5529 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5530 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5531 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5532 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5533 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5534 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5535 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5536 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5537 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5538 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5539 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5540 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
5541 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
5542 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5543 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5544 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5545 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5546 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5547 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5548 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5549 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5550 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5551 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5552 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5553 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5554 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5555 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5556 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
5557 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
5558 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5559 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5560 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5561 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5562 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5563 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5564 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5565 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5566 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5567 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5568 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5569 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5570 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5571 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
5572 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
5573 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5574 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
5575 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5576 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5577 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
5578 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5579 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5580 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5581 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
5582 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5583 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
5584 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5585 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5586 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5587 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5588 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5589 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5590 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
5591 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5592 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5593 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5594 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5595 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5596 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5597 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5598 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5599 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5600 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5601 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
5602 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5603 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5604 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5605 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5606 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5607 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
5608 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5609 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5610 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5611 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5612 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5613 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5614 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5615 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5616 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5617 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5618 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5619 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5620 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5621 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5622 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5623 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5624 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5625 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5626 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
5627 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
5628 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
5629 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5630 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5631 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5632 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
5633 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
5634 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
5635 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
5636 default: return "<unknown request>";
5641 rilSocketIdToString(RIL_SOCKET_ID socket_id)
5645 return "RIL_SOCKET_1";
5646 #if (SIM_COUNT >= 2)
5648 return "RIL_SOCKET_2";
5650 #if (SIM_COUNT >= 3)
5652 return "RIL_SOCKET_3";
5654 #if (SIM_COUNT >= 4)
5656 return "RIL_SOCKET_4";
5659 return "not a valid RIL";
5664 * Returns true for a debuggable build.
5666 static bool isDebuggable() {
5667 char debuggable[PROP_VALUE_MAX];
5668 property_get("ro.debuggable", debuggable, "0");
5669 if (strcmp(debuggable, "1") == 0) {
5675 } /* namespace android */
5677 void rilEventAddWakeup_helper(struct ril_event *ev) {
5678 android::rilEventAddWakeup(ev);
5681 void listenCallback_helper(int fd, short flags, void *param) {
5682 android::listenCallback(fd, flags, param);
5685 int blockingWrite_helper(int fd, void *buffer, size_t len) {
5686 return android::blockingWrite(fd, buffer, len);