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