1 /* //device/libs/telephony/ril.cpp
3 ** Copyright 2006, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
18 #define LOG_TAG "RILC"
20 #include <hardware_legacy/power.h>
22 #include <telephony/ril.h>
23 #include <telephony/ril_cdma_sms.h>
24 #include <cutils/sockets.h>
25 #include <cutils/jstring.h>
26 #include <cutils/record_stream.h>
27 #include <utils/Log.h>
28 #include <utils/SystemClock.h>
30 #include <utils/Parcel.h>
31 #include <cutils/jstring.h>
33 #include <sys/types.h>
49 #include <netinet/in.h>
50 #include <cutils/properties.h>
52 #include <ril_event.h>
56 #define PHONE_PROCESS "radio"
58 #define SOCKET_NAME_RIL "rild"
59 #define SOCKET_NAME_RIL_DEBUG "rild-debug"
61 #define ANDROID_WAKE_LOCK_NAME "radio-interface"
64 #define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
66 // match with constant in RIL.java
67 #define MAX_COMMAND_BYTES (8 * 1024)
69 // Basically: memset buffers that the client library
70 // shouldn't be using anymore in an attempt to find
71 // memory usage issues sooner.
72 #define MEMSET_FREED 1
74 #define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
76 #define MIN(a,b) ((a)<(b) ? (a) : (b))
78 /* Constants for response types */
79 #define RESPONSE_SOLICITED 0
80 #define RESPONSE_UNSOLICITED 1
82 /* Negative values for private RIL errno's */
83 #define RIL_ERRNO_INVALID_RESPONSE -1
85 // request, response, and unsolicited msg print macro
86 #define PRINTBUF_SIZE 8096
92 #define startRequest sprintf(printBuf, "(")
93 #define closeRequest sprintf(printBuf, "%s)", printBuf)
94 #define printRequest(token, req) \
95 LOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
97 #define startResponse sprintf(printBuf, "%s {", printBuf)
98 #define closeResponse sprintf(printBuf, "%s}", printBuf)
99 #define printResponse LOGD("%s", printBuf)
101 #define clearPrintBuf printBuf[0] = 0
102 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
103 #define appendPrintBuf(x...) sprintf(printBuf, x)
107 #define printRequest(token, req)
108 #define startResponse
109 #define closeResponse
110 #define printResponse
111 #define clearPrintBuf
112 #define removeLastChar
113 #define appendPrintBuf(x...)
116 enum WakeType {DONT_WAKE, WAKE_PARTIAL};
120 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
121 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
126 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
130 typedef struct RequestInfo {
131 int32_t token; //this is not RIL_Token
133 struct RequestInfo *p_next;
135 char local; // responses to local commands do not go back to command process
138 typedef struct UserCallbackInfo{
139 RIL_TimedCallback p_callback;
141 struct ril_event event;
142 struct UserCallbackInfo *p_next;
146 /*******************************************************************/
148 RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
149 static int s_registerCalled = 0;
151 static pthread_t s_tid_dispatch;
152 static pthread_t s_tid_reader;
153 static int s_started = 0;
155 static int s_fdListen = -1;
156 static int s_fdCommand = -1;
157 static int s_fdDebug = -1;
159 static int s_fdWakeupRead;
160 static int s_fdWakeupWrite;
162 static struct ril_event s_commands_event;
163 static struct ril_event s_wakeupfd_event;
164 static struct ril_event s_listen_event;
165 static struct ril_event s_wake_timeout_event;
166 static struct ril_event s_debug_event;
169 static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
171 static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
172 static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
173 static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
174 static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
176 static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
177 static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
179 static RequestInfo *s_pendingRequests = NULL;
181 static RequestInfo *s_toDispatchHead = NULL;
182 static RequestInfo *s_toDispatchTail = NULL;
184 static UserCallbackInfo *s_last_wake_timeout_info = NULL;
186 static void *s_lastNITZTimeData = NULL;
187 static size_t s_lastNITZTimeDataSize;
190 static char printBuf[PRINTBUF_SIZE];
193 /*******************************************************************/
195 static void dispatchVoid (Parcel& p, RequestInfo *pRI);
196 static void dispatchString (Parcel& p, RequestInfo *pRI);
197 static void dispatchStrings (Parcel& p, RequestInfo *pRI);
198 static void dispatchInts (Parcel& p, RequestInfo *pRI);
199 static void dispatchDial (Parcel& p, RequestInfo *pRI);
200 static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
201 static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
202 static void dispatchRaw(Parcel& p, RequestInfo *pRI);
203 static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
205 static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
206 static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
207 static void dispatchBrSmsCnf(Parcel &p, RequestInfo *pRI);
208 static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
209 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
210 static int responseInts(Parcel &p, void *response, size_t responselen);
211 static int responseStrings(Parcel &p, void *response, size_t responselen);
212 static int responseString(Parcel &p, void *response, size_t responselen);
213 static int responseVoid(Parcel &p, void *response, size_t responselen);
214 static int responseCallList(Parcel &p, void *response, size_t responselen);
215 static int responseSMS(Parcel &p, void *response, size_t responselen);
216 static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
217 static int responseCallForwards(Parcel &p, void *response, size_t responselen);
218 static int responseDataCallList(Parcel &p, void *response, size_t responselen);
219 static int responseRaw(Parcel &p, void *response, size_t responselen);
220 static int responseSsn(Parcel &p, void *response, size_t responselen);
221 static int responseSimStatus(Parcel &p, void *response, size_t responselen);
222 static int responseBrSmsCnf(Parcel &p, void *response, size_t responselen);
223 static int responseCdmaBrCnf(Parcel &p, void *response, size_t responselen);
224 static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
225 static int responseCellList(Parcel &p, void *response, size_t responselen);
227 extern "C" const char * requestToString(int request);
228 extern "C" const char * failCauseToString(RIL_Errno);
229 extern "C" const char * callStateToString(RIL_CallState);
230 extern "C" const char * radioStateToString(RIL_RadioState);
233 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
237 static UserCallbackInfo * internalRequestTimedCallback
238 (RIL_TimedCallback callback, void *param,
239 const struct timeval *relativeTime);
241 /** Index == requestNumber */
242 static CommandInfo s_commands[] = {
243 #include "ril_commands.h"
246 static UnsolResponseInfo s_unsolResponses[] = {
247 #include "ril_unsol_commands.h"
252 strdupReadString(Parcel &p) {
256 s16 = p.readString16Inplace(&stringlen);
258 return strndup16to8(s16, stringlen);
261 static void writeStringToParcel(Parcel &p, const char *s) {
264 s16 = strdup8to16(s, &s16_len);
265 p.writeString16(s16, s16_len);
271 memsetString (char *s) {
273 memset (s, 0, strlen(s));
277 void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
278 const size_t* objects, size_t objectsSize,
280 // do nothing -- the data reference lives longer than the Parcel object
284 * To be called from dispatch thread
285 * Issue a single local request, ensuring that the response
286 * is not sent back up to the command process
289 issueLocalRequest(int request, void *data, int len) {
293 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
296 pRI->token = 0xffffffff; // token is not used in this context
297 pRI->pCI = &(s_commands[request]);
299 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
302 pRI->p_next = s_pendingRequests;
303 s_pendingRequests = pRI;
305 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
308 LOGD("C[locl]> %s", requestToString(request));
310 s_callbacks.onRequest(request, data, len, pRI);
316 processCommandBuffer(void *buffer, size_t buflen) {
324 p.setData((uint8_t *) buffer, buflen);
326 // status checked at end
327 status = p.readInt32(&request);
328 status = p.readInt32 (&token);
330 if (status != NO_ERROR) {
331 LOGE("invalid request block");
335 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
336 LOGE("unsupported request code %d token %d", request, token);
337 // FIXME this should perhaps return a response
342 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
345 pRI->pCI = &(s_commands[request]);
347 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
350 pRI->p_next = s_pendingRequests;
351 s_pendingRequests = pRI;
353 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
356 /* sLastDispatchedToken = token; */
358 pRI->pCI->dispatchFunction(p, pRI);
364 invalidCommandBlock (RequestInfo *pRI) {
365 LOGE("invalid command block for token %d request %s",
366 pRI->token, requestToString(pRI->pCI->requestNumber));
369 /** Callee expects NULL */
371 dispatchVoid (Parcel& p, RequestInfo *pRI) {
373 printRequest(pRI->token, pRI->pCI->requestNumber);
374 s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
377 /** Callee expects const char * */
379 dispatchString (Parcel& p, RequestInfo *pRI) {
383 char *string8 = NULL;
385 string8 = strdupReadString(p);
388 appendPrintBuf("%s%s", printBuf, string8);
390 printRequest(pRI->token, pRI->pCI->requestNumber);
392 s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
393 sizeof(char *), pRI);
396 memsetString(string8);
402 invalidCommandBlock(pRI);
406 /** Callee expects const char ** */
408 dispatchStrings (Parcel &p, RequestInfo *pRI) {
409 int32_t countStrings;
414 status = p.readInt32 (&countStrings);
416 if (status != NO_ERROR) {
421 if (countStrings == 0) {
422 // just some non-null pointer
423 pStrings = (char **)alloca(sizeof(char *));
425 } else if (((int)countStrings) == -1) {
429 datalen = sizeof(char *) * countStrings;
431 pStrings = (char **)alloca(datalen);
433 for (int i = 0 ; i < countStrings ; i++) {
434 pStrings[i] = strdupReadString(p);
435 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
440 printRequest(pRI->token, pRI->pCI->requestNumber);
442 s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
444 if (pStrings != NULL) {
445 for (int i = 0 ; i < countStrings ; i++) {
447 memsetString (pStrings[i]);
453 memset(pStrings, 0, datalen);
459 invalidCommandBlock(pRI);
463 /** Callee expects const int * */
465 dispatchInts (Parcel &p, RequestInfo *pRI) {
471 status = p.readInt32 (&count);
473 if (status != NO_ERROR || count == 0) {
477 datalen = sizeof(int) * count;
478 pInts = (int *)alloca(datalen);
481 for (int i = 0 ; i < count ; i++) {
484 status = p.readInt32(&t);
486 appendPrintBuf("%s%d,", printBuf, t);
488 if (status != NO_ERROR) {
494 printRequest(pRI->token, pRI->pCI->requestNumber);
496 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts),
500 memset(pInts, 0, datalen);
505 invalidCommandBlock(pRI);
511 * Callee expects const RIL_SMS_WriteArgs *
517 dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
518 RIL_SMS_WriteArgs args;
522 memset (&args, 0, sizeof(args));
524 status = p.readInt32(&t);
525 args.status = (int)t;
527 args.pdu = strdupReadString(p);
529 if (status != NO_ERROR || args.pdu == NULL) {
533 args.smsc = strdupReadString(p);
536 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
537 (char*)args.pdu, (char*)args.smsc);
539 printRequest(pRI->token, pRI->pCI->requestNumber);
541 s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
544 memsetString (args.pdu);
550 memset(&args, 0, sizeof(args));
555 invalidCommandBlock(pRI);
560 * Callee expects const RIL_Dial *
566 dispatchDial (Parcel &p, RequestInfo *pRI) {
571 memset (&dial, 0, sizeof(dial));
573 dial.address = strdupReadString(p);
575 status = p.readInt32(&t);
578 if (status != NO_ERROR || dial.address == NULL) {
583 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
585 printRequest(pRI->token, pRI->pCI->requestNumber);
587 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeof(dial), pRI);
590 memsetString (dial.address);
596 memset(&dial, 0, sizeof(dial));
601 invalidCommandBlock(pRI);
606 * Callee expects const RIL_SIM_IO *
616 dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
621 memset (&simIO, 0, sizeof(simIO));
623 // note we only check status at the end
625 status = p.readInt32(&t);
626 simIO.command = (int)t;
628 status = p.readInt32(&t);
629 simIO.fileid = (int)t;
631 simIO.path = strdupReadString(p);
633 status = p.readInt32(&t);
636 status = p.readInt32(&t);
639 status = p.readInt32(&t);
642 simIO.data = strdupReadString(p);
643 simIO.pin2 = strdupReadString(p);
646 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s", printBuf,
647 simIO.command, simIO.fileid, (char*)simIO.path,
648 simIO.p1, simIO.p2, simIO.p3,
649 (char*)simIO.data, (char*)simIO.pin2);
651 printRequest(pRI->token, pRI->pCI->requestNumber);
653 if (status != NO_ERROR) {
657 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, sizeof(simIO), pRI);
660 memsetString (simIO.path);
661 memsetString (simIO.data);
662 memsetString (simIO.pin2);
670 memset(&simIO, 0, sizeof(simIO));
675 invalidCommandBlock(pRI);
680 * Callee expects const RIL_CallForwardInfo *
682 * int32_t status/action
684 * int32_t serviceCode
686 * String number (0 length -> null)
687 * int32_t timeSeconds
690 dispatchCallForward(Parcel &p, RequestInfo *pRI) {
691 RIL_CallForwardInfo cff;
695 memset (&cff, 0, sizeof(cff));
697 // note we only check status at the end
699 status = p.readInt32(&t);
702 status = p.readInt32(&t);
705 status = p.readInt32(&t);
706 cff.serviceClass = (int)t;
708 status = p.readInt32(&t);
711 cff.number = strdupReadString(p);
713 status = p.readInt32(&t);
714 cff.timeSeconds = (int)t;
716 if (status != NO_ERROR) {
720 // special case: number 0-length fields is null
722 if (cff.number != NULL && strlen (cff.number) == 0) {
727 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
728 cff.status, cff.reason, cff.serviceClass, cff.toa,
729 (char*)cff.number, cff.timeSeconds);
731 printRequest(pRI->token, pRI->pCI->requestNumber);
733 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
736 memsetString(cff.number);
742 memset(&cff, 0, sizeof(cff));
747 invalidCommandBlock(pRI);
753 dispatchRaw(Parcel &p, RequestInfo *pRI) {
758 status = p.readInt32(&len);
760 if (status != NO_ERROR) {
764 // The java code writes -1 for null arrays
765 if (((int)len) == -1) {
770 data = p.readInplace(len);
773 appendPrintBuf("%sraw_size=%d", printBuf, len);
775 printRequest(pRI->token, pRI->pCI->requestNumber);
777 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
781 invalidCommandBlock(pRI);
786 dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
787 RIL_CDMA_SMS_Message rcsm;
794 memset(&rcsm, 0, sizeof(rcsm));
796 status = p.readInt32(&t);
797 rcsm.uTeleserviceID = (int) t;
799 status = p.read(&ut,sizeof(ut));
800 rcsm.bIsServicePresent = (uint8_t) ut;
802 status = p.readInt32(&t);
803 rcsm.uServicecategory = (int) t;
805 status = p.readInt32(&t);
806 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
808 status = p.readInt32(&t);
809 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
811 status = p.readInt32(&t);
812 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
814 status = p.readInt32(&t);
815 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
817 status = p.read(&ut,sizeof(ut));
818 rcsm.sAddress.number_of_digits= (uint8_t) ut;
820 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
821 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
822 status = p.read(&ut,sizeof(ut));
823 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
826 status = p.readInt32(&t);
827 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
829 status = p.read(&ut,sizeof(ut));
830 rcsm.sSubAddress.odd = (uint8_t) ut;
832 status = p.read(&ut,sizeof(ut));
833 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
835 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
836 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
837 status = p.read(&ut,sizeof(ut));
838 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
841 status = p.readInt32(&t);
842 rcsm.uBearerDataLen = (int) t;
844 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
845 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
846 status = p.read(&ut, sizeof(ut));
847 rcsm.aBearerData[digitCount] = (uint8_t) ut;
850 if (status != NO_ERROR) {
855 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
856 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
857 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
858 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
861 printRequest(pRI->token, pRI->pCI->requestNumber);
863 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
866 memset(&rcsm, 0, sizeof(rcsm));
872 invalidCommandBlock(pRI);
877 dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
878 RIL_CDMA_SMS_Ack rcsa;
883 memset(&rcsa, 0, sizeof(rcsa));
885 status = p.readInt32(&t);
886 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
888 status = p.readInt32(&t);
889 rcsa.uSMSCauseCode = (int) t;
891 if (status != NO_ERROR) {
896 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
897 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
900 printRequest(pRI->token, pRI->pCI->requestNumber);
902 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI);
905 memset(&rcsa, 0, sizeof(rcsa));
911 invalidCommandBlock(pRI);
916 dispatchBrSmsCnf(Parcel &p, RequestInfo *pRI) {
917 RIL_BroadcastSMSConfig rbsc;
923 memset(&rbsc, 0, sizeof(rbsc));
925 status = p.readInt32(&t);
928 status = p.readInt32(&t);
929 rbsc.entries->uFromServiceID = (int) t;
931 status = p.readInt32(&t);
932 rbsc.entries->uToserviceID = (int) t;
934 //usage of read function on assumption that it reads any length given as 2nd argument
935 status = p.read(&ut,sizeof(ut));
936 rbsc.entries->bSelected = (uint8_t) ut;
938 if (status != NO_ERROR) {
943 appendPrintBuf("%ssize=%d, entries.uFromServiceID=%d, \
944 entries.uToserviceID=%d, entries.bSelected =%d, ", printBuf,
945 rbsc.size,rbsc.entries->uFromServiceID, rbsc.entries->uToserviceID,
946 rbsc.entries->bSelected);
949 printRequest(pRI->token, pRI->pCI->requestNumber);
951 s_callbacks.onRequest(pRI->pCI->requestNumber, &rbsc, sizeof(rbsc),pRI);
954 memset(&rbsc, 0, sizeof(rbsc));
960 invalidCommandBlock(pRI);
966 dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
967 RIL_CDMA_BroadcastSMSConfig rcbsc;
973 status = p.readInt32(&t);
974 rcbsc.size = (int) t;
976 LOGE("RIL_CPP: dispatchCdmaBrSmsCnf(), isize=%d", rcbsc.size);
978 if (rcbsc.size != 0) {
979 RIL_CDMA_BroadcastServiceInfo cdmaBsi[rcbsc.size];
980 for (int i = 0 ; i < rcbsc.size ; i++ ) {
981 status = p.readInt32(&t);
982 cdmaBsi[i].uServiceCategory = (int) t;
984 status = p.readInt32(&t);
985 cdmaBsi[i].uLanguage = (int) t;
987 status = p.readInt32(&t);
988 cdmaBsi[i].bSelected = (uint8_t) t;
991 appendPrintBuf("%sentries.uServicecategory=%d, entries.uLanguage =%d, \
992 entries.bSelected =%d, ", printBuf, cdmaBsi[i].uServiceCategory,
993 cdmaBsi[i].uLanguage, cdmaBsi[i].bSelected);
996 rcbsc.entries = (RIL_CDMA_BroadcastServiceInfo *)calloc(rcbsc.size,
997 sizeof(RIL_CDMA_BroadcastServiceInfo));
998 memcpy(rcbsc.entries, cdmaBsi, (sizeof(RIL_CDMA_BroadcastServiceInfo) * rcbsc.size));
1000 rcbsc.entries = NULL;
1003 if (status != NO_ERROR) {
1007 s_callbacks.onRequest(pRI->pCI->requestNumber,
1009 (sizeof(RIL_CDMA_BroadcastServiceInfo) * rcbsc.size) + sizeof(int),
1013 memset(&rcbsc, 0, sizeof(rcbsc));
1019 invalidCommandBlock(pRI);
1024 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1025 RIL_CDMA_SMS_WriteArgs rcsw;
1032 memset(&rcsw, 0, sizeof(rcsw));
1034 status = p.readInt32(&t);
1037 status = p.readInt32(&t);
1038 rcsw.message.uTeleserviceID = (int) t;
1040 status = p.read(&uct,sizeof(uct));
1041 rcsw.message.bIsServicePresent = (uint8_t) uct;
1043 status = p.readInt32(&t);
1044 rcsw.message.uServicecategory = (int) t;
1046 status = p.readInt32(&t);
1047 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1049 status = p.readInt32(&t);
1050 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1052 status = p.readInt32(&t);
1053 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1055 status = p.readInt32(&t);
1056 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1058 status = p.read(&uct,sizeof(uct));
1059 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1061 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1062 status = p.read(&uct,sizeof(uct));
1063 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1066 status = p.readInt32(&t);
1067 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1069 status = p.read(&uct,sizeof(uct));
1070 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1072 status = p.read(&uct,sizeof(uct));
1073 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1075 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1076 status = p.read(&uct,sizeof(uct));
1077 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1080 status = p.readInt32(&t);
1081 rcsw.message.uBearerDataLen = (int) t;
1083 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1084 status = p.read(&uct, sizeof(uct));
1085 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1088 if (status != NO_ERROR) {
1093 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1094 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1095 message.sAddress.number_mode=%d, \
1096 message.sAddress.number_type=%d, ",
1097 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1098 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1099 rcsw.message.sAddress.number_mode,
1100 rcsw.message.sAddress.number_type);
1103 printRequest(pRI->token, pRI->pCI->requestNumber);
1105 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI);
1108 memset(&rcsw, 0, sizeof(rcsw));
1114 invalidCommandBlock(pRI);
1120 blockingWrite(int fd, const void *buffer, size_t len) {
1121 size_t writeOffset = 0;
1122 const uint8_t *toWrite;
1124 toWrite = (const uint8_t *)buffer;
1126 while (writeOffset < len) {
1129 written = write (fd, toWrite + writeOffset,
1131 } while (written < 0 && errno == EINTR);
1134 writeOffset += written;
1135 } else { // written < 0
1136 LOGE ("RIL Response: unexpected error on write errno:%d", errno);
1146 sendResponseRaw (const void *data, size_t dataSize) {
1147 int fd = s_fdCommand;
1151 if (s_fdCommand < 0) {
1155 if (dataSize > MAX_COMMAND_BYTES) {
1156 LOGE("RIL: packet larger than %u (%u)",
1157 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1163 // FIXME is blocking here ok? issue #550970
1165 pthread_mutex_lock(&s_writeMutex);
1167 header = htonl(dataSize);
1169 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1175 blockingWrite(fd, data, dataSize);
1181 pthread_mutex_unlock(&s_writeMutex);
1187 sendResponse (Parcel &p) {
1189 return sendResponseRaw(p.data(), p.dataSize());
1192 /** response is an int* pointing to an array of ints*/
1195 responseInts(Parcel &p, void *response, size_t responselen) {
1198 if (response == NULL && responselen != 0) {
1199 LOGE("invalid response: NULL");
1200 return RIL_ERRNO_INVALID_RESPONSE;
1202 if (responselen % sizeof(int) != 0) {
1203 LOGE("invalid response length %d expected multiple of %d\n",
1204 (int)responselen, (int)sizeof(int));
1205 return RIL_ERRNO_INVALID_RESPONSE;
1208 int *p_int = (int *) response;
1210 numInts = responselen / sizeof(int *);
1211 p.writeInt32 (numInts);
1215 for (int i = 0 ; i < numInts ; i++) {
1216 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1217 p.writeInt32(p_int[i]);
1225 /** response is a char **, pointing to an array of char *'s */
1226 static int responseStrings(Parcel &p, void *response, size_t responselen) {
1229 if (response == NULL && responselen != 0) {
1230 LOGE("invalid response: NULL");
1231 return RIL_ERRNO_INVALID_RESPONSE;
1233 if (responselen % sizeof(char *) != 0) {
1234 LOGE("invalid response length %d expected multiple of %d\n",
1235 (int)responselen, (int)sizeof(char *));
1236 return RIL_ERRNO_INVALID_RESPONSE;
1239 if (response == NULL) {
1242 char **p_cur = (char **) response;
1244 numStrings = responselen / sizeof(char *);
1245 p.writeInt32 (numStrings);
1249 for (int i = 0 ; i < numStrings ; i++) {
1250 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1251 writeStringToParcel (p, p_cur[i]);
1261 * NULL strings are accepted
1262 * FIXME currently ignores responselen
1264 static int responseString(Parcel &p, void *response, size_t responselen) {
1265 /* one string only */
1267 appendPrintBuf("%s%s", printBuf, (char*)response);
1270 writeStringToParcel(p, (const char *)response);
1275 static int responseVoid(Parcel &p, void *response, size_t responselen) {
1281 static int responseCallList(Parcel &p, void *response, size_t responselen) {
1284 if (response == NULL && responselen != 0) {
1285 LOGE("invalid response: NULL");
1286 return RIL_ERRNO_INVALID_RESPONSE;
1289 if (responselen % sizeof (RIL_Call *) != 0) {
1290 LOGE("invalid response length %d expected multiple of %d\n",
1291 (int)responselen, (int)sizeof (RIL_Call *));
1292 return RIL_ERRNO_INVALID_RESPONSE;
1296 /* number of call info's */
1297 num = responselen / sizeof(RIL_Call *);
1300 for (int i = 0 ; i < num ; i++) {
1301 /* NEWRIL:TODO Remove this conditional and the else clause when we have the new ril */
1303 LOGD("Compilied for NEWRIL"); // NEWRIL:TODO remove when we have the new ril
1304 RIL_Call *p_cur = ((RIL_Call **) response)[i];
1305 /* each call info */
1306 p.writeInt32(p_cur->state);
1307 p.writeInt32(p_cur->index);
1308 p.writeInt32(p_cur->toa);
1309 p.writeInt32(p_cur->isMpty);
1310 p.writeInt32(p_cur->isMT);
1311 p.writeInt32(p_cur->als);
1312 p.writeInt32(p_cur->isVoice);
1313 p.writeInt32(p_cur->isVoicePrivacy);
1314 writeStringToParcel(p, p_cur->number);
1315 p.writeInt32(p_cur->numberPresentation);
1316 writeStringToParcel(p, p_cur->name);
1317 p.writeInt32(p_cur->namePresentation);
1318 appendPrintBuf("%s[id=%d,%s,toa=%d,%s,%s,als=%d,%s,%s,%s,cli=%d,name='%s',%d],",
1321 callStateToString(p_cur->state),
1323 (p_cur->isMpty)?"conf":"norm",
1324 (p_cur->isMT)?"mt":"mo",
1326 (p_cur->isVoice)?"voc":"nonvoc",
1327 (p_cur->isVoicePrivacy)?"evp":"noevp",
1329 p_cur->numberPresentation,
1331 p_cur->namePresentation);
1334 RIL_CallOld *p_cur = ((RIL_CallOld **) response)[i];
1335 /* each call info */
1336 p.writeInt32(p_cur->state);
1337 p.writeInt32(p_cur->index);
1338 p.writeInt32(p_cur->toa);
1339 p.writeInt32(p_cur->isMpty);
1340 p.writeInt32(p_cur->isMT);
1341 p.writeInt32(p_cur->als);
1342 p.writeInt32(p_cur->isVoice);
1343 p.writeInt32(0); // p_cur->isVoicePrivacy);
1344 writeStringToParcel (p, p_cur->number);
1345 p.writeInt32(p_cur->numberPresentation);
1346 writeStringToParcel (p, "a-person");
1347 p.writeInt32(2); // p_cur->namePresentation);
1348 appendPrintBuf("%s[id=%d,%s,toa=%d,%s,%s,als=%d,%s,%s,%s,cli=%d,name='%s',%d],",
1351 callStateToString(p_cur->state),
1353 (p_cur->isMpty)?"conf":"norm",
1354 (p_cur->isMT)?"mt":"mo",
1356 (p_cur->isVoice)?"voc":"nonvoc",
1357 (p_cur->isVoicePrivacy)?"evp":"noevp",
1359 p_cur->numberPresentation,
1361 p_cur->namePresentation);
1370 static int responseSMS(Parcel &p, void *response, size_t responselen) {
1371 if (response == NULL) {
1372 LOGE("invalid response: NULL");
1373 return RIL_ERRNO_INVALID_RESPONSE;
1376 if (responselen != sizeof (RIL_SMS_Response) ) {
1377 LOGE("invalid response length %d expected %d",
1378 (int)responselen, (int)sizeof (RIL_SMS_Response));
1379 return RIL_ERRNO_INVALID_RESPONSE;
1382 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1384 p.writeInt32(p_cur->messageRef);
1385 writeStringToParcel(p, p_cur->ackPDU);
1388 appendPrintBuf("%s%d,%s", printBuf, p_cur->messageRef,
1389 (char*)p_cur->ackPDU);
1395 static int responseDataCallList(Parcel &p, void *response, size_t responselen)
1397 if (response == NULL && responselen != 0) {
1398 LOGE("invalid response: NULL");
1399 return RIL_ERRNO_INVALID_RESPONSE;
1402 if (responselen % sizeof(RIL_Data_Call_Response) != 0) {
1403 LOGE("invalid response length %d expected multiple of %d",
1404 (int)responselen, (int)sizeof(RIL_Data_Call_Response));
1405 return RIL_ERRNO_INVALID_RESPONSE;
1408 int num = responselen / sizeof(RIL_Data_Call_Response);
1411 RIL_Data_Call_Response *p_cur = (RIL_Data_Call_Response *) response;
1414 for (i = 0; i < num; i++) {
1415 p.writeInt32(p_cur[i].cid);
1416 p.writeInt32(p_cur[i].active);
1417 writeStringToParcel(p, p_cur[i].type);
1418 writeStringToParcel(p, p_cur[i].apn);
1419 writeStringToParcel(p, p_cur[i].address);
1420 appendPrintBuf("%s[cid=%d,%s,%s,%s,%s],", printBuf,
1422 (p_cur[i].active==0)?"down":"up",
1423 (char*)p_cur[i].type,
1424 (char*)p_cur[i].apn,
1425 (char*)p_cur[i].address);
1433 static int responseRaw(Parcel &p, void *response, size_t responselen) {
1434 if (response == NULL && responselen != 0) {
1435 LOGE("invalid response: NULL with responselen != 0");
1436 return RIL_ERRNO_INVALID_RESPONSE;
1439 // The java code reads -1 size as null byte array
1440 if (response == NULL) {
1443 p.writeInt32(responselen);
1444 p.write(response, responselen);
1451 static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
1452 if (response == NULL) {
1453 LOGE("invalid response: NULL");
1454 return RIL_ERRNO_INVALID_RESPONSE;
1457 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
1458 LOGE("invalid response length was %d expected %d",
1459 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
1460 return RIL_ERRNO_INVALID_RESPONSE;
1463 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
1464 p.writeInt32(p_cur->sw1);
1465 p.writeInt32(p_cur->sw2);
1466 writeStringToParcel(p, p_cur->simResponse);
1469 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
1470 (char*)p_cur->simResponse);
1477 static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
1480 if (response == NULL && responselen != 0) {
1481 LOGE("invalid response: NULL");
1482 return RIL_ERRNO_INVALID_RESPONSE;
1485 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
1486 LOGE("invalid response length %d expected multiple of %d",
1487 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
1488 return RIL_ERRNO_INVALID_RESPONSE;
1491 /* number of call info's */
1492 num = responselen / sizeof(RIL_CallForwardInfo *);
1496 for (int i = 0 ; i < num ; i++) {
1497 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
1499 p.writeInt32(p_cur->status);
1500 p.writeInt32(p_cur->reason);
1501 p.writeInt32(p_cur->serviceClass);
1502 p.writeInt32(p_cur->toa);
1503 writeStringToParcel(p, p_cur->number);
1504 p.writeInt32(p_cur->timeSeconds);
1505 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
1506 (p_cur->status==1)?"enable":"disable",
1507 p_cur->reason, p_cur->serviceClass, p_cur->toa,
1508 (char*)p_cur->number,
1509 p_cur->timeSeconds);
1517 static int responseSsn(Parcel &p, void *response, size_t responselen) {
1518 if (response == NULL) {
1519 LOGE("invalid response: NULL");
1520 return RIL_ERRNO_INVALID_RESPONSE;
1523 if (responselen != sizeof(RIL_SuppSvcNotification)) {
1524 LOGE("invalid response length was %d expected %d",
1525 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
1526 return RIL_ERRNO_INVALID_RESPONSE;
1529 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
1530 p.writeInt32(p_cur->notificationType);
1531 p.writeInt32(p_cur->code);
1532 p.writeInt32(p_cur->index);
1533 p.writeInt32(p_cur->type);
1534 writeStringToParcel(p, p_cur->number);
1537 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
1538 (p_cur->notificationType==0)?"mo":"mt",
1539 p_cur->code, p_cur->index, p_cur->type,
1540 (char*)p_cur->number);
1546 static int responseCellList(Parcel &p, void *response, size_t responselen)
1550 if (response == NULL && responselen != 0) {
1551 LOGE("invalid response: NULL");
1552 return RIL_ERRNO_INVALID_RESPONSE;
1555 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
1556 LOGE("invalid response length %d expected multiple of %d\n",
1557 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
1558 return RIL_ERRNO_INVALID_RESPONSE;
1562 /* number of cell info's */
1563 num = responselen / sizeof(RIL_NeighboringCell *);
1566 for (int i = 0 ; i < num ; i++) {
1567 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
1569 /* each cell info */
1570 p.writeInt32(p_cur->rssi);
1571 writeStringToParcel (p, p_cur->cid);
1573 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
1574 p_cur->cid, p_cur->rssi);
1582 static void triggerEvLoop()
1585 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
1586 /* trigger event loop to wakeup. No reason to do this,
1587 * if we're in the event loop thread */
1589 ret = write (s_fdWakeupWrite, " ", 1);
1590 } while (ret < 0 && errno == EINTR);
1594 static void rilEventAddWakeup(struct ril_event *ev)
1600 static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
1603 if (response == NULL && responselen != 0) {
1604 LOGE("invalid response: NULL");
1605 return RIL_ERRNO_INVALID_RESPONSE;
1608 if (responselen % sizeof (RIL_CardStatus *) != 0) {
1609 LOGE("invalid response length %d expected multiple of %d\n",
1610 (int)responselen, (int)sizeof (RIL_CardStatus *));
1611 return RIL_ERRNO_INVALID_RESPONSE;
1614 RIL_CardStatus *p_cur = ((RIL_CardStatus *) response);
1616 p.writeInt32(p_cur->card_state);
1617 p.writeInt32(p_cur->universal_pin_state);
1618 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
1619 p.writeInt32(p_cur->cdma_subscription_app_index);
1620 p.writeInt32(p_cur->num_applications);
1623 for (i = 0; i < p_cur->num_applications; i++) {
1624 p.writeInt32(p_cur->applications[i].app_type);
1625 p.writeInt32(p_cur->applications[i].app_state);
1626 p.writeInt32(p_cur->applications[i].perso_substate);
1627 writeStringToParcel (p, (const char*)(p_cur->applications[i].aid_ptr));
1628 writeStringToParcel (p, (const char*)(p_cur->applications[i].app_label_ptr));
1629 p.writeInt32(p_cur->applications[i].pin1_replaced);
1630 p.writeInt32(p_cur->applications[i].pin1);
1631 p.writeInt32(p_cur->applications[i].pin2);
1632 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,aid_ptr=%s,\
1633 app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
1635 p_cur->applications[i].app_type,
1636 p_cur->applications[i].app_state,
1637 p_cur->applications[i].perso_substate,
1638 p_cur->applications[i].aid_ptr,
1639 p_cur->applications[i].app_label_ptr,
1640 p_cur->applications[i].pin1_replaced,
1641 p_cur->applications[i].pin1,
1642 p_cur->applications[i].pin2);
1649 static int responseBrSmsCnf(Parcel &p, void *response, size_t responselen) {
1652 if (response == NULL && responselen != 0) {
1653 LOGE("invalid response: NULL");
1654 return RIL_ERRNO_INVALID_RESPONSE;
1657 if (responselen % sizeof(RIL_BroadcastSMSConfig) != 0) {
1658 LOGE("invalid response length %d expected multiple of %d",
1659 (int)responselen, (int)sizeof(RIL_BroadcastSMSConfig));
1660 return RIL_ERRNO_INVALID_RESPONSE;
1663 /* number of call info's */
1664 num = responselen / sizeof(RIL_BroadcastSMSConfig *);
1667 RIL_BroadcastSMSConfig *p_cur = (RIL_BroadcastSMSConfig *) response;
1668 p.writeInt32(p_cur->size);
1669 p.writeInt32(p_cur->entries->uFromServiceID);
1670 p.writeInt32(p_cur->entries->uToserviceID);
1671 p.write(&(p_cur->entries->bSelected),sizeof(p_cur->entries->bSelected));
1674 appendPrintBuf("%s size=%d, entries.uFromServiceID=%d, \
1675 entries.uToserviceID=%d, entries.bSelected =%d, ",
1676 printBuf, p_cur->size,p_cur->entries->uFromServiceID,
1677 p_cur->entries->uToserviceID, p_cur->entries->bSelected);
1683 static int responseCdmaBrCnf(Parcel &p, void *response, size_t responselen) {
1684 int numServiceCategories;
1686 if (response == NULL && responselen != 0) {
1687 LOGE("invalid response: NULL");
1688 return RIL_ERRNO_INVALID_RESPONSE;
1691 if (responselen == 0) {
1692 LOGE("invalid response length %d expected >= of %d",
1693 (int)responselen, (int)sizeof(RIL_BroadcastSMSConfig));
1694 return RIL_ERRNO_INVALID_RESPONSE;
1697 RIL_CDMA_BroadcastSMSConfig *p_cur = (RIL_CDMA_BroadcastSMSConfig *) response;
1699 numServiceCategories = p_cur->size;
1700 p.writeInt32(p_cur->size);
1703 appendPrintBuf("%ssize=%d ", printBuf,p_cur->size);
1706 if (numServiceCategories != 0) {
1707 RIL_CDMA_BroadcastServiceInfo cdmaBsi[numServiceCategories];
1708 memcpy(cdmaBsi, p_cur->entries,
1709 sizeof(RIL_CDMA_BroadcastServiceInfo) * numServiceCategories);
1711 for (int i = 0 ; i < numServiceCategories ; i++ ) {
1712 p.writeInt32(cdmaBsi[i].uServiceCategory);
1713 p.writeInt32(cdmaBsi[i].uLanguage);
1714 p.writeInt32(cdmaBsi[i].bSelected);
1717 appendPrintBuf("%sentries[%d].uServicecategory=%d, entries[%d].uLanguage =%d, \
1718 entries[%d].bSelected =%d, ", printBuf, i, cdmaBsi[i].uServiceCategory, i,
1719 cdmaBsi[i].uLanguage, i, cdmaBsi[i].bSelected);
1729 static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
1736 LOGD("Inside responseCdmaSms");
1738 if (response == NULL && responselen != 0) {
1739 LOGE("invalid response: NULL");
1740 return RIL_ERRNO_INVALID_RESPONSE;
1743 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
1744 LOGE("invalid response length was %d expected %d",
1745 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
1746 return RIL_ERRNO_INVALID_RESPONSE;
1749 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
1750 p.writeInt32(p_cur->uTeleserviceID);
1751 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
1752 p.writeInt32(p_cur->uServicecategory);
1753 p.writeInt32(p_cur->sAddress.digit_mode);
1754 p.writeInt32(p_cur->sAddress.number_mode);
1755 p.writeInt32(p_cur->sAddress.number_type);
1756 p.writeInt32(p_cur->sAddress.number_plan);
1757 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
1758 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1759 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1760 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
1763 p.writeInt32(p_cur->sSubAddress.subaddressType);
1764 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
1765 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
1766 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1767 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1768 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
1771 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1772 p.writeInt32(p_cur->uBearerDataLen);
1773 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1774 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
1778 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1779 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
1780 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
1781 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
1788 * A write on the wakeup fd is done just to pop us out of select()
1789 * We empty the buffer here and then ril_event will reset the timers on the
1792 static void processWakeupCallback(int fd, short flags, void *param) {
1796 LOGV("processWakeupCallback");
1798 /* empty our wakeup socket out */
1800 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
1801 } while (ret > 0 || (ret < 0 && errno == EINTR));
1804 static void onCommandsSocketClosed() {
1808 /* mark pending requests as "cancelled" so we dont report responses */
1810 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
1813 p_cur = s_pendingRequests;
1815 for (p_cur = s_pendingRequests
1817 ; p_cur = p_cur->p_next
1819 p_cur->cancelled = 1;
1822 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
1826 static void processCommandsCallback(int fd, short flags, void *param) {
1832 assert(fd == s_fdCommand);
1834 p_rs = (RecordStream *)param;
1837 /* loop until EAGAIN/EINTR, end of stream, or other error */
1838 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
1840 if (ret == 0 && p_record == NULL) {
1843 } else if (ret < 0) {
1845 } else if (ret == 0) { /* && p_record != NULL */
1846 processCommandBuffer(p_record, recordlen);
1850 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
1851 /* fatal error or end-of-stream */
1853 LOGE("error on reading command socket errno:%d\n", errno);
1855 LOGW("EOS. Closing command socket.");
1861 ril_event_del(&s_commands_event);
1863 record_stream_free(p_rs);
1865 /* start listening for new connections again */
1866 rilEventAddWakeup(&s_listen_event);
1868 onCommandsSocketClosed();
1873 static void onNewCommandConnect() {
1874 // implicit radio state changed
1875 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
1878 // Send last NITZ time data, in case it was missed
1879 if (s_lastNITZTimeData != NULL) {
1880 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
1882 free(s_lastNITZTimeData);
1883 s_lastNITZTimeData = NULL;
1886 // Get version string
1887 if (s_callbacks.getVersion != NULL) {
1888 const char *version;
1889 version = s_callbacks.getVersion();
1890 LOGI("RIL Daemon version: %s\n", version);
1892 property_set(PROPERTY_RIL_IMPL, version);
1894 LOGI("RIL Daemon version: unavailable\n");
1895 property_set(PROPERTY_RIL_IMPL, "unavailable");
1900 static void listenCallback (int fd, short flags, void *param) {
1903 int is_phone_socket;
1906 struct sockaddr_un peeraddr;
1907 socklen_t socklen = sizeof (peeraddr);
1910 socklen_t szCreds = sizeof(creds);
1912 struct passwd *pwd = NULL;
1914 assert (s_fdCommand < 0);
1915 assert (fd == s_fdListen);
1917 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
1919 if (s_fdCommand < 0 ) {
1920 LOGE("Error on accept() errno:%d", errno);
1921 /* start listening for new connections again */
1922 rilEventAddWakeup(&s_listen_event);
1926 /* check the credential of the other side and only accept socket from
1930 is_phone_socket = 0;
1932 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
1934 if (err == 0 && szCreds > 0) {
1936 pwd = getpwuid(creds.uid);
1938 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
1939 is_phone_socket = 1;
1941 LOGE("RILD can't accept socket from process %s", pwd->pw_name);
1944 LOGE("Error on getpwuid() errno: %d", errno);
1947 LOGD("Error on getsockopt() errno: %d", errno);
1950 if ( !is_phone_socket ) {
1951 LOGE("RILD must accept socket from %s", PHONE_PROCESS);
1956 onCommandsSocketClosed();
1958 /* start listening for new connections again */
1959 rilEventAddWakeup(&s_listen_event);
1964 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
1967 LOGE ("Error setting O_NONBLOCK errno:%d", errno);
1970 LOGI("libril: new connection");
1972 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
1974 ril_event_set (&s_commands_event, s_fdCommand, 1,
1975 processCommandsCallback, p_rs);
1977 rilEventAddWakeup (&s_commands_event);
1979 onNewCommandConnect();
1982 static void freeDebugCallbackArgs(int number, char **args) {
1983 for (int i = 0; i < number; i++) {
1984 if (args[i] != NULL) {
1991 static void debugCallback (int fd, short flags, void *param) {
1992 int acceptFD, option;
1993 struct sockaddr_un peeraddr;
1994 socklen_t socklen = sizeof (peeraddr);
1996 unsigned int qxdm_data[6];
1997 const char *deactData[1] = {"1"};
2000 int hangupData[1] = {1};
2004 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
2007 LOGE ("error accepting on debug port: %d\n", errno);
2011 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
2012 LOGE ("error reading on socket: number of Args: \n");
2015 args = (char **) malloc(sizeof(char*) * number);
2017 for (int i = 0; i < number; i++) {
2019 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
2020 LOGE ("error reading on socket: Len of Args: \n");
2021 freeDebugCallbackArgs(i, args);
2025 args[i] = (char *) malloc((sizeof(char) * len) + 1);
2026 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
2027 != (int)sizeof(char) * len) {
2028 LOGE ("error reading on socket: Args[%d] \n", i);
2029 freeDebugCallbackArgs(i, args);
2032 char * buf = args[i];
2036 switch (atoi(args[0])) {
2038 LOGI ("Connection on debug port: issuing reset.");
2039 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
2042 LOGI ("Connection on debug port: issuing radio power off.");
2044 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2050 LOGI ("Debug port: issuing unsolicited network change.");
2051 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED,
2055 LOGI ("Debug port: QXDM log enable.");
2056 qxdm_data[0] = 65536;
2062 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2066 LOGI ("Debug port: QXDM log disable.");
2067 qxdm_data[0] = 65536;
2073 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2077 LOGI("Debug port: Radio On");
2079 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2081 // Set network selection automatic.
2082 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
2085 LOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
2086 actData[0] = args[1];
2087 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
2091 LOGI("Debug port: Deactivate Data Call");
2092 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
2096 LOGI("Debug port: Dial Call");
2098 dialData.address = args[1];
2099 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
2102 LOGI("Debug port: Answer Call");
2103 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
2106 LOGI("Debug port: End Call");
2107 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
2108 sizeof(hangupData));
2111 LOGE ("Invalid request");
2114 freeDebugCallbackArgs(number, args);
2119 static void userTimerCallback (int fd, short flags, void *param) {
2120 UserCallbackInfo *p_info;
2122 p_info = (UserCallbackInfo *)param;
2124 p_info->p_callback(p_info->userParam);
2127 // FIXME generalize this...there should be a cancel mechanism
2128 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
2129 s_last_wake_timeout_info = NULL;
2137 eventLoop(void *param) {
2143 pthread_mutex_lock(&s_startupMutex);
2146 pthread_cond_broadcast(&s_startupCond);
2148 pthread_mutex_unlock(&s_startupMutex);
2150 ret = pipe(filedes);
2153 LOGE("Error in pipe() errno:%d", errno);
2157 s_fdWakeupRead = filedes[0];
2158 s_fdWakeupWrite = filedes[1];
2160 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
2162 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
2163 processWakeupCallback, NULL);
2165 rilEventAddWakeup (&s_wakeupfd_event);
2167 // Only returns on error
2169 LOGE ("error in event_loop_base errno:%d", errno);
2175 RIL_startEventLoop(void) {
2177 pthread_attr_t attr;
2179 /* spin up eventLoop thread and wait for it to get started */
2181 pthread_mutex_lock(&s_startupMutex);
2183 pthread_attr_init (&attr);
2184 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
2185 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
2187 while (s_started == 0) {
2188 pthread_cond_wait(&s_startupCond, &s_startupMutex);
2191 pthread_mutex_unlock(&s_startupMutex);
2194 LOGE("Failed to create dispatch thread errno:%d", errno);
2199 // Used for testing purpose only.
2200 extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
2201 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
2205 RIL_register (const RIL_RadioFunctions *callbacks) {
2209 if (callbacks == NULL
2210 || ! (callbacks->version == RIL_VERSION || callbacks->version == 1)
2213 "RIL_register: RIL_RadioFunctions * null or invalid version"
2214 " (expected %d)", RIL_VERSION);
2218 if (s_registerCalled > 0) {
2219 LOGE("RIL_register has been called more than once. "
2220 "Subsequent call ignored");
2224 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
2226 s_registerCalled = 1;
2228 // Little self-check
2230 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
2231 assert(i == s_commands[i].requestNumber);
2234 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
2235 assert(i + RIL_UNSOL_RESPONSE_BASE
2236 == s_unsolResponses[i].requestNumber);
2239 // New rild impl calls RIL_startEventLoop() first
2240 // old standalone impl wants it here.
2242 if (s_started == 0) {
2243 RIL_startEventLoop();
2246 // start listen socket
2249 ret = socket_local_server (SOCKET_NAME_RIL,
2250 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
2253 LOGE("Unable to bind socket errno:%d", errno);
2259 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
2260 if (s_fdListen < 0) {
2261 LOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
2265 ret = listen(s_fdListen, 4);
2268 LOGE("Failed to listen on control socket '%d': %s",
2269 s_fdListen, strerror(errno));
2275 /* note: non-persistent so we can accept only one connection at a time */
2276 ril_event_set (&s_listen_event, s_fdListen, false,
2277 listenCallback, NULL);
2279 rilEventAddWakeup (&s_listen_event);
2282 // start debug interface socket
2284 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
2285 if (s_fdDebug < 0) {
2286 LOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
2290 ret = listen(s_fdDebug, 4);
2293 LOGE("Failed to listen on ril debug socket '%d': %s",
2294 s_fdDebug, strerror(errno));
2298 ril_event_set (&s_debug_event, s_fdDebug, true,
2299 debugCallback, NULL);
2301 rilEventAddWakeup (&s_debug_event);
2307 checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
2314 pthread_mutex_lock(&s_pendingRequestsMutex);
2316 for(RequestInfo **ppCur = &s_pendingRequests
2318 ; ppCur = &((*ppCur)->p_next)
2320 if (pRI == *ppCur) {
2323 *ppCur = (*ppCur)->p_next;
2328 pthread_mutex_unlock(&s_pendingRequestsMutex);
2335 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
2340 pRI = (RequestInfo *)t;
2342 if (!checkAndDequeueRequestInfo(pRI)) {
2343 LOGE ("RIL_onRequestComplete: invalid RIL_Token");
2347 if (pRI->local > 0) {
2348 // Locally issued command...void only!
2349 // response does not go back up the command socket
2350 LOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
2355 appendPrintBuf("[%04d]< %s",
2356 pRI->token, requestToString(pRI->pCI->requestNumber));
2358 if (pRI->cancelled == 0) {
2361 p.writeInt32 (RESPONSE_SOLICITED);
2362 p.writeInt32 (pRI->token);
2363 errorOffset = p.dataPosition();
2367 if (e == RIL_E_SUCCESS) {
2368 /* process response on success */
2369 ret = pRI->pCI->responseFunction(p, response, responselen);
2371 /* if an error occurred, rewind and mark it */
2373 p.setDataPosition(errorOffset);
2377 appendPrintBuf("%s returns %s", printBuf, failCauseToString(e));
2380 if (s_fdCommand < 0) {
2381 LOGD ("RIL onRequestComplete: Command channel closed");
2392 grabPartialWakeLock() {
2393 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
2398 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
2402 * Timer callback to put us back to sleep before the default timeout
2405 wakeTimeoutCallback (void *param) {
2406 // We're using "param != NULL" as a cancellation mechanism
2407 if (param == NULL) {
2408 //LOGD("wakeTimeout: releasing wake lock");
2412 //LOGD("wakeTimeout: releasing wake lock CANCELLED");
2417 void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
2420 int unsolResponseIndex;
2422 int64_t timeReceived = 0;
2423 bool shouldScheduleTimeout = false;
2425 if (s_registerCalled == 0) {
2426 // Ignore RIL_onUnsolicitedResponse before RIL_register
2427 LOGW("RIL_onUnsolicitedResponse called before RIL_register");
2431 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
2433 if ((unsolResponseIndex < 0)
2434 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
2435 LOGE("unsupported unsolicited response code %d", unsolResponse);
2439 // Grab a wake lock if needed for this reponse,
2440 // as we exit we'll either release it immediately
2441 // or set a timer to release it later.
2442 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
2444 grabPartialWakeLock();
2445 shouldScheduleTimeout = true;
2450 // No wake lock is grabed so don't set timeout
2451 shouldScheduleTimeout = false;
2455 // Mark the time this was received, doing this
2456 // after grabing the wakelock incase getting
2457 // the elapsedRealTime might cause us to goto
2459 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
2460 timeReceived = elapsedRealtime();
2463 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
2467 p.writeInt32 (RESPONSE_UNSOLICITED);
2468 p.writeInt32 (unsolResponse);
2470 ret = s_unsolResponses[unsolResponseIndex]
2471 .responseFunction(p, data, datalen);
2473 // Problem with the response. Don't continue;
2477 // some things get more payload
2478 switch(unsolResponse) {
2479 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
2480 p.writeInt32(s_callbacks.onStateRequest());
2481 appendPrintBuf("%s {%s}", printBuf,
2482 radioStateToString(s_callbacks.onStateRequest()));
2486 case RIL_UNSOL_NITZ_TIME_RECEIVED:
2487 // Store the time that this was received so the
2488 // handler of this message can account for
2489 // the time it takes to arrive and process. In
2490 // particular the system has been known to sleep
2491 // before this message can be processed.
2492 p.writeInt64(timeReceived);
2496 ret = sendResponse(p);
2497 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
2499 // Unfortunately, NITZ time is not poll/update like everything
2500 // else in the system. So, if the upstream client isn't connected,
2501 // keep a copy of the last NITZ response (with receive time noted
2502 // above) around so we can deliver it when it is connected
2504 if (s_lastNITZTimeData != NULL) {
2505 free (s_lastNITZTimeData);
2506 s_lastNITZTimeData = NULL;
2509 s_lastNITZTimeData = malloc(p.dataSize());
2510 s_lastNITZTimeDataSize = p.dataSize();
2511 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
2514 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
2515 // FIXME The java code should handshake here to release wake lock
2517 if (shouldScheduleTimeout) {
2518 // Cancel the previous request
2519 if (s_last_wake_timeout_info != NULL) {
2520 s_last_wake_timeout_info->userParam = (void *)1;
2523 s_last_wake_timeout_info
2524 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
2525 &TIMEVAL_WAKE_TIMEOUT);
2532 // There was an error and we've got the wake lock so release it.
2533 if (shouldScheduleTimeout) {
2538 /** FIXME generalize this if you track UserCAllbackInfo, clear it
2539 when the callback occurs
2541 static UserCallbackInfo *
2542 internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
2543 const struct timeval *relativeTime)
2545 struct timeval myRelativeTime;
2546 UserCallbackInfo *p_info;
2548 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
2550 p_info->p_callback = callback;
2551 p_info->userParam = param;
2553 if (relativeTime == NULL) {
2554 /* treat null parameter as a 0 relative time */
2555 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
2557 /* FIXME I think event_add's tv param is really const anyway */
2558 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
2561 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
2563 ril_timer_add(&(p_info->event), &myRelativeTime);
2571 RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
2572 const struct timeval *relativeTime) {
2573 internalRequestTimedCallback (callback, param, relativeTime);
2577 failCauseToString(RIL_Errno e) {
2579 case RIL_E_SUCCESS: return "E_SUCCESS";
2580 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RAIDO_NOT_AVAILABLE";
2581 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
2582 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
2583 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
2584 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
2585 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
2586 case RIL_E_CANCELLED: return "E_CANCELLED";
2587 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
2588 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
2589 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
2590 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
2591 #ifdef FEATURE_MULTIMODE_ANDROID
2592 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
2593 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
2595 default: return "<unknown error>";
2600 radioStateToString(RIL_RadioState s) {
2602 case RADIO_STATE_OFF: return "RADIO_OFF";
2603 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
2604 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
2605 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
2606 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
2607 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
2608 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
2609 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
2610 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
2611 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
2612 default: return "<unknown state>";
2617 callStateToString(RIL_CallState s) {
2619 case RIL_CALL_ACTIVE : return "ACTIVE";
2620 case RIL_CALL_HOLDING: return "HOLDING";
2621 case RIL_CALL_DIALING: return "DIALING";
2622 case RIL_CALL_ALERTING: return "ALERTING";
2623 case RIL_CALL_INCOMING: return "INCOMING";
2624 case RIL_CALL_WAITING: return "WAITING";
2625 default: return "<unknown state>";
2630 requestToString(int request) {
2632 cat libs/telephony/ril_commands.h \
2633 | egrep "^ *{RIL_" \
2634 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
2637 cat libs/telephony/ril_unsol_commands.h \
2638 | egrep "^ *{RIL_" \
2639 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
2643 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
2644 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
2645 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
2646 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
2647 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
2648 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
2649 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
2650 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
2651 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
2652 case RIL_REQUEST_DIAL: return "DIAL";
2653 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
2654 case RIL_REQUEST_HANGUP: return "HANGUP";
2655 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
2656 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
2657 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
2658 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
2659 case RIL_REQUEST_UDUB: return "UDUB";
2660 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
2661 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
2662 case RIL_REQUEST_REGISTRATION_STATE: return "REGISTRATION_STATE";
2663 case RIL_REQUEST_GPRS_REGISTRATION_STATE: return "GPRS_REGISTRATION_STATE";
2664 case RIL_REQUEST_OPERATOR: return "OPERATOR";
2665 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
2666 case RIL_REQUEST_DTMF: return "DTMF";
2667 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
2668 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
2669 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
2670 case RIL_REQUEST_SIM_IO: return "SIM_IO";
2671 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
2672 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
2673 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
2674 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
2675 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
2676 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
2677 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
2678 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
2679 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
2680 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
2681 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
2682 case RIL_REQUEST_ANSWER: return "ANSWER";
2683 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
2684 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
2685 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
2686 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
2687 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
2688 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
2689 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
2690 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
2691 case RIL_REQUEST_DTMF_START: return "DTMF_START";
2692 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
2693 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
2694 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
2695 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
2696 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
2697 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
2698 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
2699 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
2700 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
2701 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
2702 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
2703 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
2704 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
2705 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
2706 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
2707 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
2708 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
2709 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
2710 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
2711 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
2712 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
2713 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
2714 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
2715 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
2716 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION:return"CDMA_SET_SUBSCRIPTION";
2717 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
2718 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
2719 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
2720 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
2721 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
2722 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
2723 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
2724 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
2725 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
2726 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
2727 case RIL_REQUEST_GET_BROADCAST_CONFIG:return"GET_BROADCAST_CONFIG";
2728 case RIL_REQUEST_SET_BROADCAST_CONFIG:return"SET_BROADCAST_CONFIG";
2729 case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG:return "CDMA_GET_BROADCAST_CONFIG";
2730 case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG:return "SET_CDMA_BROADCAST_CONFIG";
2731 case RIL_REQUEST_BROADCAST_ACTIVATION:return "BROADCAST_ACTIVATION";
2732 case RIL_REQUEST_CDMA_VALIDATE_AKEY: return"CDMA_VALIDATE_AKEY";
2733 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
2734 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
2735 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
2736 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
2737 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
2738 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
2739 case RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_NETWORK_STATE_CHANGED";
2740 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
2741 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
2742 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
2743 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
2744 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
2745 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
2746 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
2747 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
2748 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
2749 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
2750 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
2751 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
2752 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
2753 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
2754 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
2755 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
2756 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
2757 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
2758 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
2759 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
2760 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
2761 default: return "<unknown request>";
2765 } /* namespace android */