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>
22 #include <telephony/ril.h>
23 #include <telephony/ril_cdma_sms.h>
24 #include <cutils/sockets.h>
25 #include <cutils/jstring.h>
26 #include <cutils/record_stream.h>
27 #include <utils/Log.h>
28 #include <utils/SystemClock.h>
30 #include <binder/Parcel.h>
31 #include <cutils/jstring.h>
33 #include <sys/types.h>
34 #include <sys/limits.h>
50 #include <netinet/in.h>
51 #include <cutils/properties.h>
53 #include <ril_event.h>
57 #define PHONE_PROCESS "radio"
59 #define SOCKET_NAME_RIL "rild"
60 #define SOCKET_NAME_RIL_DEBUG "rild-debug"
62 #define ANDROID_WAKE_LOCK_NAME "radio-interface"
65 #define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
67 // match with constant in RIL.java
68 #define MAX_COMMAND_BYTES (8 * 1024)
70 // Basically: memset buffers that the client library
71 // shouldn't be using anymore in an attempt to find
72 // memory usage issues sooner.
73 #define MEMSET_FREED 1
75 #define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
77 #define MIN(a,b) ((a)<(b) ? (a) : (b))
79 /* Constants for response types */
80 #define RESPONSE_SOLICITED 0
81 #define RESPONSE_UNSOLICITED 1
83 /* Negative values for private RIL errno's */
84 #define RIL_ERRNO_INVALID_RESPONSE -1
86 // request, response, and unsolicited msg print macro
87 #define PRINTBUF_SIZE 8096
93 #define startRequest sprintf(printBuf, "(")
94 #define closeRequest sprintf(printBuf, "%s)", printBuf)
95 #define printRequest(token, req) \
96 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
98 #define startResponse sprintf(printBuf, "%s {", printBuf)
99 #define closeResponse sprintf(printBuf, "%s}", printBuf)
100 #define printResponse RLOGD("%s", printBuf)
102 #define clearPrintBuf printBuf[0] = 0
103 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
104 #define appendPrintBuf(x...) sprintf(printBuf, x)
108 #define printRequest(token, req)
109 #define startResponse
110 #define closeResponse
111 #define printResponse
112 #define clearPrintBuf
113 #define removeLastChar
114 #define appendPrintBuf(x...)
117 enum WakeType {DONT_WAKE, WAKE_PARTIAL};
121 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
122 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
127 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
131 typedef struct RequestInfo {
132 int32_t token; //this is not RIL_Token
134 struct RequestInfo *p_next;
136 char local; // responses to local commands do not go back to command process
139 typedef struct UserCallbackInfo {
140 RIL_TimedCallback p_callback;
142 struct ril_event event;
143 struct UserCallbackInfo *p_next;
147 /*******************************************************************/
149 RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
150 static int s_registerCalled = 0;
152 static pthread_t s_tid_dispatch;
153 static pthread_t s_tid_reader;
154 static int s_started = 0;
156 static int s_fdListen = -1;
157 static int s_fdCommand = -1;
158 static int s_fdDebug = -1;
160 static int s_fdWakeupRead;
161 static int s_fdWakeupWrite;
163 static struct ril_event s_commands_event;
164 static struct ril_event s_wakeupfd_event;
165 static struct ril_event s_listen_event;
166 static struct ril_event s_wake_timeout_event;
167 static struct ril_event s_debug_event;
170 static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
172 static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
173 static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
174 static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
175 static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
177 static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
178 static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
180 static RequestInfo *s_pendingRequests = NULL;
182 static RequestInfo *s_toDispatchHead = NULL;
183 static RequestInfo *s_toDispatchTail = NULL;
185 static UserCallbackInfo *s_last_wake_timeout_info = NULL;
187 static void *s_lastNITZTimeData = NULL;
188 static size_t s_lastNITZTimeDataSize;
191 static char printBuf[PRINTBUF_SIZE];
194 /*******************************************************************/
196 static void dispatchVoid (Parcel& p, RequestInfo *pRI);
197 static void dispatchString (Parcel& p, RequestInfo *pRI);
198 static void dispatchStrings (Parcel& p, RequestInfo *pRI);
199 static void dispatchInts (Parcel& p, RequestInfo *pRI);
200 static void dispatchDial (Parcel& p, RequestInfo *pRI);
201 static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
202 static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
203 static void dispatchRaw(Parcel& p, RequestInfo *pRI);
204 static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
205 static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
206 static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
207 static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
209 static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
210 static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
211 static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
212 static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
213 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
214 static int responseInts(Parcel &p, void *response, size_t responselen);
215 static int responseStrings(Parcel &p, void *response, size_t responselen);
216 static int responseString(Parcel &p, void *response, size_t responselen);
217 static int responseVoid(Parcel &p, void *response, size_t responselen);
218 static int responseCallList(Parcel &p, void *response, size_t responselen);
219 static int responseSMS(Parcel &p, void *response, size_t responselen);
220 static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
221 static int responseCallForwards(Parcel &p, void *response, size_t responselen);
222 static int responseDataCallList(Parcel &p, void *response, size_t responselen);
223 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
224 static int responseRaw(Parcel &p, void *response, size_t responselen);
225 static int responseSsn(Parcel &p, void *response, size_t responselen);
226 static int responseSimStatus(Parcel &p, void *response, size_t responselen);
227 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
228 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
229 static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
230 static int responseCellList(Parcel &p, void *response, size_t responselen);
231 static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
232 static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
233 static int responseCallRing(Parcel &p, void *response, size_t responselen);
234 static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
235 static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
236 static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
237 static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
239 static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
240 static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
241 static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
243 extern "C" const char * requestToString(int request);
244 extern "C" const char * failCauseToString(RIL_Errno);
245 extern "C" const char * callStateToString(RIL_CallState);
246 extern "C" const char * radioStateToString(RIL_RadioState);
249 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
253 static UserCallbackInfo * internalRequestTimedCallback
254 (RIL_TimedCallback callback, void *param,
255 const struct timeval *relativeTime);
257 /** Index == requestNumber */
258 static CommandInfo s_commands[] = {
259 #include "ril_commands.h"
262 static UnsolResponseInfo s_unsolResponses[] = {
263 #include "ril_unsol_commands.h"
266 /* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
267 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
268 radio state message and store it. Every time there is a change in Radio State
269 check to see if voice radio tech changes and notify telephony
271 int voiceRadioTech = -1;
273 /* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
274 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
275 source from radio state and store it. Every time there is a change in Radio State
276 check to see if subscription source changed and notify telephony
278 int cdmaSubscriptionSource = -1;
280 /* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
281 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
282 check to see if SIM/RUIM status changed and notify telephony
284 int simRuimStatus = -1;
287 strdupReadString(Parcel &p) {
291 s16 = p.readString16Inplace(&stringlen);
293 return strndup16to8(s16, stringlen);
296 static void writeStringToParcel(Parcel &p, const char *s) {
299 s16 = strdup8to16(s, &s16_len);
300 p.writeString16(s16, s16_len);
306 memsetString (char *s) {
308 memset (s, 0, strlen(s));
312 void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
313 const size_t* objects, size_t objectsSize,
315 // do nothing -- the data reference lives longer than the Parcel object
319 * To be called from dispatch thread
320 * Issue a single local request, ensuring that the response
321 * is not sent back up to the command process
324 issueLocalRequest(int request, void *data, int len) {
328 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
331 pRI->token = 0xffffffff; // token is not used in this context
332 pRI->pCI = &(s_commands[request]);
334 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
337 pRI->p_next = s_pendingRequests;
338 s_pendingRequests = pRI;
340 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
343 RLOGD("C[locl]> %s", requestToString(request));
345 s_callbacks.onRequest(request, data, len, pRI);
351 processCommandBuffer(void *buffer, size_t buflen) {
359 p.setData((uint8_t *) buffer, buflen);
361 // status checked at end
362 status = p.readInt32(&request);
363 status = p.readInt32 (&token);
365 if (status != NO_ERROR) {
366 RLOGE("invalid request block");
370 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
371 RLOGE("unsupported request code %d token %d", request, token);
372 // FIXME this should perhaps return a response
377 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
380 pRI->pCI = &(s_commands[request]);
382 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
385 pRI->p_next = s_pendingRequests;
386 s_pendingRequests = pRI;
388 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
391 /* sLastDispatchedToken = token; */
393 pRI->pCI->dispatchFunction(p, pRI);
399 invalidCommandBlock (RequestInfo *pRI) {
400 RLOGE("invalid command block for token %d request %s",
401 pRI->token, requestToString(pRI->pCI->requestNumber));
404 /** Callee expects NULL */
406 dispatchVoid (Parcel& p, RequestInfo *pRI) {
408 printRequest(pRI->token, pRI->pCI->requestNumber);
409 s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
412 /** Callee expects const char * */
414 dispatchString (Parcel& p, RequestInfo *pRI) {
418 char *string8 = NULL;
420 string8 = strdupReadString(p);
423 appendPrintBuf("%s%s", printBuf, string8);
425 printRequest(pRI->token, pRI->pCI->requestNumber);
427 s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
428 sizeof(char *), pRI);
431 memsetString(string8);
437 invalidCommandBlock(pRI);
441 /** Callee expects const char ** */
443 dispatchStrings (Parcel &p, RequestInfo *pRI) {
444 int32_t countStrings;
449 status = p.readInt32 (&countStrings);
451 if (status != NO_ERROR) {
456 if (countStrings == 0) {
457 // just some non-null pointer
458 pStrings = (char **)alloca(sizeof(char *));
460 } else if (((int)countStrings) == -1) {
464 datalen = sizeof(char *) * countStrings;
466 pStrings = (char **)alloca(datalen);
468 for (int i = 0 ; i < countStrings ; i++) {
469 pStrings[i] = strdupReadString(p);
470 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
475 printRequest(pRI->token, pRI->pCI->requestNumber);
477 s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
479 if (pStrings != NULL) {
480 for (int i = 0 ; i < countStrings ; i++) {
482 memsetString (pStrings[i]);
488 memset(pStrings, 0, datalen);
494 invalidCommandBlock(pRI);
498 /** Callee expects const int * */
500 dispatchInts (Parcel &p, RequestInfo *pRI) {
506 status = p.readInt32 (&count);
508 if (status != NO_ERROR || count == 0) {
512 datalen = sizeof(int) * count;
513 pInts = (int *)alloca(datalen);
516 for (int i = 0 ; i < count ; i++) {
519 status = p.readInt32(&t);
521 appendPrintBuf("%s%d,", printBuf, t);
523 if (status != NO_ERROR) {
529 printRequest(pRI->token, pRI->pCI->requestNumber);
531 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts),
535 memset(pInts, 0, datalen);
540 invalidCommandBlock(pRI);
546 * Callee expects const RIL_SMS_WriteArgs *
552 dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
553 RIL_SMS_WriteArgs args;
557 memset (&args, 0, sizeof(args));
559 status = p.readInt32(&t);
560 args.status = (int)t;
562 args.pdu = strdupReadString(p);
564 if (status != NO_ERROR || args.pdu == NULL) {
568 args.smsc = strdupReadString(p);
571 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
572 (char*)args.pdu, (char*)args.smsc);
574 printRequest(pRI->token, pRI->pCI->requestNumber);
576 s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
579 memsetString (args.pdu);
585 memset(&args, 0, sizeof(args));
590 invalidCommandBlock(pRI);
595 * Callee expects const RIL_Dial *
601 dispatchDial (Parcel &p, RequestInfo *pRI) {
603 RIL_UUS_Info uusInfo;
609 memset (&dial, 0, sizeof(dial));
611 dial.address = strdupReadString(p);
613 status = p.readInt32(&t);
616 if (status != NO_ERROR || dial.address == NULL) {
620 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
622 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
624 status = p.readInt32(&uusPresent);
626 if (status != NO_ERROR) {
630 if (uusPresent == 0) {
635 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
637 status = p.readInt32(&t);
638 uusInfo.uusType = (RIL_UUS_Type) t;
640 status = p.readInt32(&t);
641 uusInfo.uusDcs = (RIL_UUS_DCS) t;
643 status = p.readInt32(&len);
644 if (status != NO_ERROR) {
648 // The java code writes -1 for null arrays
649 if (((int) len) == -1) {
650 uusInfo.uusData = NULL;
653 uusInfo.uusData = (char*) p.readInplace(len);
656 uusInfo.uusLength = len;
657 dial.uusInfo = &uusInfo;
659 sizeOfDial = sizeof(dial);
663 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
665 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
666 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
667 dial.uusInfo->uusLength);
670 printRequest(pRI->token, pRI->pCI->requestNumber);
672 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI);
675 memsetString (dial.address);
681 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
682 memset(&dial, 0, sizeof(dial));
687 invalidCommandBlock(pRI);
692 * Callee expects const RIL_SIM_IO *
703 dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
713 memset (&simIO, 0, sizeof(simIO));
715 // note we only check status at the end
717 status = p.readInt32(&t);
718 simIO.v6.command = (int)t;
720 status = p.readInt32(&t);
721 simIO.v6.fileid = (int)t;
723 simIO.v6.path = strdupReadString(p);
725 status = p.readInt32(&t);
726 simIO.v6.p1 = (int)t;
728 status = p.readInt32(&t);
729 simIO.v6.p2 = (int)t;
731 status = p.readInt32(&t);
732 simIO.v6.p3 = (int)t;
734 simIO.v6.data = strdupReadString(p);
735 simIO.v6.pin2 = strdupReadString(p);
736 simIO.v6.aidPtr = strdupReadString(p);
739 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
740 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
741 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
742 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
744 printRequest(pRI->token, pRI->pCI->requestNumber);
746 if (status != NO_ERROR) {
750 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
751 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, size, pRI);
754 memsetString (simIO.v6.path);
755 memsetString (simIO.v6.data);
756 memsetString (simIO.v6.pin2);
757 memsetString (simIO.v6.aidPtr);
760 free (simIO.v6.path);
761 free (simIO.v6.data);
762 free (simIO.v6.pin2);
763 free (simIO.v6.aidPtr);
766 memset(&simIO, 0, sizeof(simIO));
771 invalidCommandBlock(pRI);
776 * Callee expects const RIL_CallForwardInfo *
778 * int32_t status/action
780 * int32_t serviceCode
782 * String number (0 length -> null)
783 * int32_t timeSeconds
786 dispatchCallForward(Parcel &p, RequestInfo *pRI) {
787 RIL_CallForwardInfo cff;
791 memset (&cff, 0, sizeof(cff));
793 // note we only check status at the end
795 status = p.readInt32(&t);
798 status = p.readInt32(&t);
801 status = p.readInt32(&t);
802 cff.serviceClass = (int)t;
804 status = p.readInt32(&t);
807 cff.number = strdupReadString(p);
809 status = p.readInt32(&t);
810 cff.timeSeconds = (int)t;
812 if (status != NO_ERROR) {
816 // special case: number 0-length fields is null
818 if (cff.number != NULL && strlen (cff.number) == 0) {
823 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
824 cff.status, cff.reason, cff.serviceClass, cff.toa,
825 (char*)cff.number, cff.timeSeconds);
827 printRequest(pRI->token, pRI->pCI->requestNumber);
829 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
832 memsetString(cff.number);
838 memset(&cff, 0, sizeof(cff));
843 invalidCommandBlock(pRI);
849 dispatchRaw(Parcel &p, RequestInfo *pRI) {
854 status = p.readInt32(&len);
856 if (status != NO_ERROR) {
860 // The java code writes -1 for null arrays
861 if (((int)len) == -1) {
866 data = p.readInplace(len);
869 appendPrintBuf("%sraw_size=%d", printBuf, len);
871 printRequest(pRI->token, pRI->pCI->requestNumber);
873 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
877 invalidCommandBlock(pRI);
882 dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
883 RIL_CDMA_SMS_Message rcsm;
890 memset(&rcsm, 0, sizeof(rcsm));
892 status = p.readInt32(&t);
893 rcsm.uTeleserviceID = (int) t;
895 status = p.read(&ut,sizeof(ut));
896 rcsm.bIsServicePresent = (uint8_t) ut;
898 status = p.readInt32(&t);
899 rcsm.uServicecategory = (int) t;
901 status = p.readInt32(&t);
902 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
904 status = p.readInt32(&t);
905 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
907 status = p.readInt32(&t);
908 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
910 status = p.readInt32(&t);
911 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
913 status = p.read(&ut,sizeof(ut));
914 rcsm.sAddress.number_of_digits= (uint8_t) ut;
916 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
917 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
918 status = p.read(&ut,sizeof(ut));
919 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
922 status = p.readInt32(&t);
923 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
925 status = p.read(&ut,sizeof(ut));
926 rcsm.sSubAddress.odd = (uint8_t) ut;
928 status = p.read(&ut,sizeof(ut));
929 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
931 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
932 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
933 status = p.read(&ut,sizeof(ut));
934 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
937 status = p.readInt32(&t);
938 rcsm.uBearerDataLen = (int) t;
940 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
941 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
942 status = p.read(&ut, sizeof(ut));
943 rcsm.aBearerData[digitCount] = (uint8_t) ut;
946 if (status != NO_ERROR) {
951 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
952 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
953 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
954 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
957 printRequest(pRI->token, pRI->pCI->requestNumber);
959 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
962 memset(&rcsm, 0, sizeof(rcsm));
968 invalidCommandBlock(pRI);
973 dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
974 RIL_CDMA_SMS_Ack rcsa;
979 memset(&rcsa, 0, sizeof(rcsa));
981 status = p.readInt32(&t);
982 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
984 status = p.readInt32(&t);
985 rcsa.uSMSCauseCode = (int) t;
987 if (status != NO_ERROR) {
992 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
993 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
996 printRequest(pRI->token, pRI->pCI->requestNumber);
998 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI);
1001 memset(&rcsa, 0, sizeof(rcsa));
1007 invalidCommandBlock(pRI);
1012 dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1017 status = p.readInt32(&num);
1018 if (status != NO_ERROR) {
1023 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1024 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
1027 for (int i = 0 ; i < num ; i++ ) {
1028 gsmBciPtrs[i] = &gsmBci[i];
1030 status = p.readInt32(&t);
1031 gsmBci[i].fromServiceId = (int) t;
1033 status = p.readInt32(&t);
1034 gsmBci[i].toServiceId = (int) t;
1036 status = p.readInt32(&t);
1037 gsmBci[i].fromCodeScheme = (int) t;
1039 status = p.readInt32(&t);
1040 gsmBci[i].toCodeScheme = (int) t;
1042 status = p.readInt32(&t);
1043 gsmBci[i].selected = (uint8_t) t;
1045 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1046 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1047 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1048 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1049 gsmBci[i].selected);
1053 if (status != NO_ERROR) {
1057 s_callbacks.onRequest(pRI->pCI->requestNumber,
1059 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1063 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1064 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
1071 invalidCommandBlock(pRI);
1076 dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1081 status = p.readInt32(&num);
1082 if (status != NO_ERROR) {
1087 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1088 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
1091 for (int i = 0 ; i < num ; i++ ) {
1092 cdmaBciPtrs[i] = &cdmaBci[i];
1094 status = p.readInt32(&t);
1095 cdmaBci[i].service_category = (int) t;
1097 status = p.readInt32(&t);
1098 cdmaBci[i].language = (int) t;
1100 status = p.readInt32(&t);
1101 cdmaBci[i].selected = (uint8_t) t;
1103 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1104 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1105 cdmaBci[i].language, cdmaBci[i].selected);
1109 if (status != NO_ERROR) {
1113 s_callbacks.onRequest(pRI->pCI->requestNumber,
1115 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1119 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1120 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
1127 invalidCommandBlock(pRI);
1131 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1132 RIL_CDMA_SMS_WriteArgs rcsw;
1139 memset(&rcsw, 0, sizeof(rcsw));
1141 status = p.readInt32(&t);
1144 status = p.readInt32(&t);
1145 rcsw.message.uTeleserviceID = (int) t;
1147 status = p.read(&uct,sizeof(uct));
1148 rcsw.message.bIsServicePresent = (uint8_t) uct;
1150 status = p.readInt32(&t);
1151 rcsw.message.uServicecategory = (int) t;
1153 status = p.readInt32(&t);
1154 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1156 status = p.readInt32(&t);
1157 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1159 status = p.readInt32(&t);
1160 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1162 status = p.readInt32(&t);
1163 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1165 status = p.read(&uct,sizeof(uct));
1166 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1168 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1169 status = p.read(&uct,sizeof(uct));
1170 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1173 status = p.readInt32(&t);
1174 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1176 status = p.read(&uct,sizeof(uct));
1177 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1179 status = p.read(&uct,sizeof(uct));
1180 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1182 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1183 status = p.read(&uct,sizeof(uct));
1184 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1187 status = p.readInt32(&t);
1188 rcsw.message.uBearerDataLen = (int) t;
1190 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1191 status = p.read(&uct, sizeof(uct));
1192 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1195 if (status != NO_ERROR) {
1200 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1201 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1202 message.sAddress.number_mode=%d, \
1203 message.sAddress.number_type=%d, ",
1204 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1205 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1206 rcsw.message.sAddress.number_mode,
1207 rcsw.message.sAddress.number_type);
1210 printRequest(pRI->token, pRI->pCI->requestNumber);
1212 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI);
1215 memset(&rcsw, 0, sizeof(rcsw));
1221 invalidCommandBlock(pRI);
1226 // For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1227 // Version 4 of the RIL interface adds a new PDP type parameter to support
1228 // IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1229 // RIL, remove the parameter from the request.
1230 static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1231 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1232 const int numParamsRilV3 = 6;
1234 // The first bytes of the RIL parcel contain the request number and the
1235 // serial number - see processCommandBuffer(). Copy them over too.
1236 int pos = p.dataPosition();
1238 int numParams = p.readInt32();
1239 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1241 p2.appendFrom(&p, 0, pos);
1242 p2.writeInt32(numParamsRilV3);
1243 for(int i = 0; i < numParamsRilV3; i++) {
1244 p2.writeString16(p.readString16());
1246 p2.setDataPosition(pos);
1247 dispatchStrings(p2, pRI);
1249 p.setDataPosition(pos);
1250 dispatchStrings(p, pRI);
1254 // For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1255 // When all RILs handle this request, this function can be removed and
1256 // the request can be sent directly to the RIL using dispatchVoid.
1257 static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
1258 RIL_RadioState state = s_callbacks.onStateRequest();
1260 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1261 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1264 // RILs that support RADIO_STATE_ON should support this request.
1265 if (RADIO_STATE_ON == state) {
1266 dispatchVoid(p, pRI);
1270 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1271 // will not support this new request either and decode Voice Radio Technology
1273 voiceRadioTech = decodeVoiceRadioTechnology(state);
1275 if (voiceRadioTech < 0)
1276 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1278 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1281 // For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1282 // When all RILs handle this request, this function can be removed and
1283 // the request can be sent directly to the RIL using dispatchVoid.
1284 static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
1285 RIL_RadioState state = s_callbacks.onStateRequest();
1287 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1288 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1291 // RILs that support RADIO_STATE_ON should support this request.
1292 if (RADIO_STATE_ON == state) {
1293 dispatchVoid(p, pRI);
1297 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1298 // will not support this new request either and decode CDMA Subscription Source
1300 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1302 if (cdmaSubscriptionSource < 0)
1303 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1305 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1309 blockingWrite(int fd, const void *buffer, size_t len) {
1310 size_t writeOffset = 0;
1311 const uint8_t *toWrite;
1313 toWrite = (const uint8_t *)buffer;
1315 while (writeOffset < len) {
1318 written = write (fd, toWrite + writeOffset,
1320 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
1323 writeOffset += written;
1324 } else { // written < 0
1325 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
1335 sendResponseRaw (const void *data, size_t dataSize) {
1336 int fd = s_fdCommand;
1340 if (s_fdCommand < 0) {
1344 if (dataSize > MAX_COMMAND_BYTES) {
1345 RLOGE("RIL: packet larger than %u (%u)",
1346 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1351 pthread_mutex_lock(&s_writeMutex);
1353 header = htonl(dataSize);
1355 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1358 pthread_mutex_unlock(&s_writeMutex);
1362 ret = blockingWrite(fd, data, dataSize);
1365 pthread_mutex_unlock(&s_writeMutex);
1369 pthread_mutex_unlock(&s_writeMutex);
1375 sendResponse (Parcel &p) {
1377 return sendResponseRaw(p.data(), p.dataSize());
1380 /** response is an int* pointing to an array of ints*/
1383 responseInts(Parcel &p, void *response, size_t responselen) {
1386 if (response == NULL && responselen != 0) {
1387 RLOGE("invalid response: NULL");
1388 return RIL_ERRNO_INVALID_RESPONSE;
1390 if (responselen % sizeof(int) != 0) {
1391 RLOGE("invalid response length %d expected multiple of %d\n",
1392 (int)responselen, (int)sizeof(int));
1393 return RIL_ERRNO_INVALID_RESPONSE;
1396 int *p_int = (int *) response;
1398 numInts = responselen / sizeof(int *);
1399 p.writeInt32 (numInts);
1403 for (int i = 0 ; i < numInts ; i++) {
1404 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1405 p.writeInt32(p_int[i]);
1413 /** response is a char **, pointing to an array of char *'s
1414 The parcel will begin with the version */
1415 static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1416 p.writeInt32(version);
1417 return responseStrings(p, response, responselen);
1420 /** response is a char **, pointing to an array of char *'s */
1421 static int responseStrings(Parcel &p, void *response, size_t responselen) {
1424 if (response == NULL && responselen != 0) {
1425 RLOGE("invalid response: NULL");
1426 return RIL_ERRNO_INVALID_RESPONSE;
1428 if (responselen % sizeof(char *) != 0) {
1429 RLOGE("invalid response length %d expected multiple of %d\n",
1430 (int)responselen, (int)sizeof(char *));
1431 return RIL_ERRNO_INVALID_RESPONSE;
1434 if (response == NULL) {
1437 char **p_cur = (char **) response;
1439 numStrings = responselen / sizeof(char *);
1440 p.writeInt32 (numStrings);
1444 for (int i = 0 ; i < numStrings ; i++) {
1445 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1446 writeStringToParcel (p, p_cur[i]);
1456 * NULL strings are accepted
1457 * FIXME currently ignores responselen
1459 static int responseString(Parcel &p, void *response, size_t responselen) {
1460 /* one string only */
1462 appendPrintBuf("%s%s", printBuf, (char*)response);
1465 writeStringToParcel(p, (const char *)response);
1470 static int responseVoid(Parcel &p, void *response, size_t responselen) {
1476 static int responseCallList(Parcel &p, void *response, size_t responselen) {
1479 if (response == NULL && responselen != 0) {
1480 RLOGE("invalid response: NULL");
1481 return RIL_ERRNO_INVALID_RESPONSE;
1484 if (responselen % sizeof (RIL_Call *) != 0) {
1485 RLOGE("invalid response length %d expected multiple of %d\n",
1486 (int)responselen, (int)sizeof (RIL_Call *));
1487 return RIL_ERRNO_INVALID_RESPONSE;
1491 /* number of call info's */
1492 num = responselen / sizeof(RIL_Call *);
1495 for (int i = 0 ; i < num ; i++) {
1496 RIL_Call *p_cur = ((RIL_Call **) response)[i];
1497 /* each call info */
1498 p.writeInt32(p_cur->state);
1499 p.writeInt32(p_cur->index);
1500 p.writeInt32(p_cur->toa);
1501 p.writeInt32(p_cur->isMpty);
1502 p.writeInt32(p_cur->isMT);
1503 p.writeInt32(p_cur->als);
1504 p.writeInt32(p_cur->isVoice);
1505 p.writeInt32(p_cur->isVoicePrivacy);
1506 writeStringToParcel(p, p_cur->number);
1507 p.writeInt32(p_cur->numberPresentation);
1508 writeStringToParcel(p, p_cur->name);
1509 p.writeInt32(p_cur->namePresentation);
1510 // Remove when partners upgrade to version 3
1511 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
1512 p.writeInt32(0); /* UUS Information is absent */
1514 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
1515 p.writeInt32(1); /* UUS Information is present */
1516 p.writeInt32(uusInfo->uusType);
1517 p.writeInt32(uusInfo->uusDcs);
1518 p.writeInt32(uusInfo->uusLength);
1519 p.write(uusInfo->uusData, uusInfo->uusLength);
1521 appendPrintBuf("%s[id=%d,%s,toa=%d,",
1524 callStateToString(p_cur->state),
1526 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
1528 (p_cur->isMpty)?"conf":"norm",
1529 (p_cur->isMT)?"mt":"mo",
1531 (p_cur->isVoice)?"voc":"nonvoc",
1532 (p_cur->isVoicePrivacy)?"evp":"noevp");
1533 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
1536 p_cur->numberPresentation,
1538 p_cur->namePresentation);
1546 static int responseSMS(Parcel &p, void *response, size_t responselen) {
1547 if (response == NULL) {
1548 RLOGE("invalid response: NULL");
1549 return RIL_ERRNO_INVALID_RESPONSE;
1552 if (responselen != sizeof (RIL_SMS_Response) ) {
1553 RLOGE("invalid response length %d expected %d",
1554 (int)responselen, (int)sizeof (RIL_SMS_Response));
1555 return RIL_ERRNO_INVALID_RESPONSE;
1558 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1560 p.writeInt32(p_cur->messageRef);
1561 writeStringToParcel(p, p_cur->ackPDU);
1562 p.writeInt32(p_cur->errorCode);
1565 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
1566 (char*)p_cur->ackPDU, p_cur->errorCode);
1572 static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
1574 if (response == NULL && responselen != 0) {
1575 RLOGE("invalid response: NULL");
1576 return RIL_ERRNO_INVALID_RESPONSE;
1579 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
1580 RLOGE("invalid response length %d expected multiple of %d",
1581 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
1582 return RIL_ERRNO_INVALID_RESPONSE;
1585 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
1588 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
1591 for (i = 0; i < num; i++) {
1592 p.writeInt32(p_cur[i].cid);
1593 p.writeInt32(p_cur[i].active);
1594 writeStringToParcel(p, p_cur[i].type);
1595 // apn is not used, so don't send.
1596 writeStringToParcel(p, p_cur[i].address);
1597 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
1599 (p_cur[i].active==0)?"down":"up",
1600 (char*)p_cur[i].type,
1601 (char*)p_cur[i].address);
1609 static int responseDataCallList(Parcel &p, void *response, size_t responselen)
1612 p.writeInt32(s_callbacks.version);
1614 if (s_callbacks.version < 5) {
1615 return responseDataCallListV4(p, response, responselen);
1617 if (response == NULL && responselen != 0) {
1618 RLOGE("invalid response: NULL");
1619 return RIL_ERRNO_INVALID_RESPONSE;
1622 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
1623 RLOGE("invalid response length %d expected multiple of %d",
1624 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
1625 return RIL_ERRNO_INVALID_RESPONSE;
1628 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
1631 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
1634 for (i = 0; i < num; i++) {
1635 p.writeInt32((int)p_cur[i].status);
1636 p.writeInt32(p_cur[i].suggestedRetryTime);
1637 p.writeInt32(p_cur[i].cid);
1638 p.writeInt32(p_cur[i].active);
1639 writeStringToParcel(p, p_cur[i].type);
1640 writeStringToParcel(p, p_cur[i].ifname);
1641 writeStringToParcel(p, p_cur[i].addresses);
1642 writeStringToParcel(p, p_cur[i].dnses);
1643 writeStringToParcel(p, p_cur[i].gateways);
1644 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
1646 p_cur[i].suggestedRetryTime,
1648 (p_cur[i].active==0)?"down":"up",
1649 (char*)p_cur[i].type,
1650 (char*)p_cur[i].ifname,
1651 (char*)p_cur[i].addresses,
1652 (char*)p_cur[i].dnses,
1653 (char*)p_cur[i].gateways);
1662 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
1664 if (s_callbacks.version < 5) {
1665 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
1667 return responseDataCallList(p, response, responselen);
1671 static int responseRaw(Parcel &p, void *response, size_t responselen) {
1672 if (response == NULL && responselen != 0) {
1673 RLOGE("invalid response: NULL with responselen != 0");
1674 return RIL_ERRNO_INVALID_RESPONSE;
1677 // The java code reads -1 size as null byte array
1678 if (response == NULL) {
1681 p.writeInt32(responselen);
1682 p.write(response, responselen);
1689 static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
1690 if (response == NULL) {
1691 RLOGE("invalid response: NULL");
1692 return RIL_ERRNO_INVALID_RESPONSE;
1695 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
1696 RLOGE("invalid response length was %d expected %d",
1697 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
1698 return RIL_ERRNO_INVALID_RESPONSE;
1701 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
1702 p.writeInt32(p_cur->sw1);
1703 p.writeInt32(p_cur->sw2);
1704 writeStringToParcel(p, p_cur->simResponse);
1707 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
1708 (char*)p_cur->simResponse);
1715 static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
1718 if (response == NULL && responselen != 0) {
1719 RLOGE("invalid response: NULL");
1720 return RIL_ERRNO_INVALID_RESPONSE;
1723 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
1724 RLOGE("invalid response length %d expected multiple of %d",
1725 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
1726 return RIL_ERRNO_INVALID_RESPONSE;
1729 /* number of call info's */
1730 num = responselen / sizeof(RIL_CallForwardInfo *);
1734 for (int i = 0 ; i < num ; i++) {
1735 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
1737 p.writeInt32(p_cur->status);
1738 p.writeInt32(p_cur->reason);
1739 p.writeInt32(p_cur->serviceClass);
1740 p.writeInt32(p_cur->toa);
1741 writeStringToParcel(p, p_cur->number);
1742 p.writeInt32(p_cur->timeSeconds);
1743 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
1744 (p_cur->status==1)?"enable":"disable",
1745 p_cur->reason, p_cur->serviceClass, p_cur->toa,
1746 (char*)p_cur->number,
1747 p_cur->timeSeconds);
1755 static int responseSsn(Parcel &p, void *response, size_t responselen) {
1756 if (response == NULL) {
1757 RLOGE("invalid response: NULL");
1758 return RIL_ERRNO_INVALID_RESPONSE;
1761 if (responselen != sizeof(RIL_SuppSvcNotification)) {
1762 RLOGE("invalid response length was %d expected %d",
1763 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
1764 return RIL_ERRNO_INVALID_RESPONSE;
1767 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
1768 p.writeInt32(p_cur->notificationType);
1769 p.writeInt32(p_cur->code);
1770 p.writeInt32(p_cur->index);
1771 p.writeInt32(p_cur->type);
1772 writeStringToParcel(p, p_cur->number);
1775 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
1776 (p_cur->notificationType==0)?"mo":"mt",
1777 p_cur->code, p_cur->index, p_cur->type,
1778 (char*)p_cur->number);
1784 static int responseCellList(Parcel &p, void *response, size_t responselen) {
1787 if (response == NULL && responselen != 0) {
1788 RLOGE("invalid response: NULL");
1789 return RIL_ERRNO_INVALID_RESPONSE;
1792 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
1793 RLOGE("invalid response length %d expected multiple of %d\n",
1794 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
1795 return RIL_ERRNO_INVALID_RESPONSE;
1799 /* number of records */
1800 num = responselen / sizeof(RIL_NeighboringCell *);
1803 for (int i = 0 ; i < num ; i++) {
1804 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
1806 p.writeInt32(p_cur->rssi);
1807 writeStringToParcel (p, p_cur->cid);
1809 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
1810 p_cur->cid, p_cur->rssi);
1819 * Marshall the signalInfoRecord into the parcel if it exists.
1821 static void marshallSignalInfoRecord(Parcel &p,
1822 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
1823 p.writeInt32(p_signalInfoRecord.isPresent);
1824 p.writeInt32(p_signalInfoRecord.signalType);
1825 p.writeInt32(p_signalInfoRecord.alertPitch);
1826 p.writeInt32(p_signalInfoRecord.signal);
1829 static int responseCdmaInformationRecords(Parcel &p,
1830 void *response, size_t responselen) {
1832 char* string8 = NULL;
1834 RIL_CDMA_InformationRecord *infoRec;
1836 if (response == NULL && responselen != 0) {
1837 RLOGE("invalid response: NULL");
1838 return RIL_ERRNO_INVALID_RESPONSE;
1841 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
1842 RLOGE("invalid response length %d expected multiple of %d\n",
1843 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
1844 return RIL_ERRNO_INVALID_RESPONSE;
1847 RIL_CDMA_InformationRecords *p_cur =
1848 (RIL_CDMA_InformationRecords *) response;
1849 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
1854 for (int i = 0 ; i < num ; i++) {
1855 infoRec = &p_cur->infoRec[i];
1856 p.writeInt32(infoRec->name);
1857 switch (infoRec->name) {
1858 case RIL_CDMA_DISPLAY_INFO_REC:
1859 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
1860 if (infoRec->rec.display.alpha_len >
1861 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
1862 RLOGE("invalid display info response length %d \
1863 expected not more than %d\n",
1864 (int)infoRec->rec.display.alpha_len,
1865 CDMA_ALPHA_INFO_BUFFER_LENGTH);
1866 return RIL_ERRNO_INVALID_RESPONSE;
1868 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
1870 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
1871 string8[i] = infoRec->rec.display.alpha_buf[i];
1873 string8[(int)infoRec->rec.display.alpha_len] = '\0';
1874 writeStringToParcel(p, (const char*)string8);
1878 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
1879 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
1880 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
1881 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
1882 RLOGE("invalid display info response length %d \
1883 expected not more than %d\n",
1884 (int)infoRec->rec.number.len,
1885 CDMA_NUMBER_INFO_BUFFER_LENGTH);
1886 return RIL_ERRNO_INVALID_RESPONSE;
1888 string8 = (char*) malloc((infoRec->rec.number.len + 1)
1890 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
1891 string8[i] = infoRec->rec.number.buf[i];
1893 string8[(int)infoRec->rec.number.len] = '\0';
1894 writeStringToParcel(p, (const char*)string8);
1897 p.writeInt32(infoRec->rec.number.number_type);
1898 p.writeInt32(infoRec->rec.number.number_plan);
1899 p.writeInt32(infoRec->rec.number.pi);
1900 p.writeInt32(infoRec->rec.number.si);
1902 case RIL_CDMA_SIGNAL_INFO_REC:
1903 p.writeInt32(infoRec->rec.signal.isPresent);
1904 p.writeInt32(infoRec->rec.signal.signalType);
1905 p.writeInt32(infoRec->rec.signal.alertPitch);
1906 p.writeInt32(infoRec->rec.signal.signal);
1908 appendPrintBuf("%sisPresent=%X, signalType=%X, \
1909 alertPitch=%X, signal=%X, ",
1910 printBuf, (int)infoRec->rec.signal.isPresent,
1911 (int)infoRec->rec.signal.signalType,
1912 (int)infoRec->rec.signal.alertPitch,
1913 (int)infoRec->rec.signal.signal);
1916 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
1917 if (infoRec->rec.redir.redirectingNumber.len >
1918 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
1919 RLOGE("invalid display info response length %d \
1920 expected not more than %d\n",
1921 (int)infoRec->rec.redir.redirectingNumber.len,
1922 CDMA_NUMBER_INFO_BUFFER_LENGTH);
1923 return RIL_ERRNO_INVALID_RESPONSE;
1925 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
1926 .len + 1) * sizeof(char) );
1928 i < infoRec->rec.redir.redirectingNumber.len;
1930 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
1932 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
1933 writeStringToParcel(p, (const char*)string8);
1936 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
1937 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
1938 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
1939 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
1940 p.writeInt32(infoRec->rec.redir.redirectingReason);
1942 case RIL_CDMA_LINE_CONTROL_INFO_REC:
1943 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
1944 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
1945 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
1946 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
1948 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
1949 lineCtrlToggle=%d, lineCtrlReverse=%d, \
1950 lineCtrlPowerDenial=%d, ", printBuf,
1951 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
1952 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
1953 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
1954 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
1957 case RIL_CDMA_T53_CLIR_INFO_REC:
1958 p.writeInt32((int)(infoRec->rec.clir.cause));
1960 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
1963 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
1964 p.writeInt32(infoRec->rec.audioCtrl.upLink);
1965 p.writeInt32(infoRec->rec.audioCtrl.downLink);
1967 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
1968 infoRec->rec.audioCtrl.upLink,
1969 infoRec->rec.audioCtrl.downLink);
1972 case RIL_CDMA_T53_RELEASE_INFO_REC:
1973 // TODO(Moto): See David Krause, he has the answer:)
1974 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
1975 return RIL_ERRNO_INVALID_RESPONSE;
1977 RLOGE("Incorrect name value");
1978 return RIL_ERRNO_INVALID_RESPONSE;
1986 static int responseRilSignalStrength(Parcel &p,
1987 void *response, size_t responselen) {
1988 if (response == NULL && responselen != 0) {
1989 RLOGE("invalid response: NULL");
1990 return RIL_ERRNO_INVALID_RESPONSE;
1993 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
1994 RIL_SignalStrength_v6 *p_cur = ((RIL_SignalStrength_v6 *) response);
1996 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
1997 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
1998 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
1999 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2000 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2001 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2002 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2003 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
2005 * Fixup LTE for backwards compatibility
2007 if (s_callbacks.version <= 6) {
2008 // signalStrength: -1 -> 99
2009 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2010 p_cur->LTE_SignalStrength.signalStrength = 99;
2012 // rsrp: -1 -> INT_MAX all other negative value to positive.
2014 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2015 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2016 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2017 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2019 // rsrq: -1 -> INT_MAX
2020 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2021 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2023 // Not remapping rssnr is already using INT_MAX
2025 // cqi: -1 -> INT_MAX
2026 if (p_cur->LTE_SignalStrength.cqi == -1) {
2027 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2030 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2031 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2032 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2033 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2034 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2037 p.writeInt32(INT_MAX);
2038 p.writeInt32(INT_MAX);
2039 p.writeInt32(INT_MAX);
2040 p.writeInt32(INT_MAX);
2044 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
2045 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2046 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2047 EVDO_SS.signalNoiseRatio=%d,\
2048 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
2049 LTE_SS.rssnr=%d,LTE_SS.cqi=%d]",
2051 p_cur->GW_SignalStrength.signalStrength,
2052 p_cur->GW_SignalStrength.bitErrorRate,
2053 p_cur->CDMA_SignalStrength.dbm,
2054 p_cur->CDMA_SignalStrength.ecio,
2055 p_cur->EVDO_SignalStrength.dbm,
2056 p_cur->EVDO_SignalStrength.ecio,
2057 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2058 p_cur->LTE_SignalStrength.signalStrength,
2059 p_cur->LTE_SignalStrength.rsrp,
2060 p_cur->LTE_SignalStrength.rsrq,
2061 p_cur->LTE_SignalStrength.rssnr,
2062 p_cur->LTE_SignalStrength.cqi);
2066 RLOGE("invalid response length");
2067 return RIL_ERRNO_INVALID_RESPONSE;
2073 static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2074 if ((response == NULL) || (responselen == 0)) {
2075 return responseVoid(p, response, responselen);
2077 return responseCdmaSignalInfoRecord(p, response, responselen);
2081 static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2082 if (response == NULL || responselen == 0) {
2083 RLOGE("invalid response: NULL");
2084 return RIL_ERRNO_INVALID_RESPONSE;
2087 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
2088 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
2089 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2090 return RIL_ERRNO_INVALID_RESPONSE;
2095 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2096 marshallSignalInfoRecord(p, *p_cur);
2098 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2110 static int responseCdmaCallWaiting(Parcel &p, void *response,
2111 size_t responselen) {
2112 if (response == NULL && responselen != 0) {
2113 RLOGE("invalid response: NULL");
2114 return RIL_ERRNO_INVALID_RESPONSE;
2117 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
2118 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
2121 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2123 writeStringToParcel(p, p_cur->number);
2124 p.writeInt32(p_cur->numberPresentation);
2125 writeStringToParcel(p, p_cur->name);
2126 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2128 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2129 p.writeInt32(p_cur->number_type);
2130 p.writeInt32(p_cur->number_plan);
2137 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2138 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2139 signal=%d,number_type=%d,number_plan=%d]",
2142 p_cur->numberPresentation,
2144 p_cur->signalInfoRecord.isPresent,
2145 p_cur->signalInfoRecord.signalType,
2146 p_cur->signalInfoRecord.alertPitch,
2147 p_cur->signalInfoRecord.signal,
2149 p_cur->number_plan);
2155 static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2156 if (response == NULL && responselen != 0) {
2157 RLOGE("responseSimRefresh: invalid response: NULL");
2158 return RIL_ERRNO_INVALID_RESPONSE;
2162 if (s_callbacks.version == 7) {
2163 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2164 p.writeInt32(p_cur->result);
2165 p.writeInt32(p_cur->ef_id);
2166 writeStringToParcel(p, p_cur->aid);
2168 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2174 int *p_cur = ((int *) response);
2175 p.writeInt32(p_cur[0]);
2176 p.writeInt32(p_cur[1]);
2177 writeStringToParcel(p, NULL);
2179 appendPrintBuf("%sresult=%d, ef_id=%d",
2189 static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2191 if (response == NULL && responselen != 0) {
2192 RLOGE("invalid response: NULL");
2193 return RIL_ERRNO_INVALID_RESPONSE;
2196 if (responselen % sizeof(RIL_CellInfo) != 0) {
2197 RLOGE("invalid response length %d expected multiple of %d",
2198 (int)responselen, (int)sizeof(RIL_CellInfo));
2199 return RIL_ERRNO_INVALID_RESPONSE;
2202 int num = responselen / sizeof(RIL_CellInfo);
2205 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2208 for (i = 0; i < num; i++) {
2209 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2210 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2211 p.writeInt32((int)p_cur->cellInfoType);
2212 p.writeInt32(p_cur->registered);
2213 p.writeInt32(p_cur->timeStampType);
2214 p.writeInt64(p_cur->timeStamp);
2215 switch(p_cur->cellInfoType) {
2216 case RIL_CELL_INFO_TYPE_GSM: {
2217 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2218 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2219 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2220 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
2221 p_cur->CellInfo.gsm.cellIdentityGsm.cid,
2222 p_cur->CellInfo.gsm.cellIdentityGsm.psc);
2223 appendPrintBuf("%s SS: gsmSS ss=%d,ber=%d],", printBuf,
2224 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2225 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2227 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2228 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2229 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2230 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2231 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.psc);
2232 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2233 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2236 case RIL_CELL_INFO_TYPE_CDMA: {
2237 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2238 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2239 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2240 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2241 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2242 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2244 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2245 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
2246 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
2247 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
2248 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2250 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
2251 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
2252 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
2253 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
2254 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
2255 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2257 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
2258 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
2259 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
2260 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
2261 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2264 case RIL_CELL_INFO_TYPE_LTE: {
2265 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
2266 p_cur->CellInfo.lte.cellIdentityLte.mcc,
2267 p_cur->CellInfo.lte.cellIdentityLte.mnc,
2268 p_cur->CellInfo.lte.cellIdentityLte.ci,
2269 p_cur->CellInfo.lte.cellIdentityLte.pci,
2270 p_cur->CellInfo.lte.cellIdentityLte.tac);
2272 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
2273 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
2274 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
2275 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
2276 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
2278 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
2279 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
2280 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
2281 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
2282 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
2283 p_cur->CellInfo.lte.signalStrengthLte.cqi,
2284 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2285 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
2286 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
2287 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
2288 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
2289 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
2290 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2302 static void triggerEvLoop() {
2304 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
2305 /* trigger event loop to wakeup. No reason to do this,
2306 * if we're in the event loop thread */
2308 ret = write (s_fdWakeupWrite, " ", 1);
2309 } while (ret < 0 && errno == EINTR);
2313 static void rilEventAddWakeup(struct ril_event *ev) {
2318 static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
2319 p.writeInt32(num_apps);
2321 for (int i = 0; i < num_apps; i++) {
2322 p.writeInt32(appStatus[i].app_type);
2323 p.writeInt32(appStatus[i].app_state);
2324 p.writeInt32(appStatus[i].perso_substate);
2325 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
2326 writeStringToParcel(p, (const char*)
2327 (appStatus[i].app_label_ptr));
2328 p.writeInt32(appStatus[i].pin1_replaced);
2329 p.writeInt32(appStatus[i].pin1);
2330 p.writeInt32(appStatus[i].pin2);
2331 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
2332 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
2334 appStatus[i].app_type,
2335 appStatus[i].app_state,
2336 appStatus[i].perso_substate,
2337 appStatus[i].aid_ptr,
2338 appStatus[i].app_label_ptr,
2339 appStatus[i].pin1_replaced,
2346 static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
2349 if (response == NULL && responselen != 0) {
2350 RLOGE("invalid response: NULL");
2351 return RIL_ERRNO_INVALID_RESPONSE;
2354 if (responselen == sizeof (RIL_CardStatus_v6)) {
2355 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
2357 p.writeInt32(p_cur->card_state);
2358 p.writeInt32(p_cur->universal_pin_state);
2359 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2360 p.writeInt32(p_cur->cdma_subscription_app_index);
2361 p.writeInt32(p_cur->ims_subscription_app_index);
2363 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2364 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
2365 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
2367 p.writeInt32(p_cur->card_state);
2368 p.writeInt32(p_cur->universal_pin_state);
2369 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2370 p.writeInt32(p_cur->cdma_subscription_app_index);
2373 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2375 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
2376 return RIL_ERRNO_INVALID_RESPONSE;
2382 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2383 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
2387 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
2388 (RIL_GSM_BroadcastSmsConfigInfo **) response;
2389 for (int i = 0; i < num; i++) {
2390 p.writeInt32(p_cur[i]->fromServiceId);
2391 p.writeInt32(p_cur[i]->toServiceId);
2392 p.writeInt32(p_cur[i]->fromCodeScheme);
2393 p.writeInt32(p_cur[i]->toCodeScheme);
2394 p.writeInt32(p_cur[i]->selected);
2396 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
2397 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
2398 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
2399 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
2400 p_cur[i]->selected);
2407 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2408 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
2409 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
2411 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
2415 for (int i = 0 ; i < num ; i++ ) {
2416 p.writeInt32(p_cur[i]->service_category);
2417 p.writeInt32(p_cur[i]->language);
2418 p.writeInt32(p_cur[i]->selected);
2420 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
2422 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
2423 p_cur[i]->selected);
2430 static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
2437 RLOGD("Inside responseCdmaSms");
2439 if (response == NULL && responselen != 0) {
2440 RLOGE("invalid response: NULL");
2441 return RIL_ERRNO_INVALID_RESPONSE;
2444 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
2445 RLOGE("invalid response length was %d expected %d",
2446 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
2447 return RIL_ERRNO_INVALID_RESPONSE;
2450 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
2451 p.writeInt32(p_cur->uTeleserviceID);
2452 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
2453 p.writeInt32(p_cur->uServicecategory);
2454 p.writeInt32(p_cur->sAddress.digit_mode);
2455 p.writeInt32(p_cur->sAddress.number_mode);
2456 p.writeInt32(p_cur->sAddress.number_type);
2457 p.writeInt32(p_cur->sAddress.number_plan);
2458 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
2459 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2460 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2461 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
2464 p.writeInt32(p_cur->sSubAddress.subaddressType);
2465 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
2466 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
2467 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2468 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2469 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
2472 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2473 p.writeInt32(p_cur->uBearerDataLen);
2474 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2475 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
2479 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
2480 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
2481 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
2482 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
2489 * A write on the wakeup fd is done just to pop us out of select()
2490 * We empty the buffer here and then ril_event will reset the timers on the
2493 static void processWakeupCallback(int fd, short flags, void *param) {
2497 RLOGV("processWakeupCallback");
2499 /* empty our wakeup socket out */
2501 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
2502 } while (ret > 0 || (ret < 0 && errno == EINTR));
2505 static void onCommandsSocketClosed() {
2509 /* mark pending requests as "cancelled" so we dont report responses */
2511 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
2514 p_cur = s_pendingRequests;
2516 for (p_cur = s_pendingRequests
2518 ; p_cur = p_cur->p_next
2520 p_cur->cancelled = 1;
2523 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
2527 static void processCommandsCallback(int fd, short flags, void *param) {
2533 assert(fd == s_fdCommand);
2535 p_rs = (RecordStream *)param;
2538 /* loop until EAGAIN/EINTR, end of stream, or other error */
2539 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
2541 if (ret == 0 && p_record == NULL) {
2544 } else if (ret < 0) {
2546 } else if (ret == 0) { /* && p_record != NULL */
2547 processCommandBuffer(p_record, recordlen);
2551 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
2552 /* fatal error or end-of-stream */
2554 RLOGE("error on reading command socket errno:%d\n", errno);
2556 RLOGW("EOS. Closing command socket.");
2562 ril_event_del(&s_commands_event);
2564 record_stream_free(p_rs);
2566 /* start listening for new connections again */
2567 rilEventAddWakeup(&s_listen_event);
2569 onCommandsSocketClosed();
2574 static void onNewCommandConnect() {
2575 // Inform we are connected and the ril version
2576 int rilVer = s_callbacks.version;
2577 RIL_onUnsolicitedResponse(RIL_UNSOL_RIL_CONNECTED,
2578 &rilVer, sizeof(rilVer));
2580 // implicit radio state changed
2581 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
2584 // Send last NITZ time data, in case it was missed
2585 if (s_lastNITZTimeData != NULL) {
2586 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
2588 free(s_lastNITZTimeData);
2589 s_lastNITZTimeData = NULL;
2592 // Get version string
2593 if (s_callbacks.getVersion != NULL) {
2594 const char *version;
2595 version = s_callbacks.getVersion();
2596 RLOGI("RIL Daemon version: %s\n", version);
2598 property_set(PROPERTY_RIL_IMPL, version);
2600 RLOGI("RIL Daemon version: unavailable\n");
2601 property_set(PROPERTY_RIL_IMPL, "unavailable");
2606 static void listenCallback (int fd, short flags, void *param) {
2609 int is_phone_socket;
2612 struct sockaddr_un peeraddr;
2613 socklen_t socklen = sizeof (peeraddr);
2616 socklen_t szCreds = sizeof(creds);
2618 struct passwd *pwd = NULL;
2620 assert (s_fdCommand < 0);
2621 assert (fd == s_fdListen);
2623 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
2625 if (s_fdCommand < 0 ) {
2626 RLOGE("Error on accept() errno:%d", errno);
2627 /* start listening for new connections again */
2628 rilEventAddWakeup(&s_listen_event);
2632 /* check the credential of the other side and only accept socket from
2636 is_phone_socket = 0;
2638 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
2640 if (err == 0 && szCreds > 0) {
2642 pwd = getpwuid(creds.uid);
2644 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
2645 is_phone_socket = 1;
2647 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
2650 RLOGE("Error on getpwuid() errno: %d", errno);
2653 RLOGD("Error on getsockopt() errno: %d", errno);
2656 if ( !is_phone_socket ) {
2657 RLOGE("RILD must accept socket from %s", PHONE_PROCESS);
2662 onCommandsSocketClosed();
2664 /* start listening for new connections again */
2665 rilEventAddWakeup(&s_listen_event);
2670 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
2673 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
2676 RLOGI("libril: new connection");
2678 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
2680 ril_event_set (&s_commands_event, s_fdCommand, 1,
2681 processCommandsCallback, p_rs);
2683 rilEventAddWakeup (&s_commands_event);
2685 onNewCommandConnect();
2688 static void freeDebugCallbackArgs(int number, char **args) {
2689 for (int i = 0; i < number; i++) {
2690 if (args[i] != NULL) {
2697 static void debugCallback (int fd, short flags, void *param) {
2698 int acceptFD, option;
2699 struct sockaddr_un peeraddr;
2700 socklen_t socklen = sizeof (peeraddr);
2702 unsigned int qxdm_data[6];
2703 const char *deactData[1] = {"1"};
2706 int hangupData[1] = {1};
2710 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
2713 RLOGE ("error accepting on debug port: %d\n", errno);
2717 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
2718 RLOGE ("error reading on socket: number of Args: \n");
2721 args = (char **) malloc(sizeof(char*) * number);
2723 for (int i = 0; i < number; i++) {
2725 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
2726 RLOGE ("error reading on socket: Len of Args: \n");
2727 freeDebugCallbackArgs(i, args);
2731 args[i] = (char *) malloc((sizeof(char) * len) + 1);
2732 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
2733 != (int)sizeof(char) * len) {
2734 RLOGE ("error reading on socket: Args[%d] \n", i);
2735 freeDebugCallbackArgs(i, args);
2738 char * buf = args[i];
2742 switch (atoi(args[0])) {
2744 RLOGI ("Connection on debug port: issuing reset.");
2745 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
2748 RLOGI ("Connection on debug port: issuing radio power off.");
2750 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2756 RLOGI ("Debug port: issuing unsolicited voice network change.");
2757 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
2761 RLOGI ("Debug port: QXDM log enable.");
2762 qxdm_data[0] = 65536; // head.func_tag
2763 qxdm_data[1] = 16; // head.len
2764 qxdm_data[2] = 1; // mode: 1 for 'start logging'
2765 qxdm_data[3] = 32; // log_file_size: 32megabytes
2766 qxdm_data[4] = 0; // log_mask
2767 qxdm_data[5] = 8; // log_max_fileindex
2768 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2772 RLOGI ("Debug port: QXDM log disable.");
2773 qxdm_data[0] = 65536;
2775 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
2779 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2783 RLOGI("Debug port: Radio On");
2785 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2787 // Set network selection automatic.
2788 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
2791 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
2792 actData[0] = args[1];
2793 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
2797 RLOGI("Debug port: Deactivate Data Call");
2798 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
2802 RLOGI("Debug port: Dial Call");
2804 dialData.address = args[1];
2805 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
2808 RLOGI("Debug port: Answer Call");
2809 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
2812 RLOGI("Debug port: End Call");
2813 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
2814 sizeof(hangupData));
2817 RLOGE ("Invalid request");
2820 freeDebugCallbackArgs(number, args);
2825 static void userTimerCallback (int fd, short flags, void *param) {
2826 UserCallbackInfo *p_info;
2828 p_info = (UserCallbackInfo *)param;
2830 p_info->p_callback(p_info->userParam);
2833 // FIXME generalize this...there should be a cancel mechanism
2834 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
2835 s_last_wake_timeout_info = NULL;
2843 eventLoop(void *param) {
2849 pthread_mutex_lock(&s_startupMutex);
2852 pthread_cond_broadcast(&s_startupCond);
2854 pthread_mutex_unlock(&s_startupMutex);
2856 ret = pipe(filedes);
2859 RLOGE("Error in pipe() errno:%d", errno);
2863 s_fdWakeupRead = filedes[0];
2864 s_fdWakeupWrite = filedes[1];
2866 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
2868 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
2869 processWakeupCallback, NULL);
2871 rilEventAddWakeup (&s_wakeupfd_event);
2873 // Only returns on error
2875 RLOGE ("error in event_loop_base errno:%d", errno);
2876 // kill self to restart on error
2883 RIL_startEventLoop(void) {
2885 pthread_attr_t attr;
2887 /* spin up eventLoop thread and wait for it to get started */
2889 pthread_mutex_lock(&s_startupMutex);
2891 pthread_attr_init (&attr);
2892 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
2893 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
2895 while (s_started == 0) {
2896 pthread_cond_wait(&s_startupCond, &s_startupMutex);
2899 pthread_mutex_unlock(&s_startupMutex);
2902 RLOGE("Failed to create dispatch thread errno:%d", errno);
2907 // Used for testing purpose only.
2908 extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
2909 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
2913 RIL_register (const RIL_RadioFunctions *callbacks) {
2917 if (callbacks == NULL) {
2918 RLOGE("RIL_register: RIL_RadioFunctions * null");
2921 if (callbacks->version < RIL_VERSION_MIN) {
2922 RLOGE("RIL_register: version %d is to old, min version is %d",
2923 callbacks->version, RIL_VERSION_MIN);
2926 if (callbacks->version > RIL_VERSION) {
2927 RLOGE("RIL_register: version %d is too new, max version is %d",
2928 callbacks->version, RIL_VERSION);
2931 RLOGE("RIL_register: RIL version %d", callbacks->version);
2933 if (s_registerCalled > 0) {
2934 RLOGE("RIL_register has been called more than once. "
2935 "Subsequent call ignored");
2939 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
2941 s_registerCalled = 1;
2943 // Little self-check
2945 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
2946 assert(i == s_commands[i].requestNumber);
2949 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
2950 assert(i + RIL_UNSOL_RESPONSE_BASE
2951 == s_unsolResponses[i].requestNumber);
2954 // New rild impl calls RIL_startEventLoop() first
2955 // old standalone impl wants it here.
2957 if (s_started == 0) {
2958 RIL_startEventLoop();
2961 // start listen socket
2964 ret = socket_local_server (SOCKET_NAME_RIL,
2965 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
2968 RLOGE("Unable to bind socket errno:%d", errno);
2974 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
2975 if (s_fdListen < 0) {
2976 RLOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
2980 ret = listen(s_fdListen, 4);
2983 RLOGE("Failed to listen on control socket '%d': %s",
2984 s_fdListen, strerror(errno));
2990 /* note: non-persistent so we can accept only one connection at a time */
2991 ril_event_set (&s_listen_event, s_fdListen, false,
2992 listenCallback, NULL);
2994 rilEventAddWakeup (&s_listen_event);
2997 // start debug interface socket
2999 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
3000 if (s_fdDebug < 0) {
3001 RLOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
3005 ret = listen(s_fdDebug, 4);
3008 RLOGE("Failed to listen on ril debug socket '%d': %s",
3009 s_fdDebug, strerror(errno));
3013 ril_event_set (&s_debug_event, s_fdDebug, true,
3014 debugCallback, NULL);
3016 rilEventAddWakeup (&s_debug_event);
3022 checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
3029 pthread_mutex_lock(&s_pendingRequestsMutex);
3031 for(RequestInfo **ppCur = &s_pendingRequests
3033 ; ppCur = &((*ppCur)->p_next)
3035 if (pRI == *ppCur) {
3038 *ppCur = (*ppCur)->p_next;
3043 pthread_mutex_unlock(&s_pendingRequestsMutex);
3050 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
3055 pRI = (RequestInfo *)t;
3057 if (!checkAndDequeueRequestInfo(pRI)) {
3058 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
3062 if (pRI->local > 0) {
3063 // Locally issued command...void only!
3064 // response does not go back up the command socket
3065 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
3070 appendPrintBuf("[%04d]< %s",
3071 pRI->token, requestToString(pRI->pCI->requestNumber));
3073 if (pRI->cancelled == 0) {
3076 p.writeInt32 (RESPONSE_SOLICITED);
3077 p.writeInt32 (pRI->token);
3078 errorOffset = p.dataPosition();
3082 if (response != NULL) {
3083 // there is a response payload, no matter success or not.
3084 ret = pRI->pCI->responseFunction(p, response, responselen);
3086 /* if an error occurred, rewind and mark it */
3088 p.setDataPosition(errorOffset);
3093 if (e != RIL_E_SUCCESS) {
3094 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
3097 if (s_fdCommand < 0) {
3098 RLOGD ("RIL onRequestComplete: Command channel closed");
3109 grabPartialWakeLock() {
3110 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
3115 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
3119 * Timer callback to put us back to sleep before the default timeout
3122 wakeTimeoutCallback (void *param) {
3123 // We're using "param != NULL" as a cancellation mechanism
3124 if (param == NULL) {
3125 //RLOGD("wakeTimeout: releasing wake lock");
3129 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
3134 decodeVoiceRadioTechnology (RIL_RadioState radioState) {
3135 switch (radioState) {
3136 case RADIO_STATE_SIM_NOT_READY:
3137 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3138 case RADIO_STATE_SIM_READY:
3139 return RADIO_TECH_UMTS;
3141 case RADIO_STATE_RUIM_NOT_READY:
3142 case RADIO_STATE_RUIM_READY:
3143 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3144 case RADIO_STATE_NV_NOT_READY:
3145 case RADIO_STATE_NV_READY:
3146 return RADIO_TECH_1xRTT;
3149 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
3155 decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
3156 switch (radioState) {
3157 case RADIO_STATE_SIM_NOT_READY:
3158 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3159 case RADIO_STATE_SIM_READY:
3160 case RADIO_STATE_RUIM_NOT_READY:
3161 case RADIO_STATE_RUIM_READY:
3162 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3163 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
3165 case RADIO_STATE_NV_NOT_READY:
3166 case RADIO_STATE_NV_READY:
3167 return CDMA_SUBSCRIPTION_SOURCE_NV;
3170 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
3176 decodeSimStatus (RIL_RadioState radioState) {
3177 switch (radioState) {
3178 case RADIO_STATE_SIM_NOT_READY:
3179 case RADIO_STATE_RUIM_NOT_READY:
3180 case RADIO_STATE_NV_NOT_READY:
3181 case RADIO_STATE_NV_READY:
3183 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3184 case RADIO_STATE_SIM_READY:
3185 case RADIO_STATE_RUIM_READY:
3186 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3189 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
3194 static bool is3gpp2(int radioTech) {
3195 switch (radioTech) {
3196 case RADIO_TECH_IS95A:
3197 case RADIO_TECH_IS95B:
3198 case RADIO_TECH_1xRTT:
3199 case RADIO_TECH_EVDO_0:
3200 case RADIO_TECH_EVDO_A:
3201 case RADIO_TECH_EVDO_B:
3202 case RADIO_TECH_EHRPD:
3209 /* If RIL sends SIM states or RUIM states, store the voice radio
3210 * technology and subscription source information so that they can be
3211 * returned when telephony framework requests them
3213 static RIL_RadioState
3214 processRadioState(RIL_RadioState newRadioState) {
3216 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
3217 int newVoiceRadioTech;
3218 int newCdmaSubscriptionSource;
3221 /* This is old RIL. Decode Subscription source and Voice Radio Technology
3222 from Radio State and send change notifications if there has been a change */
3223 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
3224 if(newVoiceRadioTech != voiceRadioTech) {
3225 voiceRadioTech = newVoiceRadioTech;
3226 RIL_onUnsolicitedResponse (RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
3227 &voiceRadioTech, sizeof(voiceRadioTech));
3229 if(is3gpp2(newVoiceRadioTech)) {
3230 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
3231 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
3232 cdmaSubscriptionSource = newCdmaSubscriptionSource;
3233 RIL_onUnsolicitedResponse (RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
3234 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource));
3237 newSimStatus = decodeSimStatus(newRadioState);
3238 if(newSimStatus != simRuimStatus) {
3239 simRuimStatus = newSimStatus;
3240 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
3243 /* Send RADIO_ON to telephony */
3244 newRadioState = RADIO_STATE_ON;
3247 return newRadioState;
3251 void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
3254 int unsolResponseIndex;
3256 int64_t timeReceived = 0;
3257 bool shouldScheduleTimeout = false;
3258 RIL_RadioState newState;
3260 if (s_registerCalled == 0) {
3261 // Ignore RIL_onUnsolicitedResponse before RIL_register
3262 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
3266 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
3268 if ((unsolResponseIndex < 0)
3269 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
3270 RLOGE("unsupported unsolicited response code %d", unsolResponse);
3274 // Grab a wake lock if needed for this reponse,
3275 // as we exit we'll either release it immediately
3276 // or set a timer to release it later.
3277 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
3279 grabPartialWakeLock();
3280 shouldScheduleTimeout = true;
3285 // No wake lock is grabed so don't set timeout
3286 shouldScheduleTimeout = false;
3290 // Mark the time this was received, doing this
3291 // after grabing the wakelock incase getting
3292 // the elapsedRealTime might cause us to goto
3294 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3295 timeReceived = elapsedRealtime();
3298 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
3302 p.writeInt32 (RESPONSE_UNSOLICITED);
3303 p.writeInt32 (unsolResponse);
3305 ret = s_unsolResponses[unsolResponseIndex]
3306 .responseFunction(p, data, datalen);
3308 // Problem with the response. Don't continue;
3312 // some things get more payload
3313 switch(unsolResponse) {
3314 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
3315 newState = processRadioState(s_callbacks.onStateRequest());
3316 p.writeInt32(newState);
3317 appendPrintBuf("%s {%s}", printBuf,
3318 radioStateToString(s_callbacks.onStateRequest()));
3322 case RIL_UNSOL_NITZ_TIME_RECEIVED:
3323 // Store the time that this was received so the
3324 // handler of this message can account for
3325 // the time it takes to arrive and process. In
3326 // particular the system has been known to sleep
3327 // before this message can be processed.
3328 p.writeInt64(timeReceived);
3332 ret = sendResponse(p);
3333 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3335 // Unfortunately, NITZ time is not poll/update like everything
3336 // else in the system. So, if the upstream client isn't connected,
3337 // keep a copy of the last NITZ response (with receive time noted
3338 // above) around so we can deliver it when it is connected
3340 if (s_lastNITZTimeData != NULL) {
3341 free (s_lastNITZTimeData);
3342 s_lastNITZTimeData = NULL;
3345 s_lastNITZTimeData = malloc(p.dataSize());
3346 s_lastNITZTimeDataSize = p.dataSize();
3347 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
3350 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
3351 // FIXME The java code should handshake here to release wake lock
3353 if (shouldScheduleTimeout) {
3354 // Cancel the previous request
3355 if (s_last_wake_timeout_info != NULL) {
3356 s_last_wake_timeout_info->userParam = (void *)1;
3359 s_last_wake_timeout_info
3360 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
3361 &TIMEVAL_WAKE_TIMEOUT);
3368 if (shouldScheduleTimeout) {
3373 /** FIXME generalize this if you track UserCAllbackInfo, clear it
3374 when the callback occurs
3376 static UserCallbackInfo *
3377 internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
3378 const struct timeval *relativeTime)
3380 struct timeval myRelativeTime;
3381 UserCallbackInfo *p_info;
3383 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
3385 p_info->p_callback = callback;
3386 p_info->userParam = param;
3388 if (relativeTime == NULL) {
3389 /* treat null parameter as a 0 relative time */
3390 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
3392 /* FIXME I think event_add's tv param is really const anyway */
3393 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
3396 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
3398 ril_timer_add(&(p_info->event), &myRelativeTime);
3406 RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
3407 const struct timeval *relativeTime) {
3408 internalRequestTimedCallback (callback, param, relativeTime);
3412 failCauseToString(RIL_Errno e) {
3414 case RIL_E_SUCCESS: return "E_SUCCESS";
3415 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RAIDO_NOT_AVAILABLE";
3416 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
3417 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
3418 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
3419 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
3420 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
3421 case RIL_E_CANCELLED: return "E_CANCELLED";
3422 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
3423 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
3424 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
3425 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
3426 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
3427 #ifdef FEATURE_MULTIMODE_ANDROID
3428 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
3429 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
3431 default: return "<unknown error>";
3436 radioStateToString(RIL_RadioState s) {
3438 case RADIO_STATE_OFF: return "RADIO_OFF";
3439 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
3440 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
3441 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
3442 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
3443 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
3444 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
3445 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
3446 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
3447 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
3448 case RADIO_STATE_ON:return"RADIO_ON";
3449 default: return "<unknown state>";
3454 callStateToString(RIL_CallState s) {
3456 case RIL_CALL_ACTIVE : return "ACTIVE";
3457 case RIL_CALL_HOLDING: return "HOLDING";
3458 case RIL_CALL_DIALING: return "DIALING";
3459 case RIL_CALL_ALERTING: return "ALERTING";
3460 case RIL_CALL_INCOMING: return "INCOMING";
3461 case RIL_CALL_WAITING: return "WAITING";
3462 default: return "<unknown state>";
3467 requestToString(int request) {
3469 cat libs/telephony/ril_commands.h \
3470 | egrep "^ *{RIL_" \
3471 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3474 cat libs/telephony/ril_unsol_commands.h \
3475 | egrep "^ *{RIL_" \
3476 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
3480 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3481 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3482 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3483 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3484 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3485 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3486 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3487 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3488 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3489 case RIL_REQUEST_DIAL: return "DIAL";
3490 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3491 case RIL_REQUEST_HANGUP: return "HANGUP";
3492 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3493 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3494 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3495 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3496 case RIL_REQUEST_UDUB: return "UDUB";
3497 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3498 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3499 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3500 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3501 case RIL_REQUEST_OPERATOR: return "OPERATOR";
3502 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3503 case RIL_REQUEST_DTMF: return "DTMF";
3504 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3505 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3506 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3507 case RIL_REQUEST_SIM_IO: return "SIM_IO";
3508 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3509 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3510 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3511 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3512 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3513 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3514 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3515 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3516 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3517 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3518 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3519 case RIL_REQUEST_ANSWER: return "ANSWER";
3520 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3521 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3522 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3523 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3524 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3525 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3526 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3527 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3528 case RIL_REQUEST_DTMF_START: return "DTMF_START";
3529 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3530 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3531 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3532 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
3533 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
3534 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
3535 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3536 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3537 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3538 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3539 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3540 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3541 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3542 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3543 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3544 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3545 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
3546 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
3547 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
3548 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
3549 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
3550 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3551 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
3552 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
3553 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
3554 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
3555 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
3556 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
3557 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
3558 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
3559 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
3560 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
3561 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
3562 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
3563 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
3564 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
3565 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
3566 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
3567 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
3568 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
3569 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
3570 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
3571 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
3572 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
3573 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
3574 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
3575 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
3576 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
3577 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
3578 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
3579 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
3580 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
3581 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
3582 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
3583 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
3584 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
3585 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
3586 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
3587 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
3588 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
3589 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
3590 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
3591 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
3592 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
3593 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
3594 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
3595 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
3596 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
3597 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
3598 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
3599 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
3600 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
3601 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
3602 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
3603 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
3604 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
3605 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
3606 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
3607 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
3608 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
3609 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
3610 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
3611 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
3612 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
3613 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
3614 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
3615 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
3616 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
3617 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
3618 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
3619 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
3620 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
3621 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
3622 default: return "<unknown request>";
3626 } /* namespace android */