1 /* //device/libs/telephony/ril.cpp
3 ** Copyright 2006, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
18 #define LOG_TAG "RILC"
20 #include <hardware_legacy/power.h>
22 #include <telephony/ril.h>
23 #include <telephony/ril_cdma_sms.h>
24 #include <cutils/sockets.h>
25 #include <cutils/jstring.h>
26 #include <cutils/record_stream.h>
27 #include <utils/Log.h>
28 #include <utils/SystemClock.h>
30 #include <binder/Parcel.h>
31 #include <cutils/jstring.h>
33 #include <sys/types.h>
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 ALOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
97 #define startResponse sprintf(printBuf, "%s {", printBuf)
98 #define closeResponse sprintf(printBuf, "%s}", printBuf)
99 #define printResponse ALOGD("%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);
204 static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
205 static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
206 static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
208 static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
209 static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
210 static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
211 static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
212 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
213 static int responseInts(Parcel &p, void *response, size_t responselen);
214 static int responseStrings(Parcel &p, void *response, size_t responselen);
215 static int responseString(Parcel &p, void *response, size_t responselen);
216 static int responseVoid(Parcel &p, void *response, size_t responselen);
217 static int responseCallList(Parcel &p, void *response, size_t responselen);
218 static int responseSMS(Parcel &p, void *response, size_t responselen);
219 static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
220 static int responseCallForwards(Parcel &p, void *response, size_t responselen);
221 static int responseDataCallList(Parcel &p, void *response, size_t responselen);
222 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
223 static int responseRaw(Parcel &p, void *response, size_t responselen);
224 static int responseSsn(Parcel &p, void *response, size_t responselen);
225 static int responseSimStatus(Parcel &p, void *response, size_t responselen);
226 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
227 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
228 static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
229 static int responseCellList(Parcel &p, void *response, size_t responselen);
230 static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
231 static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
232 static int responseCallRing(Parcel &p, void *response, size_t responselen);
233 static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
234 static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
235 static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
237 static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
238 static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
239 static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
241 extern "C" const char * requestToString(int request);
242 extern "C" const char * failCauseToString(RIL_Errno);
243 extern "C" const char * callStateToString(RIL_CallState);
244 extern "C" const char * radioStateToString(RIL_RadioState);
247 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
251 static UserCallbackInfo * internalRequestTimedCallback
252 (RIL_TimedCallback callback, void *param,
253 const struct timeval *relativeTime);
255 /** Index == requestNumber */
256 static CommandInfo s_commands[] = {
257 #include "ril_commands.h"
260 static UnsolResponseInfo s_unsolResponses[] = {
261 #include "ril_unsol_commands.h"
264 /* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
265 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
266 radio state message and store it. Every time there is a change in Radio State
267 check to see if voice radio tech changes and notify telephony
269 int voiceRadioTech = -1;
271 /* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
272 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
273 source from radio state and store it. Every time there is a change in Radio State
274 check to see if subscription source changed and notify telephony
276 int cdmaSubscriptionSource = -1;
278 /* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
279 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
280 check to see if SIM/RUIM status changed and notify telephony
282 int simRuimStatus = -1;
285 strdupReadString(Parcel &p) {
289 s16 = p.readString16Inplace(&stringlen);
291 return strndup16to8(s16, stringlen);
294 static void writeStringToParcel(Parcel &p, const char *s) {
297 s16 = strdup8to16(s, &s16_len);
298 p.writeString16(s16, s16_len);
304 memsetString (char *s) {
306 memset (s, 0, strlen(s));
310 void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
311 const size_t* objects, size_t objectsSize,
313 // do nothing -- the data reference lives longer than the Parcel object
317 * To be called from dispatch thread
318 * Issue a single local request, ensuring that the response
319 * is not sent back up to the command process
322 issueLocalRequest(int request, void *data, int len) {
326 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
329 pRI->token = 0xffffffff; // token is not used in this context
330 pRI->pCI = &(s_commands[request]);
332 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
335 pRI->p_next = s_pendingRequests;
336 s_pendingRequests = pRI;
338 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
341 ALOGD("C[locl]> %s", requestToString(request));
343 s_callbacks.onRequest(request, data, len, pRI);
349 processCommandBuffer(void *buffer, size_t buflen) {
357 p.setData((uint8_t *) buffer, buflen);
359 // status checked at end
360 status = p.readInt32(&request);
361 status = p.readInt32 (&token);
363 if (status != NO_ERROR) {
364 ALOGE("invalid request block");
368 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
369 ALOGE("unsupported request code %d token %d", request, token);
370 // FIXME this should perhaps return a response
375 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
378 pRI->pCI = &(s_commands[request]);
380 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
383 pRI->p_next = s_pendingRequests;
384 s_pendingRequests = pRI;
386 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
389 /* sLastDispatchedToken = token; */
391 pRI->pCI->dispatchFunction(p, pRI);
397 invalidCommandBlock (RequestInfo *pRI) {
398 ALOGE("invalid command block for token %d request %s",
399 pRI->token, requestToString(pRI->pCI->requestNumber));
402 /** Callee expects NULL */
404 dispatchVoid (Parcel& p, RequestInfo *pRI) {
406 printRequest(pRI->token, pRI->pCI->requestNumber);
407 s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
410 /** Callee expects const char * */
412 dispatchString (Parcel& p, RequestInfo *pRI) {
416 char *string8 = NULL;
418 string8 = strdupReadString(p);
421 appendPrintBuf("%s%s", printBuf, string8);
423 printRequest(pRI->token, pRI->pCI->requestNumber);
425 s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
426 sizeof(char *), pRI);
429 memsetString(string8);
435 invalidCommandBlock(pRI);
439 /** Callee expects const char ** */
441 dispatchStrings (Parcel &p, RequestInfo *pRI) {
442 int32_t countStrings;
447 status = p.readInt32 (&countStrings);
449 if (status != NO_ERROR) {
454 if (countStrings == 0) {
455 // just some non-null pointer
456 pStrings = (char **)alloca(sizeof(char *));
458 } else if (((int)countStrings) == -1) {
462 datalen = sizeof(char *) * countStrings;
464 pStrings = (char **)alloca(datalen);
466 for (int i = 0 ; i < countStrings ; i++) {
467 pStrings[i] = strdupReadString(p);
468 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
473 printRequest(pRI->token, pRI->pCI->requestNumber);
475 s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
477 if (pStrings != NULL) {
478 for (int i = 0 ; i < countStrings ; i++) {
480 memsetString (pStrings[i]);
486 memset(pStrings, 0, datalen);
492 invalidCommandBlock(pRI);
496 /** Callee expects const int * */
498 dispatchInts (Parcel &p, RequestInfo *pRI) {
504 status = p.readInt32 (&count);
506 if (status != NO_ERROR || count == 0) {
510 datalen = sizeof(int) * count;
511 pInts = (int *)alloca(datalen);
514 for (int i = 0 ; i < count ; i++) {
517 status = p.readInt32(&t);
519 appendPrintBuf("%s%d,", printBuf, t);
521 if (status != NO_ERROR) {
527 printRequest(pRI->token, pRI->pCI->requestNumber);
529 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts),
533 memset(pInts, 0, datalen);
538 invalidCommandBlock(pRI);
544 * Callee expects const RIL_SMS_WriteArgs *
550 dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
551 RIL_SMS_WriteArgs args;
555 memset (&args, 0, sizeof(args));
557 status = p.readInt32(&t);
558 args.status = (int)t;
560 args.pdu = strdupReadString(p);
562 if (status != NO_ERROR || args.pdu == NULL) {
566 args.smsc = strdupReadString(p);
569 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
570 (char*)args.pdu, (char*)args.smsc);
572 printRequest(pRI->token, pRI->pCI->requestNumber);
574 s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
577 memsetString (args.pdu);
583 memset(&args, 0, sizeof(args));
588 invalidCommandBlock(pRI);
593 * Callee expects const RIL_Dial *
599 dispatchDial (Parcel &p, RequestInfo *pRI) {
601 RIL_UUS_Info uusInfo;
607 memset (&dial, 0, sizeof(dial));
609 dial.address = strdupReadString(p);
611 status = p.readInt32(&t);
614 if (status != NO_ERROR || dial.address == NULL) {
618 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
620 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
622 status = p.readInt32(&uusPresent);
624 if (status != NO_ERROR) {
628 if (uusPresent == 0) {
633 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
635 status = p.readInt32(&t);
636 uusInfo.uusType = (RIL_UUS_Type) t;
638 status = p.readInt32(&t);
639 uusInfo.uusDcs = (RIL_UUS_DCS) t;
641 status = p.readInt32(&len);
642 if (status != NO_ERROR) {
646 // The java code writes -1 for null arrays
647 if (((int) len) == -1) {
648 uusInfo.uusData = NULL;
651 uusInfo.uusData = (char*) p.readInplace(len);
654 uusInfo.uusLength = len;
655 dial.uusInfo = &uusInfo;
657 sizeOfDial = sizeof(dial);
661 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
663 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
664 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
665 dial.uusInfo->uusLength);
668 printRequest(pRI->token, pRI->pCI->requestNumber);
670 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI);
673 memsetString (dial.address);
679 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
680 memset(&dial, 0, sizeof(dial));
685 invalidCommandBlock(pRI);
690 * Callee expects const RIL_SIM_IO *
701 dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
711 memset (&simIO, 0, sizeof(simIO));
713 // note we only check status at the end
715 status = p.readInt32(&t);
716 simIO.v6.command = (int)t;
718 status = p.readInt32(&t);
719 simIO.v6.fileid = (int)t;
721 simIO.v6.path = strdupReadString(p);
723 status = p.readInt32(&t);
724 simIO.v6.p1 = (int)t;
726 status = p.readInt32(&t);
727 simIO.v6.p2 = (int)t;
729 status = p.readInt32(&t);
730 simIO.v6.p3 = (int)t;
732 simIO.v6.data = strdupReadString(p);
733 simIO.v6.pin2 = strdupReadString(p);
734 simIO.v6.aidPtr = strdupReadString(p);
737 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
738 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
739 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
740 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
742 printRequest(pRI->token, pRI->pCI->requestNumber);
744 if (status != NO_ERROR) {
748 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
749 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, size, pRI);
752 memsetString (simIO.v6.path);
753 memsetString (simIO.v6.data);
754 memsetString (simIO.v6.pin2);
755 memsetString (simIO.v6.aidPtr);
758 free (simIO.v6.path);
759 free (simIO.v6.data);
760 free (simIO.v6.pin2);
761 free (simIO.v6.aidPtr);
764 memset(&simIO, 0, sizeof(simIO));
769 invalidCommandBlock(pRI);
774 * Callee expects const RIL_CallForwardInfo *
776 * int32_t status/action
778 * int32_t serviceCode
780 * String number (0 length -> null)
781 * int32_t timeSeconds
784 dispatchCallForward(Parcel &p, RequestInfo *pRI) {
785 RIL_CallForwardInfo cff;
789 memset (&cff, 0, sizeof(cff));
791 // note we only check status at the end
793 status = p.readInt32(&t);
796 status = p.readInt32(&t);
799 status = p.readInt32(&t);
800 cff.serviceClass = (int)t;
802 status = p.readInt32(&t);
805 cff.number = strdupReadString(p);
807 status = p.readInt32(&t);
808 cff.timeSeconds = (int)t;
810 if (status != NO_ERROR) {
814 // special case: number 0-length fields is null
816 if (cff.number != NULL && strlen (cff.number) == 0) {
821 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
822 cff.status, cff.reason, cff.serviceClass, cff.toa,
823 (char*)cff.number, cff.timeSeconds);
825 printRequest(pRI->token, pRI->pCI->requestNumber);
827 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
830 memsetString(cff.number);
836 memset(&cff, 0, sizeof(cff));
841 invalidCommandBlock(pRI);
847 dispatchRaw(Parcel &p, RequestInfo *pRI) {
852 status = p.readInt32(&len);
854 if (status != NO_ERROR) {
858 // The java code writes -1 for null arrays
859 if (((int)len) == -1) {
864 data = p.readInplace(len);
867 appendPrintBuf("%sraw_size=%d", printBuf, len);
869 printRequest(pRI->token, pRI->pCI->requestNumber);
871 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
875 invalidCommandBlock(pRI);
880 dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
881 RIL_CDMA_SMS_Message rcsm;
888 memset(&rcsm, 0, sizeof(rcsm));
890 status = p.readInt32(&t);
891 rcsm.uTeleserviceID = (int) t;
893 status = p.read(&ut,sizeof(ut));
894 rcsm.bIsServicePresent = (uint8_t) ut;
896 status = p.readInt32(&t);
897 rcsm.uServicecategory = (int) t;
899 status = p.readInt32(&t);
900 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
902 status = p.readInt32(&t);
903 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
905 status = p.readInt32(&t);
906 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
908 status = p.readInt32(&t);
909 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
911 status = p.read(&ut,sizeof(ut));
912 rcsm.sAddress.number_of_digits= (uint8_t) ut;
914 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
915 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
916 status = p.read(&ut,sizeof(ut));
917 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
920 status = p.readInt32(&t);
921 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
923 status = p.read(&ut,sizeof(ut));
924 rcsm.sSubAddress.odd = (uint8_t) ut;
926 status = p.read(&ut,sizeof(ut));
927 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
929 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
930 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
931 status = p.read(&ut,sizeof(ut));
932 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
935 status = p.readInt32(&t);
936 rcsm.uBearerDataLen = (int) t;
938 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
939 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
940 status = p.read(&ut, sizeof(ut));
941 rcsm.aBearerData[digitCount] = (uint8_t) ut;
944 if (status != NO_ERROR) {
949 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
950 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
951 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
952 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
955 printRequest(pRI->token, pRI->pCI->requestNumber);
957 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
960 memset(&rcsm, 0, sizeof(rcsm));
966 invalidCommandBlock(pRI);
971 dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
972 RIL_CDMA_SMS_Ack rcsa;
977 memset(&rcsa, 0, sizeof(rcsa));
979 status = p.readInt32(&t);
980 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
982 status = p.readInt32(&t);
983 rcsa.uSMSCauseCode = (int) t;
985 if (status != NO_ERROR) {
990 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
991 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
994 printRequest(pRI->token, pRI->pCI->requestNumber);
996 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI);
999 memset(&rcsa, 0, sizeof(rcsa));
1005 invalidCommandBlock(pRI);
1010 dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1015 status = p.readInt32(&num);
1016 if (status != NO_ERROR) {
1020 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1021 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
1024 for (int i = 0 ; i < num ; i++ ) {
1025 gsmBciPtrs[i] = &gsmBci[i];
1027 status = p.readInt32(&t);
1028 gsmBci[i].fromServiceId = (int) t;
1030 status = p.readInt32(&t);
1031 gsmBci[i].toServiceId = (int) t;
1033 status = p.readInt32(&t);
1034 gsmBci[i].fromCodeScheme = (int) t;
1036 status = p.readInt32(&t);
1037 gsmBci[i].toCodeScheme = (int) t;
1039 status = p.readInt32(&t);
1040 gsmBci[i].selected = (uint8_t) t;
1042 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1043 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1044 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1045 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1046 gsmBci[i].selected);
1050 if (status != NO_ERROR) {
1054 s_callbacks.onRequest(pRI->pCI->requestNumber,
1056 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1060 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1061 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
1067 invalidCommandBlock(pRI);
1072 dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1077 status = p.readInt32(&num);
1078 if (status != NO_ERROR) {
1082 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1083 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
1086 for (int i = 0 ; i < num ; i++ ) {
1087 cdmaBciPtrs[i] = &cdmaBci[i];
1089 status = p.readInt32(&t);
1090 cdmaBci[i].service_category = (int) t;
1092 status = p.readInt32(&t);
1093 cdmaBci[i].language = (int) t;
1095 status = p.readInt32(&t);
1096 cdmaBci[i].selected = (uint8_t) t;
1098 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1099 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1100 cdmaBci[i].language, cdmaBci[i].selected);
1104 if (status != NO_ERROR) {
1108 s_callbacks.onRequest(pRI->pCI->requestNumber,
1110 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1114 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1115 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
1121 invalidCommandBlock(pRI);
1125 static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1126 RIL_CDMA_SMS_WriteArgs rcsw;
1133 memset(&rcsw, 0, sizeof(rcsw));
1135 status = p.readInt32(&t);
1138 status = p.readInt32(&t);
1139 rcsw.message.uTeleserviceID = (int) t;
1141 status = p.read(&uct,sizeof(uct));
1142 rcsw.message.bIsServicePresent = (uint8_t) uct;
1144 status = p.readInt32(&t);
1145 rcsw.message.uServicecategory = (int) t;
1147 status = p.readInt32(&t);
1148 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1150 status = p.readInt32(&t);
1151 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1153 status = p.readInt32(&t);
1154 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1156 status = p.readInt32(&t);
1157 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1159 status = p.read(&uct,sizeof(uct));
1160 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1162 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1163 status = p.read(&uct,sizeof(uct));
1164 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1167 status = p.readInt32(&t);
1168 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1170 status = p.read(&uct,sizeof(uct));
1171 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1173 status = p.read(&uct,sizeof(uct));
1174 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1176 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1177 status = p.read(&uct,sizeof(uct));
1178 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1181 status = p.readInt32(&t);
1182 rcsw.message.uBearerDataLen = (int) t;
1184 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1185 status = p.read(&uct, sizeof(uct));
1186 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1189 if (status != NO_ERROR) {
1194 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1195 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1196 message.sAddress.number_mode=%d, \
1197 message.sAddress.number_type=%d, ",
1198 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1199 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1200 rcsw.message.sAddress.number_mode,
1201 rcsw.message.sAddress.number_type);
1204 printRequest(pRI->token, pRI->pCI->requestNumber);
1206 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI);
1209 memset(&rcsw, 0, sizeof(rcsw));
1215 invalidCommandBlock(pRI);
1220 // For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1221 // Version 4 of the RIL interface adds a new PDP type parameter to support
1222 // IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1223 // RIL, remove the parameter from the request.
1224 static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1225 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1226 const int numParamsRilV3 = 6;
1228 // The first bytes of the RIL parcel contain the request number and the
1229 // serial number - see processCommandBuffer(). Copy them over too.
1230 int pos = p.dataPosition();
1232 int numParams = p.readInt32();
1233 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1235 p2.appendFrom(&p, 0, pos);
1236 p2.writeInt32(numParamsRilV3);
1237 for(int i = 0; i < numParamsRilV3; i++) {
1238 p2.writeString16(p.readString16());
1240 p2.setDataPosition(pos);
1241 dispatchStrings(p2, pRI);
1243 p.setDataPosition(pos);
1244 dispatchStrings(p, pRI);
1248 // For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1249 // When all RILs handle this request, this function can be removed and
1250 // the request can be sent directly to the RIL using dispatchVoid.
1251 static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
1252 RIL_RadioState state = s_callbacks.onStateRequest();
1254 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1255 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1258 // RILs that support RADIO_STATE_ON should support this request.
1259 if (RADIO_STATE_ON == state) {
1260 dispatchVoid(p, pRI);
1264 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1265 // will not support this new request either and decode Voice Radio Technology
1267 voiceRadioTech = decodeVoiceRadioTechnology(state);
1269 if (voiceRadioTech < 0)
1270 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1272 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1275 // For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1276 // When all RILs handle this request, this function can be removed and
1277 // the request can be sent directly to the RIL using dispatchVoid.
1278 static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
1279 RIL_RadioState state = s_callbacks.onStateRequest();
1281 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1282 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1285 // RILs that support RADIO_STATE_ON should support this request.
1286 if (RADIO_STATE_ON == state) {
1287 dispatchVoid(p, pRI);
1291 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1292 // will not support this new request either and decode CDMA Subscription Source
1294 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1296 if (cdmaSubscriptionSource < 0)
1297 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1299 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1303 blockingWrite(int fd, const void *buffer, size_t len) {
1304 size_t writeOffset = 0;
1305 const uint8_t *toWrite;
1307 toWrite = (const uint8_t *)buffer;
1309 while (writeOffset < len) {
1312 written = write (fd, toWrite + writeOffset,
1314 } while (written < 0 && errno == EINTR);
1317 writeOffset += written;
1318 } else { // written < 0
1319 ALOGE ("RIL Response: unexpected error on write errno:%d", errno);
1329 sendResponseRaw (const void *data, size_t dataSize) {
1330 int fd = s_fdCommand;
1334 if (s_fdCommand < 0) {
1338 if (dataSize > MAX_COMMAND_BYTES) {
1339 ALOGE("RIL: packet larger than %u (%u)",
1340 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1345 pthread_mutex_lock(&s_writeMutex);
1347 header = htonl(dataSize);
1349 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1352 pthread_mutex_unlock(&s_writeMutex);
1356 ret = blockingWrite(fd, data, dataSize);
1359 pthread_mutex_unlock(&s_writeMutex);
1363 pthread_mutex_unlock(&s_writeMutex);
1369 sendResponse (Parcel &p) {
1371 return sendResponseRaw(p.data(), p.dataSize());
1374 /** response is an int* pointing to an array of ints*/
1377 responseInts(Parcel &p, void *response, size_t responselen) {
1380 if (response == NULL && responselen != 0) {
1381 ALOGE("invalid response: NULL");
1382 return RIL_ERRNO_INVALID_RESPONSE;
1384 if (responselen % sizeof(int) != 0) {
1385 ALOGE("invalid response length %d expected multiple of %d\n",
1386 (int)responselen, (int)sizeof(int));
1387 return RIL_ERRNO_INVALID_RESPONSE;
1390 int *p_int = (int *) response;
1392 numInts = responselen / sizeof(int *);
1393 p.writeInt32 (numInts);
1397 for (int i = 0 ; i < numInts ; i++) {
1398 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1399 p.writeInt32(p_int[i]);
1407 /** response is a char **, pointing to an array of char *'s
1408 The parcel will begin with the version */
1409 static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1410 p.writeInt32(version);
1411 return responseStrings(p, response, responselen);
1414 /** response is a char **, pointing to an array of char *'s */
1415 static int responseStrings(Parcel &p, void *response, size_t responselen) {
1418 if (response == NULL && responselen != 0) {
1419 ALOGE("invalid response: NULL");
1420 return RIL_ERRNO_INVALID_RESPONSE;
1422 if (responselen % sizeof(char *) != 0) {
1423 ALOGE("invalid response length %d expected multiple of %d\n",
1424 (int)responselen, (int)sizeof(char *));
1425 return RIL_ERRNO_INVALID_RESPONSE;
1428 if (response == NULL) {
1431 char **p_cur = (char **) response;
1433 numStrings = responselen / sizeof(char *);
1434 p.writeInt32 (numStrings);
1438 for (int i = 0 ; i < numStrings ; i++) {
1439 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1440 writeStringToParcel (p, p_cur[i]);
1450 * NULL strings are accepted
1451 * FIXME currently ignores responselen
1453 static int responseString(Parcel &p, void *response, size_t responselen) {
1454 /* one string only */
1456 appendPrintBuf("%s%s", printBuf, (char*)response);
1459 writeStringToParcel(p, (const char *)response);
1464 static int responseVoid(Parcel &p, void *response, size_t responselen) {
1470 static int responseCallList(Parcel &p, void *response, size_t responselen) {
1473 if (response == NULL && responselen != 0) {
1474 ALOGE("invalid response: NULL");
1475 return RIL_ERRNO_INVALID_RESPONSE;
1478 if (responselen % sizeof (RIL_Call *) != 0) {
1479 ALOGE("invalid response length %d expected multiple of %d\n",
1480 (int)responselen, (int)sizeof (RIL_Call *));
1481 return RIL_ERRNO_INVALID_RESPONSE;
1485 /* number of call info's */
1486 num = responselen / sizeof(RIL_Call *);
1489 for (int i = 0 ; i < num ; i++) {
1490 RIL_Call *p_cur = ((RIL_Call **) response)[i];
1491 /* each call info */
1492 p.writeInt32(p_cur->state);
1493 p.writeInt32(p_cur->index);
1494 p.writeInt32(p_cur->toa);
1495 p.writeInt32(p_cur->isMpty);
1496 p.writeInt32(p_cur->isMT);
1497 p.writeInt32(p_cur->als);
1498 p.writeInt32(p_cur->isVoice);
1499 p.writeInt32(p_cur->isVoicePrivacy);
1500 writeStringToParcel(p, p_cur->number);
1501 p.writeInt32(p_cur->numberPresentation);
1502 writeStringToParcel(p, p_cur->name);
1503 p.writeInt32(p_cur->namePresentation);
1504 // Remove when partners upgrade to version 3
1505 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
1506 p.writeInt32(0); /* UUS Information is absent */
1508 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
1509 p.writeInt32(1); /* UUS Information is present */
1510 p.writeInt32(uusInfo->uusType);
1511 p.writeInt32(uusInfo->uusDcs);
1512 p.writeInt32(uusInfo->uusLength);
1513 p.write(uusInfo->uusData, uusInfo->uusLength);
1515 appendPrintBuf("%s[id=%d,%s,toa=%d,",
1518 callStateToString(p_cur->state),
1520 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
1522 (p_cur->isMpty)?"conf":"norm",
1523 (p_cur->isMT)?"mt":"mo",
1525 (p_cur->isVoice)?"voc":"nonvoc",
1526 (p_cur->isVoicePrivacy)?"evp":"noevp");
1527 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
1530 p_cur->numberPresentation,
1532 p_cur->namePresentation);
1540 static int responseSMS(Parcel &p, void *response, size_t responselen) {
1541 if (response == NULL) {
1542 ALOGE("invalid response: NULL");
1543 return RIL_ERRNO_INVALID_RESPONSE;
1546 if (responselen != sizeof (RIL_SMS_Response) ) {
1547 ALOGE("invalid response length %d expected %d",
1548 (int)responselen, (int)sizeof (RIL_SMS_Response));
1549 return RIL_ERRNO_INVALID_RESPONSE;
1552 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1554 p.writeInt32(p_cur->messageRef);
1555 writeStringToParcel(p, p_cur->ackPDU);
1556 p.writeInt32(p_cur->errorCode);
1559 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
1560 (char*)p_cur->ackPDU, p_cur->errorCode);
1566 static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
1568 if (response == NULL && responselen != 0) {
1569 ALOGE("invalid response: NULL");
1570 return RIL_ERRNO_INVALID_RESPONSE;
1573 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
1574 ALOGE("invalid response length %d expected multiple of %d",
1575 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
1576 return RIL_ERRNO_INVALID_RESPONSE;
1579 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
1582 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
1585 for (i = 0; i < num; i++) {
1586 p.writeInt32(p_cur[i].cid);
1587 p.writeInt32(p_cur[i].active);
1588 writeStringToParcel(p, p_cur[i].type);
1589 // apn is not used, so don't send.
1590 writeStringToParcel(p, p_cur[i].address);
1591 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
1593 (p_cur[i].active==0)?"down":"up",
1594 (char*)p_cur[i].type,
1595 (char*)p_cur[i].address);
1603 static int responseDataCallList(Parcel &p, void *response, size_t responselen)
1606 p.writeInt32(s_callbacks.version);
1608 if (s_callbacks.version < 5) {
1609 return responseDataCallListV4(p, response, responselen);
1611 if (response == NULL && responselen != 0) {
1612 ALOGE("invalid response: NULL");
1613 return RIL_ERRNO_INVALID_RESPONSE;
1616 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
1617 ALOGE("invalid response length %d expected multiple of %d",
1618 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
1619 return RIL_ERRNO_INVALID_RESPONSE;
1622 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
1625 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
1628 for (i = 0; i < num; i++) {
1629 p.writeInt32((int)p_cur[i].status);
1630 p.writeInt32(p_cur[i].suggestedRetryTime);
1631 p.writeInt32(p_cur[i].cid);
1632 p.writeInt32(p_cur[i].active);
1633 writeStringToParcel(p, p_cur[i].type);
1634 writeStringToParcel(p, p_cur[i].ifname);
1635 writeStringToParcel(p, p_cur[i].addresses);
1636 writeStringToParcel(p, p_cur[i].dnses);
1637 writeStringToParcel(p, p_cur[i].gateways);
1638 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%d,%s,%s,%s],", printBuf,
1640 p_cur[i].suggestedRetryTime,
1642 (p_cur[i].active==0)?"down":"up",
1643 (char*)p_cur[i].ifname,
1644 (char*)p_cur[i].addresses,
1645 (char*)p_cur[i].dnses,
1646 (char*)p_cur[i].gateways);
1655 static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
1657 if (s_callbacks.version < 5) {
1658 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
1660 return responseDataCallList(p, response, responselen);
1664 static int responseRaw(Parcel &p, void *response, size_t responselen) {
1665 if (response == NULL && responselen != 0) {
1666 ALOGE("invalid response: NULL with responselen != 0");
1667 return RIL_ERRNO_INVALID_RESPONSE;
1670 // The java code reads -1 size as null byte array
1671 if (response == NULL) {
1674 p.writeInt32(responselen);
1675 p.write(response, responselen);
1682 static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
1683 if (response == NULL) {
1684 ALOGE("invalid response: NULL");
1685 return RIL_ERRNO_INVALID_RESPONSE;
1688 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
1689 ALOGE("invalid response length was %d expected %d",
1690 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
1691 return RIL_ERRNO_INVALID_RESPONSE;
1694 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
1695 p.writeInt32(p_cur->sw1);
1696 p.writeInt32(p_cur->sw2);
1697 writeStringToParcel(p, p_cur->simResponse);
1700 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
1701 (char*)p_cur->simResponse);
1708 static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
1711 if (response == NULL && responselen != 0) {
1712 ALOGE("invalid response: NULL");
1713 return RIL_ERRNO_INVALID_RESPONSE;
1716 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
1717 ALOGE("invalid response length %d expected multiple of %d",
1718 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
1719 return RIL_ERRNO_INVALID_RESPONSE;
1722 /* number of call info's */
1723 num = responselen / sizeof(RIL_CallForwardInfo *);
1727 for (int i = 0 ; i < num ; i++) {
1728 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
1730 p.writeInt32(p_cur->status);
1731 p.writeInt32(p_cur->reason);
1732 p.writeInt32(p_cur->serviceClass);
1733 p.writeInt32(p_cur->toa);
1734 writeStringToParcel(p, p_cur->number);
1735 p.writeInt32(p_cur->timeSeconds);
1736 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
1737 (p_cur->status==1)?"enable":"disable",
1738 p_cur->reason, p_cur->serviceClass, p_cur->toa,
1739 (char*)p_cur->number,
1740 p_cur->timeSeconds);
1748 static int responseSsn(Parcel &p, void *response, size_t responselen) {
1749 if (response == NULL) {
1750 ALOGE("invalid response: NULL");
1751 return RIL_ERRNO_INVALID_RESPONSE;
1754 if (responselen != sizeof(RIL_SuppSvcNotification)) {
1755 ALOGE("invalid response length was %d expected %d",
1756 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
1757 return RIL_ERRNO_INVALID_RESPONSE;
1760 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
1761 p.writeInt32(p_cur->notificationType);
1762 p.writeInt32(p_cur->code);
1763 p.writeInt32(p_cur->index);
1764 p.writeInt32(p_cur->type);
1765 writeStringToParcel(p, p_cur->number);
1768 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
1769 (p_cur->notificationType==0)?"mo":"mt",
1770 p_cur->code, p_cur->index, p_cur->type,
1771 (char*)p_cur->number);
1777 static int responseCellList(Parcel &p, void *response, size_t responselen) {
1780 if (response == NULL && responselen != 0) {
1781 ALOGE("invalid response: NULL");
1782 return RIL_ERRNO_INVALID_RESPONSE;
1785 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
1786 ALOGE("invalid response length %d expected multiple of %d\n",
1787 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
1788 return RIL_ERRNO_INVALID_RESPONSE;
1792 /* number of records */
1793 num = responselen / sizeof(RIL_NeighboringCell *);
1796 for (int i = 0 ; i < num ; i++) {
1797 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
1799 p.writeInt32(p_cur->rssi);
1800 writeStringToParcel (p, p_cur->cid);
1802 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
1803 p_cur->cid, p_cur->rssi);
1812 * Marshall the signalInfoRecord into the parcel if it exists.
1814 static void marshallSignalInfoRecord(Parcel &p,
1815 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
1816 p.writeInt32(p_signalInfoRecord.isPresent);
1817 p.writeInt32(p_signalInfoRecord.signalType);
1818 p.writeInt32(p_signalInfoRecord.alertPitch);
1819 p.writeInt32(p_signalInfoRecord.signal);
1822 static int responseCdmaInformationRecords(Parcel &p,
1823 void *response, size_t responselen) {
1825 char* string8 = NULL;
1827 RIL_CDMA_InformationRecord *infoRec;
1829 if (response == NULL && responselen != 0) {
1830 ALOGE("invalid response: NULL");
1831 return RIL_ERRNO_INVALID_RESPONSE;
1834 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
1835 ALOGE("invalid response length %d expected multiple of %d\n",
1836 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
1837 return RIL_ERRNO_INVALID_RESPONSE;
1840 RIL_CDMA_InformationRecords *p_cur =
1841 (RIL_CDMA_InformationRecords *) response;
1842 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
1847 for (int i = 0 ; i < num ; i++) {
1848 infoRec = &p_cur->infoRec[i];
1849 p.writeInt32(infoRec->name);
1850 switch (infoRec->name) {
1851 case RIL_CDMA_DISPLAY_INFO_REC:
1852 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
1853 if (infoRec->rec.display.alpha_len >
1854 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
1855 ALOGE("invalid display info response length %d \
1856 expected not more than %d\n",
1857 (int)infoRec->rec.display.alpha_len,
1858 CDMA_ALPHA_INFO_BUFFER_LENGTH);
1859 return RIL_ERRNO_INVALID_RESPONSE;
1861 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
1863 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
1864 string8[i] = infoRec->rec.display.alpha_buf[i];
1866 string8[(int)infoRec->rec.display.alpha_len] = '\0';
1867 writeStringToParcel(p, (const char*)string8);
1871 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
1872 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
1873 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
1874 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
1875 ALOGE("invalid display info response length %d \
1876 expected not more than %d\n",
1877 (int)infoRec->rec.number.len,
1878 CDMA_NUMBER_INFO_BUFFER_LENGTH);
1879 return RIL_ERRNO_INVALID_RESPONSE;
1881 string8 = (char*) malloc((infoRec->rec.number.len + 1)
1883 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
1884 string8[i] = infoRec->rec.number.buf[i];
1886 string8[(int)infoRec->rec.number.len] = '\0';
1887 writeStringToParcel(p, (const char*)string8);
1890 p.writeInt32(infoRec->rec.number.number_type);
1891 p.writeInt32(infoRec->rec.number.number_plan);
1892 p.writeInt32(infoRec->rec.number.pi);
1893 p.writeInt32(infoRec->rec.number.si);
1895 case RIL_CDMA_SIGNAL_INFO_REC:
1896 p.writeInt32(infoRec->rec.signal.isPresent);
1897 p.writeInt32(infoRec->rec.signal.signalType);
1898 p.writeInt32(infoRec->rec.signal.alertPitch);
1899 p.writeInt32(infoRec->rec.signal.signal);
1901 appendPrintBuf("%sisPresent=%X, signalType=%X, \
1902 alertPitch=%X, signal=%X, ",
1903 printBuf, (int)infoRec->rec.signal.isPresent,
1904 (int)infoRec->rec.signal.signalType,
1905 (int)infoRec->rec.signal.alertPitch,
1906 (int)infoRec->rec.signal.signal);
1909 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
1910 if (infoRec->rec.redir.redirectingNumber.len >
1911 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
1912 ALOGE("invalid display info response length %d \
1913 expected not more than %d\n",
1914 (int)infoRec->rec.redir.redirectingNumber.len,
1915 CDMA_NUMBER_INFO_BUFFER_LENGTH);
1916 return RIL_ERRNO_INVALID_RESPONSE;
1918 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
1919 .len + 1) * sizeof(char) );
1921 i < infoRec->rec.redir.redirectingNumber.len;
1923 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
1925 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
1926 writeStringToParcel(p, (const char*)string8);
1929 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
1930 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
1931 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
1932 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
1933 p.writeInt32(infoRec->rec.redir.redirectingReason);
1935 case RIL_CDMA_LINE_CONTROL_INFO_REC:
1936 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
1937 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
1938 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
1939 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
1941 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
1942 lineCtrlToggle=%d, lineCtrlReverse=%d, \
1943 lineCtrlPowerDenial=%d, ", printBuf,
1944 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
1945 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
1946 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
1947 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
1950 case RIL_CDMA_T53_CLIR_INFO_REC:
1951 p.writeInt32((int)(infoRec->rec.clir.cause));
1953 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
1956 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
1957 p.writeInt32(infoRec->rec.audioCtrl.upLink);
1958 p.writeInt32(infoRec->rec.audioCtrl.downLink);
1960 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
1961 infoRec->rec.audioCtrl.upLink,
1962 infoRec->rec.audioCtrl.downLink);
1965 case RIL_CDMA_T53_RELEASE_INFO_REC:
1966 // TODO(Moto): See David Krause, he has the answer:)
1967 ALOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
1968 return RIL_ERRNO_INVALID_RESPONSE;
1970 ALOGE("Incorrect name value");
1971 return RIL_ERRNO_INVALID_RESPONSE;
1979 static int responseRilSignalStrength(Parcel &p,
1980 void *response, size_t responselen) {
1981 if (response == NULL && responselen != 0) {
1982 ALOGE("invalid response: NULL");
1983 return RIL_ERRNO_INVALID_RESPONSE;
1986 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
1987 RIL_SignalStrength_v6 *p_cur = ((RIL_SignalStrength_v6 *) response);
1989 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
1990 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
1991 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
1992 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
1993 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
1994 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
1995 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
1996 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
1997 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
1998 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
1999 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2000 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2001 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2003 memset(&p_cur->LTE_SignalStrength, sizeof (RIL_LTE_SignalStrength), 0);
2007 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
2008 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2009 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2010 EVDO_SS.signalNoiseRatio=%d,\
2011 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
2012 LTE_SS.rssnr=%d,LTE_SS.cqi=%d]",
2014 p_cur->GW_SignalStrength.signalStrength,
2015 p_cur->GW_SignalStrength.bitErrorRate,
2016 p_cur->CDMA_SignalStrength.dbm,
2017 p_cur->CDMA_SignalStrength.ecio,
2018 p_cur->EVDO_SignalStrength.dbm,
2019 p_cur->EVDO_SignalStrength.ecio,
2020 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2021 p_cur->LTE_SignalStrength.signalStrength,
2022 p_cur->LTE_SignalStrength.rsrp,
2023 p_cur->LTE_SignalStrength.rsrq,
2024 p_cur->LTE_SignalStrength.rssnr,
2025 p_cur->LTE_SignalStrength.cqi);
2029 ALOGE("invalid response length");
2030 return RIL_ERRNO_INVALID_RESPONSE;
2036 static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2037 if ((response == NULL) || (responselen == 0)) {
2038 return responseVoid(p, response, responselen);
2040 return responseCdmaSignalInfoRecord(p, response, responselen);
2044 static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2045 if (response == NULL || responselen == 0) {
2046 ALOGE("invalid response: NULL");
2047 return RIL_ERRNO_INVALID_RESPONSE;
2050 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
2051 ALOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
2052 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2053 return RIL_ERRNO_INVALID_RESPONSE;
2058 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2059 marshallSignalInfoRecord(p, *p_cur);
2061 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2073 static int responseCdmaCallWaiting(Parcel &p, void *response,
2074 size_t responselen) {
2075 if (response == NULL && responselen != 0) {
2076 ALOGE("invalid response: NULL");
2077 return RIL_ERRNO_INVALID_RESPONSE;
2080 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
2081 ALOGW("Upgrade to ril version %d\n", RIL_VERSION);
2084 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2086 writeStringToParcel(p, p_cur->number);
2087 p.writeInt32(p_cur->numberPresentation);
2088 writeStringToParcel(p, p_cur->name);
2089 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2091 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2092 p.writeInt32(p_cur->number_type);
2093 p.writeInt32(p_cur->number_plan);
2100 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2101 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2102 signal=%d,number_type=%d,number_plan=%d]",
2105 p_cur->numberPresentation,
2107 p_cur->signalInfoRecord.isPresent,
2108 p_cur->signalInfoRecord.signalType,
2109 p_cur->signalInfoRecord.alertPitch,
2110 p_cur->signalInfoRecord.signal,
2112 p_cur->number_plan);
2118 static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2119 if (response == NULL && responselen != 0) {
2120 ALOGE("responseSimRefresh: invalid response: NULL");
2121 return RIL_ERRNO_INVALID_RESPONSE;
2125 if (s_callbacks.version == 7) {
2126 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2127 p.writeInt32(p_cur->result);
2128 p.writeInt32(p_cur->ef_id);
2129 writeStringToParcel(p, p_cur->aid);
2131 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2137 int *p_cur = ((int *) response);
2138 p.writeInt32(p_cur[0]);
2139 p.writeInt32(p_cur[1]);
2140 writeStringToParcel(p, NULL);
2142 appendPrintBuf("%sresult=%d, ef_id=%d",
2152 static void triggerEvLoop() {
2154 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
2155 /* trigger event loop to wakeup. No reason to do this,
2156 * if we're in the event loop thread */
2158 ret = write (s_fdWakeupWrite, " ", 1);
2159 } while (ret < 0 && errno == EINTR);
2163 static void rilEventAddWakeup(struct ril_event *ev) {
2168 static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
2169 p.writeInt32(num_apps);
2171 for (int i = 0; i < num_apps; i++) {
2172 p.writeInt32(appStatus[i].app_type);
2173 p.writeInt32(appStatus[i].app_state);
2174 p.writeInt32(appStatus[i].perso_substate);
2175 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
2176 writeStringToParcel(p, (const char*)
2177 (appStatus[i].app_label_ptr));
2178 p.writeInt32(appStatus[i].pin1_replaced);
2179 p.writeInt32(appStatus[i].pin1);
2180 p.writeInt32(appStatus[i].pin2);
2181 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
2182 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
2184 appStatus[i].app_type,
2185 appStatus[i].app_state,
2186 appStatus[i].perso_substate,
2187 appStatus[i].aid_ptr,
2188 appStatus[i].app_label_ptr,
2189 appStatus[i].pin1_replaced,
2196 static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
2199 if (response == NULL && responselen != 0) {
2200 ALOGE("invalid response: NULL");
2201 return RIL_ERRNO_INVALID_RESPONSE;
2204 if (responselen == sizeof (RIL_CardStatus_v6)) {
2205 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
2207 p.writeInt32(p_cur->card_state);
2208 p.writeInt32(p_cur->universal_pin_state);
2209 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2210 p.writeInt32(p_cur->cdma_subscription_app_index);
2211 p.writeInt32(p_cur->ims_subscription_app_index);
2213 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2214 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
2215 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
2217 p.writeInt32(p_cur->card_state);
2218 p.writeInt32(p_cur->universal_pin_state);
2219 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2220 p.writeInt32(p_cur->cdma_subscription_app_index);
2223 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2225 ALOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
2226 return RIL_ERRNO_INVALID_RESPONSE;
2232 static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2233 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
2237 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
2238 (RIL_GSM_BroadcastSmsConfigInfo **) response;
2239 for (int i = 0; i < num; i++) {
2240 p.writeInt32(p_cur[i]->fromServiceId);
2241 p.writeInt32(p_cur[i]->toServiceId);
2242 p.writeInt32(p_cur[i]->fromCodeScheme);
2243 p.writeInt32(p_cur[i]->toCodeScheme);
2244 p.writeInt32(p_cur[i]->selected);
2246 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
2247 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
2248 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
2249 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
2250 p_cur[i]->selected);
2257 static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2258 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
2259 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
2261 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
2265 for (int i = 0 ; i < num ; i++ ) {
2266 p.writeInt32(p_cur[i]->service_category);
2267 p.writeInt32(p_cur[i]->language);
2268 p.writeInt32(p_cur[i]->selected);
2270 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
2272 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
2273 p_cur[i]->selected);
2280 static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
2287 ALOGD("Inside responseCdmaSms");
2289 if (response == NULL && responselen != 0) {
2290 ALOGE("invalid response: NULL");
2291 return RIL_ERRNO_INVALID_RESPONSE;
2294 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
2295 ALOGE("invalid response length was %d expected %d",
2296 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
2297 return RIL_ERRNO_INVALID_RESPONSE;
2300 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
2301 p.writeInt32(p_cur->uTeleserviceID);
2302 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
2303 p.writeInt32(p_cur->uServicecategory);
2304 p.writeInt32(p_cur->sAddress.digit_mode);
2305 p.writeInt32(p_cur->sAddress.number_mode);
2306 p.writeInt32(p_cur->sAddress.number_type);
2307 p.writeInt32(p_cur->sAddress.number_plan);
2308 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
2309 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2310 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2311 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
2314 p.writeInt32(p_cur->sSubAddress.subaddressType);
2315 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
2316 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
2317 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2318 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2319 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
2322 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2323 p.writeInt32(p_cur->uBearerDataLen);
2324 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2325 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
2329 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
2330 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
2331 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
2332 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
2339 * A write on the wakeup fd is done just to pop us out of select()
2340 * We empty the buffer here and then ril_event will reset the timers on the
2343 static void processWakeupCallback(int fd, short flags, void *param) {
2347 ALOGV("processWakeupCallback");
2349 /* empty our wakeup socket out */
2351 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
2352 } while (ret > 0 || (ret < 0 && errno == EINTR));
2355 static void onCommandsSocketClosed() {
2359 /* mark pending requests as "cancelled" so we dont report responses */
2361 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
2364 p_cur = s_pendingRequests;
2366 for (p_cur = s_pendingRequests
2368 ; p_cur = p_cur->p_next
2370 p_cur->cancelled = 1;
2373 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
2377 static void processCommandsCallback(int fd, short flags, void *param) {
2383 assert(fd == s_fdCommand);
2385 p_rs = (RecordStream *)param;
2388 /* loop until EAGAIN/EINTR, end of stream, or other error */
2389 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
2391 if (ret == 0 && p_record == NULL) {
2394 } else if (ret < 0) {
2396 } else if (ret == 0) { /* && p_record != NULL */
2397 processCommandBuffer(p_record, recordlen);
2401 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
2402 /* fatal error or end-of-stream */
2404 ALOGE("error on reading command socket errno:%d\n", errno);
2406 ALOGW("EOS. Closing command socket.");
2412 ril_event_del(&s_commands_event);
2414 record_stream_free(p_rs);
2416 /* start listening for new connections again */
2417 rilEventAddWakeup(&s_listen_event);
2419 onCommandsSocketClosed();
2424 static void onNewCommandConnect() {
2425 // Inform we are connected and the ril version
2426 int rilVer = s_callbacks.version;
2427 RIL_onUnsolicitedResponse(RIL_UNSOL_RIL_CONNECTED,
2428 &rilVer, sizeof(rilVer));
2430 // implicit radio state changed
2431 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
2434 // Send last NITZ time data, in case it was missed
2435 if (s_lastNITZTimeData != NULL) {
2436 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
2438 free(s_lastNITZTimeData);
2439 s_lastNITZTimeData = NULL;
2442 // Get version string
2443 if (s_callbacks.getVersion != NULL) {
2444 const char *version;
2445 version = s_callbacks.getVersion();
2446 ALOGI("RIL Daemon version: %s\n", version);
2448 property_set(PROPERTY_RIL_IMPL, version);
2450 ALOGI("RIL Daemon version: unavailable\n");
2451 property_set(PROPERTY_RIL_IMPL, "unavailable");
2456 static void listenCallback (int fd, short flags, void *param) {
2459 int is_phone_socket;
2462 struct sockaddr_un peeraddr;
2463 socklen_t socklen = sizeof (peeraddr);
2466 socklen_t szCreds = sizeof(creds);
2468 struct passwd *pwd = NULL;
2470 assert (s_fdCommand < 0);
2471 assert (fd == s_fdListen);
2473 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
2475 if (s_fdCommand < 0 ) {
2476 ALOGE("Error on accept() errno:%d", errno);
2477 /* start listening for new connections again */
2478 rilEventAddWakeup(&s_listen_event);
2482 /* check the credential of the other side and only accept socket from
2486 is_phone_socket = 0;
2488 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
2490 if (err == 0 && szCreds > 0) {
2492 pwd = getpwuid(creds.uid);
2494 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
2495 is_phone_socket = 1;
2497 ALOGE("RILD can't accept socket from process %s", pwd->pw_name);
2500 ALOGE("Error on getpwuid() errno: %d", errno);
2503 ALOGD("Error on getsockopt() errno: %d", errno);
2506 if ( !is_phone_socket ) {
2507 ALOGE("RILD must accept socket from %s", PHONE_PROCESS);
2512 onCommandsSocketClosed();
2514 /* start listening for new connections again */
2515 rilEventAddWakeup(&s_listen_event);
2520 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
2523 ALOGE ("Error setting O_NONBLOCK errno:%d", errno);
2526 ALOGI("libril: new connection");
2528 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
2530 ril_event_set (&s_commands_event, s_fdCommand, 1,
2531 processCommandsCallback, p_rs);
2533 rilEventAddWakeup (&s_commands_event);
2535 onNewCommandConnect();
2538 static void freeDebugCallbackArgs(int number, char **args) {
2539 for (int i = 0; i < number; i++) {
2540 if (args[i] != NULL) {
2547 static void debugCallback (int fd, short flags, void *param) {
2548 int acceptFD, option;
2549 struct sockaddr_un peeraddr;
2550 socklen_t socklen = sizeof (peeraddr);
2552 unsigned int qxdm_data[6];
2553 const char *deactData[1] = {"1"};
2556 int hangupData[1] = {1};
2560 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
2563 ALOGE ("error accepting on debug port: %d\n", errno);
2567 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
2568 ALOGE ("error reading on socket: number of Args: \n");
2571 args = (char **) malloc(sizeof(char*) * number);
2573 for (int i = 0; i < number; i++) {
2575 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
2576 ALOGE ("error reading on socket: Len of Args: \n");
2577 freeDebugCallbackArgs(i, args);
2581 args[i] = (char *) malloc((sizeof(char) * len) + 1);
2582 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
2583 != (int)sizeof(char) * len) {
2584 ALOGE ("error reading on socket: Args[%d] \n", i);
2585 freeDebugCallbackArgs(i, args);
2588 char * buf = args[i];
2592 switch (atoi(args[0])) {
2594 ALOGI ("Connection on debug port: issuing reset.");
2595 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
2598 ALOGI ("Connection on debug port: issuing radio power off.");
2600 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2606 ALOGI ("Debug port: issuing unsolicited voice network change.");
2607 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
2611 ALOGI ("Debug port: QXDM log enable.");
2612 qxdm_data[0] = 65536; // head.func_tag
2613 qxdm_data[1] = 16; // head.len
2614 qxdm_data[2] = 1; // mode: 1 for 'start logging'
2615 qxdm_data[3] = 32; // log_file_size: 32megabytes
2616 qxdm_data[4] = 0; // log_mask
2617 qxdm_data[5] = 8; // log_max_fileindex
2618 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2622 ALOGI ("Debug port: QXDM log disable.");
2623 qxdm_data[0] = 65536;
2625 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
2629 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2633 ALOGI("Debug port: Radio On");
2635 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2637 // Set network selection automatic.
2638 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
2641 ALOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
2642 actData[0] = args[1];
2643 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
2647 ALOGI("Debug port: Deactivate Data Call");
2648 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
2652 ALOGI("Debug port: Dial Call");
2654 dialData.address = args[1];
2655 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
2658 ALOGI("Debug port: Answer Call");
2659 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
2662 ALOGI("Debug port: End Call");
2663 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
2664 sizeof(hangupData));
2667 ALOGE ("Invalid request");
2670 freeDebugCallbackArgs(number, args);
2675 static void userTimerCallback (int fd, short flags, void *param) {
2676 UserCallbackInfo *p_info;
2678 p_info = (UserCallbackInfo *)param;
2680 p_info->p_callback(p_info->userParam);
2683 // FIXME generalize this...there should be a cancel mechanism
2684 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
2685 s_last_wake_timeout_info = NULL;
2693 eventLoop(void *param) {
2699 pthread_mutex_lock(&s_startupMutex);
2702 pthread_cond_broadcast(&s_startupCond);
2704 pthread_mutex_unlock(&s_startupMutex);
2706 ret = pipe(filedes);
2709 ALOGE("Error in pipe() errno:%d", errno);
2713 s_fdWakeupRead = filedes[0];
2714 s_fdWakeupWrite = filedes[1];
2716 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
2718 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
2719 processWakeupCallback, NULL);
2721 rilEventAddWakeup (&s_wakeupfd_event);
2723 // Only returns on error
2725 ALOGE ("error in event_loop_base errno:%d", errno);
2726 // kill self to restart on error
2733 RIL_startEventLoop(void) {
2735 pthread_attr_t attr;
2737 /* spin up eventLoop thread and wait for it to get started */
2739 pthread_mutex_lock(&s_startupMutex);
2741 pthread_attr_init (&attr);
2742 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
2743 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
2745 while (s_started == 0) {
2746 pthread_cond_wait(&s_startupCond, &s_startupMutex);
2749 pthread_mutex_unlock(&s_startupMutex);
2752 ALOGE("Failed to create dispatch thread errno:%d", errno);
2757 // Used for testing purpose only.
2758 extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
2759 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
2763 RIL_register (const RIL_RadioFunctions *callbacks) {
2767 if (callbacks == NULL) {
2768 ALOGE("RIL_register: RIL_RadioFunctions * null");
2771 if (callbacks->version < RIL_VERSION_MIN) {
2772 ALOGE("RIL_register: version %d is to old, min version is %d",
2773 callbacks->version, RIL_VERSION_MIN);
2776 if (callbacks->version > RIL_VERSION) {
2777 ALOGE("RIL_register: version %d is too new, max version is %d",
2778 callbacks->version, RIL_VERSION);
2781 ALOGE("RIL_register: RIL version %d", callbacks->version);
2783 if (s_registerCalled > 0) {
2784 ALOGE("RIL_register has been called more than once. "
2785 "Subsequent call ignored");
2789 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
2791 s_registerCalled = 1;
2793 // Little self-check
2795 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
2796 assert(i == s_commands[i].requestNumber);
2799 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
2800 assert(i + RIL_UNSOL_RESPONSE_BASE
2801 == s_unsolResponses[i].requestNumber);
2804 // New rild impl calls RIL_startEventLoop() first
2805 // old standalone impl wants it here.
2807 if (s_started == 0) {
2808 RIL_startEventLoop();
2811 // start listen socket
2814 ret = socket_local_server (SOCKET_NAME_RIL,
2815 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
2818 ALOGE("Unable to bind socket errno:%d", errno);
2824 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
2825 if (s_fdListen < 0) {
2826 ALOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
2830 ret = listen(s_fdListen, 4);
2833 ALOGE("Failed to listen on control socket '%d': %s",
2834 s_fdListen, strerror(errno));
2840 /* note: non-persistent so we can accept only one connection at a time */
2841 ril_event_set (&s_listen_event, s_fdListen, false,
2842 listenCallback, NULL);
2844 rilEventAddWakeup (&s_listen_event);
2847 // start debug interface socket
2849 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
2850 if (s_fdDebug < 0) {
2851 ALOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
2855 ret = listen(s_fdDebug, 4);
2858 ALOGE("Failed to listen on ril debug socket '%d': %s",
2859 s_fdDebug, strerror(errno));
2863 ril_event_set (&s_debug_event, s_fdDebug, true,
2864 debugCallback, NULL);
2866 rilEventAddWakeup (&s_debug_event);
2872 checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
2879 pthread_mutex_lock(&s_pendingRequestsMutex);
2881 for(RequestInfo **ppCur = &s_pendingRequests
2883 ; ppCur = &((*ppCur)->p_next)
2885 if (pRI == *ppCur) {
2888 *ppCur = (*ppCur)->p_next;
2893 pthread_mutex_unlock(&s_pendingRequestsMutex);
2900 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
2905 pRI = (RequestInfo *)t;
2907 if (!checkAndDequeueRequestInfo(pRI)) {
2908 ALOGE ("RIL_onRequestComplete: invalid RIL_Token");
2912 if (pRI->local > 0) {
2913 // Locally issued command...void only!
2914 // response does not go back up the command socket
2915 ALOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
2920 appendPrintBuf("[%04d]< %s",
2921 pRI->token, requestToString(pRI->pCI->requestNumber));
2923 if (pRI->cancelled == 0) {
2926 p.writeInt32 (RESPONSE_SOLICITED);
2927 p.writeInt32 (pRI->token);
2928 errorOffset = p.dataPosition();
2932 if (response != NULL) {
2933 // there is a response payload, no matter success or not.
2934 ret = pRI->pCI->responseFunction(p, response, responselen);
2936 /* if an error occurred, rewind and mark it */
2938 p.setDataPosition(errorOffset);
2943 if (e != RIL_E_SUCCESS) {
2944 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
2947 if (s_fdCommand < 0) {
2948 ALOGD ("RIL onRequestComplete: Command channel closed");
2959 grabPartialWakeLock() {
2960 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
2965 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
2969 * Timer callback to put us back to sleep before the default timeout
2972 wakeTimeoutCallback (void *param) {
2973 // We're using "param != NULL" as a cancellation mechanism
2974 if (param == NULL) {
2975 //ALOGD("wakeTimeout: releasing wake lock");
2979 //ALOGD("wakeTimeout: releasing wake lock CANCELLED");
2984 decodeVoiceRadioTechnology (RIL_RadioState radioState) {
2985 switch (radioState) {
2986 case RADIO_STATE_SIM_NOT_READY:
2987 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
2988 case RADIO_STATE_SIM_READY:
2989 return RADIO_TECH_UMTS;
2991 case RADIO_STATE_RUIM_NOT_READY:
2992 case RADIO_STATE_RUIM_READY:
2993 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
2994 case RADIO_STATE_NV_NOT_READY:
2995 case RADIO_STATE_NV_READY:
2996 return RADIO_TECH_1xRTT;
2999 ALOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
3005 decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
3006 switch (radioState) {
3007 case RADIO_STATE_SIM_NOT_READY:
3008 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3009 case RADIO_STATE_SIM_READY:
3010 case RADIO_STATE_RUIM_NOT_READY:
3011 case RADIO_STATE_RUIM_READY:
3012 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3013 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
3015 case RADIO_STATE_NV_NOT_READY:
3016 case RADIO_STATE_NV_READY:
3017 return CDMA_SUBSCRIPTION_SOURCE_NV;
3020 ALOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
3026 decodeSimStatus (RIL_RadioState radioState) {
3027 switch (radioState) {
3028 case RADIO_STATE_SIM_NOT_READY:
3029 case RADIO_STATE_RUIM_NOT_READY:
3030 case RADIO_STATE_NV_NOT_READY:
3031 case RADIO_STATE_NV_READY:
3033 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3034 case RADIO_STATE_SIM_READY:
3035 case RADIO_STATE_RUIM_READY:
3036 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3039 ALOGD("decodeSimStatus: Invoked with incorrect RadioState");
3044 static bool is3gpp2(int radioTech) {
3045 switch (radioTech) {
3046 case RADIO_TECH_IS95A:
3047 case RADIO_TECH_IS95B:
3048 case RADIO_TECH_1xRTT:
3049 case RADIO_TECH_EVDO_0:
3050 case RADIO_TECH_EVDO_A:
3051 case RADIO_TECH_EVDO_B:
3052 case RADIO_TECH_EHRPD:
3059 /* If RIL sends SIM states or RUIM states, store the voice radio
3060 * technology and subscription source information so that they can be
3061 * returned when telephony framework requests them
3063 static RIL_RadioState
3064 processRadioState(RIL_RadioState newRadioState) {
3066 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
3067 int newVoiceRadioTech;
3068 int newCdmaSubscriptionSource;
3071 /* This is old RIL. Decode Subscription source and Voice Radio Technology
3072 from Radio State and send change notifications if there has been a change */
3073 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
3074 if(newVoiceRadioTech != voiceRadioTech) {
3075 voiceRadioTech = newVoiceRadioTech;
3076 RIL_onUnsolicitedResponse (RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
3077 &voiceRadioTech, sizeof(voiceRadioTech));
3079 if(is3gpp2(newVoiceRadioTech)) {
3080 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
3081 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
3082 cdmaSubscriptionSource = newCdmaSubscriptionSource;
3083 RIL_onUnsolicitedResponse (RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
3084 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource));
3087 newSimStatus = decodeSimStatus(newRadioState);
3088 if(newSimStatus != simRuimStatus) {
3089 simRuimStatus = newSimStatus;
3090 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
3093 /* Send RADIO_ON to telephony */
3094 newRadioState = RADIO_STATE_ON;
3097 return newRadioState;
3101 void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
3104 int unsolResponseIndex;
3106 int64_t timeReceived = 0;
3107 bool shouldScheduleTimeout = false;
3108 RIL_RadioState newState;
3110 if (s_registerCalled == 0) {
3111 // Ignore RIL_onUnsolicitedResponse before RIL_register
3112 ALOGW("RIL_onUnsolicitedResponse called before RIL_register");
3116 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
3118 if ((unsolResponseIndex < 0)
3119 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
3120 ALOGE("unsupported unsolicited response code %d", unsolResponse);
3124 // Grab a wake lock if needed for this reponse,
3125 // as we exit we'll either release it immediately
3126 // or set a timer to release it later.
3127 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
3129 grabPartialWakeLock();
3130 shouldScheduleTimeout = true;
3135 // No wake lock is grabed so don't set timeout
3136 shouldScheduleTimeout = false;
3140 // Mark the time this was received, doing this
3141 // after grabing the wakelock incase getting
3142 // the elapsedRealTime might cause us to goto
3144 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3145 timeReceived = elapsedRealtime();
3148 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
3152 p.writeInt32 (RESPONSE_UNSOLICITED);
3153 p.writeInt32 (unsolResponse);
3155 ret = s_unsolResponses[unsolResponseIndex]
3156 .responseFunction(p, data, datalen);
3158 // Problem with the response. Don't continue;
3162 // some things get more payload
3163 switch(unsolResponse) {
3164 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
3165 newState = processRadioState(s_callbacks.onStateRequest());
3166 p.writeInt32(newState);
3167 appendPrintBuf("%s {%s}", printBuf,
3168 radioStateToString(s_callbacks.onStateRequest()));
3172 case RIL_UNSOL_NITZ_TIME_RECEIVED:
3173 // Store the time that this was received so the
3174 // handler of this message can account for
3175 // the time it takes to arrive and process. In
3176 // particular the system has been known to sleep
3177 // before this message can be processed.
3178 p.writeInt64(timeReceived);
3182 ret = sendResponse(p);
3183 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3185 // Unfortunately, NITZ time is not poll/update like everything
3186 // else in the system. So, if the upstream client isn't connected,
3187 // keep a copy of the last NITZ response (with receive time noted
3188 // above) around so we can deliver it when it is connected
3190 if (s_lastNITZTimeData != NULL) {
3191 free (s_lastNITZTimeData);
3192 s_lastNITZTimeData = NULL;
3195 s_lastNITZTimeData = malloc(p.dataSize());
3196 s_lastNITZTimeDataSize = p.dataSize();
3197 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
3200 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
3201 // FIXME The java code should handshake here to release wake lock
3203 if (shouldScheduleTimeout) {
3204 // Cancel the previous request
3205 if (s_last_wake_timeout_info != NULL) {
3206 s_last_wake_timeout_info->userParam = (void *)1;
3209 s_last_wake_timeout_info
3210 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
3211 &TIMEVAL_WAKE_TIMEOUT);
3218 if (shouldScheduleTimeout) {
3223 /** FIXME generalize this if you track UserCAllbackInfo, clear it
3224 when the callback occurs
3226 static UserCallbackInfo *
3227 internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
3228 const struct timeval *relativeTime)
3230 struct timeval myRelativeTime;
3231 UserCallbackInfo *p_info;
3233 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
3235 p_info->p_callback = callback;
3236 p_info->userParam = param;
3238 if (relativeTime == NULL) {
3239 /* treat null parameter as a 0 relative time */
3240 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
3242 /* FIXME I think event_add's tv param is really const anyway */
3243 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
3246 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
3248 ril_timer_add(&(p_info->event), &myRelativeTime);
3256 RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
3257 const struct timeval *relativeTime) {
3258 internalRequestTimedCallback (callback, param, relativeTime);
3262 failCauseToString(RIL_Errno e) {
3264 case RIL_E_SUCCESS: return "E_SUCCESS";
3265 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RAIDO_NOT_AVAILABLE";
3266 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
3267 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
3268 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
3269 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
3270 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
3271 case RIL_E_CANCELLED: return "E_CANCELLED";
3272 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
3273 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
3274 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
3275 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
3276 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
3277 #ifdef FEATURE_MULTIMODE_ANDROID
3278 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
3279 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
3281 default: return "<unknown error>";
3286 radioStateToString(RIL_RadioState s) {
3288 case RADIO_STATE_OFF: return "RADIO_OFF";
3289 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
3290 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
3291 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
3292 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
3293 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
3294 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
3295 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
3296 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
3297 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
3298 case RADIO_STATE_ON:return"RADIO_ON";
3299 default: return "<unknown state>";
3304 callStateToString(RIL_CallState s) {
3306 case RIL_CALL_ACTIVE : return "ACTIVE";
3307 case RIL_CALL_HOLDING: return "HOLDING";
3308 case RIL_CALL_DIALING: return "DIALING";
3309 case RIL_CALL_ALERTING: return "ALERTING";
3310 case RIL_CALL_INCOMING: return "INCOMING";
3311 case RIL_CALL_WAITING: return "WAITING";
3312 default: return "<unknown state>";
3317 requestToString(int request) {
3319 cat libs/telephony/ril_commands.h \
3320 | egrep "^ *{RIL_" \
3321 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3324 cat libs/telephony/ril_unsol_commands.h \
3325 | egrep "^ *{RIL_" \
3326 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
3330 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3331 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3332 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3333 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3334 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3335 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3336 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3337 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3338 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3339 case RIL_REQUEST_DIAL: return "DIAL";
3340 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3341 case RIL_REQUEST_HANGUP: return "HANGUP";
3342 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3343 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3344 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3345 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3346 case RIL_REQUEST_UDUB: return "UDUB";
3347 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3348 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3349 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3350 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3351 case RIL_REQUEST_OPERATOR: return "OPERATOR";
3352 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3353 case RIL_REQUEST_DTMF: return "DTMF";
3354 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3355 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3356 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3357 case RIL_REQUEST_SIM_IO: return "SIM_IO";
3358 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3359 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3360 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3361 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3362 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3363 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3364 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3365 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3366 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3367 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3368 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3369 case RIL_REQUEST_ANSWER: return "ANSWER";
3370 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3371 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3372 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3373 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3374 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3375 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3376 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3377 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3378 case RIL_REQUEST_DTMF_START: return "DTMF_START";
3379 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3380 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3381 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3382 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
3383 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
3384 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
3385 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3386 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3387 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3388 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3389 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3390 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3391 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3392 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3393 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3394 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3395 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
3396 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
3397 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
3398 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
3399 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
3400 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3401 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
3402 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
3403 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
3404 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
3405 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
3406 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
3407 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
3408 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
3409 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
3410 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
3411 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
3412 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
3413 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
3414 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
3415 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
3416 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
3417 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
3418 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
3419 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
3420 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
3421 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
3422 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
3423 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
3424 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
3425 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
3426 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
3427 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
3428 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
3429 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
3430 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
3431 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
3432 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
3433 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
3434 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
3435 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
3436 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
3437 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
3438 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
3439 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
3440 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
3441 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
3442 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
3443 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
3444 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
3445 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
3446 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
3447 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
3448 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
3449 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
3450 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
3451 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
3452 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
3453 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
3454 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
3455 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
3456 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
3457 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
3458 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
3459 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
3460 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
3461 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
3462 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
3463 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
3464 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
3465 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
3466 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
3467 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
3468 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
3469 default: return "<unknown request>";
3473 } /* namespace android */