blob: da4d5198d35ad6951995d1b67ea4aba5a6af86ea [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>
codeworkxafc051f2013-07-27 09:02:14 +020034#include <sys/limits.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020035#include <pwd.h>
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <unistd.h>
42#include <fcntl.h>
43#include <time.h>
44#include <errno.h>
45#include <assert.h>
46#include <ctype.h>
47#include <alloca.h>
48#include <sys/un.h>
49#include <assert.h>
50#include <netinet/in.h>
51#include <cutils/properties.h>
52
53#include <ril_event.h>
54
55namespace android {
56
57#define PHONE_PROCESS "radio"
58
59#define SOCKET_NAME_RIL "rild"
60#define SOCKET_NAME_RIL_DEBUG "rild-debug"
61
62#define ANDROID_WAKE_LOCK_NAME "radio-interface"
63
64
65#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
66
67// match with constant in RIL.java
68#define MAX_COMMAND_BYTES (8 * 1024)
69
70// Basically: memset buffers that the client library
71// shouldn't be using anymore in an attempt to find
72// memory usage issues sooner.
73#define MEMSET_FREED 1
74
75#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
76
77#define MIN(a,b) ((a)<(b) ? (a) : (b))
78
79/* Constants for response types */
80#define RESPONSE_SOLICITED 0
81#define RESPONSE_UNSOLICITED 1
82
83/* Negative values for private RIL errno's */
84#define RIL_ERRNO_INVALID_RESPONSE -1
85
86// request, response, and unsolicited msg print macro
87#define PRINTBUF_SIZE 8096
88
89// Enable RILC log
90#define RILC_LOG 0
91
92#if RILC_LOG
93 #define startRequest sprintf(printBuf, "(")
94 #define closeRequest sprintf(printBuf, "%s)", printBuf)
95 #define printRequest(token, req) \
codeworkxafc051f2013-07-27 09:02:14 +020096 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020097
98 #define startResponse sprintf(printBuf, "%s {", printBuf)
99 #define closeResponse sprintf(printBuf, "%s}", printBuf)
codeworkxafc051f2013-07-27 09:02:14 +0200100 #define printResponse RLOGD("%s", printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200101
102 #define clearPrintBuf printBuf[0] = 0
103 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
104 #define appendPrintBuf(x...) sprintf(printBuf, x)
105#else
106 #define startRequest
107 #define closeRequest
108 #define printRequest(token, req)
109 #define startResponse
110 #define closeResponse
111 #define printResponse
112 #define clearPrintBuf
113 #define removeLastChar
114 #define appendPrintBuf(x...)
115#endif
116
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200117#define MAX_RIL_SOL RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE
118#define MAX_RIL_UNSOL RIL_UNSOL_CELL_INFO_LIST
119
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200120enum WakeType {DONT_WAKE, WAKE_PARTIAL};
121
122typedef struct {
123 int requestNumber;
124 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
125 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
126} CommandInfo;
127
128typedef struct {
129 int requestNumber;
130 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
131 WakeType wakeType;
132} UnsolResponseInfo;
133
134typedef struct RequestInfo {
135 int32_t token; //this is not RIL_Token
136 CommandInfo *pCI;
137 struct RequestInfo *p_next;
138 char cancelled;
139 char local; // responses to local commands do not go back to command process
140} RequestInfo;
141
142typedef struct UserCallbackInfo {
143 RIL_TimedCallback p_callback;
144 void *userParam;
145 struct ril_event event;
146 struct UserCallbackInfo *p_next;
147} UserCallbackInfo;
148
149
150/*******************************************************************/
151
152RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
153static int s_registerCalled = 0;
154
155static pthread_t s_tid_dispatch;
156static pthread_t s_tid_reader;
157static int s_started = 0;
158
159static int s_fdListen = -1;
160static int s_fdCommand = -1;
161static int s_fdDebug = -1;
162
163static int s_fdWakeupRead;
164static int s_fdWakeupWrite;
165
166static struct ril_event s_commands_event;
167static struct ril_event s_wakeupfd_event;
168static struct ril_event s_listen_event;
169static struct ril_event s_wake_timeout_event;
170static struct ril_event s_debug_event;
171
172
173static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
174
175static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
176static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
177static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
178static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
179
180static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
181static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
182
183static RequestInfo *s_pendingRequests = NULL;
184
185static RequestInfo *s_toDispatchHead = NULL;
186static RequestInfo *s_toDispatchTail = NULL;
187
188static UserCallbackInfo *s_last_wake_timeout_info = NULL;
189
190static void *s_lastNITZTimeData = NULL;
191static size_t s_lastNITZTimeDataSize;
192
193#if RILC_LOG
194 static char printBuf[PRINTBUF_SIZE];
195#endif
196
197/*******************************************************************/
198
199static void dispatchVoid (Parcel& p, RequestInfo *pRI);
200static void dispatchString (Parcel& p, RequestInfo *pRI);
201static void dispatchStrings (Parcel& p, RequestInfo *pRI);
202static void dispatchInts (Parcel& p, RequestInfo *pRI);
203static void dispatchDial (Parcel& p, RequestInfo *pRI);
204static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
205static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
206static void dispatchRaw(Parcel& p, RequestInfo *pRI);
207static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
codeworkxafc051f2013-07-27 09:02:14 +0200208static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
209static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
210static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200211
212static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
213static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
214static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
215static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
216static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
217static int responseInts(Parcel &p, void *response, size_t responselen);
218static int responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen);
219static int responseStrings(Parcel &p, void *response, size_t responselen);
220static int responseStringsNetworks(Parcel &p, void *response, size_t responselen);
221static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search);
222static int responseString(Parcel &p, void *response, size_t responselen);
223static int responseVoid(Parcel &p, void *response, size_t responselen);
224static int responseCallList(Parcel &p, void *response, size_t responselen);
225static int responseSMS(Parcel &p, void *response, size_t responselen);
226static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
227static int responseCallForwards(Parcel &p, void *response, size_t responselen);
228static int responseDataCallList(Parcel &p, void *response, size_t responselen);
codeworkxafc051f2013-07-27 09:02:14 +0200229static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200230static int responseRaw(Parcel &p, void *response, size_t responselen);
231static int responseSsn(Parcel &p, void *response, size_t responselen);
232static int responseSimStatus(Parcel &p, void *response, size_t responselen);
233static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
234static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
235static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
236static int responseCellList(Parcel &p, void *response, size_t responselen);
237static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
238static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
239static int responseCallRing(Parcel &p, void *response, size_t responselen);
240static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
241static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
242static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
codeworkxafc051f2013-07-27 09:02:14 +0200243static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200244
245static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
246static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
247static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
248
249extern "C" const char * requestToString(int request);
250extern "C" const char * failCauseToString(RIL_Errno);
251extern "C" const char * callStateToString(RIL_CallState);
252extern "C" const char * radioStateToString(RIL_RadioState);
253
254#ifdef RIL_SHLIB
255extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
256 size_t datalen);
257#endif
258
259static UserCallbackInfo * internalRequestTimedCallback
260 (RIL_TimedCallback callback, void *param,
261 const struct timeval *relativeTime);
262
263/** Index == requestNumber */
264static CommandInfo s_commands[] = {
265#include "ril_commands.h"
266};
267
268static UnsolResponseInfo s_unsolResponses[] = {
269#include "ril_unsol_commands.h"
270};
271
272/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
273 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
274 radio state message and store it. Every time there is a change in Radio State
275 check to see if voice radio tech changes and notify telephony
276 */
277int voiceRadioTech = -1;
278
279/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
280 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
281 source from radio state and store it. Every time there is a change in Radio State
282 check to see if subscription source changed and notify telephony
283 */
284int cdmaSubscriptionSource = -1;
285
286/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
287 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
288 check to see if SIM/RUIM status changed and notify telephony
289 */
290int simRuimStatus = -1;
291
292static char *
293strdupReadString(Parcel &p) {
294 size_t stringlen;
295 const char16_t *s16;
296
297 s16 = p.readString16Inplace(&stringlen);
298
299 return strndup16to8(s16, stringlen);
300}
301
302static void writeStringToParcel(Parcel &p, const char *s) {
303 char16_t *s16;
304 size_t s16_len;
305 s16 = strdup8to16(s, &s16_len);
306 p.writeString16(s16, s16_len);
307 free(s16);
308}
309
310
311static void
312memsetString (char *s) {
313 if (s != NULL) {
314 memset (s, 0, strlen(s));
315 }
316}
317
318void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
319 const size_t* objects, size_t objectsSize,
320 void* cookie) {
321 // do nothing -- the data reference lives longer than the Parcel object
322}
323
324/**
325 * To be called from dispatch thread
326 * Issue a single local request, ensuring that the response
327 * is not sent back up to the command process
328 */
329static void
330issueLocalRequest(int request, void *data, int len) {
331 RequestInfo *pRI;
332 int index;
333 int ret;
334
335 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
336
337 pRI->local = 1;
338 pRI->token = 0xffffffff; // token is not used in this context
339
340 /* Hack to include Samsung requests */
341 if (request > 10000) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200342 index = request - 10000 + MAX_RIL_SOL;
343 RLOGD("SAMSUNG: request=%d, index=%d", request, index);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200344 pRI->pCI = &(s_commands[index]);
345 } else {
346 pRI->pCI = &(s_commands[request]);
347 }
348
349 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
350 assert (ret == 0);
351
352 pRI->p_next = s_pendingRequests;
353 s_pendingRequests = pRI;
354
355 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
356 assert (ret == 0);
357
codeworkxafc051f2013-07-27 09:02:14 +0200358 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200359
360 s_callbacks.onRequest(request, data, len, pRI);
361}
362
363static int
364processCommandBuffer(void *buffer, size_t buflen) {
365 Parcel p;
366 status_t status;
367 int32_t request;
368 int32_t token;
369 RequestInfo *pRI;
370 int index;
371 int ret;
372
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200373 p.setData((uint8_t *) buffer, buflen);
374
375 // status checked at end
376 status = p.readInt32(&request);
377 status = p.readInt32 (&token);
378
379 if (status != NO_ERROR) {
codeworkxafc051f2013-07-27 09:02:14 +0200380 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200381 return 0;
382 }
383
384 /* Hack to include Samsung requests */
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200385 if (request < 1 || ((request > MAX_RIL_SOL) &&
386 (request < RIL_REQUEST_GET_CELL_BROADCAST_CONFIG)) ||
387 request > RIL_REQUEST_HANGUP_VT) {
codeworkxafc051f2013-07-27 09:02:14 +0200388 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200389 // FIXME this should perhaps return a response
390 return 0;
391 }
392
393 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
394
395 pRI->token = token;
396
397 /* Hack to include Samsung requests */
398 if (request > 10000) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200399 index = request - 10000 + MAX_RIL_SOL;
400 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
401 request, index);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200402 pRI->pCI = &(s_commands[index]);
403 } else {
404 pRI->pCI = &(s_commands[request]);
405 }
406
407 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
408 assert (ret == 0);
409
410 pRI->p_next = s_pendingRequests;
411 s_pendingRequests = pRI;
412
413 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
414 assert (ret == 0);
415
416/* sLastDispatchedToken = token; */
417
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200418 pRI->pCI->dispatchFunction(p, pRI);
419
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200420 return 0;
421}
422
423static void
424invalidCommandBlock (RequestInfo *pRI) {
codeworkxafc051f2013-07-27 09:02:14 +0200425 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200426 pRI->token, requestToString(pRI->pCI->requestNumber));
427}
428
429/** Callee expects NULL */
430static void
431dispatchVoid (Parcel& p, RequestInfo *pRI) {
432 clearPrintBuf;
433 printRequest(pRI->token, pRI->pCI->requestNumber);
434 s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
435}
436
437/** Callee expects const char * */
438static void
439dispatchString (Parcel& p, RequestInfo *pRI) {
440 status_t status;
441 size_t datalen;
442 size_t stringlen;
443 char *string8 = NULL;
444
445 string8 = strdupReadString(p);
446
447 startRequest;
448 appendPrintBuf("%s%s", printBuf, string8);
449 closeRequest;
450 printRequest(pRI->token, pRI->pCI->requestNumber);
451
452 s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
453 sizeof(char *), pRI);
454
455#ifdef MEMSET_FREED
456 memsetString(string8);
457#endif
458
459 free(string8);
460 return;
461invalid:
462 invalidCommandBlock(pRI);
463 return;
464}
465
466/** Callee expects const char ** */
467static void
468dispatchStrings (Parcel &p, RequestInfo *pRI) {
469 int32_t countStrings;
470 status_t status;
471 size_t datalen;
472 char **pStrings;
473
474 status = p.readInt32 (&countStrings);
475
476 if (status != NO_ERROR) {
477 goto invalid;
478 }
479
480 startRequest;
481 if (countStrings == 0) {
482 // just some non-null pointer
483 pStrings = (char **)alloca(sizeof(char *));
484 datalen = 0;
485 } else if (((int)countStrings) == -1) {
486 pStrings = NULL;
487 datalen = 0;
488 } else {
489 datalen = sizeof(char *) * countStrings;
490
491 pStrings = (char **)alloca(datalen);
492
493 for (int i = 0 ; i < countStrings ; i++) {
494 pStrings[i] = strdupReadString(p);
495 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
496 }
497 }
498 removeLastChar;
499 closeRequest;
500 printRequest(pRI->token, pRI->pCI->requestNumber);
501
502 s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
503
504 if (pStrings != NULL) {
505 for (int i = 0 ; i < countStrings ; i++) {
506#ifdef MEMSET_FREED
507 memsetString (pStrings[i]);
508#endif
509 free(pStrings[i]);
510 }
511
512#ifdef MEMSET_FREED
513 memset(pStrings, 0, datalen);
514#endif
515 }
516
517 return;
518invalid:
519 invalidCommandBlock(pRI);
520 return;
521}
522
523/** Callee expects const int * */
524static void
525dispatchInts (Parcel &p, RequestInfo *pRI) {
526 int32_t count;
527 status_t status;
528 size_t datalen;
529 int *pInts;
530
531 status = p.readInt32 (&count);
532
533 if (status != NO_ERROR || count == 0) {
534 goto invalid;
535 }
536
537 datalen = sizeof(int) * count;
538 pInts = (int *)alloca(datalen);
539
540 startRequest;
541 for (int i = 0 ; i < count ; i++) {
542 int32_t t;
543
544 status = p.readInt32(&t);
545 pInts[i] = (int)t;
546 appendPrintBuf("%s%d,", printBuf, t);
547
548 if (status != NO_ERROR) {
549 goto invalid;
550 }
551 }
552 removeLastChar;
553 closeRequest;
554 printRequest(pRI->token, pRI->pCI->requestNumber);
555
556 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts),
557 datalen, pRI);
558
559#ifdef MEMSET_FREED
560 memset(pInts, 0, datalen);
561#endif
562
563 return;
564invalid:
565 invalidCommandBlock(pRI);
566 return;
567}
568
569
570/**
571 * Callee expects const RIL_SMS_WriteArgs *
572 * Payload is:
573 * int32_t status
574 * String pdu
575 */
576static void
577dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
578 RIL_SMS_WriteArgs args;
579 int32_t t;
580 status_t status;
581
582 memset (&args, 0, sizeof(args));
583
584 status = p.readInt32(&t);
585 args.status = (int)t;
586
587 args.pdu = strdupReadString(p);
588
589 if (status != NO_ERROR || args.pdu == NULL) {
590 goto invalid;
591 }
592
593 args.smsc = strdupReadString(p);
594
595 startRequest;
596 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
597 (char*)args.pdu, (char*)args.smsc);
598 closeRequest;
599 printRequest(pRI->token, pRI->pCI->requestNumber);
600
601 s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
602
603#ifdef MEMSET_FREED
604 memsetString (args.pdu);
605#endif
606
607 free (args.pdu);
608
609#ifdef MEMSET_FREED
610 memset(&args, 0, sizeof(args));
611#endif
612
613 return;
614invalid:
615 invalidCommandBlock(pRI);
616 return;
617}
618
619/**
620 * Callee expects const RIL_Dial *
621 * Payload is:
622 * String address
623 * int32_t clir
624 */
625static void
626dispatchDial (Parcel &p, RequestInfo *pRI) {
627 RIL_Dial dial;
628 RIL_UUS_Info uusInfo;
629 int32_t sizeOfDial;
630 int32_t t;
631 int32_t uusPresent;
632 status_t status;
633
634 memset (&dial, 0, sizeof(dial));
635
636 dial.address = strdupReadString(p);
637
638 status = p.readInt32(&t);
639 dial.clir = (int)t;
640
641 if (status != NO_ERROR || dial.address == NULL) {
642 goto invalid;
643 }
644
645 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200646 uusPresent = 0;
647 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
648 } else {
649 status = p.readInt32(&uusPresent);
650
651 if (status != NO_ERROR) {
652 goto invalid;
653 }
654
655 if (uusPresent == 0) {
656 /* Samsung hack */
657 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
658 uusInfo.uusType = (RIL_UUS_Type) 0;
659 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
660 uusInfo.uusData = NULL;
661 uusInfo.uusLength = 0;
662 dial.uusInfo = &uusInfo;
663 } else {
664 int32_t len;
665
666 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
667
668 status = p.readInt32(&t);
669 uusInfo.uusType = (RIL_UUS_Type) t;
670
671 status = p.readInt32(&t);
672 uusInfo.uusDcs = (RIL_UUS_DCS) t;
673
674 status = p.readInt32(&len);
675 if (status != NO_ERROR) {
676 goto invalid;
677 }
678
679 // The java code writes -1 for null arrays
680 if (((int) len) == -1) {
681 uusInfo.uusData = NULL;
682 len = 0;
683 } else {
684 uusInfo.uusData = (char*) p.readInplace(len);
685 }
686
687 uusInfo.uusLength = len;
688 dial.uusInfo = &uusInfo;
689 }
690 sizeOfDial = sizeof(dial);
691 }
692
693 startRequest;
694 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
695 if (uusPresent) {
696 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
697 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
698 dial.uusInfo->uusLength);
699 }
700 closeRequest;
701 printRequest(pRI->token, pRI->pCI->requestNumber);
702
703 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI);
704
705#ifdef MEMSET_FREED
706 memsetString (dial.address);
707#endif
708
709 free (dial.address);
710
711#ifdef MEMSET_FREED
712 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
713 memset(&dial, 0, sizeof(dial));
714#endif
715
716 return;
717invalid:
718 invalidCommandBlock(pRI);
719 return;
720}
721
722/**
723 * Callee expects const RIL_SIM_IO *
724 * Payload is:
725 * int32_t command
726 * int32_t fileid
727 * String path
728 * int32_t p1, p2, p3
729 * String data
730 * String pin2
731 * String aidPtr
732 */
733static void
734dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
codeworkxafc051f2013-07-27 09:02:14 +0200735 union RIL_SIM_IO {
736 RIL_SIM_IO_v6 v6;
737 RIL_SIM_IO_v5 v5;
738 } simIO;
739
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200740 int32_t t;
codeworkxafc051f2013-07-27 09:02:14 +0200741 int size;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200742 status_t status;
743
744 memset (&simIO, 0, sizeof(simIO));
745
746 // note we only check status at the end
747
748 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200749 simIO.v6.command = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200750
751 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200752 simIO.v6.fileid = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200753
codeworkxafc051f2013-07-27 09:02:14 +0200754 simIO.v6.path = strdupReadString(p);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200755
756 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200757 simIO.v6.p1 = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200758
759 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200760 simIO.v6.p2 = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200761
762 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200763 simIO.v6.p3 = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200764
codeworkxafc051f2013-07-27 09:02:14 +0200765 simIO.v6.data = strdupReadString(p);
766 simIO.v6.pin2 = strdupReadString(p);
767 simIO.v6.aidPtr = strdupReadString(p);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200768
769 startRequest;
770 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
codeworkxafc051f2013-07-27 09:02:14 +0200771 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
772 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
773 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200774 closeRequest;
775 printRequest(pRI->token, pRI->pCI->requestNumber);
776
777 if (status != NO_ERROR) {
778 goto invalid;
779 }
780
codeworkxafc051f2013-07-27 09:02:14 +0200781 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
782 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, size, pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200783
784#ifdef MEMSET_FREED
codeworkxafc051f2013-07-27 09:02:14 +0200785 memsetString (simIO.v6.path);
786 memsetString (simIO.v6.data);
787 memsetString (simIO.v6.pin2);
788 memsetString (simIO.v6.aidPtr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200789#endif
790
codeworkxafc051f2013-07-27 09:02:14 +0200791 free (simIO.v6.path);
792 free (simIO.v6.data);
793 free (simIO.v6.pin2);
794 free (simIO.v6.aidPtr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200795
796#ifdef MEMSET_FREED
797 memset(&simIO, 0, sizeof(simIO));
798#endif
799
800 return;
801invalid:
802 invalidCommandBlock(pRI);
803 return;
804}
805
806/**
807 * Callee expects const RIL_CallForwardInfo *
808 * Payload is:
809 * int32_t status/action
810 * int32_t reason
811 * int32_t serviceCode
812 * int32_t toa
813 * String number (0 length -> null)
814 * int32_t timeSeconds
815 */
816static void
817dispatchCallForward(Parcel &p, RequestInfo *pRI) {
818 RIL_CallForwardInfo cff;
819 int32_t t;
820 status_t status;
821
822 memset (&cff, 0, sizeof(cff));
823
824 // note we only check status at the end
825
826 status = p.readInt32(&t);
827 cff.status = (int)t;
828
829 status = p.readInt32(&t);
830 cff.reason = (int)t;
831
832 status = p.readInt32(&t);
833 cff.serviceClass = (int)t;
834
835 status = p.readInt32(&t);
836 cff.toa = (int)t;
837
838 cff.number = strdupReadString(p);
839
840 status = p.readInt32(&t);
841 cff.timeSeconds = (int)t;
842
843 if (status != NO_ERROR) {
844 goto invalid;
845 }
846
847 // special case: number 0-length fields is null
848
849 if (cff.number != NULL && strlen (cff.number) == 0) {
850 cff.number = NULL;
851 }
852
853 startRequest;
854 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
855 cff.status, cff.reason, cff.serviceClass, cff.toa,
856 (char*)cff.number, cff.timeSeconds);
857 closeRequest;
858 printRequest(pRI->token, pRI->pCI->requestNumber);
859
860 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
861
862#ifdef MEMSET_FREED
863 memsetString(cff.number);
864#endif
865
866 free (cff.number);
867
868#ifdef MEMSET_FREED
869 memset(&cff, 0, sizeof(cff));
870#endif
871
872 return;
873invalid:
874 invalidCommandBlock(pRI);
875 return;
876}
877
878
879static void
880dispatchRaw(Parcel &p, RequestInfo *pRI) {
881 int32_t len;
882 status_t status;
883 const void *data;
884
885 status = p.readInt32(&len);
886
887 if (status != NO_ERROR) {
888 goto invalid;
889 }
890
891 // The java code writes -1 for null arrays
892 if (((int)len) == -1) {
893 data = NULL;
894 len = 0;
895 }
896
897 data = p.readInplace(len);
898
899 startRequest;
900 appendPrintBuf("%sraw_size=%d", printBuf, len);
901 closeRequest;
902 printRequest(pRI->token, pRI->pCI->requestNumber);
903
904 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
905
906 return;
907invalid:
908 invalidCommandBlock(pRI);
909 return;
910}
911
912static void
913dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
914 RIL_CDMA_SMS_Message rcsm;
915 int32_t t;
916 uint8_t ut;
917 status_t status;
918 int32_t digitCount;
919 int digitLimit;
920
921 memset(&rcsm, 0, sizeof(rcsm));
922
923 status = p.readInt32(&t);
924 rcsm.uTeleserviceID = (int) t;
925
926 status = p.read(&ut,sizeof(ut));
927 rcsm.bIsServicePresent = (uint8_t) ut;
928
929 status = p.readInt32(&t);
930 rcsm.uServicecategory = (int) t;
931
932 status = p.readInt32(&t);
933 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
934
935 status = p.readInt32(&t);
936 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
937
938 status = p.readInt32(&t);
939 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
940
941 status = p.readInt32(&t);
942 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
943
944 status = p.read(&ut,sizeof(ut));
945 rcsm.sAddress.number_of_digits= (uint8_t) ut;
946
947 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
948 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
949 status = p.read(&ut,sizeof(ut));
950 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
951 }
952
953 status = p.readInt32(&t);
954 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
955
956 status = p.read(&ut,sizeof(ut));
957 rcsm.sSubAddress.odd = (uint8_t) ut;
958
959 status = p.read(&ut,sizeof(ut));
960 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
961
962 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
963 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
964 status = p.read(&ut,sizeof(ut));
965 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
966 }
967
968 status = p.readInt32(&t);
969 rcsm.uBearerDataLen = (int) t;
970
971 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
972 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
973 status = p.read(&ut, sizeof(ut));
974 rcsm.aBearerData[digitCount] = (uint8_t) ut;
975 }
976
977 if (status != NO_ERROR) {
978 goto invalid;
979 }
980
981 startRequest;
982 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
983 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
984 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
985 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
986 closeRequest;
987
988 printRequest(pRI->token, pRI->pCI->requestNumber);
989
990 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
991
992#ifdef MEMSET_FREED
993 memset(&rcsm, 0, sizeof(rcsm));
994#endif
995
996 return;
997
998invalid:
999 invalidCommandBlock(pRI);
1000 return;
1001}
1002
1003static void
1004dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1005 RIL_CDMA_SMS_Ack rcsa;
1006 int32_t t;
1007 status_t status;
1008 int32_t digitCount;
1009
1010 memset(&rcsa, 0, sizeof(rcsa));
1011
1012 status = p.readInt32(&t);
1013 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1014
1015 status = p.readInt32(&t);
1016 rcsa.uSMSCauseCode = (int) t;
1017
1018 if (status != NO_ERROR) {
1019 goto invalid;
1020 }
1021
1022 startRequest;
1023 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1024 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1025 closeRequest;
1026
1027 printRequest(pRI->token, pRI->pCI->requestNumber);
1028
1029 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI);
1030
1031#ifdef MEMSET_FREED
1032 memset(&rcsa, 0, sizeof(rcsa));
1033#endif
1034
1035 return;
1036
1037invalid:
1038 invalidCommandBlock(pRI);
1039 return;
1040}
1041
1042static void
1043dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1044 int32_t t;
1045 status_t status;
1046 int32_t num;
1047
1048 status = p.readInt32(&num);
1049 if (status != NO_ERROR) {
1050 goto invalid;
1051 }
1052
codeworkxafc051f2013-07-27 09:02:14 +02001053 {
1054 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1055 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001056
codeworkxafc051f2013-07-27 09:02:14 +02001057 startRequest;
1058 for (int i = 0 ; i < num ; i++ ) {
1059 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001060
codeworkxafc051f2013-07-27 09:02:14 +02001061 status = p.readInt32(&t);
1062 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001063
codeworkxafc051f2013-07-27 09:02:14 +02001064 status = p.readInt32(&t);
1065 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001066
codeworkxafc051f2013-07-27 09:02:14 +02001067 status = p.readInt32(&t);
1068 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001069
codeworkxafc051f2013-07-27 09:02:14 +02001070 status = p.readInt32(&t);
1071 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001072
codeworkxafc051f2013-07-27 09:02:14 +02001073 status = p.readInt32(&t);
1074 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001075
codeworkxafc051f2013-07-27 09:02:14 +02001076 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1077 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1078 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1079 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1080 gsmBci[i].selected);
1081 }
1082 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001083
codeworkxafc051f2013-07-27 09:02:14 +02001084 if (status != NO_ERROR) {
1085 goto invalid;
1086 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001087
codeworkxafc051f2013-07-27 09:02:14 +02001088 s_callbacks.onRequest(pRI->pCI->requestNumber,
1089 gsmBciPtrs,
1090 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1091 pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001092
1093#ifdef MEMSET_FREED
codeworkxafc051f2013-07-27 09:02:14 +02001094 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1095 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001096#endif
codeworkxafc051f2013-07-27 09:02:14 +02001097 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001098
1099 return;
1100
1101invalid:
1102 invalidCommandBlock(pRI);
1103 return;
1104}
1105
1106static void
1107dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1108 int32_t t;
1109 status_t status;
1110 int32_t num;
1111
1112 status = p.readInt32(&num);
1113 if (status != NO_ERROR) {
1114 goto invalid;
1115 }
1116
codeworkxafc051f2013-07-27 09:02:14 +02001117 {
1118 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1119 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001120
codeworkxafc051f2013-07-27 09:02:14 +02001121 startRequest;
1122 for (int i = 0 ; i < num ; i++ ) {
1123 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001124
codeworkxafc051f2013-07-27 09:02:14 +02001125 status = p.readInt32(&t);
1126 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001127
codeworkxafc051f2013-07-27 09:02:14 +02001128 status = p.readInt32(&t);
1129 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001130
codeworkxafc051f2013-07-27 09:02:14 +02001131 status = p.readInt32(&t);
1132 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001133
codeworkxafc051f2013-07-27 09:02:14 +02001134 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1135 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1136 cdmaBci[i].language, cdmaBci[i].selected);
1137 }
1138 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001139
codeworkxafc051f2013-07-27 09:02:14 +02001140 if (status != NO_ERROR) {
1141 goto invalid;
1142 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001143
codeworkxafc051f2013-07-27 09:02:14 +02001144 s_callbacks.onRequest(pRI->pCI->requestNumber,
1145 cdmaBciPtrs,
1146 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1147 pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001148
1149#ifdef MEMSET_FREED
codeworkxafc051f2013-07-27 09:02:14 +02001150 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1151 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001152#endif
codeworkxafc051f2013-07-27 09:02:14 +02001153 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001154
1155 return;
1156
1157invalid:
1158 invalidCommandBlock(pRI);
1159 return;
1160}
1161
1162static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1163 RIL_CDMA_SMS_WriteArgs rcsw;
1164 int32_t t;
1165 uint32_t ut;
1166 uint8_t uct;
1167 status_t status;
1168 int32_t digitCount;
1169
1170 memset(&rcsw, 0, sizeof(rcsw));
1171
1172 status = p.readInt32(&t);
1173 rcsw.status = t;
1174
1175 status = p.readInt32(&t);
1176 rcsw.message.uTeleserviceID = (int) t;
1177
1178 status = p.read(&uct,sizeof(uct));
1179 rcsw.message.bIsServicePresent = (uint8_t) uct;
1180
1181 status = p.readInt32(&t);
1182 rcsw.message.uServicecategory = (int) t;
1183
1184 status = p.readInt32(&t);
1185 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1186
1187 status = p.readInt32(&t);
1188 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1189
1190 status = p.readInt32(&t);
1191 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1192
1193 status = p.readInt32(&t);
1194 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1195
1196 status = p.read(&uct,sizeof(uct));
1197 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1198
1199 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1200 status = p.read(&uct,sizeof(uct));
1201 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1202 }
1203
1204 status = p.readInt32(&t);
1205 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1206
1207 status = p.read(&uct,sizeof(uct));
1208 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1209
1210 status = p.read(&uct,sizeof(uct));
1211 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1212
1213 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1214 status = p.read(&uct,sizeof(uct));
1215 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1216 }
1217
1218 status = p.readInt32(&t);
1219 rcsw.message.uBearerDataLen = (int) t;
1220
1221 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1222 status = p.read(&uct, sizeof(uct));
1223 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1224 }
1225
1226 if (status != NO_ERROR) {
1227 goto invalid;
1228 }
1229
1230 startRequest;
1231 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1232 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1233 message.sAddress.number_mode=%d, \
1234 message.sAddress.number_type=%d, ",
1235 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1236 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1237 rcsw.message.sAddress.number_mode,
1238 rcsw.message.sAddress.number_type);
1239 closeRequest;
1240
1241 printRequest(pRI->token, pRI->pCI->requestNumber);
1242
1243 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI);
1244
1245#ifdef MEMSET_FREED
1246 memset(&rcsw, 0, sizeof(rcsw));
1247#endif
1248
1249 return;
1250
1251invalid:
1252 invalidCommandBlock(pRI);
1253 return;
1254
1255}
1256
codeworkxafc051f2013-07-27 09:02:14 +02001257// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1258// Version 4 of the RIL interface adds a new PDP type parameter to support
1259// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1260// RIL, remove the parameter from the request.
1261static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1262 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1263 const int numParamsRilV3 = 6;
1264
1265 // The first bytes of the RIL parcel contain the request number and the
1266 // serial number - see processCommandBuffer(). Copy them over too.
1267 int pos = p.dataPosition();
1268
1269 int numParams = p.readInt32();
1270 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1271 Parcel p2;
1272 p2.appendFrom(&p, 0, pos);
1273 p2.writeInt32(numParamsRilV3);
1274 for(int i = 0; i < numParamsRilV3; i++) {
1275 p2.writeString16(p.readString16());
1276 }
1277 p2.setDataPosition(pos);
1278 dispatchStrings(p2, pRI);
1279 } else {
1280 p.setDataPosition(pos);
1281 dispatchStrings(p, pRI);
1282 }
1283}
1284
1285// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1286// When all RILs handle this request, this function can be removed and
1287// the request can be sent directly to the RIL using dispatchVoid.
1288static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
1289 RIL_RadioState state = s_callbacks.onStateRequest();
1290
1291 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1292 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1293 }
1294
1295 // RILs that support RADIO_STATE_ON should support this request.
1296 if (RADIO_STATE_ON == state) {
1297 dispatchVoid(p, pRI);
1298 return;
1299 }
1300
1301 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1302 // will not support this new request either and decode Voice Radio Technology
1303 // from Radio State
1304 voiceRadioTech = decodeVoiceRadioTechnology(state);
1305
1306 if (voiceRadioTech < 0)
1307 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1308 else
1309 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1310}
1311
1312// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1313// When all RILs handle this request, this function can be removed and
1314// the request can be sent directly to the RIL using dispatchVoid.
1315static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
1316 RIL_RadioState state = s_callbacks.onStateRequest();
1317
1318 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1319 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1320 }
1321
1322 // RILs that support RADIO_STATE_ON should support this request.
1323 if (RADIO_STATE_ON == state) {
1324 dispatchVoid(p, pRI);
1325 return;
1326 }
1327
1328 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1329 // will not support this new request either and decode CDMA Subscription Source
1330 // from Radio State
1331 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1332
1333 if (cdmaSubscriptionSource < 0)
1334 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1335 else
1336 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1337}
1338
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001339static int
1340blockingWrite(int fd, const void *buffer, size_t len) {
1341 size_t writeOffset = 0;
1342 const uint8_t *toWrite;
1343
1344 toWrite = (const uint8_t *)buffer;
1345
1346 while (writeOffset < len) {
1347 ssize_t written;
1348 do {
1349 written = write (fd, toWrite + writeOffset,
1350 len - writeOffset);
codeworkxafc051f2013-07-27 09:02:14 +02001351 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001352
1353 if (written >= 0) {
1354 writeOffset += written;
1355 } else { // written < 0
codeworkxafc051f2013-07-27 09:02:14 +02001356 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001357 close(fd);
1358 return -1;
1359 }
1360 }
1361
1362 return 0;
1363}
1364
1365static int
1366sendResponseRaw (const void *data, size_t dataSize) {
1367 int fd = s_fdCommand;
1368 int ret;
1369 uint32_t header;
1370
1371 if (s_fdCommand < 0) {
1372 return -1;
1373 }
1374
1375 if (dataSize > MAX_COMMAND_BYTES) {
codeworkxafc051f2013-07-27 09:02:14 +02001376 RLOGE("RIL: packet larger than %u (%u)",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001377 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1378
1379 return -1;
1380 }
1381
1382 pthread_mutex_lock(&s_writeMutex);
1383
1384 header = htonl(dataSize);
1385
1386 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1387
1388 if (ret < 0) {
1389 pthread_mutex_unlock(&s_writeMutex);
1390 return ret;
1391 }
1392
1393 ret = blockingWrite(fd, data, dataSize);
1394
1395 if (ret < 0) {
1396 pthread_mutex_unlock(&s_writeMutex);
1397 return ret;
1398 }
1399
1400 pthread_mutex_unlock(&s_writeMutex);
1401
1402 return 0;
1403}
1404
1405static int
1406sendResponse (Parcel &p) {
1407 printResponse;
1408 return sendResponseRaw(p.data(), p.dataSize());
1409}
1410
1411/** response is an int* pointing to an array of ints*/
1412
1413static int
1414responseInts(Parcel &p, void *response, size_t responselen) {
1415 int numInts;
1416
1417 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001418 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001419 return RIL_ERRNO_INVALID_RESPONSE;
1420 }
1421 if (responselen % sizeof(int) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001422 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001423 (int)responselen, (int)sizeof(int));
1424 return RIL_ERRNO_INVALID_RESPONSE;
1425 }
1426
1427 int *p_int = (int *) response;
1428
1429 numInts = responselen / sizeof(int *);
1430 p.writeInt32 (numInts);
1431
1432 /* each int*/
1433 startResponse;
1434 for (int i = 0 ; i < numInts ; i++) {
1435 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1436 p.writeInt32(p_int[i]);
1437 }
1438 removeLastChar;
1439 closeResponse;
1440
1441 return 0;
1442}
1443
1444static int
1445responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
1446 int numInts;
1447
1448 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001449 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001450 return RIL_ERRNO_INVALID_RESPONSE;
1451 }
1452 if (responselen % sizeof(int) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001453 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001454 (int)responselen, (int)sizeof(int));
1455 return RIL_ERRNO_INVALID_RESPONSE;
1456 }
1457
1458 int *p_int = (int *) response;
1459
1460 numInts = responselen / sizeof(int *);
1461 p.writeInt32 (numInts);
1462
1463 /* each int*/
1464 startResponse;
1465 for (int i = 0 ; i < numInts ; i++) {
1466 if (i == 0 && p_int[0] == 7) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02001467 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001468 p_int[0] = 0;
1469 }
1470 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1471 p.writeInt32(p_int[i]);
1472 }
1473 removeLastChar;
1474 closeResponse;
1475
1476 return 0;
1477}
1478
1479/** response is a char **, pointing to an array of char *'s
1480 The parcel will begin with the version */
1481static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1482 p.writeInt32(version);
1483 return responseStrings(p, response, responselen);
1484}
1485
1486/** response is a char **, pointing to an array of char *'s */
1487static int responseStrings(Parcel &p, void *response, size_t responselen) {
1488 return responseStrings(p, response, responselen, false);
1489}
1490
1491static int responseStringsNetworks(Parcel &p, void *response, size_t responselen) {
1492 int numStrings;
1493 int inQANElements = 5;
1494 int outQANElements = 4;
1495
1496 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001497 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001498 return RIL_ERRNO_INVALID_RESPONSE;
1499 }
1500 if (responselen % sizeof(char *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001501 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001502 (int)responselen, (int)sizeof(char *));
1503 return RIL_ERRNO_INVALID_RESPONSE;
1504 }
1505
1506 if (response == NULL) {
1507 p.writeInt32 (0);
1508 } else {
1509 char **p_cur = (char **) response;
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02001510 int j = 0;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001511
1512 numStrings = responselen / sizeof(char *);
1513 p.writeInt32 ((numStrings / inQANElements) * outQANElements);
1514
1515 /* each string*/
1516 startResponse;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001517 for (int i = 0 ; i < numStrings ; i++) {
1518 /* Samsung is sending 5 elements, upper layer expects 4.
1519 Drop every 5th element here */
1520 if (j == outQANElements) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02001521 j = 0;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001522 } else {
1523 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1524 writeStringToParcel (p, p_cur[i]);
1525 j++;
1526 }
1527 }
1528 removeLastChar;
1529 closeResponse;
1530 }
1531 return 0;
1532}
1533
1534/** response is a char **, pointing to an array of char *'s */
1535static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
1536 int numStrings;
1537
1538 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001539 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001540 return RIL_ERRNO_INVALID_RESPONSE;
1541 }
1542 if (responselen % sizeof(char *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001543 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001544 (int)responselen, (int)sizeof(char *));
1545 return RIL_ERRNO_INVALID_RESPONSE;
1546 }
1547
1548 if (response == NULL) {
1549 p.writeInt32 (0);
1550 } else {
1551 char **p_cur = (char **) response;
1552
1553 numStrings = responselen / sizeof(char *);
1554 p.writeInt32 (numStrings);
1555
1556 /* each string*/
1557 startResponse;
1558 for (int i = 0 ; i < numStrings ; i++) {
1559 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1560 writeStringToParcel (p, p_cur[i]);
1561 }
1562 removeLastChar;
1563 closeResponse;
1564 }
1565 return 0;
1566}
1567
1568/**
1569 * NULL strings are accepted
1570 * FIXME currently ignores responselen
1571 */
1572static int responseString(Parcel &p, void *response, size_t responselen) {
1573 /* one string only */
1574 startResponse;
1575 appendPrintBuf("%s%s", printBuf, (char*)response);
1576 closeResponse;
1577
1578 writeStringToParcel(p, (const char *)response);
1579
1580 return 0;
1581}
1582
1583static int responseVoid(Parcel &p, void *response, size_t responselen) {
1584 startResponse;
1585 removeLastChar;
1586 return 0;
1587}
1588
1589static int responseCallList(Parcel &p, void *response, size_t responselen) {
1590 int num;
1591
1592 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001593 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001594 return RIL_ERRNO_INVALID_RESPONSE;
1595 }
1596
1597 if (responselen % sizeof (RIL_Call *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001598 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001599 (int)responselen, (int)sizeof (RIL_Call *));
1600 return RIL_ERRNO_INVALID_RESPONSE;
1601 }
1602
1603 startResponse;
1604 /* number of call info's */
1605 num = responselen / sizeof(RIL_Call *);
1606 p.writeInt32(num);
1607
1608 for (int i = 0 ; i < num ; i++) {
1609 RIL_Call *p_cur = ((RIL_Call **) response)[i];
1610 /* each call info */
1611 p.writeInt32(p_cur->state);
1612 p.writeInt32(p_cur->index);
1613 p.writeInt32(p_cur->toa);
1614 p.writeInt32(p_cur->isMpty);
1615 p.writeInt32(p_cur->isMT);
1616 p.writeInt32(p_cur->als);
1617 p.writeInt32(p_cur->isVoice);
1618 p.writeInt32(p_cur->isVoicePrivacy);
1619 writeStringToParcel(p, p_cur->number);
1620 p.writeInt32(p_cur->numberPresentation);
1621 writeStringToParcel(p, p_cur->name);
1622 p.writeInt32(p_cur->namePresentation);
Daniel Hillenbrandea4af612013-07-09 18:47:06 +02001623 // Remove when partners upgrade to version 3
1624 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
1625 p.writeInt32(0); /* UUS Information is absent */
1626 } else {
1627 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
1628 p.writeInt32(1); /* UUS Information is present */
1629 p.writeInt32(uusInfo->uusType);
1630 p.writeInt32(uusInfo->uusDcs);
1631 p.writeInt32(uusInfo->uusLength);
1632 p.write(uusInfo->uusData, uusInfo->uusLength);
1633 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001634 appendPrintBuf("%s[id=%d,%s,toa=%d,",
1635 printBuf,
1636 p_cur->index,
1637 callStateToString(p_cur->state),
1638 p_cur->toa);
1639 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
1640 printBuf,
1641 (p_cur->isMpty)?"conf":"norm",
1642 (p_cur->isMT)?"mt":"mo",
1643 p_cur->als,
1644 (p_cur->isVoice)?"voc":"nonvoc",
1645 (p_cur->isVoicePrivacy)?"evp":"noevp");
1646 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
1647 printBuf,
1648 p_cur->number,
1649 p_cur->numberPresentation,
1650 p_cur->name,
1651 p_cur->namePresentation);
1652 }
1653 removeLastChar;
1654 closeResponse;
1655
1656 return 0;
1657}
1658
1659static int responseSMS(Parcel &p, void *response, size_t responselen) {
1660 if (response == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02001661 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001662 return RIL_ERRNO_INVALID_RESPONSE;
1663 }
1664
1665 if (responselen != sizeof (RIL_SMS_Response) ) {
codeworkxafc051f2013-07-27 09:02:14 +02001666 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001667 (int)responselen, (int)sizeof (RIL_SMS_Response));
1668 return RIL_ERRNO_INVALID_RESPONSE;
1669 }
1670
1671 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1672
1673 p.writeInt32(p_cur->messageRef);
1674 writeStringToParcel(p, p_cur->ackPDU);
1675 p.writeInt32(p_cur->errorCode);
1676
1677 startResponse;
1678 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
1679 (char*)p_cur->ackPDU, p_cur->errorCode);
1680 closeResponse;
1681
1682 return 0;
1683}
1684
codeworkxafc051f2013-07-27 09:02:14 +02001685static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001686{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001687 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001688 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001689 return RIL_ERRNO_INVALID_RESPONSE;
1690 }
1691
codeworkxafc051f2013-07-27 09:02:14 +02001692 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
1693 RLOGE("invalid response length %d expected multiple of %d",
1694 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001695 return RIL_ERRNO_INVALID_RESPONSE;
1696 }
1697
codeworkxafc051f2013-07-27 09:02:14 +02001698 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001699 p.writeInt32(num);
1700
codeworkxafc051f2013-07-27 09:02:14 +02001701 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001702 startResponse;
codeworkxafc051f2013-07-27 09:02:14 +02001703 int i;
1704 for (i = 0; i < num; i++) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001705 p.writeInt32(p_cur[i].cid);
1706 p.writeInt32(p_cur[i].active);
1707 writeStringToParcel(p, p_cur[i].type);
codeworkxafc051f2013-07-27 09:02:14 +02001708 // apn is not used, so don't send.
1709 writeStringToParcel(p, p_cur[i].address);
1710 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001711 p_cur[i].cid,
1712 (p_cur[i].active==0)?"down":"up",
1713 (char*)p_cur[i].type,
codeworkxafc051f2013-07-27 09:02:14 +02001714 (char*)p_cur[i].address);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001715 }
1716 removeLastChar;
1717 closeResponse;
1718
1719 return 0;
1720}
1721
codeworkxafc051f2013-07-27 09:02:14 +02001722static int responseDataCallList(Parcel &p, void *response, size_t responselen)
1723{
1724 // Write version
1725 p.writeInt32(s_callbacks.version);
1726
1727 if (s_callbacks.version < 5) {
1728 return responseDataCallListV4(p, response, responselen);
1729 } else {
1730 if (response == NULL && responselen != 0) {
1731 RLOGE("invalid response: NULL");
1732 return RIL_ERRNO_INVALID_RESPONSE;
1733 }
1734
1735 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
1736 RLOGE("invalid response length %d expected multiple of %d",
1737 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
1738 return RIL_ERRNO_INVALID_RESPONSE;
1739 }
1740
1741 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
1742 p.writeInt32(num);
1743
1744 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
1745 startResponse;
1746 int i;
1747 for (i = 0; i < num; i++) {
1748 p.writeInt32((int)p_cur[i].status);
1749 p.writeInt32(p_cur[i].suggestedRetryTime);
1750 p.writeInt32(p_cur[i].cid);
1751 p.writeInt32(p_cur[i].active);
1752 writeStringToParcel(p, p_cur[i].type);
1753 writeStringToParcel(p, p_cur[i].ifname);
1754 writeStringToParcel(p, p_cur[i].addresses);
1755 writeStringToParcel(p, p_cur[i].dnses);
1756 writeStringToParcel(p, p_cur[i].gateways);
1757 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
1758 p_cur[i].status,
1759 p_cur[i].suggestedRetryTime,
1760 p_cur[i].cid,
1761 (p_cur[i].active==0)?"down":"up",
1762 (char*)p_cur[i].type,
1763 (char*)p_cur[i].ifname,
1764 (char*)p_cur[i].addresses,
1765 (char*)p_cur[i].dnses,
1766 (char*)p_cur[i].gateways);
1767 }
1768 removeLastChar;
1769 closeResponse;
1770 }
1771
1772 return 0;
1773}
1774
1775static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
1776{
1777 if (s_callbacks.version < 5) {
1778 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
1779 } else {
1780 return responseDataCallList(p, response, responselen);
1781 }
1782}
1783
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001784static int responseRaw(Parcel &p, void *response, size_t responselen) {
1785 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001786 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001787 return RIL_ERRNO_INVALID_RESPONSE;
1788 }
1789
1790 // The java code reads -1 size as null byte array
1791 if (response == NULL) {
1792 p.writeInt32(-1);
1793 } else {
1794 p.writeInt32(responselen);
1795 p.write(response, responselen);
1796 }
1797
1798 return 0;
1799}
1800
1801
1802static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
1803 if (response == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02001804 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001805 return RIL_ERRNO_INVALID_RESPONSE;
1806 }
1807
1808 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
codeworkxafc051f2013-07-27 09:02:14 +02001809 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001810 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
1811 return RIL_ERRNO_INVALID_RESPONSE;
1812 }
1813
1814 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
1815 p.writeInt32(p_cur->sw1);
1816 p.writeInt32(p_cur->sw2);
1817 writeStringToParcel(p, p_cur->simResponse);
1818
1819 startResponse;
1820 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
1821 (char*)p_cur->simResponse);
1822 closeResponse;
1823
1824
1825 return 0;
1826}
1827
1828static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
1829 int num;
1830
1831 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001832 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001833 return RIL_ERRNO_INVALID_RESPONSE;
1834 }
1835
1836 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001837 RLOGE("invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001838 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
1839 return RIL_ERRNO_INVALID_RESPONSE;
1840 }
1841
1842 /* number of call info's */
1843 num = responselen / sizeof(RIL_CallForwardInfo *);
1844 p.writeInt32(num);
1845
1846 startResponse;
1847 for (int i = 0 ; i < num ; i++) {
1848 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
1849
1850 p.writeInt32(p_cur->status);
1851 p.writeInt32(p_cur->reason);
1852 p.writeInt32(p_cur->serviceClass);
1853 p.writeInt32(p_cur->toa);
1854 writeStringToParcel(p, p_cur->number);
1855 p.writeInt32(p_cur->timeSeconds);
1856 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
1857 (p_cur->status==1)?"enable":"disable",
1858 p_cur->reason, p_cur->serviceClass, p_cur->toa,
1859 (char*)p_cur->number,
1860 p_cur->timeSeconds);
1861 }
1862 removeLastChar;
1863 closeResponse;
1864
1865 return 0;
1866}
1867
1868static int responseSsn(Parcel &p, void *response, size_t responselen) {
1869 if (response == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02001870 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001871 return RIL_ERRNO_INVALID_RESPONSE;
1872 }
1873
1874 if (responselen != sizeof(RIL_SuppSvcNotification)) {
codeworkxafc051f2013-07-27 09:02:14 +02001875 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001876 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
1877 return RIL_ERRNO_INVALID_RESPONSE;
1878 }
1879
1880 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
1881 p.writeInt32(p_cur->notificationType);
1882 p.writeInt32(p_cur->code);
1883 p.writeInt32(p_cur->index);
1884 p.writeInt32(p_cur->type);
1885 writeStringToParcel(p, p_cur->number);
1886
1887 startResponse;
1888 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
1889 (p_cur->notificationType==0)?"mo":"mt",
1890 p_cur->code, p_cur->index, p_cur->type,
1891 (char*)p_cur->number);
1892 closeResponse;
1893
1894 return 0;
1895}
1896
1897static int responseCellList(Parcel &p, void *response, size_t responselen) {
1898 int num;
1899
1900 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001901 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001902 return RIL_ERRNO_INVALID_RESPONSE;
1903 }
1904
1905 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001906 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001907 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
1908 return RIL_ERRNO_INVALID_RESPONSE;
1909 }
1910
1911 startResponse;
1912 /* number of records */
1913 num = responselen / sizeof(RIL_NeighboringCell *);
1914 p.writeInt32(num);
1915
1916 for (int i = 0 ; i < num ; i++) {
1917 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
1918
1919 p.writeInt32(p_cur->rssi);
1920 writeStringToParcel (p, p_cur->cid);
1921
1922 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
1923 p_cur->cid, p_cur->rssi);
1924 }
1925 removeLastChar;
1926 closeResponse;
1927
1928 return 0;
1929}
1930
1931/**
1932 * Marshall the signalInfoRecord into the parcel if it exists.
1933 */
1934static void marshallSignalInfoRecord(Parcel &p,
1935 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
1936 p.writeInt32(p_signalInfoRecord.isPresent);
1937 p.writeInt32(p_signalInfoRecord.signalType);
1938 p.writeInt32(p_signalInfoRecord.alertPitch);
1939 p.writeInt32(p_signalInfoRecord.signal);
1940}
1941
1942static int responseCdmaInformationRecords(Parcel &p,
1943 void *response, size_t responselen) {
1944 int num;
1945 char* string8 = NULL;
1946 int buffer_lenght;
1947 RIL_CDMA_InformationRecord *infoRec;
1948
1949 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001950 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001951 return RIL_ERRNO_INVALID_RESPONSE;
1952 }
1953
1954 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
codeworkxafc051f2013-07-27 09:02:14 +02001955 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001956 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
1957 return RIL_ERRNO_INVALID_RESPONSE;
1958 }
1959
1960 RIL_CDMA_InformationRecords *p_cur =
1961 (RIL_CDMA_InformationRecords *) response;
1962 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
1963
1964 startResponse;
1965 p.writeInt32(num);
1966
1967 for (int i = 0 ; i < num ; i++) {
1968 infoRec = &p_cur->infoRec[i];
1969 p.writeInt32(infoRec->name);
1970 switch (infoRec->name) {
1971 case RIL_CDMA_DISPLAY_INFO_REC:
1972 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
1973 if (infoRec->rec.display.alpha_len >
1974 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
codeworkxafc051f2013-07-27 09:02:14 +02001975 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001976 expected not more than %d\n",
1977 (int)infoRec->rec.display.alpha_len,
1978 CDMA_ALPHA_INFO_BUFFER_LENGTH);
1979 return RIL_ERRNO_INVALID_RESPONSE;
1980 }
1981 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
1982 * sizeof(char) );
1983 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
1984 string8[i] = infoRec->rec.display.alpha_buf[i];
1985 }
1986 string8[(int)infoRec->rec.display.alpha_len] = '\0';
1987 writeStringToParcel(p, (const char*)string8);
1988 free(string8);
1989 string8 = NULL;
1990 break;
1991 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
1992 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
1993 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
1994 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
codeworkxafc051f2013-07-27 09:02:14 +02001995 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001996 expected not more than %d\n",
1997 (int)infoRec->rec.number.len,
1998 CDMA_NUMBER_INFO_BUFFER_LENGTH);
1999 return RIL_ERRNO_INVALID_RESPONSE;
2000 }
2001 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2002 * sizeof(char) );
2003 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2004 string8[i] = infoRec->rec.number.buf[i];
2005 }
2006 string8[(int)infoRec->rec.number.len] = '\0';
2007 writeStringToParcel(p, (const char*)string8);
2008 free(string8);
2009 string8 = NULL;
2010 p.writeInt32(infoRec->rec.number.number_type);
2011 p.writeInt32(infoRec->rec.number.number_plan);
2012 p.writeInt32(infoRec->rec.number.pi);
2013 p.writeInt32(infoRec->rec.number.si);
2014 break;
2015 case RIL_CDMA_SIGNAL_INFO_REC:
2016 p.writeInt32(infoRec->rec.signal.isPresent);
2017 p.writeInt32(infoRec->rec.signal.signalType);
2018 p.writeInt32(infoRec->rec.signal.alertPitch);
2019 p.writeInt32(infoRec->rec.signal.signal);
2020
2021 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2022 alertPitch=%X, signal=%X, ",
2023 printBuf, (int)infoRec->rec.signal.isPresent,
2024 (int)infoRec->rec.signal.signalType,
2025 (int)infoRec->rec.signal.alertPitch,
2026 (int)infoRec->rec.signal.signal);
2027 removeLastChar;
2028 break;
2029 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2030 if (infoRec->rec.redir.redirectingNumber.len >
2031 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
codeworkxafc051f2013-07-27 09:02:14 +02002032 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002033 expected not more than %d\n",
2034 (int)infoRec->rec.redir.redirectingNumber.len,
2035 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2036 return RIL_ERRNO_INVALID_RESPONSE;
2037 }
2038 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2039 .len + 1) * sizeof(char) );
2040 for (int i = 0;
2041 i < infoRec->rec.redir.redirectingNumber.len;
2042 i++) {
2043 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2044 }
2045 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2046 writeStringToParcel(p, (const char*)string8);
2047 free(string8);
2048 string8 = NULL;
2049 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2050 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2051 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2052 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2053 p.writeInt32(infoRec->rec.redir.redirectingReason);
2054 break;
2055 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2056 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2057 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2058 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2059 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2060
2061 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2062 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2063 lineCtrlPowerDenial=%d, ", printBuf,
2064 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2065 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2066 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2067 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2068 removeLastChar;
2069 break;
2070 case RIL_CDMA_T53_CLIR_INFO_REC:
2071 p.writeInt32((int)(infoRec->rec.clir.cause));
2072
2073 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2074 removeLastChar;
2075 break;
2076 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2077 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2078 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2079
2080 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2081 infoRec->rec.audioCtrl.upLink,
2082 infoRec->rec.audioCtrl.downLink);
2083 removeLastChar;
2084 break;
2085 case RIL_CDMA_T53_RELEASE_INFO_REC:
2086 // TODO(Moto): See David Krause, he has the answer:)
codeworkxafc051f2013-07-27 09:02:14 +02002087 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002088 return RIL_ERRNO_INVALID_RESPONSE;
2089 default:
codeworkxafc051f2013-07-27 09:02:14 +02002090 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002091 return RIL_ERRNO_INVALID_RESPONSE;
2092 }
2093 }
2094 closeResponse;
2095
2096 return 0;
2097}
2098
2099static int responseRilSignalStrength(Parcel &p,
2100 void *response, size_t responselen) {
2101
2102 int gsmSignalStrength;
2103
2104 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002105 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002106 return RIL_ERRNO_INVALID_RESPONSE;
2107 }
2108
codeworkxafc051f2013-07-27 09:02:14 +02002109 RLOGE("responseRilSignalStrength()");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002110
2111 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2112 RIL_SignalStrength_v6 *p_cur = ((RIL_SignalStrength_v6 *) response);
2113
2114 /* gsmSignalStrength */
codeworkxafc051f2013-07-27 09:02:14 +02002115 RLOGD("gsmSignalStrength (raw)=%d", p_cur->GW_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002116 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
codeworkxafc051f2013-07-27 09:02:14 +02002117 RLOGD("gsmSignalStrength (corrected)=%d", gsmSignalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002118
2119 /*
2120 * if gsmSignalStrength isn't a valid value, use cdmaDbm as fallback.
2121 * This is needed for old modem firmwares.
2122 */
2123 if (gsmSignalStrength < 0 || (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
codeworkxafc051f2013-07-27 09:02:14 +02002124 RLOGD("gsmSignalStrength-fallback (raw)=%d", p_cur->CDMA_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002125 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
2126 if (gsmSignalStrength < 0) {
2127 gsmSignalStrength = 99;
2128 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
2129 gsmSignalStrength = 31;
2130 }
codeworkxafc051f2013-07-27 09:02:14 +02002131 RLOGD("gsmSignalStrength-fallback (corrected)=%d", gsmSignalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002132 }
2133 p.writeInt32(gsmSignalStrength);
2134
2135 /* gsmBitErrorRate */
2136 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2137 /* cdmaDbm */
2138 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2139 /* cdmaEcio */
2140 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2141 /* evdoDbm */
2142 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2143 /* evdoEcio */
2144 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2145 /* evdoSnr */
2146 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2147
2148 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
2149 /* lteSignalStrength */
2150 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2151
2152 /*
2153 * ril version <=6 receives negative values for rsrp
2154 * workaround for backward compatibility
2155 */
2156 p_cur->LTE_SignalStrength.rsrp =
2157 ((s_callbacks.version <= 6) && (p_cur->LTE_SignalStrength.rsrp < 0 )) ?
2158 -(p_cur->LTE_SignalStrength.rsrp) : p_cur->LTE_SignalStrength.rsrp;
2159
2160 /* lteRsrp */
2161 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2162 /* lteRsrq */
2163 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2164 /* lteRssnr */
2165 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2166 /* lteCqi */
2167 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2168
2169 } else {
2170 memset(&p_cur->LTE_SignalStrength, sizeof (RIL_LTE_SignalStrength), 0);
2171 }
2172
2173 startResponse;
2174 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
2175 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2176 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2177 EVDO_SS.signalNoiseRatio=%d,\
2178 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
2179 LTE_SS.rssnr=%d,LTE_SS.cqi=%d]",
2180 printBuf,
2181 gsmSignalStrength,
2182 p_cur->GW_SignalStrength.bitErrorRate,
2183 p_cur->CDMA_SignalStrength.dbm,
2184 p_cur->CDMA_SignalStrength.ecio,
2185 p_cur->EVDO_SignalStrength.dbm,
2186 p_cur->EVDO_SignalStrength.ecio,
2187 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2188 p_cur->LTE_SignalStrength.signalStrength,
2189 p_cur->LTE_SignalStrength.rsrp,
2190 p_cur->LTE_SignalStrength.rsrq,
2191 p_cur->LTE_SignalStrength.rssnr,
2192 p_cur->LTE_SignalStrength.cqi);
2193 closeResponse;
2194
2195 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002196 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002197 return RIL_ERRNO_INVALID_RESPONSE;
2198 }
2199
2200 return 0;
2201}
2202
2203static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2204 if ((response == NULL) || (responselen == 0)) {
2205 return responseVoid(p, response, responselen);
2206 } else {
2207 return responseCdmaSignalInfoRecord(p, response, responselen);
2208 }
2209}
2210
2211static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2212 if (response == NULL || responselen == 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002213 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002214 return RIL_ERRNO_INVALID_RESPONSE;
2215 }
2216
2217 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
codeworkxafc051f2013-07-27 09:02:14 +02002218 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002219 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2220 return RIL_ERRNO_INVALID_RESPONSE;
2221 }
2222
2223 startResponse;
2224
2225 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2226 marshallSignalInfoRecord(p, *p_cur);
2227
2228 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2229 signal=%d]",
2230 printBuf,
2231 p_cur->isPresent,
2232 p_cur->signalType,
2233 p_cur->alertPitch,
2234 p_cur->signal);
2235
2236 closeResponse;
2237 return 0;
2238}
2239
2240static int responseCdmaCallWaiting(Parcel &p, void *response,
2241 size_t responselen) {
2242 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002243 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002244 return RIL_ERRNO_INVALID_RESPONSE;
2245 }
2246
2247 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
codeworkxafc051f2013-07-27 09:02:14 +02002248 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002249 }
2250
2251 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2252
2253 writeStringToParcel(p, p_cur->number);
2254 p.writeInt32(p_cur->numberPresentation);
2255 writeStringToParcel(p, p_cur->name);
2256 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2257
2258 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2259 p.writeInt32(p_cur->number_type);
2260 p.writeInt32(p_cur->number_plan);
2261 } else {
2262 p.writeInt32(0);
2263 p.writeInt32(0);
2264 }
2265
2266 startResponse;
2267 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2268 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2269 signal=%d,number_type=%d,number_plan=%d]",
2270 printBuf,
2271 p_cur->number,
2272 p_cur->numberPresentation,
2273 p_cur->name,
2274 p_cur->signalInfoRecord.isPresent,
2275 p_cur->signalInfoRecord.signalType,
2276 p_cur->signalInfoRecord.alertPitch,
2277 p_cur->signalInfoRecord.signal,
2278 p_cur->number_type,
2279 p_cur->number_plan);
2280 closeResponse;
2281
2282 return 0;
2283}
2284
2285static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2286 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002287 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002288 return RIL_ERRNO_INVALID_RESPONSE;
2289 }
2290
2291 startResponse;
2292 if (s_callbacks.version == 7) {
2293 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2294 p.writeInt32(p_cur->result);
2295 p.writeInt32(p_cur->ef_id);
2296 writeStringToParcel(p, p_cur->aid);
2297
2298 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2299 printBuf,
2300 p_cur->result,
2301 p_cur->ef_id,
2302 p_cur->aid);
2303 } else {
2304 int *p_cur = ((int *) response);
2305 p.writeInt32(p_cur[0]);
2306 p.writeInt32(p_cur[1]);
2307 writeStringToParcel(p, NULL);
2308
2309 appendPrintBuf("%sresult=%d, ef_id=%d",
2310 printBuf,
2311 p_cur[0],
2312 p_cur[1]);
2313 }
2314 closeResponse;
2315
2316 return 0;
2317}
2318
codeworkxafc051f2013-07-27 09:02:14 +02002319static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2320{
2321 if (response == NULL && responselen != 0) {
2322 RLOGE("invalid response: NULL");
2323 return RIL_ERRNO_INVALID_RESPONSE;
2324 }
2325
2326 if (responselen % sizeof(RIL_CellInfo) != 0) {
2327 RLOGE("invalid response length %d expected multiple of %d",
2328 (int)responselen, (int)sizeof(RIL_CellInfo));
2329 return RIL_ERRNO_INVALID_RESPONSE;
2330 }
2331
2332 int num = responselen / sizeof(RIL_CellInfo);
2333 p.writeInt32(num);
2334
2335 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2336 startResponse;
2337 int i;
2338 for (i = 0; i < num; i++) {
2339 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2340 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2341 p.writeInt32((int)p_cur->cellInfoType);
2342 p.writeInt32(p_cur->registered);
2343 p.writeInt32(p_cur->timeStampType);
2344 p.writeInt64(p_cur->timeStamp);
2345 switch(p_cur->cellInfoType) {
2346 case RIL_CELL_INFO_TYPE_GSM: {
2347 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
2348 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2349 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2350 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
2351 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2352 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
2353 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2354 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2355
2356 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2357 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2358 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2359 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2360 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2361 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2362 break;
2363 }
2364 case RIL_CELL_INFO_TYPE_WCDMA: {
2365 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2366 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2367 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2368 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2369 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2370 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2371 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2372 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2373 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2374
2375 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2376 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2377 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2378 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2379 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2380 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2381 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2382 break;
2383 }
2384 case RIL_CELL_INFO_TYPE_CDMA: {
2385 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2386 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2387 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2388 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2389 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2390 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2391
2392 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2393 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
2394 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
2395 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
2396 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2397
2398 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
2399 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
2400 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
2401 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
2402 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
2403 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2404
2405 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
2406 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
2407 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
2408 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
2409 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2410 break;
2411 }
2412 case RIL_CELL_INFO_TYPE_LTE: {
2413 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
2414 p_cur->CellInfo.lte.cellIdentityLte.mcc,
2415 p_cur->CellInfo.lte.cellIdentityLte.mnc,
2416 p_cur->CellInfo.lte.cellIdentityLte.ci,
2417 p_cur->CellInfo.lte.cellIdentityLte.pci,
2418 p_cur->CellInfo.lte.cellIdentityLte.tac);
2419
2420 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
2421 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
2422 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
2423 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
2424 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
2425
2426 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
2427 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
2428 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
2429 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
2430 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
2431 p_cur->CellInfo.lte.signalStrengthLte.cqi,
2432 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2433 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
2434 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
2435 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
2436 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
2437 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
2438 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2439 break;
2440 }
2441 }
2442 p_cur += 1;
2443 }
2444 removeLastChar;
2445 closeResponse;
2446
2447 return 0;
2448}
2449
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002450static void triggerEvLoop() {
2451 int ret;
2452 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
2453 /* trigger event loop to wakeup. No reason to do this,
2454 * if we're in the event loop thread */
2455 do {
2456 ret = write (s_fdWakeupWrite, " ", 1);
2457 } while (ret < 0 && errno == EINTR);
2458 }
2459}
2460
2461static void rilEventAddWakeup(struct ril_event *ev) {
2462 ril_event_add(ev);
2463 triggerEvLoop();
2464}
2465
2466static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
2467 p.writeInt32(num_apps);
2468 startResponse;
2469 for (int i = 0; i < num_apps; i++) {
2470 p.writeInt32(appStatus[i].app_type);
2471 p.writeInt32(appStatus[i].app_state);
2472 p.writeInt32(appStatus[i].perso_substate);
2473 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
2474 writeStringToParcel(p, (const char*)
2475 (appStatus[i].app_label_ptr));
2476 p.writeInt32(appStatus[i].pin1_replaced);
2477 p.writeInt32(appStatus[i].pin1);
2478 p.writeInt32(appStatus[i].pin2);
2479 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
2480 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
2481 printBuf,
2482 appStatus[i].app_type,
2483 appStatus[i].app_state,
2484 appStatus[i].perso_substate,
2485 appStatus[i].aid_ptr,
2486 appStatus[i].app_label_ptr,
2487 appStatus[i].pin1_replaced,
2488 appStatus[i].pin1,
2489 appStatus[i].pin2);
2490 }
2491 closeResponse;
2492}
2493
2494static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
codeworkxafc051f2013-07-27 09:02:14 +02002495 int i;
2496
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002497 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002498 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002499 return RIL_ERRNO_INVALID_RESPONSE;
2500 }
2501
2502 if (responselen == sizeof (RIL_CardStatus_v6)) {
codeworkxafc051f2013-07-27 09:02:14 +02002503 RLOGE("RIL_CardStatus_v6");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002504 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
2505
2506 p.writeInt32(p_cur->card_state);
2507 p.writeInt32(p_cur->universal_pin_state);
2508 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2509 p.writeInt32(p_cur->cdma_subscription_app_index);
2510 p.writeInt32(p_cur->ims_subscription_app_index);
2511
2512 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2513 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
codeworkxafc051f2013-07-27 09:02:14 +02002514 RLOGE("RIL_CardStatus_v5");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002515 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
2516
2517 p.writeInt32(p_cur->card_state);
2518 p.writeInt32(p_cur->universal_pin_state);
2519 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2520 p.writeInt32(p_cur->cdma_subscription_app_index);
2521 p.writeInt32(-1);
2522
2523 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2524 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002525 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
2526 RLOGE("responselen=%d", responselen);
2527 RLOGE("RIL_CardStatus_v5=%d", sizeof (RIL_CardStatus_v5));
2528 RLOGE("RIL_CardStatus_v6=%d", sizeof (RIL_CardStatus_v6));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002529 return RIL_ERRNO_INVALID_RESPONSE;
2530 }
2531
2532 return 0;
2533}
2534
2535static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2536 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
2537 p.writeInt32(num);
2538
2539 startResponse;
2540 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
2541 (RIL_GSM_BroadcastSmsConfigInfo **) response;
2542 for (int i = 0; i < num; i++) {
2543 p.writeInt32(p_cur[i]->fromServiceId);
2544 p.writeInt32(p_cur[i]->toServiceId);
2545 p.writeInt32(p_cur[i]->fromCodeScheme);
2546 p.writeInt32(p_cur[i]->toCodeScheme);
2547 p.writeInt32(p_cur[i]->selected);
2548
2549 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
2550 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
2551 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
2552 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
2553 p_cur[i]->selected);
2554 }
2555 closeResponse;
2556
2557 return 0;
2558}
2559
2560static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2561 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
2562 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
2563
2564 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
2565 p.writeInt32(num);
2566
2567 startResponse;
2568 for (int i = 0 ; i < num ; i++ ) {
2569 p.writeInt32(p_cur[i]->service_category);
2570 p.writeInt32(p_cur[i]->language);
2571 p.writeInt32(p_cur[i]->selected);
2572
2573 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
2574 selected =%d], ",
2575 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
2576 p_cur[i]->selected);
2577 }
2578 closeResponse;
2579
2580 return 0;
2581}
2582
2583static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
2584 int num;
2585 int digitCount;
2586 int digitLimit;
2587 uint8_t uct;
2588 void* dest;
2589
codeworkxafc051f2013-07-27 09:02:14 +02002590 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002591
2592 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002593 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002594 return RIL_ERRNO_INVALID_RESPONSE;
2595 }
2596
2597 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
codeworkxafc051f2013-07-27 09:02:14 +02002598 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002599 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
2600 return RIL_ERRNO_INVALID_RESPONSE;
2601 }
2602
2603 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
2604 p.writeInt32(p_cur->uTeleserviceID);
2605 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
2606 p.writeInt32(p_cur->uServicecategory);
2607 p.writeInt32(p_cur->sAddress.digit_mode);
2608 p.writeInt32(p_cur->sAddress.number_mode);
2609 p.writeInt32(p_cur->sAddress.number_type);
2610 p.writeInt32(p_cur->sAddress.number_plan);
2611 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
2612 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2613 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2614 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
2615 }
2616
2617 p.writeInt32(p_cur->sSubAddress.subaddressType);
2618 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
2619 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
2620 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2621 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2622 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
2623 }
2624
2625 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2626 p.writeInt32(p_cur->uBearerDataLen);
2627 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2628 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
2629 }
2630
2631 startResponse;
2632 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
2633 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
2634 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
2635 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
2636 closeResponse;
2637
2638 return 0;
2639}
2640
2641/**
2642 * A write on the wakeup fd is done just to pop us out of select()
2643 * We empty the buffer here and then ril_event will reset the timers on the
2644 * way back down
2645 */
2646static void processWakeupCallback(int fd, short flags, void *param) {
2647 char buff[16];
2648 int ret;
2649
codeworkxafc051f2013-07-27 09:02:14 +02002650 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002651
2652 /* empty our wakeup socket out */
2653 do {
2654 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
2655 } while (ret > 0 || (ret < 0 && errno == EINTR));
2656}
2657
2658static void onCommandsSocketClosed() {
2659 int ret;
2660 RequestInfo *p_cur;
2661
2662 /* mark pending requests as "cancelled" so we dont report responses */
2663
2664 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
2665 assert (ret == 0);
2666
2667 p_cur = s_pendingRequests;
2668
2669 for (p_cur = s_pendingRequests
2670 ; p_cur != NULL
2671 ; p_cur = p_cur->p_next
2672 ) {
2673 p_cur->cancelled = 1;
2674 }
2675
2676 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
2677 assert (ret == 0);
2678}
2679
2680static void processCommandsCallback(int fd, short flags, void *param) {
2681 RecordStream *p_rs;
2682 void *p_record;
2683 size_t recordlen;
2684 int ret;
2685
2686 assert(fd == s_fdCommand);
2687
2688 p_rs = (RecordStream *)param;
2689
2690 for (;;) {
2691 /* loop until EAGAIN/EINTR, end of stream, or other error */
2692 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
2693
2694 if (ret == 0 && p_record == NULL) {
2695 /* end-of-stream */
2696 break;
2697 } else if (ret < 0) {
2698 break;
2699 } else if (ret == 0) { /* && p_record != NULL */
2700 processCommandBuffer(p_record, recordlen);
2701 }
2702 }
2703
2704 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
2705 /* fatal error or end-of-stream */
2706 if (ret != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002707 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002708 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002709 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002710 }
2711
2712 close(s_fdCommand);
2713 s_fdCommand = -1;
2714
2715 ril_event_del(&s_commands_event);
2716
2717 record_stream_free(p_rs);
2718
2719 /* start listening for new connections again */
2720 rilEventAddWakeup(&s_listen_event);
2721
2722 onCommandsSocketClosed();
2723 }
2724}
2725
2726
2727static void onNewCommandConnect() {
2728 // Inform we are connected and the ril version
2729 int rilVer = s_callbacks.version;
2730 RIL_onUnsolicitedResponse(RIL_UNSOL_RIL_CONNECTED,
2731 &rilVer, sizeof(rilVer));
2732
2733 // implicit radio state changed
2734 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
2735 NULL, 0);
2736
2737 // Send last NITZ time data, in case it was missed
2738 if (s_lastNITZTimeData != NULL) {
2739 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
2740
2741 free(s_lastNITZTimeData);
2742 s_lastNITZTimeData = NULL;
2743 }
2744
2745 // Get version string
2746 if (s_callbacks.getVersion != NULL) {
2747 const char *version;
2748 version = s_callbacks.getVersion();
codeworkxafc051f2013-07-27 09:02:14 +02002749 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002750
2751 property_set(PROPERTY_RIL_IMPL, version);
2752 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002753 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002754 property_set(PROPERTY_RIL_IMPL, "unavailable");
2755 }
2756
2757}
2758
2759static void listenCallback (int fd, short flags, void *param) {
2760 int ret;
2761 int err;
2762 int is_phone_socket;
2763 RecordStream *p_rs;
2764
2765 struct sockaddr_un peeraddr;
2766 socklen_t socklen = sizeof (peeraddr);
2767
2768 struct ucred creds;
2769 socklen_t szCreds = sizeof(creds);
2770
2771 struct passwd *pwd = NULL;
2772
2773 assert (s_fdCommand < 0);
2774 assert (fd == s_fdListen);
2775
2776 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
2777
2778 if (s_fdCommand < 0 ) {
codeworkxafc051f2013-07-27 09:02:14 +02002779 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002780 /* start listening for new connections again */
2781 rilEventAddWakeup(&s_listen_event);
2782 return;
2783 }
2784
2785 /* check the credential of the other side and only accept socket from
2786 * phone process
2787 */
2788 errno = 0;
2789 is_phone_socket = 0;
2790
2791 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
2792
2793 if (err == 0 && szCreds > 0) {
2794 errno = 0;
2795 pwd = getpwuid(creds.uid);
2796 if (pwd != NULL) {
2797 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
2798 is_phone_socket = 1;
2799 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002800 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002801 }
2802 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002803 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002804 }
2805 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002806 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002807 }
2808
2809 if ( !is_phone_socket ) {
codeworkxafc051f2013-07-27 09:02:14 +02002810 RLOGE("RILD must accept socket from %s", PHONE_PROCESS);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002811
2812 close(s_fdCommand);
2813 s_fdCommand = -1;
2814
2815 onCommandsSocketClosed();
2816
2817 /* start listening for new connections again */
2818 rilEventAddWakeup(&s_listen_event);
2819
2820 return;
2821 }
2822
2823 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
2824
2825 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002826 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002827 }
2828
codeworkxafc051f2013-07-27 09:02:14 +02002829 RLOGI("libril: new connection");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002830
2831 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
2832
2833 ril_event_set (&s_commands_event, s_fdCommand, 1,
2834 processCommandsCallback, p_rs);
2835
2836 rilEventAddWakeup (&s_commands_event);
2837
2838 onNewCommandConnect();
2839}
2840
2841static void freeDebugCallbackArgs(int number, char **args) {
2842 for (int i = 0; i < number; i++) {
2843 if (args[i] != NULL) {
2844 free(args[i]);
2845 }
2846 }
2847 free(args);
2848}
2849
2850static void debugCallback (int fd, short flags, void *param) {
2851 int acceptFD, option;
2852 struct sockaddr_un peeraddr;
2853 socklen_t socklen = sizeof (peeraddr);
2854 int data;
2855 unsigned int qxdm_data[6];
2856 const char *deactData[1] = {"1"};
2857 char *actData[1];
2858 RIL_Dial dialData;
2859 int hangupData[1] = {1};
2860 int number;
2861 char **args;
2862
2863 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
2864
2865 if (acceptFD < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002866 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002867 return;
2868 }
2869
2870 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
codeworkxafc051f2013-07-27 09:02:14 +02002871 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002872 return;
2873 }
2874 args = (char **) malloc(sizeof(char*) * number);
2875
2876 for (int i = 0; i < number; i++) {
2877 int len;
2878 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
codeworkxafc051f2013-07-27 09:02:14 +02002879 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002880 freeDebugCallbackArgs(i, args);
2881 return;
2882 }
2883 // +1 for null-term
2884 args[i] = (char *) malloc((sizeof(char) * len) + 1);
2885 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
2886 != (int)sizeof(char) * len) {
codeworkxafc051f2013-07-27 09:02:14 +02002887 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002888 freeDebugCallbackArgs(i, args);
2889 return;
2890 }
2891 char * buf = args[i];
2892 buf[len] = 0;
2893 }
2894
2895 switch (atoi(args[0])) {
2896 case 0:
codeworkxafc051f2013-07-27 09:02:14 +02002897 RLOGI ("Connection on debug port: issuing reset.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002898 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
2899 break;
2900 case 1:
codeworkxafc051f2013-07-27 09:02:14 +02002901 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002902 data = 0;
2903 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2904 // Close the socket
2905 close(s_fdCommand);
2906 s_fdCommand = -1;
2907 break;
2908 case 2:
codeworkxafc051f2013-07-27 09:02:14 +02002909 RLOGI ("Debug port: issuing unsolicited voice network change.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002910 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
2911 NULL, 0);
2912 break;
2913 case 3:
codeworkxafc051f2013-07-27 09:02:14 +02002914 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002915 qxdm_data[0] = 65536; // head.func_tag
2916 qxdm_data[1] = 16; // head.len
2917 qxdm_data[2] = 1; // mode: 1 for 'start logging'
2918 qxdm_data[3] = 32; // log_file_size: 32megabytes
2919 qxdm_data[4] = 0; // log_mask
2920 qxdm_data[5] = 8; // log_max_fileindex
2921 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2922 6 * sizeof(int));
2923 break;
2924 case 4:
codeworkxafc051f2013-07-27 09:02:14 +02002925 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002926 qxdm_data[0] = 65536;
2927 qxdm_data[1] = 16;
2928 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
2929 qxdm_data[3] = 32;
2930 qxdm_data[4] = 0;
2931 qxdm_data[5] = 8;
2932 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
2933 6 * sizeof(int));
2934 break;
2935 case 5:
codeworkxafc051f2013-07-27 09:02:14 +02002936 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002937 data = 1;
2938 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
2939 sleep(2);
2940 // Set network selection automatic.
2941 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
2942 break;
2943 case 6:
codeworkxafc051f2013-07-27 09:02:14 +02002944 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002945 actData[0] = args[1];
2946 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
2947 sizeof(actData));
2948 break;
2949 case 7:
codeworkxafc051f2013-07-27 09:02:14 +02002950 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002951 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
2952 sizeof(deactData));
2953 break;
2954 case 8:
codeworkxafc051f2013-07-27 09:02:14 +02002955 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002956 dialData.clir = 0;
2957 dialData.address = args[1];
2958 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
2959 break;
2960 case 9:
codeworkxafc051f2013-07-27 09:02:14 +02002961 RLOGI("Debug port: Answer Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002962 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
2963 break;
2964 case 10:
codeworkxafc051f2013-07-27 09:02:14 +02002965 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002966 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
2967 sizeof(hangupData));
2968 break;
2969 default:
codeworkxafc051f2013-07-27 09:02:14 +02002970 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002971 break;
2972 }
2973 freeDebugCallbackArgs(number, args);
2974 close(acceptFD);
2975}
2976
2977
2978static void userTimerCallback (int fd, short flags, void *param) {
2979 UserCallbackInfo *p_info;
2980
2981 p_info = (UserCallbackInfo *)param;
2982
2983 p_info->p_callback(p_info->userParam);
2984
2985
2986 // FIXME generalize this...there should be a cancel mechanism
2987 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
2988 s_last_wake_timeout_info = NULL;
2989 }
2990
2991 free(p_info);
2992}
2993
2994
2995static void *
2996eventLoop(void *param) {
2997 int ret;
2998 int filedes[2];
2999
3000 ril_event_init();
3001
3002 pthread_mutex_lock(&s_startupMutex);
3003
3004 s_started = 1;
3005 pthread_cond_broadcast(&s_startupCond);
3006
3007 pthread_mutex_unlock(&s_startupMutex);
3008
3009 ret = pipe(filedes);
3010
3011 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003012 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003013 return NULL;
3014 }
3015
3016 s_fdWakeupRead = filedes[0];
3017 s_fdWakeupWrite = filedes[1];
3018
3019 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3020
3021 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3022 processWakeupCallback, NULL);
3023
3024 rilEventAddWakeup (&s_wakeupfd_event);
3025
3026 // Only returns on error
3027 ril_event_loop();
codeworkxafc051f2013-07-27 09:02:14 +02003028 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003029 // kill self to restart on error
3030 kill(0, SIGKILL);
3031
3032 return NULL;
3033}
3034
3035extern "C" void
3036RIL_startEventLoop(void) {
3037 int ret;
3038 pthread_attr_t attr;
3039
3040 /* spin up eventLoop thread and wait for it to get started */
3041 s_started = 0;
3042 pthread_mutex_lock(&s_startupMutex);
3043
3044 pthread_attr_init (&attr);
3045 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3046 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3047
3048 while (s_started == 0) {
3049 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3050 }
3051
3052 pthread_mutex_unlock(&s_startupMutex);
3053
3054 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003055 RLOGE("Failed to create dispatch thread errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003056 return;
3057 }
3058}
3059
3060// Used for testing purpose only.
3061extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3062 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3063}
3064
3065extern "C" void
3066RIL_register (const RIL_RadioFunctions *callbacks) {
3067 int ret;
3068 int flags;
3069
3070 if (callbacks == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02003071 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003072 return;
3073 }
3074 if (callbacks->version < RIL_VERSION_MIN) {
codeworkxafc051f2013-07-27 09:02:14 +02003075 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003076 callbacks->version, RIL_VERSION_MIN);
3077 return;
3078 }
3079 if (callbacks->version > RIL_VERSION) {
codeworkxafc051f2013-07-27 09:02:14 +02003080 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003081 callbacks->version, RIL_VERSION);
3082 return;
3083 }
codeworkxafc051f2013-07-27 09:02:14 +02003084 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003085
3086 if (s_registerCalled > 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003087 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003088 "Subsequent call ignored");
3089 return;
3090 }
3091
3092 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3093
3094 s_registerCalled = 1;
3095
3096 // Little self-check
3097
3098 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
3099 assert(i == s_commands[i].requestNumber);
3100 }
3101
3102 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003103 /* Hack to include Samsung responses */
3104 if (i > MAX_RIL_UNSOL - RIL_UNSOL_RESPONSE_BASE) {
3105 assert(i + SAMSUNG_UNSOL_RESPONSE_BASE - MAX_RIL_UNSOL
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003106 == s_unsolResponses[i].requestNumber);
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003107 } else {
3108 assert(i + RIL_UNSOL_RESPONSE_BASE
3109 == s_unsolResponses[i].requestNumber);
3110 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003111 }
3112
3113 // New rild impl calls RIL_startEventLoop() first
3114 // old standalone impl wants it here.
3115
3116 if (s_started == 0) {
3117 RIL_startEventLoop();
3118 }
3119
3120 // start listen socket
3121
3122#if 0
3123 ret = socket_local_server (SOCKET_NAME_RIL,
3124 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
3125
3126 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003127 RLOGE("Unable to bind socket errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003128 exit (-1);
3129 }
3130 s_fdListen = ret;
3131
3132#else
3133 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
3134 if (s_fdListen < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003135 RLOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003136 exit(-1);
3137 }
3138
3139 ret = listen(s_fdListen, 4);
3140
3141 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003142 RLOGE("Failed to listen on control socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003143 s_fdListen, strerror(errno));
3144 exit(-1);
3145 }
3146#endif
3147
3148
3149 /* note: non-persistent so we can accept only one connection at a time */
3150 ril_event_set (&s_listen_event, s_fdListen, false,
3151 listenCallback, NULL);
3152
3153 rilEventAddWakeup (&s_listen_event);
3154
3155#if 1
3156 // start debug interface socket
3157
3158 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
3159 if (s_fdDebug < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003160 RLOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003161 exit(-1);
3162 }
3163
3164 ret = listen(s_fdDebug, 4);
3165
3166 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003167 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003168 s_fdDebug, strerror(errno));
3169 exit(-1);
3170 }
3171
3172 ril_event_set (&s_debug_event, s_fdDebug, true,
3173 debugCallback, NULL);
3174
3175 rilEventAddWakeup (&s_debug_event);
3176#endif
3177
3178}
3179
3180static int
3181checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
3182 int ret = 0;
3183
3184 if (pRI == NULL) {
3185 return 0;
3186 }
3187
3188 pthread_mutex_lock(&s_pendingRequestsMutex);
3189
3190 for(RequestInfo **ppCur = &s_pendingRequests
3191 ; *ppCur != NULL
3192 ; ppCur = &((*ppCur)->p_next)
3193 ) {
3194 if (pRI == *ppCur) {
3195 ret = 1;
3196
3197 *ppCur = (*ppCur)->p_next;
3198 break;
3199 }
3200 }
3201
3202 pthread_mutex_unlock(&s_pendingRequestsMutex);
3203
3204 return ret;
3205}
3206
3207
3208extern "C" void
3209RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
3210 RequestInfo *pRI;
3211 int ret;
3212 size_t errorOffset;
3213
3214 pRI = (RequestInfo *)t;
3215
3216 if (!checkAndDequeueRequestInfo(pRI)) {
codeworkxafc051f2013-07-27 09:02:14 +02003217 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003218 return;
3219 }
3220
3221 if (pRI->local > 0) {
3222 // Locally issued command...void only!
3223 // response does not go back up the command socket
codeworkxafc051f2013-07-27 09:02:14 +02003224 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003225
3226 goto done;
3227 }
3228
3229 appendPrintBuf("[%04d]< %s",
3230 pRI->token, requestToString(pRI->pCI->requestNumber));
3231
3232 if (pRI->cancelled == 0) {
3233 Parcel p;
3234
3235 p.writeInt32 (RESPONSE_SOLICITED);
3236 p.writeInt32 (pRI->token);
3237 errorOffset = p.dataPosition();
3238
3239 p.writeInt32 (e);
3240
3241 if (response != NULL) {
3242 // there is a response payload, no matter success or not.
3243 ret = pRI->pCI->responseFunction(p, response, responselen);
3244
3245 /* if an error occurred, rewind and mark it */
3246 if (ret != 0) {
3247 p.setDataPosition(errorOffset);
3248 p.writeInt32 (ret);
3249 }
3250 }
3251
3252 if (e != RIL_E_SUCCESS) {
3253 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
3254 }
3255
3256 if (s_fdCommand < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003257 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003258 }
3259 sendResponse(p);
3260 }
3261
3262done:
3263 free(pRI);
3264}
3265
3266
3267static void
3268grabPartialWakeLock() {
3269 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
3270}
3271
3272static void
3273releaseWakeLock() {
3274 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
3275}
3276
3277/**
3278 * Timer callback to put us back to sleep before the default timeout
3279 */
3280static void
3281wakeTimeoutCallback (void *param) {
3282 // We're using "param != NULL" as a cancellation mechanism
3283 if (param == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02003284 //RLOGD("wakeTimeout: releasing wake lock");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003285
3286 releaseWakeLock();
3287 } else {
codeworkxafc051f2013-07-27 09:02:14 +02003288 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003289 }
3290}
3291
3292static int
3293decodeVoiceRadioTechnology (RIL_RadioState radioState) {
3294 switch (radioState) {
3295 case RADIO_STATE_SIM_NOT_READY:
3296 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3297 case RADIO_STATE_SIM_READY:
3298 return RADIO_TECH_UMTS;
3299
3300 case RADIO_STATE_RUIM_NOT_READY:
3301 case RADIO_STATE_RUIM_READY:
3302 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3303 case RADIO_STATE_NV_NOT_READY:
3304 case RADIO_STATE_NV_READY:
3305 return RADIO_TECH_1xRTT;
3306
3307 default:
codeworkxafc051f2013-07-27 09:02:14 +02003308 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003309 return -1;
3310 }
3311}
3312
3313static int
3314decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
3315 switch (radioState) {
3316 case RADIO_STATE_SIM_NOT_READY:
3317 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3318 case RADIO_STATE_SIM_READY:
3319 case RADIO_STATE_RUIM_NOT_READY:
3320 case RADIO_STATE_RUIM_READY:
3321 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3322 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
3323
3324 case RADIO_STATE_NV_NOT_READY:
3325 case RADIO_STATE_NV_READY:
3326 return CDMA_SUBSCRIPTION_SOURCE_NV;
3327
3328 default:
codeworkxafc051f2013-07-27 09:02:14 +02003329 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003330 return -1;
3331 }
3332}
3333
3334static int
3335decodeSimStatus (RIL_RadioState radioState) {
3336 switch (radioState) {
3337 case RADIO_STATE_SIM_NOT_READY:
3338 case RADIO_STATE_RUIM_NOT_READY:
3339 case RADIO_STATE_NV_NOT_READY:
3340 case RADIO_STATE_NV_READY:
3341 return -1;
3342 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3343 case RADIO_STATE_SIM_READY:
3344 case RADIO_STATE_RUIM_READY:
3345 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3346 return radioState;
3347 default:
codeworkxafc051f2013-07-27 09:02:14 +02003348 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003349 return -1;
3350 }
3351}
3352
3353static bool is3gpp2(int radioTech) {
3354 switch (radioTech) {
3355 case RADIO_TECH_IS95A:
3356 case RADIO_TECH_IS95B:
3357 case RADIO_TECH_1xRTT:
3358 case RADIO_TECH_EVDO_0:
3359 case RADIO_TECH_EVDO_A:
3360 case RADIO_TECH_EVDO_B:
3361 case RADIO_TECH_EHRPD:
3362 return true;
3363 default:
3364 return false;
3365 }
3366}
3367
3368/* If RIL sends SIM states or RUIM states, store the voice radio
3369 * technology and subscription source information so that they can be
3370 * returned when telephony framework requests them
3371 */
3372static RIL_RadioState
3373processRadioState(RIL_RadioState newRadioState) {
3374
3375 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
3376 int newVoiceRadioTech;
3377 int newCdmaSubscriptionSource;
3378 int newSimStatus;
3379
3380 /* This is old RIL. Decode Subscription source and Voice Radio Technology
3381 from Radio State and send change notifications if there has been a change */
3382 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
3383 if(newVoiceRadioTech != voiceRadioTech) {
3384 voiceRadioTech = newVoiceRadioTech;
3385 RIL_onUnsolicitedResponse (RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
3386 &voiceRadioTech, sizeof(voiceRadioTech));
3387 }
3388 if(is3gpp2(newVoiceRadioTech)) {
3389 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
3390 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
3391 cdmaSubscriptionSource = newCdmaSubscriptionSource;
3392 RIL_onUnsolicitedResponse (RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
3393 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource));
3394 }
3395 }
3396 newSimStatus = decodeSimStatus(newRadioState);
3397 if(newSimStatus != simRuimStatus) {
3398 simRuimStatus = newSimStatus;
3399 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
3400 }
3401
3402 /* Send RADIO_ON to telephony */
3403 newRadioState = RADIO_STATE_ON;
3404 }
3405
3406 return newRadioState;
3407}
3408
3409extern "C"
3410void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
3411 size_t datalen)
3412{
3413 int unsolResponseIndex;
3414 int ret;
3415 int64_t timeReceived = 0;
3416 bool shouldScheduleTimeout = false;
3417 RIL_RadioState newState;
3418
3419 if (s_registerCalled == 0) {
3420 // Ignore RIL_onUnsolicitedResponse before RIL_register
codeworkxafc051f2013-07-27 09:02:14 +02003421 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003422 return;
3423 }
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003424
3425 /* Hack to include Samsung responses */
3426 if (unsolResponse > SAMSUNG_UNSOL_RESPONSE_BASE) {
3427 unsolResponseIndex = unsolResponse - SAMSUNG_UNSOL_RESPONSE_BASE + MAX_RIL_UNSOL - RIL_UNSOL_RESPONSE_BASE;
3428 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, unsolResponseIndex);
3429 } else {
3430 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
3431 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003432
3433 if ((unsolResponseIndex < 0)
3434 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
codeworkxafc051f2013-07-27 09:02:14 +02003435 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003436 return;
3437 }
3438
3439 // Grab a wake lock if needed for this reponse,
3440 // as we exit we'll either release it immediately
3441 // or set a timer to release it later.
3442 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
3443 case WAKE_PARTIAL:
3444 grabPartialWakeLock();
3445 shouldScheduleTimeout = true;
3446 break;
3447
3448 case DONT_WAKE:
3449 default:
3450 // No wake lock is grabed so don't set timeout
3451 shouldScheduleTimeout = false;
3452 break;
3453 }
3454
3455 // Mark the time this was received, doing this
3456 // after grabing the wakelock incase getting
3457 // the elapsedRealTime might cause us to goto
3458 // sleep.
3459 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3460 timeReceived = elapsedRealtime();
3461 }
3462
3463 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
3464
3465 Parcel p;
3466
3467 p.writeInt32 (RESPONSE_UNSOLICITED);
3468 p.writeInt32 (unsolResponse);
3469
3470 ret = s_unsolResponses[unsolResponseIndex]
3471 .responseFunction(p, data, datalen);
3472 if (ret != 0) {
3473 // Problem with the response. Don't continue;
3474 goto error_exit;
3475 }
3476
3477 // some things get more payload
3478 switch(unsolResponse) {
3479 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
3480 newState = processRadioState(s_callbacks.onStateRequest());
3481 p.writeInt32(newState);
3482 appendPrintBuf("%s {%s}", printBuf,
3483 radioStateToString(s_callbacks.onStateRequest()));
3484 break;
3485
3486
3487 case RIL_UNSOL_NITZ_TIME_RECEIVED:
3488 // Store the time that this was received so the
3489 // handler of this message can account for
3490 // the time it takes to arrive and process. In
3491 // particular the system has been known to sleep
3492 // before this message can be processed.
3493 p.writeInt64(timeReceived);
3494 break;
3495 }
3496
3497 ret = sendResponse(p);
3498 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3499
3500 // Unfortunately, NITZ time is not poll/update like everything
3501 // else in the system. So, if the upstream client isn't connected,
3502 // keep a copy of the last NITZ response (with receive time noted
3503 // above) around so we can deliver it when it is connected
3504
3505 if (s_lastNITZTimeData != NULL) {
3506 free (s_lastNITZTimeData);
3507 s_lastNITZTimeData = NULL;
3508 }
3509
3510 s_lastNITZTimeData = malloc(p.dataSize());
3511 s_lastNITZTimeDataSize = p.dataSize();
3512 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
3513 }
3514
3515 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
3516 // FIXME The java code should handshake here to release wake lock
3517
3518 if (shouldScheduleTimeout) {
3519 // Cancel the previous request
3520 if (s_last_wake_timeout_info != NULL) {
3521 s_last_wake_timeout_info->userParam = (void *)1;
3522 }
3523
3524 s_last_wake_timeout_info
3525 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
3526 &TIMEVAL_WAKE_TIMEOUT);
3527 }
3528
3529 // Normal exit
3530 return;
3531
3532error_exit:
3533 if (shouldScheduleTimeout) {
3534 releaseWakeLock();
3535 }
3536}
3537
3538/** FIXME generalize this if you track UserCAllbackInfo, clear it
3539 when the callback occurs
3540*/
3541static UserCallbackInfo *
3542internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
3543 const struct timeval *relativeTime)
3544{
3545 struct timeval myRelativeTime;
3546 UserCallbackInfo *p_info;
3547
3548 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
3549
3550 p_info->p_callback = callback;
3551 p_info->userParam = param;
3552
3553 if (relativeTime == NULL) {
3554 /* treat null parameter as a 0 relative time */
3555 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
3556 } else {
3557 /* FIXME I think event_add's tv param is really const anyway */
3558 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
3559 }
3560
3561 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
3562
3563 ril_timer_add(&(p_info->event), &myRelativeTime);
3564
3565 triggerEvLoop();
3566 return p_info;
3567}
3568
3569
3570extern "C" void
3571RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
3572 const struct timeval *relativeTime) {
3573 internalRequestTimedCallback (callback, param, relativeTime);
3574}
3575
3576const char *
3577failCauseToString(RIL_Errno e) {
3578 switch(e) {
3579 case RIL_E_SUCCESS: return "E_SUCCESS";
codeworkxafc051f2013-07-27 09:02:14 +02003580 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003581 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
3582 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
3583 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
3584 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
3585 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
3586 case RIL_E_CANCELLED: return "E_CANCELLED";
3587 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
3588 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
3589 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
3590 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
3591 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
3592#ifdef FEATURE_MULTIMODE_ANDROID
3593 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
3594 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
3595#endif
3596 default: return "<unknown error>";
3597 }
3598}
3599
3600const char *
3601radioStateToString(RIL_RadioState s) {
3602 switch(s) {
3603 case RADIO_STATE_OFF: return "RADIO_OFF";
3604 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
3605 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
3606 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
3607 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
3608 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
3609 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
3610 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
3611 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
3612 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
3613 case RADIO_STATE_ON:return"RADIO_ON";
3614 default: return "<unknown state>";
3615 }
3616}
3617
3618const char *
3619callStateToString(RIL_CallState s) {
3620 switch(s) {
3621 case RIL_CALL_ACTIVE : return "ACTIVE";
3622 case RIL_CALL_HOLDING: return "HOLDING";
3623 case RIL_CALL_DIALING: return "DIALING";
3624 case RIL_CALL_ALERTING: return "ALERTING";
3625 case RIL_CALL_INCOMING: return "INCOMING";
3626 case RIL_CALL_WAITING: return "WAITING";
3627 default: return "<unknown state>";
3628 }
3629}
3630
3631const char *
3632requestToString(int request) {
3633/*
3634 cat libs/telephony/ril_commands.h \
3635 | egrep "^ *{RIL_" \
3636 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3637
3638
3639 cat libs/telephony/ril_unsol_commands.h \
3640 | egrep "^ *{RIL_" \
3641 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
3642
3643*/
3644 switch(request) {
3645 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3646 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3647 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3648 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3649 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3650 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3651 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3652 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3653 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3654 case RIL_REQUEST_DIAL: return "DIAL";
3655 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
3656 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3657 case RIL_REQUEST_HANGUP: return "HANGUP";
3658 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3659 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3660 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3661 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3662 case RIL_REQUEST_UDUB: return "UDUB";
3663 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3664 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3665 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3666 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3667 case RIL_REQUEST_OPERATOR: return "OPERATOR";
3668 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3669 case RIL_REQUEST_DTMF: return "DTMF";
3670 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3671 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3672 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3673 case RIL_REQUEST_SIM_IO: return "SIM_IO";
3674 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3675 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3676 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3677 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3678 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3679 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3680 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3681 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3682 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3683 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3684 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3685 case RIL_REQUEST_ANSWER: return "ANSWER";
3686 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3687 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3688 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3689 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3690 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3691 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3692 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3693 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3694 case RIL_REQUEST_DTMF_START: return "DTMF_START";
3695 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3696 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3697 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3698 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
3699 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
3700 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
3701 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3702 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3703 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3704 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3705 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3706 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3707 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3708 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3709 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3710 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3711 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
3712 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
3713 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
3714 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
3715 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
3716 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3717 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
3718 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
codeworkxafc051f2013-07-27 09:02:14 +02003719 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003720 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
3721 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
3722 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
3723 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
3724 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
3725 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
3726 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
3727 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
3728 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
3729 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
3730 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
3731 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
3732 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
3733 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
3734 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
codeworkxafc051f2013-07-27 09:02:14 +02003735 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003736 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
3737 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
3738 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
3739 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
3740 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
3741 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
3742 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
3743 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
3744 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
3745 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
3746 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
3747 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
3748 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
3749 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
codeworkxafc051f2013-07-27 09:02:14 +02003750 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
3751 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003752 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
3753 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
3754 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
3755 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
3756 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
3757 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
3758 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
3759 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
3760 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
3761 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
3762 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
3763 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
3764 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
3765 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
3766 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
3767 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
3768 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
3769 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
3770 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
3771 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
3772 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
3773 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
3774 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
3775 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
3776 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
3777 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
3778 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
3779 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
3780 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
3781 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
3782 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
3783 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
3784 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
3785 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
3786 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
codeworkxafc051f2013-07-27 09:02:14 +02003787 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003788 case RIL_UNSOL_STK_SEND_SMS_RESULT: return "RIL_UNSOL_STK_SEND_SMS_RESULT";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003789 default: return "<unknown request>";
3790 }
3791}
3792
3793} /* namespace android */