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 <telephony/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 dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
208 static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
210 static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
211 static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
212 static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
213 static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
214 static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
215 static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
216 static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
217 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
218 static int responseInts(Parcel &p, void *response, size_t responselen);
219 static int responseStrings(Parcel &p, void *response, size_t responselen);
220 static int responseString(Parcel &p, void *response, size_t responselen);
221 static int responseVoid(Parcel &p, void *response, size_t responselen);
222 static int responseCallList(Parcel &p, void *response, size_t responselen);
223 static int responseSMS(Parcel &p, void *response, size_t responselen);
224 static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
225 static int responseCallForwards(Parcel &p, void *response, size_t responselen);
226 static int responseDataCallList(Parcel &p, void *response, size_t responselen);
227 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
228 static int responseRaw(Parcel &p, void *response, size_t responselen);
229 static int responseSsn(Parcel &p, void *response, size_t responselen);
230 static int responseSimStatus(Parcel &p, void *response, size_t responselen);
231 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
232 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
233 static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
234 static int responseCellList(Parcel &p, void *response, size_t responselen);
235 static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
236 static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
237 static int responseCallRing(Parcel &p, void *response, size_t responselen);
238 static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
239 static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
240 static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
241 static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
243 static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
244 static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
245 static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
247 extern "C" const char * requestToString(int request);
248 extern "C" const char * failCauseToString(RIL_Errno);
249 extern "C" const char * callStateToString(RIL_CallState);
250 extern "C" const char * radioStateToString(RIL_RadioState);
253 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
257 static UserCallbackInfo * internalRequestTimedCallback
258 (RIL_TimedCallback callback, void *param,
259 const struct timeval *relativeTime);
261 /** Index == requestNumber */
262 static CommandInfo s_commands[] = {
263 #include "ril_commands.h"
266 static UnsolResponseInfo s_unsolResponses[] = {
267 #include "ril_unsol_commands.h"
270 /* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
271 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
272 radio state message and store it. Every time there is a change in Radio State
273 check to see if voice radio tech changes and notify telephony
275 int voiceRadioTech = -1;
277 /* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
278 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
279 source from radio state and store it. Every time there is a change in Radio State
280 check to see if subscription source changed and notify telephony
282 int cdmaSubscriptionSource = -1;
284 /* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
285 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
286 check to see if SIM/RUIM status changed and notify telephony
288 int simRuimStatus = -1;
291 strdupReadString(Parcel &p) {
295 s16 = p.readString16Inplace(&stringlen);
297 return strndup16to8(s16, stringlen);
300 static void writeStringToParcel(Parcel &p, const char *s) {
303 s16 = strdup8to16(s, &s16_len);
304 p.writeString16(s16, s16_len);
310 memsetString (char *s) {
312 memset (s, 0, strlen(s));
316 void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
317 const size_t* objects, size_t objectsSize,
319 // do nothing -- the data reference lives longer than the Parcel object
323 * To be called from dispatch thread
324 * Issue a single local request, ensuring that the response
325 * is not sent back up to the command process
328 issueLocalRequest(int request, void *data, int len) {
332 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
335 pRI->token = 0xffffffff; // token is not used in this context
336 pRI->pCI = &(s_commands[request]);
338 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
341 pRI->p_next = s_pendingRequests;
342 s_pendingRequests = pRI;
344 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
347 RLOGD("C[locl]> %s", requestToString(request));
349 s_callbacks.onRequest(request, data, len, pRI);
355 processCommandBuffer(void *buffer, size_t buflen) {
363 p.setData((uint8_t *) buffer, buflen);
365 // status checked at end
366 status = p.readInt32(&request);
367 status = p.readInt32 (&token);
369 if (status != NO_ERROR) {
370 RLOGE("invalid request block");
374 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
375 RLOGE("unsupported request code %d token %d", request, token);
376 // FIXME this should perhaps return a response
381 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
384 pRI->pCI = &(s_commands[request]);
386 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
389 pRI->p_next = s_pendingRequests;
390 s_pendingRequests = pRI;
392 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
395 /* sLastDispatchedToken = token; */
397 pRI->pCI->dispatchFunction(p, pRI);
403 invalidCommandBlock (RequestInfo *pRI) {
404 RLOGE("invalid command block for token %d request %s",
405 pRI->token, requestToString(pRI->pCI->requestNumber));
408 /** Callee expects NULL */
410 dispatchVoid (Parcel& p, RequestInfo *pRI) {
412 printRequest(pRI->token, pRI->pCI->requestNumber);
413 s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
416 /** Callee expects const char * */
418 dispatchString (Parcel& p, RequestInfo *pRI) {
422 char *string8 = NULL;
424 string8 = strdupReadString(p);
427 appendPrintBuf("%s%s", printBuf, string8);
429 printRequest(pRI->token, pRI->pCI->requestNumber);
431 s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
432 sizeof(char *), pRI);
435 memsetString(string8);
441 invalidCommandBlock(pRI);
445 /** Callee expects const char ** */
447 dispatchStrings (Parcel &p, RequestInfo *pRI) {
448 int32_t countStrings;
453 status = p.readInt32 (&countStrings);
455 if (status != NO_ERROR) {
460 if (countStrings == 0) {
461 // just some non-null pointer
462 pStrings = (char **)alloca(sizeof(char *));
464 } else if (((int)countStrings) == -1) {
468 datalen = sizeof(char *) * countStrings;
470 pStrings = (char **)alloca(datalen);
472 for (int i = 0 ; i < countStrings ; i++) {
473 pStrings[i] = strdupReadString(p);
474 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
479 printRequest(pRI->token, pRI->pCI->requestNumber);
481 s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
483 if (pStrings != NULL) {
484 for (int i = 0 ; i < countStrings ; i++) {
486 memsetString (pStrings[i]);
492 memset(pStrings, 0, datalen);
498 invalidCommandBlock(pRI);
502 /** Callee expects const int * */
504 dispatchInts (Parcel &p, RequestInfo *pRI) {
510 status = p.readInt32 (&count);
512 if (status != NO_ERROR || count == 0) {
516 datalen = sizeof(int) * count;
517 pInts = (int *)alloca(datalen);
520 for (int i = 0 ; i < count ; i++) {
523 status = p.readInt32(&t);
525 appendPrintBuf("%s%d,", printBuf, t);
527 if (status != NO_ERROR) {
533 printRequest(pRI->token, pRI->pCI->requestNumber);
535 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts),
539 memset(pInts, 0, datalen);
544 invalidCommandBlock(pRI);
550 * Callee expects const RIL_SMS_WriteArgs *
556 dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
557 RIL_SMS_WriteArgs args;
561 memset (&args, 0, sizeof(args));
563 status = p.readInt32(&t);
564 args.status = (int)t;
566 args.pdu = strdupReadString(p);
568 if (status != NO_ERROR || args.pdu == NULL) {
572 args.smsc = strdupReadString(p);
575 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
576 (char*)args.pdu, (char*)args.smsc);
578 printRequest(pRI->token, pRI->pCI->requestNumber);
580 s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
583 memsetString (args.pdu);
589 memset(&args, 0, sizeof(args));
594 invalidCommandBlock(pRI);
599 * Callee expects const RIL_Dial *
605 dispatchDial (Parcel &p, RequestInfo *pRI) {
607 RIL_UUS_Info uusInfo;
613 memset (&dial, 0, sizeof(dial));
615 dial.address = strdupReadString(p);
617 status = p.readInt32(&t);
620 if (status != NO_ERROR || dial.address == NULL) {
624 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
626 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
628 status = p.readInt32(&uusPresent);
630 if (status != NO_ERROR) {
634 if (uusPresent == 0) {
639 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
641 status = p.readInt32(&t);
642 uusInfo.uusType = (RIL_UUS_Type) t;
644 status = p.readInt32(&t);
645 uusInfo.uusDcs = (RIL_UUS_DCS) t;
647 status = p.readInt32(&len);
648 if (status != NO_ERROR) {
652 // The java code writes -1 for null arrays
653 if (((int) len) == -1) {
654 uusInfo.uusData = NULL;
657 uusInfo.uusData = (char*) p.readInplace(len);
660 uusInfo.uusLength = len;
661 dial.uusInfo = &uusInfo;
663 sizeOfDial = sizeof(dial);
667 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
669 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
670 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
671 dial.uusInfo->uusLength);
674 printRequest(pRI->token, pRI->pCI->requestNumber);
676 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI);
679 memsetString (dial.address);
685 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
686 memset(&dial, 0, sizeof(dial));
691 invalidCommandBlock(pRI);
696 * Callee expects const RIL_SIM_IO *
707 dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
717 memset (&simIO, 0, sizeof(simIO));
719 // note we only check status at the end
721 status = p.readInt32(&t);
722 simIO.v6.command = (int)t;
724 status = p.readInt32(&t);
725 simIO.v6.fileid = (int)t;
727 simIO.v6.path = strdupReadString(p);
729 status = p.readInt32(&t);
730 simIO.v6.p1 = (int)t;
732 status = p.readInt32(&t);
733 simIO.v6.p2 = (int)t;
735 status = p.readInt32(&t);
736 simIO.v6.p3 = (int)t;
738 simIO.v6.data = strdupReadString(p);
739 simIO.v6.pin2 = strdupReadString(p);
740 simIO.v6.aidPtr = strdupReadString(p);
743 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
744 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
745 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
746 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
748 printRequest(pRI->token, pRI->pCI->requestNumber);
750 if (status != NO_ERROR) {
754 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
755 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, size, pRI);
758 memsetString (simIO.v6.path);
759 memsetString (simIO.v6.data);
760 memsetString (simIO.v6.pin2);
761 memsetString (simIO.v6.aidPtr);
764 free (simIO.v6.path);
765 free (simIO.v6.data);
766 free (simIO.v6.pin2);
767 free (simIO.v6.aidPtr);
770 memset(&simIO, 0, sizeof(simIO));
775 invalidCommandBlock(pRI);
780 * Callee expects const RIL_CallForwardInfo *
782 * int32_t status/action
784 * int32_t serviceCode
786 * String number (0 length -> null)
787 * int32_t timeSeconds
790 dispatchCallForward(Parcel &p, RequestInfo *pRI) {
791 RIL_CallForwardInfo cff;
795 memset (&cff, 0, sizeof(cff));
797 // note we only check status at the end
799 status = p.readInt32(&t);
802 status = p.readInt32(&t);
805 status = p.readInt32(&t);
806 cff.serviceClass = (int)t;
808 status = p.readInt32(&t);
811 cff.number = strdupReadString(p);
813 status = p.readInt32(&t);
814 cff.timeSeconds = (int)t;
816 if (status != NO_ERROR) {
820 // special case: number 0-length fields is null
822 if (cff.number != NULL && strlen (cff.number) == 0) {
827 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
828 cff.status, cff.reason, cff.serviceClass, cff.toa,
829 (char*)cff.number, cff.timeSeconds);
831 printRequest(pRI->token, pRI->pCI->requestNumber);
833 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
836 memsetString(cff.number);
842 memset(&cff, 0, sizeof(cff));
847 invalidCommandBlock(pRI);
853 dispatchRaw(Parcel &p, RequestInfo *pRI) {
858 status = p.readInt32(&len);
860 if (status != NO_ERROR) {
864 // The java code writes -1 for null arrays
865 if (((int)len) == -1) {
870 data = p.readInplace(len);
873 appendPrintBuf("%sraw_size=%d", printBuf, len);
875 printRequest(pRI->token, pRI->pCI->requestNumber);
877 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
881 invalidCommandBlock(pRI);
886 constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
893 memset(&rcsm, 0, sizeof(rcsm));
895 status = p.readInt32(&t);
896 rcsm.uTeleserviceID = (int) t;
898 status = p.read(&ut,sizeof(ut));
899 rcsm.bIsServicePresent = (uint8_t) ut;
901 status = p.readInt32(&t);
902 rcsm.uServicecategory = (int) t;
904 status = p.readInt32(&t);
905 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
907 status = p.readInt32(&t);
908 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
910 status = p.readInt32(&t);
911 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
913 status = p.readInt32(&t);
914 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
916 status = p.read(&ut,sizeof(ut));
917 rcsm.sAddress.number_of_digits= (uint8_t) ut;
919 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
920 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
921 status = p.read(&ut,sizeof(ut));
922 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
925 status = p.readInt32(&t);
926 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
928 status = p.read(&ut,sizeof(ut));
929 rcsm.sSubAddress.odd = (uint8_t) ut;
931 status = p.read(&ut,sizeof(ut));
932 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
934 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
935 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
936 status = p.read(&ut,sizeof(ut));
937 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
940 status = p.readInt32(&t);
941 rcsm.uBearerDataLen = (int) t;
943 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
944 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
945 status = p.read(&ut, sizeof(ut));
946 rcsm.aBearerData[digitCount] = (uint8_t) ut;
949 if (status != NO_ERROR) {
954 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
955 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
956 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
957 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
960 printRequest(pRI->token, pRI->pCI->requestNumber);
966 dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
967 RIL_CDMA_SMS_Message rcsm;
969 ALOGD("dispatchCdmaSms");
970 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
974 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
977 memset(&rcsm, 0, sizeof(rcsm));
983 invalidCommandBlock(pRI);
988 dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
989 RIL_IMS_SMS_Message rism;
990 RIL_CDMA_SMS_Message rcsm;
992 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
994 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
997 memset(&rism, 0, sizeof(rism));
998 rism.tech = RADIO_TECH_3GPP2;
1000 rism.messageRef = messageRef;
1001 rism.message.cdmaMessage = &rcsm;
1003 s_callbacks.onRequest(pRI->pCI->requestNumber, &rism,
1004 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1008 memset(&rcsm, 0, sizeof(rcsm));
1009 memset(&rism, 0, sizeof(rism));
1015 invalidCommandBlock(pRI);
1020 dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1021 RIL_IMS_SMS_Message rism;
1022 int32_t countStrings;
1026 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1028 status = p.readInt32 (&countStrings);
1030 if (status != NO_ERROR) {
1034 memset(&rism, 0, sizeof(rism));
1035 rism.tech = RADIO_TECH_3GPP;
1037 rism.messageRef = messageRef;
1040 appendPrintBuf("%sformat=%d,", printBuf, rism.format);
1041 if (countStrings == 0) {
1042 // just some non-null pointer
1043 pStrings = (char **)alloca(sizeof(char *));
1045 } else if (((int)countStrings) == -1) {
1049 datalen = sizeof(char *) * countStrings;
1051 pStrings = (char **)alloca(datalen);
1053 for (int i = 0 ; i < countStrings ; i++) {
1054 pStrings[i] = strdupReadString(p);
1055 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1060 printRequest(pRI->token, pRI->pCI->requestNumber);
1062 rism.message.gsmMessage = pStrings;
1063 s_callbacks.onRequest(pRI->pCI->requestNumber, &rism,
1064 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1067 if (pStrings != NULL) {
1068 for (int i = 0 ; i < countStrings ; i++) {
1070 memsetString (pStrings[i]);
1076 memset(pStrings, 0, datalen);
1081 memset(&rism, 0, sizeof(rism));
1085 ALOGE("dispatchImsGsmSms invalid block");
1086 invalidCommandBlock(pRI);
1091 dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1093 status_t status = p.readInt32(&t);
1094 RIL_RadioTechnologyFamily format;
1098 ALOGD("dispatchImsSms");
1099 if (status != NO_ERROR) {
1102 format = (RIL_RadioTechnologyFamily) t;
1105 status = p.read(&retry,sizeof(retry));
1106 if (status != NO_ERROR) {
1109 // read messageRef field
1110 status = p.read(&messageRef,sizeof(messageRef));
1111 if (status != NO_ERROR) {
1115 if (RADIO_TECH_3GPP == format) {
1116 dispatchImsGsmSms(p, pRI, retry, messageRef);
1117 } else if (RADIO_TECH_3GPP2 == format) {
1118 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1120 ALOGE("requestImsSendSMS invalid format value =%d", format);
1126 invalidCommandBlock(pRI);
1131 dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1132 RIL_CDMA_SMS_Ack rcsa;
1137 memset(&rcsa, 0, sizeof(rcsa));
1139 status = p.readInt32(&t);
1140 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1142 status = p.readInt32(&t);
1143 rcsa.uSMSCauseCode = (int) t;
1145 if (status != NO_ERROR) {
1150 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1151 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1154 printRequest(pRI->token, pRI->pCI->requestNumber);
1156 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI);
1159 memset(&rcsa, 0, sizeof(rcsa));
1165 invalidCommandBlock(pRI);
1170 dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1175 status = p.readInt32(&num);
1176 if (status != NO_ERROR) {
1181 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1182 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
1185 for (int i = 0 ; i < num ; i++ ) {
1186 gsmBciPtrs[i] = &gsmBci[i];
1188 status = p.readInt32(&t);
1189 gsmBci[i].fromServiceId = (int) t;
1191 status = p.readInt32(&t);
1192 gsmBci[i].toServiceId = (int) t;
1194 status = p.readInt32(&t);
1195 gsmBci[i].fromCodeScheme = (int) t;
1197 status = p.readInt32(&t);
1198 gsmBci[i].toCodeScheme = (int) t;
1200 status = p.readInt32(&t);
1201 gsmBci[i].selected = (uint8_t) t;
1203 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1204 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1205 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1206 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1207 gsmBci[i].selected);
1211 if (status != NO_ERROR) {
1215 s_callbacks.onRequest(pRI->pCI->requestNumber,
1217 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1221 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1222 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
1229 invalidCommandBlock(pRI);
1234 dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1239 status = p.readInt32(&num);
1240 if (status != NO_ERROR) {
1245 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1246 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
1249 for (int i = 0 ; i < num ; i++ ) {
1250 cdmaBciPtrs[i] = &cdmaBci[i];
1252 status = p.readInt32(&t);
1253 cdmaBci[i].service_category = (int) t;
1255 status = p.readInt32(&t);
1256 cdmaBci[i].language = (int) t;
1258 status = p.readInt32(&t);
1259 cdmaBci[i].selected = (uint8_t) t;
1261 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1262 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1263 cdmaBci[i].language, cdmaBci[i].selected);
1267 if (status != NO_ERROR) {
1271 s_callbacks.onRequest(pRI->pCI->requestNumber,
1273 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1277 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1278 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
1285 invalidCommandBlock(pRI);
1289 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1290 RIL_CDMA_SMS_WriteArgs rcsw;
1297 memset(&rcsw, 0, sizeof(rcsw));
1299 status = p.readInt32(&t);
1302 status = p.readInt32(&t);
1303 rcsw.message.uTeleserviceID = (int) t;
1305 status = p.read(&uct,sizeof(uct));
1306 rcsw.message.bIsServicePresent = (uint8_t) uct;
1308 status = p.readInt32(&t);
1309 rcsw.message.uServicecategory = (int) t;
1311 status = p.readInt32(&t);
1312 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1314 status = p.readInt32(&t);
1315 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1317 status = p.readInt32(&t);
1318 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1320 status = p.readInt32(&t);
1321 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1323 status = p.read(&uct,sizeof(uct));
1324 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1326 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1327 status = p.read(&uct,sizeof(uct));
1328 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1331 status = p.readInt32(&t);
1332 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1334 status = p.read(&uct,sizeof(uct));
1335 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1337 status = p.read(&uct,sizeof(uct));
1338 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1340 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1341 status = p.read(&uct,sizeof(uct));
1342 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1345 status = p.readInt32(&t);
1346 rcsw.message.uBearerDataLen = (int) t;
1348 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1349 status = p.read(&uct, sizeof(uct));
1350 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1353 if (status != NO_ERROR) {
1358 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1359 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1360 message.sAddress.number_mode=%d, \
1361 message.sAddress.number_type=%d, ",
1362 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1363 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1364 rcsw.message.sAddress.number_mode,
1365 rcsw.message.sAddress.number_type);
1368 printRequest(pRI->token, pRI->pCI->requestNumber);
1370 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI);
1373 memset(&rcsw, 0, sizeof(rcsw));
1379 invalidCommandBlock(pRI);
1384 // For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1385 // Version 4 of the RIL interface adds a new PDP type parameter to support
1386 // IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1387 // RIL, remove the parameter from the request.
1388 static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1389 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1390 const int numParamsRilV3 = 6;
1392 // The first bytes of the RIL parcel contain the request number and the
1393 // serial number - see processCommandBuffer(). Copy them over too.
1394 int pos = p.dataPosition();
1396 int numParams = p.readInt32();
1397 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1399 p2.appendFrom(&p, 0, pos);
1400 p2.writeInt32(numParamsRilV3);
1401 for(int i = 0; i < numParamsRilV3; i++) {
1402 p2.writeString16(p.readString16());
1404 p2.setDataPosition(pos);
1405 dispatchStrings(p2, pRI);
1407 p.setDataPosition(pos);
1408 dispatchStrings(p, pRI);
1412 // For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1413 // When all RILs handle this request, this function can be removed and
1414 // the request can be sent directly to the RIL using dispatchVoid.
1415 static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
1416 RIL_RadioState state = s_callbacks.onStateRequest();
1418 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1419 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1422 // RILs that support RADIO_STATE_ON should support this request.
1423 if (RADIO_STATE_ON == state) {
1424 dispatchVoid(p, pRI);
1428 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1429 // will not support this new request either and decode Voice Radio Technology
1431 voiceRadioTech = decodeVoiceRadioTechnology(state);
1433 if (voiceRadioTech < 0)
1434 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1436 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1439 // For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1440 // When all RILs handle this request, this function can be removed and
1441 // the request can be sent directly to the RIL using dispatchVoid.
1442 static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
1443 RIL_RadioState state = s_callbacks.onStateRequest();
1445 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1446 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1449 // RILs that support RADIO_STATE_ON should support this request.
1450 if (RADIO_STATE_ON == state) {
1451 dispatchVoid(p, pRI);
1455 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1456 // will not support this new request either and decode CDMA Subscription Source
1458 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1460 if (cdmaSubscriptionSource < 0)
1461 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1463 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1466 static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1468 RIL_InitialAttachApn pf;
1472 memset(&pf, 0, sizeof(pf));
1474 pf.apn = strdupReadString(p);
1475 pf.protocol = strdupReadString(p);
1477 status = p.readInt32(&t);
1478 pf.authtype = (int) t;
1480 pf.username = strdupReadString(p);
1481 pf.password = strdupReadString(p);
1484 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
1485 printBuf, pf.apn, pf.protocol, pf.auth_type, pf.username, pf.password);
1487 printRequest(pRI->token, pRI->pCI->requestNumber);
1489 if (status != NO_ERROR) {
1492 s_callbacks.onRequest(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI);
1495 memsetString(pf.apn);
1496 memsetString(pf.protocol);
1497 memsetString(pf.username);
1498 memsetString(pf.password);
1507 memset(&pf, 0, sizeof(pf));
1512 invalidCommandBlock(pRI);
1517 blockingWrite(int fd, const void *buffer, size_t len) {
1518 size_t writeOffset = 0;
1519 const uint8_t *toWrite;
1521 toWrite = (const uint8_t *)buffer;
1523 while (writeOffset < len) {
1526 written = write (fd, toWrite + writeOffset,
1528 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
1531 writeOffset += written;
1532 } else { // written < 0
1533 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
1543 sendResponseRaw (const void *data, size_t dataSize) {
1544 int fd = s_fdCommand;
1548 if (s_fdCommand < 0) {
1552 if (dataSize > MAX_COMMAND_BYTES) {
1553 RLOGE("RIL: packet larger than %u (%u)",
1554 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1559 pthread_mutex_lock(&s_writeMutex);
1561 header = htonl(dataSize);
1563 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1566 pthread_mutex_unlock(&s_writeMutex);
1570 ret = blockingWrite(fd, data, dataSize);
1573 pthread_mutex_unlock(&s_writeMutex);
1577 pthread_mutex_unlock(&s_writeMutex);
1583 sendResponse (Parcel &p) {
1585 return sendResponseRaw(p.data(), p.dataSize());
1588 /** response is an int* pointing to an array of ints*/
1591 responseInts(Parcel &p, void *response, size_t responselen) {
1594 if (response == NULL && responselen != 0) {
1595 RLOGE("invalid response: NULL");
1596 return RIL_ERRNO_INVALID_RESPONSE;
1598 if (responselen % sizeof(int) != 0) {
1599 RLOGE("invalid response length %d expected multiple of %d\n",
1600 (int)responselen, (int)sizeof(int));
1601 return RIL_ERRNO_INVALID_RESPONSE;
1604 int *p_int = (int *) response;
1606 numInts = responselen / sizeof(int *);
1607 p.writeInt32 (numInts);
1611 for (int i = 0 ; i < numInts ; i++) {
1612 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1613 p.writeInt32(p_int[i]);
1621 /** response is a char **, pointing to an array of char *'s
1622 The parcel will begin with the version */
1623 static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1624 p.writeInt32(version);
1625 return responseStrings(p, response, responselen);
1628 /** response is a char **, pointing to an array of char *'s */
1629 static int responseStrings(Parcel &p, void *response, size_t responselen) {
1632 if (response == NULL && responselen != 0) {
1633 RLOGE("invalid response: NULL");
1634 return RIL_ERRNO_INVALID_RESPONSE;
1636 if (responselen % sizeof(char *) != 0) {
1637 RLOGE("invalid response length %d expected multiple of %d\n",
1638 (int)responselen, (int)sizeof(char *));
1639 return RIL_ERRNO_INVALID_RESPONSE;
1642 if (response == NULL) {
1645 char **p_cur = (char **) response;
1647 numStrings = responselen / sizeof(char *);
1648 p.writeInt32 (numStrings);
1652 for (int i = 0 ; i < numStrings ; i++) {
1653 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1654 writeStringToParcel (p, p_cur[i]);
1664 * NULL strings are accepted
1665 * FIXME currently ignores responselen
1667 static int responseString(Parcel &p, void *response, size_t responselen) {
1668 /* one string only */
1670 appendPrintBuf("%s%s", printBuf, (char*)response);
1673 writeStringToParcel(p, (const char *)response);
1678 static int responseVoid(Parcel &p, void *response, size_t responselen) {
1684 static int responseCallList(Parcel &p, void *response, size_t responselen) {
1687 if (response == NULL && responselen != 0) {
1688 RLOGE("invalid response: NULL");
1689 return RIL_ERRNO_INVALID_RESPONSE;
1692 if (responselen % sizeof (RIL_Call *) != 0) {
1693 RLOGE("invalid response length %d expected multiple of %d\n",
1694 (int)responselen, (int)sizeof (RIL_Call *));
1695 return RIL_ERRNO_INVALID_RESPONSE;
1699 /* number of call info's */
1700 num = responselen / sizeof(RIL_Call *);
1703 for (int i = 0 ; i < num ; i++) {
1704 RIL_Call *p_cur = ((RIL_Call **) response)[i];
1705 /* each call info */
1706 p.writeInt32(p_cur->state);
1707 p.writeInt32(p_cur->index);
1708 p.writeInt32(p_cur->toa);
1709 p.writeInt32(p_cur->isMpty);
1710 p.writeInt32(p_cur->isMT);
1711 p.writeInt32(p_cur->als);
1712 p.writeInt32(p_cur->isVoice);
1713 p.writeInt32(p_cur->isVoicePrivacy);
1714 writeStringToParcel(p, p_cur->number);
1715 p.writeInt32(p_cur->numberPresentation);
1716 writeStringToParcel(p, p_cur->name);
1717 p.writeInt32(p_cur->namePresentation);
1718 // Remove when partners upgrade to version 3
1719 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
1720 p.writeInt32(0); /* UUS Information is absent */
1722 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
1723 p.writeInt32(1); /* UUS Information is present */
1724 p.writeInt32(uusInfo->uusType);
1725 p.writeInt32(uusInfo->uusDcs);
1726 p.writeInt32(uusInfo->uusLength);
1727 p.write(uusInfo->uusData, uusInfo->uusLength);
1729 appendPrintBuf("%s[id=%d,%s,toa=%d,",
1732 callStateToString(p_cur->state),
1734 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
1736 (p_cur->isMpty)?"conf":"norm",
1737 (p_cur->isMT)?"mt":"mo",
1739 (p_cur->isVoice)?"voc":"nonvoc",
1740 (p_cur->isVoicePrivacy)?"evp":"noevp");
1741 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
1744 p_cur->numberPresentation,
1746 p_cur->namePresentation);
1754 static int responseSMS(Parcel &p, void *response, size_t responselen) {
1755 if (response == NULL) {
1756 RLOGE("invalid response: NULL");
1757 return RIL_ERRNO_INVALID_RESPONSE;
1760 if (responselen != sizeof (RIL_SMS_Response) ) {
1761 RLOGE("invalid response length %d expected %d",
1762 (int)responselen, (int)sizeof (RIL_SMS_Response));
1763 return RIL_ERRNO_INVALID_RESPONSE;
1766 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1768 p.writeInt32(p_cur->messageRef);
1769 writeStringToParcel(p, p_cur->ackPDU);
1770 p.writeInt32(p_cur->errorCode);
1773 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
1774 (char*)p_cur->ackPDU, p_cur->errorCode);
1780 static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
1782 if (response == NULL && responselen != 0) {
1783 RLOGE("invalid response: NULL");
1784 return RIL_ERRNO_INVALID_RESPONSE;
1787 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
1788 RLOGE("invalid response length %d expected multiple of %d",
1789 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
1790 return RIL_ERRNO_INVALID_RESPONSE;
1793 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
1796 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
1799 for (i = 0; i < num; i++) {
1800 p.writeInt32(p_cur[i].cid);
1801 p.writeInt32(p_cur[i].active);
1802 writeStringToParcel(p, p_cur[i].type);
1803 // apn is not used, so don't send.
1804 writeStringToParcel(p, p_cur[i].address);
1805 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
1807 (p_cur[i].active==0)?"down":"up",
1808 (char*)p_cur[i].type,
1809 (char*)p_cur[i].address);
1817 static int responseDataCallList(Parcel &p, void *response, size_t responselen)
1820 p.writeInt32(s_callbacks.version);
1822 if (s_callbacks.version < 5) {
1823 return responseDataCallListV4(p, response, responselen);
1825 if (response == NULL && responselen != 0) {
1826 RLOGE("invalid response: NULL");
1827 return RIL_ERRNO_INVALID_RESPONSE;
1830 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
1831 RLOGE("invalid response length %d expected multiple of %d",
1832 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
1833 return RIL_ERRNO_INVALID_RESPONSE;
1836 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
1839 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
1842 for (i = 0; i < num; i++) {
1843 p.writeInt32((int)p_cur[i].status);
1844 p.writeInt32(p_cur[i].suggestedRetryTime);
1845 p.writeInt32(p_cur[i].cid);
1846 p.writeInt32(p_cur[i].active);
1847 writeStringToParcel(p, p_cur[i].type);
1848 writeStringToParcel(p, p_cur[i].ifname);
1849 writeStringToParcel(p, p_cur[i].addresses);
1850 writeStringToParcel(p, p_cur[i].dnses);
1851 writeStringToParcel(p, p_cur[i].gateways);
1852 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
1854 p_cur[i].suggestedRetryTime,
1856 (p_cur[i].active==0)?"down":"up",
1857 (char*)p_cur[i].type,
1858 (char*)p_cur[i].ifname,
1859 (char*)p_cur[i].addresses,
1860 (char*)p_cur[i].dnses,
1861 (char*)p_cur[i].gateways);
1870 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
1872 if (s_callbacks.version < 5) {
1873 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
1875 return responseDataCallList(p, response, responselen);
1879 static int responseRaw(Parcel &p, void *response, size_t responselen) {
1880 if (response == NULL && responselen != 0) {
1881 RLOGE("invalid response: NULL with responselen != 0");
1882 return RIL_ERRNO_INVALID_RESPONSE;
1885 // The java code reads -1 size as null byte array
1886 if (response == NULL) {
1889 p.writeInt32(responselen);
1890 p.write(response, responselen);
1897 static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
1898 if (response == NULL) {
1899 RLOGE("invalid response: NULL");
1900 return RIL_ERRNO_INVALID_RESPONSE;
1903 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
1904 RLOGE("invalid response length was %d expected %d",
1905 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
1906 return RIL_ERRNO_INVALID_RESPONSE;
1909 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
1910 p.writeInt32(p_cur->sw1);
1911 p.writeInt32(p_cur->sw2);
1912 writeStringToParcel(p, p_cur->simResponse);
1915 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
1916 (char*)p_cur->simResponse);
1923 static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
1926 if (response == NULL && responselen != 0) {
1927 RLOGE("invalid response: NULL");
1928 return RIL_ERRNO_INVALID_RESPONSE;
1931 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
1932 RLOGE("invalid response length %d expected multiple of %d",
1933 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
1934 return RIL_ERRNO_INVALID_RESPONSE;
1937 /* number of call info's */
1938 num = responselen / sizeof(RIL_CallForwardInfo *);
1942 for (int i = 0 ; i < num ; i++) {
1943 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
1945 p.writeInt32(p_cur->status);
1946 p.writeInt32(p_cur->reason);
1947 p.writeInt32(p_cur->serviceClass);
1948 p.writeInt32(p_cur->toa);
1949 writeStringToParcel(p, p_cur->number);
1950 p.writeInt32(p_cur->timeSeconds);
1951 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
1952 (p_cur->status==1)?"enable":"disable",
1953 p_cur->reason, p_cur->serviceClass, p_cur->toa,
1954 (char*)p_cur->number,
1955 p_cur->timeSeconds);
1963 static int responseSsn(Parcel &p, void *response, size_t responselen) {
1964 if (response == NULL) {
1965 RLOGE("invalid response: NULL");
1966 return RIL_ERRNO_INVALID_RESPONSE;
1969 if (responselen != sizeof(RIL_SuppSvcNotification)) {
1970 RLOGE("invalid response length was %d expected %d",
1971 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
1972 return RIL_ERRNO_INVALID_RESPONSE;
1975 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
1976 p.writeInt32(p_cur->notificationType);
1977 p.writeInt32(p_cur->code);
1978 p.writeInt32(p_cur->index);
1979 p.writeInt32(p_cur->type);
1980 writeStringToParcel(p, p_cur->number);
1983 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
1984 (p_cur->notificationType==0)?"mo":"mt",
1985 p_cur->code, p_cur->index, p_cur->type,
1986 (char*)p_cur->number);
1992 static int responseCellList(Parcel &p, void *response, size_t responselen) {
1995 if (response == NULL && responselen != 0) {
1996 RLOGE("invalid response: NULL");
1997 return RIL_ERRNO_INVALID_RESPONSE;
2000 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
2001 RLOGE("invalid response length %d expected multiple of %d\n",
2002 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2003 return RIL_ERRNO_INVALID_RESPONSE;
2007 /* number of records */
2008 num = responselen / sizeof(RIL_NeighboringCell *);
2011 for (int i = 0 ; i < num ; i++) {
2012 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2014 p.writeInt32(p_cur->rssi);
2015 writeStringToParcel (p, p_cur->cid);
2017 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2018 p_cur->cid, p_cur->rssi);
2027 * Marshall the signalInfoRecord into the parcel if it exists.
2029 static void marshallSignalInfoRecord(Parcel &p,
2030 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2031 p.writeInt32(p_signalInfoRecord.isPresent);
2032 p.writeInt32(p_signalInfoRecord.signalType);
2033 p.writeInt32(p_signalInfoRecord.alertPitch);
2034 p.writeInt32(p_signalInfoRecord.signal);
2037 static int responseCdmaInformationRecords(Parcel &p,
2038 void *response, size_t responselen) {
2040 char* string8 = NULL;
2042 RIL_CDMA_InformationRecord *infoRec;
2044 if (response == NULL && responselen != 0) {
2045 RLOGE("invalid response: NULL");
2046 return RIL_ERRNO_INVALID_RESPONSE;
2049 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
2050 RLOGE("invalid response length %d expected multiple of %d\n",
2051 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2052 return RIL_ERRNO_INVALID_RESPONSE;
2055 RIL_CDMA_InformationRecords *p_cur =
2056 (RIL_CDMA_InformationRecords *) response;
2057 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2062 for (int i = 0 ; i < num ; i++) {
2063 infoRec = &p_cur->infoRec[i];
2064 p.writeInt32(infoRec->name);
2065 switch (infoRec->name) {
2066 case RIL_CDMA_DISPLAY_INFO_REC:
2067 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2068 if (infoRec->rec.display.alpha_len >
2069 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
2070 RLOGE("invalid display info response length %d \
2071 expected not more than %d\n",
2072 (int)infoRec->rec.display.alpha_len,
2073 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2074 return RIL_ERRNO_INVALID_RESPONSE;
2076 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2078 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2079 string8[i] = infoRec->rec.display.alpha_buf[i];
2081 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2082 writeStringToParcel(p, (const char*)string8);
2086 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2087 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2088 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2089 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
2090 RLOGE("invalid display info response length %d \
2091 expected not more than %d\n",
2092 (int)infoRec->rec.number.len,
2093 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2094 return RIL_ERRNO_INVALID_RESPONSE;
2096 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2098 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2099 string8[i] = infoRec->rec.number.buf[i];
2101 string8[(int)infoRec->rec.number.len] = '\0';
2102 writeStringToParcel(p, (const char*)string8);
2105 p.writeInt32(infoRec->rec.number.number_type);
2106 p.writeInt32(infoRec->rec.number.number_plan);
2107 p.writeInt32(infoRec->rec.number.pi);
2108 p.writeInt32(infoRec->rec.number.si);
2110 case RIL_CDMA_SIGNAL_INFO_REC:
2111 p.writeInt32(infoRec->rec.signal.isPresent);
2112 p.writeInt32(infoRec->rec.signal.signalType);
2113 p.writeInt32(infoRec->rec.signal.alertPitch);
2114 p.writeInt32(infoRec->rec.signal.signal);
2116 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2117 alertPitch=%X, signal=%X, ",
2118 printBuf, (int)infoRec->rec.signal.isPresent,
2119 (int)infoRec->rec.signal.signalType,
2120 (int)infoRec->rec.signal.alertPitch,
2121 (int)infoRec->rec.signal.signal);
2124 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2125 if (infoRec->rec.redir.redirectingNumber.len >
2126 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
2127 RLOGE("invalid display info response length %d \
2128 expected not more than %d\n",
2129 (int)infoRec->rec.redir.redirectingNumber.len,
2130 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2131 return RIL_ERRNO_INVALID_RESPONSE;
2133 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2134 .len + 1) * sizeof(char) );
2136 i < infoRec->rec.redir.redirectingNumber.len;
2138 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2140 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2141 writeStringToParcel(p, (const char*)string8);
2144 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2145 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2146 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2147 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2148 p.writeInt32(infoRec->rec.redir.redirectingReason);
2150 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2151 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2152 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2153 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2154 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2156 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2157 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2158 lineCtrlPowerDenial=%d, ", printBuf,
2159 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2160 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2161 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2162 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2165 case RIL_CDMA_T53_CLIR_INFO_REC:
2166 p.writeInt32((int)(infoRec->rec.clir.cause));
2168 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2171 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2172 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2173 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2175 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2176 infoRec->rec.audioCtrl.upLink,
2177 infoRec->rec.audioCtrl.downLink);
2180 case RIL_CDMA_T53_RELEASE_INFO_REC:
2181 // TODO(Moto): See David Krause, he has the answer:)
2182 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
2183 return RIL_ERRNO_INVALID_RESPONSE;
2185 RLOGE("Incorrect name value");
2186 return RIL_ERRNO_INVALID_RESPONSE;
2194 static int responseRilSignalStrength(Parcel &p,
2195 void *response, size_t responselen) {
2196 if (response == NULL && responselen != 0) {
2197 RLOGE("invalid response: NULL");
2198 return RIL_ERRNO_INVALID_RESPONSE;
2201 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2202 RIL_SignalStrength_v6 *p_cur = ((RIL_SignalStrength_v6 *) response);
2204 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2205 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2206 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2207 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2208 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2209 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2210 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2211 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
2213 * Fixup LTE for backwards compatibility
2215 if (s_callbacks.version <= 6) {
2216 // signalStrength: -1 -> 99
2217 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2218 p_cur->LTE_SignalStrength.signalStrength = 99;
2220 // rsrp: -1 -> INT_MAX all other negative value to positive.
2222 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2223 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2224 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2225 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2227 // rsrq: -1 -> INT_MAX
2228 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2229 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2231 // Not remapping rssnr is already using INT_MAX
2233 // cqi: -1 -> INT_MAX
2234 if (p_cur->LTE_SignalStrength.cqi == -1) {
2235 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2238 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2239 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2240 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2241 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2242 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2245 p.writeInt32(INT_MAX);
2246 p.writeInt32(INT_MAX);
2247 p.writeInt32(INT_MAX);
2248 p.writeInt32(INT_MAX);
2252 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
2253 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2254 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2255 EVDO_SS.signalNoiseRatio=%d,\
2256 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
2257 LTE_SS.rssnr=%d,LTE_SS.cqi=%d]",
2259 p_cur->GW_SignalStrength.signalStrength,
2260 p_cur->GW_SignalStrength.bitErrorRate,
2261 p_cur->CDMA_SignalStrength.dbm,
2262 p_cur->CDMA_SignalStrength.ecio,
2263 p_cur->EVDO_SignalStrength.dbm,
2264 p_cur->EVDO_SignalStrength.ecio,
2265 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2266 p_cur->LTE_SignalStrength.signalStrength,
2267 p_cur->LTE_SignalStrength.rsrp,
2268 p_cur->LTE_SignalStrength.rsrq,
2269 p_cur->LTE_SignalStrength.rssnr,
2270 p_cur->LTE_SignalStrength.cqi);
2274 RLOGE("invalid response length");
2275 return RIL_ERRNO_INVALID_RESPONSE;
2281 static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2282 if ((response == NULL) || (responselen == 0)) {
2283 return responseVoid(p, response, responselen);
2285 return responseCdmaSignalInfoRecord(p, response, responselen);
2289 static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2290 if (response == NULL || responselen == 0) {
2291 RLOGE("invalid response: NULL");
2292 return RIL_ERRNO_INVALID_RESPONSE;
2295 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
2296 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
2297 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2298 return RIL_ERRNO_INVALID_RESPONSE;
2303 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2304 marshallSignalInfoRecord(p, *p_cur);
2306 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2318 static int responseCdmaCallWaiting(Parcel &p, void *response,
2319 size_t responselen) {
2320 if (response == NULL && responselen != 0) {
2321 RLOGE("invalid response: NULL");
2322 return RIL_ERRNO_INVALID_RESPONSE;
2325 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
2326 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
2329 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2331 writeStringToParcel(p, p_cur->number);
2332 p.writeInt32(p_cur->numberPresentation);
2333 writeStringToParcel(p, p_cur->name);
2334 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2336 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2337 p.writeInt32(p_cur->number_type);
2338 p.writeInt32(p_cur->number_plan);
2345 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2346 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2347 signal=%d,number_type=%d,number_plan=%d]",
2350 p_cur->numberPresentation,
2352 p_cur->signalInfoRecord.isPresent,
2353 p_cur->signalInfoRecord.signalType,
2354 p_cur->signalInfoRecord.alertPitch,
2355 p_cur->signalInfoRecord.signal,
2357 p_cur->number_plan);
2363 static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2364 if (response == NULL && responselen != 0) {
2365 RLOGE("responseSimRefresh: invalid response: NULL");
2366 return RIL_ERRNO_INVALID_RESPONSE;
2370 if (s_callbacks.version == 7) {
2371 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2372 p.writeInt32(p_cur->result);
2373 p.writeInt32(p_cur->ef_id);
2374 writeStringToParcel(p, p_cur->aid);
2376 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2382 int *p_cur = ((int *) response);
2383 p.writeInt32(p_cur[0]);
2384 p.writeInt32(p_cur[1]);
2385 writeStringToParcel(p, NULL);
2387 appendPrintBuf("%sresult=%d, ef_id=%d",
2397 static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2399 if (response == NULL && responselen != 0) {
2400 RLOGE("invalid response: NULL");
2401 return RIL_ERRNO_INVALID_RESPONSE;
2404 if (responselen % sizeof(RIL_CellInfo) != 0) {
2405 RLOGE("invalid response length %d expected multiple of %d",
2406 (int)responselen, (int)sizeof(RIL_CellInfo));
2407 return RIL_ERRNO_INVALID_RESPONSE;
2410 int num = responselen / sizeof(RIL_CellInfo);
2413 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2416 for (i = 0; i < num; i++) {
2417 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2418 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2419 p.writeInt32((int)p_cur->cellInfoType);
2420 p.writeInt32(p_cur->registered);
2421 p.writeInt32(p_cur->timeStampType);
2422 p.writeInt64(p_cur->timeStamp);
2423 switch(p_cur->cellInfoType) {
2424 case RIL_CELL_INFO_TYPE_GSM: {
2425 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
2426 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2427 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2428 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
2429 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2430 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
2431 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2432 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2434 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2435 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2436 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2437 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2438 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2439 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2442 case RIL_CELL_INFO_TYPE_WCDMA: {
2443 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2444 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2445 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2446 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2447 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2448 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2449 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2450 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2451 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2453 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2454 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2455 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2456 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2457 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2458 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2459 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2462 case RIL_CELL_INFO_TYPE_CDMA: {
2463 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2464 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2465 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2466 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2467 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2468 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2470 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2471 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
2472 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
2473 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
2474 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2476 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
2477 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
2478 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
2479 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
2480 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
2481 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2483 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
2484 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
2485 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
2486 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
2487 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2490 case RIL_CELL_INFO_TYPE_LTE: {
2491 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
2492 p_cur->CellInfo.lte.cellIdentityLte.mcc,
2493 p_cur->CellInfo.lte.cellIdentityLte.mnc,
2494 p_cur->CellInfo.lte.cellIdentityLte.ci,
2495 p_cur->CellInfo.lte.cellIdentityLte.pci,
2496 p_cur->CellInfo.lte.cellIdentityLte.tac);
2498 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
2499 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
2500 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
2501 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
2502 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
2504 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
2505 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
2506 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
2507 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
2508 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
2509 p_cur->CellInfo.lte.signalStrengthLte.cqi,
2510 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2511 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
2512 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
2513 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
2514 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
2515 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
2516 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2528 static void triggerEvLoop() {
2530 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
2531 /* trigger event loop to wakeup. No reason to do this,
2532 * if we're in the event loop thread */
2534 ret = write (s_fdWakeupWrite, " ", 1);
2535 } while (ret < 0 && errno == EINTR);
2539 static void rilEventAddWakeup(struct ril_event *ev) {
2544 static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
2545 p.writeInt32(num_apps);
2547 for (int i = 0; i < num_apps; i++) {
2548 p.writeInt32(appStatus[i].app_type);
2549 p.writeInt32(appStatus[i].app_state);
2550 p.writeInt32(appStatus[i].perso_substate);
2551 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
2552 writeStringToParcel(p, (const char*)
2553 (appStatus[i].app_label_ptr));
2554 p.writeInt32(appStatus[i].pin1_replaced);
2555 p.writeInt32(appStatus[i].pin1);
2556 p.writeInt32(appStatus[i].pin2);
2557 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
2558 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
2560 appStatus[i].app_type,
2561 appStatus[i].app_state,
2562 appStatus[i].perso_substate,
2563 appStatus[i].aid_ptr,
2564 appStatus[i].app_label_ptr,
2565 appStatus[i].pin1_replaced,
2572 static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
2575 if (response == NULL && responselen != 0) {
2576 RLOGE("invalid response: NULL");
2577 return RIL_ERRNO_INVALID_RESPONSE;
2580 if (responselen == sizeof (RIL_CardStatus_v6)) {
2581 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
2583 p.writeInt32(p_cur->card_state);
2584 p.writeInt32(p_cur->universal_pin_state);
2585 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2586 p.writeInt32(p_cur->cdma_subscription_app_index);
2587 p.writeInt32(p_cur->ims_subscription_app_index);
2589 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2590 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
2591 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
2593 p.writeInt32(p_cur->card_state);
2594 p.writeInt32(p_cur->universal_pin_state);
2595 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2596 p.writeInt32(p_cur->cdma_subscription_app_index);
2599 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2601 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
2602 return RIL_ERRNO_INVALID_RESPONSE;
2608 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2609 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
2613 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
2614 (RIL_GSM_BroadcastSmsConfigInfo **) response;
2615 for (int i = 0; i < num; i++) {
2616 p.writeInt32(p_cur[i]->fromServiceId);
2617 p.writeInt32(p_cur[i]->toServiceId);
2618 p.writeInt32(p_cur[i]->fromCodeScheme);
2619 p.writeInt32(p_cur[i]->toCodeScheme);
2620 p.writeInt32(p_cur[i]->selected);
2622 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
2623 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
2624 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
2625 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
2626 p_cur[i]->selected);
2633 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2634 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
2635 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
2637 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
2641 for (int i = 0 ; i < num ; i++ ) {
2642 p.writeInt32(p_cur[i]->service_category);
2643 p.writeInt32(p_cur[i]->language);
2644 p.writeInt32(p_cur[i]->selected);
2646 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
2648 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
2649 p_cur[i]->selected);
2656 static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
2663 RLOGD("Inside responseCdmaSms");
2665 if (response == NULL && responselen != 0) {
2666 RLOGE("invalid response: NULL");
2667 return RIL_ERRNO_INVALID_RESPONSE;
2670 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
2671 RLOGE("invalid response length was %d expected %d",
2672 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
2673 return RIL_ERRNO_INVALID_RESPONSE;
2676 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
2677 p.writeInt32(p_cur->uTeleserviceID);
2678 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
2679 p.writeInt32(p_cur->uServicecategory);
2680 p.writeInt32(p_cur->sAddress.digit_mode);
2681 p.writeInt32(p_cur->sAddress.number_mode);
2682 p.writeInt32(p_cur->sAddress.number_type);
2683 p.writeInt32(p_cur->sAddress.number_plan);
2684 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
2685 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2686 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2687 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
2690 p.writeInt32(p_cur->sSubAddress.subaddressType);
2691 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
2692 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
2693 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2694 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2695 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
2698 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2699 p.writeInt32(p_cur->uBearerDataLen);
2700 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2701 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
2705 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
2706 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
2707 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
2708 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
2715 * A write on the wakeup fd is done just to pop us out of select()
2716 * We empty the buffer here and then ril_event will reset the timers on the
2719 static void processWakeupCallback(int fd, short flags, void *param) {
2723 RLOGV("processWakeupCallback");
2725 /* empty our wakeup socket out */
2727 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
2728 } while (ret > 0 || (ret < 0 && errno == EINTR));
2731 static void onCommandsSocketClosed() {
2735 /* mark pending requests as "cancelled" so we dont report responses */
2737 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
2740 p_cur = s_pendingRequests;
2742 for (p_cur = s_pendingRequests
2744 ; p_cur = p_cur->p_next
2746 p_cur->cancelled = 1;
2749 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
2753 static void processCommandsCallback(int fd, short flags, void *param) {
2759 assert(fd == s_fdCommand);
2761 p_rs = (RecordStream *)param;
2764 /* loop until EAGAIN/EINTR, end of stream, or other error */
2765 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
2767 if (ret == 0 && p_record == NULL) {
2770 } else if (ret < 0) {
2772 } else if (ret == 0) { /* && p_record != NULL */
2773 processCommandBuffer(p_record, recordlen);
2777 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
2778 /* fatal error or end-of-stream */
2780 RLOGE("error on reading command socket errno:%d\n", errno);
2782 RLOGW("EOS. Closing command socket.");
2788 ril_event_del(&s_commands_event);
2790 record_stream_free(p_rs);
2792 /* start listening for new connections again */
2793 rilEventAddWakeup(&s_listen_event);
2795 onCommandsSocketClosed();
2800 static void onNewCommandConnect() {
2801 // Inform we are connected and the ril version
2802 int rilVer = s_callbacks.version;
2803 RIL_onUnsolicitedResponse(RIL_UNSOL_RIL_CONNECTED,
2804 &rilVer, sizeof(rilVer));
2806 // implicit radio state changed
2807 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
2810 // Send last NITZ time data, in case it was missed
2811 if (s_lastNITZTimeData != NULL) {
2812 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
2814 free(s_lastNITZTimeData);
2815 s_lastNITZTimeData = NULL;
2818 // Get version string
2819 if (s_callbacks.getVersion != NULL) {
2820 const char *version;
2821 version = s_callbacks.getVersion();
2822 RLOGI("RIL Daemon version: %s\n", version);
2824 property_set(PROPERTY_RIL_IMPL, version);
2826 RLOGI("RIL Daemon version: unavailable\n");
2827 property_set(PROPERTY_RIL_IMPL, "unavailable");
2832 static void listenCallback (int fd, short flags, void *param) {
2835 int is_phone_socket;
2838 struct sockaddr_un peeraddr;
2839 socklen_t socklen = sizeof (peeraddr);
2842 socklen_t szCreds = sizeof(creds);
2844 struct passwd *pwd = NULL;
2846 assert (s_fdCommand < 0);
2847 assert (fd == s_fdListen);
2849 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
2851 if (s_fdCommand < 0 ) {
2852 RLOGE("Error on accept() errno:%d", errno);
2853 /* start listening for new connections again */
2854 rilEventAddWakeup(&s_listen_event);
2858 /* check the credential of the other side and only accept socket from
2862 is_phone_socket = 0;
2864 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
2866 if (err == 0 && szCreds > 0) {
2868 pwd = getpwuid(creds.uid);
2870 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
2871 is_phone_socket = 1;
2873 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
2876 RLOGE("Error on getpwuid() errno: %d", errno);
2879 RLOGD("Error on getsockopt() errno: %d", errno);
2882 if ( !is_phone_socket ) {
2883 RLOGE("RILD must accept socket from %s", PHONE_PROCESS);
2888 onCommandsSocketClosed();
2890 /* start listening for new connections again */
2891 rilEventAddWakeup(&s_listen_event);
2896 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
2899 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
2902 RLOGI("libril: new connection");
2904 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
2906 ril_event_set (&s_commands_event, s_fdCommand, 1,
2907 processCommandsCallback, p_rs);
2909 rilEventAddWakeup (&s_commands_event);
2911 onNewCommandConnect();
2914 static void freeDebugCallbackArgs(int number, char **args) {
2915 for (int i = 0; i < number; i++) {
2916 if (args[i] != NULL) {
2923 static void debugCallback (int fd, short flags, void *param) {
2924 int acceptFD, option;
2925 struct sockaddr_un peeraddr;
2926 socklen_t socklen = sizeof (peeraddr);
2928 unsigned int qxdm_data[6];
2929 const char *deactData[1] = {"1"};
2931 int hangupData[1] = {1};
2934 int MAX_DIAL_ADDRESS = 128;
2936 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
2939 RLOGE ("error accepting on debug port: %d\n", errno);
2943 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
2944 RLOGE ("error reading on socket: number of Args: \n");
2947 args = (char **) malloc(sizeof(char*) * number);
2949 for (int i = 0; i < number; i++) {
2951 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
2952 RLOGE ("error reading on socket: Len of Args: \n");
2953 freeDebugCallbackArgs(i, args);
2957 args[i] = (char *) malloc((sizeof(char) * len) + 1);
2958 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
2959 != (int)sizeof(char) * len) {
2960 RLOGE ("error reading on socket: Args[%d] \n", i);
2961 freeDebugCallbackArgs(i, args);
2964 char * buf = args[i];
2968 switch (atoi(args[0])) {
2970 RLOGI ("Connection on debug port: issuing reset.");
2971 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
2974 RLOGI ("Connection on debug port: issuing radio power off.");
2976 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2982 RLOGI ("Debug port: issuing unsolicited voice network change.");
2983 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
2987 RLOGI ("Debug port: QXDM log enable.");
2988 qxdm_data[0] = 65536; // head.func_tag
2989 qxdm_data[1] = 16; // head.len
2990 qxdm_data[2] = 1; // mode: 1 for 'start logging'
2991 qxdm_data[3] = 32; // log_file_size: 32megabytes
2992 qxdm_data[4] = 0; // log_mask
2993 qxdm_data[5] = 8; // log_max_fileindex
2994 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2998 RLOGI ("Debug port: QXDM log disable.");
2999 qxdm_data[0] = 65536;
3001 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
3005 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
3009 RLOGI("Debug port: Radio On");
3011 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
3013 // Set network selection automatic.
3014 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
3017 RLOGI("Debug port: Deactivate Data Call");
3018 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
3022 RLOGI("Debug port: Dial Call");
3024 if (strlen(args[1]) > MAX_DIAL_ADDRESS) {
3025 RLOGE("Debug port: Error calling Dial");
3026 freeDebugCallbackArgs(number, args);
3030 dialData.address = args[1];
3031 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
3034 RLOGI("Debug port: Answer Call");
3035 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
3038 RLOGI("Debug port: End Call");
3039 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
3040 sizeof(hangupData));
3043 RLOGE ("Invalid request");
3046 freeDebugCallbackArgs(number, args);
3051 static void userTimerCallback (int fd, short flags, void *param) {
3052 UserCallbackInfo *p_info;
3054 p_info = (UserCallbackInfo *)param;
3056 p_info->p_callback(p_info->userParam);
3059 // FIXME generalize this...there should be a cancel mechanism
3060 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3061 s_last_wake_timeout_info = NULL;
3069 eventLoop(void *param) {
3075 pthread_mutex_lock(&s_startupMutex);
3078 pthread_cond_broadcast(&s_startupCond);
3080 pthread_mutex_unlock(&s_startupMutex);
3082 ret = pipe(filedes);
3085 RLOGE("Error in pipe() errno:%d", errno);
3089 s_fdWakeupRead = filedes[0];
3090 s_fdWakeupWrite = filedes[1];
3092 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3094 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3095 processWakeupCallback, NULL);
3097 rilEventAddWakeup (&s_wakeupfd_event);
3099 // Only returns on error
3101 RLOGE ("error in event_loop_base errno:%d", errno);
3102 // kill self to restart on error
3109 RIL_startEventLoop(void) {
3111 pthread_attr_t attr;
3113 /* spin up eventLoop thread and wait for it to get started */
3115 pthread_mutex_lock(&s_startupMutex);
3117 pthread_attr_init (&attr);
3118 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3119 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3121 while (s_started == 0) {
3122 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3125 pthread_mutex_unlock(&s_startupMutex);
3128 RLOGE("Failed to create dispatch thread errno:%d", errno);
3133 // Used for testing purpose only.
3134 extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3135 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3139 RIL_register (const RIL_RadioFunctions *callbacks) {
3143 if (callbacks == NULL) {
3144 RLOGE("RIL_register: RIL_RadioFunctions * null");
3147 if (callbacks->version < RIL_VERSION_MIN) {
3148 RLOGE("RIL_register: version %d is to old, min version is %d",
3149 callbacks->version, RIL_VERSION_MIN);
3152 if (callbacks->version > RIL_VERSION) {
3153 RLOGE("RIL_register: version %d is too new, max version is %d",
3154 callbacks->version, RIL_VERSION);
3157 RLOGE("RIL_register: RIL version %d", callbacks->version);
3159 if (s_registerCalled > 0) {
3160 RLOGE("RIL_register has been called more than once. "
3161 "Subsequent call ignored");
3165 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3167 s_registerCalled = 1;
3169 // Little self-check
3171 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
3172 assert(i == s_commands[i].requestNumber);
3175 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
3176 assert(i + RIL_UNSOL_RESPONSE_BASE
3177 == s_unsolResponses[i].requestNumber);
3180 // New rild impl calls RIL_startEventLoop() first
3181 // old standalone impl wants it here.
3183 if (s_started == 0) {
3184 RIL_startEventLoop();
3187 // start listen socket
3190 ret = socket_local_server (SOCKET_NAME_RIL,
3191 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
3194 RLOGE("Unable to bind socket errno:%d", errno);
3200 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
3201 if (s_fdListen < 0) {
3202 RLOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
3206 ret = listen(s_fdListen, 4);
3209 RLOGE("Failed to listen on control socket '%d': %s",
3210 s_fdListen, strerror(errno));
3216 /* note: non-persistent so we can accept only one connection at a time */
3217 ril_event_set (&s_listen_event, s_fdListen, false,
3218 listenCallback, NULL);
3220 rilEventAddWakeup (&s_listen_event);
3223 // start debug interface socket
3225 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
3226 if (s_fdDebug < 0) {
3227 RLOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
3231 ret = listen(s_fdDebug, 4);
3234 RLOGE("Failed to listen on ril debug socket '%d': %s",
3235 s_fdDebug, strerror(errno));
3239 ril_event_set (&s_debug_event, s_fdDebug, true,
3240 debugCallback, NULL);
3242 rilEventAddWakeup (&s_debug_event);
3248 checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
3255 pthread_mutex_lock(&s_pendingRequestsMutex);
3257 for(RequestInfo **ppCur = &s_pendingRequests
3259 ; ppCur = &((*ppCur)->p_next)
3261 if (pRI == *ppCur) {
3264 *ppCur = (*ppCur)->p_next;
3269 pthread_mutex_unlock(&s_pendingRequestsMutex);
3276 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
3281 pRI = (RequestInfo *)t;
3283 if (!checkAndDequeueRequestInfo(pRI)) {
3284 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
3288 if (pRI->local > 0) {
3289 // Locally issued command...void only!
3290 // response does not go back up the command socket
3291 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
3296 appendPrintBuf("[%04d]< %s",
3297 pRI->token, requestToString(pRI->pCI->requestNumber));
3299 if (pRI->cancelled == 0) {
3302 p.writeInt32 (RESPONSE_SOLICITED);
3303 p.writeInt32 (pRI->token);
3304 errorOffset = p.dataPosition();
3308 if (response != NULL) {
3309 // there is a response payload, no matter success or not.
3310 ret = pRI->pCI->responseFunction(p, response, responselen);
3312 /* if an error occurred, rewind and mark it */
3314 p.setDataPosition(errorOffset);
3319 if (e != RIL_E_SUCCESS) {
3320 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
3323 if (s_fdCommand < 0) {
3324 RLOGD ("RIL onRequestComplete: Command channel closed");
3335 grabPartialWakeLock() {
3336 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
3341 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
3345 * Timer callback to put us back to sleep before the default timeout
3348 wakeTimeoutCallback (void *param) {
3349 // We're using "param != NULL" as a cancellation mechanism
3350 if (param == NULL) {
3351 //RLOGD("wakeTimeout: releasing wake lock");
3355 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
3360 decodeVoiceRadioTechnology (RIL_RadioState radioState) {
3361 switch (radioState) {
3362 case RADIO_STATE_SIM_NOT_READY:
3363 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3364 case RADIO_STATE_SIM_READY:
3365 return RADIO_TECH_UMTS;
3367 case RADIO_STATE_RUIM_NOT_READY:
3368 case RADIO_STATE_RUIM_READY:
3369 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3370 case RADIO_STATE_NV_NOT_READY:
3371 case RADIO_STATE_NV_READY:
3372 return RADIO_TECH_1xRTT;
3375 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
3381 decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
3382 switch (radioState) {
3383 case RADIO_STATE_SIM_NOT_READY:
3384 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3385 case RADIO_STATE_SIM_READY:
3386 case RADIO_STATE_RUIM_NOT_READY:
3387 case RADIO_STATE_RUIM_READY:
3388 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3389 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
3391 case RADIO_STATE_NV_NOT_READY:
3392 case RADIO_STATE_NV_READY:
3393 return CDMA_SUBSCRIPTION_SOURCE_NV;
3396 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
3402 decodeSimStatus (RIL_RadioState radioState) {
3403 switch (radioState) {
3404 case RADIO_STATE_SIM_NOT_READY:
3405 case RADIO_STATE_RUIM_NOT_READY:
3406 case RADIO_STATE_NV_NOT_READY:
3407 case RADIO_STATE_NV_READY:
3409 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3410 case RADIO_STATE_SIM_READY:
3411 case RADIO_STATE_RUIM_READY:
3412 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3415 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
3420 static bool is3gpp2(int radioTech) {
3421 switch (radioTech) {
3422 case RADIO_TECH_IS95A:
3423 case RADIO_TECH_IS95B:
3424 case RADIO_TECH_1xRTT:
3425 case RADIO_TECH_EVDO_0:
3426 case RADIO_TECH_EVDO_A:
3427 case RADIO_TECH_EVDO_B:
3428 case RADIO_TECH_EHRPD:
3435 /* If RIL sends SIM states or RUIM states, store the voice radio
3436 * technology and subscription source information so that they can be
3437 * returned when telephony framework requests them
3439 static RIL_RadioState
3440 processRadioState(RIL_RadioState newRadioState) {
3442 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
3443 int newVoiceRadioTech;
3444 int newCdmaSubscriptionSource;
3447 /* This is old RIL. Decode Subscription source and Voice Radio Technology
3448 from Radio State and send change notifications if there has been a change */
3449 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
3450 if(newVoiceRadioTech != voiceRadioTech) {
3451 voiceRadioTech = newVoiceRadioTech;
3452 RIL_onUnsolicitedResponse (RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
3453 &voiceRadioTech, sizeof(voiceRadioTech));
3455 if(is3gpp2(newVoiceRadioTech)) {
3456 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
3457 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
3458 cdmaSubscriptionSource = newCdmaSubscriptionSource;
3459 RIL_onUnsolicitedResponse (RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
3460 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource));
3463 newSimStatus = decodeSimStatus(newRadioState);
3464 if(newSimStatus != simRuimStatus) {
3465 simRuimStatus = newSimStatus;
3466 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
3469 /* Send RADIO_ON to telephony */
3470 newRadioState = RADIO_STATE_ON;
3473 return newRadioState;
3477 void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
3480 int unsolResponseIndex;
3482 int64_t timeReceived = 0;
3483 bool shouldScheduleTimeout = false;
3484 RIL_RadioState newState;
3486 if (s_registerCalled == 0) {
3487 // Ignore RIL_onUnsolicitedResponse before RIL_register
3488 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
3492 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
3494 if ((unsolResponseIndex < 0)
3495 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
3496 RLOGE("unsupported unsolicited response code %d", unsolResponse);
3500 // Grab a wake lock if needed for this reponse,
3501 // as we exit we'll either release it immediately
3502 // or set a timer to release it later.
3503 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
3505 grabPartialWakeLock();
3506 shouldScheduleTimeout = true;
3511 // No wake lock is grabed so don't set timeout
3512 shouldScheduleTimeout = false;
3516 // Mark the time this was received, doing this
3517 // after grabing the wakelock incase getting
3518 // the elapsedRealTime might cause us to goto
3520 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3521 timeReceived = elapsedRealtime();
3524 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
3528 p.writeInt32 (RESPONSE_UNSOLICITED);
3529 p.writeInt32 (unsolResponse);
3531 ret = s_unsolResponses[unsolResponseIndex]
3532 .responseFunction(p, data, datalen);
3534 // Problem with the response. Don't continue;
3538 // some things get more payload
3539 switch(unsolResponse) {
3540 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
3541 newState = processRadioState(s_callbacks.onStateRequest());
3542 p.writeInt32(newState);
3543 appendPrintBuf("%s {%s}", printBuf,
3544 radioStateToString(s_callbacks.onStateRequest()));
3548 case RIL_UNSOL_NITZ_TIME_RECEIVED:
3549 // Store the time that this was received so the
3550 // handler of this message can account for
3551 // the time it takes to arrive and process. In
3552 // particular the system has been known to sleep
3553 // before this message can be processed.
3554 p.writeInt64(timeReceived);
3558 ret = sendResponse(p);
3559 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3561 // Unfortunately, NITZ time is not poll/update like everything
3562 // else in the system. So, if the upstream client isn't connected,
3563 // keep a copy of the last NITZ response (with receive time noted
3564 // above) around so we can deliver it when it is connected
3566 if (s_lastNITZTimeData != NULL) {
3567 free (s_lastNITZTimeData);
3568 s_lastNITZTimeData = NULL;
3571 s_lastNITZTimeData = malloc(p.dataSize());
3572 s_lastNITZTimeDataSize = p.dataSize();
3573 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
3576 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
3577 // FIXME The java code should handshake here to release wake lock
3579 if (shouldScheduleTimeout) {
3580 // Cancel the previous request
3581 if (s_last_wake_timeout_info != NULL) {
3582 s_last_wake_timeout_info->userParam = (void *)1;
3585 s_last_wake_timeout_info
3586 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
3587 &TIMEVAL_WAKE_TIMEOUT);
3594 if (shouldScheduleTimeout) {
3599 /** FIXME generalize this if you track UserCAllbackInfo, clear it
3600 when the callback occurs
3602 static UserCallbackInfo *
3603 internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
3604 const struct timeval *relativeTime)
3606 struct timeval myRelativeTime;
3607 UserCallbackInfo *p_info;
3609 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
3611 p_info->p_callback = callback;
3612 p_info->userParam = param;
3614 if (relativeTime == NULL) {
3615 /* treat null parameter as a 0 relative time */
3616 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
3618 /* FIXME I think event_add's tv param is really const anyway */
3619 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
3622 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
3624 ril_timer_add(&(p_info->event), &myRelativeTime);
3632 RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
3633 const struct timeval *relativeTime) {
3634 internalRequestTimedCallback (callback, param, relativeTime);
3638 failCauseToString(RIL_Errno e) {
3640 case RIL_E_SUCCESS: return "E_SUCCESS";
3641 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
3642 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
3643 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
3644 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
3645 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
3646 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
3647 case RIL_E_CANCELLED: return "E_CANCELLED";
3648 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
3649 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
3650 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
3651 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
3652 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
3653 #ifdef FEATURE_MULTIMODE_ANDROID
3654 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
3655 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
3657 default: return "<unknown error>";
3662 radioStateToString(RIL_RadioState s) {
3664 case RADIO_STATE_OFF: return "RADIO_OFF";
3665 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
3666 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
3667 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
3668 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
3669 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
3670 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
3671 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
3672 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
3673 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
3674 case RADIO_STATE_ON:return"RADIO_ON";
3675 default: return "<unknown state>";
3680 callStateToString(RIL_CallState s) {
3682 case RIL_CALL_ACTIVE : return "ACTIVE";
3683 case RIL_CALL_HOLDING: return "HOLDING";
3684 case RIL_CALL_DIALING: return "DIALING";
3685 case RIL_CALL_ALERTING: return "ALERTING";
3686 case RIL_CALL_INCOMING: return "INCOMING";
3687 case RIL_CALL_WAITING: return "WAITING";
3688 default: return "<unknown state>";
3693 requestToString(int request) {
3695 cat libs/telephony/ril_commands.h \
3696 | egrep "^ *{RIL_" \
3697 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3700 cat libs/telephony/ril_unsol_commands.h \
3701 | egrep "^ *{RIL_" \
3702 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
3706 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3707 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3708 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3709 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3710 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3711 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3712 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3713 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3714 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3715 case RIL_REQUEST_DIAL: return "DIAL";
3716 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3717 case RIL_REQUEST_HANGUP: return "HANGUP";
3718 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3719 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3720 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3721 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3722 case RIL_REQUEST_UDUB: return "UDUB";
3723 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3724 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3725 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3726 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3727 case RIL_REQUEST_OPERATOR: return "OPERATOR";
3728 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3729 case RIL_REQUEST_DTMF: return "DTMF";
3730 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3731 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3732 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3733 case RIL_REQUEST_SIM_IO: return "SIM_IO";
3734 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3735 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3736 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3737 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3738 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3739 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3740 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3741 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3742 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3743 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3744 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3745 case RIL_REQUEST_ANSWER: return "ANSWER";
3746 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3747 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3748 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3749 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3750 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3751 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3752 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3753 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3754 case RIL_REQUEST_DTMF_START: return "DTMF_START";
3755 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3756 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3757 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3758 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
3759 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
3760 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
3761 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3762 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3763 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3764 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3765 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3766 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3767 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3768 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3769 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3770 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3771 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
3772 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
3773 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
3774 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
3775 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
3776 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3777 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
3778 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
3779 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
3780 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
3781 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
3782 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
3783 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
3784 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
3785 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
3786 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
3787 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
3788 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
3789 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
3790 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
3791 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
3792 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
3793 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
3794 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
3795 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
3796 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
3797 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
3798 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
3799 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
3800 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
3801 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
3802 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
3803 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
3804 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
3805 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
3806 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
3807 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
3808 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
3809 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
3810 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
3811 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
3812 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
3813 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
3814 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
3815 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
3816 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
3817 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
3818 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
3819 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
3820 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
3821 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
3822 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
3823 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
3824 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
3825 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
3826 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
3827 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
3828 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
3829 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
3830 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
3831 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
3832 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
3833 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
3834 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
3835 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
3836 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
3837 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
3838 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
3839 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
3840 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
3841 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
3842 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
3843 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
3844 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
3845 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
3846 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
3847 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
3848 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
3849 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
3850 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
3851 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
3852 default: return "<unknown request>";
3856 } /* namespace android */