blob: 074647479d599efdc84ef6ef9e12155a8916714c [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>
Andrew Jiangca4a9a02014-01-18 18:04:08 -050026#include <telephony/record_stream.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020027#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>
XpLoDWilDba5c6a32013-07-27 21:12:19 +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) \
XpLoDWilDba5c6a32013-07-27 21:12:19 +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)
XpLoDWilDba5c6a32013-07-27 21:12:19 +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);
208static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
209static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500210static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200211static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
212
213static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500214static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
215static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
216static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200217static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
218static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
219static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
220static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
221static int responseInts(Parcel &p, void *response, size_t responselen);
222static int responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen);
223static int responseStrings(Parcel &p, void *response, size_t responselen);
224static int responseStringsNetworks(Parcel &p, void *response, size_t responselen);
225static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search);
226static int responseString(Parcel &p, void *response, size_t responselen);
227static int responseVoid(Parcel &p, void *response, size_t responselen);
228static int responseCallList(Parcel &p, void *response, size_t responselen);
229static int responseSMS(Parcel &p, void *response, size_t responselen);
230static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
231static int responseCallForwards(Parcel &p, void *response, size_t responselen);
232static int responseDataCallList(Parcel &p, void *response, size_t responselen);
233static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
234static int responseRaw(Parcel &p, void *response, size_t responselen);
235static int responseSsn(Parcel &p, void *response, size_t responselen);
236static int responseSimStatus(Parcel &p, void *response, size_t responselen);
237static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
238static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
239static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
240static int responseCellList(Parcel &p, void *response, size_t responselen);
241static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
242static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
243static int responseCallRing(Parcel &p, void *response, size_t responselen);
244static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
245static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
246static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200247static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200248
249static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
250static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
251static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
252
253extern "C" const char * requestToString(int request);
254extern "C" const char * failCauseToString(RIL_Errno);
255extern "C" const char * callStateToString(RIL_CallState);
256extern "C" const char * radioStateToString(RIL_RadioState);
257
258#ifdef RIL_SHLIB
259extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
260 size_t datalen);
261#endif
262
263static UserCallbackInfo * internalRequestTimedCallback
264 (RIL_TimedCallback callback, void *param,
265 const struct timeval *relativeTime);
266
267/** Index == requestNumber */
268static CommandInfo s_commands[] = {
269#include "ril_commands.h"
270};
271
272static UnsolResponseInfo s_unsolResponses[] = {
273#include "ril_unsol_commands.h"
274};
275
276/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
277 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
278 radio state message and store it. Every time there is a change in Radio State
279 check to see if voice radio tech changes and notify telephony
280 */
281int voiceRadioTech = -1;
282
283/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
284 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
285 source from radio state and store it. Every time there is a change in Radio State
286 check to see if subscription source changed and notify telephony
287 */
288int cdmaSubscriptionSource = -1;
289
290/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
291 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
292 check to see if SIM/RUIM status changed and notify telephony
293 */
294int simRuimStatus = -1;
295
296static char *
297strdupReadString(Parcel &p) {
298 size_t stringlen;
299 const char16_t *s16;
300
301 s16 = p.readString16Inplace(&stringlen);
302
303 return strndup16to8(s16, stringlen);
304}
305
306static void writeStringToParcel(Parcel &p, const char *s) {
307 char16_t *s16;
308 size_t s16_len;
309 s16 = strdup8to16(s, &s16_len);
310 p.writeString16(s16, s16_len);
311 free(s16);
312}
313
314
315static void
316memsetString (char *s) {
317 if (s != NULL) {
318 memset (s, 0, strlen(s));
319 }
320}
321
322void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
323 const size_t* objects, size_t objectsSize,
324 void* cookie) {
325 // do nothing -- the data reference lives longer than the Parcel object
326}
327
328/**
329 * To be called from dispatch thread
330 * Issue a single local request, ensuring that the response
331 * is not sent back up to the command process
332 */
333static void
334issueLocalRequest(int request, void *data, int len) {
335 RequestInfo *pRI;
336 int index;
337 int ret;
338
339 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
340
341 pRI->local = 1;
342 pRI->token = 0xffffffff; // token is not used in this context
343
344 /* Hack to include Samsung requests */
345 if (request > 10000) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200346 index = request - 10000 + MAX_RIL_SOL;
Ethan Chend6e30652013-08-04 22:49:56 -0700347 RLOGD("SAMSUNG: request=%d, index=%d", request, index);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200348 pRI->pCI = &(s_commands[index]);
349 } else {
350 pRI->pCI = &(s_commands[request]);
351 }
352
353 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
354 assert (ret == 0);
355
356 pRI->p_next = s_pendingRequests;
357 s_pendingRequests = pRI;
358
359 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
360 assert (ret == 0);
361
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200362 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200363
364 s_callbacks.onRequest(request, data, len, pRI);
365}
366
367static int
368processCommandBuffer(void *buffer, size_t buflen) {
369 Parcel p;
370 status_t status;
371 int32_t request;
372 int32_t token;
373 RequestInfo *pRI;
374 int index;
375 int ret;
376
377 p.setData((uint8_t *) buffer, buflen);
378
379 // status checked at end
380 status = p.readInt32(&request);
381 status = p.readInt32 (&token);
382
383 if (status != NO_ERROR) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200384 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200385 return 0;
386 }
387
388 /* Hack to include Samsung requests */
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200389 if (request < 1 || ((request > MAX_RIL_SOL) &&
Ethan Chend6e30652013-08-04 22:49:56 -0700390 (request < RIL_REQUEST_GET_CELL_BROADCAST_CONFIG)) ||
391 request > RIL_REQUEST_HANGUP_VT) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200392 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200393 // FIXME this should perhaps return a response
394 return 0;
395 }
396
397 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
398
399 pRI->token = token;
400
401 /* Hack to include Samsung requests */
402 if (request > 10000) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200403 index = request - 10000 + MAX_RIL_SOL;
Ethan Chend6e30652013-08-04 22:49:56 -0700404 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
405 request, index);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200406 pRI->pCI = &(s_commands[index]);
407 } else {
408 pRI->pCI = &(s_commands[request]);
409 }
410
411 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
412 assert (ret == 0);
413
414 pRI->p_next = s_pendingRequests;
415 s_pendingRequests = pRI;
416
417 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
418 assert (ret == 0);
419
420/* sLastDispatchedToken = token; */
421
422 pRI->pCI->dispatchFunction(p, pRI);
423
424 return 0;
425}
426
427static void
428invalidCommandBlock (RequestInfo *pRI) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200429 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200430 pRI->token, requestToString(pRI->pCI->requestNumber));
431}
432
433/** Callee expects NULL */
434static void
435dispatchVoid (Parcel& p, RequestInfo *pRI) {
436 clearPrintBuf;
437 printRequest(pRI->token, pRI->pCI->requestNumber);
438 s_callbacks.onRequest(pRI->pCI->requestNumber, NULL, 0, pRI);
439}
440
441/** Callee expects const char * */
442static void
443dispatchString (Parcel& p, RequestInfo *pRI) {
444 status_t status;
445 size_t datalen;
446 size_t stringlen;
447 char *string8 = NULL;
448
449 string8 = strdupReadString(p);
450
451 startRequest;
452 appendPrintBuf("%s%s", printBuf, string8);
453 closeRequest;
454 printRequest(pRI->token, pRI->pCI->requestNumber);
455
456 s_callbacks.onRequest(pRI->pCI->requestNumber, string8,
457 sizeof(char *), pRI);
458
459#ifdef MEMSET_FREED
460 memsetString(string8);
461#endif
462
463 free(string8);
464 return;
465invalid:
466 invalidCommandBlock(pRI);
467 return;
468}
469
470/** Callee expects const char ** */
471static void
472dispatchStrings (Parcel &p, RequestInfo *pRI) {
473 int32_t countStrings;
474 status_t status;
475 size_t datalen;
476 char **pStrings;
477
478 status = p.readInt32 (&countStrings);
479
480 if (status != NO_ERROR) {
481 goto invalid;
482 }
483
484 startRequest;
485 if (countStrings == 0) {
486 // just some non-null pointer
487 pStrings = (char **)alloca(sizeof(char *));
488 datalen = 0;
489 } else if (((int)countStrings) == -1) {
490 pStrings = NULL;
491 datalen = 0;
492 } else {
493 datalen = sizeof(char *) * countStrings;
494
495 pStrings = (char **)alloca(datalen);
496
497 for (int i = 0 ; i < countStrings ; i++) {
498 pStrings[i] = strdupReadString(p);
499 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
500 }
501 }
502 removeLastChar;
503 closeRequest;
504 printRequest(pRI->token, pRI->pCI->requestNumber);
505
506 s_callbacks.onRequest(pRI->pCI->requestNumber, pStrings, datalen, pRI);
507
508 if (pStrings != NULL) {
509 for (int i = 0 ; i < countStrings ; i++) {
510#ifdef MEMSET_FREED
511 memsetString (pStrings[i]);
512#endif
513 free(pStrings[i]);
514 }
515
516#ifdef MEMSET_FREED
517 memset(pStrings, 0, datalen);
518#endif
519 }
520
521 return;
522invalid:
523 invalidCommandBlock(pRI);
524 return;
525}
526
527/** Callee expects const int * */
528static void
529dispatchInts (Parcel &p, RequestInfo *pRI) {
530 int32_t count;
531 status_t status;
532 size_t datalen;
533 int *pInts;
534
535 status = p.readInt32 (&count);
536
537 if (status != NO_ERROR || count == 0) {
538 goto invalid;
539 }
540
541 datalen = sizeof(int) * count;
542 pInts = (int *)alloca(datalen);
543
544 startRequest;
545 for (int i = 0 ; i < count ; i++) {
546 int32_t t;
547
548 status = p.readInt32(&t);
549 pInts[i] = (int)t;
550 appendPrintBuf("%s%d,", printBuf, t);
551
552 if (status != NO_ERROR) {
553 goto invalid;
554 }
555 }
556 removeLastChar;
557 closeRequest;
558 printRequest(pRI->token, pRI->pCI->requestNumber);
559
560 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<int *>(pInts),
561 datalen, pRI);
562
563#ifdef MEMSET_FREED
564 memset(pInts, 0, datalen);
565#endif
566
567 return;
568invalid:
569 invalidCommandBlock(pRI);
570 return;
571}
572
573
574/**
575 * Callee expects const RIL_SMS_WriteArgs *
576 * Payload is:
577 * int32_t status
578 * String pdu
579 */
580static void
581dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
582 RIL_SMS_WriteArgs args;
583 int32_t t;
584 status_t status;
585
586 memset (&args, 0, sizeof(args));
587
588 status = p.readInt32(&t);
589 args.status = (int)t;
590
591 args.pdu = strdupReadString(p);
592
593 if (status != NO_ERROR || args.pdu == NULL) {
594 goto invalid;
595 }
596
597 args.smsc = strdupReadString(p);
598
599 startRequest;
600 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
601 (char*)args.pdu, (char*)args.smsc);
602 closeRequest;
603 printRequest(pRI->token, pRI->pCI->requestNumber);
604
605 s_callbacks.onRequest(pRI->pCI->requestNumber, &args, sizeof(args), pRI);
606
607#ifdef MEMSET_FREED
608 memsetString (args.pdu);
609#endif
610
611 free (args.pdu);
612
613#ifdef MEMSET_FREED
614 memset(&args, 0, sizeof(args));
615#endif
616
617 return;
618invalid:
619 invalidCommandBlock(pRI);
620 return;
621}
622
623/**
624 * Callee expects const RIL_Dial *
625 * Payload is:
626 * String address
627 * int32_t clir
628 */
629static void
630dispatchDial (Parcel &p, RequestInfo *pRI) {
631 RIL_Dial dial;
632 RIL_UUS_Info uusInfo;
633 int32_t sizeOfDial;
634 int32_t t;
635 int32_t uusPresent;
636 status_t status;
637
638 memset (&dial, 0, sizeof(dial));
639
640 dial.address = strdupReadString(p);
641
642 status = p.readInt32(&t);
643 dial.clir = (int)t;
644
645 if (status != NO_ERROR || dial.address == NULL) {
646 goto invalid;
647 }
648
649 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
650 uusPresent = 0;
651 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
652 } else {
653 status = p.readInt32(&uusPresent);
654
655 if (status != NO_ERROR) {
656 goto invalid;
657 }
658
659 if (uusPresent == 0) {
660 dial.uusInfo = NULL;
661 } else {
662 int32_t len;
663
664 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
665
666 status = p.readInt32(&t);
667 uusInfo.uusType = (RIL_UUS_Type) t;
668
669 status = p.readInt32(&t);
670 uusInfo.uusDcs = (RIL_UUS_DCS) t;
671
672 status = p.readInt32(&len);
673 if (status != NO_ERROR) {
674 goto invalid;
675 }
676
677 // The java code writes -1 for null arrays
678 if (((int) len) == -1) {
679 uusInfo.uusData = NULL;
680 len = 0;
681 } else {
682 uusInfo.uusData = (char*) p.readInplace(len);
683 }
684
685 uusInfo.uusLength = len;
686 dial.uusInfo = &uusInfo;
687 }
688 sizeOfDial = sizeof(dial);
689 }
690
691 startRequest;
692 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
693 if (uusPresent) {
694 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
695 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
696 dial.uusInfo->uusLength);
697 }
698 closeRequest;
699 printRequest(pRI->token, pRI->pCI->requestNumber);
700
701 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI);
702
703#ifdef MEMSET_FREED
704 memsetString (dial.address);
705#endif
706
707 free (dial.address);
708
709#ifdef MEMSET_FREED
710 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
711 memset(&dial, 0, sizeof(dial));
712#endif
713
714 return;
715invalid:
716 invalidCommandBlock(pRI);
717 return;
718}
719
720/**
721 * Callee expects const RIL_SIM_IO *
722 * Payload is:
723 * int32_t command
724 * int32_t fileid
725 * String path
726 * int32_t p1, p2, p3
727 * String data
728 * String pin2
729 * String aidPtr
730 */
731static void
732dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
733 union RIL_SIM_IO {
734 RIL_SIM_IO_v6 v6;
735 RIL_SIM_IO_v5 v5;
736 } simIO;
737
738 int32_t t;
739 int size;
740 status_t status;
741
742 memset (&simIO, 0, sizeof(simIO));
743
744 // note we only check status at the end
745
746 status = p.readInt32(&t);
747 simIO.v6.command = (int)t;
748
749 status = p.readInt32(&t);
750 simIO.v6.fileid = (int)t;
751
752 simIO.v6.path = strdupReadString(p);
753
754 status = p.readInt32(&t);
755 simIO.v6.p1 = (int)t;
756
757 status = p.readInt32(&t);
758 simIO.v6.p2 = (int)t;
759
760 status = p.readInt32(&t);
761 simIO.v6.p3 = (int)t;
762
763 simIO.v6.data = strdupReadString(p);
764 simIO.v6.pin2 = strdupReadString(p);
765 simIO.v6.aidPtr = strdupReadString(p);
766
767 startRequest;
768 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
769 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
770 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
771 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
772 closeRequest;
773 printRequest(pRI->token, pRI->pCI->requestNumber);
774
775 if (status != NO_ERROR) {
776 goto invalid;
777 }
778
779 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
780 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, size, pRI);
781
782#ifdef MEMSET_FREED
783 memsetString (simIO.v6.path);
784 memsetString (simIO.v6.data);
785 memsetString (simIO.v6.pin2);
786 memsetString (simIO.v6.aidPtr);
787#endif
788
789 free (simIO.v6.path);
790 free (simIO.v6.data);
791 free (simIO.v6.pin2);
792 free (simIO.v6.aidPtr);
793
794#ifdef MEMSET_FREED
795 memset(&simIO, 0, sizeof(simIO));
796#endif
797
798 return;
799invalid:
800 invalidCommandBlock(pRI);
801 return;
802}
803
804/**
805 * Callee expects const RIL_CallForwardInfo *
806 * Payload is:
807 * int32_t status/action
808 * int32_t reason
809 * int32_t serviceCode
810 * int32_t toa
811 * String number (0 length -> null)
812 * int32_t timeSeconds
813 */
814static void
815dispatchCallForward(Parcel &p, RequestInfo *pRI) {
816 RIL_CallForwardInfo cff;
817 int32_t t;
818 status_t status;
819
820 memset (&cff, 0, sizeof(cff));
821
822 // note we only check status at the end
823
824 status = p.readInt32(&t);
825 cff.status = (int)t;
826
827 status = p.readInt32(&t);
828 cff.reason = (int)t;
829
830 status = p.readInt32(&t);
831 cff.serviceClass = (int)t;
832
833 status = p.readInt32(&t);
834 cff.toa = (int)t;
835
836 cff.number = strdupReadString(p);
837
838 status = p.readInt32(&t);
839 cff.timeSeconds = (int)t;
840
841 if (status != NO_ERROR) {
842 goto invalid;
843 }
844
845 // special case: number 0-length fields is null
846
847 if (cff.number != NULL && strlen (cff.number) == 0) {
848 cff.number = NULL;
849 }
850
851 startRequest;
852 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
853 cff.status, cff.reason, cff.serviceClass, cff.toa,
854 (char*)cff.number, cff.timeSeconds);
855 closeRequest;
856 printRequest(pRI->token, pRI->pCI->requestNumber);
857
858 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
859
860#ifdef MEMSET_FREED
861 memsetString(cff.number);
862#endif
863
864 free (cff.number);
865
866#ifdef MEMSET_FREED
867 memset(&cff, 0, sizeof(cff));
868#endif
869
870 return;
871invalid:
872 invalidCommandBlock(pRI);
873 return;
874}
875
876
877static void
878dispatchRaw(Parcel &p, RequestInfo *pRI) {
879 int32_t len;
880 status_t status;
881 const void *data;
882
883 status = p.readInt32(&len);
884
885 if (status != NO_ERROR) {
886 goto invalid;
887 }
888
889 // The java code writes -1 for null arrays
890 if (((int)len) == -1) {
891 data = NULL;
892 len = 0;
893 }
894
895 data = p.readInplace(len);
896
897 startRequest;
898 appendPrintBuf("%sraw_size=%d", printBuf, len);
899 closeRequest;
900 printRequest(pRI->token, pRI->pCI->requestNumber);
901
902 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
903
904 return;
905invalid:
906 invalidCommandBlock(pRI);
907 return;
908}
909
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500910static status_t
911constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200912 int32_t t;
913 uint8_t ut;
914 status_t status;
915 int32_t digitCount;
916 int digitLimit;
917
918 memset(&rcsm, 0, sizeof(rcsm));
919
920 status = p.readInt32(&t);
921 rcsm.uTeleserviceID = (int) t;
922
923 status = p.read(&ut,sizeof(ut));
924 rcsm.bIsServicePresent = (uint8_t) ut;
925
926 status = p.readInt32(&t);
927 rcsm.uServicecategory = (int) t;
928
929 status = p.readInt32(&t);
930 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
931
932 status = p.readInt32(&t);
933 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
934
935 status = p.readInt32(&t);
936 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
937
938 status = p.readInt32(&t);
939 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
940
941 status = p.read(&ut,sizeof(ut));
942 rcsm.sAddress.number_of_digits= (uint8_t) ut;
943
944 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
945 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
946 status = p.read(&ut,sizeof(ut));
947 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
948 }
949
950 status = p.readInt32(&t);
951 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
952
953 status = p.read(&ut,sizeof(ut));
954 rcsm.sSubAddress.odd = (uint8_t) ut;
955
956 status = p.read(&ut,sizeof(ut));
957 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
958
959 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
960 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
961 status = p.read(&ut,sizeof(ut));
962 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
963 }
964
965 status = p.readInt32(&t);
966 rcsm.uBearerDataLen = (int) t;
967
968 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
969 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
970 status = p.read(&ut, sizeof(ut));
971 rcsm.aBearerData[digitCount] = (uint8_t) ut;
972 }
973
974 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500975 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200976 }
977
978 startRequest;
979 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
980 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
981 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
982 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
983 closeRequest;
984
985 printRequest(pRI->token, pRI->pCI->requestNumber);
986
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500987 return status;
988}
989
990static void
991dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
992 RIL_CDMA_SMS_Message rcsm;
993
994 ALOGD("dispatchCdmaSms");
995 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
996 goto invalid;
997 }
998
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200999 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
1000
1001#ifdef MEMSET_FREED
1002 memset(&rcsm, 0, sizeof(rcsm));
1003#endif
1004
1005 return;
1006
1007invalid:
1008 invalidCommandBlock(pRI);
1009 return;
1010}
1011
1012static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001013dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1014 RIL_IMS_SMS_Message rism;
1015 RIL_CDMA_SMS_Message rcsm;
1016
1017 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1018
1019 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1020 goto invalid;
1021 }
1022 memset(&rism, 0, sizeof(rism));
1023 rism.tech = RADIO_TECH_3GPP2;
1024 rism.retry = retry;
1025 rism.messageRef = messageRef;
1026 rism.message.cdmaMessage = &rcsm;
1027
1028 s_callbacks.onRequest(pRI->pCI->requestNumber, &rism,
1029 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1030 +sizeof(rcsm),pRI);
1031
1032#ifdef MEMSET_FREED
1033 memset(&rcsm, 0, sizeof(rcsm));
1034 memset(&rism, 0, sizeof(rism));
1035#endif
1036
1037 return;
1038
1039invalid:
1040 invalidCommandBlock(pRI);
1041 return;
1042}
1043
1044static void
1045dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1046 RIL_IMS_SMS_Message rism;
1047 int32_t countStrings;
1048 status_t status;
1049 size_t datalen;
1050 char **pStrings;
1051 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1052
1053 status = p.readInt32 (&countStrings);
1054
1055 if (status != NO_ERROR) {
1056 goto invalid;
1057 }
1058
1059 memset(&rism, 0, sizeof(rism));
1060 rism.tech = RADIO_TECH_3GPP;
1061 rism.retry = retry;
1062 rism.messageRef = messageRef;
1063
1064 startRequest;
1065 appendPrintBuf("%sformat=%d,", printBuf, rism.format);
1066 if (countStrings == 0) {
1067 // just some non-null pointer
1068 pStrings = (char **)alloca(sizeof(char *));
1069 datalen = 0;
1070 } else if (((int)countStrings) == -1) {
1071 pStrings = NULL;
1072 datalen = 0;
1073 } else {
1074 datalen = sizeof(char *) * countStrings;
1075
1076 pStrings = (char **)alloca(datalen);
1077
1078 for (int i = 0 ; i < countStrings ; i++) {
1079 pStrings[i] = strdupReadString(p);
1080 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1081 }
1082 }
1083 removeLastChar;
1084 closeRequest;
1085 printRequest(pRI->token, pRI->pCI->requestNumber);
1086
1087 rism.message.gsmMessage = pStrings;
1088 s_callbacks.onRequest(pRI->pCI->requestNumber, &rism,
1089 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1090 +datalen, pRI);
1091
1092 if (pStrings != NULL) {
1093 for (int i = 0 ; i < countStrings ; i++) {
1094#ifdef MEMSET_FREED
1095 memsetString (pStrings[i]);
1096#endif
1097 free(pStrings[i]);
1098 }
1099
1100#ifdef MEMSET_FREED
1101 memset(pStrings, 0, datalen);
1102#endif
1103 }
1104
1105#ifdef MEMSET_FREED
1106 memset(&rism, 0, sizeof(rism));
1107#endif
1108 return;
1109invalid:
1110 ALOGE("dispatchImsGsmSms invalid block");
1111 invalidCommandBlock(pRI);
1112 return;
1113}
1114
1115static void
1116dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1117 int32_t t;
1118 status_t status = p.readInt32(&t);
1119 RIL_RadioTechnologyFamily format;
1120 uint8_t retry;
1121 int32_t messageRef;
1122
1123 ALOGD("dispatchImsSms");
1124 if (status != NO_ERROR) {
1125 goto invalid;
1126 }
1127 format = (RIL_RadioTechnologyFamily) t;
1128
1129 // read retry field
1130 status = p.read(&retry,sizeof(retry));
1131 if (status != NO_ERROR) {
1132 goto invalid;
1133 }
1134 // read messageRef field
1135 status = p.read(&messageRef,sizeof(messageRef));
1136 if (status != NO_ERROR) {
1137 goto invalid;
1138 }
1139
1140 if (RADIO_TECH_3GPP == format) {
1141 dispatchImsGsmSms(p, pRI, retry, messageRef);
1142 } else if (RADIO_TECH_3GPP2 == format) {
1143 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1144 } else {
1145 ALOGE("requestImsSendSMS invalid format value =%d", format);
1146 }
1147
1148 return;
1149
1150invalid:
1151 invalidCommandBlock(pRI);
1152 return;
1153}
1154
1155static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001156dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1157 RIL_CDMA_SMS_Ack rcsa;
1158 int32_t t;
1159 status_t status;
1160 int32_t digitCount;
1161
1162 memset(&rcsa, 0, sizeof(rcsa));
1163
1164 status = p.readInt32(&t);
1165 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1166
1167 status = p.readInt32(&t);
1168 rcsa.uSMSCauseCode = (int) t;
1169
1170 if (status != NO_ERROR) {
1171 goto invalid;
1172 }
1173
1174 startRequest;
1175 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1176 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1177 closeRequest;
1178
1179 printRequest(pRI->token, pRI->pCI->requestNumber);
1180
1181 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI);
1182
1183#ifdef MEMSET_FREED
1184 memset(&rcsa, 0, sizeof(rcsa));
1185#endif
1186
1187 return;
1188
1189invalid:
1190 invalidCommandBlock(pRI);
1191 return;
1192}
1193
1194static void
1195dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1196 int32_t t;
1197 status_t status;
1198 int32_t num;
1199
1200 status = p.readInt32(&num);
1201 if (status != NO_ERROR) {
1202 goto invalid;
1203 }
1204
Ethan Chend6e30652013-08-04 22:49:56 -07001205 {
1206 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1207 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001208
Ethan Chend6e30652013-08-04 22:49:56 -07001209 startRequest;
1210 for (int i = 0 ; i < num ; i++ ) {
1211 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001212
Ethan Chend6e30652013-08-04 22:49:56 -07001213 status = p.readInt32(&t);
1214 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001215
Ethan Chend6e30652013-08-04 22:49:56 -07001216 status = p.readInt32(&t);
1217 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001218
Ethan Chend6e30652013-08-04 22:49:56 -07001219 status = p.readInt32(&t);
1220 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001221
Ethan Chend6e30652013-08-04 22:49:56 -07001222 status = p.readInt32(&t);
1223 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001224
Ethan Chend6e30652013-08-04 22:49:56 -07001225 status = p.readInt32(&t);
1226 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001227
Ethan Chend6e30652013-08-04 22:49:56 -07001228 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1229 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1230 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1231 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1232 gsmBci[i].selected);
1233 }
1234 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001235
Ethan Chend6e30652013-08-04 22:49:56 -07001236 if (status != NO_ERROR) {
1237 goto invalid;
1238 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001239
Ethan Chend6e30652013-08-04 22:49:56 -07001240 s_callbacks.onRequest(pRI->pCI->requestNumber,
1241 gsmBciPtrs,
1242 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1243 pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001244
1245#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001246 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1247 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001248#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001249 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001250
1251 return;
1252
1253invalid:
1254 invalidCommandBlock(pRI);
1255 return;
1256}
1257
1258static void
1259dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1260 int32_t t;
1261 status_t status;
1262 int32_t num;
1263
1264 status = p.readInt32(&num);
1265 if (status != NO_ERROR) {
1266 goto invalid;
1267 }
1268
Ethan Chend6e30652013-08-04 22:49:56 -07001269 {
1270 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1271 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001272
Ethan Chend6e30652013-08-04 22:49:56 -07001273 startRequest;
1274 for (int i = 0 ; i < num ; i++ ) {
1275 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001276
Ethan Chend6e30652013-08-04 22:49:56 -07001277 status = p.readInt32(&t);
1278 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001279
Ethan Chend6e30652013-08-04 22:49:56 -07001280 status = p.readInt32(&t);
1281 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001282
Ethan Chend6e30652013-08-04 22:49:56 -07001283 status = p.readInt32(&t);
1284 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001285
Ethan Chend6e30652013-08-04 22:49:56 -07001286 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1287 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1288 cdmaBci[i].language, cdmaBci[i].selected);
1289 }
1290 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001291
Ethan Chend6e30652013-08-04 22:49:56 -07001292 if (status != NO_ERROR) {
1293 goto invalid;
1294 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001295
Ethan Chend6e30652013-08-04 22:49:56 -07001296 s_callbacks.onRequest(pRI->pCI->requestNumber,
1297 cdmaBciPtrs,
1298 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1299 pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001300
1301#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001302 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1303 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001304#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001305 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001306
1307 return;
1308
1309invalid:
1310 invalidCommandBlock(pRI);
1311 return;
1312}
1313
1314static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1315 RIL_CDMA_SMS_WriteArgs rcsw;
1316 int32_t t;
1317 uint32_t ut;
1318 uint8_t uct;
1319 status_t status;
1320 int32_t digitCount;
1321
1322 memset(&rcsw, 0, sizeof(rcsw));
1323
1324 status = p.readInt32(&t);
1325 rcsw.status = t;
1326
1327 status = p.readInt32(&t);
1328 rcsw.message.uTeleserviceID = (int) t;
1329
1330 status = p.read(&uct,sizeof(uct));
1331 rcsw.message.bIsServicePresent = (uint8_t) uct;
1332
1333 status = p.readInt32(&t);
1334 rcsw.message.uServicecategory = (int) t;
1335
1336 status = p.readInt32(&t);
1337 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1338
1339 status = p.readInt32(&t);
1340 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1341
1342 status = p.readInt32(&t);
1343 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1344
1345 status = p.readInt32(&t);
1346 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1347
1348 status = p.read(&uct,sizeof(uct));
1349 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1350
1351 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1352 status = p.read(&uct,sizeof(uct));
1353 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1354 }
1355
1356 status = p.readInt32(&t);
1357 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1358
1359 status = p.read(&uct,sizeof(uct));
1360 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1361
1362 status = p.read(&uct,sizeof(uct));
1363 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1364
1365 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1366 status = p.read(&uct,sizeof(uct));
1367 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1368 }
1369
1370 status = p.readInt32(&t);
1371 rcsw.message.uBearerDataLen = (int) t;
1372
1373 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1374 status = p.read(&uct, sizeof(uct));
1375 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1376 }
1377
1378 if (status != NO_ERROR) {
1379 goto invalid;
1380 }
1381
1382 startRequest;
1383 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1384 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1385 message.sAddress.number_mode=%d, \
1386 message.sAddress.number_type=%d, ",
1387 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1388 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1389 rcsw.message.sAddress.number_mode,
1390 rcsw.message.sAddress.number_type);
1391 closeRequest;
1392
1393 printRequest(pRI->token, pRI->pCI->requestNumber);
1394
1395 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI);
1396
1397#ifdef MEMSET_FREED
1398 memset(&rcsw, 0, sizeof(rcsw));
1399#endif
1400
1401 return;
1402
1403invalid:
1404 invalidCommandBlock(pRI);
1405 return;
1406
1407}
1408
Ethan Chend6e30652013-08-04 22:49:56 -07001409// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1410// Version 4 of the RIL interface adds a new PDP type parameter to support
1411// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1412// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001413static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001414 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001415 const int numParamsRilV3 = 6;
1416
Ethan Chend6e30652013-08-04 22:49:56 -07001417 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001418 // serial number - see processCommandBuffer(). Copy them over too.
1419 int pos = p.dataPosition();
1420
1421 int numParams = p.readInt32();
1422 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1423 Parcel p2;
1424 p2.appendFrom(&p, 0, pos);
1425 p2.writeInt32(numParamsRilV3);
1426 for(int i = 0; i < numParamsRilV3; i++) {
1427 p2.writeString16(p.readString16());
1428 }
1429 p2.setDataPosition(pos);
1430 dispatchStrings(p2, pRI);
1431 } else {
1432 p.setDataPosition(pos);
1433 dispatchStrings(p, pRI);
1434 }
1435}
1436
1437// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001438// When all RILs handle this request, this function can be removed and
1439// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001440static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
1441 RIL_RadioState state = s_callbacks.onStateRequest();
1442
1443 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1444 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1445 }
1446
Ethan Chend6e30652013-08-04 22:49:56 -07001447 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001448 if (RADIO_STATE_ON == state) {
1449 dispatchVoid(p, pRI);
1450 return;
1451 }
1452
Ethan Chend6e30652013-08-04 22:49:56 -07001453 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1454 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001455 // from Radio State
1456 voiceRadioTech = decodeVoiceRadioTechnology(state);
1457
1458 if (voiceRadioTech < 0)
1459 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1460 else
1461 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1462}
1463
Ethan Chend6e30652013-08-04 22:49:56 -07001464// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1465// When all RILs handle this request, this function can be removed and
1466// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001467static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
1468 RIL_RadioState state = s_callbacks.onStateRequest();
1469
1470 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1471 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1472 }
1473
1474 // RILs that support RADIO_STATE_ON should support this request.
1475 if (RADIO_STATE_ON == state) {
1476 dispatchVoid(p, pRI);
1477 return;
1478 }
1479
Ethan Chend6e30652013-08-04 22:49:56 -07001480 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001481 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001482 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001483 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1484
1485 if (cdmaSubscriptionSource < 0)
1486 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1487 else
1488 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1489}
1490
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001491static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1492{
1493 RIL_InitialAttachApn pf;
1494 int32_t t;
1495 status_t status;
1496
1497 memset(&pf, 0, sizeof(pf));
1498
1499 pf.apn = strdupReadString(p);
1500 pf.protocol = strdupReadString(p);
1501
1502 status = p.readInt32(&t);
1503 pf.authtype = (int) t;
1504
1505 pf.username = strdupReadString(p);
1506 pf.password = strdupReadString(p);
1507
1508 startRequest;
1509 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
1510 printBuf, pf.apn, pf.protocol, pf.auth_type, pf.username, pf.password);
1511 closeRequest;
1512 printRequest(pRI->token, pRI->pCI->requestNumber);
1513
1514 if (status != NO_ERROR) {
1515 goto invalid;
1516 }
1517 s_callbacks.onRequest(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI);
1518
1519#ifdef MEMSET_FREED
1520 memsetString(pf.apn);
1521 memsetString(pf.protocol);
1522 memsetString(pf.username);
1523 memsetString(pf.password);
1524#endif
1525
1526 free(pf.apn);
1527 free(pf.protocol);
1528 free(pf.username);
1529 free(pf.password);
1530
1531#ifdef MEMSET_FREED
1532 memset(&pf, 0, sizeof(pf));
1533#endif
1534
1535 return;
1536invalid:
1537 invalidCommandBlock(pRI);
1538 return;
1539}
1540
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001541static int
1542blockingWrite(int fd, const void *buffer, size_t len) {
1543 size_t writeOffset = 0;
1544 const uint8_t *toWrite;
1545
1546 toWrite = (const uint8_t *)buffer;
1547
1548 while (writeOffset < len) {
1549 ssize_t written;
1550 do {
1551 written = write (fd, toWrite + writeOffset,
1552 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001553 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001554
1555 if (written >= 0) {
1556 writeOffset += written;
1557 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001558 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001559 close(fd);
1560 return -1;
1561 }
1562 }
1563
1564 return 0;
1565}
1566
1567static int
1568sendResponseRaw (const void *data, size_t dataSize) {
1569 int fd = s_fdCommand;
1570 int ret;
1571 uint32_t header;
1572
1573 if (s_fdCommand < 0) {
1574 return -1;
1575 }
1576
1577 if (dataSize > MAX_COMMAND_BYTES) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001578 RLOGE("RIL: packet larger than %u (%u)",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001579 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1580
1581 return -1;
1582 }
1583
1584 pthread_mutex_lock(&s_writeMutex);
1585
1586 header = htonl(dataSize);
1587
1588 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1589
1590 if (ret < 0) {
1591 pthread_mutex_unlock(&s_writeMutex);
1592 return ret;
1593 }
1594
1595 ret = blockingWrite(fd, data, dataSize);
1596
1597 if (ret < 0) {
1598 pthread_mutex_unlock(&s_writeMutex);
1599 return ret;
1600 }
1601
1602 pthread_mutex_unlock(&s_writeMutex);
1603
1604 return 0;
1605}
1606
1607static int
1608sendResponse (Parcel &p) {
1609 printResponse;
1610 return sendResponseRaw(p.data(), p.dataSize());
1611}
1612
1613/** response is an int* pointing to an array of ints*/
1614
1615static int
1616responseInts(Parcel &p, void *response, size_t responselen) {
1617 int numInts;
1618
1619 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001620 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001621 return RIL_ERRNO_INVALID_RESPONSE;
1622 }
1623 if (responselen % sizeof(int) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001624 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001625 (int)responselen, (int)sizeof(int));
1626 return RIL_ERRNO_INVALID_RESPONSE;
1627 }
1628
1629 int *p_int = (int *) response;
1630
1631 numInts = responselen / sizeof(int *);
1632 p.writeInt32 (numInts);
1633
1634 /* each int*/
1635 startResponse;
1636 for (int i = 0 ; i < numInts ; i++) {
1637 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1638 p.writeInt32(p_int[i]);
1639 }
1640 removeLastChar;
1641 closeResponse;
1642
1643 return 0;
1644}
1645
1646static int
1647responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
1648 int numInts;
1649
1650 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001651 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001652 return RIL_ERRNO_INVALID_RESPONSE;
1653 }
1654 if (responselen % sizeof(int) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001655 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02001656 (int)responselen, (int)sizeof(int));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001657 return RIL_ERRNO_INVALID_RESPONSE;
1658 }
1659
1660 int *p_int = (int *) response;
1661
1662 numInts = responselen / sizeof(int *);
1663 p.writeInt32 (numInts);
1664
1665 /* each int*/
1666 startResponse;
1667 for (int i = 0 ; i < numInts ; i++) {
1668 if (i == 0 && p_int[0] == 7) {
Ethan Chend6e30652013-08-04 22:49:56 -07001669 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001670 p_int[0] = 0;
1671 }
1672 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1673 p.writeInt32(p_int[i]);
1674 }
1675 removeLastChar;
1676 closeResponse;
1677
1678 return 0;
1679}
1680
1681/** response is a char **, pointing to an array of char *'s
1682 The parcel will begin with the version */
1683static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1684 p.writeInt32(version);
1685 return responseStrings(p, response, responselen);
1686}
1687
1688/** response is a char **, pointing to an array of char *'s */
1689static int responseStrings(Parcel &p, void *response, size_t responselen) {
1690 return responseStrings(p, response, responselen, false);
1691}
1692
1693static int responseStringsNetworks(Parcel &p, void *response, size_t responselen) {
1694 int numStrings;
1695 int inQANElements = 5;
1696 int outQANElements = 4;
1697
1698 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001699 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001700 return RIL_ERRNO_INVALID_RESPONSE;
1701 }
1702 if (responselen % sizeof(char *) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001703 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001704 (int)responselen, (int)sizeof(char *));
1705 return RIL_ERRNO_INVALID_RESPONSE;
1706 }
Daniel Hillenbrandea4af612013-07-09 18:47:06 +02001707
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001708 if (response == NULL) {
1709 p.writeInt32 (0);
1710 } else {
1711 char **p_cur = (char **) response;
Ethan Chend6e30652013-08-04 22:49:56 -07001712 int j = 0;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001713
1714 numStrings = responselen / sizeof(char *);
1715 p.writeInt32 ((numStrings / inQANElements) * outQANElements);
1716
1717 /* each string*/
1718 startResponse;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001719 for (int i = 0 ; i < numStrings ; i++) {
1720 /* Samsung is sending 5 elements, upper layer expects 4.
1721 Drop every 5th element here */
1722 if (j == outQANElements) {
Ethan Chend6e30652013-08-04 22:49:56 -07001723 j = 0;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001724 } else {
1725 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1726 writeStringToParcel (p, p_cur[i]);
1727 j++;
1728 }
1729 }
1730 removeLastChar;
1731 closeResponse;
1732 }
1733 return 0;
1734}
1735
1736/** response is a char **, pointing to an array of char *'s */
1737static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
1738 int numStrings;
1739
1740 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001741 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001742 return RIL_ERRNO_INVALID_RESPONSE;
1743 }
1744 if (responselen % sizeof(char *) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001745 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001746 (int)responselen, (int)sizeof(char *));
1747 return RIL_ERRNO_INVALID_RESPONSE;
1748 }
1749
1750 if (response == NULL) {
1751 p.writeInt32 (0);
1752 } else {
1753 char **p_cur = (char **) response;
1754
1755 numStrings = responselen / sizeof(char *);
1756 p.writeInt32 (numStrings);
1757
1758 /* each string*/
1759 startResponse;
1760 for (int i = 0 ; i < numStrings ; i++) {
1761 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1762 writeStringToParcel (p, p_cur[i]);
1763 }
1764 removeLastChar;
1765 closeResponse;
1766 }
1767 return 0;
1768}
1769
1770/**
1771 * NULL strings are accepted
1772 * FIXME currently ignores responselen
1773 */
1774static int responseString(Parcel &p, void *response, size_t responselen) {
1775 /* one string only */
1776 startResponse;
1777 appendPrintBuf("%s%s", printBuf, (char*)response);
1778 closeResponse;
1779
1780 writeStringToParcel(p, (const char *)response);
1781
1782 return 0;
1783}
1784
1785static int responseVoid(Parcel &p, void *response, size_t responselen) {
1786 startResponse;
1787 removeLastChar;
1788 return 0;
1789}
1790
1791static int responseCallList(Parcel &p, void *response, size_t responselen) {
1792 int num;
1793
1794 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001795 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001796 return RIL_ERRNO_INVALID_RESPONSE;
1797 }
1798
1799 if (responselen % sizeof (RIL_Call *) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001800 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001801 (int)responselen, (int)sizeof (RIL_Call *));
1802 return RIL_ERRNO_INVALID_RESPONSE;
1803 }
1804
1805 startResponse;
1806 /* number of call info's */
1807 num = responselen / sizeof(RIL_Call *);
1808 p.writeInt32(num);
1809
1810 for (int i = 0 ; i < num ; i++) {
1811 RIL_Call *p_cur = ((RIL_Call **) response)[i];
1812 /* each call info */
1813 p.writeInt32(p_cur->state);
1814 p.writeInt32(p_cur->index);
1815 p.writeInt32(p_cur->toa);
1816 p.writeInt32(p_cur->isMpty);
1817 p.writeInt32(p_cur->isMT);
1818 p.writeInt32(p_cur->als);
1819 p.writeInt32(p_cur->isVoice);
1820 p.writeInt32(p_cur->isVoicePrivacy);
1821 writeStringToParcel(p, p_cur->number);
1822 p.writeInt32(p_cur->numberPresentation);
1823 writeStringToParcel(p, p_cur->name);
1824 p.writeInt32(p_cur->namePresentation);
1825 // Remove when partners upgrade to version 3
1826 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
1827 p.writeInt32(0); /* UUS Information is absent */
1828 } else {
1829 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
1830 p.writeInt32(1); /* UUS Information is present */
1831 p.writeInt32(uusInfo->uusType);
1832 p.writeInt32(uusInfo->uusDcs);
1833 p.writeInt32(uusInfo->uusLength);
1834 p.write(uusInfo->uusData, uusInfo->uusLength);
1835 }
1836 appendPrintBuf("%s[id=%d,%s,toa=%d,",
1837 printBuf,
1838 p_cur->index,
1839 callStateToString(p_cur->state),
1840 p_cur->toa);
1841 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
1842 printBuf,
1843 (p_cur->isMpty)?"conf":"norm",
1844 (p_cur->isMT)?"mt":"mo",
1845 p_cur->als,
1846 (p_cur->isVoice)?"voc":"nonvoc",
1847 (p_cur->isVoicePrivacy)?"evp":"noevp");
1848 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
1849 printBuf,
1850 p_cur->number,
1851 p_cur->numberPresentation,
1852 p_cur->name,
1853 p_cur->namePresentation);
1854 }
1855 removeLastChar;
1856 closeResponse;
1857
1858 return 0;
1859}
1860
1861static int responseSMS(Parcel &p, void *response, size_t responselen) {
1862 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001863 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001864 return RIL_ERRNO_INVALID_RESPONSE;
1865 }
1866
1867 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001868 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001869 (int)responselen, (int)sizeof (RIL_SMS_Response));
1870 return RIL_ERRNO_INVALID_RESPONSE;
1871 }
1872
1873 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1874
1875 p.writeInt32(p_cur->messageRef);
1876 writeStringToParcel(p, p_cur->ackPDU);
1877 p.writeInt32(p_cur->errorCode);
1878
1879 startResponse;
1880 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
1881 (char*)p_cur->ackPDU, p_cur->errorCode);
1882 closeResponse;
1883
1884 return 0;
1885}
1886
1887static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
1888{
1889 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001890 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001891 return RIL_ERRNO_INVALID_RESPONSE;
1892 }
1893
1894 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001895 RLOGE("invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001896 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
1897 return RIL_ERRNO_INVALID_RESPONSE;
1898 }
1899
1900 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
1901 p.writeInt32(num);
1902
1903 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
1904 startResponse;
1905 int i;
1906 for (i = 0; i < num; i++) {
1907 p.writeInt32(p_cur[i].cid);
1908 p.writeInt32(p_cur[i].active);
1909 writeStringToParcel(p, p_cur[i].type);
1910 // apn is not used, so don't send.
1911 writeStringToParcel(p, p_cur[i].address);
1912 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
1913 p_cur[i].cid,
1914 (p_cur[i].active==0)?"down":"up",
1915 (char*)p_cur[i].type,
1916 (char*)p_cur[i].address);
1917 }
1918 removeLastChar;
1919 closeResponse;
1920
1921 return 0;
1922}
1923
1924static int responseDataCallList(Parcel &p, void *response, size_t responselen)
1925{
1926 // Write version
1927 p.writeInt32(s_callbacks.version);
1928
1929 if (s_callbacks.version < 5) {
1930 return responseDataCallListV4(p, response, responselen);
1931 } else {
1932 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001933 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001934 return RIL_ERRNO_INVALID_RESPONSE;
1935 }
1936
1937 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001938 RLOGE("invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001939 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
1940 return RIL_ERRNO_INVALID_RESPONSE;
1941 }
1942
1943 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
1944 p.writeInt32(num);
1945
1946 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
1947 startResponse;
1948 int i;
1949 for (i = 0; i < num; i++) {
1950 p.writeInt32((int)p_cur[i].status);
1951 p.writeInt32(p_cur[i].suggestedRetryTime);
1952 p.writeInt32(p_cur[i].cid);
1953 p.writeInt32(p_cur[i].active);
1954 writeStringToParcel(p, p_cur[i].type);
1955 writeStringToParcel(p, p_cur[i].ifname);
1956 writeStringToParcel(p, p_cur[i].addresses);
1957 writeStringToParcel(p, p_cur[i].dnses);
1958 writeStringToParcel(p, p_cur[i].gateways);
1959 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
1960 p_cur[i].status,
1961 p_cur[i].suggestedRetryTime,
1962 p_cur[i].cid,
1963 (p_cur[i].active==0)?"down":"up",
1964 (char*)p_cur[i].type,
1965 (char*)p_cur[i].ifname,
1966 (char*)p_cur[i].addresses,
1967 (char*)p_cur[i].dnses,
1968 (char*)p_cur[i].gateways);
1969 }
1970 removeLastChar;
1971 closeResponse;
1972 }
1973
1974 return 0;
1975}
1976
1977static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
1978{
1979 if (s_callbacks.version < 5) {
1980 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
1981 } else {
1982 return responseDataCallList(p, response, responselen);
1983 }
1984}
1985
1986static int responseRaw(Parcel &p, void *response, size_t responselen) {
1987 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02001988 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001989 return RIL_ERRNO_INVALID_RESPONSE;
1990 }
1991
1992 // The java code reads -1 size as null byte array
1993 if (response == NULL) {
1994 p.writeInt32(-1);
1995 } else {
1996 p.writeInt32(responselen);
1997 p.write(response, responselen);
1998 }
1999
2000 return 0;
2001}
2002
2003
2004static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2005 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002006 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002007 return RIL_ERRNO_INVALID_RESPONSE;
2008 }
2009
2010 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002011 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002012 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2013 return RIL_ERRNO_INVALID_RESPONSE;
2014 }
2015
2016 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2017 p.writeInt32(p_cur->sw1);
2018 p.writeInt32(p_cur->sw2);
2019 writeStringToParcel(p, p_cur->simResponse);
2020
2021 startResponse;
2022 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2023 (char*)p_cur->simResponse);
2024 closeResponse;
2025
2026
2027 return 0;
2028}
2029
2030static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2031 int num;
2032
2033 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002034 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002035 return RIL_ERRNO_INVALID_RESPONSE;
2036 }
2037
2038 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002039 RLOGE("invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002040 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2041 return RIL_ERRNO_INVALID_RESPONSE;
2042 }
2043
2044 /* number of call info's */
2045 num = responselen / sizeof(RIL_CallForwardInfo *);
2046 p.writeInt32(num);
2047
2048 startResponse;
2049 for (int i = 0 ; i < num ; i++) {
2050 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2051
2052 p.writeInt32(p_cur->status);
2053 p.writeInt32(p_cur->reason);
2054 p.writeInt32(p_cur->serviceClass);
2055 p.writeInt32(p_cur->toa);
2056 writeStringToParcel(p, p_cur->number);
2057 p.writeInt32(p_cur->timeSeconds);
2058 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2059 (p_cur->status==1)?"enable":"disable",
2060 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2061 (char*)p_cur->number,
2062 p_cur->timeSeconds);
2063 }
2064 removeLastChar;
2065 closeResponse;
2066
2067 return 0;
2068}
2069
2070static int responseSsn(Parcel &p, void *response, size_t responselen) {
2071 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002072 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002073 return RIL_ERRNO_INVALID_RESPONSE;
2074 }
2075
2076 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002077 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002078 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2079 return RIL_ERRNO_INVALID_RESPONSE;
2080 }
2081
2082 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2083 p.writeInt32(p_cur->notificationType);
2084 p.writeInt32(p_cur->code);
2085 p.writeInt32(p_cur->index);
2086 p.writeInt32(p_cur->type);
2087 writeStringToParcel(p, p_cur->number);
2088
2089 startResponse;
2090 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2091 (p_cur->notificationType==0)?"mo":"mt",
2092 p_cur->code, p_cur->index, p_cur->type,
2093 (char*)p_cur->number);
2094 closeResponse;
2095
2096 return 0;
2097}
2098
2099static int responseCellList(Parcel &p, void *response, size_t responselen) {
2100 int num;
2101
2102 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002103 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002104 return RIL_ERRNO_INVALID_RESPONSE;
2105 }
2106
2107 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002108 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002109 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2110 return RIL_ERRNO_INVALID_RESPONSE;
2111 }
2112
2113 startResponse;
2114 /* number of records */
2115 num = responselen / sizeof(RIL_NeighboringCell *);
2116 p.writeInt32(num);
2117
2118 for (int i = 0 ; i < num ; i++) {
2119 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2120
2121 p.writeInt32(p_cur->rssi);
2122 writeStringToParcel (p, p_cur->cid);
2123
2124 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2125 p_cur->cid, p_cur->rssi);
2126 }
2127 removeLastChar;
2128 closeResponse;
2129
2130 return 0;
2131}
2132
2133/**
2134 * Marshall the signalInfoRecord into the parcel if it exists.
2135 */
2136static void marshallSignalInfoRecord(Parcel &p,
2137 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2138 p.writeInt32(p_signalInfoRecord.isPresent);
2139 p.writeInt32(p_signalInfoRecord.signalType);
2140 p.writeInt32(p_signalInfoRecord.alertPitch);
2141 p.writeInt32(p_signalInfoRecord.signal);
2142}
2143
2144static int responseCdmaInformationRecords(Parcel &p,
2145 void *response, size_t responselen) {
2146 int num;
2147 char* string8 = NULL;
2148 int buffer_lenght;
2149 RIL_CDMA_InformationRecord *infoRec;
2150
2151 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002152 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002153 return RIL_ERRNO_INVALID_RESPONSE;
2154 }
2155
2156 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002157 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002158 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2159 return RIL_ERRNO_INVALID_RESPONSE;
2160 }
2161
2162 RIL_CDMA_InformationRecords *p_cur =
2163 (RIL_CDMA_InformationRecords *) response;
2164 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2165
2166 startResponse;
2167 p.writeInt32(num);
2168
2169 for (int i = 0 ; i < num ; i++) {
2170 infoRec = &p_cur->infoRec[i];
2171 p.writeInt32(infoRec->name);
2172 switch (infoRec->name) {
2173 case RIL_CDMA_DISPLAY_INFO_REC:
2174 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2175 if (infoRec->rec.display.alpha_len >
2176 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002177 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002178 expected not more than %d\n",
2179 (int)infoRec->rec.display.alpha_len,
2180 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2181 return RIL_ERRNO_INVALID_RESPONSE;
2182 }
2183 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2184 * sizeof(char) );
2185 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2186 string8[i] = infoRec->rec.display.alpha_buf[i];
2187 }
2188 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2189 writeStringToParcel(p, (const char*)string8);
2190 free(string8);
2191 string8 = NULL;
2192 break;
2193 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2194 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2195 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2196 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002197 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002198 expected not more than %d\n",
2199 (int)infoRec->rec.number.len,
2200 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2201 return RIL_ERRNO_INVALID_RESPONSE;
2202 }
2203 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2204 * sizeof(char) );
2205 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2206 string8[i] = infoRec->rec.number.buf[i];
2207 }
2208 string8[(int)infoRec->rec.number.len] = '\0';
2209 writeStringToParcel(p, (const char*)string8);
2210 free(string8);
2211 string8 = NULL;
2212 p.writeInt32(infoRec->rec.number.number_type);
2213 p.writeInt32(infoRec->rec.number.number_plan);
2214 p.writeInt32(infoRec->rec.number.pi);
2215 p.writeInt32(infoRec->rec.number.si);
2216 break;
2217 case RIL_CDMA_SIGNAL_INFO_REC:
2218 p.writeInt32(infoRec->rec.signal.isPresent);
2219 p.writeInt32(infoRec->rec.signal.signalType);
2220 p.writeInt32(infoRec->rec.signal.alertPitch);
2221 p.writeInt32(infoRec->rec.signal.signal);
2222
2223 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2224 alertPitch=%X, signal=%X, ",
2225 printBuf, (int)infoRec->rec.signal.isPresent,
2226 (int)infoRec->rec.signal.signalType,
2227 (int)infoRec->rec.signal.alertPitch,
2228 (int)infoRec->rec.signal.signal);
2229 removeLastChar;
2230 break;
2231 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2232 if (infoRec->rec.redir.redirectingNumber.len >
2233 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002234 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002235 expected not more than %d\n",
2236 (int)infoRec->rec.redir.redirectingNumber.len,
2237 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2238 return RIL_ERRNO_INVALID_RESPONSE;
2239 }
2240 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2241 .len + 1) * sizeof(char) );
2242 for (int i = 0;
2243 i < infoRec->rec.redir.redirectingNumber.len;
2244 i++) {
2245 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2246 }
2247 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2248 writeStringToParcel(p, (const char*)string8);
2249 free(string8);
2250 string8 = NULL;
2251 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2252 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2253 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2254 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2255 p.writeInt32(infoRec->rec.redir.redirectingReason);
2256 break;
2257 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2258 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2259 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2260 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2261 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2262
2263 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2264 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2265 lineCtrlPowerDenial=%d, ", printBuf,
2266 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2267 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2268 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2269 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2270 removeLastChar;
2271 break;
2272 case RIL_CDMA_T53_CLIR_INFO_REC:
2273 p.writeInt32((int)(infoRec->rec.clir.cause));
2274
2275 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2276 removeLastChar;
2277 break;
2278 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2279 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2280 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2281
2282 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2283 infoRec->rec.audioCtrl.upLink,
2284 infoRec->rec.audioCtrl.downLink);
2285 removeLastChar;
2286 break;
2287 case RIL_CDMA_T53_RELEASE_INFO_REC:
2288 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002289 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002290 return RIL_ERRNO_INVALID_RESPONSE;
2291 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002292 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002293 return RIL_ERRNO_INVALID_RESPONSE;
2294 }
2295 }
2296 closeResponse;
2297
2298 return 0;
2299}
2300
2301static int responseRilSignalStrength(Parcel &p,
2302 void *response, size_t responselen) {
2303
2304 int gsmSignalStrength;
2305 int cdmaDbm;
2306 int evdoDbm;
2307
2308 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002309 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002310 return RIL_ERRNO_INVALID_RESPONSE;
2311 }
2312
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002313 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2314 RIL_SignalStrength_v6 *p_cur = ((RIL_SignalStrength_v6 *) response);
2315
2316 /* gsmSignalStrength */
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002317 RLOGD("gsmSignalStrength (raw)=%d", p_cur->GW_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002318 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
2319 if (gsmSignalStrength < 0) {
2320 gsmSignalStrength = 99;
2321 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
2322 gsmSignalStrength = 31;
2323 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002324 RLOGD("gsmSignalStrength (corrected)=%d", gsmSignalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002325 p.writeInt32(gsmSignalStrength);
2326
2327 /* gsmBitErrorRate */
2328 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2329
2330 /* cdmaDbm */
Ethan Chend6e30652013-08-04 22:49:56 -07002331 RLOGD("cdmaDbm (raw)=%d", p_cur->CDMA_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002332 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
2333 if (cdmaDbm < 0) {
2334 cdmaDbm = 99;
2335 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
2336 cdmaDbm = 31;
2337 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002338 //RLOGD("cdmaDbm (corrected)=%d", cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002339 p.writeInt32(cdmaDbm);
2340
2341 /* cdmaEcio */
2342 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2343
2344 /* evdoDbm */
Ethan Chend6e30652013-08-04 22:49:56 -07002345 RLOGD("evdoDbm (raw)=%d", p_cur->EVDO_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002346 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
2347 if (evdoDbm < 0) {
2348 evdoDbm = 99;
2349 } else if (evdoDbm > 31 && evdoDbm != 99) {
2350 evdoDbm = 31;
2351 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002352 //RLOGD("evdoDbm (corrected)=%d", evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002353 p.writeInt32(evdoDbm);
2354
2355 /* evdoEcio */
2356 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2357 /* evdoSnr */
2358 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2359
2360 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002361 /*
Ethan Chend6e30652013-08-04 22:49:56 -07002362 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002363 */
Ethan Chend6e30652013-08-04 22:49:56 -07002364 if (s_callbacks.version <= 6) {
2365 // signalStrength: -1 -> 99
2366 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2367 p_cur->LTE_SignalStrength.signalStrength = 99;
2368 }
2369 // rsrp: -1 -> INT_MAX all other negative value to positive.
2370 // So remap here
2371 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2372 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2373 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2374 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2375 }
2376 // rsrq: -1 -> INT_MAX
2377 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2378 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2379 }
2380 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002381
Ethan Chend6e30652013-08-04 22:49:56 -07002382 // cqi: -1 -> INT_MAX
2383 if (p_cur->LTE_SignalStrength.cqi == -1) {
2384 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2385 }
2386 }
2387 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002388 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002389 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002390 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002391 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002392 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07002393 p.writeInt32(99);
2394 p.writeInt32(INT_MAX);
2395 p.writeInt32(INT_MAX);
2396 p.writeInt32(INT_MAX);
2397 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002398 }
2399
2400 startResponse;
2401 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
2402 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2403 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2404 EVDO_SS.signalNoiseRatio=%d,\
2405 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
2406 LTE_SS.rssnr=%d,LTE_SS.cqi=%d]",
2407 printBuf,
2408 gsmSignalStrength,
2409 p_cur->GW_SignalStrength.bitErrorRate,
2410 cdmaDbm,
2411 p_cur->CDMA_SignalStrength.ecio,
2412 evdoDbm,
2413 p_cur->EVDO_SignalStrength.ecio,
2414 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2415 p_cur->LTE_SignalStrength.signalStrength,
2416 p_cur->LTE_SignalStrength.rsrp,
2417 p_cur->LTE_SignalStrength.rsrq,
2418 p_cur->LTE_SignalStrength.rssnr,
2419 p_cur->LTE_SignalStrength.cqi);
2420 closeResponse;
2421
2422 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002423 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002424 return RIL_ERRNO_INVALID_RESPONSE;
2425 }
2426
2427 return 0;
2428}
2429
2430static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2431 if ((response == NULL) || (responselen == 0)) {
2432 return responseVoid(p, response, responselen);
2433 } else {
2434 return responseCdmaSignalInfoRecord(p, response, responselen);
2435 }
2436}
2437
2438static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2439 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002440 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002441 return RIL_ERRNO_INVALID_RESPONSE;
2442 }
2443
2444 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002445 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002446 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2447 return RIL_ERRNO_INVALID_RESPONSE;
2448 }
2449
2450 startResponse;
2451
2452 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2453 marshallSignalInfoRecord(p, *p_cur);
2454
2455 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2456 signal=%d]",
2457 printBuf,
2458 p_cur->isPresent,
2459 p_cur->signalType,
2460 p_cur->alertPitch,
2461 p_cur->signal);
2462
2463 closeResponse;
2464 return 0;
2465}
2466
2467static int responseCdmaCallWaiting(Parcel &p, void *response,
2468 size_t responselen) {
2469 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002470 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002471 return RIL_ERRNO_INVALID_RESPONSE;
2472 }
2473
2474 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002475 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002476 }
2477
2478 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2479
2480 writeStringToParcel(p, p_cur->number);
2481 p.writeInt32(p_cur->numberPresentation);
2482 writeStringToParcel(p, p_cur->name);
2483 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2484
2485 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2486 p.writeInt32(p_cur->number_type);
2487 p.writeInt32(p_cur->number_plan);
2488 } else {
2489 p.writeInt32(0);
2490 p.writeInt32(0);
2491 }
2492
2493 startResponse;
2494 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2495 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2496 signal=%d,number_type=%d,number_plan=%d]",
2497 printBuf,
2498 p_cur->number,
2499 p_cur->numberPresentation,
2500 p_cur->name,
2501 p_cur->signalInfoRecord.isPresent,
2502 p_cur->signalInfoRecord.signalType,
2503 p_cur->signalInfoRecord.alertPitch,
2504 p_cur->signalInfoRecord.signal,
2505 p_cur->number_type,
2506 p_cur->number_plan);
2507 closeResponse;
2508
2509 return 0;
2510}
2511
2512static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2513 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002514 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002515 return RIL_ERRNO_INVALID_RESPONSE;
2516 }
2517
2518 startResponse;
2519 if (s_callbacks.version == 7) {
2520 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2521 p.writeInt32(p_cur->result);
2522 p.writeInt32(p_cur->ef_id);
2523 writeStringToParcel(p, p_cur->aid);
2524
2525 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2526 printBuf,
2527 p_cur->result,
2528 p_cur->ef_id,
2529 p_cur->aid);
2530 } else {
2531 int *p_cur = ((int *) response);
2532 p.writeInt32(p_cur[0]);
2533 p.writeInt32(p_cur[1]);
2534 writeStringToParcel(p, NULL);
2535
2536 appendPrintBuf("%sresult=%d, ef_id=%d",
2537 printBuf,
2538 p_cur[0],
2539 p_cur[1]);
2540 }
2541 closeResponse;
2542
2543 return 0;
2544}
2545
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002546static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2547{
2548 if (response == NULL && responselen != 0) {
2549 RLOGE("invalid response: NULL");
2550 return RIL_ERRNO_INVALID_RESPONSE;
2551 }
2552
2553 if (responselen % sizeof(RIL_CellInfo) != 0) {
2554 RLOGE("invalid response length %d expected multiple of %d",
2555 (int)responselen, (int)sizeof(RIL_CellInfo));
2556 return RIL_ERRNO_INVALID_RESPONSE;
2557 }
2558
2559 int num = responselen / sizeof(RIL_CellInfo);
2560 p.writeInt32(num);
2561
2562 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2563 startResponse;
2564 int i;
2565 for (i = 0; i < num; i++) {
2566 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2567 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2568 p.writeInt32((int)p_cur->cellInfoType);
2569 p.writeInt32(p_cur->registered);
2570 p.writeInt32(p_cur->timeStampType);
2571 p.writeInt64(p_cur->timeStamp);
2572 switch(p_cur->cellInfoType) {
2573 case RIL_CELL_INFO_TYPE_GSM: {
2574 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
2575 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2576 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2577 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
2578 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2579 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
2580 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2581 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2582
2583 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2584 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2585 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2586 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2587 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2588 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2589 break;
2590 }
2591 case RIL_CELL_INFO_TYPE_WCDMA: {
2592 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2593 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2594 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2595 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2596 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2597 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2598 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2599 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2600 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2601
2602 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2603 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2604 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2605 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2606 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2607 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2608 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2609 break;
2610 }
2611 case RIL_CELL_INFO_TYPE_CDMA: {
2612 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2613 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2614 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2615 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2616 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2617 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2618
2619 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2620 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
2621 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
2622 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
2623 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2624
2625 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
2626 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
2627 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
2628 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
2629 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
2630 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2631
2632 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
2633 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
2634 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
2635 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
2636 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2637 break;
2638 }
2639 case RIL_CELL_INFO_TYPE_LTE: {
2640 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
2641 p_cur->CellInfo.lte.cellIdentityLte.mcc,
2642 p_cur->CellInfo.lte.cellIdentityLte.mnc,
2643 p_cur->CellInfo.lte.cellIdentityLte.ci,
2644 p_cur->CellInfo.lte.cellIdentityLte.pci,
2645 p_cur->CellInfo.lte.cellIdentityLte.tac);
2646
2647 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
2648 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
2649 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
2650 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
2651 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
2652
2653 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
2654 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
2655 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
2656 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
2657 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
2658 p_cur->CellInfo.lte.signalStrengthLte.cqi,
2659 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2660 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
2661 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
2662 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
2663 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
2664 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
2665 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2666 break;
2667 }
2668 }
2669 p_cur += 1;
2670 }
2671 removeLastChar;
2672 closeResponse;
2673
2674 return 0;
2675}
2676
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002677static void triggerEvLoop() {
2678 int ret;
2679 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
2680 /* trigger event loop to wakeup. No reason to do this,
2681 * if we're in the event loop thread */
2682 do {
2683 ret = write (s_fdWakeupWrite, " ", 1);
2684 } while (ret < 0 && errno == EINTR);
2685 }
2686}
2687
2688static void rilEventAddWakeup(struct ril_event *ev) {
2689 ril_event_add(ev);
2690 triggerEvLoop();
2691}
2692
2693static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
2694 p.writeInt32(num_apps);
2695 startResponse;
2696 for (int i = 0; i < num_apps; i++) {
2697 p.writeInt32(appStatus[i].app_type);
2698 p.writeInt32(appStatus[i].app_state);
2699 p.writeInt32(appStatus[i].perso_substate);
2700 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
2701 writeStringToParcel(p, (const char*)
2702 (appStatus[i].app_label_ptr));
2703 p.writeInt32(appStatus[i].pin1_replaced);
2704 p.writeInt32(appStatus[i].pin1);
2705 p.writeInt32(appStatus[i].pin2);
2706 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
2707 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
2708 printBuf,
2709 appStatus[i].app_type,
2710 appStatus[i].app_state,
2711 appStatus[i].perso_substate,
2712 appStatus[i].aid_ptr,
2713 appStatus[i].app_label_ptr,
2714 appStatus[i].pin1_replaced,
2715 appStatus[i].pin1,
2716 appStatus[i].pin2);
2717 }
2718 closeResponse;
2719}
2720
2721static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002722 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002723 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002724 return RIL_ERRNO_INVALID_RESPONSE;
2725 }
2726
2727 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002728 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
2729
2730 p.writeInt32(p_cur->card_state);
2731 p.writeInt32(p_cur->universal_pin_state);
2732 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2733 p.writeInt32(p_cur->cdma_subscription_app_index);
2734 p.writeInt32(p_cur->ims_subscription_app_index);
2735
2736 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2737 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002738 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
2739
2740 p.writeInt32(p_cur->card_state);
2741 p.writeInt32(p_cur->universal_pin_state);
2742 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2743 p.writeInt32(p_cur->cdma_subscription_app_index);
2744 p.writeInt32(-1);
2745
2746 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2747 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002748 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002749 return RIL_ERRNO_INVALID_RESPONSE;
2750 }
2751
2752 return 0;
2753}
2754
2755static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2756 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
2757 p.writeInt32(num);
2758
2759 startResponse;
2760 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
2761 (RIL_GSM_BroadcastSmsConfigInfo **) response;
2762 for (int i = 0; i < num; i++) {
2763 p.writeInt32(p_cur[i]->fromServiceId);
2764 p.writeInt32(p_cur[i]->toServiceId);
2765 p.writeInt32(p_cur[i]->fromCodeScheme);
2766 p.writeInt32(p_cur[i]->toCodeScheme);
2767 p.writeInt32(p_cur[i]->selected);
2768
2769 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
2770 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
2771 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
2772 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
2773 p_cur[i]->selected);
2774 }
2775 closeResponse;
2776
2777 return 0;
2778}
2779
2780static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2781 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
2782 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
2783
2784 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
2785 p.writeInt32(num);
2786
2787 startResponse;
2788 for (int i = 0 ; i < num ; i++ ) {
2789 p.writeInt32(p_cur[i]->service_category);
2790 p.writeInt32(p_cur[i]->language);
2791 p.writeInt32(p_cur[i]->selected);
2792
2793 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
2794 selected =%d], ",
2795 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
2796 p_cur[i]->selected);
2797 }
2798 closeResponse;
2799
2800 return 0;
2801}
2802
2803static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
2804 int num;
2805 int digitCount;
2806 int digitLimit;
2807 uint8_t uct;
2808 void* dest;
2809
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002810 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002811
2812 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002813 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002814 return RIL_ERRNO_INVALID_RESPONSE;
2815 }
2816
2817 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002818 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002819 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
2820 return RIL_ERRNO_INVALID_RESPONSE;
2821 }
2822
2823 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
2824 p.writeInt32(p_cur->uTeleserviceID);
2825 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
2826 p.writeInt32(p_cur->uServicecategory);
2827 p.writeInt32(p_cur->sAddress.digit_mode);
2828 p.writeInt32(p_cur->sAddress.number_mode);
2829 p.writeInt32(p_cur->sAddress.number_type);
2830 p.writeInt32(p_cur->sAddress.number_plan);
2831 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
2832 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2833 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2834 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
2835 }
2836
2837 p.writeInt32(p_cur->sSubAddress.subaddressType);
2838 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
2839 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
2840 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2841 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2842 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
2843 }
2844
2845 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2846 p.writeInt32(p_cur->uBearerDataLen);
2847 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2848 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
2849 }
2850
2851 startResponse;
2852 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
2853 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
2854 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
2855 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
2856 closeResponse;
2857
2858 return 0;
2859}
2860
2861/**
2862 * A write on the wakeup fd is done just to pop us out of select()
2863 * We empty the buffer here and then ril_event will reset the timers on the
2864 * way back down
2865 */
2866static void processWakeupCallback(int fd, short flags, void *param) {
2867 char buff[16];
2868 int ret;
2869
Ethan Chend6e30652013-08-04 22:49:56 -07002870 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002871
2872 /* empty our wakeup socket out */
2873 do {
2874 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
2875 } while (ret > 0 || (ret < 0 && errno == EINTR));
2876}
2877
2878static void onCommandsSocketClosed() {
2879 int ret;
2880 RequestInfo *p_cur;
2881
2882 /* mark pending requests as "cancelled" so we dont report responses */
2883
2884 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
2885 assert (ret == 0);
2886
2887 p_cur = s_pendingRequests;
2888
2889 for (p_cur = s_pendingRequests
2890 ; p_cur != NULL
2891 ; p_cur = p_cur->p_next
2892 ) {
2893 p_cur->cancelled = 1;
2894 }
2895
2896 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
2897 assert (ret == 0);
2898}
2899
2900static void processCommandsCallback(int fd, short flags, void *param) {
2901 RecordStream *p_rs;
2902 void *p_record;
2903 size_t recordlen;
2904 int ret;
2905
2906 assert(fd == s_fdCommand);
2907
2908 p_rs = (RecordStream *)param;
2909
2910 for (;;) {
2911 /* loop until EAGAIN/EINTR, end of stream, or other error */
2912 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
2913
2914 if (ret == 0 && p_record == NULL) {
2915 /* end-of-stream */
2916 break;
2917 } else if (ret < 0) {
2918 break;
2919 } else if (ret == 0) { /* && p_record != NULL */
2920 processCommandBuffer(p_record, recordlen);
2921 }
2922 }
2923
2924 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
2925 /* fatal error or end-of-stream */
2926 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002927 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002928 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002929 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002930 }
2931
2932 close(s_fdCommand);
2933 s_fdCommand = -1;
2934
2935 ril_event_del(&s_commands_event);
2936
2937 record_stream_free(p_rs);
2938
2939 /* start listening for new connections again */
2940 rilEventAddWakeup(&s_listen_event);
2941
2942 onCommandsSocketClosed();
2943 }
2944}
2945
2946
2947static void onNewCommandConnect() {
2948 // Inform we are connected and the ril version
2949 int rilVer = s_callbacks.version;
2950 RIL_onUnsolicitedResponse(RIL_UNSOL_RIL_CONNECTED,
2951 &rilVer, sizeof(rilVer));
2952
2953 // implicit radio state changed
2954 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
2955 NULL, 0);
2956
2957 // Send last NITZ time data, in case it was missed
2958 if (s_lastNITZTimeData != NULL) {
2959 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
2960
2961 free(s_lastNITZTimeData);
2962 s_lastNITZTimeData = NULL;
2963 }
2964
2965 // Get version string
2966 if (s_callbacks.getVersion != NULL) {
2967 const char *version;
2968 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002969 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002970
2971 property_set(PROPERTY_RIL_IMPL, version);
2972 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002973 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002974 property_set(PROPERTY_RIL_IMPL, "unavailable");
2975 }
2976
2977}
2978
2979static void listenCallback (int fd, short flags, void *param) {
2980 int ret;
2981 int err;
2982 int is_phone_socket;
2983 RecordStream *p_rs;
2984
2985 struct sockaddr_un peeraddr;
2986 socklen_t socklen = sizeof (peeraddr);
2987
2988 struct ucred creds;
2989 socklen_t szCreds = sizeof(creds);
2990
2991 struct passwd *pwd = NULL;
2992
2993 assert (s_fdCommand < 0);
2994 assert (fd == s_fdListen);
2995
2996 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
2997
2998 if (s_fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002999 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003000 /* start listening for new connections again */
3001 rilEventAddWakeup(&s_listen_event);
3002 return;
3003 }
3004
3005 /* check the credential of the other side and only accept socket from
3006 * phone process
3007 */
3008 errno = 0;
3009 is_phone_socket = 0;
3010
3011 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
3012
3013 if (err == 0 && szCreds > 0) {
3014 errno = 0;
3015 pwd = getpwuid(creds.uid);
3016 if (pwd != NULL) {
3017 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
3018 is_phone_socket = 1;
3019 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003020 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003021 }
3022 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003023 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003024 }
3025 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003026 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003027 }
3028
3029 if ( !is_phone_socket ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003030 RLOGE("RILD must accept socket from %s", PHONE_PROCESS);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003031
3032 close(s_fdCommand);
3033 s_fdCommand = -1;
3034
3035 onCommandsSocketClosed();
3036
3037 /* start listening for new connections again */
3038 rilEventAddWakeup(&s_listen_event);
3039
3040 return;
3041 }
3042
3043 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
3044
3045 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003046 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003047 }
3048
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003049 RLOGI("libril: new connection");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003050
3051 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
3052
3053 ril_event_set (&s_commands_event, s_fdCommand, 1,
3054 processCommandsCallback, p_rs);
3055
3056 rilEventAddWakeup (&s_commands_event);
3057
3058 onNewCommandConnect();
3059}
3060
3061static void freeDebugCallbackArgs(int number, char **args) {
3062 for (int i = 0; i < number; i++) {
3063 if (args[i] != NULL) {
3064 free(args[i]);
3065 }
3066 }
3067 free(args);
3068}
3069
3070static void debugCallback (int fd, short flags, void *param) {
3071 int acceptFD, option;
3072 struct sockaddr_un peeraddr;
3073 socklen_t socklen = sizeof (peeraddr);
3074 int data;
3075 unsigned int qxdm_data[6];
3076 const char *deactData[1] = {"1"};
3077 char *actData[1];
3078 RIL_Dial dialData;
3079 int hangupData[1] = {1};
3080 int number;
3081 char **args;
3082
3083 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3084
3085 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003086 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003087 return;
3088 }
3089
3090 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003091 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003092 return;
3093 }
3094 args = (char **) malloc(sizeof(char*) * number);
3095
3096 for (int i = 0; i < number; i++) {
3097 int len;
3098 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003099 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003100 freeDebugCallbackArgs(i, args);
3101 return;
3102 }
3103 // +1 for null-term
3104 args[i] = (char *) malloc((sizeof(char) * len) + 1);
3105 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
3106 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003107 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003108 freeDebugCallbackArgs(i, args);
3109 return;
3110 }
3111 char * buf = args[i];
3112 buf[len] = 0;
3113 }
3114
3115 switch (atoi(args[0])) {
3116 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003117 RLOGI ("Connection on debug port: issuing reset.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003118 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
3119 break;
3120 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003121 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003122 data = 0;
3123 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
3124 // Close the socket
3125 close(s_fdCommand);
3126 s_fdCommand = -1;
3127 break;
3128 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003129 RLOGI ("Debug port: issuing unsolicited voice network change.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003130 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
3131 NULL, 0);
3132 break;
3133 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003134 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003135 qxdm_data[0] = 65536; // head.func_tag
3136 qxdm_data[1] = 16; // head.len
3137 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3138 qxdm_data[3] = 32; // log_file_size: 32megabytes
3139 qxdm_data[4] = 0; // log_mask
3140 qxdm_data[5] = 8; // log_max_fileindex
3141 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
3142 6 * sizeof(int));
3143 break;
3144 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003145 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003146 qxdm_data[0] = 65536;
3147 qxdm_data[1] = 16;
3148 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
3149 qxdm_data[3] = 32;
3150 qxdm_data[4] = 0;
3151 qxdm_data[5] = 8;
3152 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
3153 6 * sizeof(int));
3154 break;
3155 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003156 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003157 data = 1;
3158 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
3159 sleep(2);
3160 // Set network selection automatic.
3161 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
3162 break;
3163 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003164 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003165 actData[0] = args[1];
3166 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
3167 sizeof(actData));
3168 break;
3169 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003170 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003171 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
3172 sizeof(deactData));
3173 break;
3174 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003175 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003176 dialData.clir = 0;
3177 dialData.address = args[1];
3178 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
3179 break;
3180 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003181 RLOGI("Debug port: Answer Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003182 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
3183 break;
3184 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003185 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003186 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
3187 sizeof(hangupData));
3188 break;
3189 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003190 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003191 break;
3192 }
3193 freeDebugCallbackArgs(number, args);
3194 close(acceptFD);
3195}
3196
3197
3198static void userTimerCallback (int fd, short flags, void *param) {
3199 UserCallbackInfo *p_info;
3200
3201 p_info = (UserCallbackInfo *)param;
3202
3203 p_info->p_callback(p_info->userParam);
3204
3205
3206 // FIXME generalize this...there should be a cancel mechanism
3207 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3208 s_last_wake_timeout_info = NULL;
3209 }
3210
3211 free(p_info);
3212}
3213
3214
3215static void *
3216eventLoop(void *param) {
3217 int ret;
3218 int filedes[2];
3219
3220 ril_event_init();
3221
3222 pthread_mutex_lock(&s_startupMutex);
3223
3224 s_started = 1;
3225 pthread_cond_broadcast(&s_startupCond);
3226
3227 pthread_mutex_unlock(&s_startupMutex);
3228
3229 ret = pipe(filedes);
3230
3231 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003232 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003233 return NULL;
3234 }
3235
3236 s_fdWakeupRead = filedes[0];
3237 s_fdWakeupWrite = filedes[1];
3238
3239 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3240
3241 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3242 processWakeupCallback, NULL);
3243
3244 rilEventAddWakeup (&s_wakeupfd_event);
3245
3246 // Only returns on error
3247 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003248 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003249 // kill self to restart on error
3250 kill(0, SIGKILL);
3251
3252 return NULL;
3253}
3254
3255extern "C" void
3256RIL_startEventLoop(void) {
3257 int ret;
3258 pthread_attr_t attr;
3259
3260 /* spin up eventLoop thread and wait for it to get started */
3261 s_started = 0;
3262 pthread_mutex_lock(&s_startupMutex);
3263
3264 pthread_attr_init (&attr);
3265 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3266 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3267
3268 while (s_started == 0) {
3269 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3270 }
3271
3272 pthread_mutex_unlock(&s_startupMutex);
3273
3274 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003275 RLOGE("Failed to create dispatch thread errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003276 return;
3277 }
3278}
3279
3280// Used for testing purpose only.
3281extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3282 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3283}
3284
3285extern "C" void
3286RIL_register (const RIL_RadioFunctions *callbacks) {
3287 int ret;
3288 int flags;
3289
3290 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003291 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003292 return;
3293 }
3294 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003295 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003296 callbacks->version, RIL_VERSION_MIN);
3297 return;
3298 }
3299 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003300 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003301 callbacks->version, RIL_VERSION);
3302 return;
3303 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003304 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003305
3306 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003307 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003308 "Subsequent call ignored");
3309 return;
3310 }
3311
3312 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3313
3314 s_registerCalled = 1;
3315
3316 // Little self-check
3317
3318 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
3319 assert(i == s_commands[i].requestNumber);
3320 }
3321
3322 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003323 /* Hack to include Samsung responses */
3324 if (i > MAX_RIL_UNSOL - RIL_UNSOL_RESPONSE_BASE) {
3325 assert(i + SAMSUNG_UNSOL_RESPONSE_BASE - MAX_RIL_UNSOL
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003326 == s_unsolResponses[i].requestNumber);
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003327 } else {
3328 assert(i + RIL_UNSOL_RESPONSE_BASE
3329 == s_unsolResponses[i].requestNumber);
3330 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003331 }
3332
3333 // New rild impl calls RIL_startEventLoop() first
3334 // old standalone impl wants it here.
3335
3336 if (s_started == 0) {
3337 RIL_startEventLoop();
3338 }
3339
3340 // start listen socket
3341
3342#if 0
3343 ret = socket_local_server (SOCKET_NAME_RIL,
3344 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
3345
3346 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003347 RLOGE("Unable to bind socket errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003348 exit (-1);
3349 }
3350 s_fdListen = ret;
3351
3352#else
3353 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
3354 if (s_fdListen < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003355 RLOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003356 exit(-1);
3357 }
3358
3359 ret = listen(s_fdListen, 4);
3360
3361 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003362 RLOGE("Failed to listen on control socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003363 s_fdListen, strerror(errno));
3364 exit(-1);
3365 }
3366#endif
3367
3368
3369 /* note: non-persistent so we can accept only one connection at a time */
3370 ril_event_set (&s_listen_event, s_fdListen, false,
3371 listenCallback, NULL);
3372
3373 rilEventAddWakeup (&s_listen_event);
3374
3375#if 1
3376 // start debug interface socket
3377
3378 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
3379 if (s_fdDebug < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003380 RLOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003381 exit(-1);
3382 }
3383
3384 ret = listen(s_fdDebug, 4);
3385
3386 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003387 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003388 s_fdDebug, strerror(errno));
3389 exit(-1);
3390 }
3391
3392 ril_event_set (&s_debug_event, s_fdDebug, true,
3393 debugCallback, NULL);
3394
3395 rilEventAddWakeup (&s_debug_event);
3396#endif
3397
3398}
3399
3400static int
3401checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
3402 int ret = 0;
3403
3404 if (pRI == NULL) {
3405 return 0;
3406 }
3407
3408 pthread_mutex_lock(&s_pendingRequestsMutex);
3409
3410 for(RequestInfo **ppCur = &s_pendingRequests
3411 ; *ppCur != NULL
3412 ; ppCur = &((*ppCur)->p_next)
3413 ) {
3414 if (pRI == *ppCur) {
3415 ret = 1;
3416
3417 *ppCur = (*ppCur)->p_next;
3418 break;
3419 }
3420 }
3421
3422 pthread_mutex_unlock(&s_pendingRequestsMutex);
3423
3424 return ret;
3425}
3426
3427
3428extern "C" void
3429RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
3430 RequestInfo *pRI;
3431 int ret;
3432 size_t errorOffset;
3433
3434 pRI = (RequestInfo *)t;
3435
3436 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003437 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003438 return;
3439 }
3440
3441 if (pRI->local > 0) {
3442 // Locally issued command...void only!
3443 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003444 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003445
3446 goto done;
3447 }
3448
3449 appendPrintBuf("[%04d]< %s",
3450 pRI->token, requestToString(pRI->pCI->requestNumber));
3451
3452 if (pRI->cancelled == 0) {
3453 Parcel p;
3454
3455 p.writeInt32 (RESPONSE_SOLICITED);
3456 p.writeInt32 (pRI->token);
3457 errorOffset = p.dataPosition();
3458
3459 p.writeInt32 (e);
3460
3461 if (response != NULL) {
3462 // there is a response payload, no matter success or not.
3463 ret = pRI->pCI->responseFunction(p, response, responselen);
3464
3465 /* if an error occurred, rewind and mark it */
3466 if (ret != 0) {
3467 p.setDataPosition(errorOffset);
3468 p.writeInt32 (ret);
3469 }
3470 }
3471
3472 if (e != RIL_E_SUCCESS) {
3473 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
3474 }
3475
3476 if (s_fdCommand < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003477 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003478 }
3479 sendResponse(p);
3480 }
3481
3482done:
3483 free(pRI);
3484}
3485
3486
3487static void
3488grabPartialWakeLock() {
3489 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
3490}
3491
3492static void
3493releaseWakeLock() {
3494 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
3495}
3496
3497/**
3498 * Timer callback to put us back to sleep before the default timeout
3499 */
3500static void
3501wakeTimeoutCallback (void *param) {
3502 // We're using "param != NULL" as a cancellation mechanism
3503 if (param == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003504 //RLOGD("wakeTimeout: releasing wake lock");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003505
3506 releaseWakeLock();
3507 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003508 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003509 }
3510}
3511
3512static int
3513decodeVoiceRadioTechnology (RIL_RadioState radioState) {
3514 switch (radioState) {
3515 case RADIO_STATE_SIM_NOT_READY:
3516 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3517 case RADIO_STATE_SIM_READY:
3518 return RADIO_TECH_UMTS;
3519
3520 case RADIO_STATE_RUIM_NOT_READY:
3521 case RADIO_STATE_RUIM_READY:
3522 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3523 case RADIO_STATE_NV_NOT_READY:
3524 case RADIO_STATE_NV_READY:
3525 return RADIO_TECH_1xRTT;
3526
3527 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003528 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003529 return -1;
3530 }
3531}
3532
3533static int
3534decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
3535 switch (radioState) {
3536 case RADIO_STATE_SIM_NOT_READY:
3537 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3538 case RADIO_STATE_SIM_READY:
3539 case RADIO_STATE_RUIM_NOT_READY:
3540 case RADIO_STATE_RUIM_READY:
3541 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3542 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
3543
3544 case RADIO_STATE_NV_NOT_READY:
3545 case RADIO_STATE_NV_READY:
3546 return CDMA_SUBSCRIPTION_SOURCE_NV;
3547
3548 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003549 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003550 return -1;
3551 }
3552}
3553
3554static int
3555decodeSimStatus (RIL_RadioState radioState) {
3556 switch (radioState) {
3557 case RADIO_STATE_SIM_NOT_READY:
3558 case RADIO_STATE_RUIM_NOT_READY:
3559 case RADIO_STATE_NV_NOT_READY:
3560 case RADIO_STATE_NV_READY:
3561 return -1;
3562 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3563 case RADIO_STATE_SIM_READY:
3564 case RADIO_STATE_RUIM_READY:
3565 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3566 return radioState;
3567 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003568 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003569 return -1;
3570 }
3571}
3572
3573static bool is3gpp2(int radioTech) {
3574 switch (radioTech) {
3575 case RADIO_TECH_IS95A:
3576 case RADIO_TECH_IS95B:
3577 case RADIO_TECH_1xRTT:
3578 case RADIO_TECH_EVDO_0:
3579 case RADIO_TECH_EVDO_A:
3580 case RADIO_TECH_EVDO_B:
3581 case RADIO_TECH_EHRPD:
3582 return true;
3583 default:
3584 return false;
3585 }
3586}
3587
3588/* If RIL sends SIM states or RUIM states, store the voice radio
3589 * technology and subscription source information so that they can be
3590 * returned when telephony framework requests them
3591 */
3592static RIL_RadioState
3593processRadioState(RIL_RadioState newRadioState) {
3594
3595 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
3596 int newVoiceRadioTech;
3597 int newCdmaSubscriptionSource;
3598 int newSimStatus;
3599
3600 /* This is old RIL. Decode Subscription source and Voice Radio Technology
3601 from Radio State and send change notifications if there has been a change */
3602 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
3603 if(newVoiceRadioTech != voiceRadioTech) {
3604 voiceRadioTech = newVoiceRadioTech;
3605 RIL_onUnsolicitedResponse (RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
3606 &voiceRadioTech, sizeof(voiceRadioTech));
3607 }
3608 if(is3gpp2(newVoiceRadioTech)) {
3609 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
3610 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
3611 cdmaSubscriptionSource = newCdmaSubscriptionSource;
3612 RIL_onUnsolicitedResponse (RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
3613 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource));
3614 }
3615 }
3616 newSimStatus = decodeSimStatus(newRadioState);
3617 if(newSimStatus != simRuimStatus) {
3618 simRuimStatus = newSimStatus;
3619 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
3620 }
3621
3622 /* Send RADIO_ON to telephony */
3623 newRadioState = RADIO_STATE_ON;
3624 }
3625
3626 return newRadioState;
3627}
3628
3629extern "C"
3630void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
3631 size_t datalen)
3632{
3633 int unsolResponseIndex;
3634 int ret;
3635 int64_t timeReceived = 0;
3636 bool shouldScheduleTimeout = false;
3637 RIL_RadioState newState;
3638
3639 if (s_registerCalled == 0) {
3640 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003641 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003642 return;
3643 }
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003644
3645 /* Hack to include Samsung responses */
3646 if (unsolResponse > SAMSUNG_UNSOL_RESPONSE_BASE) {
3647 unsolResponseIndex = unsolResponse - SAMSUNG_UNSOL_RESPONSE_BASE + MAX_RIL_UNSOL - RIL_UNSOL_RESPONSE_BASE;
3648 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, unsolResponseIndex);
3649 } else {
3650 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
3651 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003652
3653 if ((unsolResponseIndex < 0)
3654 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003655 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003656 return;
3657 }
3658
3659 // Grab a wake lock if needed for this reponse,
3660 // as we exit we'll either release it immediately
3661 // or set a timer to release it later.
3662 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
3663 case WAKE_PARTIAL:
3664 grabPartialWakeLock();
3665 shouldScheduleTimeout = true;
3666 break;
3667
3668 case DONT_WAKE:
3669 default:
3670 // No wake lock is grabed so don't set timeout
3671 shouldScheduleTimeout = false;
3672 break;
3673 }
3674
3675 // Mark the time this was received, doing this
3676 // after grabing the wakelock incase getting
3677 // the elapsedRealTime might cause us to goto
3678 // sleep.
3679 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3680 timeReceived = elapsedRealtime();
3681 }
3682
3683 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
3684
3685 Parcel p;
3686
3687 p.writeInt32 (RESPONSE_UNSOLICITED);
3688 p.writeInt32 (unsolResponse);
3689
3690 ret = s_unsolResponses[unsolResponseIndex]
3691 .responseFunction(p, data, datalen);
3692 if (ret != 0) {
3693 // Problem with the response. Don't continue;
3694 goto error_exit;
3695 }
3696
3697 // some things get more payload
3698 switch(unsolResponse) {
3699 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
3700 newState = processRadioState(s_callbacks.onStateRequest());
3701 p.writeInt32(newState);
3702 appendPrintBuf("%s {%s}", printBuf,
3703 radioStateToString(s_callbacks.onStateRequest()));
3704 break;
3705
3706
3707 case RIL_UNSOL_NITZ_TIME_RECEIVED:
3708 // Store the time that this was received so the
3709 // handler of this message can account for
3710 // the time it takes to arrive and process. In
3711 // particular the system has been known to sleep
3712 // before this message can be processed.
3713 p.writeInt64(timeReceived);
3714 break;
3715 }
3716
3717 ret = sendResponse(p);
3718 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3719
3720 // Unfortunately, NITZ time is not poll/update like everything
3721 // else in the system. So, if the upstream client isn't connected,
3722 // keep a copy of the last NITZ response (with receive time noted
3723 // above) around so we can deliver it when it is connected
3724
3725 if (s_lastNITZTimeData != NULL) {
3726 free (s_lastNITZTimeData);
3727 s_lastNITZTimeData = NULL;
3728 }
3729
3730 s_lastNITZTimeData = malloc(p.dataSize());
3731 s_lastNITZTimeDataSize = p.dataSize();
3732 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
3733 }
3734
3735 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
3736 // FIXME The java code should handshake here to release wake lock
3737
3738 if (shouldScheduleTimeout) {
3739 // Cancel the previous request
3740 if (s_last_wake_timeout_info != NULL) {
3741 s_last_wake_timeout_info->userParam = (void *)1;
3742 }
3743
3744 s_last_wake_timeout_info
3745 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
3746 &TIMEVAL_WAKE_TIMEOUT);
3747 }
3748
3749 // Normal exit
3750 return;
3751
3752error_exit:
3753 if (shouldScheduleTimeout) {
3754 releaseWakeLock();
3755 }
3756}
3757
3758/** FIXME generalize this if you track UserCAllbackInfo, clear it
3759 when the callback occurs
3760*/
3761static UserCallbackInfo *
3762internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
3763 const struct timeval *relativeTime)
3764{
3765 struct timeval myRelativeTime;
3766 UserCallbackInfo *p_info;
3767
3768 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
3769
3770 p_info->p_callback = callback;
3771 p_info->userParam = param;
3772
3773 if (relativeTime == NULL) {
3774 /* treat null parameter as a 0 relative time */
3775 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
3776 } else {
3777 /* FIXME I think event_add's tv param is really const anyway */
3778 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
3779 }
3780
3781 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
3782
3783 ril_timer_add(&(p_info->event), &myRelativeTime);
3784
3785 triggerEvLoop();
3786 return p_info;
3787}
3788
3789
3790extern "C" void
3791RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
3792 const struct timeval *relativeTime) {
3793 internalRequestTimedCallback (callback, param, relativeTime);
3794}
3795
3796const char *
3797failCauseToString(RIL_Errno e) {
3798 switch(e) {
3799 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003800 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003801 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
3802 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
3803 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
3804 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
3805 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
3806 case RIL_E_CANCELLED: return "E_CANCELLED";
3807 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
3808 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
3809 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
3810 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
3811 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
3812#ifdef FEATURE_MULTIMODE_ANDROID
3813 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
3814 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
3815#endif
3816 default: return "<unknown error>";
3817 }
3818}
3819
3820const char *
3821radioStateToString(RIL_RadioState s) {
3822 switch(s) {
3823 case RADIO_STATE_OFF: return "RADIO_OFF";
3824 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
3825 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
3826 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
3827 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
3828 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
3829 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
3830 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
3831 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
3832 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
3833 case RADIO_STATE_ON:return"RADIO_ON";
3834 default: return "<unknown state>";
3835 }
3836}
3837
3838const char *
3839callStateToString(RIL_CallState s) {
3840 switch(s) {
3841 case RIL_CALL_ACTIVE : return "ACTIVE";
3842 case RIL_CALL_HOLDING: return "HOLDING";
3843 case RIL_CALL_DIALING: return "DIALING";
3844 case RIL_CALL_ALERTING: return "ALERTING";
3845 case RIL_CALL_INCOMING: return "INCOMING";
3846 case RIL_CALL_WAITING: return "WAITING";
3847 default: return "<unknown state>";
3848 }
3849}
3850
3851const char *
3852requestToString(int request) {
3853/*
3854 cat libs/telephony/ril_commands.h \
3855 | egrep "^ *{RIL_" \
3856 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3857
3858
3859 cat libs/telephony/ril_unsol_commands.h \
3860 | egrep "^ *{RIL_" \
3861 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
3862
3863*/
3864 switch(request) {
3865 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3866 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3867 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3868 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3869 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3870 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3871 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3872 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3873 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3874 case RIL_REQUEST_DIAL: return "DIAL";
3875 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
3876 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3877 case RIL_REQUEST_HANGUP: return "HANGUP";
3878 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3879 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3880 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3881 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3882 case RIL_REQUEST_UDUB: return "UDUB";
3883 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3884 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3885 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3886 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3887 case RIL_REQUEST_OPERATOR: return "OPERATOR";
3888 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3889 case RIL_REQUEST_DTMF: return "DTMF";
3890 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3891 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3892 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3893 case RIL_REQUEST_SIM_IO: return "SIM_IO";
3894 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3895 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3896 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3897 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3898 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3899 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3900 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3901 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3902 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3903 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3904 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3905 case RIL_REQUEST_ANSWER: return "ANSWER";
3906 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3907 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3908 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3909 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3910 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3911 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3912 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3913 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3914 case RIL_REQUEST_DTMF_START: return "DTMF_START";
3915 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3916 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3917 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3918 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
3919 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
3920 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
3921 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3922 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3923 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3924 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3925 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3926 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3927 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3928 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3929 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3930 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3931 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
3932 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
3933 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
3934 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
3935 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
3936 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3937 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
3938 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003939 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003940 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
3941 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
3942 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
3943 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
3944 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
3945 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
3946 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
3947 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
3948 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
3949 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
3950 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
3951 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
3952 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
3953 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
3954 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07003955 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003956 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
3957 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
3958 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
3959 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
3960 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
3961 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
3962 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
3963 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
3964 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
3965 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
3966 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
3967 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
3968 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
3969 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003970 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
3971 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05003972 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
3973 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
3974 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003975 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
3976 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
3977 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
3978 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
3979 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
3980 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
3981 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
3982 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
3983 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
3984 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
3985 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
3986 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
3987 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
3988 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
3989 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
3990 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
3991 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
3992 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
3993 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
3994 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
3995 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
3996 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
3997 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
3998 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
3999 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4000 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4001 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
4002 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
4003 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
4004 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
4005 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
4006 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4007 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
4008 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
4009 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07004010 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05004011 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02004012 case RIL_UNSOL_STK_SEND_SMS_RESULT: return "RIL_UNSOL_STK_SEND_SMS_RESULT";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004013 default: return "<unknown request>";
4014 }
4015}
4016
4017} /* namespace android */