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 void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI);
286 static int responseInts(Parcel &p, void *response, size_t responselen);
287 static int responseFailCause(Parcel &p, void *response, size_t responselen);
288 static int responseStrings(Parcel &p, void *response, size_t responselen);
289 static int responseString(Parcel &p, void *response, size_t responselen);
290 static int responseVoid(Parcel &p, void *response, size_t responselen);
291 static int responseCallList(Parcel &p, void *response, size_t responselen);
292 static int responseSMS(Parcel &p, void *response, size_t responselen);
293 static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
294 static int responseCallForwards(Parcel &p, void *response, size_t responselen);
295 static int responseDataCallList(Parcel &p, void *response, size_t responselen);
296 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
297 static int responseRaw(Parcel &p, void *response, size_t responselen);
298 static int responseSsn(Parcel &p, void *response, size_t responselen);
299 static int responseSimStatus(Parcel &p, void *response, size_t responselen);
300 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
301 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
302 static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
303 static int responseCellList(Parcel &p, void *response, size_t responselen);
304 static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
305 static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
306 static int responseCallRing(Parcel &p, void *response, size_t responselen);
307 static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
308 static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
309 static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
310 static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
311 static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
312 static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
313 static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
314 static int responseSSData(Parcel &p, void *response, size_t responselen);
315 static int responseLceStatus(Parcel &p, void *response, size_t responselen);
316 static int responseLceData(Parcel &p, void *response, size_t responselen);
317 static int responseActivityData(Parcel &p, void *response, size_t responselen);
318 static int responseCarrierRestrictions(Parcel &p, void *response, size_t responselen);
319 static int responsePcoData(Parcel &p, void *response, size_t responselen);
321 static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
322 static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
323 static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
324 static void grabPartialWakeLock();
325 static void releaseWakeLock();
326 static void wakeTimeoutCallback(void *);
328 static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
330 static bool isDebuggable();
333 #if defined(ANDROID_MULTI_SIM)
334 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
335 size_t datalen, RIL_SOCKET_ID socket_id);
337 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
342 #if defined(ANDROID_MULTI_SIM)
343 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
344 #define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
345 #define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
347 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
348 #define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
349 #define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
352 static UserCallbackInfo * internalRequestTimedCallback
353 (RIL_TimedCallback callback, void *param,
354 const struct timeval *relativeTime);
356 /** Index == requestNumber */
357 static CommandInfo s_commands[] = {
358 #include "ril_commands.h"
361 static UnsolResponseInfo s_unsolResponses[] = {
362 #include "ril_unsol_commands.h"
365 /* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
366 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
367 radio state message and store it. Every time there is a change in Radio State
368 check to see if voice radio tech changes and notify telephony
370 int voiceRadioTech = -1;
372 /* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
373 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
374 source from radio state and store it. Every time there is a change in Radio State
375 check to see if subscription source changed and notify telephony
377 int cdmaSubscriptionSource = -1;
379 /* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
380 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
381 check to see if SIM/RUIM status changed and notify telephony
383 int simRuimStatus = -1;
385 static char * RIL_getRilSocketName() {
390 void RIL_setRilSocketName(const char * s) {
391 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
395 strdupReadString(Parcel &p) {
399 s16 = p.readString16Inplace(&stringlen);
401 return strndup16to8(s16, stringlen);
405 readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
409 s16 = p.readString16Inplace(&s16Len);
413 size_t strLen = strnlen16to8(s16, s16Len);
414 if ((strLen + 1) > maxLen) {
417 if (strncpy16to8(str, s16, strLen) == NULL) {
424 static void writeStringToParcel(Parcel &p, const char *s) {
427 s16 = strdup8to16(s, &s16_len);
428 p.writeString16(s16, s16_len);
434 memsetString (char *s) {
436 memset (s, 0, strlen(s));
440 void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
441 const size_t* objects, size_t objectsSize,
443 // do nothing -- the data reference lives longer than the Parcel object
447 * To be called from dispatch thread
448 * Issue a single local request, ensuring that the response
449 * is not sent back up to the command process
452 issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
455 /* Hook for current context */
456 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
457 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
458 /* pendingRequestsHook refer to &s_pendingRequests */
459 RequestInfo** pendingRequestsHook = &s_pendingRequests;
462 if (socket_id == RIL_SOCKET_2) {
463 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
464 pendingRequestsHook = &s_pendingRequests_socket2;
468 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
470 RLOGE("Memory allocation failed for request %s", requestToString(request));
475 pRI->token = 0xffffffff; // token is not used in this context
476 pRI->pCI = &(s_commands[request]);
477 pRI->socket_id = socket_id;
479 ret = pthread_mutex_lock(pendingRequestsMutexHook);
482 pRI->p_next = *pendingRequestsHook;
483 *pendingRequestsHook = pRI;
485 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
488 RLOGD("C[locl]> %s", requestToString(request));
490 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
496 processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
503 /* Hook for current context */
504 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
505 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
506 /* pendingRequestsHook refer to &s_pendingRequests */
507 RequestInfo** pendingRequestsHook = &s_pendingRequests;
509 p.setData((uint8_t *) buffer, buflen);
511 // status checked at end
512 status = p.readInt32(&request);
513 status = p.readInt32 (&token);
516 if (socket_id == RIL_SOCKET_2) {
517 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
518 pendingRequestsHook = &s_pendingRequests_socket2;
521 else if (socket_id == RIL_SOCKET_3) {
522 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
523 pendingRequestsHook = &s_pendingRequests_socket3;
527 else if (socket_id == RIL_SOCKET_4) {
528 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
529 pendingRequestsHook = &s_pendingRequests_socket4;
534 if (status != NO_ERROR) {
535 RLOGE("invalid request block");
539 // Received an Ack for the previous result sent to RIL.java,
540 // so release wakelock and exit
541 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
546 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
548 RLOGE("unsupported request code %d token %d", request, token);
549 // FIXME this should perhaps return a response
550 pErr.writeInt32 (RESPONSE_SOLICITED);
551 pErr.writeInt32 (token);
552 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
554 sendResponse(pErr, socket_id);
558 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
560 RLOGE("Memory allocation failed for request %s", requestToString(request));
565 pRI->pCI = &(s_commands[request]);
566 pRI->socket_id = socket_id;
568 ret = pthread_mutex_lock(pendingRequestsMutexHook);
571 pRI->p_next = *pendingRequestsHook;
572 *pendingRequestsHook = pRI;
574 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
577 /* sLastDispatchedToken = token; */
579 pRI->pCI->dispatchFunction(p, pRI);
585 invalidCommandBlock (RequestInfo *pRI) {
586 RLOGE("invalid command block for token %d request %s",
587 pRI->token, requestToString(pRI->pCI->requestNumber));
590 /** Callee expects NULL */
592 dispatchVoid (Parcel& p, RequestInfo *pRI) {
594 printRequest(pRI->token, pRI->pCI->requestNumber);
595 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
598 /** Callee expects const char * */
600 dispatchString (Parcel& p, RequestInfo *pRI) {
604 char *string8 = NULL;
606 string8 = strdupReadString(p);
609 appendPrintBuf("%s%s", printBuf, string8);
611 printRequest(pRI->token, pRI->pCI->requestNumber);
613 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
614 sizeof(char *), pRI, pRI->socket_id);
617 memsetString(string8);
623 invalidCommandBlock(pRI);
627 /** Callee expects const char ** */
629 dispatchStrings (Parcel &p, RequestInfo *pRI) {
630 int32_t countStrings;
635 status = p.readInt32 (&countStrings);
637 if (status != NO_ERROR) {
642 if (countStrings == 0) {
643 // just some non-null pointer
644 pStrings = (char **)calloc(1, sizeof(char *));
645 if (pStrings == NULL) {
646 RLOGE("Memory allocation failed for request %s",
647 requestToString(pRI->pCI->requestNumber));
653 } else if (countStrings < 0) {
657 datalen = sizeof(char *) * countStrings;
659 pStrings = (char **)calloc(countStrings, sizeof(char *));
660 if (pStrings == NULL) {
661 RLOGE("Memory allocation failed for request %s",
662 requestToString(pRI->pCI->requestNumber));
667 for (int i = 0 ; i < countStrings ; i++) {
668 pStrings[i] = strdupReadString(p);
669 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
674 printRequest(pRI->token, pRI->pCI->requestNumber);
676 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
678 if (pStrings != NULL) {
679 for (int i = 0 ; i < countStrings ; i++) {
681 memsetString (pStrings[i]);
687 memset(pStrings, 0, datalen);
694 invalidCommandBlock(pRI);
698 /** Callee expects const int * */
700 dispatchInts (Parcel &p, RequestInfo *pRI) {
706 status = p.readInt32 (&count);
708 if (status != NO_ERROR || count <= 0) {
712 datalen = sizeof(int) * count;
713 pInts = (int *)calloc(count, sizeof(int));
715 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
720 for (int i = 0 ; i < count ; i++) {
723 status = p.readInt32(&t);
725 appendPrintBuf("%s%d,", printBuf, t);
727 if (status != NO_ERROR) {
734 printRequest(pRI->token, pRI->pCI->requestNumber);
736 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
737 datalen, pRI, pRI->socket_id);
740 memset(pInts, 0, datalen);
745 invalidCommandBlock(pRI);
751 * Callee expects const RIL_SMS_WriteArgs *
757 dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
758 RIL_SMS_WriteArgs args;
762 RLOGD("dispatchSmsWrite");
763 memset (&args, 0, sizeof(args));
765 status = p.readInt32(&t);
766 args.status = (int)t;
768 args.pdu = strdupReadString(p);
770 if (status != NO_ERROR || args.pdu == NULL) {
774 args.smsc = strdupReadString(p);
777 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
778 (char*)args.pdu, (char*)args.smsc);
780 printRequest(pRI->token, pRI->pCI->requestNumber);
782 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
785 memsetString (args.pdu);
791 memset(&args, 0, sizeof(args));
796 invalidCommandBlock(pRI);
801 * Callee expects const RIL_Dial *
807 dispatchDial (Parcel &p, RequestInfo *pRI) {
809 RIL_UUS_Info uusInfo;
815 RLOGD("dispatchDial");
816 memset (&dial, 0, sizeof(dial));
818 dial.address = strdupReadString(p);
820 status = p.readInt32(&t);
823 if (status != NO_ERROR || dial.address == NULL) {
827 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
829 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
831 status = p.readInt32(&uusPresent);
833 if (status != NO_ERROR) {
837 if (uusPresent == 0) {
842 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
844 status = p.readInt32(&t);
845 uusInfo.uusType = (RIL_UUS_Type) t;
847 status = p.readInt32(&t);
848 uusInfo.uusDcs = (RIL_UUS_DCS) t;
850 status = p.readInt32(&len);
851 if (status != NO_ERROR) {
855 // The java code writes -1 for null arrays
856 if (((int) len) == -1) {
857 uusInfo.uusData = NULL;
860 uusInfo.uusData = (char*) p.readInplace(len);
863 uusInfo.uusLength = len;
864 dial.uusInfo = &uusInfo;
866 sizeOfDial = sizeof(dial);
870 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
872 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
873 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
874 dial.uusInfo->uusLength);
877 printRequest(pRI->token, pRI->pCI->requestNumber);
879 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
882 memsetString (dial.address);
888 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
889 memset(&dial, 0, sizeof(dial));
894 invalidCommandBlock(pRI);
899 * Callee expects const RIL_SIM_IO *
910 dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
921 RLOGD("dispatchSIM_IO");
923 memset (&simIO, 0, sizeof(simIO));
925 // note we only check status at the end
927 status = p.readInt32(&t);
928 simIO.v6.command = (int)t;
930 status = p.readInt32(&t);
931 simIO.v6.fileid = (int)t;
933 simIO.v6.path = strdupReadString(p);
935 status = p.readInt32(&t);
936 simIO.v6.p1 = (int)t;
938 status = p.readInt32(&t);
939 simIO.v6.p2 = (int)t;
941 status = p.readInt32(&t);
942 simIO.v6.p3 = (int)t;
944 simIO.v6.data = strdupReadString(p);
945 simIO.v6.pin2 = strdupReadString(p);
946 simIO.v6.aidPtr = strdupReadString(p);
949 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
950 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
951 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
952 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
954 printRequest(pRI->token, pRI->pCI->requestNumber);
956 if (status != NO_ERROR) {
960 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
961 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
964 memsetString (simIO.v6.path);
965 memsetString (simIO.v6.data);
966 memsetString (simIO.v6.pin2);
967 memsetString (simIO.v6.aidPtr);
970 free (simIO.v6.path);
971 free (simIO.v6.data);
972 free (simIO.v6.pin2);
973 free (simIO.v6.aidPtr);
976 memset(&simIO, 0, sizeof(simIO));
981 invalidCommandBlock(pRI);
986 * Callee expects const RIL_SIM_APDU *
990 * int32_t instruction
995 dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
1001 RLOGD("dispatchSIM_APDU");
1003 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1005 // Note we only check status at the end. Any single failure leads to
1006 // subsequent reads filing.
1007 status = p.readInt32(&t);
1008 apdu.sessionid = (int)t;
1010 status = p.readInt32(&t);
1013 status = p.readInt32(&t);
1014 apdu.instruction = (int)t;
1016 status = p.readInt32(&t);
1019 status = p.readInt32(&t);
1022 status = p.readInt32(&t);
1025 apdu.data = strdupReadString(p);
1028 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1029 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1030 apdu.p3, (char*)apdu.data);
1032 printRequest(pRI->token, pRI->pCI->requestNumber);
1034 if (status != NO_ERROR) {
1038 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1041 memsetString(apdu.data);
1046 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1051 invalidCommandBlock(pRI);
1057 * Callee expects const RIL_CallForwardInfo *
1059 * int32_t status/action
1061 * int32_t serviceCode
1063 * String number (0 length -> null)
1064 * int32_t timeSeconds
1067 dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1068 RIL_CallForwardInfo cff;
1072 RLOGD("dispatchCallForward");
1073 memset (&cff, 0, sizeof(cff));
1075 // note we only check status at the end
1077 status = p.readInt32(&t);
1078 cff.status = (int)t;
1080 status = p.readInt32(&t);
1081 cff.reason = (int)t;
1083 status = p.readInt32(&t);
1084 cff.serviceClass = (int)t;
1086 status = p.readInt32(&t);
1089 cff.number = strdupReadString(p);
1091 status = p.readInt32(&t);
1092 cff.timeSeconds = (int)t;
1094 if (status != NO_ERROR) {
1098 // special case: number 0-length fields is null
1100 if (cff.number != NULL && strlen (cff.number) == 0) {
1105 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1106 cff.status, cff.reason, cff.serviceClass, cff.toa,
1107 (char*)cff.number, cff.timeSeconds);
1109 printRequest(pRI->token, pRI->pCI->requestNumber);
1111 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
1114 memsetString(cff.number);
1120 memset(&cff, 0, sizeof(cff));
1125 invalidCommandBlock(pRI);
1131 dispatchRaw(Parcel &p, RequestInfo *pRI) {
1136 status = p.readInt32(&len);
1138 if (status != NO_ERROR) {
1142 // The java code writes -1 for null arrays
1143 if (((int)len) == -1) {
1148 data = p.readInplace(len);
1151 appendPrintBuf("%sraw_size=%d", printBuf, len);
1153 printRequest(pRI->token, pRI->pCI->requestNumber);
1155 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
1159 invalidCommandBlock(pRI);
1164 constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
1171 memset(&rcsm, 0, sizeof(rcsm));
1173 status = p.readInt32(&t);
1174 rcsm.uTeleserviceID = (int) t;
1176 status = p.read(&ut,sizeof(ut));
1177 rcsm.bIsServicePresent = (uint8_t) ut;
1179 status = p.readInt32(&t);
1180 rcsm.uServicecategory = (int) t;
1182 status = p.readInt32(&t);
1183 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1185 status = p.readInt32(&t);
1186 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1188 status = p.readInt32(&t);
1189 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1191 status = p.readInt32(&t);
1192 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1194 status = p.read(&ut,sizeof(ut));
1195 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1197 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1198 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1199 status = p.read(&ut,sizeof(ut));
1200 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1203 status = p.readInt32(&t);
1204 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1206 status = p.read(&ut,sizeof(ut));
1207 rcsm.sSubAddress.odd = (uint8_t) ut;
1209 status = p.read(&ut,sizeof(ut));
1210 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1212 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1213 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1214 status = p.read(&ut,sizeof(ut));
1215 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1218 status = p.readInt32(&t);
1219 rcsm.uBearerDataLen = (int) t;
1221 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1222 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1223 status = p.read(&ut, sizeof(ut));
1224 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1227 if (status != NO_ERROR) {
1232 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1233 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1234 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1235 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1238 printRequest(pRI->token, pRI->pCI->requestNumber);
1244 dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1245 RIL_CDMA_SMS_Message rcsm;
1247 RLOGD("dispatchCdmaSms");
1248 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1252 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
1255 memset(&rcsm, 0, sizeof(rcsm));
1261 invalidCommandBlock(pRI);
1266 dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1267 RIL_IMS_SMS_Message rism;
1268 RIL_CDMA_SMS_Message rcsm;
1270 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1272 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1275 memset(&rism, 0, sizeof(rism));
1276 rism.tech = RADIO_TECH_3GPP2;
1278 rism.messageRef = messageRef;
1279 rism.message.cdmaMessage = &rcsm;
1281 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
1282 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1283 +sizeof(rcsm),pRI, pRI->socket_id);
1286 memset(&rcsm, 0, sizeof(rcsm));
1287 memset(&rism, 0, sizeof(rism));
1293 invalidCommandBlock(pRI);
1298 dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1299 RIL_IMS_SMS_Message rism;
1300 int32_t countStrings;
1304 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1306 status = p.readInt32 (&countStrings);
1308 if (status != NO_ERROR) {
1312 memset(&rism, 0, sizeof(rism));
1313 rism.tech = RADIO_TECH_3GPP;
1315 rism.messageRef = messageRef;
1318 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1319 (int)rism.tech, (int)rism.retry, rism.messageRef);
1320 if (countStrings == 0) {
1321 // just some non-null pointer
1322 pStrings = (char **)calloc(1, sizeof(char *));
1323 if (pStrings == NULL) {
1324 RLOGE("Memory allocation failed for request %s",
1325 requestToString(pRI->pCI->requestNumber));
1331 } else if (countStrings < 0) {
1335 if ((size_t)countStrings > (INT_MAX/sizeof(char *))) {
1336 RLOGE("Invalid value of countStrings: \n");
1340 datalen = sizeof(char *) * countStrings;
1342 pStrings = (char **)calloc(countStrings, sizeof(char *));
1343 if (pStrings == NULL) {
1344 RLOGE("Memory allocation failed for request %s",
1345 requestToString(pRI->pCI->requestNumber));
1350 for (int i = 0 ; i < countStrings ; i++) {
1351 pStrings[i] = strdupReadString(p);
1352 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1357 printRequest(pRI->token, pRI->pCI->requestNumber);
1359 rism.message.gsmMessage = pStrings;
1360 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
1361 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1362 +datalen, pRI, pRI->socket_id);
1364 if (pStrings != NULL) {
1365 for (int i = 0 ; i < countStrings ; i++) {
1367 memsetString (pStrings[i]);
1373 memset(pStrings, 0, datalen);
1379 memset(&rism, 0, sizeof(rism));
1383 ALOGE("dispatchImsGsmSms invalid block");
1384 invalidCommandBlock(pRI);
1389 dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1391 status_t status = p.readInt32(&t);
1392 RIL_RadioTechnologyFamily format;
1396 RLOGD("dispatchImsSms");
1397 if (status != NO_ERROR) {
1400 format = (RIL_RadioTechnologyFamily) t;
1403 status = p.read(&retry,sizeof(retry));
1404 if (status != NO_ERROR) {
1407 // read messageRef field
1408 status = p.read(&messageRef,sizeof(messageRef));
1409 if (status != NO_ERROR) {
1413 if (RADIO_TECH_3GPP == format) {
1414 dispatchImsGsmSms(p, pRI, retry, messageRef);
1415 } else if (RADIO_TECH_3GPP2 == format) {
1416 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1418 ALOGE("requestImsSendSMS invalid format value =%d", format);
1424 invalidCommandBlock(pRI);
1429 dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1430 RIL_CDMA_SMS_Ack rcsa;
1435 RLOGD("dispatchCdmaSmsAck");
1436 memset(&rcsa, 0, sizeof(rcsa));
1438 status = p.readInt32(&t);
1439 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1441 status = p.readInt32(&t);
1442 rcsa.uSMSCauseCode = (int) t;
1444 if (status != NO_ERROR) {
1449 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1450 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1453 printRequest(pRI->token, pRI->pCI->requestNumber);
1455 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
1458 memset(&rcsa, 0, sizeof(rcsa));
1464 invalidCommandBlock(pRI);
1469 dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1474 status = p.readInt32(&num);
1475 if (status != NO_ERROR) {
1480 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1481 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
1484 for (int i = 0 ; i < num ; i++ ) {
1485 gsmBciPtrs[i] = &gsmBci[i];
1487 status = p.readInt32(&t);
1488 gsmBci[i].fromServiceId = (int) t;
1490 status = p.readInt32(&t);
1491 gsmBci[i].toServiceId = (int) t;
1493 status = p.readInt32(&t);
1494 gsmBci[i].fromCodeScheme = (int) t;
1496 status = p.readInt32(&t);
1497 gsmBci[i].toCodeScheme = (int) t;
1499 status = p.readInt32(&t);
1500 gsmBci[i].selected = (uint8_t) t;
1502 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1503 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1504 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1505 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1506 gsmBci[i].selected);
1510 if (status != NO_ERROR) {
1514 CALL_ONREQUEST(pRI->pCI->requestNumber,
1516 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1517 pRI, pRI->socket_id);
1520 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1521 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
1528 invalidCommandBlock(pRI);
1533 dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1538 status = p.readInt32(&num);
1539 if (status != NO_ERROR) {
1544 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1545 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
1548 for (int i = 0 ; i < num ; i++ ) {
1549 cdmaBciPtrs[i] = &cdmaBci[i];
1551 status = p.readInt32(&t);
1552 cdmaBci[i].service_category = (int) t;
1554 status = p.readInt32(&t);
1555 cdmaBci[i].language = (int) t;
1557 status = p.readInt32(&t);
1558 cdmaBci[i].selected = (uint8_t) t;
1560 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1561 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1562 cdmaBci[i].language, cdmaBci[i].selected);
1566 if (status != NO_ERROR) {
1570 CALL_ONREQUEST(pRI->pCI->requestNumber,
1572 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1573 pRI, pRI->socket_id);
1576 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1577 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
1584 invalidCommandBlock(pRI);
1588 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1589 RIL_CDMA_SMS_WriteArgs rcsw;
1597 memset(&rcsw, 0, sizeof(rcsw));
1599 status = p.readInt32(&t);
1602 status = p.readInt32(&t);
1603 rcsw.message.uTeleserviceID = (int) t;
1605 status = p.read(&uct,sizeof(uct));
1606 rcsw.message.bIsServicePresent = (uint8_t) uct;
1608 status = p.readInt32(&t);
1609 rcsw.message.uServicecategory = (int) t;
1611 status = p.readInt32(&t);
1612 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1614 status = p.readInt32(&t);
1615 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1617 status = p.readInt32(&t);
1618 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1620 status = p.readInt32(&t);
1621 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1623 status = p.read(&uct,sizeof(uct));
1624 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1626 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1628 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1629 status = p.read(&uct,sizeof(uct));
1630 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1633 status = p.readInt32(&t);
1634 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1636 status = p.read(&uct,sizeof(uct));
1637 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1639 status = p.read(&uct,sizeof(uct));
1640 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1642 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1644 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1645 status = p.read(&uct,sizeof(uct));
1646 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1649 status = p.readInt32(&t);
1650 rcsw.message.uBearerDataLen = (int) t;
1652 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1654 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
1655 status = p.read(&uct, sizeof(uct));
1656 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1659 if (status != NO_ERROR) {
1664 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1665 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1666 message.sAddress.number_mode=%d, \
1667 message.sAddress.number_type=%d, ",
1668 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1669 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1670 rcsw.message.sAddress.number_mode,
1671 rcsw.message.sAddress.number_type);
1674 printRequest(pRI->token, pRI->pCI->requestNumber);
1676 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
1679 memset(&rcsw, 0, sizeof(rcsw));
1685 invalidCommandBlock(pRI);
1690 // For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1691 // Version 4 of the RIL interface adds a new PDP type parameter to support
1692 // IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1693 // RIL, remove the parameter from the request.
1694 static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1695 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1696 const int numParamsRilV3 = 6;
1698 // The first bytes of the RIL parcel contain the request number and the
1699 // serial number - see processCommandBuffer(). Copy them over too.
1700 int pos = p.dataPosition();
1702 int numParams = p.readInt32();
1703 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1705 p2.appendFrom(&p, 0, pos);
1706 p2.writeInt32(numParamsRilV3);
1707 for(int i = 0; i < numParamsRilV3; i++) {
1708 p2.writeString16(p.readString16());
1710 p2.setDataPosition(pos);
1711 dispatchStrings(p2, pRI);
1713 p.setDataPosition(pos);
1714 dispatchStrings(p, pRI);
1718 // For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1719 // When all RILs handle this request, this function can be removed and
1720 // the request can be sent directly to the RIL using dispatchVoid.
1721 static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
1722 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
1724 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1725 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1728 // RILs that support RADIO_STATE_ON should support this request.
1729 if (RADIO_STATE_ON == state) {
1730 dispatchVoid(p, pRI);
1734 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1735 // will not support this new request either and decode Voice Radio Technology
1737 voiceRadioTech = decodeVoiceRadioTechnology(state);
1739 if (voiceRadioTech < 0)
1740 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1742 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1745 // For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1746 // When all RILs handle this request, this function can be removed and
1747 // the request can be sent directly to the RIL using dispatchVoid.
1748 static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
1749 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
1751 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1752 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1755 // RILs that support RADIO_STATE_ON should support this request.
1756 if (RADIO_STATE_ON == state) {
1757 dispatchVoid(p, pRI);
1761 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1762 // will not support this new request either and decode CDMA Subscription Source
1764 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1766 if (cdmaSubscriptionSource < 0)
1767 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1769 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1772 static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1774 RIL_InitialAttachApn pf;
1778 memset(&pf, 0, sizeof(pf));
1780 pf.apn = strdupReadString(p);
1781 pf.protocol = strdupReadString(p);
1783 status = p.readInt32(&t);
1784 pf.authtype = (int) t;
1786 pf.username = strdupReadString(p);
1787 pf.password = strdupReadString(p);
1790 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1791 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
1793 printRequest(pRI->token, pRI->pCI->requestNumber);
1795 if (status != NO_ERROR) {
1798 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1801 memsetString(pf.apn);
1802 memsetString(pf.protocol);
1803 memsetString(pf.username);
1804 memsetString(pf.password);
1813 memset(&pf, 0, sizeof(pf));
1818 invalidCommandBlock(pRI);
1822 static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1823 RIL_NV_ReadItem nvri;
1827 memset(&nvri, 0, sizeof(nvri));
1829 status = p.readInt32(&t);
1830 nvri.itemID = (RIL_NV_Item) t;
1832 if (status != NO_ERROR) {
1837 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1840 printRequest(pRI->token, pRI->pCI->requestNumber);
1842 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1845 memset(&nvri, 0, sizeof(nvri));
1851 invalidCommandBlock(pRI);
1855 static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1856 RIL_NV_WriteItem nvwi;
1860 memset(&nvwi, 0, sizeof(nvwi));
1862 status = p.readInt32(&t);
1863 nvwi.itemID = (RIL_NV_Item) t;
1865 nvwi.value = strdupReadString(p);
1867 if (status != NO_ERROR || nvwi.value == NULL) {
1872 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1876 printRequest(pRI->token, pRI->pCI->requestNumber);
1878 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1881 memsetString(nvwi.value);
1887 memset(&nvwi, 0, sizeof(nvwi));
1893 invalidCommandBlock(pRI);
1898 static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1899 RIL_SelectUiccSub uicc_sub;
1902 memset(&uicc_sub, 0, sizeof(uicc_sub));
1904 status = p.readInt32(&t);
1905 if (status != NO_ERROR) {
1908 uicc_sub.slot = (int) t;
1910 status = p.readInt32(&t);
1911 if (status != NO_ERROR) {
1914 uicc_sub.app_index = (int) t;
1916 status = p.readInt32(&t);
1917 if (status != NO_ERROR) {
1920 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1922 status = p.readInt32(&t);
1923 if (status != NO_ERROR) {
1926 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1929 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1930 uicc_sub.act_status);
1931 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1932 uicc_sub.app_index, uicc_sub.act_status);
1934 printRequest(pRI->token, pRI->pCI->requestNumber);
1936 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1939 memset(&uicc_sub, 0, sizeof(uicc_sub));
1944 invalidCommandBlock(pRI);
1948 static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1950 RIL_SimAuthentication pf;
1954 memset(&pf, 0, sizeof(pf));
1956 status = p.readInt32(&t);
1957 pf.authContext = (int) t;
1958 pf.authData = strdupReadString(p);
1959 pf.aid = strdupReadString(p);
1962 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1964 printRequest(pRI->token, pRI->pCI->requestNumber);
1966 if (status != NO_ERROR) {
1969 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1972 memsetString(pf.authData);
1973 memsetString(pf.aid);
1980 memset(&pf, 0, sizeof(pf));
1985 invalidCommandBlock(pRI);
1989 static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1994 status = p.readInt32(&num);
1995 if (status != NO_ERROR || num < 0) {
2000 RIL_DataProfileInfo *dataProfiles =
2001 (RIL_DataProfileInfo *)calloc(num, sizeof(RIL_DataProfileInfo));
2002 if (dataProfiles == NULL) {
2003 RLOGE("Memory allocation failed for request %s",
2004 requestToString(pRI->pCI->requestNumber));
2007 RIL_DataProfileInfo **dataProfilePtrs =
2008 (RIL_DataProfileInfo **)calloc(num, sizeof(RIL_DataProfileInfo *));
2009 if (dataProfilePtrs == NULL) {
2010 RLOGE("Memory allocation failed for request %s",
2011 requestToString(pRI->pCI->requestNumber));
2017 for (int i = 0 ; i < num ; i++ ) {
2018 dataProfilePtrs[i] = &dataProfiles[i];
2020 status = p.readInt32(&t);
2021 dataProfiles[i].profileId = (int) t;
2023 dataProfiles[i].apn = strdupReadString(p);
2024 dataProfiles[i].protocol = strdupReadString(p);
2025 status = p.readInt32(&t);
2026 dataProfiles[i].authType = (int) t;
2028 dataProfiles[i].user = strdupReadString(p);
2029 dataProfiles[i].password = strdupReadString(p);
2031 status = p.readInt32(&t);
2032 dataProfiles[i].type = (int) t;
2034 status = p.readInt32(&t);
2035 dataProfiles[i].maxConnsTime = (int) t;
2036 status = p.readInt32(&t);
2037 dataProfiles[i].maxConns = (int) t;
2038 status = p.readInt32(&t);
2039 dataProfiles[i].waitTime = (int) t;
2041 status = p.readInt32(&t);
2042 dataProfiles[i].enabled = (int) t;
2044 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2045 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2046 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2047 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2048 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2049 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2050 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2053 printRequest(pRI->token, pRI->pCI->requestNumber);
2055 if (status != NO_ERROR) {
2057 free(dataProfilePtrs);
2060 CALL_ONREQUEST(pRI->pCI->requestNumber,
2062 num * sizeof(RIL_DataProfileInfo *),
2063 pRI, pRI->socket_id);
2066 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2067 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2070 free(dataProfilePtrs);
2076 invalidCommandBlock(pRI);
2080 static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2081 RIL_RadioCapability rc;
2085 memset (&rc, 0, sizeof(RIL_RadioCapability));
2087 status = p.readInt32(&t);
2088 rc.version = (int)t;
2089 if (status != NO_ERROR) {
2093 status = p.readInt32(&t);
2095 if (status != NO_ERROR) {
2099 status = p.readInt32(&t);
2101 if (status != NO_ERROR) {
2105 status = p.readInt32(&t);
2107 if (status != NO_ERROR) {
2111 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2112 if (status != NO_ERROR) {
2116 status = p.readInt32(&t);
2119 if (status != NO_ERROR) {
2124 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
2125 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
2126 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
2129 printRequest(pRI->token, pRI->pCI->requestNumber);
2131 CALL_ONREQUEST(pRI->pCI->requestNumber,
2133 sizeof(RIL_RadioCapability),
2134 pRI, pRI->socket_id);
2137 invalidCommandBlock(pRI);
2142 * Callee expects const RIL_CarrierRestrictions *
2144 static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI) {
2145 RIL_CarrierRestrictions cr;
2146 RIL_Carrier * allowed_carriers = NULL;
2147 RIL_Carrier * excluded_carriers = NULL;
2151 memset(&cr, 0, sizeof(RIL_CarrierRestrictions));
2153 if (s_callbacks.version < 14) {
2154 RLOGE("Unsuppoted RIL version %d, min version expected %d",
2155 s_callbacks.version, 14);
2156 RIL_onRequestComplete(pRI, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
2160 status = p.readInt32(&t);
2161 if (status != NO_ERROR) {
2164 allowed_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2165 if (allowed_carriers == NULL) {
2166 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2169 cr.len_allowed_carriers = t;
2170 cr.allowed_carriers = allowed_carriers;
2172 status = p.readInt32(&t);
2173 if (status != NO_ERROR) {
2176 excluded_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
2177 if (excluded_carriers == NULL) {
2178 RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
2181 cr.len_excluded_carriers = t;
2182 cr.excluded_carriers = excluded_carriers;
2185 appendPrintBuf("%s len_allowed_carriers:%d, len_excluded_carriers:%d,",
2186 printBuf, cr.len_allowed_carriers, cr.len_excluded_carriers);
2188 appendPrintBuf("%s allowed_carriers:", printBuf);
2189 for (int32_t i = 0; i < cr.len_allowed_carriers; i++) {
2190 RIL_Carrier *p_cr = allowed_carriers + i;
2191 p_cr->mcc = strdupReadString(p);
2192 p_cr->mnc = strdupReadString(p);
2193 status = p.readInt32(&t);
2194 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2195 if (status != NO_ERROR) {
2198 p_cr->match_data = strdupReadString(p);
2199 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2200 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
2203 for (int32_t i = 0; i < cr.len_excluded_carriers; i++) {
2204 RIL_Carrier *p_cr = excluded_carriers + i;
2205 p_cr->mcc = strdupReadString(p);
2206 p_cr->mnc = strdupReadString(p);
2207 status = p.readInt32(&t);
2208 p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
2209 if (status != NO_ERROR) {
2212 p_cr->match_data = strdupReadString(p);
2213 appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
2214 printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
2218 printRequest(pRI->token, pRI->pCI->requestNumber);
2220 CALL_ONREQUEST(pRI->pCI->requestNumber,
2222 sizeof(RIL_CarrierRestrictions),
2223 pRI, pRI->socket_id);
2228 invalidCommandBlock(pRI);
2229 RIL_onRequestComplete(pRI, RIL_E_INVALID_ARGUMENTS, NULL, 0);
2231 if (allowed_carriers != NULL) {
2232 free(allowed_carriers);
2234 if (excluded_carriers != NULL) {
2235 free(excluded_carriers);
2241 blockingWrite(int fd, const void *buffer, size_t len) {
2242 size_t writeOffset = 0;
2243 const uint8_t *toWrite;
2245 toWrite = (const uint8_t *)buffer;
2247 while (writeOffset < len) {
2250 written = write (fd, toWrite + writeOffset,
2252 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
2255 writeOffset += written;
2256 } else { // written < 0
2257 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
2263 RLOGE("RIL Response bytes written:%d", writeOffset);
2269 sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2270 int fd = s_ril_param_socket.fdCommand;
2273 pthread_mutex_t * writeMutexHook = &s_writeMutex;
2276 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2279 #if (SIM_COUNT >= 2)
2280 if (socket_id == RIL_SOCKET_2) {
2281 fd = s_ril_param_socket2.fdCommand;
2282 writeMutexHook = &s_writeMutex_socket2;
2284 #if (SIM_COUNT >= 3)
2285 else if (socket_id == RIL_SOCKET_3) {
2286 fd = s_ril_param_socket3.fdCommand;
2287 writeMutexHook = &s_writeMutex_socket3;
2290 #if (SIM_COUNT >= 4)
2291 else if (socket_id == RIL_SOCKET_4) {
2292 fd = s_ril_param_socket4.fdCommand;
2293 writeMutexHook = &s_writeMutex_socket4;
2301 if (dataSize > MAX_COMMAND_BYTES) {
2302 RLOGE("RIL: packet larger than %u (%u)",
2303 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2308 pthread_mutex_lock(writeMutexHook);
2310 header = htonl(dataSize);
2312 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2315 pthread_mutex_unlock(writeMutexHook);
2319 ret = blockingWrite(fd, data, dataSize);
2322 pthread_mutex_unlock(writeMutexHook);
2326 pthread_mutex_unlock(writeMutexHook);
2332 sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
2334 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
2337 /** response is an int* pointing to an array of ints */
2340 responseInts(Parcel &p, void *response, size_t responselen) {
2343 if (response == NULL && responselen != 0) {
2344 RLOGE("invalid response: NULL");
2345 return RIL_ERRNO_INVALID_RESPONSE;
2347 if (responselen % sizeof(int) != 0) {
2348 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2349 (int)responselen, (int)sizeof(int));
2350 return RIL_ERRNO_INVALID_RESPONSE;
2353 int *p_int = (int *) response;
2355 numInts = responselen / sizeof(int);
2356 p.writeInt32 (numInts);
2360 for (int i = 0 ; i < numInts ; i++) {
2361 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2362 p.writeInt32(p_int[i]);
2370 // Response is an int or RIL_LastCallFailCauseInfo.
2371 // Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2372 // TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2373 static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2374 if (response == NULL && responselen != 0) {
2375 RLOGE("invalid response: NULL");
2376 return RIL_ERRNO_INVALID_RESPONSE;
2379 if (responselen == sizeof(int)) {
2381 int *p_int = (int *) response;
2382 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2383 p.writeInt32(p_int[0]);
2386 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2388 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2389 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2390 p_fail_cause_info->vendor_cause);
2391 p.writeInt32(p_fail_cause_info->cause_code);
2392 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2396 RLOGE("responseFailCause: invalid response length %d expected an int or "
2397 "RIL_LastCallFailCauseInfo", (int)responselen);
2398 return RIL_ERRNO_INVALID_RESPONSE;
2404 /** response is a char **, pointing to an array of char *'s
2405 The parcel will begin with the version */
2406 static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2407 p.writeInt32(version);
2408 return responseStrings(p, response, responselen);
2411 /** response is a char **, pointing to an array of char *'s */
2412 static int responseStrings(Parcel &p, void *response, size_t responselen) {
2415 if (response == NULL && responselen != 0) {
2416 RLOGE("invalid response: NULL");
2417 return RIL_ERRNO_INVALID_RESPONSE;
2419 if (responselen % sizeof(char *) != 0) {
2420 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
2421 (int)responselen, (int)sizeof(char *));
2422 return RIL_ERRNO_INVALID_RESPONSE;
2425 if (response == NULL) {
2428 char **p_cur = (char **) response;
2430 numStrings = responselen / sizeof(char *);
2431 p.writeInt32 (numStrings);
2435 for (int i = 0 ; i < numStrings ; i++) {
2436 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2437 writeStringToParcel (p, p_cur[i]);
2447 * NULL strings are accepted
2448 * FIXME currently ignores responselen
2450 static int responseString(Parcel &p, void *response, size_t responselen) {
2451 /* one string only */
2453 appendPrintBuf("%s%s", printBuf, (char*)response);
2456 writeStringToParcel(p, (const char *)response);
2461 static int responseVoid(Parcel &p, void *response, size_t responselen) {
2467 static int responseCallList(Parcel &p, void *response, size_t responselen) {
2470 if (response == NULL && responselen != 0) {
2471 RLOGE("invalid response: NULL");
2472 return RIL_ERRNO_INVALID_RESPONSE;
2475 if (responselen % sizeof (RIL_Call *) != 0) {
2476 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
2477 (int)responselen, (int)sizeof (RIL_Call *));
2478 return RIL_ERRNO_INVALID_RESPONSE;
2482 /* number of call info's */
2483 num = responselen / sizeof(RIL_Call *);
2486 for (int i = 0 ; i < num ; i++) {
2487 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2488 /* each call info */
2489 p.writeInt32(p_cur->state);
2490 p.writeInt32(p_cur->index);
2491 p.writeInt32(p_cur->toa);
2492 p.writeInt32(p_cur->isMpty);
2493 p.writeInt32(p_cur->isMT);
2494 p.writeInt32(p_cur->als);
2495 p.writeInt32(p_cur->isVoice);
2496 p.writeInt32(p_cur->isVoicePrivacy);
2497 writeStringToParcel(p, p_cur->number);
2498 p.writeInt32(p_cur->numberPresentation);
2499 writeStringToParcel(p, p_cur->name);
2500 p.writeInt32(p_cur->namePresentation);
2501 // Remove when partners upgrade to version 3
2502 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2503 p.writeInt32(0); /* UUS Information is absent */
2505 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2506 p.writeInt32(1); /* UUS Information is present */
2507 p.writeInt32(uusInfo->uusType);
2508 p.writeInt32(uusInfo->uusDcs);
2509 p.writeInt32(uusInfo->uusLength);
2510 p.write(uusInfo->uusData, uusInfo->uusLength);
2512 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2515 callStateToString(p_cur->state),
2517 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2519 (p_cur->isMpty)?"conf":"norm",
2520 (p_cur->isMT)?"mt":"mo",
2522 (p_cur->isVoice)?"voc":"nonvoc",
2523 (p_cur->isVoicePrivacy)?"evp":"noevp");
2524 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2527 p_cur->numberPresentation,
2529 p_cur->namePresentation);
2537 static int responseSMS(Parcel &p, void *response, size_t responselen) {
2538 if (response == NULL) {
2539 RLOGE("invalid response: NULL");
2540 return RIL_ERRNO_INVALID_RESPONSE;
2543 if (responselen != sizeof (RIL_SMS_Response) ) {
2544 RLOGE("invalid response length %d expected %d",
2545 (int)responselen, (int)sizeof (RIL_SMS_Response));
2546 return RIL_ERRNO_INVALID_RESPONSE;
2549 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2551 p.writeInt32(p_cur->messageRef);
2552 writeStringToParcel(p, p_cur->ackPDU);
2553 p.writeInt32(p_cur->errorCode);
2556 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2557 (char*)p_cur->ackPDU, p_cur->errorCode);
2563 static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2565 if (response == NULL && responselen != 0) {
2566 RLOGE("invalid response: NULL");
2567 return RIL_ERRNO_INVALID_RESPONSE;
2570 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
2571 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
2572 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2573 return RIL_ERRNO_INVALID_RESPONSE;
2579 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2582 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2585 for (i = 0; i < num; i++) {
2586 p.writeInt32(p_cur[i].cid);
2587 p.writeInt32(p_cur[i].active);
2588 writeStringToParcel(p, p_cur[i].type);
2589 // apn is not used, so don't send.
2590 writeStringToParcel(p, p_cur[i].address);
2591 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2593 (p_cur[i].active==0)?"down":"up",
2594 (char*)p_cur[i].type,
2595 (char*)p_cur[i].address);
2603 static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2605 if (response == NULL && responselen != 0) {
2606 RLOGE("invalid response: NULL");
2607 return RIL_ERRNO_INVALID_RESPONSE;
2610 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2611 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2612 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2613 return RIL_ERRNO_INVALID_RESPONSE;
2619 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2622 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2625 for (i = 0; i < num; i++) {
2626 p.writeInt32((int)p_cur[i].status);
2627 p.writeInt32(p_cur[i].suggestedRetryTime);
2628 p.writeInt32(p_cur[i].cid);
2629 p.writeInt32(p_cur[i].active);
2630 writeStringToParcel(p, p_cur[i].type);
2631 writeStringToParcel(p, p_cur[i].ifname);
2632 writeStringToParcel(p, p_cur[i].addresses);
2633 writeStringToParcel(p, p_cur[i].dnses);
2634 writeStringToParcel(p, p_cur[i].gateways);
2635 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2637 p_cur[i].suggestedRetryTime,
2639 (p_cur[i].active==0)?"down":"up",
2640 (char*)p_cur[i].type,
2641 (char*)p_cur[i].ifname,
2642 (char*)p_cur[i].addresses,
2643 (char*)p_cur[i].dnses,
2644 (char*)p_cur[i].gateways);
2652 static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2654 if (response == NULL && responselen != 0) {
2655 RLOGE("invalid response: NULL");
2656 return RIL_ERRNO_INVALID_RESPONSE;
2659 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2660 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2661 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2662 return RIL_ERRNO_INVALID_RESPONSE;
2668 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2671 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2674 for (i = 0; i < num; i++) {
2675 p.writeInt32((int)p_cur[i].status);
2676 p.writeInt32(p_cur[i].suggestedRetryTime);
2677 p.writeInt32(p_cur[i].cid);
2678 p.writeInt32(p_cur[i].active);
2679 writeStringToParcel(p, p_cur[i].type);
2680 writeStringToParcel(p, p_cur[i].ifname);
2681 writeStringToParcel(p, p_cur[i].addresses);
2682 writeStringToParcel(p, p_cur[i].dnses);
2683 writeStringToParcel(p, p_cur[i].gateways);
2684 writeStringToParcel(p, p_cur[i].pcscf);
2685 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2687 p_cur[i].suggestedRetryTime,
2689 (p_cur[i].active==0)?"down":"up",
2690 (char*)p_cur[i].type,
2691 (char*)p_cur[i].ifname,
2692 (char*)p_cur[i].addresses,
2693 (char*)p_cur[i].dnses,
2694 (char*)p_cur[i].gateways,
2695 (char*)p_cur[i].pcscf);
2703 static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) {
2704 if (response == NULL && responselen != 0) {
2705 RLOGE("invalid response: NULL");
2706 return RIL_ERRNO_INVALID_RESPONSE;
2709 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2710 RLOGE("invalid response length %d expected multiple of %d",
2711 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
2712 return RIL_ERRNO_INVALID_RESPONSE;
2718 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
2721 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
2724 for (i = 0; i < num; i++) {
2725 p.writeInt32((int)p_cur[i].status);
2726 p.writeInt32(p_cur[i].suggestedRetryTime);
2727 p.writeInt32(p_cur[i].cid);
2728 p.writeInt32(p_cur[i].active);
2729 writeStringToParcel(p, p_cur[i].type);
2730 writeStringToParcel(p, p_cur[i].ifname);
2731 writeStringToParcel(p, p_cur[i].addresses);
2732 writeStringToParcel(p, p_cur[i].dnses);
2733 writeStringToParcel(p, p_cur[i].gateways);
2734 writeStringToParcel(p, p_cur[i].pcscf);
2735 p.writeInt32(p_cur[i].mtu);
2736 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
2738 p_cur[i].suggestedRetryTime,
2740 (p_cur[i].active==0)?"down":"up",
2741 (char*)p_cur[i].type,
2742 (char*)p_cur[i].ifname,
2743 (char*)p_cur[i].addresses,
2744 (char*)p_cur[i].dnses,
2745 (char*)p_cur[i].gateways,
2746 (char*)p_cur[i].pcscf,
2755 static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2757 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
2758 if (s_callbacks.version < 5) {
2759 RLOGD("responseDataCallList: v4");
2760 return responseDataCallListV4(p, response, responselen);
2761 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2762 return responseDataCallListV6(p, response, responselen);
2763 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2764 return responseDataCallListV9(p, response, responselen);
2766 return responseDataCallListV11(p, response, responselen);
2768 } else { // RIL version >= 13
2769 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2770 RLOGE("Data structure expected is RIL_Data_Call_Response_v11");
2771 if (!isDebuggable()) {
2772 return RIL_ERRNO_INVALID_RESPONSE;
2777 return responseDataCallListV11(p, response, responselen);
2781 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2783 if (s_callbacks.version < 5) {
2784 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2786 return responseDataCallList(p, response, responselen);
2790 static int responseRaw(Parcel &p, void *response, size_t responselen) {
2791 if (response == NULL && responselen != 0) {
2792 RLOGE("invalid response: NULL with responselen != 0");
2793 return RIL_ERRNO_INVALID_RESPONSE;
2796 // The java code reads -1 size as null byte array
2797 if (response == NULL) {
2800 p.writeInt32(responselen);
2801 p.write(response, responselen);
2808 static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2809 if (response == NULL) {
2810 RLOGE("invalid response: NULL");
2811 return RIL_ERRNO_INVALID_RESPONSE;
2814 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
2815 RLOGE("invalid response length was %d expected %d",
2816 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2817 return RIL_ERRNO_INVALID_RESPONSE;
2820 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2821 p.writeInt32(p_cur->sw1);
2822 p.writeInt32(p_cur->sw2);
2823 writeStringToParcel(p, p_cur->simResponse);
2826 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2827 (char*)p_cur->simResponse);
2834 static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2837 if (response == NULL && responselen != 0) {
2838 RLOGE("invalid response: NULL");
2839 return RIL_ERRNO_INVALID_RESPONSE;
2842 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
2843 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
2844 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2845 return RIL_ERRNO_INVALID_RESPONSE;
2848 /* number of call info's */
2849 num = responselen / sizeof(RIL_CallForwardInfo *);
2853 for (int i = 0 ; i < num ; i++) {
2854 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2856 p.writeInt32(p_cur->status);
2857 p.writeInt32(p_cur->reason);
2858 p.writeInt32(p_cur->serviceClass);
2859 p.writeInt32(p_cur->toa);
2860 writeStringToParcel(p, p_cur->number);
2861 p.writeInt32(p_cur->timeSeconds);
2862 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2863 (p_cur->status==1)?"enable":"disable",
2864 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2865 (char*)p_cur->number,
2866 p_cur->timeSeconds);
2874 static int responseSsn(Parcel &p, void *response, size_t responselen) {
2875 if (response == NULL) {
2876 RLOGE("invalid response: NULL");
2877 return RIL_ERRNO_INVALID_RESPONSE;
2880 if (responselen != sizeof(RIL_SuppSvcNotification)) {
2881 RLOGE("invalid response length was %d expected %d",
2882 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2883 return RIL_ERRNO_INVALID_RESPONSE;
2886 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2887 p.writeInt32(p_cur->notificationType);
2888 p.writeInt32(p_cur->code);
2889 p.writeInt32(p_cur->index);
2890 p.writeInt32(p_cur->type);
2891 writeStringToParcel(p, p_cur->number);
2894 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2895 (p_cur->notificationType==0)?"mo":"mt",
2896 p_cur->code, p_cur->index, p_cur->type,
2897 (char*)p_cur->number);
2903 static int responseCellList(Parcel &p, void *response, size_t responselen) {
2906 if (response == NULL && responselen != 0) {
2907 RLOGE("invalid response: NULL");
2908 return RIL_ERRNO_INVALID_RESPONSE;
2911 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
2912 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
2913 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2914 return RIL_ERRNO_INVALID_RESPONSE;
2918 /* number of records */
2919 num = responselen / sizeof(RIL_NeighboringCell *);
2922 for (int i = 0 ; i < num ; i++) {
2923 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2925 p.writeInt32(p_cur->rssi);
2926 writeStringToParcel (p, p_cur->cid);
2928 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2929 p_cur->cid, p_cur->rssi);
2938 * Marshall the signalInfoRecord into the parcel if it exists.
2940 static void marshallSignalInfoRecord(Parcel &p,
2941 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2942 p.writeInt32(p_signalInfoRecord.isPresent);
2943 p.writeInt32(p_signalInfoRecord.signalType);
2944 p.writeInt32(p_signalInfoRecord.alertPitch);
2945 p.writeInt32(p_signalInfoRecord.signal);
2948 static int responseCdmaInformationRecords(Parcel &p,
2949 void *response, size_t responselen) {
2951 char* string8 = NULL;
2953 RIL_CDMA_InformationRecord *infoRec;
2955 if (response == NULL && responselen != 0) {
2956 RLOGE("invalid response: NULL");
2957 return RIL_ERRNO_INVALID_RESPONSE;
2960 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
2961 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
2962 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2963 return RIL_ERRNO_INVALID_RESPONSE;
2966 RIL_CDMA_InformationRecords *p_cur =
2967 (RIL_CDMA_InformationRecords *) response;
2968 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2973 for (int i = 0 ; i < num ; i++) {
2974 infoRec = &p_cur->infoRec[i];
2975 p.writeInt32(infoRec->name);
2976 switch (infoRec->name) {
2977 case RIL_CDMA_DISPLAY_INFO_REC:
2978 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2979 if (infoRec->rec.display.alpha_len >
2980 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
2981 RLOGE("invalid display info response length %d \
2982 expected not more than %d\n",
2983 (int)infoRec->rec.display.alpha_len,
2984 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2985 return RIL_ERRNO_INVALID_RESPONSE;
2987 string8 = (char*) calloc(infoRec->rec.display.alpha_len + 1, sizeof(char));
2988 if (string8 == NULL) {
2989 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
2991 return RIL_ERRNO_NO_MEMORY;
2993 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2994 string8[i] = infoRec->rec.display.alpha_buf[i];
2996 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2997 writeStringToParcel(p, (const char*)string8);
3001 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
3002 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
3003 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
3004 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
3005 RLOGE("invalid display info response length %d \
3006 expected not more than %d\n",
3007 (int)infoRec->rec.number.len,
3008 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3009 return RIL_ERRNO_INVALID_RESPONSE;
3011 string8 = (char*) calloc(infoRec->rec.number.len + 1, sizeof(char));
3012 if (string8 == NULL) {
3013 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3015 return RIL_ERRNO_NO_MEMORY;
3017 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
3018 string8[i] = infoRec->rec.number.buf[i];
3020 string8[(int)infoRec->rec.number.len] = '\0';
3021 writeStringToParcel(p, (const char*)string8);
3024 p.writeInt32(infoRec->rec.number.number_type);
3025 p.writeInt32(infoRec->rec.number.number_plan);
3026 p.writeInt32(infoRec->rec.number.pi);
3027 p.writeInt32(infoRec->rec.number.si);
3029 case RIL_CDMA_SIGNAL_INFO_REC:
3030 p.writeInt32(infoRec->rec.signal.isPresent);
3031 p.writeInt32(infoRec->rec.signal.signalType);
3032 p.writeInt32(infoRec->rec.signal.alertPitch);
3033 p.writeInt32(infoRec->rec.signal.signal);
3035 appendPrintBuf("%sisPresent=%X, signalType=%X, \
3036 alertPitch=%X, signal=%X, ",
3037 printBuf, (int)infoRec->rec.signal.isPresent,
3038 (int)infoRec->rec.signal.signalType,
3039 (int)infoRec->rec.signal.alertPitch,
3040 (int)infoRec->rec.signal.signal);
3043 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
3044 if (infoRec->rec.redir.redirectingNumber.len >
3045 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
3046 RLOGE("invalid display info response length %d \
3047 expected not more than %d\n",
3048 (int)infoRec->rec.redir.redirectingNumber.len,
3049 CDMA_NUMBER_INFO_BUFFER_LENGTH);
3050 return RIL_ERRNO_INVALID_RESPONSE;
3052 string8 = (char*) calloc(infoRec->rec.redir.redirectingNumber.len + 1,
3054 if (string8 == NULL) {
3055 RLOGE("Memory allocation failed for responseCdmaInformationRecords");
3057 return RIL_ERRNO_NO_MEMORY;
3060 i < infoRec->rec.redir.redirectingNumber.len;
3062 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
3064 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
3065 writeStringToParcel(p, (const char*)string8);
3068 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
3069 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
3070 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
3071 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
3072 p.writeInt32(infoRec->rec.redir.redirectingReason);
3074 case RIL_CDMA_LINE_CONTROL_INFO_REC:
3075 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
3076 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
3077 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
3078 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3080 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
3081 lineCtrlToggle=%d, lineCtrlReverse=%d, \
3082 lineCtrlPowerDenial=%d, ", printBuf,
3083 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
3084 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
3085 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
3086 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
3089 case RIL_CDMA_T53_CLIR_INFO_REC:
3090 p.writeInt32((int)(infoRec->rec.clir.cause));
3092 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
3095 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
3096 p.writeInt32(infoRec->rec.audioCtrl.upLink);
3097 p.writeInt32(infoRec->rec.audioCtrl.downLink);
3099 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
3100 infoRec->rec.audioCtrl.upLink,
3101 infoRec->rec.audioCtrl.downLink);
3104 case RIL_CDMA_T53_RELEASE_INFO_REC:
3105 // TODO(Moto): See David Krause, he has the answer:)
3106 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
3107 return RIL_ERRNO_INVALID_RESPONSE;
3109 RLOGE("Incorrect name value");
3110 return RIL_ERRNO_INVALID_RESPONSE;
3118 static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3119 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
3120 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
3121 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
3122 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
3123 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
3124 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
3125 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
3128 static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3130 * Fixup LTE for backwards compatibility
3132 // signalStrength: -1 -> 99
3133 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3134 p_cur->LTE_SignalStrength.signalStrength = 99;
3136 // rsrp: -1 -> INT_MAX all other negative value to positive.
3138 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3139 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3140 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3141 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3143 // rsrq: -1 -> INT_MAX
3144 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3145 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3147 // Not remapping rssnr is already using INT_MAX
3149 // cqi: -1 -> INT_MAX
3150 if (p_cur->LTE_SignalStrength.cqi == -1) {
3151 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3154 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
3155 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
3156 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
3157 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
3158 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
3161 static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) {
3162 responseRilSignalStrengthV5(p, p_cur);
3163 responseRilSignalStrengthV6Extra(p, p_cur);
3164 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3167 static int responseRilSignalStrength(Parcel &p,
3168 void *response, size_t responselen) {
3169 if (response == NULL && responselen != 0) {
3170 RLOGE("invalid response: NULL");
3171 return RIL_ERRNO_INVALID_RESPONSE;
3174 RIL_SignalStrength_v10 *p_cur;
3175 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3176 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
3177 p_cur = ((RIL_SignalStrength_v10 *) response);
3179 responseRilSignalStrengthV5(p, p_cur);
3181 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
3182 responseRilSignalStrengthV6Extra(p, p_cur);
3183 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3184 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3186 p.writeInt32(INT_MAX);
3190 p.writeInt32(INT_MAX);
3191 p.writeInt32(INT_MAX);
3192 p.writeInt32(INT_MAX);
3193 p.writeInt32(INT_MAX);
3194 p.writeInt32(INT_MAX);
3197 RLOGE("invalid response length");
3198 return RIL_ERRNO_INVALID_RESPONSE;
3200 } else { // RIL version >= 13
3201 if (responselen % sizeof(RIL_SignalStrength_v10) != 0) {
3202 RLOGE("Data structure expected is RIL_SignalStrength_v10");
3203 if (!isDebuggable()) {
3204 return RIL_ERRNO_INVALID_RESPONSE;
3209 p_cur = ((RIL_SignalStrength_v10 *) response);
3210 responseRilSignalStrengthV10(p, p_cur);
3213 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3214 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3215 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3216 EVDO_SS.signalNoiseRatio=%d,\
3217 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
3218 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
3220 p_cur->GW_SignalStrength.signalStrength,
3221 p_cur->GW_SignalStrength.bitErrorRate,
3222 p_cur->CDMA_SignalStrength.dbm,
3223 p_cur->CDMA_SignalStrength.ecio,
3224 p_cur->EVDO_SignalStrength.dbm,
3225 p_cur->EVDO_SignalStrength.ecio,
3226 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3227 p_cur->LTE_SignalStrength.signalStrength,
3228 p_cur->LTE_SignalStrength.rsrp,
3229 p_cur->LTE_SignalStrength.rsrq,
3230 p_cur->LTE_SignalStrength.rssnr,
3231 p_cur->LTE_SignalStrength.cqi,
3232 p_cur->TD_SCDMA_SignalStrength.rscp);
3237 static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3238 if ((response == NULL) || (responselen == 0)) {
3239 return responseVoid(p, response, responselen);
3241 return responseCdmaSignalInfoRecord(p, response, responselen);
3245 static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3246 if (response == NULL || responselen == 0) {
3247 RLOGE("invalid response: NULL");
3248 return RIL_ERRNO_INVALID_RESPONSE;
3251 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
3252 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
3253 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3254 return RIL_ERRNO_INVALID_RESPONSE;
3259 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3260 marshallSignalInfoRecord(p, *p_cur);
3262 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3274 static int responseCdmaCallWaiting(Parcel &p, void *response,
3275 size_t responselen) {
3276 if (response == NULL && responselen != 0) {
3277 RLOGE("invalid response: NULL");
3278 return RIL_ERRNO_INVALID_RESPONSE;
3281 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
3282 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
3285 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3287 writeStringToParcel(p, p_cur->number);
3288 p.writeInt32(p_cur->numberPresentation);
3289 writeStringToParcel(p, p_cur->name);
3290 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3292 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3293 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3294 p.writeInt32(p_cur->number_type);
3295 p.writeInt32(p_cur->number_plan);
3300 } else { // RIL version >= 13
3301 if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) {
3302 RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6");
3303 if (!isDebuggable()) {
3304 return RIL_ERRNO_INVALID_RESPONSE;
3309 p.writeInt32(p_cur->number_type);
3310 p.writeInt32(p_cur->number_plan);
3314 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3315 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3316 signal=%d,number_type=%d,number_plan=%d]",
3319 p_cur->numberPresentation,
3321 p_cur->signalInfoRecord.isPresent,
3322 p_cur->signalInfoRecord.signalType,
3323 p_cur->signalInfoRecord.alertPitch,
3324 p_cur->signalInfoRecord.signal,
3326 p_cur->number_plan);
3332 static void responseSimRefreshV7(Parcel &p, void *response) {
3333 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3334 p.writeInt32(p_cur->result);
3335 p.writeInt32(p_cur->ef_id);
3336 writeStringToParcel(p, p_cur->aid);
3338 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3346 static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3347 if (response == NULL && responselen != 0) {
3348 RLOGE("responseSimRefresh: invalid response: NULL");
3349 return RIL_ERRNO_INVALID_RESPONSE;
3353 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3354 if (s_callbacks.version >= 7) {
3355 responseSimRefreshV7(p, response);
3357 int *p_cur = ((int *) response);
3358 p.writeInt32(p_cur[0]);
3359 p.writeInt32(p_cur[1]);
3360 writeStringToParcel(p, NULL);
3362 appendPrintBuf("%sresult=%d, ef_id=%d",
3367 } else { // RIL version >= 13
3368 if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) {
3369 RLOGE("Data structure expected is RIL_SimRefreshResponse_v7");
3370 if (!isDebuggable()) {
3371 return RIL_ERRNO_INVALID_RESPONSE;
3376 responseSimRefreshV7(p, response);
3384 static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) {
3385 if (response == NULL && responselen != 0) {
3386 RLOGE("invalid response: NULL");
3387 return RIL_ERRNO_INVALID_RESPONSE;
3390 if (responselen % sizeof(RIL_CellInfo) != 0) {
3391 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3392 (int)responselen, (int)sizeof(RIL_CellInfo));
3393 return RIL_ERRNO_INVALID_RESPONSE;
3396 int num = responselen / sizeof(RIL_CellInfo);
3399 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3402 for (i = 0; i < num; i++) {
3403 p.writeInt32((int)p_cur->cellInfoType);
3404 p.writeInt32(p_cur->registered);
3405 p.writeInt32(p_cur->timeStampType);
3406 p.writeInt64(p_cur->timeStamp);
3407 switch(p_cur->cellInfoType) {
3408 case RIL_CELL_INFO_TYPE_GSM: {
3409 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3410 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3411 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3412 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3413 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3414 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3417 case RIL_CELL_INFO_TYPE_WCDMA: {
3418 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3419 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3420 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3421 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3422 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3423 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3424 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3427 case RIL_CELL_INFO_TYPE_CDMA: {
3428 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3429 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3430 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3431 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3432 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3434 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3435 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3436 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3437 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3438 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3441 case RIL_CELL_INFO_TYPE_LTE: {
3442 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3443 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3444 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3445 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3446 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3448 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3449 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3450 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3451 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3452 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3453 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3456 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3457 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3458 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3459 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3460 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3461 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3462 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3474 static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) {
3475 if (response == NULL && responselen != 0) {
3476 RLOGE("invalid response: NULL");
3477 return RIL_ERRNO_INVALID_RESPONSE;
3480 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3481 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
3482 (int)responselen, (int)sizeof(RIL_CellInfo_v12));
3483 return RIL_ERRNO_INVALID_RESPONSE;
3486 int num = responselen / sizeof(RIL_CellInfo_v12);
3489 RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response;
3492 for (i = 0; i < num; i++) {
3493 p.writeInt32((int)p_cur->cellInfoType);
3494 p.writeInt32(p_cur->registered);
3495 p.writeInt32(p_cur->timeStampType);
3496 p.writeInt64(p_cur->timeStamp);
3497 switch(p_cur->cellInfoType) {
3498 case RIL_CELL_INFO_TYPE_GSM: {
3499 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3500 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3501 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3502 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3503 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn);
3504 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic);
3505 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3506 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3507 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance);
3510 case RIL_CELL_INFO_TYPE_WCDMA: {
3511 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3512 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3513 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3514 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3515 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3516 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn);
3517 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3518 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3521 case RIL_CELL_INFO_TYPE_CDMA: {
3522 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3523 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3524 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3525 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3526 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3528 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3529 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3530 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3531 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3532 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3535 case RIL_CELL_INFO_TYPE_LTE: {
3536 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3537 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3538 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3539 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3540 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3541 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn);
3543 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3544 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3545 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3546 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3547 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3548 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3551 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3552 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3553 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3554 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3555 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3556 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3557 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3568 static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3570 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3571 if (s_callbacks.version < 12) {
3572 RLOGD("responseCellInfoList: v6");
3573 return responseCellInfoListV6(p, response, responselen);
3575 RLOGD("responseCellInfoList: v12");
3576 return responseCellInfoListV12(p, response, responselen);
3578 } else { // RIL version >= 13
3579 if (responselen % sizeof(RIL_CellInfo_v12) != 0) {
3580 RLOGE("Data structure expected is RIL_CellInfo_v12");
3581 if (!isDebuggable()) {
3582 return RIL_ERRNO_INVALID_RESPONSE;
3587 return responseCellInfoListV12(p, response, responselen);
3593 static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3595 if (response == NULL && responselen != 0) {
3596 RLOGE("invalid response: NULL");
3597 return RIL_ERRNO_INVALID_RESPONSE;
3600 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3601 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3602 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3603 return RIL_ERRNO_INVALID_RESPONSE;
3606 int num = responselen / sizeof(RIL_HardwareConfig);
3608 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3613 for (i = 0; i < num; i++) {
3614 switch (p_cur[i].type) {
3615 case RIL_HARDWARE_CONFIG_MODEM: {
3616 writeStringToParcel(p, p_cur[i].uuid);
3617 p.writeInt32((int)p_cur[i].state);
3618 p.writeInt32(p_cur[i].cfg.modem.rat);
3619 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3620 p.writeInt32(p_cur[i].cfg.modem.maxData);
3621 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3623 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3624 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3625 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3628 case RIL_HARDWARE_CONFIG_SIM: {
3629 writeStringToParcel(p, p_cur[i].uuid);
3630 p.writeInt32((int)p_cur[i].state);
3631 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3633 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3634 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3644 static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3645 if (response == NULL) {
3646 RLOGE("invalid response: NULL");
3647 return RIL_ERRNO_INVALID_RESPONSE;
3650 if (responselen != sizeof (RIL_RadioCapability) ) {
3651 RLOGE("invalid response length was %d expected %d",
3652 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3653 return RIL_ERRNO_INVALID_RESPONSE;
3656 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3657 p.writeInt32(p_cur->version);
3658 p.writeInt32(p_cur->session);
3659 p.writeInt32(p_cur->phase);
3660 p.writeInt32(p_cur->rat);
3661 writeStringToParcel(p, p_cur->logicalModemUuid);
3662 p.writeInt32(p_cur->status);
3665 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
3666 rat=%s,logicalModemUuid=%s,status=%d]",
3672 p_cur->logicalModemUuid,
3678 static int responseSSData(Parcel &p, void *response, size_t responselen) {
3679 RLOGD("In responseSSData");
3682 if (response == NULL && responselen != 0) {
3683 RLOGE("invalid response length was %d expected %d",
3684 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3685 return RIL_ERRNO_INVALID_RESPONSE;
3688 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3689 RLOGE("invalid response length %d, expected %d",
3690 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3691 return RIL_ERRNO_INVALID_RESPONSE;
3695 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3696 p.writeInt32(p_cur->serviceType);
3697 p.writeInt32(p_cur->requestType);
3698 p.writeInt32(p_cur->teleserviceType);
3699 p.writeInt32(p_cur->serviceClass);
3700 p.writeInt32(p_cur->result);
3702 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3703 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3704 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3705 RLOGE("numValidIndexes is greater than max value %d, "
3706 "truncating it to max value", NUM_SERVICE_CLASSES);
3707 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3709 /* number of call info's */
3710 p.writeInt32(p_cur->cfData.numValidIndexes);
3712 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3713 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3715 p.writeInt32(cf.status);
3716 p.writeInt32(cf.reason);
3717 p.writeInt32(cf.serviceClass);
3718 p.writeInt32(cf.toa);
3719 writeStringToParcel(p, cf.number);
3720 p.writeInt32(cf.timeSeconds);
3721 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3722 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3723 (char*)cf.number, cf.timeSeconds);
3724 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3725 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3728 p.writeInt32 (SS_INFO_MAX);
3731 for (int i = 0; i < SS_INFO_MAX; i++) {
3732 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3733 RLOGD("Data: %d",p_cur->ssInfo[i]);
3734 p.writeInt32(p_cur->ssInfo[i]);
3743 static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3744 if ((reqType == SS_INTERROGATION) &&
3745 (serType == SS_CFU ||
3746 serType == SS_CF_BUSY ||
3747 serType == SS_CF_NO_REPLY ||
3748 serType == SS_CF_NOT_REACHABLE ||
3749 serType == SS_CF_ALL ||
3750 serType == SS_CF_ALL_CONDITIONAL)) {
3756 static void triggerEvLoop() {
3758 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3759 /* trigger event loop to wakeup. No reason to do this,
3760 * if we're in the event loop thread */
3762 ret = write (s_fdWakeupWrite, " ", 1);
3763 } while (ret < 0 && errno == EINTR);
3767 static void rilEventAddWakeup(struct ril_event *ev) {
3772 static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3773 p.writeInt32(num_apps);
3775 for (int i = 0; i < num_apps; i++) {
3776 p.writeInt32(appStatus[i].app_type);
3777 p.writeInt32(appStatus[i].app_state);
3778 p.writeInt32(appStatus[i].perso_substate);
3779 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3780 writeStringToParcel(p, (const char*)
3781 (appStatus[i].app_label_ptr));
3782 p.writeInt32(appStatus[i].pin1_replaced);
3783 p.writeInt32(appStatus[i].pin1);
3784 p.writeInt32(appStatus[i].pin2);
3785 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3786 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3788 appStatus[i].app_type,
3789 appStatus[i].app_state,
3790 appStatus[i].perso_substate,
3791 appStatus[i].aid_ptr,
3792 appStatus[i].app_label_ptr,
3793 appStatus[i].pin1_replaced,
3800 static void responseSimStatusV5(Parcel &p, void *response) {
3801 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3803 p.writeInt32(p_cur->card_state);
3804 p.writeInt32(p_cur->universal_pin_state);
3805 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3806 p.writeInt32(p_cur->cdma_subscription_app_index);
3808 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3811 static void responseSimStatusV6(Parcel &p, void *response) {
3812 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3814 p.writeInt32(p_cur->card_state);
3815 p.writeInt32(p_cur->universal_pin_state);
3816 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3817 p.writeInt32(p_cur->cdma_subscription_app_index);
3818 p.writeInt32(p_cur->ims_subscription_app_index);
3820 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3823 static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3826 if (response == NULL && responselen != 0) {
3827 RLOGE("invalid response: NULL");
3828 return RIL_ERRNO_INVALID_RESPONSE;
3831 if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) {
3832 if (responselen == sizeof (RIL_CardStatus_v6)) {
3833 responseSimStatusV6(p, response);
3834 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
3835 responseSimStatusV5(p, response);
3837 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
3838 return RIL_ERRNO_INVALID_RESPONSE;
3840 } else { // RIL version >= 13
3841 if (responselen % sizeof(RIL_CardStatus_v6) != 0) {
3842 RLOGE("Data structure expected is RIL_CardStatus_v6");
3843 if (!isDebuggable()) {
3844 return RIL_ERRNO_INVALID_RESPONSE;
3849 responseSimStatusV6(p, response);
3855 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3856 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3860 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3861 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3862 for (int i = 0; i < num; i++) {
3863 p.writeInt32(p_cur[i]->fromServiceId);
3864 p.writeInt32(p_cur[i]->toServiceId);
3865 p.writeInt32(p_cur[i]->fromCodeScheme);
3866 p.writeInt32(p_cur[i]->toCodeScheme);
3867 p.writeInt32(p_cur[i]->selected);
3869 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3870 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3871 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3872 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3873 p_cur[i]->selected);
3880 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3881 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3882 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3884 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3888 for (int i = 0 ; i < num ; i++ ) {
3889 p.writeInt32(p_cur[i]->service_category);
3890 p.writeInt32(p_cur[i]->language);
3891 p.writeInt32(p_cur[i]->selected);
3893 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3895 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3896 p_cur[i]->selected);
3903 static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3910 RLOGD("Inside responseCdmaSms");
3912 if (response == NULL && responselen != 0) {
3913 RLOGE("invalid response: NULL");
3914 return RIL_ERRNO_INVALID_RESPONSE;
3917 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
3918 RLOGE("invalid response length was %d expected %d",
3919 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3920 return RIL_ERRNO_INVALID_RESPONSE;
3923 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3924 p.writeInt32(p_cur->uTeleserviceID);
3925 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3926 p.writeInt32(p_cur->uServicecategory);
3927 p.writeInt32(p_cur->sAddress.digit_mode);
3928 p.writeInt32(p_cur->sAddress.number_mode);
3929 p.writeInt32(p_cur->sAddress.number_type);
3930 p.writeInt32(p_cur->sAddress.number_plan);
3931 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3932 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3933 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3934 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3937 p.writeInt32(p_cur->sSubAddress.subaddressType);
3938 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3939 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3940 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3941 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3942 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3945 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3946 p.writeInt32(p_cur->uBearerDataLen);
3947 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3948 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3952 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3953 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3954 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3955 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3961 static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3963 int num = responselen / sizeof(RIL_DcRtInfo);
3964 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3965 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3966 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3967 return RIL_ERRNO_INVALID_RESPONSE;
3971 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3972 p.writeInt64(pDcRtInfo->time);
3973 p.writeInt32(pDcRtInfo->powerState);
3974 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3976 pDcRtInfo->powerState);
3982 static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3983 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3984 if (response == NULL) {
3985 RLOGE("invalid response: NULL");
3988 RLOGE("responseLceStatus: invalid response length %u expecting len: %u",
3989 (unsigned)sizeof(RIL_LceStatusInfo), (unsigned)responselen);
3991 return RIL_ERRNO_INVALID_RESPONSE;
3994 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3995 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3996 p.writeInt32(p_cur->actual_interval_ms);
3999 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
4000 p_cur->lce_status, p_cur->actual_interval_ms);
4006 static int responseLceData(Parcel &p, void *response, size_t responselen) {
4007 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
4008 if (response == NULL) {
4009 RLOGE("invalid response: NULL");
4012 RLOGE("responseLceData: invalid response length %u expecting len: %u",
4013 (unsigned)sizeof(RIL_LceDataInfo), (unsigned)responselen);
4015 return RIL_ERRNO_INVALID_RESPONSE;
4018 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
4019 p.writeInt32(p_cur->last_hop_capacity_kbps);
4021 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
4022 p.write((void *)&(p_cur->confidence_level), 1);
4023 p.write((void *)&(p_cur->lce_suspended), 1);
4026 appendPrintBuf("LCE info received: capacity %d confidence level %d \
4028 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
4029 p_cur->lce_suspended);
4035 static int responseActivityData(Parcel &p, void *response, size_t responselen) {
4036 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
4037 if (response == NULL) {
4038 RLOGE("invalid response: NULL");
4041 RLOGE("responseActivityData: invalid response length %u expecting len: %u",
4042 (unsigned)sizeof(RIL_ActivityStatsInfo), (unsigned)responselen);
4044 return RIL_ERRNO_INVALID_RESPONSE;
4047 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
4048 p.writeInt32(p_cur->sleep_mode_time_ms);
4049 p.writeInt32(p_cur->idle_mode_time_ms);
4050 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
4051 p.writeInt32(p_cur->tx_mode_time_ms[i]);
4053 p.writeInt32(p_cur->rx_mode_time_ms);
4056 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d \
4057 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
4058 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
4059 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
4060 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
4066 static int responseCarrierRestrictions(Parcel &p, void *response, size_t responselen) {
4067 if (response == NULL) {
4068 RLOGE("invalid response: NULL");
4069 return RIL_ERRNO_INVALID_RESPONSE;
4071 if (responselen != sizeof(RIL_CarrierRestrictions)) {
4072 RLOGE("responseCarrierRestrictions: invalid response length %u expecting len: %u",
4073 (unsigned)responselen, (unsigned)sizeof(RIL_CarrierRestrictions));
4074 return RIL_ERRNO_INVALID_RESPONSE;
4077 RIL_CarrierRestrictions *p_cr = (RIL_CarrierRestrictions *)response;
4080 p.writeInt32(p_cr->len_allowed_carriers);
4081 p.writeInt32(p_cr->len_excluded_carriers);
4082 appendPrintBuf(" %s len_allowed_carriers: %d, len_excluded_carriers: %d,", printBuf,
4083 p_cr->len_allowed_carriers,p_cr->len_excluded_carriers);
4085 appendPrintBuf(" %s allowed_carriers:", printBuf);
4086 for(int32_t i = 0; i < p_cr->len_allowed_carriers; i++) {
4087 RIL_Carrier *carrier = p_cr->allowed_carriers + i;
4088 writeStringToParcel(p, carrier->mcc);
4089 writeStringToParcel(p, carrier->mnc);
4090 p.writeInt32(carrier->match_type);
4091 writeStringToParcel(p, carrier->match_data);
4092 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4093 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
4096 appendPrintBuf(" %s excluded_carriers:", printBuf);
4097 for(int32_t i = 0; i < p_cr->len_excluded_carriers; i++) {
4098 RIL_Carrier *carrier = p_cr->excluded_carriers + i;
4099 writeStringToParcel(p, carrier->mcc);
4100 writeStringToParcel(p, carrier->mnc);
4101 p.writeInt32(carrier->match_type);
4102 writeStringToParcel(p, carrier->match_data);
4103 appendPrintBuf(" %s [%d mcc: %s, mnc: %s, match_type: %d, match_data: %s],", printBuf,
4104 i, carrier->mcc, carrier->mnc, carrier->match_type, carrier->match_data);
4112 static int responsePcoData(Parcel &p, void *response, size_t responselen) {
4113 if (response == NULL) {
4114 RLOGE("responsePcoData: invalid NULL response");
4115 return RIL_ERRNO_INVALID_RESPONSE;
4117 if (responselen != sizeof(RIL_PCO_Data)) {
4118 RLOGE("responsePcoData: invalid response length %u, expecting %u",
4119 (unsigned)responselen, (unsigned)sizeof(RIL_PCO_Data));
4120 return RIL_ERRNO_INVALID_RESPONSE;
4123 RIL_PCO_Data *p_cur = (RIL_PCO_Data *)response;
4124 p.writeInt32(p_cur->cid);
4125 writeStringToParcel(p, p_cur->bearer_proto);
4126 p.writeInt32(p_cur->pco_id);
4127 p.writeInt32(p_cur->contents_length);
4128 p.write(p_cur->contents, p_cur->contents_length);
4131 appendPrintBuf("PCO data received: cid %d, id %d, length %d",
4132 p_cur->cid, p_cur->pco_id, p_cur->contents_length);
4139 * A write on the wakeup fd is done just to pop us out of select()
4140 * We empty the buffer here and then ril_event will reset the timers on the
4143 static void processWakeupCallback(int fd, short flags, void *param) {
4147 RLOGV("processWakeupCallback");
4149 /* empty our wakeup socket out */
4151 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
4152 } while (ret > 0 || (ret < 0 && errno == EINTR));
4155 static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
4158 /* Hook for current context
4159 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4160 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
4161 /* pendingRequestsHook refer to &s_pendingRequests */
4162 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
4164 #if (SIM_COUNT >= 2)
4165 if (socket_id == RIL_SOCKET_2) {
4166 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4167 pendingRequestsHook = &s_pendingRequests_socket2;
4169 #if (SIM_COUNT >= 3)
4170 else if (socket_id == RIL_SOCKET_3) {
4171 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4172 pendingRequestsHook = &s_pendingRequests_socket3;
4175 #if (SIM_COUNT >= 4)
4176 else if (socket_id == RIL_SOCKET_4) {
4177 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4178 pendingRequestsHook = &s_pendingRequests_socket4;
4182 /* mark pending requests as "cancelled" so we dont report responses */
4183 ret = pthread_mutex_lock(pendingRequestsMutexHook);
4186 p_cur = *pendingRequestsHook;
4188 for (p_cur = *pendingRequestsHook
4190 ; p_cur = p_cur->p_next
4192 p_cur->cancelled = 1;
4195 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
4199 static void processCommandsCallback(int fd, short flags, void *param) {
4204 SocketListenParam *p_info = (SocketListenParam *)param;
4206 assert(fd == p_info->fdCommand);
4208 p_rs = p_info->p_rs;
4211 /* loop until EAGAIN/EINTR, end of stream, or other error */
4212 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
4214 if (ret == 0 && p_record == NULL) {
4217 } else if (ret < 0) {
4219 } else if (ret == 0) { /* && p_record != NULL */
4220 processCommandBuffer(p_record, recordlen, p_info->socket_id);
4224 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
4225 /* fatal error or end-of-stream */
4227 RLOGE("error on reading command socket errno:%d\n", errno);
4229 RLOGW("EOS. Closing command socket.");
4233 p_info->fdCommand = -1;
4235 ril_event_del(p_info->commands_event);
4237 record_stream_free(p_rs);
4239 /* start listening for new connections again */
4240 rilEventAddWakeup(&s_listen_event);
4242 onCommandsSocketClosed(p_info->socket_id);
4247 static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
4248 // Inform we are connected and the ril version
4249 int rilVer = s_callbacks.version;
4250 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
4251 &rilVer, sizeof(rilVer), socket_id);
4253 // implicit radio state changed
4254 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
4255 NULL, 0, socket_id);
4257 // Send last NITZ time data, in case it was missed
4258 if (s_lastNITZTimeData != NULL) {
4259 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
4261 free(s_lastNITZTimeData);
4262 s_lastNITZTimeData = NULL;
4265 // Get version string
4266 if (s_callbacks.getVersion != NULL) {
4267 const char *version;
4268 version = s_callbacks.getVersion();
4269 RLOGI("RIL Daemon version: %s\n", version);
4271 property_set(PROPERTY_RIL_IMPL, version);
4273 RLOGI("RIL Daemon version: unavailable\n");
4274 property_set(PROPERTY_RIL_IMPL, "unavailable");
4279 static void listenCallback (int fd, short flags, void *param) {
4282 int is_phone_socket;
4284 const char* processName;
4286 MySocketListenParam* listenParam;
4287 RilSocket *sapSocket = NULL;
4288 socketClient *sClient = NULL;
4290 SocketListenParam *p_info = (SocketListenParam *)param;
4292 if(RIL_SAP_SOCKET == p_info->type) {
4293 listenParam = (MySocketListenParam *)param;
4294 sapSocket = listenParam->socket;
4297 struct sockaddr_un peeraddr;
4298 socklen_t socklen = sizeof (peeraddr);
4301 socklen_t szCreds = sizeof(creds);
4303 struct passwd *pwd = NULL;
4305 if(NULL == sapSocket) {
4306 assert (*p_info->fdCommand < 0);
4307 assert (fd == *p_info->fdListen);
4308 processName = PHONE_PROCESS;
4310 assert (sapSocket->commandFd < 0);
4311 assert (fd == sapSocket->listenFd);
4312 processName = BLUETOOTH_PROCESS;
4316 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
4318 if (fdCommand < 0 ) {
4319 RLOGE("Error on accept() errno:%d", errno);
4320 /* start listening for new connections again */
4321 if(NULL == sapSocket) {
4322 rilEventAddWakeup(p_info->listen_event);
4324 rilEventAddWakeup(sapSocket->getListenEvent());
4329 /* check the credential of the other side and only accept socket from
4333 is_phone_socket = 0;
4335 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
4337 if (err == 0 && szCreds > 0) {
4339 pwd = getpwuid(creds.uid);
4341 if (strcmp(pwd->pw_name, processName) == 0) {
4342 is_phone_socket = 1;
4344 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
4347 RLOGE("Error on getpwuid() errno: %d", errno);
4350 RLOGD("Error on getsockopt() errno: %d", errno);
4353 if (!is_phone_socket) {
4354 RLOGE("RILD must accept socket from %s", processName);
4359 if(NULL == sapSocket) {
4360 onCommandsSocketClosed(p_info->socket_id);
4362 /* start listening for new connections again */
4363 rilEventAddWakeup(p_info->listen_event);
4365 sapSocket->onCommandsSocketClosed();
4367 /* start listening for new connections again */
4368 rilEventAddWakeup(sapSocket->getListenEvent());
4374 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
4377 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
4380 if(NULL == sapSocket) {
4381 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
4383 p_info->fdCommand = fdCommand;
4384 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4385 p_info->p_rs = p_rs;
4387 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
4388 p_info->processCommandsCallback, p_info);
4389 rilEventAddWakeup (p_info->commands_event);
4391 onNewCommandConnect(p_info->socket_id);
4393 RLOGI("libril: new connection");
4395 sapSocket->setCommandFd(fdCommand);
4396 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4397 sClient = new socketClient(sapSocket,p_rs);
4398 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4399 sapSocket->getCommandCb(), sClient);
4401 rilEventAddWakeup(sapSocket->getCallbackEvent());
4402 sapSocket->onNewCommandConnect();
4406 static void freeDebugCallbackArgs(int number, char **args) {
4407 for (int i = 0; i < number; i++) {
4408 if (args[i] != NULL) {
4415 static void debugCallback (int fd, short flags, void *param) {
4416 int acceptFD, option;
4417 struct sockaddr_un peeraddr;
4418 socklen_t socklen = sizeof (peeraddr);
4420 unsigned int qxdm_data[6];
4421 const char *deactData[1] = {"1"};
4423 int hangupData[1] = {1};
4426 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4427 int MAX_DIAL_ADDRESS = 128;
4430 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
4432 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4435 RLOGE ("error accepting on debug port: %d\n", errno);
4439 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
4440 RLOGE ("error reading on socket: number of Args: \n");
4446 RLOGE ("Invalid number of arguments: \n");
4451 args = (char **) calloc(number, sizeof(char*));
4453 RLOGE("Memory allocation failed for debug args");
4458 for (int i = 0; i < number; i++) {
4460 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
4461 RLOGE ("error reading on socket: Len of Args: \n");
4462 freeDebugCallbackArgs(i, args);
4466 if (len == INT_MAX || len < 0) {
4467 RLOGE("Invalid value of len: \n");
4468 freeDebugCallbackArgs(i, args);
4474 args[i] = (char *) calloc(len + 1, sizeof(char));
4475 if (args[i] == NULL) {
4476 RLOGE("Memory allocation failed for debug args");
4477 freeDebugCallbackArgs(i, args);
4481 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4482 != (int)sizeof(char) * len) {
4483 RLOGE ("error reading on socket: Args[%d] \n", i);
4484 freeDebugCallbackArgs(i, args);
4488 char * buf = args[i];
4490 if ((i+1) == number) {
4491 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4492 sim_id = atoi(args[i]);
4495 socket_id = RIL_SOCKET_1;
4497 #if (SIM_COUNT >= 2)
4499 socket_id = RIL_SOCKET_2;
4502 #if (SIM_COUNT >= 3)
4504 socket_id = RIL_SOCKET_3;
4507 #if (SIM_COUNT >= 4)
4509 socket_id = RIL_SOCKET_4;
4513 socket_id = RIL_SOCKET_1;
4519 switch (atoi(args[0])) {
4521 RLOGI ("Connection on debug port: issuing reset.");
4522 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
4525 RLOGI ("Connection on debug port: issuing radio power off.");
4527 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
4529 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4530 close(s_ril_param_socket.fdCommand);
4531 s_ril_param_socket.fdCommand = -1;
4533 #if (SIM_COUNT == 2)
4534 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4535 close(s_ril_param_socket2.fdCommand);
4536 s_ril_param_socket2.fdCommand = -1;
4541 RLOGI ("Debug port: issuing unsolicited voice network change.");
4542 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
4545 RLOGI ("Debug port: QXDM log enable.");
4546 qxdm_data[0] = 65536; // head.func_tag
4547 qxdm_data[1] = 16; // head.len
4548 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4549 qxdm_data[3] = 32; // log_file_size: 32megabytes
4550 qxdm_data[4] = 0; // log_mask
4551 qxdm_data[5] = 8; // log_max_fileindex
4552 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
4553 6 * sizeof(int), socket_id);
4556 RLOGI ("Debug port: QXDM log disable.");
4557 qxdm_data[0] = 65536;
4559 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4563 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
4564 6 * sizeof(int), socket_id);
4567 RLOGI("Debug port: Radio On");
4569 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
4571 // Set network selection automatic.
4572 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
4575 RLOGI("Debug port: Deactivate Data Call");
4576 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
4577 sizeof(deactData), socket_id);
4580 RLOGI("Debug port: Dial Call");
4582 if (strlen(args[1]) > MAX_DIAL_ADDRESS) {
4583 RLOGE("Debug port: Error calling Dial");
4584 freeDebugCallbackArgs(number, args);
4588 dialData.address = args[1];
4589 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
4592 RLOGI("Debug port: Answer Call");
4593 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
4596 RLOGI("Debug port: End Call");
4597 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
4598 sizeof(hangupData), socket_id);
4601 RLOGE ("Invalid request");
4604 freeDebugCallbackArgs(number, args);
4609 static void userTimerCallback (int fd, short flags, void *param) {
4610 UserCallbackInfo *p_info;
4612 p_info = (UserCallbackInfo *)param;
4614 p_info->p_callback(p_info->userParam);
4617 // FIXME generalize this...there should be a cancel mechanism
4618 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4619 s_last_wake_timeout_info = NULL;
4627 eventLoop(void *param) {
4633 pthread_mutex_lock(&s_startupMutex);
4636 pthread_cond_broadcast(&s_startupCond);
4638 pthread_mutex_unlock(&s_startupMutex);
4640 ret = pipe(filedes);
4643 RLOGE("Error in pipe() errno:%d", errno);
4647 s_fdWakeupRead = filedes[0];
4648 s_fdWakeupWrite = filedes[1];
4650 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4652 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4653 processWakeupCallback, NULL);
4655 rilEventAddWakeup (&s_wakeupfd_event);
4657 // Only returns on error
4659 RLOGE ("error in event_loop_base errno:%d", errno);
4660 // kill self to restart on error
4667 RIL_startEventLoop(void) {
4668 /* spin up eventLoop thread and wait for it to get started */
4670 pthread_mutex_lock(&s_startupMutex);
4672 pthread_attr_t attr;
4673 pthread_attr_init(&attr);
4674 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
4676 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4678 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4682 while (s_started == 0) {
4683 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4687 pthread_mutex_unlock(&s_startupMutex);
4690 // Used for testing purpose only.
4691 extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4692 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4695 static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4698 char socket_name[10];
4700 memset(socket_name, 0, sizeof(char)*10);
4704 strncpy(socket_name, RIL_getRilSocketName(), 9);
4706 #if (SIM_COUNT >= 2)
4708 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4711 #if (SIM_COUNT >= 3)
4713 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4716 #if (SIM_COUNT >= 4)
4718 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4722 RLOGE("Socket id is wrong!!");
4726 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4728 fdListen = android_get_control_socket(socket_name);
4730 RLOGE("Failed to get socket %s", socket_name);
4734 ret = listen(fdListen, 4);
4737 RLOGE("Failed to listen on control socket '%d': %s",
4738 fdListen, strerror(errno));
4741 socket_listen_p->fdListen = fdListen;
4743 /* note: non-persistent so we can accept only one connection at a time */
4744 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4745 listenCallback, socket_listen_p);
4747 rilEventAddWakeup (socket_listen_p->listen_event);
4751 RIL_register (const RIL_RadioFunctions *callbacks) {
4755 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4757 if (callbacks == NULL) {
4758 RLOGE("RIL_register: RIL_RadioFunctions * null");
4761 if (callbacks->version < RIL_VERSION_MIN) {
4762 RLOGE("RIL_register: version %d is to old, min version is %d",
4763 callbacks->version, RIL_VERSION_MIN);
4767 RLOGE("RIL_register: RIL version %d", callbacks->version);
4769 if (s_registerCalled > 0) {
4770 RLOGE("RIL_register has been called more than once. "
4771 "Subsequent call ignored");
4775 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4777 /* Initialize socket1 parameters */
4778 s_ril_param_socket = {
4779 RIL_SOCKET_1, /* socket_id */
4782 PHONE_PROCESS, /* processName */
4783 &s_commands_event, /* commands_event */
4784 &s_listen_event, /* listen_event */
4785 processCommandsCallback, /* processCommandsCallback */
4787 RIL_TELEPHONY_SOCKET /* type */
4790 #if (SIM_COUNT >= 2)
4791 s_ril_param_socket2 = {
4792 RIL_SOCKET_2, /* socket_id */
4795 PHONE_PROCESS, /* processName */
4796 &s_commands_event_socket2, /* commands_event */
4797 &s_listen_event_socket2, /* listen_event */
4798 processCommandsCallback, /* processCommandsCallback */
4800 RIL_TELEPHONY_SOCKET /* type */
4804 #if (SIM_COUNT >= 3)
4805 s_ril_param_socket3 = {
4806 RIL_SOCKET_3, /* socket_id */
4809 PHONE_PROCESS, /* processName */
4810 &s_commands_event_socket3, /* commands_event */
4811 &s_listen_event_socket3, /* listen_event */
4812 processCommandsCallback, /* processCommandsCallback */
4814 RIL_TELEPHONY_SOCKET /* type */
4818 #if (SIM_COUNT >= 4)
4819 s_ril_param_socket4 = {
4820 RIL_SOCKET_4, /* socket_id */
4823 PHONE_PROCESS, /* processName */
4824 &s_commands_event_socket4, /* commands_event */
4825 &s_listen_event_socket4, /* listen_event */
4826 processCommandsCallback, /* processCommandsCallback */
4828 RIL_TELEPHONY_SOCKET /* type */
4833 s_registerCalled = 1;
4835 RLOGI("s_registerCalled flag set, %d", s_started);
4836 // Little self-check
4838 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4839 assert(i == s_commands[i].requestNumber);
4842 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
4843 assert(i + RIL_UNSOL_RESPONSE_BASE
4844 == s_unsolResponses[i].requestNumber);
4847 // New rild impl calls RIL_startEventLoop() first
4848 // old standalone impl wants it here.
4850 if (s_started == 0) {
4851 RIL_startEventLoop();
4854 // start listen socket1
4855 startListen(RIL_SOCKET_1, &s_ril_param_socket);
4857 #if (SIM_COUNT >= 2)
4858 // start listen socket2
4859 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4860 #endif /* (SIM_COUNT == 2) */
4862 #if (SIM_COUNT >= 3)
4863 // start listen socket3
4864 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4865 #endif /* (SIM_COUNT == 3) */
4867 #if (SIM_COUNT >= 4)
4868 // start listen socket4
4869 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4870 #endif /* (SIM_COUNT == 4) */
4874 // start debug interface socket
4877 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4878 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4881 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4883 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4886 s_fdDebug = android_get_control_socket(rildebug);
4887 if (s_fdDebug < 0) {
4888 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
4892 ret = listen(s_fdDebug, 4);
4895 RLOGE("Failed to listen on ril debug socket '%d': %s",
4896 s_fdDebug, strerror(errno));
4900 ril_event_set (&s_debug_event, s_fdDebug, true,
4901 debugCallback, NULL);
4903 rilEventAddWakeup (&s_debug_event);
4909 RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4911 RIL_RadioFunctions* UimFuncs = NULL;
4914 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4916 switch(socketType) {
4917 case RIL_SAP_SOCKET:
4918 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4920 #if (SIM_COUNT >= 2)
4921 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4924 #if (SIM_COUNT >= 3)
4925 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4928 #if (SIM_COUNT >= 4)
4929 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4937 // Check and remove RequestInfo if its a response and not just ack sent back
4939 checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
4941 /* Hook for current context
4942 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4943 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4944 /* pendingRequestsHook refer to &s_pendingRequests */
4945 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
4951 #if (SIM_COUNT >= 2)
4952 if (pRI->socket_id == RIL_SOCKET_2) {
4953 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4954 pendingRequestsHook = &s_pendingRequests_socket2;
4956 #if (SIM_COUNT >= 3)
4957 if (pRI->socket_id == RIL_SOCKET_3) {
4958 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4959 pendingRequestsHook = &s_pendingRequests_socket3;
4962 #if (SIM_COUNT >= 4)
4963 if (pRI->socket_id == RIL_SOCKET_4) {
4964 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4965 pendingRequestsHook = &s_pendingRequests_socket4;
4969 pthread_mutex_lock(pendingRequestsMutexHook);
4971 for(RequestInfo **ppCur = pendingRequestsHook
4973 ; ppCur = &((*ppCur)->p_next)
4975 if (pRI == *ppCur) {
4977 if (isAck) { // Async ack
4978 if (pRI->wasAckSent == 1) {
4979 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
4981 pRI->wasAckSent = 1;
4984 *ppCur = (*ppCur)->p_next;
4990 pthread_mutex_unlock(pendingRequestsMutexHook);
4995 static int findFd(int socket_id) {
4996 int fd = s_ril_param_socket.fdCommand;
4997 #if (SIM_COUNT >= 2)
4998 if (socket_id == RIL_SOCKET_2) {
4999 fd = s_ril_param_socket2.fdCommand;
5001 #if (SIM_COUNT >= 3)
5002 if (socket_id == RIL_SOCKET_3) {
5003 fd = s_ril_param_socket3.fdCommand;
5006 #if (SIM_COUNT >= 4)
5007 if (socket_id == RIL_SOCKET_4) {
5008 fd = s_ril_param_socket4.fdCommand;
5016 RIL_onRequestAck(RIL_Token t) {
5021 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5023 pRI = (RequestInfo *)t;
5025 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
5026 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
5030 socket_id = pRI->socket_id;
5031 fd = findFd(socket_id);
5034 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
5037 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
5039 if (pRI->cancelled == 0) {
5042 p.writeInt32 (RESPONSE_SOLICITED_ACK);
5043 p.writeInt32 (pRI->token);
5046 RLOGD ("RIL onRequestComplete: Command channel closed");
5049 sendResponse(p, socket_id);
5054 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
5059 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
5061 pRI = (RequestInfo *)t;
5063 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
5064 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
5068 socket_id = pRI->socket_id;
5069 fd = findFd(socket_id);
5072 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
5075 if (pRI->local > 0) {
5076 // Locally issued command...void only!
5077 // response does not go back up the command socket
5078 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
5083 appendPrintBuf("[%04d]< %s",
5084 pRI->token, requestToString(pRI->pCI->requestNumber));
5086 if (pRI->cancelled == 0) {
5089 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
5090 // If ack was already sent, then this call is an asynchronous response. So we need to
5091 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
5092 p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
5093 grabPartialWakeLock();
5095 p.writeInt32 (RESPONSE_SOLICITED);
5097 p.writeInt32 (pRI->token);
5098 errorOffset = p.dataPosition();
5102 if (response != NULL) {
5103 // there is a response payload, no matter success or not.
5104 ret = pRI->pCI->responseFunction(p, response, responselen);
5106 /* if an error occurred, rewind and mark it */
5108 RLOGE ("responseFunction error, ret %d", ret);
5109 p.setDataPosition(errorOffset);
5114 if (e != RIL_E_SUCCESS) {
5115 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
5119 RLOGD ("RIL onRequestComplete: Command channel closed");
5121 sendResponse(p, socket_id);
5129 grabPartialWakeLock() {
5130 if (s_callbacks.version >= 13) {
5132 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5134 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5136 UserCallbackInfo *p_info =
5137 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
5138 if (p_info == NULL) {
5139 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5142 if (s_last_wake_timeout_info != NULL) {
5143 s_last_wake_timeout_info->userParam = (void *)1;
5145 s_last_wake_timeout_info = p_info;
5147 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5150 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
5156 if (s_callbacks.version >= 13) {
5158 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5161 if (s_wakelock_count > 1) {
5164 s_wakelock_count = 0;
5165 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5166 if (s_last_wake_timeout_info != NULL) {
5167 s_last_wake_timeout_info->userParam = (void *)1;
5171 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5174 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5179 * Timer callback to put us back to sleep before the default timeout
5182 wakeTimeoutCallback (void *param) {
5183 // We're using "param != NULL" as a cancellation mechanism
5184 if (s_callbacks.version >= 13) {
5185 if (param == NULL) {
5187 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
5189 s_wakelock_count = 0;
5190 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
5191 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
5195 if (param == NULL) {
5202 decodeVoiceRadioTechnology (RIL_RadioState radioState) {
5203 switch (radioState) {
5204 case RADIO_STATE_SIM_NOT_READY:
5205 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5206 case RADIO_STATE_SIM_READY:
5207 return RADIO_TECH_UMTS;
5209 case RADIO_STATE_RUIM_NOT_READY:
5210 case RADIO_STATE_RUIM_READY:
5211 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5212 case RADIO_STATE_NV_NOT_READY:
5213 case RADIO_STATE_NV_READY:
5214 return RADIO_TECH_1xRTT;
5217 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
5223 decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
5224 switch (radioState) {
5225 case RADIO_STATE_SIM_NOT_READY:
5226 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5227 case RADIO_STATE_SIM_READY:
5228 case RADIO_STATE_RUIM_NOT_READY:
5229 case RADIO_STATE_RUIM_READY:
5230 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5231 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
5233 case RADIO_STATE_NV_NOT_READY:
5234 case RADIO_STATE_NV_READY:
5235 return CDMA_SUBSCRIPTION_SOURCE_NV;
5238 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
5244 decodeSimStatus (RIL_RadioState radioState) {
5245 switch (radioState) {
5246 case RADIO_STATE_SIM_NOT_READY:
5247 case RADIO_STATE_RUIM_NOT_READY:
5248 case RADIO_STATE_NV_NOT_READY:
5249 case RADIO_STATE_NV_READY:
5251 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
5252 case RADIO_STATE_SIM_READY:
5253 case RADIO_STATE_RUIM_READY:
5254 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
5257 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
5262 static bool is3gpp2(int radioTech) {
5263 switch (radioTech) {
5264 case RADIO_TECH_IS95A:
5265 case RADIO_TECH_IS95B:
5266 case RADIO_TECH_1xRTT:
5267 case RADIO_TECH_EVDO_0:
5268 case RADIO_TECH_EVDO_A:
5269 case RADIO_TECH_EVDO_B:
5270 case RADIO_TECH_EHRPD:
5277 /* If RIL sends SIM states or RUIM states, store the voice radio
5278 * technology and subscription source information so that they can be
5279 * returned when telephony framework requests them
5281 static RIL_RadioState
5282 processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
5284 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
5285 int newVoiceRadioTech;
5286 int newCdmaSubscriptionSource;
5289 /* This is old RIL. Decode Subscription source and Voice Radio Technology
5290 from Radio State and send change notifications if there has been a change */
5291 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
5292 if(newVoiceRadioTech != voiceRadioTech) {
5293 voiceRadioTech = newVoiceRadioTech;
5294 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
5295 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
5297 if(is3gpp2(newVoiceRadioTech)) {
5298 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
5299 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
5300 cdmaSubscriptionSource = newCdmaSubscriptionSource;
5301 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
5302 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
5305 newSimStatus = decodeSimStatus(newRadioState);
5306 if(newSimStatus != simRuimStatus) {
5307 simRuimStatus = newSimStatus;
5308 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
5311 /* Send RADIO_ON to telephony */
5312 newRadioState = RADIO_STATE_ON;
5315 return newRadioState;
5319 #if defined(ANDROID_MULTI_SIM)
5321 void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
5322 size_t datalen, RIL_SOCKET_ID socket_id)
5325 void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
5329 int unsolResponseIndex;
5331 int64_t timeReceived = 0;
5332 bool shouldScheduleTimeout = false;
5333 RIL_RadioState newState;
5334 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
5336 #if defined(ANDROID_MULTI_SIM)
5341 if (s_registerCalled == 0) {
5342 // Ignore RIL_onUnsolicitedResponse before RIL_register
5343 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
5347 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
5349 if ((unsolResponseIndex < 0)
5350 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
5351 RLOGE("unsupported unsolicited response code %d", unsolResponse);
5355 // Grab a wake lock if needed for this reponse,
5356 // as we exit we'll either release it immediately
5357 // or set a timer to release it later.
5358 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
5360 grabPartialWakeLock();
5361 shouldScheduleTimeout = true;
5366 // No wake lock is grabed so don't set timeout
5367 shouldScheduleTimeout = false;
5371 // Mark the time this was received, doing this
5372 // after grabing the wakelock incase getting
5373 // the elapsedRealTime might cause us to goto
5375 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5376 timeReceived = elapsedRealtime();
5379 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
5382 if (s_callbacks.version >= 13
5383 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
5384 p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
5386 p.writeInt32 (RESPONSE_UNSOLICITED);
5388 p.writeInt32 (unsolResponse);
5390 ret = s_unsolResponses[unsolResponseIndex]
5391 .responseFunction(p, const_cast<void*>(data), datalen);
5393 // Problem with the response. Don't continue;
5397 // some things get more payload
5398 switch(unsolResponse) {
5399 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
5400 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
5401 p.writeInt32(newState);
5402 appendPrintBuf("%s {%s}", printBuf,
5403 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
5407 case RIL_UNSOL_NITZ_TIME_RECEIVED:
5408 // Store the time that this was received so the
5409 // handler of this message can account for
5410 // the time it takes to arrive and process. In
5411 // particular the system has been known to sleep
5412 // before this message can be processed.
5413 p.writeInt64(timeReceived);
5417 if (s_callbacks.version < 13) {
5418 if (shouldScheduleTimeout) {
5419 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5420 &TIMEVAL_WAKE_TIMEOUT);
5422 if (p_info == NULL) {
5425 // Cancel the previous request
5426 if (s_last_wake_timeout_info != NULL) {
5427 s_last_wake_timeout_info->userParam = (void *)1;
5429 s_last_wake_timeout_info = p_info;
5435 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
5437 ret = sendResponse(p, soc_id);
5438 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5440 // Unfortunately, NITZ time is not poll/update like everything
5441 // else in the system. So, if the upstream client isn't connected,
5442 // keep a copy of the last NITZ response (with receive time noted
5443 // above) around so we can deliver it when it is connected
5445 if (s_lastNITZTimeData != NULL) {
5446 free (s_lastNITZTimeData);
5447 s_lastNITZTimeData = NULL;
5450 s_lastNITZTimeData = calloc(p.dataSize(), 1);
5451 if (s_lastNITZTimeData == NULL) {
5452 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
5455 s_lastNITZTimeDataSize = p.dataSize();
5456 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5463 if (shouldScheduleTimeout) {
5468 /** FIXME generalize this if you track UserCAllbackInfo, clear it
5469 when the callback occurs
5471 static UserCallbackInfo *
5472 internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5473 const struct timeval *relativeTime)
5475 struct timeval myRelativeTime;
5476 UserCallbackInfo *p_info;
5478 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
5479 if (p_info == NULL) {
5480 RLOGE("Memory allocation failed in internalRequestTimedCallback");
5485 p_info->p_callback = callback;
5486 p_info->userParam = param;
5488 if (relativeTime == NULL) {
5489 /* treat null parameter as a 0 relative time */
5490 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5492 /* FIXME I think event_add's tv param is really const anyway */
5493 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5496 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5498 ril_timer_add(&(p_info->event), &myRelativeTime);
5506 RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5507 const struct timeval *relativeTime) {
5508 internalRequestTimedCallback (callback, param, relativeTime);
5512 failCauseToString(RIL_Errno e) {
5514 case RIL_E_SUCCESS: return "E_SUCCESS";
5515 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
5516 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5517 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5518 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5519 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5520 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5521 case RIL_E_CANCELLED: return "E_CANCELLED";
5522 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5523 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5524 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5525 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5526 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5527 #ifdef FEATURE_MULTIMODE_ANDROID
5528 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5529 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5531 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
5532 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
5533 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
5534 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
5535 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
5536 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
5537 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
5538 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
5539 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
5540 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
5541 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
5542 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
5543 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
5544 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
5545 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
5546 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
5547 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
5548 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
5549 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
5550 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
5551 case RIL_E_SIM_ERR: return "E_SIM_ERR";
5552 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
5553 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
5554 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
5555 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
5556 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
5557 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
5558 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
5559 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
5560 case RIL_E_SIM_FULL: return "E_SIM_FULL";
5561 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
5562 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
5563 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
5564 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
5565 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
5566 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
5567 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
5568 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
5569 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
5570 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
5571 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
5572 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
5573 case RIL_E_ABORTED: return "E_ABORTED";
5574 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
5575 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
5576 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
5577 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
5578 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
5579 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
5580 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
5581 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
5582 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
5583 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
5584 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
5585 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
5586 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
5587 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
5588 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
5589 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
5590 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
5591 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
5592 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
5593 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
5594 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
5595 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
5596 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
5597 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
5598 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
5599 default: return "<unknown error>";
5604 radioStateToString(RIL_RadioState s) {
5606 case RADIO_STATE_OFF: return "RADIO_OFF";
5607 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5608 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5609 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5610 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5611 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5612 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5613 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5614 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5615 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5616 case RADIO_STATE_ON:return"RADIO_ON";
5617 default: return "<unknown state>";
5622 callStateToString(RIL_CallState s) {
5624 case RIL_CALL_ACTIVE : return "ACTIVE";
5625 case RIL_CALL_HOLDING: return "HOLDING";
5626 case RIL_CALL_DIALING: return "DIALING";
5627 case RIL_CALL_ALERTING: return "ALERTING";
5628 case RIL_CALL_INCOMING: return "INCOMING";
5629 case RIL_CALL_WAITING: return "WAITING";
5630 default: return "<unknown state>";
5635 requestToString(int request) {
5637 cat libs/telephony/ril_commands.h \
5638 | egrep "^ *{RIL_" \
5639 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5642 cat libs/telephony/ril_unsol_commands.h \
5643 | egrep "^ *{RIL_" \
5644 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5648 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5649 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5650 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5651 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5652 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5653 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5654 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5655 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5656 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5657 case RIL_REQUEST_DIAL: return "DIAL";
5658 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5659 case RIL_REQUEST_HANGUP: return "HANGUP";
5660 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5661 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5662 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5663 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5664 case RIL_REQUEST_UDUB: return "UDUB";
5665 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5666 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5667 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5668 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5669 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5670 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5671 case RIL_REQUEST_DTMF: return "DTMF";
5672 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5673 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5674 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5675 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5676 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5677 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5678 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5679 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5680 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5681 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5682 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5683 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5684 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5685 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5686 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5687 case RIL_REQUEST_ANSWER: return "ANSWER";
5688 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5689 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5690 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5691 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5692 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5693 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5694 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5695 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5696 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5697 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5698 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5699 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5700 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5701 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5702 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5703 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5704 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5705 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5706 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5707 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5708 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
5709 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5710 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5711 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5712 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5713 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5714 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5715 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5716 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5717 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5718 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5719 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5720 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5721 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
5722 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
5723 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5724 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5725 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5726 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5727 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5728 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5729 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5730 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5731 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5732 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5733 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5734 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5735 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5736 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5737 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
5738 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
5739 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5740 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5741 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5742 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5743 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5744 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5745 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5746 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5747 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5748 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5749 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5750 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5751 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5752 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
5753 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
5754 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5755 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
5756 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5757 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5758 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
5759 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5760 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5761 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5762 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
5763 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5764 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
5765 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5766 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5767 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5768 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5769 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5770 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5771 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
5772 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
5773 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
5774 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5775 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5776 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5777 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5778 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5779 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5780 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5781 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5782 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5783 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
5784 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
5785 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5786 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5787 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5788 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5789 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5790 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
5791 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5792 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5793 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5794 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5795 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5796 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5797 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5798 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5799 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5800 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5801 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5802 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5803 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5804 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5805 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5806 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5807 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5808 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5809 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
5810 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
5811 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
5812 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5813 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5814 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5815 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
5816 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
5817 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
5818 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT";
5819 case RIL_UNSOL_PCO_DATA: return "RIL_UNSOL_PCO_DATA";
5820 default: return "<unknown request>";
5825 rilSocketIdToString(RIL_SOCKET_ID socket_id)
5829 return "RIL_SOCKET_1";
5830 #if (SIM_COUNT >= 2)
5832 return "RIL_SOCKET_2";
5834 #if (SIM_COUNT >= 3)
5836 return "RIL_SOCKET_3";
5838 #if (SIM_COUNT >= 4)
5840 return "RIL_SOCKET_4";
5843 return "not a valid RIL";
5848 * Returns true for a debuggable build.
5850 static bool isDebuggable() {
5851 char debuggable[PROP_VALUE_MAX];
5852 property_get("ro.debuggable", debuggable, "0");
5853 if (strcmp(debuggable, "1") == 0) {
5859 } /* namespace android */
5861 void rilEventAddWakeup_helper(struct ril_event *ev) {
5862 android::rilEventAddWakeup(ev);
5865 void listenCallback_helper(int fd, short flags, void *param) {
5866 android::listenCallback(fd, flags, param);
5869 int blockingWrite_helper(int fd, void *buffer, size_t len) {
5870 return android::blockingWrite(fd, buffer, len);