blob: d3573e3e2fbab987294fb23f8e65b852110eed6b [file] [log] [blame]
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
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
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
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.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
21
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>
29#include <pthread.h>
30#include <binder/Parcel.h>
31#include <cutils/jstring.h>
32
33#include <sys/types.h>
34#include <pwd.h>
35
36#include <stdio.h>
37#include <stdlib.h>
38#include <stdarg.h>
39#include <string.h>
40#include <unistd.h>
41#include <fcntl.h>
42#include <time.h>
43#include <errno.h>
44#include <assert.h>
45#include <ctype.h>
46#include <alloca.h>
47#include <sys/un.h>
48#include <assert.h>
49#include <netinet/in.h>
50#include <cutils/properties.h>
51
52#include <ril_event.h>
53
54namespace android {
55
56#define PHONE_PROCESS "radio"
57
58#define SOCKET_NAME_RIL "rild"
59#define SOCKET_NAME_RIL_DEBUG "rild-debug"
60
61#define ANDROID_WAKE_LOCK_NAME "radio-interface"
62
63
64#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
65
66// match with constant in RIL.java
67#define MAX_COMMAND_BYTES (8 * 1024)
68
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
73
74#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
75
76#define MIN(a,b) ((a)<(b) ? (a) : (b))
77
78/* Constants for response types */
79#define RESPONSE_SOLICITED 0
80#define RESPONSE_UNSOLICITED 1
81
82/* Negative values for private RIL errno's */
83#define RIL_ERRNO_INVALID_RESPONSE -1
84
85// request, response, and unsolicited msg print macro
86#define PRINTBUF_SIZE 8096
87
88// Enable RILC log
89#define RILC_LOG 0
90
91#if RILC_LOG
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)
96
97 #define startResponse sprintf(printBuf, "%s {", printBuf)
98 #define closeResponse sprintf(printBuf, "%s}", printBuf)
99 #define printResponse ALOGD("%s", printBuf)
100
101 #define clearPrintBuf printBuf[0] = 0
102 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
103 #define appendPrintBuf(x...) sprintf(printBuf, x)
104#else
105 #define startRequest
106 #define closeRequest
107 #define printRequest(token, req)
108 #define startResponse
109 #define closeResponse
110 #define printResponse
111 #define clearPrintBuf
112 #define removeLastChar
113 #define appendPrintBuf(x...)
114#endif
115
116enum WakeType {DONT_WAKE, WAKE_PARTIAL};
117
118typedef struct {
119 int requestNumber;
120 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
121 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
122} CommandInfo;
123
124typedef struct {
125 int requestNumber;
126 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
127 WakeType wakeType;
128} UnsolResponseInfo;
129
130typedef struct RequestInfo {
131 int32_t token; //this is not RIL_Token
132 CommandInfo *pCI;
133 struct RequestInfo *p_next;
134 char cancelled;
135 char local; // responses to local commands do not go back to command process
136} RequestInfo;
137
138typedef struct UserCallbackInfo {
139 RIL_TimedCallback p_callback;
140 void *userParam;
141 struct ril_event event;
142 struct UserCallbackInfo *p_next;
143} UserCallbackInfo;
144
145
146/*******************************************************************/
147
148RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
149static int s_registerCalled = 0;
150
151static pthread_t s_tid_dispatch;
152static pthread_t s_tid_reader;
153static int s_started = 0;
154
155static int s_fdListen = -1;
156static int s_fdCommand = -1;
157static int s_fdDebug = -1;
158
159static int s_fdWakeupRead;
160static int s_fdWakeupWrite;
161
162static struct ril_event s_commands_event;
163static struct ril_event s_wakeupfd_event;
164static struct ril_event s_listen_event;
165static struct ril_event s_wake_timeout_event;
166static struct ril_event s_debug_event;
167
168
169static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
170
171static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
172static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
173static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
174static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
175
176static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
177static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
178
179static RequestInfo *s_pendingRequests = NULL;
180
181static RequestInfo *s_toDispatchHead = NULL;
182static RequestInfo *s_toDispatchTail = NULL;
183
184static UserCallbackInfo *s_last_wake_timeout_info = NULL;
185
186static void *s_lastNITZTimeData = NULL;
187static size_t s_lastNITZTimeDataSize;
188
189#if RILC_LOG
190 static char printBuf[PRINTBUF_SIZE];
191#endif
192
193/*******************************************************************/
194
195static void dispatchVoid (Parcel& p, RequestInfo *pRI);
196static void dispatchString (Parcel& p, RequestInfo *pRI);
197static void dispatchStrings (Parcel& p, RequestInfo *pRI);
198static void dispatchInts (Parcel& p, RequestInfo *pRI);
199static void dispatchDial (Parcel& p, RequestInfo *pRI);
200static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
201static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
202static void dispatchRaw(Parcel& p, RequestInfo *pRI);
203static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
204
205static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
206static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
207static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
208static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
209static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
210static int responseInts(Parcel &p, void *response, size_t responselen);
211static int responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen);
212static int responseStrings(Parcel &p, void *response, size_t responselen);
213static int responseStringsNetworks(Parcel &p, void *response, size_t responselen);
214static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search);
215static int responseString(Parcel &p, void *response, size_t responselen);
216static int responseVoid(Parcel &p, void *response, size_t responselen);
217static int responseCallList(Parcel &p, void *response, size_t responselen);
218static int responseSMS(Parcel &p, void *response, size_t responselen);
219static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
220static int responseCallForwards(Parcel &p, void *response, size_t responselen);
221static int responseDataCallList(Parcel &p, void *response, size_t responselen);
222static int responseRaw(Parcel &p, void *response, size_t responselen);
223static int responseSsn(Parcel &p, void *response, size_t responselen);
224static int responseSimStatus(Parcel &p, void *response, size_t responselen);
225static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
226static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
227static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
228static int responseCellList(Parcel &p, void *response, size_t responselen);
229static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
230static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
231static int responseCallRing(Parcel &p, void *response, size_t responselen);
232static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
233static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
234static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
235
236static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
237static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
238static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
239
240extern "C" const char * requestToString(int request);
241extern "C" const char * failCauseToString(RIL_Errno);
242extern "C" const char * callStateToString(RIL_CallState);
243extern "C" const char * radioStateToString(RIL_RadioState);
244
245#ifdef RIL_SHLIB
246extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
247 size_t datalen);
248#endif
249
250static UserCallbackInfo * internalRequestTimedCallback
251 (RIL_TimedCallback callback, void *param,
252 const struct timeval *relativeTime);
253
254/** Index == requestNumber */
255static CommandInfo s_commands[] = {
256#include "ril_commands.h"
257};
258
259static UnsolResponseInfo s_unsolResponses[] = {
260#include "ril_unsol_commands.h"
261};
262
263/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
264 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
265 radio state message and store it. Every time there is a change in Radio State
266 check to see if voice radio tech changes and notify telephony
267 */
268int voiceRadioTech = -1;
269
270/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
271 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
272 source from radio state and store it. Every time there is a change in Radio State
273 check to see if subscription source changed and notify telephony
274 */
275int cdmaSubscriptionSource = -1;
276
277/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
278 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
279 check to see if SIM/RUIM status changed and notify telephony
280 */
281int simRuimStatus = -1;
282
283static char *
284strdupReadString(Parcel &p) {
285 size_t stringlen;
286 const char16_t *s16;
287
288 s16 = p.readString16Inplace(&stringlen);
289
290 return strndup16to8(s16, stringlen);
291}
292
293static void writeStringToParcel(Parcel &p, const char *s) {
294 char16_t *s16;
295 size_t s16_len;
296 s16 = strdup8to16(s, &s16_len);
297 p.writeString16(s16, s16_len);
298 free(s16);
299}
300
301
302static void
303memsetString (char *s) {
304 if (s != NULL) {
305 memset (s, 0, strlen(s));
306 }
307}
308
309void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
310 const size_t* objects, size_t objectsSize,
311 void* cookie) {
312 // do nothing -- the data reference lives longer than the Parcel object
313}
314
315/**
316 * To be called from dispatch thread
317 * Issue a single local request, ensuring that the response
318 * is not sent back up to the command process
319 */
320static void
321issueLocalRequest(int request, void *data, int len) {
322 RequestInfo *pRI;
323 int index;
324 int ret;
325
326 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
327
328 pRI->local = 1;
329 pRI->token = 0xffffffff; // token is not used in this context
330
331 /* Hack to include Samsung requests */
332 if (request > 10000) {
333 index = request - 10000 + RIL_REQUEST_VOICE_RADIO_TECH;
334 ALOGE("SAMSUNG: request=%d, index=%d", request, index);
335 pRI->pCI = &(s_commands[index]);
336 } else {
337 pRI->pCI = &(s_commands[request]);
338 }
339
340 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
341 assert (ret == 0);
342
343 pRI->p_next = s_pendingRequests;
344 s_pendingRequests = pRI;
345
346 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
347 assert (ret == 0);
348
349 ALOGD("C[locl]> %s", requestToString(request));
350
351 s_callbacks.onRequest(request, data, len, pRI);
352}
353
354static int
355processCommandBuffer(void *buffer, size_t buflen) {
356 Parcel p;
357 status_t status;
358 int32_t request;
359 int32_t token;
360 RequestInfo *pRI;
361 int index;
362 int ret;
363
364 ALOGE("processCommandBuffer: enter");
365
366 p.setData((uint8_t *) buffer, buflen);
367
368 // status checked at end
369 status = p.readInt32(&request);
370 status = p.readInt32 (&token);
371
372 if (status != NO_ERROR) {
373 ALOGE("invalid request block");
374 return 0;
375 }
376
377 /* Hack to include Samsung requests */
378 //if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
379 if (request < 1 || ((request > RIL_REQUEST_VOICE_RADIO_TECH) && (request < RIL_REQUEST_GET_CELL_BROADCAST_CONFIG)) || request > RIL_REQUEST_HANGUP_VT) {
380 ALOGE("unsupported request code %d token %d", request, token);
381 // FIXME this should perhaps return a response
382 return 0;
383 }
384
385 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
386
387 pRI->token = token;
388
389 /* Hack to include Samsung requests */
390 if (request > 10000) {
391 index = request - 10000 + RIL_REQUEST_VOICE_RADIO_TECH;
392 ALOGE("processCommandBuffer: samsung request=%d, index=%d", request, index);
393 pRI->pCI = &(s_commands[index]);
394 } else {
395 pRI->pCI = &(s_commands[request]);
396 }
397
398 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
399 assert (ret == 0);
400
401 pRI->p_next = s_pendingRequests;
402 s_pendingRequests = pRI;
403
404 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
405 assert (ret == 0);
406
407/* sLastDispatchedToken = token; */
408
409 ALOGE("processCommandBuffer: dispatchFunction()");
410 pRI->pCI->dispatchFunction(p, pRI);
411
412 ALOGE("processCommandBuffer: exit");
413 return 0;
414}
415
416static void
417invalidCommandBlock (RequestInfo *pRI) {
418 ALOGE("invalid command block for token %d request %s",
419 pRI->token, requestToString(pRI->pCI->requestNumber));
420}
421
422/** Callee expects NULL */
423static void
424dispatchVoid (Parcel& p, RequestInfo *pRI) {
425 clearPrintBuf;
426 printRequest(pRI->token, pRI->pCI->requestNumber);
427 s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
428}
429
430/** Callee expects const char * */
431static void
432dispatchString (Parcel& p, RequestInfo *pRI) {
433 status_t status;
434 size_t datalen;
435 size_t stringlen;
436 char *string8 = NULL;
437
438 string8 = strdupReadString(p);
439
440 startRequest;
441 appendPrintBuf("%s%s", printBuf, string8);
442 closeRequest;
443 printRequest(pRI->token, pRI->pCI->requestNumber);
444
445 s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
446 sizeof(char *), pRI);
447
448#ifdef MEMSET_FREED
449 memsetString(string8);
450#endif
451
452 free(string8);
453 return;
454invalid:
455 invalidCommandBlock(pRI);
456 return;
457}
458
459/** Callee expects const char ** */
460static void
461dispatchStrings (Parcel &p, RequestInfo *pRI) {
462 int32_t countStrings;
463 status_t status;
464 size_t datalen;
465 char **pStrings;
466
467 status = p.readInt32 (&countStrings);
468
469 if (status != NO_ERROR) {
470 goto invalid;
471 }
472
473 startRequest;
474 if (countStrings == 0) {
475 // just some non-null pointer
476 pStrings = (char **)alloca(sizeof(char *));
477 datalen = 0;
478 } else if (((int)countStrings) == -1) {
479 pStrings = NULL;
480 datalen = 0;
481 } else {
482 datalen = sizeof(char *) * countStrings;
483
484 pStrings = (char **)alloca(datalen);
485
486 for (int i = 0 ; i < countStrings ; i++) {
487 pStrings[i] = strdupReadString(p);
488 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
489 }
490 }
491 removeLastChar;
492 closeRequest;
493 printRequest(pRI->token, pRI->pCI->requestNumber);
494
495 s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
496
497 if (pStrings != NULL) {
498 for (int i = 0 ; i < countStrings ; i++) {
499#ifdef MEMSET_FREED
500 memsetString (pStrings[i]);
501#endif
502 free(pStrings[i]);
503 }
504
505#ifdef MEMSET_FREED
506 memset(pStrings, 0, datalen);
507#endif
508 }
509
510 return;
511invalid:
512 invalidCommandBlock(pRI);
513 return;
514}
515
516/** Callee expects const int * */
517static void
518dispatchInts (Parcel &p, RequestInfo *pRI) {
519 int32_t count;
520 status_t status;
521 size_t datalen;
522 int *pInts;
523
524 status = p.readInt32 (&count);
525
526 if (status != NO_ERROR || count == 0) {
527 goto invalid;
528 }
529
530 datalen = sizeof(int) * count;
531 pInts = (int *)alloca(datalen);
532
533 startRequest;
534 for (int i = 0 ; i < count ; i++) {
535 int32_t t;
536
537 status = p.readInt32(&t);
538 pInts[i] = (int)t;
539 appendPrintBuf("%s%d,", printBuf, t);
540
541 if (status != NO_ERROR) {
542 goto invalid;
543 }
544 }
545 removeLastChar;
546 closeRequest;
547 printRequest(pRI->token, pRI->pCI->requestNumber);
548
549 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts),
550 datalen, pRI);
551
552#ifdef MEMSET_FREED
553 memset(pInts, 0, datalen);
554#endif
555
556 return;
557invalid:
558 invalidCommandBlock(pRI);
559 return;
560}
561
562
563/**
564 * Callee expects const RIL_SMS_WriteArgs *
565 * Payload is:
566 * int32_t status
567 * String pdu
568 */
569static void
570dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
571 RIL_SMS_WriteArgs args;
572 int32_t t;
573 status_t status;
574
575 memset (&args, 0, sizeof(args));
576
577 status = p.readInt32(&t);
578 args.status = (int)t;
579
580 args.pdu = strdupReadString(p);
581
582 if (status != NO_ERROR || args.pdu == NULL) {
583 goto invalid;
584 }
585
586 args.smsc = strdupReadString(p);
587
588 startRequest;
589 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
590 (char*)args.pdu, (char*)args.smsc);
591 closeRequest;
592 printRequest(pRI->token, pRI->pCI->requestNumber);
593
594 s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
595
596#ifdef MEMSET_FREED
597 memsetString (args.pdu);
598#endif
599
600 free (args.pdu);
601
602#ifdef MEMSET_FREED
603 memset(&args, 0, sizeof(args));
604#endif
605
606 return;
607invalid:
608 invalidCommandBlock(pRI);
609 return;
610}
611
612/**
613 * Callee expects const RIL_Dial *
614 * Payload is:
615 * String address
616 * int32_t clir
617 */
618static void
619dispatchDial (Parcel &p, RequestInfo *pRI) {
620 RIL_Dial dial;
621 RIL_UUS_Info uusInfo;
622 int32_t sizeOfDial;
623 int32_t t;
624 int32_t uusPresent;
625 status_t status;
626
627 memset (&dial, 0, sizeof(dial));
628
629 dial.address = strdupReadString(p);
630
631 status = p.readInt32(&t);
632 dial.clir = (int)t;
633
634 if (status != NO_ERROR || dial.address == NULL) {
635 goto invalid;
636 }
637
638 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
639 ALOGE("dispatchDial: s_callbacks.version < 3");
640 uusPresent = 0;
641 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
642 } else {
643 status = p.readInt32(&uusPresent);
644
645 if (status != NO_ERROR) {
646 goto invalid;
647 }
648
649 if (uusPresent == 0) {
650 /* Samsung hack */
651 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
652 uusInfo.uusType = (RIL_UUS_Type) 0;
653 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
654 uusInfo.uusData = NULL;
655 uusInfo.uusLength = 0;
656 dial.uusInfo = &uusInfo;
657 } else {
658 int32_t len;
659
660 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
661
662 status = p.readInt32(&t);
663 uusInfo.uusType = (RIL_UUS_Type) t;
664
665 status = p.readInt32(&t);
666 uusInfo.uusDcs = (RIL_UUS_DCS) t;
667
668 status = p.readInt32(&len);
669 if (status != NO_ERROR) {
670 goto invalid;
671 }
672
673 // The java code writes -1 for null arrays
674 if (((int) len) == -1) {
675 uusInfo.uusData = NULL;
676 len = 0;
677 } else {
678 uusInfo.uusData = (char*) p.readInplace(len);
679 }
680
681 uusInfo.uusLength = len;
682 dial.uusInfo = &uusInfo;
683 }
684 sizeOfDial = sizeof(dial);
685 }
686
687 startRequest;
688 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
689 if (uusPresent) {
690 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
691 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
692 dial.uusInfo->uusLength);
693 }
694 closeRequest;
695 printRequest(pRI->token, pRI->pCI->requestNumber);
696
697 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI);
698
699#ifdef MEMSET_FREED
700 memsetString (dial.address);
701#endif
702
703 free (dial.address);
704
705#ifdef MEMSET_FREED
706 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
707 memset(&dial, 0, sizeof(dial));
708#endif
709
710 return;
711invalid:
712 invalidCommandBlock(pRI);
713 return;
714}
715
716/**
717 * Callee expects const RIL_SIM_IO *
718 * Payload is:
719 * int32_t command
720 * int32_t fileid
721 * String path
722 * int32_t p1, p2, p3
723 * String data
724 * String pin2
725 * String aidPtr
726 */
727static void
728dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
729 RIL_SIM_IO_v6 simIO;
730 int32_t t;
731 status_t status;
732
733 memset (&simIO, 0, sizeof(simIO));
734
735 // note we only check status at the end
736
737 status = p.readInt32(&t);
738 simIO.command = (int)t;
739
740 status = p.readInt32(&t);
741 simIO.fileid = (int)t;
742
743 simIO.path = strdupReadString(p);
744
745 status = p.readInt32(&t);
746 simIO.p1 = (int)t;
747
748 status = p.readInt32(&t);
749 simIO.p2 = (int)t;
750
751 status = p.readInt32(&t);
752 simIO.p3 = (int)t;
753
754 simIO.data = strdupReadString(p);
755 simIO.pin2 = strdupReadString(p);
756 simIO.aidPtr = strdupReadString(p);
757
758 startRequest;
759 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
760 simIO.command, simIO.fileid, (char*)simIO.path,
761 simIO.p1, simIO.p2, simIO.p3,
762 (char*)simIO.data, (char*)simIO.pin2, simIO.aidPtr);
763 closeRequest;
764 printRequest(pRI->token, pRI->pCI->requestNumber);
765
766 if (status != NO_ERROR) {
767 goto invalid;
768 }
769
770 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, sizeof(simIO), pRI);
771
772#ifdef MEMSET_FREED
773 memsetString (simIO.path);
774 memsetString (simIO.data);
775 memsetString (simIO.pin2);
776 memsetString (simIO.aidPtr);
777#endif
778
779 free (simIO.path);
780 free (simIO.data);
781 free (simIO.pin2);
782 free (simIO.aidPtr);
783
784#ifdef MEMSET_FREED
785 memset(&simIO, 0, sizeof(simIO));
786#endif
787
788 return;
789invalid:
790 invalidCommandBlock(pRI);
791 return;
792}
793
794/**
795 * Callee expects const RIL_CallForwardInfo *
796 * Payload is:
797 * int32_t status/action
798 * int32_t reason
799 * int32_t serviceCode
800 * int32_t toa
801 * String number (0 length -> null)
802 * int32_t timeSeconds
803 */
804static void
805dispatchCallForward(Parcel &p, RequestInfo *pRI) {
806 RIL_CallForwardInfo cff;
807 int32_t t;
808 status_t status;
809
810 memset (&cff, 0, sizeof(cff));
811
812 // note we only check status at the end
813
814 status = p.readInt32(&t);
815 cff.status = (int)t;
816
817 status = p.readInt32(&t);
818 cff.reason = (int)t;
819
820 status = p.readInt32(&t);
821 cff.serviceClass = (int)t;
822
823 status = p.readInt32(&t);
824 cff.toa = (int)t;
825
826 cff.number = strdupReadString(p);
827
828 status = p.readInt32(&t);
829 cff.timeSeconds = (int)t;
830
831 if (status != NO_ERROR) {
832 goto invalid;
833 }
834
835 // special case: number 0-length fields is null
836
837 if (cff.number != NULL && strlen (cff.number) == 0) {
838 cff.number = NULL;
839 }
840
841 startRequest;
842 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
843 cff.status, cff.reason, cff.serviceClass, cff.toa,
844 (char*)cff.number, cff.timeSeconds);
845 closeRequest;
846 printRequest(pRI->token, pRI->pCI->requestNumber);
847
848 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
849
850#ifdef MEMSET_FREED
851 memsetString(cff.number);
852#endif
853
854 free (cff.number);
855
856#ifdef MEMSET_FREED
857 memset(&cff, 0, sizeof(cff));
858#endif
859
860 return;
861invalid:
862 invalidCommandBlock(pRI);
863 return;
864}
865
866
867static void
868dispatchRaw(Parcel &p, RequestInfo *pRI) {
869 int32_t len;
870 status_t status;
871 const void *data;
872
873 status = p.readInt32(&len);
874
875 if (status != NO_ERROR) {
876 goto invalid;
877 }
878
879 // The java code writes -1 for null arrays
880 if (((int)len) == -1) {
881 data = NULL;
882 len = 0;
883 }
884
885 data = p.readInplace(len);
886
887 startRequest;
888 appendPrintBuf("%sraw_size=%d", printBuf, len);
889 closeRequest;
890 printRequest(pRI->token, pRI->pCI->requestNumber);
891
892 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
893
894 return;
895invalid:
896 invalidCommandBlock(pRI);
897 return;
898}
899
900static void
901dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
902 RIL_CDMA_SMS_Message rcsm;
903 int32_t t;
904 uint8_t ut;
905 status_t status;
906 int32_t digitCount;
907 int digitLimit;
908
909 memset(&rcsm, 0, sizeof(rcsm));
910
911 status = p.readInt32(&t);
912 rcsm.uTeleserviceID = (int) t;
913
914 status = p.read(&ut,sizeof(ut));
915 rcsm.bIsServicePresent = (uint8_t) ut;
916
917 status = p.readInt32(&t);
918 rcsm.uServicecategory = (int) t;
919
920 status = p.readInt32(&t);
921 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
922
923 status = p.readInt32(&t);
924 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
925
926 status = p.readInt32(&t);
927 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
928
929 status = p.readInt32(&t);
930 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
931
932 status = p.read(&ut,sizeof(ut));
933 rcsm.sAddress.number_of_digits= (uint8_t) ut;
934
935 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
936 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
937 status = p.read(&ut,sizeof(ut));
938 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
939 }
940
941 status = p.readInt32(&t);
942 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
943
944 status = p.read(&ut,sizeof(ut));
945 rcsm.sSubAddress.odd = (uint8_t) ut;
946
947 status = p.read(&ut,sizeof(ut));
948 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
949
950 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
951 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
952 status = p.read(&ut,sizeof(ut));
953 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
954 }
955
956 status = p.readInt32(&t);
957 rcsm.uBearerDataLen = (int) t;
958
959 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
960 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
961 status = p.read(&ut, sizeof(ut));
962 rcsm.aBearerData[digitCount] = (uint8_t) ut;
963 }
964
965 if (status != NO_ERROR) {
966 goto invalid;
967 }
968
969 startRequest;
970 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
971 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
972 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
973 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
974 closeRequest;
975
976 printRequest(pRI->token, pRI->pCI->requestNumber);
977
978 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
979
980#ifdef MEMSET_FREED
981 memset(&rcsm, 0, sizeof(rcsm));
982#endif
983
984 return;
985
986invalid:
987 invalidCommandBlock(pRI);
988 return;
989}
990
991static void
992dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
993 RIL_CDMA_SMS_Ack rcsa;
994 int32_t t;
995 status_t status;
996 int32_t digitCount;
997
998 memset(&rcsa, 0, sizeof(rcsa));
999
1000 status = p.readInt32(&t);
1001 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1002
1003 status = p.readInt32(&t);
1004 rcsa.uSMSCauseCode = (int) t;
1005
1006 if (status != NO_ERROR) {
1007 goto invalid;
1008 }
1009
1010 startRequest;
1011 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1012 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1013 closeRequest;
1014
1015 printRequest(pRI->token, pRI->pCI->requestNumber);
1016
1017 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI);
1018
1019#ifdef MEMSET_FREED
1020 memset(&rcsa, 0, sizeof(rcsa));
1021#endif
1022
1023 return;
1024
1025invalid:
1026 invalidCommandBlock(pRI);
1027 return;
1028}
1029
1030static void
1031dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1032 int32_t t;
1033 status_t status;
1034 int32_t num;
1035
1036 status = p.readInt32(&num);
1037 if (status != NO_ERROR) {
1038 goto invalid;
1039 }
1040
1041 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1042 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
1043
1044 startRequest;
1045 for (int i = 0 ; i < num ; i++ ) {
1046 gsmBciPtrs[i] = &gsmBci[i];
1047
1048 status = p.readInt32(&t);
1049 gsmBci[i].fromServiceId = (int) t;
1050
1051 status = p.readInt32(&t);
1052 gsmBci[i].toServiceId = (int) t;
1053
1054 status = p.readInt32(&t);
1055 gsmBci[i].fromCodeScheme = (int) t;
1056
1057 status = p.readInt32(&t);
1058 gsmBci[i].toCodeScheme = (int) t;
1059
1060 status = p.readInt32(&t);
1061 gsmBci[i].selected = (uint8_t) t;
1062
1063 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1064 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1065 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1066 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1067 gsmBci[i].selected);
1068 }
1069 closeRequest;
1070
1071 if (status != NO_ERROR) {
1072 goto invalid;
1073 }
1074
1075 s_callbacks.onRequest(pRI->pCI->requestNumber,
1076 gsmBciPtrs,
1077 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1078 pRI);
1079
1080#ifdef MEMSET_FREED
1081 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1082 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
1083#endif
1084
1085 return;
1086
1087invalid:
1088 invalidCommandBlock(pRI);
1089 return;
1090}
1091
1092static void
1093dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1094 int32_t t;
1095 status_t status;
1096 int32_t num;
1097
1098 status = p.readInt32(&num);
1099 if (status != NO_ERROR) {
1100 goto invalid;
1101 }
1102
1103 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1104 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
1105
1106 startRequest;
1107 for (int i = 0 ; i < num ; i++ ) {
1108 cdmaBciPtrs[i] = &cdmaBci[i];
1109
1110 status = p.readInt32(&t);
1111 cdmaBci[i].service_category = (int) t;
1112
1113 status = p.readInt32(&t);
1114 cdmaBci[i].language = (int) t;
1115
1116 status = p.readInt32(&t);
1117 cdmaBci[i].selected = (uint8_t) t;
1118
1119 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1120 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1121 cdmaBci[i].language, cdmaBci[i].selected);
1122 }
1123 closeRequest;
1124
1125 if (status != NO_ERROR) {
1126 goto invalid;
1127 }
1128
1129 s_callbacks.onRequest(pRI->pCI->requestNumber,
1130 cdmaBciPtrs,
1131 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1132 pRI);
1133
1134#ifdef MEMSET_FREED
1135 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1136 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
1137#endif
1138
1139 return;
1140
1141invalid:
1142 invalidCommandBlock(pRI);
1143 return;
1144}
1145
1146static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1147 RIL_CDMA_SMS_WriteArgs rcsw;
1148 int32_t t;
1149 uint32_t ut;
1150 uint8_t uct;
1151 status_t status;
1152 int32_t digitCount;
1153
1154 memset(&rcsw, 0, sizeof(rcsw));
1155
1156 status = p.readInt32(&t);
1157 rcsw.status = t;
1158
1159 status = p.readInt32(&t);
1160 rcsw.message.uTeleserviceID = (int) t;
1161
1162 status = p.read(&uct,sizeof(uct));
1163 rcsw.message.bIsServicePresent = (uint8_t) uct;
1164
1165 status = p.readInt32(&t);
1166 rcsw.message.uServicecategory = (int) t;
1167
1168 status = p.readInt32(&t);
1169 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1170
1171 status = p.readInt32(&t);
1172 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1173
1174 status = p.readInt32(&t);
1175 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1176
1177 status = p.readInt32(&t);
1178 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1179
1180 status = p.read(&uct,sizeof(uct));
1181 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1182
1183 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1184 status = p.read(&uct,sizeof(uct));
1185 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1186 }
1187
1188 status = p.readInt32(&t);
1189 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1190
1191 status = p.read(&uct,sizeof(uct));
1192 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1193
1194 status = p.read(&uct,sizeof(uct));
1195 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1196
1197 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1198 status = p.read(&uct,sizeof(uct));
1199 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1200 }
1201
1202 status = p.readInt32(&t);
1203 rcsw.message.uBearerDataLen = (int) t;
1204
1205 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1206 status = p.read(&uct, sizeof(uct));
1207 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1208 }
1209
1210 if (status != NO_ERROR) {
1211 goto invalid;
1212 }
1213
1214 startRequest;
1215 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1216 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1217 message.sAddress.number_mode=%d, \
1218 message.sAddress.number_type=%d, ",
1219 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1220 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1221 rcsw.message.sAddress.number_mode,
1222 rcsw.message.sAddress.number_type);
1223 closeRequest;
1224
1225 printRequest(pRI->token, pRI->pCI->requestNumber);
1226
1227 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI);
1228
1229#ifdef MEMSET_FREED
1230 memset(&rcsw, 0, sizeof(rcsw));
1231#endif
1232
1233 return;
1234
1235invalid:
1236 invalidCommandBlock(pRI);
1237 return;
1238
1239}
1240
1241static int
1242blockingWrite(int fd, const void *buffer, size_t len) {
1243 size_t writeOffset = 0;
1244 const uint8_t *toWrite;
1245
1246 toWrite = (const uint8_t *)buffer;
1247
1248 while (writeOffset < len) {
1249 ssize_t written;
1250 do {
1251 written = write (fd, toWrite + writeOffset,
1252 len - writeOffset);
1253 } while (written < 0 && errno == EINTR);
1254
1255 if (written >= 0) {
1256 writeOffset += written;
1257 } else { // written < 0
1258 ALOGE ("RIL Response: unexpected error on write errno:%d", errno);
1259 close(fd);
1260 return -1;
1261 }
1262 }
1263
1264 return 0;
1265}
1266
1267static int
1268sendResponseRaw (const void *data, size_t dataSize) {
1269 int fd = s_fdCommand;
1270 int ret;
1271 uint32_t header;
1272
1273 if (s_fdCommand < 0) {
1274 return -1;
1275 }
1276
1277 if (dataSize > MAX_COMMAND_BYTES) {
1278 ALOGE("RIL: packet larger than %u (%u)",
1279 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1280
1281 return -1;
1282 }
1283
1284 pthread_mutex_lock(&s_writeMutex);
1285
1286 header = htonl(dataSize);
1287
1288 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1289
1290 if (ret < 0) {
1291 pthread_mutex_unlock(&s_writeMutex);
1292 return ret;
1293 }
1294
1295 ret = blockingWrite(fd, data, dataSize);
1296
1297 if (ret < 0) {
1298 pthread_mutex_unlock(&s_writeMutex);
1299 return ret;
1300 }
1301
1302 pthread_mutex_unlock(&s_writeMutex);
1303
1304 return 0;
1305}
1306
1307static int
1308sendResponse (Parcel &p) {
1309 printResponse;
1310 return sendResponseRaw(p.data(), p.dataSize());
1311}
1312
1313/** response is an int* pointing to an array of ints*/
1314
1315static int
1316responseInts(Parcel &p, void *response, size_t responselen) {
1317 int numInts;
1318
1319 if (response == NULL && responselen != 0) {
1320 ALOGE("invalid response: NULL");
1321 return RIL_ERRNO_INVALID_RESPONSE;
1322 }
1323 if (responselen % sizeof(int) != 0) {
1324 ALOGE("invalid response length %d expected multiple of %d\n",
1325 (int)responselen, (int)sizeof(int));
1326 return RIL_ERRNO_INVALID_RESPONSE;
1327 }
1328
1329 int *p_int = (int *) response;
1330
1331 numInts = responselen / sizeof(int *);
1332 p.writeInt32 (numInts);
1333
1334 /* each int*/
1335 startResponse;
1336 for (int i = 0 ; i < numInts ; i++) {
1337 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1338 p.writeInt32(p_int[i]);
1339 }
1340 removeLastChar;
1341 closeResponse;
1342
1343 return 0;
1344}
1345
1346static int
1347responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
1348 int numInts;
1349
1350 if (response == NULL && responselen != 0) {
1351 ALOGE("invalid response: NULL");
1352 return RIL_ERRNO_INVALID_RESPONSE;
1353 }
1354 if (responselen % sizeof(int) != 0) {
1355 ALOGE("invalid response length %d expected multiple of %d\n",
1356 (int)responselen, (int)sizeof(int));
1357 return RIL_ERRNO_INVALID_RESPONSE;
1358 }
1359
1360 int *p_int = (int *) response;
1361
1362 numInts = responselen / sizeof(int *);
1363 p.writeInt32 (numInts);
1364
1365 /* each int*/
1366 startResponse;
1367 for (int i = 0 ; i < numInts ; i++) {
1368 if (i == 0 && p_int[0] == 7) {
1369 ALOGE("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
1370 p_int[0] = 0;
1371 }
1372 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1373 p.writeInt32(p_int[i]);
1374 }
1375 removeLastChar;
1376 closeResponse;
1377
1378 return 0;
1379}
1380
1381/** response is a char **, pointing to an array of char *'s
1382 The parcel will begin with the version */
1383static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1384 p.writeInt32(version);
1385 return responseStrings(p, response, responselen);
1386}
1387
1388/** response is a char **, pointing to an array of char *'s */
1389static int responseStrings(Parcel &p, void *response, size_t responselen) {
1390 return responseStrings(p, response, responselen, false);
1391}
1392
1393static int responseStringsNetworks(Parcel &p, void *response, size_t responselen) {
1394 int numStrings;
1395 int inQANElements = 5;
1396 int outQANElements = 4;
1397
1398 if (response == NULL && responselen != 0) {
1399 ALOGE("invalid response: NULL");
1400 return RIL_ERRNO_INVALID_RESPONSE;
1401 }
1402 if (responselen % sizeof(char *) != 0) {
1403 ALOGE("invalid response length %d expected multiple of %d\n",
1404 (int)responselen, (int)sizeof(char *));
1405 return RIL_ERRNO_INVALID_RESPONSE;
1406 }
1407
1408 if (response == NULL) {
1409 p.writeInt32 (0);
1410 } else {
1411 char **p_cur = (char **) response;
1412
1413 numStrings = responselen / sizeof(char *);
1414 p.writeInt32 ((numStrings / inQANElements) * outQANElements);
1415
1416 /* each string*/
1417 startResponse;
1418 int j=0;
1419 for (int i = 0 ; i < numStrings ; i++) {
1420 /* Samsung is sending 5 elements, upper layer expects 4.
1421 Drop every 5th element here */
1422 if (j == outQANElements) {
1423 j=0;
1424 } else {
1425 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1426 writeStringToParcel (p, p_cur[i]);
1427 j++;
1428 }
1429 }
1430 removeLastChar;
1431 closeResponse;
1432 }
1433 return 0;
1434}
1435
1436/** response is a char **, pointing to an array of char *'s */
1437static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
1438 int numStrings;
1439
1440 if (response == NULL && responselen != 0) {
1441 ALOGE("invalid response: NULL");
1442 return RIL_ERRNO_INVALID_RESPONSE;
1443 }
1444 if (responselen % sizeof(char *) != 0) {
1445 ALOGE("invalid response length %d expected multiple of %d\n",
1446 (int)responselen, (int)sizeof(char *));
1447 return RIL_ERRNO_INVALID_RESPONSE;
1448 }
1449
1450 if (response == NULL) {
1451 p.writeInt32 (0);
1452 } else {
1453 char **p_cur = (char **) response;
1454
1455 numStrings = responselen / sizeof(char *);
1456 p.writeInt32 (numStrings);
1457
1458 /* each string*/
1459 startResponse;
1460 for (int i = 0 ; i < numStrings ; i++) {
1461 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1462 writeStringToParcel (p, p_cur[i]);
1463 }
1464 removeLastChar;
1465 closeResponse;
1466 }
1467 return 0;
1468}
1469
1470/**
1471 * NULL strings are accepted
1472 * FIXME currently ignores responselen
1473 */
1474static int responseString(Parcel &p, void *response, size_t responselen) {
1475 /* one string only */
1476 startResponse;
1477 appendPrintBuf("%s%s", printBuf, (char*)response);
1478 closeResponse;
1479
1480 writeStringToParcel(p, (const char *)response);
1481
1482 return 0;
1483}
1484
1485static int responseVoid(Parcel &p, void *response, size_t responselen) {
1486 startResponse;
1487 removeLastChar;
1488 return 0;
1489}
1490
1491static int responseCallList(Parcel &p, void *response, size_t responselen) {
1492 int num;
1493
1494 if (response == NULL && responselen != 0) {
1495 ALOGE("invalid response: NULL");
1496 return RIL_ERRNO_INVALID_RESPONSE;
1497 }
1498
1499 if (responselen % sizeof (RIL_Call *) != 0) {
1500 ALOGE("invalid response length %d expected multiple of %d\n",
1501 (int)responselen, (int)sizeof (RIL_Call *));
1502 return RIL_ERRNO_INVALID_RESPONSE;
1503 }
1504
1505 startResponse;
1506 /* number of call info's */
1507 num = responselen / sizeof(RIL_Call *);
1508 p.writeInt32(num);
1509
1510 for (int i = 0 ; i < num ; i++) {
1511 RIL_Call *p_cur = ((RIL_Call **) response)[i];
1512 /* each call info */
1513 p.writeInt32(p_cur->state);
1514 p.writeInt32(p_cur->index);
1515 p.writeInt32(p_cur->toa);
1516 p.writeInt32(p_cur->isMpty);
1517 p.writeInt32(p_cur->isMT);
1518 p.writeInt32(p_cur->als);
1519 p.writeInt32(p_cur->isVoice);
1520 p.writeInt32(p_cur->isVoicePrivacy);
1521 writeStringToParcel(p, p_cur->number);
1522 p.writeInt32(p_cur->numberPresentation);
1523 writeStringToParcel(p, p_cur->name);
1524 p.writeInt32(p_cur->namePresentation);
1525 p.writeInt32(0); /* UUS Information is absent */
1526
1527 appendPrintBuf("%s[id=%d,%s,toa=%d,",
1528 printBuf,
1529 p_cur->index,
1530 callStateToString(p_cur->state),
1531 p_cur->toa);
1532 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
1533 printBuf,
1534 (p_cur->isMpty)?"conf":"norm",
1535 (p_cur->isMT)?"mt":"mo",
1536 p_cur->als,
1537 (p_cur->isVoice)?"voc":"nonvoc",
1538 (p_cur->isVoicePrivacy)?"evp":"noevp");
1539 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
1540 printBuf,
1541 p_cur->number,
1542 p_cur->numberPresentation,
1543 p_cur->name,
1544 p_cur->namePresentation);
1545 }
1546 removeLastChar;
1547 closeResponse;
1548
1549 return 0;
1550}
1551
1552static int responseSMS(Parcel &p, void *response, size_t responselen) {
1553 if (response == NULL) {
1554 ALOGE("invalid response: NULL");
1555 return RIL_ERRNO_INVALID_RESPONSE;
1556 }
1557
1558 if (responselen != sizeof (RIL_SMS_Response) ) {
1559 ALOGE("invalid response length %d expected %d",
1560 (int)responselen, (int)sizeof (RIL_SMS_Response));
1561 return RIL_ERRNO_INVALID_RESPONSE;
1562 }
1563
1564 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1565
1566 p.writeInt32(p_cur->messageRef);
1567 writeStringToParcel(p, p_cur->ackPDU);
1568 p.writeInt32(p_cur->errorCode);
1569
1570 startResponse;
1571 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
1572 (char*)p_cur->ackPDU, p_cur->errorCode);
1573 closeResponse;
1574
1575 return 0;
1576}
1577
1578static int responseDataCallList(Parcel &p, void *response, size_t responselen)
1579{
1580 // Write version
1581 p.writeInt32(s_callbacks.version);
1582
1583 if (response == NULL && responselen != 0) {
1584 ALOGE("invalid response: NULL");
1585 return RIL_ERRNO_INVALID_RESPONSE;
1586 }
1587
1588 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
1589 ALOGE("invalid response length %d expected multiple of %d",
1590 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
1591 return RIL_ERRNO_INVALID_RESPONSE;
1592 }
1593
1594 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
1595 p.writeInt32(num);
1596
1597 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
1598 startResponse;
1599
1600 for (int i = 0; i < num; i++) {
1601 p.writeInt32((int)p_cur[i].status);
1602 p.writeInt32(p_cur[i].suggestedRetryTime);
1603 p.writeInt32(p_cur[i].cid);
1604 p.writeInt32(p_cur[i].active);
1605 writeStringToParcel(p, p_cur[i].type);
1606 writeStringToParcel(p, p_cur[i].ifname);
1607 writeStringToParcel(p, p_cur[i].addresses);
1608 writeStringToParcel(p, p_cur[i].dnses);
1609 writeStringToParcel(p, p_cur[i].gateways);
1610 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
1611 p_cur[i].status,
1612 p_cur[i].suggestedRetryTime,
1613 p_cur[i].cid,
1614 (p_cur[i].active==0)?"down":"up",
1615 (char*)p_cur[i].type,
1616 (char*)p_cur[i].ifname,
1617 (char*)p_cur[i].addresses,
1618 (char*)p_cur[i].dnses,
1619 (char*)p_cur[i].gateways);
1620 }
1621 removeLastChar;
1622 closeResponse;
1623
1624 return 0;
1625}
1626
1627static int responseRaw(Parcel &p, void *response, size_t responselen) {
1628 if (response == NULL && responselen != 0) {
1629 ALOGE("invalid response: NULL with responselen != 0");
1630 return RIL_ERRNO_INVALID_RESPONSE;
1631 }
1632
1633 // The java code reads -1 size as null byte array
1634 if (response == NULL) {
1635 p.writeInt32(-1);
1636 } else {
1637 p.writeInt32(responselen);
1638 p.write(response, responselen);
1639 }
1640
1641 return 0;
1642}
1643
1644
1645static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
1646 if (response == NULL) {
1647 ALOGE("invalid response: NULL");
1648 return RIL_ERRNO_INVALID_RESPONSE;
1649 }
1650
1651 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
1652 ALOGE("invalid response length was %d expected %d",
1653 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
1654 return RIL_ERRNO_INVALID_RESPONSE;
1655 }
1656
1657 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
1658 p.writeInt32(p_cur->sw1);
1659 p.writeInt32(p_cur->sw2);
1660 writeStringToParcel(p, p_cur->simResponse);
1661
1662 startResponse;
1663 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
1664 (char*)p_cur->simResponse);
1665 closeResponse;
1666
1667
1668 return 0;
1669}
1670
1671static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
1672 int num;
1673
1674 if (response == NULL && responselen != 0) {
1675 ALOGE("invalid response: NULL");
1676 return RIL_ERRNO_INVALID_RESPONSE;
1677 }
1678
1679 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
1680 ALOGE("invalid response length %d expected multiple of %d",
1681 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
1682 return RIL_ERRNO_INVALID_RESPONSE;
1683 }
1684
1685 /* number of call info's */
1686 num = responselen / sizeof(RIL_CallForwardInfo *);
1687 p.writeInt32(num);
1688
1689 startResponse;
1690 for (int i = 0 ; i < num ; i++) {
1691 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
1692
1693 p.writeInt32(p_cur->status);
1694 p.writeInt32(p_cur->reason);
1695 p.writeInt32(p_cur->serviceClass);
1696 p.writeInt32(p_cur->toa);
1697 writeStringToParcel(p, p_cur->number);
1698 p.writeInt32(p_cur->timeSeconds);
1699 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
1700 (p_cur->status==1)?"enable":"disable",
1701 p_cur->reason, p_cur->serviceClass, p_cur->toa,
1702 (char*)p_cur->number,
1703 p_cur->timeSeconds);
1704 }
1705 removeLastChar;
1706 closeResponse;
1707
1708 return 0;
1709}
1710
1711static int responseSsn(Parcel &p, void *response, size_t responselen) {
1712 if (response == NULL) {
1713 ALOGE("invalid response: NULL");
1714 return RIL_ERRNO_INVALID_RESPONSE;
1715 }
1716
1717 if (responselen != sizeof(RIL_SuppSvcNotification)) {
1718 ALOGE("invalid response length was %d expected %d",
1719 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
1720 return RIL_ERRNO_INVALID_RESPONSE;
1721 }
1722
1723 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
1724 p.writeInt32(p_cur->notificationType);
1725 p.writeInt32(p_cur->code);
1726 p.writeInt32(p_cur->index);
1727 p.writeInt32(p_cur->type);
1728 writeStringToParcel(p, p_cur->number);
1729
1730 startResponse;
1731 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
1732 (p_cur->notificationType==0)?"mo":"mt",
1733 p_cur->code, p_cur->index, p_cur->type,
1734 (char*)p_cur->number);
1735 closeResponse;
1736
1737 return 0;
1738}
1739
1740static int responseCellList(Parcel &p, void *response, size_t responselen) {
1741 int num;
1742
1743 if (response == NULL && responselen != 0) {
1744 ALOGE("invalid response: NULL");
1745 return RIL_ERRNO_INVALID_RESPONSE;
1746 }
1747
1748 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
1749 ALOGE("invalid response length %d expected multiple of %d\n",
1750 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
1751 return RIL_ERRNO_INVALID_RESPONSE;
1752 }
1753
1754 startResponse;
1755 /* number of records */
1756 num = responselen / sizeof(RIL_NeighboringCell *);
1757 p.writeInt32(num);
1758
1759 for (int i = 0 ; i < num ; i++) {
1760 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
1761
1762 p.writeInt32(p_cur->rssi);
1763 writeStringToParcel (p, p_cur->cid);
1764
1765 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
1766 p_cur->cid, p_cur->rssi);
1767 }
1768 removeLastChar;
1769 closeResponse;
1770
1771 return 0;
1772}
1773
1774/**
1775 * Marshall the signalInfoRecord into the parcel if it exists.
1776 */
1777static void marshallSignalInfoRecord(Parcel &p,
1778 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
1779 p.writeInt32(p_signalInfoRecord.isPresent);
1780 p.writeInt32(p_signalInfoRecord.signalType);
1781 p.writeInt32(p_signalInfoRecord.alertPitch);
1782 p.writeInt32(p_signalInfoRecord.signal);
1783}
1784
1785static int responseCdmaInformationRecords(Parcel &p,
1786 void *response, size_t responselen) {
1787 int num;
1788 char* string8 = NULL;
1789 int buffer_lenght;
1790 RIL_CDMA_InformationRecord *infoRec;
1791
1792 if (response == NULL && responselen != 0) {
1793 ALOGE("invalid response: NULL");
1794 return RIL_ERRNO_INVALID_RESPONSE;
1795 }
1796
1797 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
1798 ALOGE("invalid response length %d expected multiple of %d\n",
1799 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
1800 return RIL_ERRNO_INVALID_RESPONSE;
1801 }
1802
1803 RIL_CDMA_InformationRecords *p_cur =
1804 (RIL_CDMA_InformationRecords *) response;
1805 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
1806
1807 startResponse;
1808 p.writeInt32(num);
1809
1810 for (int i = 0 ; i < num ; i++) {
1811 infoRec = &p_cur->infoRec[i];
1812 p.writeInt32(infoRec->name);
1813 switch (infoRec->name) {
1814 case RIL_CDMA_DISPLAY_INFO_REC:
1815 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
1816 if (infoRec->rec.display.alpha_len >
1817 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
1818 ALOGE("invalid display info response length %d \
1819 expected not more than %d\n",
1820 (int)infoRec->rec.display.alpha_len,
1821 CDMA_ALPHA_INFO_BUFFER_LENGTH);
1822 return RIL_ERRNO_INVALID_RESPONSE;
1823 }
1824 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
1825 * sizeof(char) );
1826 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
1827 string8[i] = infoRec->rec.display.alpha_buf[i];
1828 }
1829 string8[(int)infoRec->rec.display.alpha_len] = '\0';
1830 writeStringToParcel(p, (const char*)string8);
1831 free(string8);
1832 string8 = NULL;
1833 break;
1834 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
1835 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
1836 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
1837 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
1838 ALOGE("invalid display info response length %d \
1839 expected not more than %d\n",
1840 (int)infoRec->rec.number.len,
1841 CDMA_NUMBER_INFO_BUFFER_LENGTH);
1842 return RIL_ERRNO_INVALID_RESPONSE;
1843 }
1844 string8 = (char*) malloc((infoRec->rec.number.len + 1)
1845 * sizeof(char) );
1846 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
1847 string8[i] = infoRec->rec.number.buf[i];
1848 }
1849 string8[(int)infoRec->rec.number.len] = '\0';
1850 writeStringToParcel(p, (const char*)string8);
1851 free(string8);
1852 string8 = NULL;
1853 p.writeInt32(infoRec->rec.number.number_type);
1854 p.writeInt32(infoRec->rec.number.number_plan);
1855 p.writeInt32(infoRec->rec.number.pi);
1856 p.writeInt32(infoRec->rec.number.si);
1857 break;
1858 case RIL_CDMA_SIGNAL_INFO_REC:
1859 p.writeInt32(infoRec->rec.signal.isPresent);
1860 p.writeInt32(infoRec->rec.signal.signalType);
1861 p.writeInt32(infoRec->rec.signal.alertPitch);
1862 p.writeInt32(infoRec->rec.signal.signal);
1863
1864 appendPrintBuf("%sisPresent=%X, signalType=%X, \
1865 alertPitch=%X, signal=%X, ",
1866 printBuf, (int)infoRec->rec.signal.isPresent,
1867 (int)infoRec->rec.signal.signalType,
1868 (int)infoRec->rec.signal.alertPitch,
1869 (int)infoRec->rec.signal.signal);
1870 removeLastChar;
1871 break;
1872 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
1873 if (infoRec->rec.redir.redirectingNumber.len >
1874 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
1875 ALOGE("invalid display info response length %d \
1876 expected not more than %d\n",
1877 (int)infoRec->rec.redir.redirectingNumber.len,
1878 CDMA_NUMBER_INFO_BUFFER_LENGTH);
1879 return RIL_ERRNO_INVALID_RESPONSE;
1880 }
1881 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
1882 .len + 1) * sizeof(char) );
1883 for (int i = 0;
1884 i < infoRec->rec.redir.redirectingNumber.len;
1885 i++) {
1886 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
1887 }
1888 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
1889 writeStringToParcel(p, (const char*)string8);
1890 free(string8);
1891 string8 = NULL;
1892 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
1893 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
1894 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
1895 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
1896 p.writeInt32(infoRec->rec.redir.redirectingReason);
1897 break;
1898 case RIL_CDMA_LINE_CONTROL_INFO_REC:
1899 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
1900 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
1901 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
1902 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
1903
1904 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
1905 lineCtrlToggle=%d, lineCtrlReverse=%d, \
1906 lineCtrlPowerDenial=%d, ", printBuf,
1907 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
1908 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
1909 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
1910 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
1911 removeLastChar;
1912 break;
1913 case RIL_CDMA_T53_CLIR_INFO_REC:
1914 p.writeInt32((int)(infoRec->rec.clir.cause));
1915
1916 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
1917 removeLastChar;
1918 break;
1919 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
1920 p.writeInt32(infoRec->rec.audioCtrl.upLink);
1921 p.writeInt32(infoRec->rec.audioCtrl.downLink);
1922
1923 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
1924 infoRec->rec.audioCtrl.upLink,
1925 infoRec->rec.audioCtrl.downLink);
1926 removeLastChar;
1927 break;
1928 case RIL_CDMA_T53_RELEASE_INFO_REC:
1929 // TODO(Moto): See David Krause, he has the answer:)
1930 ALOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
1931 return RIL_ERRNO_INVALID_RESPONSE;
1932 default:
1933 ALOGE("Incorrect name value");
1934 return RIL_ERRNO_INVALID_RESPONSE;
1935 }
1936 }
1937 closeResponse;
1938
1939 return 0;
1940}
1941
1942static int responseRilSignalStrength(Parcel &p,
1943 void *response, size_t responselen) {
1944
1945 int gsmSignalStrength;
1946
1947 if (response == NULL && responselen != 0) {
1948 ALOGE("invalid response: NULL");
1949 return RIL_ERRNO_INVALID_RESPONSE;
1950 }
1951
1952 ALOGE("responseRilSignalStrength()");
1953
1954 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
1955 RIL_SignalStrength_v6 *p_cur = ((RIL_SignalStrength_v6 *) response);
1956
1957 /* gsmSignalStrength */
1958 ALOGD("gsmSignalStrength (raw)=%d", p_cur->GW_SignalStrength.signalStrength);
1959 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
1960 ALOGD("gsmSignalStrength (corrected)=%d", gsmSignalStrength);
1961
1962 /*
1963 * if gsmSignalStrength isn't a valid value, use cdmaDbm as fallback.
1964 * This is needed for old modem firmwares.
1965 */
1966 if (gsmSignalStrength < 0 || (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
1967 ALOGD("gsmSignalStrength-fallback (raw)=%d", p_cur->CDMA_SignalStrength.dbm);
1968 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
1969 if (gsmSignalStrength < 0) {
1970 gsmSignalStrength = 99;
1971 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
1972 gsmSignalStrength = 31;
1973 }
1974 ALOGD("gsmSignalStrength-fallback (corrected)=%d", gsmSignalStrength);
1975 }
1976 p.writeInt32(gsmSignalStrength);
1977
1978 /* gsmBitErrorRate */
1979 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
1980 /* cdmaDbm */
1981 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
1982 /* cdmaEcio */
1983 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
1984 /* evdoDbm */
1985 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
1986 /* evdoEcio */
1987 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
1988 /* evdoSnr */
1989 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
1990
1991 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
1992 /* lteSignalStrength */
1993 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
1994
1995 /*
1996 * ril version <=6 receives negative values for rsrp
1997 * workaround for backward compatibility
1998 */
1999 p_cur->LTE_SignalStrength.rsrp =
2000 ((s_callbacks.version <= 6) && (p_cur->LTE_SignalStrength.rsrp < 0 )) ?
2001 -(p_cur->LTE_SignalStrength.rsrp) : p_cur->LTE_SignalStrength.rsrp;
2002
2003 /* lteRsrp */
2004 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2005 /* lteRsrq */
2006 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2007 /* lteRssnr */
2008 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2009 /* lteCqi */
2010 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2011
2012 } else {
2013 memset(&p_cur->LTE_SignalStrength, sizeof (RIL_LTE_SignalStrength), 0);
2014 }
2015
2016 startResponse;
2017 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
2018 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2019 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2020 EVDO_SS.signalNoiseRatio=%d,\
2021 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
2022 LTE_SS.rssnr=%d,LTE_SS.cqi=%d]",
2023 printBuf,
2024 gsmSignalStrength,
2025 p_cur->GW_SignalStrength.bitErrorRate,
2026 p_cur->CDMA_SignalStrength.dbm,
2027 p_cur->CDMA_SignalStrength.ecio,
2028 p_cur->EVDO_SignalStrength.dbm,
2029 p_cur->EVDO_SignalStrength.ecio,
2030 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2031 p_cur->LTE_SignalStrength.signalStrength,
2032 p_cur->LTE_SignalStrength.rsrp,
2033 p_cur->LTE_SignalStrength.rsrq,
2034 p_cur->LTE_SignalStrength.rssnr,
2035 p_cur->LTE_SignalStrength.cqi);
2036 closeResponse;
2037
2038 } else {
2039 ALOGE("invalid response length");
2040 return RIL_ERRNO_INVALID_RESPONSE;
2041 }
2042
2043 return 0;
2044}
2045
2046static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2047 if ((response == NULL) || (responselen == 0)) {
2048 return responseVoid(p, response, responselen);
2049 } else {
2050 return responseCdmaSignalInfoRecord(p, response, responselen);
2051 }
2052}
2053
2054static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2055 if (response == NULL || responselen == 0) {
2056 ALOGE("invalid response: NULL");
2057 return RIL_ERRNO_INVALID_RESPONSE;
2058 }
2059
2060 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
2061 ALOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
2062 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2063 return RIL_ERRNO_INVALID_RESPONSE;
2064 }
2065
2066 startResponse;
2067
2068 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2069 marshallSignalInfoRecord(p, *p_cur);
2070
2071 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2072 signal=%d]",
2073 printBuf,
2074 p_cur->isPresent,
2075 p_cur->signalType,
2076 p_cur->alertPitch,
2077 p_cur->signal);
2078
2079 closeResponse;
2080 return 0;
2081}
2082
2083static int responseCdmaCallWaiting(Parcel &p, void *response,
2084 size_t responselen) {
2085 if (response == NULL && responselen != 0) {
2086 ALOGE("invalid response: NULL");
2087 return RIL_ERRNO_INVALID_RESPONSE;
2088 }
2089
2090 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
2091 ALOGW("Upgrade to ril version %d\n", RIL_VERSION);
2092 }
2093
2094 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2095
2096 writeStringToParcel(p, p_cur->number);
2097 p.writeInt32(p_cur->numberPresentation);
2098 writeStringToParcel(p, p_cur->name);
2099 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2100
2101 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2102 p.writeInt32(p_cur->number_type);
2103 p.writeInt32(p_cur->number_plan);
2104 } else {
2105 p.writeInt32(0);
2106 p.writeInt32(0);
2107 }
2108
2109 startResponse;
2110 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2111 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2112 signal=%d,number_type=%d,number_plan=%d]",
2113 printBuf,
2114 p_cur->number,
2115 p_cur->numberPresentation,
2116 p_cur->name,
2117 p_cur->signalInfoRecord.isPresent,
2118 p_cur->signalInfoRecord.signalType,
2119 p_cur->signalInfoRecord.alertPitch,
2120 p_cur->signalInfoRecord.signal,
2121 p_cur->number_type,
2122 p_cur->number_plan);
2123 closeResponse;
2124
2125 return 0;
2126}
2127
2128static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2129 if (response == NULL && responselen != 0) {
2130 ALOGE("responseSimRefresh: invalid response: NULL");
2131 return RIL_ERRNO_INVALID_RESPONSE;
2132 }
2133
2134 startResponse;
2135 if (s_callbacks.version == 7) {
2136 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2137 p.writeInt32(p_cur->result);
2138 p.writeInt32(p_cur->ef_id);
2139 writeStringToParcel(p, p_cur->aid);
2140
2141 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2142 printBuf,
2143 p_cur->result,
2144 p_cur->ef_id,
2145 p_cur->aid);
2146 } else {
2147 int *p_cur = ((int *) response);
2148 p.writeInt32(p_cur[0]);
2149 p.writeInt32(p_cur[1]);
2150 writeStringToParcel(p, NULL);
2151
2152 appendPrintBuf("%sresult=%d, ef_id=%d",
2153 printBuf,
2154 p_cur[0],
2155 p_cur[1]);
2156 }
2157 closeResponse;
2158
2159 return 0;
2160}
2161
2162static void triggerEvLoop() {
2163 int ret;
2164 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
2165 /* trigger event loop to wakeup. No reason to do this,
2166 * if we're in the event loop thread */
2167 do {
2168 ret = write (s_fdWakeupWrite, " ", 1);
2169 } while (ret < 0 && errno == EINTR);
2170 }
2171}
2172
2173static void rilEventAddWakeup(struct ril_event *ev) {
2174 ril_event_add(ev);
2175 triggerEvLoop();
2176}
2177
2178static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
2179 p.writeInt32(num_apps);
2180 startResponse;
2181 for (int i = 0; i < num_apps; i++) {
2182 p.writeInt32(appStatus[i].app_type);
2183 p.writeInt32(appStatus[i].app_state);
2184 p.writeInt32(appStatus[i].perso_substate);
2185 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
2186 writeStringToParcel(p, (const char*)
2187 (appStatus[i].app_label_ptr));
2188 p.writeInt32(appStatus[i].pin1_replaced);
2189 p.writeInt32(appStatus[i].pin1);
2190 p.writeInt32(appStatus[i].pin2);
2191 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
2192 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
2193 printBuf,
2194 appStatus[i].app_type,
2195 appStatus[i].app_state,
2196 appStatus[i].perso_substate,
2197 appStatus[i].aid_ptr,
2198 appStatus[i].app_label_ptr,
2199 appStatus[i].pin1_replaced,
2200 appStatus[i].pin1,
2201 appStatus[i].pin2);
2202 }
2203 closeResponse;
2204}
2205
2206static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
2207 if (response == NULL && responselen != 0) {
2208 ALOGE("invalid response: NULL");
2209 return RIL_ERRNO_INVALID_RESPONSE;
2210 }
2211
2212 if (responselen == sizeof (RIL_CardStatus_v6)) {
2213 ALOGE("RIL_CardStatus_v6");
2214 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
2215
2216 p.writeInt32(p_cur->card_state);
2217 p.writeInt32(p_cur->universal_pin_state);
2218 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2219 p.writeInt32(p_cur->cdma_subscription_app_index);
2220 p.writeInt32(p_cur->ims_subscription_app_index);
2221
2222 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2223 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
2224 ALOGE("RIL_CardStatus_v5");
2225 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
2226
2227 p.writeInt32(p_cur->card_state);
2228 p.writeInt32(p_cur->universal_pin_state);
2229 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2230 p.writeInt32(p_cur->cdma_subscription_app_index);
2231 p.writeInt32(-1);
2232
2233 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2234 } else {
2235 ALOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
2236 ALOGE("responselen=%d", responselen);
2237 ALOGE("RIL_CardStatus_v5=%d", sizeof (RIL_CardStatus_v5));
2238 ALOGE("RIL_CardStatus_v6=%d", sizeof (RIL_CardStatus_v6));
2239 return RIL_ERRNO_INVALID_RESPONSE;
2240 }
2241
2242 return 0;
2243}
2244
2245static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2246 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
2247 p.writeInt32(num);
2248
2249 startResponse;
2250 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
2251 (RIL_GSM_BroadcastSmsConfigInfo **) response;
2252 for (int i = 0; i < num; i++) {
2253 p.writeInt32(p_cur[i]->fromServiceId);
2254 p.writeInt32(p_cur[i]->toServiceId);
2255 p.writeInt32(p_cur[i]->fromCodeScheme);
2256 p.writeInt32(p_cur[i]->toCodeScheme);
2257 p.writeInt32(p_cur[i]->selected);
2258
2259 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
2260 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
2261 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
2262 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
2263 p_cur[i]->selected);
2264 }
2265 closeResponse;
2266
2267 return 0;
2268}
2269
2270static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2271 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
2272 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
2273
2274 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
2275 p.writeInt32(num);
2276
2277 startResponse;
2278 for (int i = 0 ; i < num ; i++ ) {
2279 p.writeInt32(p_cur[i]->service_category);
2280 p.writeInt32(p_cur[i]->language);
2281 p.writeInt32(p_cur[i]->selected);
2282
2283 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
2284 selected =%d], ",
2285 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
2286 p_cur[i]->selected);
2287 }
2288 closeResponse;
2289
2290 return 0;
2291}
2292
2293static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
2294 int num;
2295 int digitCount;
2296 int digitLimit;
2297 uint8_t uct;
2298 void* dest;
2299
2300 ALOGD("Inside responseCdmaSms");
2301
2302 if (response == NULL && responselen != 0) {
2303 ALOGE("invalid response: NULL");
2304 return RIL_ERRNO_INVALID_RESPONSE;
2305 }
2306
2307 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
2308 ALOGE("invalid response length was %d expected %d",
2309 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
2310 return RIL_ERRNO_INVALID_RESPONSE;
2311 }
2312
2313 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
2314 p.writeInt32(p_cur->uTeleserviceID);
2315 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
2316 p.writeInt32(p_cur->uServicecategory);
2317 p.writeInt32(p_cur->sAddress.digit_mode);
2318 p.writeInt32(p_cur->sAddress.number_mode);
2319 p.writeInt32(p_cur->sAddress.number_type);
2320 p.writeInt32(p_cur->sAddress.number_plan);
2321 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
2322 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2323 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2324 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
2325 }
2326
2327 p.writeInt32(p_cur->sSubAddress.subaddressType);
2328 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
2329 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
2330 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2331 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2332 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
2333 }
2334
2335 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2336 p.writeInt32(p_cur->uBearerDataLen);
2337 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2338 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
2339 }
2340
2341 startResponse;
2342 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
2343 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
2344 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
2345 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
2346 closeResponse;
2347
2348 return 0;
2349}
2350
2351/**
2352 * A write on the wakeup fd is done just to pop us out of select()
2353 * We empty the buffer here and then ril_event will reset the timers on the
2354 * way back down
2355 */
2356static void processWakeupCallback(int fd, short flags, void *param) {
2357 char buff[16];
2358 int ret;
2359
2360 ALOGV("processWakeupCallback");
2361
2362 /* empty our wakeup socket out */
2363 do {
2364 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
2365 } while (ret > 0 || (ret < 0 && errno == EINTR));
2366}
2367
2368static void onCommandsSocketClosed() {
2369 int ret;
2370 RequestInfo *p_cur;
2371
2372 /* mark pending requests as "cancelled" so we dont report responses */
2373
2374 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
2375 assert (ret == 0);
2376
2377 p_cur = s_pendingRequests;
2378
2379 for (p_cur = s_pendingRequests
2380 ; p_cur != NULL
2381 ; p_cur = p_cur->p_next
2382 ) {
2383 p_cur->cancelled = 1;
2384 }
2385
2386 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
2387 assert (ret == 0);
2388}
2389
2390static void processCommandsCallback(int fd, short flags, void *param) {
2391 RecordStream *p_rs;
2392 void *p_record;
2393 size_t recordlen;
2394 int ret;
2395
2396 assert(fd == s_fdCommand);
2397
2398 p_rs = (RecordStream *)param;
2399
2400 for (;;) {
2401 /* loop until EAGAIN/EINTR, end of stream, or other error */
2402 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
2403
2404 if (ret == 0 && p_record == NULL) {
2405 /* end-of-stream */
2406 break;
2407 } else if (ret < 0) {
2408 break;
2409 } else if (ret == 0) { /* && p_record != NULL */
2410 processCommandBuffer(p_record, recordlen);
2411 }
2412 }
2413
2414 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
2415 /* fatal error or end-of-stream */
2416 if (ret != 0) {
2417 ALOGE("error on reading command socket errno:%d\n", errno);
2418 } else {
2419 ALOGW("EOS. Closing command socket.");
2420 }
2421
2422 close(s_fdCommand);
2423 s_fdCommand = -1;
2424
2425 ril_event_del(&s_commands_event);
2426
2427 record_stream_free(p_rs);
2428
2429 /* start listening for new connections again */
2430 rilEventAddWakeup(&s_listen_event);
2431
2432 onCommandsSocketClosed();
2433 }
2434}
2435
2436
2437static void onNewCommandConnect() {
2438 // Inform we are connected and the ril version
2439 int rilVer = s_callbacks.version;
2440 RIL_onUnsolicitedResponse(RIL_UNSOL_RIL_CONNECTED,
2441 &rilVer, sizeof(rilVer));
2442
2443 // implicit radio state changed
2444 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
2445 NULL, 0);
2446
2447 // Send last NITZ time data, in case it was missed
2448 if (s_lastNITZTimeData != NULL) {
2449 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
2450
2451 free(s_lastNITZTimeData);
2452 s_lastNITZTimeData = NULL;
2453 }
2454
2455 // Get version string
2456 if (s_callbacks.getVersion != NULL) {
2457 const char *version;
2458 version = s_callbacks.getVersion();
2459 ALOGI("RIL Daemon version: %s\n", version);
2460
2461 property_set(PROPERTY_RIL_IMPL, version);
2462 } else {
2463 ALOGI("RIL Daemon version: unavailable\n");
2464 property_set(PROPERTY_RIL_IMPL, "unavailable");
2465 }
2466
2467}
2468
2469static void listenCallback (int fd, short flags, void *param) {
2470 int ret;
2471 int err;
2472 int is_phone_socket;
2473 RecordStream *p_rs;
2474
2475 struct sockaddr_un peeraddr;
2476 socklen_t socklen = sizeof (peeraddr);
2477
2478 struct ucred creds;
2479 socklen_t szCreds = sizeof(creds);
2480
2481 struct passwd *pwd = NULL;
2482
2483 assert (s_fdCommand < 0);
2484 assert (fd == s_fdListen);
2485
2486 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
2487
2488 if (s_fdCommand < 0 ) {
2489 ALOGE("Error on accept() errno:%d", errno);
2490 /* start listening for new connections again */
2491 rilEventAddWakeup(&s_listen_event);
2492 return;
2493 }
2494
2495 /* check the credential of the other side and only accept socket from
2496 * phone process
2497 */
2498 errno = 0;
2499 is_phone_socket = 0;
2500
2501 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
2502
2503 if (err == 0 && szCreds > 0) {
2504 errno = 0;
2505 pwd = getpwuid(creds.uid);
2506 if (pwd != NULL) {
2507 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
2508 is_phone_socket = 1;
2509 } else {
2510 ALOGE("RILD can't accept socket from process %s", pwd->pw_name);
2511 }
2512 } else {
2513 ALOGE("Error on getpwuid() errno: %d", errno);
2514 }
2515 } else {
2516 ALOGD("Error on getsockopt() errno: %d", errno);
2517 }
2518
2519 if ( !is_phone_socket ) {
2520 ALOGE("RILD must accept socket from %s", PHONE_PROCESS);
2521
2522 close(s_fdCommand);
2523 s_fdCommand = -1;
2524
2525 onCommandsSocketClosed();
2526
2527 /* start listening for new connections again */
2528 rilEventAddWakeup(&s_listen_event);
2529
2530 return;
2531 }
2532
2533 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
2534
2535 if (ret < 0) {
2536 ALOGE ("Error setting O_NONBLOCK errno:%d", errno);
2537 }
2538
2539 ALOGI("libril: new connection");
2540
2541 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
2542
2543 ril_event_set (&s_commands_event, s_fdCommand, 1,
2544 processCommandsCallback, p_rs);
2545
2546 rilEventAddWakeup (&s_commands_event);
2547
2548 onNewCommandConnect();
2549}
2550
2551static void freeDebugCallbackArgs(int number, char **args) {
2552 for (int i = 0; i < number; i++) {
2553 if (args[i] != NULL) {
2554 free(args[i]);
2555 }
2556 }
2557 free(args);
2558}
2559
2560static void debugCallback (int fd, short flags, void *param) {
2561 int acceptFD, option;
2562 struct sockaddr_un peeraddr;
2563 socklen_t socklen = sizeof (peeraddr);
2564 int data;
2565 unsigned int qxdm_data[6];
2566 const char *deactData[1] = {"1"};
2567 char *actData[1];
2568 RIL_Dial dialData;
2569 int hangupData[1] = {1};
2570 int number;
2571 char **args;
2572
2573 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
2574
2575 if (acceptFD < 0) {
2576 ALOGE ("error accepting on debug port: %d\n", errno);
2577 return;
2578 }
2579
2580 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
2581 ALOGE ("error reading on socket: number of Args: \n");
2582 return;
2583 }
2584 args = (char **) malloc(sizeof(char*) * number);
2585
2586 for (int i = 0; i < number; i++) {
2587 int len;
2588 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
2589 ALOGE ("error reading on socket: Len of Args: \n");
2590 freeDebugCallbackArgs(i, args);
2591 return;
2592 }
2593 // +1 for null-term
2594 args[i] = (char *) malloc((sizeof(char) * len) + 1);
2595 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
2596 != (int)sizeof(char) * len) {
2597 ALOGE ("error reading on socket: Args[%d] \n", i);
2598 freeDebugCallbackArgs(i, args);
2599 return;
2600 }
2601 char * buf = args[i];
2602 buf[len] = 0;
2603 }
2604
2605 switch (atoi(args[0])) {
2606 case 0:
2607 ALOGI ("Connection on debug port: issuing reset.");
2608 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
2609 break;
2610 case 1:
2611 ALOGI ("Connection on debug port: issuing radio power off.");
2612 data = 0;
2613 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2614 // Close the socket
2615 close(s_fdCommand);
2616 s_fdCommand = -1;
2617 break;
2618 case 2:
2619 ALOGI ("Debug port: issuing unsolicited voice network change.");
2620 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
2621 NULL, 0);
2622 break;
2623 case 3:
2624 ALOGI ("Debug port: QXDM log enable.");
2625 qxdm_data[0] = 65536; // head.func_tag
2626 qxdm_data[1] = 16; // head.len
2627 qxdm_data[2] = 1; // mode: 1 for 'start logging'
2628 qxdm_data[3] = 32; // log_file_size: 32megabytes
2629 qxdm_data[4] = 0; // log_mask
2630 qxdm_data[5] = 8; // log_max_fileindex
2631 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2632 6 * sizeof(int));
2633 break;
2634 case 4:
2635 ALOGI ("Debug port: QXDM log disable.");
2636 qxdm_data[0] = 65536;
2637 qxdm_data[1] = 16;
2638 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
2639 qxdm_data[3] = 32;
2640 qxdm_data[4] = 0;
2641 qxdm_data[5] = 8;
2642 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2643 6 * sizeof(int));
2644 break;
2645 case 5:
2646 ALOGI("Debug port: Radio On");
2647 data = 1;
2648 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2649 sleep(2);
2650 // Set network selection automatic.
2651 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
2652 break;
2653 case 6:
2654 ALOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
2655 actData[0] = args[1];
2656 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
2657 sizeof(actData));
2658 break;
2659 case 7:
2660 ALOGI("Debug port: Deactivate Data Call");
2661 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
2662 sizeof(deactData));
2663 break;
2664 case 8:
2665 ALOGI("Debug port: Dial Call");
2666 dialData.clir = 0;
2667 dialData.address = args[1];
2668 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
2669 break;
2670 case 9:
2671 ALOGI("Debug port: Answer Call");
2672 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
2673 break;
2674 case 10:
2675 ALOGI("Debug port: End Call");
2676 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
2677 sizeof(hangupData));
2678 break;
2679 default:
2680 ALOGE ("Invalid request");
2681 break;
2682 }
2683 freeDebugCallbackArgs(number, args);
2684 close(acceptFD);
2685}
2686
2687
2688static void userTimerCallback (int fd, short flags, void *param) {
2689 UserCallbackInfo *p_info;
2690
2691 p_info = (UserCallbackInfo *)param;
2692
2693 p_info->p_callback(p_info->userParam);
2694
2695
2696 // FIXME generalize this...there should be a cancel mechanism
2697 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
2698 s_last_wake_timeout_info = NULL;
2699 }
2700
2701 free(p_info);
2702}
2703
2704
2705static void *
2706eventLoop(void *param) {
2707 int ret;
2708 int filedes[2];
2709
2710 ril_event_init();
2711
2712 pthread_mutex_lock(&s_startupMutex);
2713
2714 s_started = 1;
2715 pthread_cond_broadcast(&s_startupCond);
2716
2717 pthread_mutex_unlock(&s_startupMutex);
2718
2719 ret = pipe(filedes);
2720
2721 if (ret < 0) {
2722 ALOGE("Error in pipe() errno:%d", errno);
2723 return NULL;
2724 }
2725
2726 s_fdWakeupRead = filedes[0];
2727 s_fdWakeupWrite = filedes[1];
2728
2729 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
2730
2731 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
2732 processWakeupCallback, NULL);
2733
2734 rilEventAddWakeup (&s_wakeupfd_event);
2735
2736 // Only returns on error
2737 ril_event_loop();
2738 ALOGE ("error in event_loop_base errno:%d", errno);
2739 // kill self to restart on error
2740 kill(0, SIGKILL);
2741
2742 return NULL;
2743}
2744
2745extern "C" void
2746RIL_startEventLoop(void) {
2747 int ret;
2748 pthread_attr_t attr;
2749
2750 /* spin up eventLoop thread and wait for it to get started */
2751 s_started = 0;
2752 pthread_mutex_lock(&s_startupMutex);
2753
2754 pthread_attr_init (&attr);
2755 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
2756 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
2757
2758 while (s_started == 0) {
2759 pthread_cond_wait(&s_startupCond, &s_startupMutex);
2760 }
2761
2762 pthread_mutex_unlock(&s_startupMutex);
2763
2764 if (ret < 0) {
2765 ALOGE("Failed to create dispatch thread errno:%d", errno);
2766 return;
2767 }
2768}
2769
2770// Used for testing purpose only.
2771extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
2772 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
2773}
2774
2775extern "C" void
2776RIL_register (const RIL_RadioFunctions *callbacks) {
2777 int ret;
2778 int flags;
2779
2780 if (callbacks == NULL) {
2781 ALOGE("RIL_register: RIL_RadioFunctions * null");
2782 return;
2783 }
2784 if (callbacks->version < RIL_VERSION_MIN) {
2785 ALOGE("RIL_register: version %d is to old, min version is %d",
2786 callbacks->version, RIL_VERSION_MIN);
2787 return;
2788 }
2789 if (callbacks->version > RIL_VERSION) {
2790 ALOGE("RIL_register: version %d is too new, max version is %d",
2791 callbacks->version, RIL_VERSION);
2792 return;
2793 }
2794 ALOGE("RIL_register: RIL version %d", callbacks->version);
2795
2796 if (s_registerCalled > 0) {
2797 ALOGE("RIL_register has been called more than once. "
2798 "Subsequent call ignored");
2799 return;
2800 }
2801
2802 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
2803
2804 s_registerCalled = 1;
2805
2806 // Little self-check
2807
2808 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
2809 assert(i == s_commands[i].requestNumber);
2810 }
2811
2812 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
2813 assert(i + RIL_UNSOL_RESPONSE_BASE
2814 == s_unsolResponses[i].requestNumber);
2815 }
2816
2817 // New rild impl calls RIL_startEventLoop() first
2818 // old standalone impl wants it here.
2819
2820 if (s_started == 0) {
2821 RIL_startEventLoop();
2822 }
2823
2824 // start listen socket
2825
2826#if 0
2827 ret = socket_local_server (SOCKET_NAME_RIL,
2828 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
2829
2830 if (ret < 0) {
2831 ALOGE("Unable to bind socket errno:%d", errno);
2832 exit (-1);
2833 }
2834 s_fdListen = ret;
2835
2836#else
2837 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
2838 if (s_fdListen < 0) {
2839 ALOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
2840 exit(-1);
2841 }
2842
2843 ret = listen(s_fdListen, 4);
2844
2845 if (ret < 0) {
2846 ALOGE("Failed to listen on control socket '%d': %s",
2847 s_fdListen, strerror(errno));
2848 exit(-1);
2849 }
2850#endif
2851
2852
2853 /* note: non-persistent so we can accept only one connection at a time */
2854 ril_event_set (&s_listen_event, s_fdListen, false,
2855 listenCallback, NULL);
2856
2857 rilEventAddWakeup (&s_listen_event);
2858
2859#if 1
2860 // start debug interface socket
2861
2862 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
2863 if (s_fdDebug < 0) {
2864 ALOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
2865 exit(-1);
2866 }
2867
2868 ret = listen(s_fdDebug, 4);
2869
2870 if (ret < 0) {
2871 ALOGE("Failed to listen on ril debug socket '%d': %s",
2872 s_fdDebug, strerror(errno));
2873 exit(-1);
2874 }
2875
2876 ril_event_set (&s_debug_event, s_fdDebug, true,
2877 debugCallback, NULL);
2878
2879 rilEventAddWakeup (&s_debug_event);
2880#endif
2881
2882}
2883
2884static int
2885checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
2886 int ret = 0;
2887
2888 if (pRI == NULL) {
2889 return 0;
2890 }
2891
2892 pthread_mutex_lock(&s_pendingRequestsMutex);
2893
2894 for(RequestInfo **ppCur = &s_pendingRequests
2895 ; *ppCur != NULL
2896 ; ppCur = &((*ppCur)->p_next)
2897 ) {
2898 if (pRI == *ppCur) {
2899 ret = 1;
2900
2901 *ppCur = (*ppCur)->p_next;
2902 break;
2903 }
2904 }
2905
2906 pthread_mutex_unlock(&s_pendingRequestsMutex);
2907
2908 return ret;
2909}
2910
2911
2912extern "C" void
2913RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
2914 RequestInfo *pRI;
2915 int ret;
2916 size_t errorOffset;
2917
2918 pRI = (RequestInfo *)t;
2919
2920 if (!checkAndDequeueRequestInfo(pRI)) {
2921 ALOGE ("RIL_onRequestComplete: invalid RIL_Token");
2922 return;
2923 }
2924
2925 if (pRI->local > 0) {
2926 // Locally issued command...void only!
2927 // response does not go back up the command socket
2928 ALOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
2929
2930 goto done;
2931 }
2932
2933 appendPrintBuf("[%04d]< %s",
2934 pRI->token, requestToString(pRI->pCI->requestNumber));
2935
2936 if (pRI->cancelled == 0) {
2937 Parcel p;
2938
2939 p.writeInt32 (RESPONSE_SOLICITED);
2940 p.writeInt32 (pRI->token);
2941 errorOffset = p.dataPosition();
2942
2943 p.writeInt32 (e);
2944
2945 if (response != NULL) {
2946 // there is a response payload, no matter success or not.
2947 ret = pRI->pCI->responseFunction(p, response, responselen);
2948
2949 /* if an error occurred, rewind and mark it */
2950 if (ret != 0) {
2951 p.setDataPosition(errorOffset);
2952 p.writeInt32 (ret);
2953 }
2954 }
2955
2956 if (e != RIL_E_SUCCESS) {
2957 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
2958 }
2959
2960 if (s_fdCommand < 0) {
2961 ALOGD ("RIL onRequestComplete: Command channel closed");
2962 }
2963 sendResponse(p);
2964 }
2965
2966done:
2967 free(pRI);
2968}
2969
2970
2971static void
2972grabPartialWakeLock() {
2973 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
2974}
2975
2976static void
2977releaseWakeLock() {
2978 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
2979}
2980
2981/**
2982 * Timer callback to put us back to sleep before the default timeout
2983 */
2984static void
2985wakeTimeoutCallback (void *param) {
2986 // We're using "param != NULL" as a cancellation mechanism
2987 if (param == NULL) {
2988 //ALOGD("wakeTimeout: releasing wake lock");
2989
2990 releaseWakeLock();
2991 } else {
2992 //ALOGD("wakeTimeout: releasing wake lock CANCELLED");
2993 }
2994}
2995
2996static int
2997decodeVoiceRadioTechnology (RIL_RadioState radioState) {
2998 switch (radioState) {
2999 case RADIO_STATE_SIM_NOT_READY:
3000 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3001 case RADIO_STATE_SIM_READY:
3002 return RADIO_TECH_UMTS;
3003
3004 case RADIO_STATE_RUIM_NOT_READY:
3005 case RADIO_STATE_RUIM_READY:
3006 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3007 case RADIO_STATE_NV_NOT_READY:
3008 case RADIO_STATE_NV_READY:
3009 return RADIO_TECH_1xRTT;
3010
3011 default:
3012 ALOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
3013 return -1;
3014 }
3015}
3016
3017static int
3018decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
3019 switch (radioState) {
3020 case RADIO_STATE_SIM_NOT_READY:
3021 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3022 case RADIO_STATE_SIM_READY:
3023 case RADIO_STATE_RUIM_NOT_READY:
3024 case RADIO_STATE_RUIM_READY:
3025 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3026 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
3027
3028 case RADIO_STATE_NV_NOT_READY:
3029 case RADIO_STATE_NV_READY:
3030 return CDMA_SUBSCRIPTION_SOURCE_NV;
3031
3032 default:
3033 ALOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
3034 return -1;
3035 }
3036}
3037
3038static int
3039decodeSimStatus (RIL_RadioState radioState) {
3040 switch (radioState) {
3041 case RADIO_STATE_SIM_NOT_READY:
3042 case RADIO_STATE_RUIM_NOT_READY:
3043 case RADIO_STATE_NV_NOT_READY:
3044 case RADIO_STATE_NV_READY:
3045 return -1;
3046 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3047 case RADIO_STATE_SIM_READY:
3048 case RADIO_STATE_RUIM_READY:
3049 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3050 return radioState;
3051 default:
3052 ALOGD("decodeSimStatus: Invoked with incorrect RadioState");
3053 return -1;
3054 }
3055}
3056
3057static bool is3gpp2(int radioTech) {
3058 switch (radioTech) {
3059 case RADIO_TECH_IS95A:
3060 case RADIO_TECH_IS95B:
3061 case RADIO_TECH_1xRTT:
3062 case RADIO_TECH_EVDO_0:
3063 case RADIO_TECH_EVDO_A:
3064 case RADIO_TECH_EVDO_B:
3065 case RADIO_TECH_EHRPD:
3066 return true;
3067 default:
3068 return false;
3069 }
3070}
3071
3072/* If RIL sends SIM states or RUIM states, store the voice radio
3073 * technology and subscription source information so that they can be
3074 * returned when telephony framework requests them
3075 */
3076static RIL_RadioState
3077processRadioState(RIL_RadioState newRadioState) {
3078
3079 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
3080 int newVoiceRadioTech;
3081 int newCdmaSubscriptionSource;
3082 int newSimStatus;
3083
3084 /* This is old RIL. Decode Subscription source and Voice Radio Technology
3085 from Radio State and send change notifications if there has been a change */
3086 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
3087 if(newVoiceRadioTech != voiceRadioTech) {
3088 voiceRadioTech = newVoiceRadioTech;
3089 RIL_onUnsolicitedResponse (RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
3090 &voiceRadioTech, sizeof(voiceRadioTech));
3091 }
3092 if(is3gpp2(newVoiceRadioTech)) {
3093 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
3094 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
3095 cdmaSubscriptionSource = newCdmaSubscriptionSource;
3096 RIL_onUnsolicitedResponse (RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
3097 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource));
3098 }
3099 }
3100 newSimStatus = decodeSimStatus(newRadioState);
3101 if(newSimStatus != simRuimStatus) {
3102 simRuimStatus = newSimStatus;
3103 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
3104 }
3105
3106 /* Send RADIO_ON to telephony */
3107 newRadioState = RADIO_STATE_ON;
3108 }
3109
3110 return newRadioState;
3111}
3112
3113extern "C"
3114void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
3115 size_t datalen)
3116{
3117 int unsolResponseIndex;
3118 int ret;
3119 int64_t timeReceived = 0;
3120 bool shouldScheduleTimeout = false;
3121 RIL_RadioState newState;
3122
3123 if (s_registerCalled == 0) {
3124 // Ignore RIL_onUnsolicitedResponse before RIL_register
3125 ALOGW("RIL_onUnsolicitedResponse called before RIL_register");
3126 return;
3127 }
3128
3129 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
3130
3131 if ((unsolResponseIndex < 0)
3132 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
3133 ALOGE("unsupported unsolicited response code %d", unsolResponse);
3134 return;
3135 }
3136
3137 // Grab a wake lock if needed for this reponse,
3138 // as we exit we'll either release it immediately
3139 // or set a timer to release it later.
3140 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
3141 case WAKE_PARTIAL:
3142 grabPartialWakeLock();
3143 shouldScheduleTimeout = true;
3144 break;
3145
3146 case DONT_WAKE:
3147 default:
3148 // No wake lock is grabed so don't set timeout
3149 shouldScheduleTimeout = false;
3150 break;
3151 }
3152
3153 // Mark the time this was received, doing this
3154 // after grabing the wakelock incase getting
3155 // the elapsedRealTime might cause us to goto
3156 // sleep.
3157 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3158 timeReceived = elapsedRealtime();
3159 }
3160
3161 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
3162
3163 Parcel p;
3164
3165 p.writeInt32 (RESPONSE_UNSOLICITED);
3166 p.writeInt32 (unsolResponse);
3167
3168 ret = s_unsolResponses[unsolResponseIndex]
3169 .responseFunction(p, data, datalen);
3170 if (ret != 0) {
3171 // Problem with the response. Don't continue;
3172 goto error_exit;
3173 }
3174
3175 // some things get more payload
3176 switch(unsolResponse) {
3177 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
3178 newState = processRadioState(s_callbacks.onStateRequest());
3179 p.writeInt32(newState);
3180 appendPrintBuf("%s {%s}", printBuf,
3181 radioStateToString(s_callbacks.onStateRequest()));
3182 break;
3183
3184
3185 case RIL_UNSOL_NITZ_TIME_RECEIVED:
3186 // Store the time that this was received so the
3187 // handler of this message can account for
3188 // the time it takes to arrive and process. In
3189 // particular the system has been known to sleep
3190 // before this message can be processed.
3191 p.writeInt64(timeReceived);
3192 break;
3193 }
3194
3195 ret = sendResponse(p);
3196 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3197
3198 // Unfortunately, NITZ time is not poll/update like everything
3199 // else in the system. So, if the upstream client isn't connected,
3200 // keep a copy of the last NITZ response (with receive time noted
3201 // above) around so we can deliver it when it is connected
3202
3203 if (s_lastNITZTimeData != NULL) {
3204 free (s_lastNITZTimeData);
3205 s_lastNITZTimeData = NULL;
3206 }
3207
3208 s_lastNITZTimeData = malloc(p.dataSize());
3209 s_lastNITZTimeDataSize = p.dataSize();
3210 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
3211 }
3212
3213 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
3214 // FIXME The java code should handshake here to release wake lock
3215
3216 if (shouldScheduleTimeout) {
3217 // Cancel the previous request
3218 if (s_last_wake_timeout_info != NULL) {
3219 s_last_wake_timeout_info->userParam = (void *)1;
3220 }
3221
3222 s_last_wake_timeout_info
3223 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
3224 &TIMEVAL_WAKE_TIMEOUT);
3225 }
3226
3227 // Normal exit
3228 return;
3229
3230error_exit:
3231 if (shouldScheduleTimeout) {
3232 releaseWakeLock();
3233 }
3234}
3235
3236/** FIXME generalize this if you track UserCAllbackInfo, clear it
3237 when the callback occurs
3238*/
3239static UserCallbackInfo *
3240internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
3241 const struct timeval *relativeTime)
3242{
3243 struct timeval myRelativeTime;
3244 UserCallbackInfo *p_info;
3245
3246 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
3247
3248 p_info->p_callback = callback;
3249 p_info->userParam = param;
3250
3251 if (relativeTime == NULL) {
3252 /* treat null parameter as a 0 relative time */
3253 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
3254 } else {
3255 /* FIXME I think event_add's tv param is really const anyway */
3256 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
3257 }
3258
3259 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
3260
3261 ril_timer_add(&(p_info->event), &myRelativeTime);
3262
3263 triggerEvLoop();
3264 return p_info;
3265}
3266
3267
3268extern "C" void
3269RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
3270 const struct timeval *relativeTime) {
3271 internalRequestTimedCallback (callback, param, relativeTime);
3272}
3273
3274const char *
3275failCauseToString(RIL_Errno e) {
3276 switch(e) {
3277 case RIL_E_SUCCESS: return "E_SUCCESS";
3278 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RAIDO_NOT_AVAILABLE";
3279 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
3280 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
3281 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
3282 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
3283 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
3284 case RIL_E_CANCELLED: return "E_CANCELLED";
3285 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
3286 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
3287 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
3288 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
3289 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
3290#ifdef FEATURE_MULTIMODE_ANDROID
3291 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
3292 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
3293#endif
3294 default: return "<unknown error>";
3295 }
3296}
3297
3298const char *
3299radioStateToString(RIL_RadioState s) {
3300 switch(s) {
3301 case RADIO_STATE_OFF: return "RADIO_OFF";
3302 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
3303 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
3304 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
3305 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
3306 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
3307 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
3308 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
3309 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
3310 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
3311 case RADIO_STATE_ON:return"RADIO_ON";
3312 default: return "<unknown state>";
3313 }
3314}
3315
3316const char *
3317callStateToString(RIL_CallState s) {
3318 switch(s) {
3319 case RIL_CALL_ACTIVE : return "ACTIVE";
3320 case RIL_CALL_HOLDING: return "HOLDING";
3321 case RIL_CALL_DIALING: return "DIALING";
3322 case RIL_CALL_ALERTING: return "ALERTING";
3323 case RIL_CALL_INCOMING: return "INCOMING";
3324 case RIL_CALL_WAITING: return "WAITING";
3325 default: return "<unknown state>";
3326 }
3327}
3328
3329const char *
3330requestToString(int request) {
3331/*
3332 cat libs/telephony/ril_commands.h \
3333 | egrep "^ *{RIL_" \
3334 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3335
3336
3337 cat libs/telephony/ril_unsol_commands.h \
3338 | egrep "^ *{RIL_" \
3339 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
3340
3341*/
3342 switch(request) {
3343 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3344 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3345 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3346 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3347 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3348 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3349 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3350 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3351 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3352 case RIL_REQUEST_DIAL: return "DIAL";
3353 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
3354 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3355 case RIL_REQUEST_HANGUP: return "HANGUP";
3356 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3357 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3358 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3359 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3360 case RIL_REQUEST_UDUB: return "UDUB";
3361 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3362 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3363 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3364 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3365 case RIL_REQUEST_OPERATOR: return "OPERATOR";
3366 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3367 case RIL_REQUEST_DTMF: return "DTMF";
3368 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3369 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3370 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3371 case RIL_REQUEST_SIM_IO: return "SIM_IO";
3372 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3373 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3374 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3375 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3376 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3377 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3378 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3379 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3380 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3381 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3382 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3383 case RIL_REQUEST_ANSWER: return "ANSWER";
3384 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3385 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3386 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3387 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3388 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3389 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3390 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3391 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3392 case RIL_REQUEST_DTMF_START: return "DTMF_START";
3393 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3394 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3395 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3396 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
3397 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
3398 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
3399 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3400 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3401 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3402 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3403 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3404 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3405 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3406 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3407 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3408 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3409 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
3410 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
3411 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
3412 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
3413 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
3414 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3415 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
3416 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
3417 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE";
3418 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
3419 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
3420 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
3421 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
3422 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
3423 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
3424 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
3425 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
3426 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
3427 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
3428 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
3429 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
3430 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
3431 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
3432 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
3433 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY";
3434 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
3435 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
3436 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
3437 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
3438 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
3439 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
3440 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
3441 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
3442 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
3443 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
3444 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
3445 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
3446 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
3447 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
3448 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
3449 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
3450 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
3451 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
3452 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
3453 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
3454 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
3455 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
3456 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
3457 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
3458 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
3459 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
3460 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
3461 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
3462 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
3463 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
3464 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
3465 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
3466 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
3467 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
3468 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
3469 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
3470 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
3471 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
3472 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
3473 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
3474 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
3475 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
3476 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
3477 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
3478 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
3479 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
3480 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
3481 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
3482 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
3483 default: return "<unknown request>";
3484 }
3485}
3486
3487} /* namespace android */