blob: aacfb37e0e8abcd70cbed45497b86858d1076b78 [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>
codeworkxafc051f2013-07-27 09:02:14 +020034#include <sys/limits.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020035#include <pwd.h>
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <unistd.h>
42#include <fcntl.h>
43#include <time.h>
44#include <errno.h>
45#include <assert.h>
46#include <ctype.h>
47#include <alloca.h>
48#include <sys/un.h>
49#include <assert.h>
50#include <netinet/in.h>
51#include <cutils/properties.h>
52
53#include <ril_event.h>
54
55namespace android {
56
57#define PHONE_PROCESS "radio"
58
59#define SOCKET_NAME_RIL "rild"
60#define SOCKET_NAME_RIL_DEBUG "rild-debug"
61
62#define ANDROID_WAKE_LOCK_NAME "radio-interface"
63
64
65#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
66
67// match with constant in RIL.java
68#define MAX_COMMAND_BYTES (8 * 1024)
69
70// Basically: memset buffers that the client library
71// shouldn't be using anymore in an attempt to find
72// memory usage issues sooner.
73#define MEMSET_FREED 1
74
75#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
76
77#define MIN(a,b) ((a)<(b) ? (a) : (b))
78
79/* Constants for response types */
80#define RESPONSE_SOLICITED 0
81#define RESPONSE_UNSOLICITED 1
82
83/* Negative values for private RIL errno's */
84#define RIL_ERRNO_INVALID_RESPONSE -1
85
86// request, response, and unsolicited msg print macro
87#define PRINTBUF_SIZE 8096
88
89// Enable RILC log
90#define RILC_LOG 0
91
92#if RILC_LOG
93 #define startRequest sprintf(printBuf, "(")
94 #define closeRequest sprintf(printBuf, "%s)", printBuf)
95 #define printRequest(token, req) \
codeworkxafc051f2013-07-27 09:02:14 +020096 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020097
98 #define startResponse sprintf(printBuf, "%s {", printBuf)
99 #define closeResponse sprintf(printBuf, "%s}", printBuf)
codeworkxafc051f2013-07-27 09:02:14 +0200100 #define printResponse RLOGD("%s", printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200101
102 #define clearPrintBuf printBuf[0] = 0
103 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
104 #define appendPrintBuf(x...) sprintf(printBuf, x)
105#else
106 #define startRequest
107 #define closeRequest
108 #define printRequest(token, req)
109 #define startResponse
110 #define closeResponse
111 #define printResponse
112 #define clearPrintBuf
113 #define removeLastChar
114 #define appendPrintBuf(x...)
115#endif
116
bmork36b50652015-01-03 19:31:26 +0100117#define MAX_RIL_SOL RIL_REQUEST_IMS_SEND_SMS
118#define MAX_RIL_UNSOL RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +0200119
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200120enum WakeType {DONT_WAKE, WAKE_PARTIAL};
121
122typedef struct {
123 int requestNumber;
124 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
125 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
126} CommandInfo;
127
128typedef struct {
129 int requestNumber;
130 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
131 WakeType wakeType;
132} UnsolResponseInfo;
133
134typedef struct RequestInfo {
135 int32_t token; //this is not RIL_Token
136 CommandInfo *pCI;
137 struct RequestInfo *p_next;
138 char cancelled;
139 char local; // responses to local commands do not go back to command process
140} RequestInfo;
141
142typedef struct UserCallbackInfo {
143 RIL_TimedCallback p_callback;
144 void *userParam;
145 struct ril_event event;
146 struct UserCallbackInfo *p_next;
147} UserCallbackInfo;
148
149
150/*******************************************************************/
151
152RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
153static int s_registerCalled = 0;
154
155static pthread_t s_tid_dispatch;
156static pthread_t s_tid_reader;
157static int s_started = 0;
158
159static int s_fdListen = -1;
160static int s_fdCommand = -1;
161static int s_fdDebug = -1;
162
163static int s_fdWakeupRead;
164static int s_fdWakeupWrite;
165
166static struct ril_event s_commands_event;
167static struct ril_event s_wakeupfd_event;
168static struct ril_event s_listen_event;
169static struct ril_event s_wake_timeout_event;
170static struct ril_event s_debug_event;
171
172
173static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
174
175static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
176static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
177static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
178static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
179
180static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
181static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
182
183static RequestInfo *s_pendingRequests = NULL;
184
185static RequestInfo *s_toDispatchHead = NULL;
186static RequestInfo *s_toDispatchTail = NULL;
187
188static UserCallbackInfo *s_last_wake_timeout_info = NULL;
189
190static void *s_lastNITZTimeData = NULL;
191static size_t s_lastNITZTimeDataSize;
192
193#if RILC_LOG
194 static char printBuf[PRINTBUF_SIZE];
195#endif
196
197/*******************************************************************/
198
199static void dispatchVoid (Parcel& p, RequestInfo *pRI);
200static void dispatchString (Parcel& p, RequestInfo *pRI);
201static void dispatchStrings (Parcel& p, RequestInfo *pRI);
202static void dispatchInts (Parcel& p, RequestInfo *pRI);
203static void dispatchDial (Parcel& p, RequestInfo *pRI);
204static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
205static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
206static void dispatchRaw(Parcel& p, RequestInfo *pRI);
207static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
codeworkxafc051f2013-07-27 09:02:14 +0200208static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
209static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500210static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
codeworkxafc051f2013-07-27 09:02:14 +0200211static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200212
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);
codeworkxafc051f2013-07-27 09:02:14 +0200233static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200234static 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);
codeworkxafc051f2013-07-27 09:02:14 +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;
347 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
codeworkxafc051f2013-07-27 09:02:14 +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
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200377 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) {
codeworkxafc051f2013-07-27 09:02:14 +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) &&
390 (request < RIL_REQUEST_GET_CELL_BROADCAST_CONFIG)) ||
391 request > RIL_REQUEST_HANGUP_VT) {
codeworkxafc051f2013-07-27 09:02:14 +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;
404 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
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200422 pRI->pCI->dispatchFunction(p, pRI);
423
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200424 return 0;
425}
426
427static void
428invalidCommandBlock (RequestInfo *pRI) {
codeworkxafc051f2013-07-27 09:02:14 +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
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200650 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 /* Samsung hack */
661 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
662 uusInfo.uusType = (RIL_UUS_Type) 0;
663 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
664 uusInfo.uusData = NULL;
665 uusInfo.uusLength = 0;
666 dial.uusInfo = &uusInfo;
667 } else {
668 int32_t len;
669
670 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
671
672 status = p.readInt32(&t);
673 uusInfo.uusType = (RIL_UUS_Type) t;
674
675 status = p.readInt32(&t);
676 uusInfo.uusDcs = (RIL_UUS_DCS) t;
677
678 status = p.readInt32(&len);
679 if (status != NO_ERROR) {
680 goto invalid;
681 }
682
683 // The java code writes -1 for null arrays
684 if (((int) len) == -1) {
685 uusInfo.uusData = NULL;
686 len = 0;
687 } else {
688 uusInfo.uusData = (char*) p.readInplace(len);
689 }
690
691 uusInfo.uusLength = len;
692 dial.uusInfo = &uusInfo;
693 }
694 sizeOfDial = sizeof(dial);
695 }
696
697 startRequest;
698 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
699 if (uusPresent) {
700 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
701 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
702 dial.uusInfo->uusLength);
703 }
704 closeRequest;
705 printRequest(pRI->token, pRI->pCI->requestNumber);
706
707 s_callbacks.onRequest(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI);
708
709#ifdef MEMSET_FREED
710 memsetString (dial.address);
711#endif
712
713 free (dial.address);
714
715#ifdef MEMSET_FREED
716 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
717 memset(&dial, 0, sizeof(dial));
718#endif
719
720 return;
721invalid:
722 invalidCommandBlock(pRI);
723 return;
724}
725
726/**
727 * Callee expects const RIL_SIM_IO *
728 * Payload is:
729 * int32_t command
730 * int32_t fileid
731 * String path
732 * int32_t p1, p2, p3
733 * String data
734 * String pin2
735 * String aidPtr
736 */
737static void
738dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
codeworkxafc051f2013-07-27 09:02:14 +0200739 union RIL_SIM_IO {
740 RIL_SIM_IO_v6 v6;
741 RIL_SIM_IO_v5 v5;
742 } simIO;
743
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200744 int32_t t;
codeworkxafc051f2013-07-27 09:02:14 +0200745 int size;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200746 status_t status;
747
748 memset (&simIO, 0, sizeof(simIO));
749
750 // note we only check status at the end
751
752 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200753 simIO.v6.command = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200754
755 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200756 simIO.v6.fileid = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200757
codeworkxafc051f2013-07-27 09:02:14 +0200758 simIO.v6.path = strdupReadString(p);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200759
760 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200761 simIO.v6.p1 = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200762
763 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200764 simIO.v6.p2 = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200765
766 status = p.readInt32(&t);
codeworkxafc051f2013-07-27 09:02:14 +0200767 simIO.v6.p3 = (int)t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200768
codeworkxafc051f2013-07-27 09:02:14 +0200769 simIO.v6.data = strdupReadString(p);
770 simIO.v6.pin2 = strdupReadString(p);
771 simIO.v6.aidPtr = strdupReadString(p);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200772
773 startRequest;
774 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
codeworkxafc051f2013-07-27 09:02:14 +0200775 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
776 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
777 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200778 closeRequest;
779 printRequest(pRI->token, pRI->pCI->requestNumber);
780
781 if (status != NO_ERROR) {
782 goto invalid;
783 }
784
codeworkxafc051f2013-07-27 09:02:14 +0200785 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
786 s_callbacks.onRequest(pRI->pCI->requestNumber, &simIO, size, pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200787
788#ifdef MEMSET_FREED
codeworkxafc051f2013-07-27 09:02:14 +0200789 memsetString (simIO.v6.path);
790 memsetString (simIO.v6.data);
791 memsetString (simIO.v6.pin2);
792 memsetString (simIO.v6.aidPtr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200793#endif
794
codeworkxafc051f2013-07-27 09:02:14 +0200795 free (simIO.v6.path);
796 free (simIO.v6.data);
797 free (simIO.v6.pin2);
798 free (simIO.v6.aidPtr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200799
800#ifdef MEMSET_FREED
801 memset(&simIO, 0, sizeof(simIO));
802#endif
803
804 return;
805invalid:
806 invalidCommandBlock(pRI);
807 return;
808}
809
810/**
811 * Callee expects const RIL_CallForwardInfo *
812 * Payload is:
813 * int32_t status/action
814 * int32_t reason
815 * int32_t serviceCode
816 * int32_t toa
817 * String number (0 length -> null)
818 * int32_t timeSeconds
819 */
820static void
821dispatchCallForward(Parcel &p, RequestInfo *pRI) {
822 RIL_CallForwardInfo cff;
823 int32_t t;
824 status_t status;
825
826 memset (&cff, 0, sizeof(cff));
827
828 // note we only check status at the end
829
830 status = p.readInt32(&t);
831 cff.status = (int)t;
832
833 status = p.readInt32(&t);
834 cff.reason = (int)t;
835
836 status = p.readInt32(&t);
837 cff.serviceClass = (int)t;
838
839 status = p.readInt32(&t);
840 cff.toa = (int)t;
841
842 cff.number = strdupReadString(p);
843
844 status = p.readInt32(&t);
845 cff.timeSeconds = (int)t;
846
847 if (status != NO_ERROR) {
848 goto invalid;
849 }
850
851 // special case: number 0-length fields is null
852
853 if (cff.number != NULL && strlen (cff.number) == 0) {
854 cff.number = NULL;
855 }
856
857 startRequest;
858 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
859 cff.status, cff.reason, cff.serviceClass, cff.toa,
860 (char*)cff.number, cff.timeSeconds);
861 closeRequest;
862 printRequest(pRI->token, pRI->pCI->requestNumber);
863
864 s_callbacks.onRequest(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI);
865
866#ifdef MEMSET_FREED
867 memsetString(cff.number);
868#endif
869
870 free (cff.number);
871
872#ifdef MEMSET_FREED
873 memset(&cff, 0, sizeof(cff));
874#endif
875
876 return;
877invalid:
878 invalidCommandBlock(pRI);
879 return;
880}
881
882
883static void
884dispatchRaw(Parcel &p, RequestInfo *pRI) {
885 int32_t len;
886 status_t status;
887 const void *data;
888
889 status = p.readInt32(&len);
890
891 if (status != NO_ERROR) {
892 goto invalid;
893 }
894
895 // The java code writes -1 for null arrays
896 if (((int)len) == -1) {
897 data = NULL;
898 len = 0;
899 }
900
901 data = p.readInplace(len);
902
903 startRequest;
904 appendPrintBuf("%sraw_size=%d", printBuf, len);
905 closeRequest;
906 printRequest(pRI->token, pRI->pCI->requestNumber);
907
908 s_callbacks.onRequest(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI);
909
910 return;
911invalid:
912 invalidCommandBlock(pRI);
913 return;
914}
915
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500916static status_t
917constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200918 int32_t t;
919 uint8_t ut;
920 status_t status;
921 int32_t digitCount;
922 int digitLimit;
923
924 memset(&rcsm, 0, sizeof(rcsm));
925
926 status = p.readInt32(&t);
927 rcsm.uTeleserviceID = (int) t;
928
929 status = p.read(&ut,sizeof(ut));
930 rcsm.bIsServicePresent = (uint8_t) ut;
931
932 status = p.readInt32(&t);
933 rcsm.uServicecategory = (int) t;
934
935 status = p.readInt32(&t);
936 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
937
938 status = p.readInt32(&t);
939 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
940
941 status = p.readInt32(&t);
942 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
943
944 status = p.readInt32(&t);
945 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
946
947 status = p.read(&ut,sizeof(ut));
948 rcsm.sAddress.number_of_digits= (uint8_t) ut;
949
950 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
951 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
952 status = p.read(&ut,sizeof(ut));
953 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
954 }
955
956 status = p.readInt32(&t);
957 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
958
959 status = p.read(&ut,sizeof(ut));
960 rcsm.sSubAddress.odd = (uint8_t) ut;
961
962 status = p.read(&ut,sizeof(ut));
963 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
964
965 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
966 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
967 status = p.read(&ut,sizeof(ut));
968 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
969 }
970
971 status = p.readInt32(&t);
972 rcsm.uBearerDataLen = (int) t;
973
974 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
975 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
976 status = p.read(&ut, sizeof(ut));
977 rcsm.aBearerData[digitCount] = (uint8_t) ut;
978 }
979
980 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500981 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200982 }
983
984 startRequest;
985 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
986 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
987 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
988 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
989 closeRequest;
990
991 printRequest(pRI->token, pRI->pCI->requestNumber);
992
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500993 return status;
994}
995
996static void
997dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
998 RIL_CDMA_SMS_Message rcsm;
999
1000 ALOGD("dispatchCdmaSms");
1001 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1002 goto invalid;
1003 }
1004
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001005 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI);
1006
1007#ifdef MEMSET_FREED
1008 memset(&rcsm, 0, sizeof(rcsm));
1009#endif
1010
1011 return;
1012
1013invalid:
1014 invalidCommandBlock(pRI);
1015 return;
1016}
1017
1018static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001019dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1020 RIL_IMS_SMS_Message rism;
1021 RIL_CDMA_SMS_Message rcsm;
1022
1023 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1024
1025 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1026 goto invalid;
1027 }
1028 memset(&rism, 0, sizeof(rism));
1029 rism.tech = RADIO_TECH_3GPP2;
1030 rism.retry = retry;
1031 rism.messageRef = messageRef;
1032 rism.message.cdmaMessage = &rcsm;
1033
1034 s_callbacks.onRequest(pRI->pCI->requestNumber, &rism,
1035 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1036 +sizeof(rcsm),pRI);
1037
1038#ifdef MEMSET_FREED
1039 memset(&rcsm, 0, sizeof(rcsm));
1040 memset(&rism, 0, sizeof(rism));
1041#endif
1042
1043 return;
1044
1045invalid:
1046 invalidCommandBlock(pRI);
1047 return;
1048}
1049
1050static void
1051dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1052 RIL_IMS_SMS_Message rism;
1053 int32_t countStrings;
1054 status_t status;
1055 size_t datalen;
1056 char **pStrings;
1057 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1058
1059 status = p.readInt32 (&countStrings);
1060
1061 if (status != NO_ERROR) {
1062 goto invalid;
1063 }
1064
1065 memset(&rism, 0, sizeof(rism));
1066 rism.tech = RADIO_TECH_3GPP;
1067 rism.retry = retry;
1068 rism.messageRef = messageRef;
1069
1070 startRequest;
1071 appendPrintBuf("%sformat=%d,", printBuf, rism.format);
1072 if (countStrings == 0) {
1073 // just some non-null pointer
1074 pStrings = (char **)alloca(sizeof(char *));
1075 datalen = 0;
1076 } else if (((int)countStrings) == -1) {
1077 pStrings = NULL;
1078 datalen = 0;
1079 } else {
1080 datalen = sizeof(char *) * countStrings;
1081
1082 pStrings = (char **)alloca(datalen);
1083
1084 for (int i = 0 ; i < countStrings ; i++) {
1085 pStrings[i] = strdupReadString(p);
1086 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1087 }
1088 }
1089 removeLastChar;
1090 closeRequest;
1091 printRequest(pRI->token, pRI->pCI->requestNumber);
1092
1093 rism.message.gsmMessage = pStrings;
1094 s_callbacks.onRequest(pRI->pCI->requestNumber, &rism,
1095 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
1096 +datalen, pRI);
1097
1098 if (pStrings != NULL) {
1099 for (int i = 0 ; i < countStrings ; i++) {
1100#ifdef MEMSET_FREED
1101 memsetString (pStrings[i]);
1102#endif
1103 free(pStrings[i]);
1104 }
1105
1106#ifdef MEMSET_FREED
1107 memset(pStrings, 0, datalen);
1108#endif
1109 }
1110
1111#ifdef MEMSET_FREED
1112 memset(&rism, 0, sizeof(rism));
1113#endif
1114 return;
1115invalid:
1116 ALOGE("dispatchImsGsmSms invalid block");
1117 invalidCommandBlock(pRI);
1118 return;
1119}
1120
1121static void
1122dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1123 int32_t t;
1124 status_t status = p.readInt32(&t);
1125 RIL_RadioTechnologyFamily format;
1126 uint8_t retry;
1127 int32_t messageRef;
1128
1129 ALOGD("dispatchImsSms");
1130 if (status != NO_ERROR) {
1131 goto invalid;
1132 }
1133 format = (RIL_RadioTechnologyFamily) t;
1134
1135 // read retry field
1136 status = p.read(&retry,sizeof(retry));
1137 if (status != NO_ERROR) {
1138 goto invalid;
1139 }
1140 // read messageRef field
1141 status = p.read(&messageRef,sizeof(messageRef));
1142 if (status != NO_ERROR) {
1143 goto invalid;
1144 }
1145
1146 if (RADIO_TECH_3GPP == format) {
1147 dispatchImsGsmSms(p, pRI, retry, messageRef);
1148 } else if (RADIO_TECH_3GPP2 == format) {
1149 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1150 } else {
1151 ALOGE("requestImsSendSMS invalid format value =%d", format);
1152 }
1153
1154 return;
1155
1156invalid:
1157 invalidCommandBlock(pRI);
1158 return;
1159}
1160
1161static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001162dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1163 RIL_CDMA_SMS_Ack rcsa;
1164 int32_t t;
1165 status_t status;
1166 int32_t digitCount;
1167
1168 memset(&rcsa, 0, sizeof(rcsa));
1169
1170 status = p.readInt32(&t);
1171 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1172
1173 status = p.readInt32(&t);
1174 rcsa.uSMSCauseCode = (int) t;
1175
1176 if (status != NO_ERROR) {
1177 goto invalid;
1178 }
1179
1180 startRequest;
1181 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1182 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1183 closeRequest;
1184
1185 printRequest(pRI->token, pRI->pCI->requestNumber);
1186
1187 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI);
1188
1189#ifdef MEMSET_FREED
1190 memset(&rcsa, 0, sizeof(rcsa));
1191#endif
1192
1193 return;
1194
1195invalid:
1196 invalidCommandBlock(pRI);
1197 return;
1198}
1199
1200static void
1201dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1202 int32_t t;
1203 status_t status;
1204 int32_t num;
1205
1206 status = p.readInt32(&num);
1207 if (status != NO_ERROR) {
1208 goto invalid;
1209 }
1210
codeworkxafc051f2013-07-27 09:02:14 +02001211 {
1212 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1213 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001214
codeworkxafc051f2013-07-27 09:02:14 +02001215 startRequest;
1216 for (int i = 0 ; i < num ; i++ ) {
1217 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001218
codeworkxafc051f2013-07-27 09:02:14 +02001219 status = p.readInt32(&t);
1220 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001221
codeworkxafc051f2013-07-27 09:02:14 +02001222 status = p.readInt32(&t);
1223 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001224
codeworkxafc051f2013-07-27 09:02:14 +02001225 status = p.readInt32(&t);
1226 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001227
codeworkxafc051f2013-07-27 09:02:14 +02001228 status = p.readInt32(&t);
1229 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001230
codeworkxafc051f2013-07-27 09:02:14 +02001231 status = p.readInt32(&t);
1232 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001233
codeworkxafc051f2013-07-27 09:02:14 +02001234 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1235 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1236 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1237 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1238 gsmBci[i].selected);
1239 }
1240 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001241
codeworkxafc051f2013-07-27 09:02:14 +02001242 if (status != NO_ERROR) {
1243 goto invalid;
1244 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001245
codeworkxafc051f2013-07-27 09:02:14 +02001246 s_callbacks.onRequest(pRI->pCI->requestNumber,
1247 gsmBciPtrs,
1248 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
1249 pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001250
1251#ifdef MEMSET_FREED
codeworkxafc051f2013-07-27 09:02:14 +02001252 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1253 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001254#endif
codeworkxafc051f2013-07-27 09:02:14 +02001255 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001256
1257 return;
1258
1259invalid:
1260 invalidCommandBlock(pRI);
1261 return;
1262}
1263
1264static void
1265dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1266 int32_t t;
1267 status_t status;
1268 int32_t num;
1269
1270 status = p.readInt32(&num);
1271 if (status != NO_ERROR) {
1272 goto invalid;
1273 }
1274
codeworkxafc051f2013-07-27 09:02:14 +02001275 {
1276 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1277 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001278
codeworkxafc051f2013-07-27 09:02:14 +02001279 startRequest;
1280 for (int i = 0 ; i < num ; i++ ) {
1281 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001282
codeworkxafc051f2013-07-27 09:02:14 +02001283 status = p.readInt32(&t);
1284 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001285
codeworkxafc051f2013-07-27 09:02:14 +02001286 status = p.readInt32(&t);
1287 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001288
codeworkxafc051f2013-07-27 09:02:14 +02001289 status = p.readInt32(&t);
1290 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001291
codeworkxafc051f2013-07-27 09:02:14 +02001292 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1293 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1294 cdmaBci[i].language, cdmaBci[i].selected);
1295 }
1296 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001297
codeworkxafc051f2013-07-27 09:02:14 +02001298 if (status != NO_ERROR) {
1299 goto invalid;
1300 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001301
codeworkxafc051f2013-07-27 09:02:14 +02001302 s_callbacks.onRequest(pRI->pCI->requestNumber,
1303 cdmaBciPtrs,
1304 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
1305 pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001306
1307#ifdef MEMSET_FREED
codeworkxafc051f2013-07-27 09:02:14 +02001308 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1309 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001310#endif
codeworkxafc051f2013-07-27 09:02:14 +02001311 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001312
1313 return;
1314
1315invalid:
1316 invalidCommandBlock(pRI);
1317 return;
1318}
1319
1320static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1321 RIL_CDMA_SMS_WriteArgs rcsw;
1322 int32_t t;
1323 uint32_t ut;
1324 uint8_t uct;
1325 status_t status;
1326 int32_t digitCount;
1327
1328 memset(&rcsw, 0, sizeof(rcsw));
1329
1330 status = p.readInt32(&t);
1331 rcsw.status = t;
1332
1333 status = p.readInt32(&t);
1334 rcsw.message.uTeleserviceID = (int) t;
1335
1336 status = p.read(&uct,sizeof(uct));
1337 rcsw.message.bIsServicePresent = (uint8_t) uct;
1338
1339 status = p.readInt32(&t);
1340 rcsw.message.uServicecategory = (int) t;
1341
1342 status = p.readInt32(&t);
1343 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1344
1345 status = p.readInt32(&t);
1346 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1347
1348 status = p.readInt32(&t);
1349 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1350
1351 status = p.readInt32(&t);
1352 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1353
1354 status = p.read(&uct,sizeof(uct));
1355 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1356
1357 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1358 status = p.read(&uct,sizeof(uct));
1359 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1360 }
1361
1362 status = p.readInt32(&t);
1363 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1364
1365 status = p.read(&uct,sizeof(uct));
1366 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1367
1368 status = p.read(&uct,sizeof(uct));
1369 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1370
1371 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1372 status = p.read(&uct,sizeof(uct));
1373 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1374 }
1375
1376 status = p.readInt32(&t);
1377 rcsw.message.uBearerDataLen = (int) t;
1378
1379 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1380 status = p.read(&uct, sizeof(uct));
1381 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1382 }
1383
1384 if (status != NO_ERROR) {
1385 goto invalid;
1386 }
1387
1388 startRequest;
1389 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1390 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1391 message.sAddress.number_mode=%d, \
1392 message.sAddress.number_type=%d, ",
1393 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1394 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1395 rcsw.message.sAddress.number_mode,
1396 rcsw.message.sAddress.number_type);
1397 closeRequest;
1398
1399 printRequest(pRI->token, pRI->pCI->requestNumber);
1400
1401 s_callbacks.onRequest(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI);
1402
1403#ifdef MEMSET_FREED
1404 memset(&rcsw, 0, sizeof(rcsw));
1405#endif
1406
1407 return;
1408
1409invalid:
1410 invalidCommandBlock(pRI);
1411 return;
1412
1413}
1414
codeworkxafc051f2013-07-27 09:02:14 +02001415// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1416// Version 4 of the RIL interface adds a new PDP type parameter to support
1417// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1418// RIL, remove the parameter from the request.
1419static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1420 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1421 const int numParamsRilV3 = 6;
1422
1423 // The first bytes of the RIL parcel contain the request number and the
1424 // serial number - see processCommandBuffer(). Copy them over too.
1425 int pos = p.dataPosition();
1426
1427 int numParams = p.readInt32();
1428 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1429 Parcel p2;
1430 p2.appendFrom(&p, 0, pos);
1431 p2.writeInt32(numParamsRilV3);
1432 for(int i = 0; i < numParamsRilV3; i++) {
1433 p2.writeString16(p.readString16());
1434 }
1435 p2.setDataPosition(pos);
1436 dispatchStrings(p2, pRI);
1437 } else {
1438 p.setDataPosition(pos);
1439 dispatchStrings(p, pRI);
1440 }
1441}
1442
1443// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1444// When all RILs handle this request, this function can be removed and
1445// the request can be sent directly to the RIL using dispatchVoid.
1446static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
1447 RIL_RadioState state = s_callbacks.onStateRequest();
1448
1449 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1450 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1451 }
1452
1453 // RILs that support RADIO_STATE_ON should support this request.
1454 if (RADIO_STATE_ON == state) {
1455 dispatchVoid(p, pRI);
1456 return;
1457 }
1458
1459 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1460 // will not support this new request either and decode Voice Radio Technology
1461 // from Radio State
1462 voiceRadioTech = decodeVoiceRadioTechnology(state);
1463
1464 if (voiceRadioTech < 0)
1465 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1466 else
1467 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1468}
1469
1470// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1471// When all RILs handle this request, this function can be removed and
1472// the request can be sent directly to the RIL using dispatchVoid.
1473static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
1474 RIL_RadioState state = s_callbacks.onStateRequest();
1475
1476 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1477 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1478 }
1479
1480 // RILs that support RADIO_STATE_ON should support this request.
1481 if (RADIO_STATE_ON == state) {
1482 dispatchVoid(p, pRI);
1483 return;
1484 }
1485
1486 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1487 // will not support this new request either and decode CDMA Subscription Source
1488 // from Radio State
1489 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1490
1491 if (cdmaSubscriptionSource < 0)
1492 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1493 else
1494 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1495}
1496
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001497static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1498{
1499 RIL_InitialAttachApn pf;
1500 int32_t t;
1501 status_t status;
1502
1503 memset(&pf, 0, sizeof(pf));
1504
1505 pf.apn = strdupReadString(p);
1506 pf.protocol = strdupReadString(p);
1507
1508 status = p.readInt32(&t);
1509 pf.authtype = (int) t;
1510
1511 pf.username = strdupReadString(p);
1512 pf.password = strdupReadString(p);
1513
1514 startRequest;
1515 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
1516 printBuf, pf.apn, pf.protocol, pf.auth_type, pf.username, pf.password);
1517 closeRequest;
1518 printRequest(pRI->token, pRI->pCI->requestNumber);
1519
1520 if (status != NO_ERROR) {
1521 goto invalid;
1522 }
1523 s_callbacks.onRequest(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI);
1524
1525#ifdef MEMSET_FREED
1526 memsetString(pf.apn);
1527 memsetString(pf.protocol);
1528 memsetString(pf.username);
1529 memsetString(pf.password);
1530#endif
1531
1532 free(pf.apn);
1533 free(pf.protocol);
1534 free(pf.username);
1535 free(pf.password);
1536
1537#ifdef MEMSET_FREED
1538 memset(&pf, 0, sizeof(pf));
1539#endif
1540
1541 return;
1542invalid:
1543 invalidCommandBlock(pRI);
1544 return;
1545}
1546
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001547static int
1548blockingWrite(int fd, const void *buffer, size_t len) {
1549 size_t writeOffset = 0;
1550 const uint8_t *toWrite;
1551
1552 toWrite = (const uint8_t *)buffer;
1553
1554 while (writeOffset < len) {
1555 ssize_t written;
1556 do {
1557 written = write (fd, toWrite + writeOffset,
1558 len - writeOffset);
codeworkxafc051f2013-07-27 09:02:14 +02001559 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001560
1561 if (written >= 0) {
1562 writeOffset += written;
1563 } else { // written < 0
codeworkxafc051f2013-07-27 09:02:14 +02001564 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001565 close(fd);
1566 return -1;
1567 }
1568 }
1569
1570 return 0;
1571}
1572
1573static int
1574sendResponseRaw (const void *data, size_t dataSize) {
1575 int fd = s_fdCommand;
1576 int ret;
1577 uint32_t header;
1578
1579 if (s_fdCommand < 0) {
1580 return -1;
1581 }
1582
1583 if (dataSize > MAX_COMMAND_BYTES) {
codeworkxafc051f2013-07-27 09:02:14 +02001584 RLOGE("RIL: packet larger than %u (%u)",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001585 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1586
1587 return -1;
1588 }
1589
1590 pthread_mutex_lock(&s_writeMutex);
1591
1592 header = htonl(dataSize);
1593
1594 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1595
1596 if (ret < 0) {
1597 pthread_mutex_unlock(&s_writeMutex);
1598 return ret;
1599 }
1600
1601 ret = blockingWrite(fd, data, dataSize);
1602
1603 if (ret < 0) {
1604 pthread_mutex_unlock(&s_writeMutex);
1605 return ret;
1606 }
1607
1608 pthread_mutex_unlock(&s_writeMutex);
1609
1610 return 0;
1611}
1612
1613static int
1614sendResponse (Parcel &p) {
1615 printResponse;
1616 return sendResponseRaw(p.data(), p.dataSize());
1617}
1618
1619/** response is an int* pointing to an array of ints*/
1620
1621static int
1622responseInts(Parcel &p, void *response, size_t responselen) {
1623 int numInts;
1624
1625 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001626 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001627 return RIL_ERRNO_INVALID_RESPONSE;
1628 }
1629 if (responselen % sizeof(int) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001630 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001631 (int)responselen, (int)sizeof(int));
1632 return RIL_ERRNO_INVALID_RESPONSE;
1633 }
1634
1635 int *p_int = (int *) response;
1636
1637 numInts = responselen / sizeof(int *);
1638 p.writeInt32 (numInts);
1639
1640 /* each int*/
1641 startResponse;
1642 for (int i = 0 ; i < numInts ; i++) {
1643 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1644 p.writeInt32(p_int[i]);
1645 }
1646 removeLastChar;
1647 closeResponse;
1648
1649 return 0;
1650}
1651
1652static int
1653responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
1654 int numInts;
1655
1656 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001657 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001658 return RIL_ERRNO_INVALID_RESPONSE;
1659 }
1660 if (responselen % sizeof(int) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001661 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001662 (int)responselen, (int)sizeof(int));
1663 return RIL_ERRNO_INVALID_RESPONSE;
1664 }
1665
1666 int *p_int = (int *) response;
1667
1668 numInts = responselen / sizeof(int *);
1669 p.writeInt32 (numInts);
1670
1671 /* each int*/
1672 startResponse;
1673 for (int i = 0 ; i < numInts ; i++) {
1674 if (i == 0 && p_int[0] == 7) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02001675 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001676 p_int[0] = 0;
1677 }
1678 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1679 p.writeInt32(p_int[i]);
1680 }
1681 removeLastChar;
1682 closeResponse;
1683
1684 return 0;
1685}
1686
1687/** response is a char **, pointing to an array of char *'s
1688 The parcel will begin with the version */
1689static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1690 p.writeInt32(version);
1691 return responseStrings(p, response, responselen);
1692}
1693
1694/** response is a char **, pointing to an array of char *'s */
1695static int responseStrings(Parcel &p, void *response, size_t responselen) {
1696 return responseStrings(p, response, responselen, false);
1697}
1698
1699static int responseStringsNetworks(Parcel &p, void *response, size_t responselen) {
1700 int numStrings;
1701 int inQANElements = 5;
1702 int outQANElements = 4;
1703
1704 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001705 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001706 return RIL_ERRNO_INVALID_RESPONSE;
1707 }
1708 if (responselen % sizeof(char *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001709 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001710 (int)responselen, (int)sizeof(char *));
1711 return RIL_ERRNO_INVALID_RESPONSE;
1712 }
1713
1714 if (response == NULL) {
1715 p.writeInt32 (0);
1716 } else {
1717 char **p_cur = (char **) response;
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02001718 int j = 0;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001719
1720 numStrings = responselen / sizeof(char *);
1721 p.writeInt32 ((numStrings / inQANElements) * outQANElements);
1722
1723 /* each string*/
1724 startResponse;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001725 for (int i = 0 ; i < numStrings ; i++) {
1726 /* Samsung is sending 5 elements, upper layer expects 4.
1727 Drop every 5th element here */
1728 if (j == outQANElements) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02001729 j = 0;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001730 } else {
1731 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1732 writeStringToParcel (p, p_cur[i]);
1733 j++;
1734 }
1735 }
1736 removeLastChar;
1737 closeResponse;
1738 }
1739 return 0;
1740}
1741
1742/** response is a char **, pointing to an array of char *'s */
1743static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
1744 int numStrings;
1745
1746 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001747 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001748 return RIL_ERRNO_INVALID_RESPONSE;
1749 }
1750 if (responselen % sizeof(char *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001751 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001752 (int)responselen, (int)sizeof(char *));
1753 return RIL_ERRNO_INVALID_RESPONSE;
1754 }
1755
1756 if (response == NULL) {
1757 p.writeInt32 (0);
1758 } else {
1759 char **p_cur = (char **) response;
1760
1761 numStrings = responselen / sizeof(char *);
1762 p.writeInt32 (numStrings);
1763
1764 /* each string*/
1765 startResponse;
1766 for (int i = 0 ; i < numStrings ; i++) {
1767 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1768 writeStringToParcel (p, p_cur[i]);
1769 }
1770 removeLastChar;
1771 closeResponse;
1772 }
1773 return 0;
1774}
1775
1776/**
1777 * NULL strings are accepted
1778 * FIXME currently ignores responselen
1779 */
1780static int responseString(Parcel &p, void *response, size_t responselen) {
1781 /* one string only */
1782 startResponse;
1783 appendPrintBuf("%s%s", printBuf, (char*)response);
1784 closeResponse;
1785
1786 writeStringToParcel(p, (const char *)response);
1787
1788 return 0;
1789}
1790
1791static int responseVoid(Parcel &p, void *response, size_t responselen) {
1792 startResponse;
1793 removeLastChar;
1794 return 0;
1795}
1796
1797static int responseCallList(Parcel &p, void *response, size_t responselen) {
1798 int num;
1799
1800 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001801 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001802 return RIL_ERRNO_INVALID_RESPONSE;
1803 }
1804
1805 if (responselen % sizeof (RIL_Call *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001806 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001807 (int)responselen, (int)sizeof (RIL_Call *));
1808 return RIL_ERRNO_INVALID_RESPONSE;
1809 }
1810
1811 startResponse;
1812 /* number of call info's */
1813 num = responselen / sizeof(RIL_Call *);
1814 p.writeInt32(num);
1815
1816 for (int i = 0 ; i < num ; i++) {
1817 RIL_Call *p_cur = ((RIL_Call **) response)[i];
1818 /* each call info */
1819 p.writeInt32(p_cur->state);
1820 p.writeInt32(p_cur->index);
1821 p.writeInt32(p_cur->toa);
1822 p.writeInt32(p_cur->isMpty);
1823 p.writeInt32(p_cur->isMT);
1824 p.writeInt32(p_cur->als);
1825 p.writeInt32(p_cur->isVoice);
1826 p.writeInt32(p_cur->isVoicePrivacy);
1827 writeStringToParcel(p, p_cur->number);
1828 p.writeInt32(p_cur->numberPresentation);
1829 writeStringToParcel(p, p_cur->name);
1830 p.writeInt32(p_cur->namePresentation);
Daniel Hillenbrandea4af612013-07-09 18:47:06 +02001831 // Remove when partners upgrade to version 3
1832 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
1833 p.writeInt32(0); /* UUS Information is absent */
1834 } else {
1835 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
1836 p.writeInt32(1); /* UUS Information is present */
1837 p.writeInt32(uusInfo->uusType);
1838 p.writeInt32(uusInfo->uusDcs);
1839 p.writeInt32(uusInfo->uusLength);
1840 p.write(uusInfo->uusData, uusInfo->uusLength);
1841 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001842 appendPrintBuf("%s[id=%d,%s,toa=%d,",
1843 printBuf,
1844 p_cur->index,
1845 callStateToString(p_cur->state),
1846 p_cur->toa);
1847 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
1848 printBuf,
1849 (p_cur->isMpty)?"conf":"norm",
1850 (p_cur->isMT)?"mt":"mo",
1851 p_cur->als,
1852 (p_cur->isVoice)?"voc":"nonvoc",
1853 (p_cur->isVoicePrivacy)?"evp":"noevp");
1854 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
1855 printBuf,
1856 p_cur->number,
1857 p_cur->numberPresentation,
1858 p_cur->name,
1859 p_cur->namePresentation);
1860 }
1861 removeLastChar;
1862 closeResponse;
1863
1864 return 0;
1865}
1866
1867static int responseSMS(Parcel &p, void *response, size_t responselen) {
1868 if (response == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02001869 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001870 return RIL_ERRNO_INVALID_RESPONSE;
1871 }
1872
1873 if (responselen != sizeof (RIL_SMS_Response) ) {
codeworkxafc051f2013-07-27 09:02:14 +02001874 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001875 (int)responselen, (int)sizeof (RIL_SMS_Response));
1876 return RIL_ERRNO_INVALID_RESPONSE;
1877 }
1878
1879 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
1880
1881 p.writeInt32(p_cur->messageRef);
1882 writeStringToParcel(p, p_cur->ackPDU);
1883 p.writeInt32(p_cur->errorCode);
1884
1885 startResponse;
1886 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
1887 (char*)p_cur->ackPDU, p_cur->errorCode);
1888 closeResponse;
1889
1890 return 0;
1891}
1892
codeworkxafc051f2013-07-27 09:02:14 +02001893static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001894{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001895 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001896 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001897 return RIL_ERRNO_INVALID_RESPONSE;
1898 }
1899
codeworkxafc051f2013-07-27 09:02:14 +02001900 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
1901 RLOGE("invalid response length %d expected multiple of %d",
1902 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001903 return RIL_ERRNO_INVALID_RESPONSE;
1904 }
1905
codeworkxafc051f2013-07-27 09:02:14 +02001906 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001907 p.writeInt32(num);
1908
codeworkxafc051f2013-07-27 09:02:14 +02001909 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001910 startResponse;
codeworkxafc051f2013-07-27 09:02:14 +02001911 int i;
1912 for (i = 0; i < num; i++) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001913 p.writeInt32(p_cur[i].cid);
1914 p.writeInt32(p_cur[i].active);
1915 writeStringToParcel(p, p_cur[i].type);
codeworkxafc051f2013-07-27 09:02:14 +02001916 // apn is not used, so don't send.
1917 writeStringToParcel(p, p_cur[i].address);
1918 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001919 p_cur[i].cid,
1920 (p_cur[i].active==0)?"down":"up",
1921 (char*)p_cur[i].type,
codeworkxafc051f2013-07-27 09:02:14 +02001922 (char*)p_cur[i].address);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001923 }
1924 removeLastChar;
1925 closeResponse;
1926
1927 return 0;
1928}
1929
codeworkxafc051f2013-07-27 09:02:14 +02001930static int responseDataCallList(Parcel &p, void *response, size_t responselen)
1931{
1932 // Write version
1933 p.writeInt32(s_callbacks.version);
1934
1935 if (s_callbacks.version < 5) {
1936 return responseDataCallListV4(p, response, responselen);
1937 } else {
1938 if (response == NULL && responselen != 0) {
1939 RLOGE("invalid response: NULL");
1940 return RIL_ERRNO_INVALID_RESPONSE;
1941 }
1942
1943 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
1944 RLOGE("invalid response length %d expected multiple of %d",
1945 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
1946 return RIL_ERRNO_INVALID_RESPONSE;
1947 }
1948
1949 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
1950 p.writeInt32(num);
1951
1952 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
1953 startResponse;
1954 int i;
1955 for (i = 0; i < num; i++) {
1956 p.writeInt32((int)p_cur[i].status);
1957 p.writeInt32(p_cur[i].suggestedRetryTime);
1958 p.writeInt32(p_cur[i].cid);
1959 p.writeInt32(p_cur[i].active);
1960 writeStringToParcel(p, p_cur[i].type);
1961 writeStringToParcel(p, p_cur[i].ifname);
1962 writeStringToParcel(p, p_cur[i].addresses);
1963 writeStringToParcel(p, p_cur[i].dnses);
Howard Sucbf8e0a2015-01-04 10:33:32 +01001964 writeStringToParcel(p, p_cur[i].addresses);
codeworkxafc051f2013-07-27 09:02:14 +02001965 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
1966 p_cur[i].status,
1967 p_cur[i].suggestedRetryTime,
1968 p_cur[i].cid,
1969 (p_cur[i].active==0)?"down":"up",
1970 (char*)p_cur[i].type,
1971 (char*)p_cur[i].ifname,
1972 (char*)p_cur[i].addresses,
1973 (char*)p_cur[i].dnses,
Howard Sucbf8e0a2015-01-04 10:33:32 +01001974 (char*)p_cur[i].addresses);
codeworkxafc051f2013-07-27 09:02:14 +02001975 }
1976 removeLastChar;
1977 closeResponse;
1978 }
1979
1980 return 0;
1981}
1982
1983static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
1984{
1985 if (s_callbacks.version < 5) {
1986 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
1987 } else {
1988 return responseDataCallList(p, response, responselen);
1989 }
1990}
1991
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001992static int responseRaw(Parcel &p, void *response, size_t responselen) {
1993 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02001994 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001995 return RIL_ERRNO_INVALID_RESPONSE;
1996 }
1997
1998 // The java code reads -1 size as null byte array
1999 if (response == NULL) {
2000 p.writeInt32(-1);
2001 } else {
2002 p.writeInt32(responselen);
2003 p.write(response, responselen);
2004 }
2005
2006 return 0;
2007}
2008
2009
2010static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2011 if (response == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02002012 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002013 return RIL_ERRNO_INVALID_RESPONSE;
2014 }
2015
2016 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
codeworkxafc051f2013-07-27 09:02:14 +02002017 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002018 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2019 return RIL_ERRNO_INVALID_RESPONSE;
2020 }
2021
2022 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2023 p.writeInt32(p_cur->sw1);
2024 p.writeInt32(p_cur->sw2);
2025 writeStringToParcel(p, p_cur->simResponse);
2026
2027 startResponse;
2028 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2029 (char*)p_cur->simResponse);
2030 closeResponse;
2031
2032
2033 return 0;
2034}
2035
2036static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2037 int num;
2038
2039 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002040 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002041 return RIL_ERRNO_INVALID_RESPONSE;
2042 }
2043
2044 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002045 RLOGE("invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002046 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2047 return RIL_ERRNO_INVALID_RESPONSE;
2048 }
2049
2050 /* number of call info's */
2051 num = responselen / sizeof(RIL_CallForwardInfo *);
2052 p.writeInt32(num);
2053
2054 startResponse;
2055 for (int i = 0 ; i < num ; i++) {
2056 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2057
2058 p.writeInt32(p_cur->status);
2059 p.writeInt32(p_cur->reason);
2060 p.writeInt32(p_cur->serviceClass);
2061 p.writeInt32(p_cur->toa);
2062 writeStringToParcel(p, p_cur->number);
2063 p.writeInt32(p_cur->timeSeconds);
2064 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2065 (p_cur->status==1)?"enable":"disable",
2066 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2067 (char*)p_cur->number,
2068 p_cur->timeSeconds);
2069 }
2070 removeLastChar;
2071 closeResponse;
2072
2073 return 0;
2074}
2075
2076static int responseSsn(Parcel &p, void *response, size_t responselen) {
2077 if (response == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02002078 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002079 return RIL_ERRNO_INVALID_RESPONSE;
2080 }
2081
2082 if (responselen != sizeof(RIL_SuppSvcNotification)) {
codeworkxafc051f2013-07-27 09:02:14 +02002083 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002084 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2085 return RIL_ERRNO_INVALID_RESPONSE;
2086 }
2087
2088 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2089 p.writeInt32(p_cur->notificationType);
2090 p.writeInt32(p_cur->code);
2091 p.writeInt32(p_cur->index);
2092 p.writeInt32(p_cur->type);
2093 writeStringToParcel(p, p_cur->number);
2094
2095 startResponse;
2096 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2097 (p_cur->notificationType==0)?"mo":"mt",
2098 p_cur->code, p_cur->index, p_cur->type,
2099 (char*)p_cur->number);
2100 closeResponse;
2101
2102 return 0;
2103}
2104
2105static int responseCellList(Parcel &p, void *response, size_t responselen) {
2106 int num;
2107
2108 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002109 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002110 return RIL_ERRNO_INVALID_RESPONSE;
2111 }
2112
2113 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002114 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002115 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2116 return RIL_ERRNO_INVALID_RESPONSE;
2117 }
2118
2119 startResponse;
2120 /* number of records */
2121 num = responselen / sizeof(RIL_NeighboringCell *);
2122 p.writeInt32(num);
2123
2124 for (int i = 0 ; i < num ; i++) {
2125 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2126
2127 p.writeInt32(p_cur->rssi);
2128 writeStringToParcel (p, p_cur->cid);
2129
2130 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2131 p_cur->cid, p_cur->rssi);
2132 }
2133 removeLastChar;
2134 closeResponse;
2135
2136 return 0;
2137}
2138
2139/**
2140 * Marshall the signalInfoRecord into the parcel if it exists.
2141 */
2142static void marshallSignalInfoRecord(Parcel &p,
2143 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2144 p.writeInt32(p_signalInfoRecord.isPresent);
2145 p.writeInt32(p_signalInfoRecord.signalType);
2146 p.writeInt32(p_signalInfoRecord.alertPitch);
2147 p.writeInt32(p_signalInfoRecord.signal);
2148}
2149
2150static int responseCdmaInformationRecords(Parcel &p,
2151 void *response, size_t responselen) {
2152 int num;
2153 char* string8 = NULL;
2154 int buffer_lenght;
2155 RIL_CDMA_InformationRecord *infoRec;
2156
2157 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002158 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002159 return RIL_ERRNO_INVALID_RESPONSE;
2160 }
2161
2162 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
codeworkxafc051f2013-07-27 09:02:14 +02002163 RLOGE("invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002164 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2165 return RIL_ERRNO_INVALID_RESPONSE;
2166 }
2167
2168 RIL_CDMA_InformationRecords *p_cur =
2169 (RIL_CDMA_InformationRecords *) response;
2170 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2171
2172 startResponse;
2173 p.writeInt32(num);
2174
2175 for (int i = 0 ; i < num ; i++) {
2176 infoRec = &p_cur->infoRec[i];
2177 p.writeInt32(infoRec->name);
2178 switch (infoRec->name) {
2179 case RIL_CDMA_DISPLAY_INFO_REC:
2180 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2181 if (infoRec->rec.display.alpha_len >
2182 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
codeworkxafc051f2013-07-27 09:02:14 +02002183 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002184 expected not more than %d\n",
2185 (int)infoRec->rec.display.alpha_len,
2186 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2187 return RIL_ERRNO_INVALID_RESPONSE;
2188 }
2189 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2190 * sizeof(char) );
2191 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2192 string8[i] = infoRec->rec.display.alpha_buf[i];
2193 }
2194 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2195 writeStringToParcel(p, (const char*)string8);
2196 free(string8);
2197 string8 = NULL;
2198 break;
2199 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2200 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2201 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2202 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
codeworkxafc051f2013-07-27 09:02:14 +02002203 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002204 expected not more than %d\n",
2205 (int)infoRec->rec.number.len,
2206 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2207 return RIL_ERRNO_INVALID_RESPONSE;
2208 }
2209 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2210 * sizeof(char) );
2211 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2212 string8[i] = infoRec->rec.number.buf[i];
2213 }
2214 string8[(int)infoRec->rec.number.len] = '\0';
2215 writeStringToParcel(p, (const char*)string8);
2216 free(string8);
2217 string8 = NULL;
2218 p.writeInt32(infoRec->rec.number.number_type);
2219 p.writeInt32(infoRec->rec.number.number_plan);
2220 p.writeInt32(infoRec->rec.number.pi);
2221 p.writeInt32(infoRec->rec.number.si);
2222 break;
2223 case RIL_CDMA_SIGNAL_INFO_REC:
2224 p.writeInt32(infoRec->rec.signal.isPresent);
2225 p.writeInt32(infoRec->rec.signal.signalType);
2226 p.writeInt32(infoRec->rec.signal.alertPitch);
2227 p.writeInt32(infoRec->rec.signal.signal);
2228
2229 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2230 alertPitch=%X, signal=%X, ",
2231 printBuf, (int)infoRec->rec.signal.isPresent,
2232 (int)infoRec->rec.signal.signalType,
2233 (int)infoRec->rec.signal.alertPitch,
2234 (int)infoRec->rec.signal.signal);
2235 removeLastChar;
2236 break;
2237 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2238 if (infoRec->rec.redir.redirectingNumber.len >
2239 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
codeworkxafc051f2013-07-27 09:02:14 +02002240 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002241 expected not more than %d\n",
2242 (int)infoRec->rec.redir.redirectingNumber.len,
2243 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2244 return RIL_ERRNO_INVALID_RESPONSE;
2245 }
2246 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2247 .len + 1) * sizeof(char) );
2248 for (int i = 0;
2249 i < infoRec->rec.redir.redirectingNumber.len;
2250 i++) {
2251 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2252 }
2253 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2254 writeStringToParcel(p, (const char*)string8);
2255 free(string8);
2256 string8 = NULL;
2257 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2258 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2259 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2260 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2261 p.writeInt32(infoRec->rec.redir.redirectingReason);
2262 break;
2263 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2264 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2265 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2266 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2267 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2268
2269 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2270 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2271 lineCtrlPowerDenial=%d, ", printBuf,
2272 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2273 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2274 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2275 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2276 removeLastChar;
2277 break;
2278 case RIL_CDMA_T53_CLIR_INFO_REC:
2279 p.writeInt32((int)(infoRec->rec.clir.cause));
2280
2281 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2282 removeLastChar;
2283 break;
2284 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2285 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2286 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2287
2288 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2289 infoRec->rec.audioCtrl.upLink,
2290 infoRec->rec.audioCtrl.downLink);
2291 removeLastChar;
2292 break;
2293 case RIL_CDMA_T53_RELEASE_INFO_REC:
2294 // TODO(Moto): See David Krause, he has the answer:)
codeworkxafc051f2013-07-27 09:02:14 +02002295 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002296 return RIL_ERRNO_INVALID_RESPONSE;
2297 default:
codeworkxafc051f2013-07-27 09:02:14 +02002298 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002299 return RIL_ERRNO_INVALID_RESPONSE;
2300 }
2301 }
2302 closeResponse;
2303
2304 return 0;
2305}
2306
2307static int responseRilSignalStrength(Parcel &p,
2308 void *response, size_t responselen) {
2309
2310 int gsmSignalStrength;
2311
2312 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002313 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002314 return RIL_ERRNO_INVALID_RESPONSE;
2315 }
2316
codeworkxafc051f2013-07-27 09:02:14 +02002317 RLOGE("responseRilSignalStrength()");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002318
2319 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
2320 RIL_SignalStrength_v6 *p_cur = ((RIL_SignalStrength_v6 *) response);
2321
2322 /* gsmSignalStrength */
codeworkxafc051f2013-07-27 09:02:14 +02002323 RLOGD("gsmSignalStrength (raw)=%d", p_cur->GW_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002324 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
codeworkxafc051f2013-07-27 09:02:14 +02002325 RLOGD("gsmSignalStrength (corrected)=%d", gsmSignalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002326
2327 /*
2328 * if gsmSignalStrength isn't a valid value, use cdmaDbm as fallback.
2329 * This is needed for old modem firmwares.
2330 */
2331 if (gsmSignalStrength < 0 || (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
codeworkxafc051f2013-07-27 09:02:14 +02002332 RLOGD("gsmSignalStrength-fallback (raw)=%d", p_cur->CDMA_SignalStrength.dbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002333 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
2334 if (gsmSignalStrength < 0) {
2335 gsmSignalStrength = 99;
2336 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
2337 gsmSignalStrength = 31;
2338 }
codeworkxafc051f2013-07-27 09:02:14 +02002339 RLOGD("gsmSignalStrength-fallback (corrected)=%d", gsmSignalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002340 }
2341 p.writeInt32(gsmSignalStrength);
2342
2343 /* gsmBitErrorRate */
2344 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2345 /* cdmaDbm */
2346 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2347 /* cdmaEcio */
2348 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2349 /* evdoDbm */
2350 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2351 /* evdoEcio */
2352 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2353 /* evdoSnr */
2354 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
2355
2356 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
2357 /* lteSignalStrength */
2358 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
2359
2360 /*
2361 * ril version <=6 receives negative values for rsrp
2362 * workaround for backward compatibility
2363 */
2364 p_cur->LTE_SignalStrength.rsrp =
2365 ((s_callbacks.version <= 6) && (p_cur->LTE_SignalStrength.rsrp < 0 )) ?
2366 -(p_cur->LTE_SignalStrength.rsrp) : p_cur->LTE_SignalStrength.rsrp;
2367
2368 /* lteRsrp */
2369 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2370 /* lteRsrq */
2371 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2372 /* lteRssnr */
2373 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2374 /* lteCqi */
2375 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
2376
2377 } else {
2378 memset(&p_cur->LTE_SignalStrength, sizeof (RIL_LTE_SignalStrength), 0);
2379 }
2380
2381 startResponse;
2382 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
2383 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2384 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2385 EVDO_SS.signalNoiseRatio=%d,\
2386 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
2387 LTE_SS.rssnr=%d,LTE_SS.cqi=%d]",
2388 printBuf,
2389 gsmSignalStrength,
2390 p_cur->GW_SignalStrength.bitErrorRate,
2391 p_cur->CDMA_SignalStrength.dbm,
2392 p_cur->CDMA_SignalStrength.ecio,
2393 p_cur->EVDO_SignalStrength.dbm,
2394 p_cur->EVDO_SignalStrength.ecio,
2395 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2396 p_cur->LTE_SignalStrength.signalStrength,
2397 p_cur->LTE_SignalStrength.rsrp,
2398 p_cur->LTE_SignalStrength.rsrq,
2399 p_cur->LTE_SignalStrength.rssnr,
2400 p_cur->LTE_SignalStrength.cqi);
2401 closeResponse;
2402
2403 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002404 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002405 return RIL_ERRNO_INVALID_RESPONSE;
2406 }
2407
2408 return 0;
2409}
2410
2411static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2412 if ((response == NULL) || (responselen == 0)) {
2413 return responseVoid(p, response, responselen);
2414 } else {
2415 return responseCdmaSignalInfoRecord(p, response, responselen);
2416 }
2417}
2418
2419static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2420 if (response == NULL || responselen == 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002421 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002422 return RIL_ERRNO_INVALID_RESPONSE;
2423 }
2424
2425 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
codeworkxafc051f2013-07-27 09:02:14 +02002426 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002427 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2428 return RIL_ERRNO_INVALID_RESPONSE;
2429 }
2430
2431 startResponse;
2432
2433 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2434 marshallSignalInfoRecord(p, *p_cur);
2435
2436 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2437 signal=%d]",
2438 printBuf,
2439 p_cur->isPresent,
2440 p_cur->signalType,
2441 p_cur->alertPitch,
2442 p_cur->signal);
2443
2444 closeResponse;
2445 return 0;
2446}
2447
2448static int responseCdmaCallWaiting(Parcel &p, void *response,
2449 size_t responselen) {
2450 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002451 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002452 return RIL_ERRNO_INVALID_RESPONSE;
2453 }
2454
2455 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
codeworkxafc051f2013-07-27 09:02:14 +02002456 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002457 }
2458
2459 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2460
2461 writeStringToParcel(p, p_cur->number);
2462 p.writeInt32(p_cur->numberPresentation);
2463 writeStringToParcel(p, p_cur->name);
2464 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2465
2466 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2467 p.writeInt32(p_cur->number_type);
2468 p.writeInt32(p_cur->number_plan);
2469 } else {
2470 p.writeInt32(0);
2471 p.writeInt32(0);
2472 }
2473
2474 startResponse;
2475 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2476 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
2477 signal=%d,number_type=%d,number_plan=%d]",
2478 printBuf,
2479 p_cur->number,
2480 p_cur->numberPresentation,
2481 p_cur->name,
2482 p_cur->signalInfoRecord.isPresent,
2483 p_cur->signalInfoRecord.signalType,
2484 p_cur->signalInfoRecord.alertPitch,
2485 p_cur->signalInfoRecord.signal,
2486 p_cur->number_type,
2487 p_cur->number_plan);
2488 closeResponse;
2489
2490 return 0;
2491}
2492
2493static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2494 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002495 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002496 return RIL_ERRNO_INVALID_RESPONSE;
2497 }
2498
2499 startResponse;
2500 if (s_callbacks.version == 7) {
2501 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2502 p.writeInt32(p_cur->result);
2503 p.writeInt32(p_cur->ef_id);
2504 writeStringToParcel(p, p_cur->aid);
2505
2506 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2507 printBuf,
2508 p_cur->result,
2509 p_cur->ef_id,
2510 p_cur->aid);
2511 } else {
2512 int *p_cur = ((int *) response);
2513 p.writeInt32(p_cur[0]);
2514 p.writeInt32(p_cur[1]);
2515 writeStringToParcel(p, NULL);
2516
2517 appendPrintBuf("%sresult=%d, ef_id=%d",
2518 printBuf,
2519 p_cur[0],
2520 p_cur[1]);
2521 }
2522 closeResponse;
2523
2524 return 0;
2525}
2526
codeworkxafc051f2013-07-27 09:02:14 +02002527static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2528{
2529 if (response == NULL && responselen != 0) {
2530 RLOGE("invalid response: NULL");
2531 return RIL_ERRNO_INVALID_RESPONSE;
2532 }
2533
2534 if (responselen % sizeof(RIL_CellInfo) != 0) {
2535 RLOGE("invalid response length %d expected multiple of %d",
2536 (int)responselen, (int)sizeof(RIL_CellInfo));
2537 return RIL_ERRNO_INVALID_RESPONSE;
2538 }
2539
2540 int num = responselen / sizeof(RIL_CellInfo);
2541 p.writeInt32(num);
2542
2543 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2544 startResponse;
2545 int i;
2546 for (i = 0; i < num; i++) {
2547 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2548 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2549 p.writeInt32((int)p_cur->cellInfoType);
2550 p.writeInt32(p_cur->registered);
2551 p.writeInt32(p_cur->timeStampType);
2552 p.writeInt64(p_cur->timeStamp);
2553 switch(p_cur->cellInfoType) {
2554 case RIL_CELL_INFO_TYPE_GSM: {
2555 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
2556 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2557 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2558 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
2559 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2560 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
2561 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2562 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2563
2564 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2565 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2566 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2567 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2568 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2569 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2570 break;
2571 }
2572 case RIL_CELL_INFO_TYPE_WCDMA: {
2573 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2574 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2575 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2576 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2577 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2578 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2579 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2580 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2581 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2582
2583 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2584 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2585 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2586 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2587 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2588 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2589 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2590 break;
2591 }
2592 case RIL_CELL_INFO_TYPE_CDMA: {
2593 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2594 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2595 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2596 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2597 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2598 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2599
2600 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2601 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
2602 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
2603 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
2604 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2605
2606 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
2607 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
2608 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
2609 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
2610 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
2611 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2612
2613 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
2614 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
2615 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
2616 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
2617 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2618 break;
2619 }
2620 case RIL_CELL_INFO_TYPE_LTE: {
2621 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
2622 p_cur->CellInfo.lte.cellIdentityLte.mcc,
2623 p_cur->CellInfo.lte.cellIdentityLte.mnc,
2624 p_cur->CellInfo.lte.cellIdentityLte.ci,
2625 p_cur->CellInfo.lte.cellIdentityLte.pci,
2626 p_cur->CellInfo.lte.cellIdentityLte.tac);
2627
2628 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
2629 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
2630 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
2631 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
2632 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
2633
2634 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
2635 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
2636 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
2637 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
2638 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
2639 p_cur->CellInfo.lte.signalStrengthLte.cqi,
2640 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2641 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
2642 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
2643 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
2644 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
2645 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
2646 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2647 break;
2648 }
2649 }
2650 p_cur += 1;
2651 }
2652 removeLastChar;
2653 closeResponse;
2654
2655 return 0;
2656}
2657
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002658static void triggerEvLoop() {
2659 int ret;
2660 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
2661 /* trigger event loop to wakeup. No reason to do this,
2662 * if we're in the event loop thread */
2663 do {
2664 ret = write (s_fdWakeupWrite, " ", 1);
2665 } while (ret < 0 && errno == EINTR);
2666 }
2667}
2668
2669static void rilEventAddWakeup(struct ril_event *ev) {
2670 ril_event_add(ev);
2671 triggerEvLoop();
2672}
2673
2674static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
2675 p.writeInt32(num_apps);
2676 startResponse;
2677 for (int i = 0; i < num_apps; i++) {
2678 p.writeInt32(appStatus[i].app_type);
2679 p.writeInt32(appStatus[i].app_state);
2680 p.writeInt32(appStatus[i].perso_substate);
2681 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
2682 writeStringToParcel(p, (const char*)
2683 (appStatus[i].app_label_ptr));
2684 p.writeInt32(appStatus[i].pin1_replaced);
2685 p.writeInt32(appStatus[i].pin1);
2686 p.writeInt32(appStatus[i].pin2);
2687 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
2688 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
2689 printBuf,
2690 appStatus[i].app_type,
2691 appStatus[i].app_state,
2692 appStatus[i].perso_substate,
2693 appStatus[i].aid_ptr,
2694 appStatus[i].app_label_ptr,
2695 appStatus[i].pin1_replaced,
2696 appStatus[i].pin1,
2697 appStatus[i].pin2);
2698 }
2699 closeResponse;
2700}
2701
2702static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
codeworkxafc051f2013-07-27 09:02:14 +02002703 int i;
2704
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002705 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002706 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002707 return RIL_ERRNO_INVALID_RESPONSE;
2708 }
2709
2710 if (responselen == sizeof (RIL_CardStatus_v6)) {
codeworkxafc051f2013-07-27 09:02:14 +02002711 RLOGE("RIL_CardStatus_v6");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002712 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
2713
2714 p.writeInt32(p_cur->card_state);
2715 p.writeInt32(p_cur->universal_pin_state);
2716 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2717 p.writeInt32(p_cur->cdma_subscription_app_index);
2718 p.writeInt32(p_cur->ims_subscription_app_index);
2719
2720 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2721 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
codeworkxafc051f2013-07-27 09:02:14 +02002722 RLOGE("RIL_CardStatus_v5");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002723 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
2724
2725 p.writeInt32(p_cur->card_state);
2726 p.writeInt32(p_cur->universal_pin_state);
2727 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
2728 p.writeInt32(p_cur->cdma_subscription_app_index);
2729 p.writeInt32(-1);
2730
2731 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
2732 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002733 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
2734 RLOGE("responselen=%d", responselen);
2735 RLOGE("RIL_CardStatus_v5=%d", sizeof (RIL_CardStatus_v5));
2736 RLOGE("RIL_CardStatus_v6=%d", sizeof (RIL_CardStatus_v6));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002737 return RIL_ERRNO_INVALID_RESPONSE;
2738 }
2739
2740 return 0;
2741}
2742
2743static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2744 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
2745 p.writeInt32(num);
2746
2747 startResponse;
2748 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
2749 (RIL_GSM_BroadcastSmsConfigInfo **) response;
2750 for (int i = 0; i < num; i++) {
2751 p.writeInt32(p_cur[i]->fromServiceId);
2752 p.writeInt32(p_cur[i]->toServiceId);
2753 p.writeInt32(p_cur[i]->fromCodeScheme);
2754 p.writeInt32(p_cur[i]->toCodeScheme);
2755 p.writeInt32(p_cur[i]->selected);
2756
2757 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
2758 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
2759 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
2760 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
2761 p_cur[i]->selected);
2762 }
2763 closeResponse;
2764
2765 return 0;
2766}
2767
2768static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
2769 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
2770 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
2771
2772 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
2773 p.writeInt32(num);
2774
2775 startResponse;
2776 for (int i = 0 ; i < num ; i++ ) {
2777 p.writeInt32(p_cur[i]->service_category);
2778 p.writeInt32(p_cur[i]->language);
2779 p.writeInt32(p_cur[i]->selected);
2780
2781 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
2782 selected =%d], ",
2783 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
2784 p_cur[i]->selected);
2785 }
2786 closeResponse;
2787
2788 return 0;
2789}
2790
2791static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
2792 int num;
2793 int digitCount;
2794 int digitLimit;
2795 uint8_t uct;
2796 void* dest;
2797
codeworkxafc051f2013-07-27 09:02:14 +02002798 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002799
2800 if (response == NULL && responselen != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002801 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002802 return RIL_ERRNO_INVALID_RESPONSE;
2803 }
2804
2805 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
codeworkxafc051f2013-07-27 09:02:14 +02002806 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002807 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
2808 return RIL_ERRNO_INVALID_RESPONSE;
2809 }
2810
2811 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
2812 p.writeInt32(p_cur->uTeleserviceID);
2813 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
2814 p.writeInt32(p_cur->uServicecategory);
2815 p.writeInt32(p_cur->sAddress.digit_mode);
2816 p.writeInt32(p_cur->sAddress.number_mode);
2817 p.writeInt32(p_cur->sAddress.number_type);
2818 p.writeInt32(p_cur->sAddress.number_plan);
2819 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
2820 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2821 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2822 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
2823 }
2824
2825 p.writeInt32(p_cur->sSubAddress.subaddressType);
2826 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
2827 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
2828 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2829 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2830 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
2831 }
2832
2833 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2834 p.writeInt32(p_cur->uBearerDataLen);
2835 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
2836 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
2837 }
2838
2839 startResponse;
2840 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
2841 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
2842 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
2843 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
2844 closeResponse;
2845
2846 return 0;
2847}
2848
2849/**
2850 * A write on the wakeup fd is done just to pop us out of select()
2851 * We empty the buffer here and then ril_event will reset the timers on the
2852 * way back down
2853 */
2854static void processWakeupCallback(int fd, short flags, void *param) {
2855 char buff[16];
2856 int ret;
2857
codeworkxafc051f2013-07-27 09:02:14 +02002858 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002859
2860 /* empty our wakeup socket out */
2861 do {
2862 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
2863 } while (ret > 0 || (ret < 0 && errno == EINTR));
2864}
2865
2866static void onCommandsSocketClosed() {
2867 int ret;
2868 RequestInfo *p_cur;
2869
2870 /* mark pending requests as "cancelled" so we dont report responses */
2871
2872 ret = pthread_mutex_lock(&s_pendingRequestsMutex);
2873 assert (ret == 0);
2874
2875 p_cur = s_pendingRequests;
2876
2877 for (p_cur = s_pendingRequests
2878 ; p_cur != NULL
2879 ; p_cur = p_cur->p_next
2880 ) {
2881 p_cur->cancelled = 1;
2882 }
2883
2884 ret = pthread_mutex_unlock(&s_pendingRequestsMutex);
2885 assert (ret == 0);
2886}
2887
2888static void processCommandsCallback(int fd, short flags, void *param) {
2889 RecordStream *p_rs;
2890 void *p_record;
2891 size_t recordlen;
2892 int ret;
2893
2894 assert(fd == s_fdCommand);
2895
2896 p_rs = (RecordStream *)param;
2897
2898 for (;;) {
2899 /* loop until EAGAIN/EINTR, end of stream, or other error */
2900 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
2901
2902 if (ret == 0 && p_record == NULL) {
2903 /* end-of-stream */
2904 break;
2905 } else if (ret < 0) {
2906 break;
2907 } else if (ret == 0) { /* && p_record != NULL */
2908 processCommandBuffer(p_record, recordlen);
2909 }
2910 }
2911
2912 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
2913 /* fatal error or end-of-stream */
2914 if (ret != 0) {
codeworkxafc051f2013-07-27 09:02:14 +02002915 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002916 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002917 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002918 }
2919
2920 close(s_fdCommand);
2921 s_fdCommand = -1;
2922
2923 ril_event_del(&s_commands_event);
2924
2925 record_stream_free(p_rs);
2926
2927 /* start listening for new connections again */
2928 rilEventAddWakeup(&s_listen_event);
2929
2930 onCommandsSocketClosed();
2931 }
2932}
2933
2934
2935static void onNewCommandConnect() {
2936 // Inform we are connected and the ril version
2937 int rilVer = s_callbacks.version;
2938 RIL_onUnsolicitedResponse(RIL_UNSOL_RIL_CONNECTED,
2939 &rilVer, sizeof(rilVer));
2940
2941 // implicit radio state changed
2942 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
2943 NULL, 0);
2944
2945 // Send last NITZ time data, in case it was missed
2946 if (s_lastNITZTimeData != NULL) {
2947 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize);
2948
2949 free(s_lastNITZTimeData);
2950 s_lastNITZTimeData = NULL;
2951 }
2952
2953 // Get version string
2954 if (s_callbacks.getVersion != NULL) {
2955 const char *version;
2956 version = s_callbacks.getVersion();
codeworkxafc051f2013-07-27 09:02:14 +02002957 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002958
2959 property_set(PROPERTY_RIL_IMPL, version);
2960 } else {
codeworkxafc051f2013-07-27 09:02:14 +02002961 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002962 property_set(PROPERTY_RIL_IMPL, "unavailable");
2963 }
2964
2965}
2966
2967static void listenCallback (int fd, short flags, void *param) {
2968 int ret;
2969 int err;
2970 int is_phone_socket;
2971 RecordStream *p_rs;
2972
2973 struct sockaddr_un peeraddr;
2974 socklen_t socklen = sizeof (peeraddr);
2975
2976 struct ucred creds;
2977 socklen_t szCreds = sizeof(creds);
2978
2979 struct passwd *pwd = NULL;
2980
2981 assert (s_fdCommand < 0);
2982 assert (fd == s_fdListen);
2983
2984 s_fdCommand = accept(s_fdListen, (sockaddr *) &peeraddr, &socklen);
2985
2986 if (s_fdCommand < 0 ) {
codeworkxafc051f2013-07-27 09:02:14 +02002987 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002988 /* start listening for new connections again */
2989 rilEventAddWakeup(&s_listen_event);
2990 return;
2991 }
2992
2993 /* check the credential of the other side and only accept socket from
2994 * phone process
2995 */
2996 errno = 0;
2997 is_phone_socket = 0;
2998
2999 err = getsockopt(s_fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
3000
3001 if (err == 0 && szCreds > 0) {
3002 errno = 0;
3003 pwd = getpwuid(creds.uid);
3004 if (pwd != NULL) {
3005 if (strcmp(pwd->pw_name, PHONE_PROCESS) == 0) {
3006 is_phone_socket = 1;
3007 } else {
codeworkxafc051f2013-07-27 09:02:14 +02003008 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003009 }
3010 } else {
codeworkxafc051f2013-07-27 09:02:14 +02003011 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003012 }
3013 } else {
codeworkxafc051f2013-07-27 09:02:14 +02003014 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003015 }
3016
3017 if ( !is_phone_socket ) {
codeworkxafc051f2013-07-27 09:02:14 +02003018 RLOGE("RILD must accept socket from %s", PHONE_PROCESS);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003019
3020 close(s_fdCommand);
3021 s_fdCommand = -1;
3022
3023 onCommandsSocketClosed();
3024
3025 /* start listening for new connections again */
3026 rilEventAddWakeup(&s_listen_event);
3027
3028 return;
3029 }
3030
3031 ret = fcntl(s_fdCommand, F_SETFL, O_NONBLOCK);
3032
3033 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003034 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003035 }
3036
codeworkxafc051f2013-07-27 09:02:14 +02003037 RLOGI("libril: new connection");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003038
3039 p_rs = record_stream_new(s_fdCommand, MAX_COMMAND_BYTES);
3040
3041 ril_event_set (&s_commands_event, s_fdCommand, 1,
3042 processCommandsCallback, p_rs);
3043
3044 rilEventAddWakeup (&s_commands_event);
3045
3046 onNewCommandConnect();
3047}
3048
3049static void freeDebugCallbackArgs(int number, char **args) {
3050 for (int i = 0; i < number; i++) {
3051 if (args[i] != NULL) {
3052 free(args[i]);
3053 }
3054 }
3055 free(args);
3056}
3057
3058static void debugCallback (int fd, short flags, void *param) {
3059 int acceptFD, option;
3060 struct sockaddr_un peeraddr;
3061 socklen_t socklen = sizeof (peeraddr);
3062 int data;
3063 unsigned int qxdm_data[6];
3064 const char *deactData[1] = {"1"};
3065 char *actData[1];
3066 RIL_Dial dialData;
3067 int hangupData[1] = {1};
3068 int number;
3069 char **args;
3070
3071 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3072
3073 if (acceptFD < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003074 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003075 return;
3076 }
3077
3078 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
codeworkxafc051f2013-07-27 09:02:14 +02003079 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003080 return;
3081 }
3082 args = (char **) malloc(sizeof(char*) * number);
3083
3084 for (int i = 0; i < number; i++) {
3085 int len;
3086 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
codeworkxafc051f2013-07-27 09:02:14 +02003087 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003088 freeDebugCallbackArgs(i, args);
3089 return;
3090 }
3091 // +1 for null-term
3092 args[i] = (char *) malloc((sizeof(char) * len) + 1);
3093 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
3094 != (int)sizeof(char) * len) {
codeworkxafc051f2013-07-27 09:02:14 +02003095 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003096 freeDebugCallbackArgs(i, args);
3097 return;
3098 }
3099 char * buf = args[i];
3100 buf[len] = 0;
3101 }
3102
3103 switch (atoi(args[0])) {
3104 case 0:
codeworkxafc051f2013-07-27 09:02:14 +02003105 RLOGI ("Connection on debug port: issuing reset.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003106 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0);
3107 break;
3108 case 1:
codeworkxafc051f2013-07-27 09:02:14 +02003109 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003110 data = 0;
3111 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
3112 // Close the socket
3113 close(s_fdCommand);
3114 s_fdCommand = -1;
3115 break;
3116 case 2:
codeworkxafc051f2013-07-27 09:02:14 +02003117 RLOGI ("Debug port: issuing unsolicited voice network change.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003118 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED,
3119 NULL, 0);
3120 break;
3121 case 3:
codeworkxafc051f2013-07-27 09:02:14 +02003122 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003123 qxdm_data[0] = 65536; // head.func_tag
3124 qxdm_data[1] = 16; // head.len
3125 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3126 qxdm_data[3] = 32; // log_file_size: 32megabytes
3127 qxdm_data[4] = 0; // log_mask
3128 qxdm_data[5] = 8; // log_max_fileindex
3129 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
3130 6 * sizeof(int));
3131 break;
3132 case 4:
codeworkxafc051f2013-07-27 09:02:14 +02003133 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003134 qxdm_data[0] = 65536;
3135 qxdm_data[1] = 16;
3136 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
3137 qxdm_data[3] = 32;
3138 qxdm_data[4] = 0;
3139 qxdm_data[5] = 8;
3140 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
3141 6 * sizeof(int));
3142 break;
3143 case 5:
codeworkxafc051f2013-07-27 09:02:14 +02003144 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003145 data = 1;
3146 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int));
3147 sleep(2);
3148 // Set network selection automatic.
3149 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0);
3150 break;
3151 case 6:
codeworkxafc051f2013-07-27 09:02:14 +02003152 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003153 actData[0] = args[1];
3154 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
3155 sizeof(actData));
3156 break;
3157 case 7:
codeworkxafc051f2013-07-27 09:02:14 +02003158 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003159 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
3160 sizeof(deactData));
3161 break;
3162 case 8:
codeworkxafc051f2013-07-27 09:02:14 +02003163 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003164 dialData.clir = 0;
3165 dialData.address = args[1];
3166 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData));
3167 break;
3168 case 9:
codeworkxafc051f2013-07-27 09:02:14 +02003169 RLOGI("Debug port: Answer Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003170 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0);
3171 break;
3172 case 10:
codeworkxafc051f2013-07-27 09:02:14 +02003173 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003174 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
3175 sizeof(hangupData));
3176 break;
3177 default:
codeworkxafc051f2013-07-27 09:02:14 +02003178 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003179 break;
3180 }
3181 freeDebugCallbackArgs(number, args);
3182 close(acceptFD);
3183}
3184
3185
3186static void userTimerCallback (int fd, short flags, void *param) {
3187 UserCallbackInfo *p_info;
3188
3189 p_info = (UserCallbackInfo *)param;
3190
3191 p_info->p_callback(p_info->userParam);
3192
3193
3194 // FIXME generalize this...there should be a cancel mechanism
3195 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3196 s_last_wake_timeout_info = NULL;
3197 }
3198
3199 free(p_info);
3200}
3201
3202
3203static void *
3204eventLoop(void *param) {
3205 int ret;
3206 int filedes[2];
3207
3208 ril_event_init();
3209
3210 pthread_mutex_lock(&s_startupMutex);
3211
3212 s_started = 1;
3213 pthread_cond_broadcast(&s_startupCond);
3214
3215 pthread_mutex_unlock(&s_startupMutex);
3216
3217 ret = pipe(filedes);
3218
3219 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003220 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003221 return NULL;
3222 }
3223
3224 s_fdWakeupRead = filedes[0];
3225 s_fdWakeupWrite = filedes[1];
3226
3227 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3228
3229 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3230 processWakeupCallback, NULL);
3231
3232 rilEventAddWakeup (&s_wakeupfd_event);
3233
3234 // Only returns on error
3235 ril_event_loop();
codeworkxafc051f2013-07-27 09:02:14 +02003236 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003237 // kill self to restart on error
3238 kill(0, SIGKILL);
3239
3240 return NULL;
3241}
3242
3243extern "C" void
3244RIL_startEventLoop(void) {
3245 int ret;
3246 pthread_attr_t attr;
3247
3248 /* spin up eventLoop thread and wait for it to get started */
3249 s_started = 0;
3250 pthread_mutex_lock(&s_startupMutex);
3251
3252 pthread_attr_init (&attr);
3253 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3254 ret = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3255
3256 while (s_started == 0) {
3257 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3258 }
3259
3260 pthread_mutex_unlock(&s_startupMutex);
3261
3262 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003263 RLOGE("Failed to create dispatch thread errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003264 return;
3265 }
3266}
3267
3268// Used for testing purpose only.
3269extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3270 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3271}
3272
3273extern "C" void
3274RIL_register (const RIL_RadioFunctions *callbacks) {
3275 int ret;
3276 int flags;
3277
3278 if (callbacks == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02003279 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003280 return;
3281 }
3282 if (callbacks->version < RIL_VERSION_MIN) {
codeworkxafc051f2013-07-27 09:02:14 +02003283 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003284 callbacks->version, RIL_VERSION_MIN);
3285 return;
3286 }
3287 if (callbacks->version > RIL_VERSION) {
codeworkxafc051f2013-07-27 09:02:14 +02003288 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003289 callbacks->version, RIL_VERSION);
3290 return;
3291 }
codeworkxafc051f2013-07-27 09:02:14 +02003292 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003293
3294 if (s_registerCalled > 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003295 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003296 "Subsequent call ignored");
3297 return;
3298 }
3299
3300 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3301
3302 s_registerCalled = 1;
3303
3304 // Little self-check
3305
3306 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
3307 assert(i == s_commands[i].requestNumber);
3308 }
3309
3310 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003311 /* Hack to include Samsung responses */
3312 if (i > MAX_RIL_UNSOL - RIL_UNSOL_RESPONSE_BASE) {
3313 assert(i + SAMSUNG_UNSOL_RESPONSE_BASE - MAX_RIL_UNSOL
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003314 == s_unsolResponses[i].requestNumber);
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003315 } else {
3316 assert(i + RIL_UNSOL_RESPONSE_BASE
3317 == s_unsolResponses[i].requestNumber);
3318 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003319 }
3320
3321 // New rild impl calls RIL_startEventLoop() first
3322 // old standalone impl wants it here.
3323
3324 if (s_started == 0) {
3325 RIL_startEventLoop();
3326 }
3327
3328 // start listen socket
3329
3330#if 0
3331 ret = socket_local_server (SOCKET_NAME_RIL,
3332 ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM);
3333
3334 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003335 RLOGE("Unable to bind socket errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003336 exit (-1);
3337 }
3338 s_fdListen = ret;
3339
3340#else
3341 s_fdListen = android_get_control_socket(SOCKET_NAME_RIL);
3342 if (s_fdListen < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003343 RLOGE("Failed to get socket '" SOCKET_NAME_RIL "'");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003344 exit(-1);
3345 }
3346
3347 ret = listen(s_fdListen, 4);
3348
3349 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003350 RLOGE("Failed to listen on control socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003351 s_fdListen, strerror(errno));
3352 exit(-1);
3353 }
3354#endif
3355
3356
3357 /* note: non-persistent so we can accept only one connection at a time */
3358 ril_event_set (&s_listen_event, s_fdListen, false,
3359 listenCallback, NULL);
3360
3361 rilEventAddWakeup (&s_listen_event);
3362
3363#if 1
3364 // start debug interface socket
3365
3366 s_fdDebug = android_get_control_socket(SOCKET_NAME_RIL_DEBUG);
3367 if (s_fdDebug < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003368 RLOGE("Failed to get socket '" SOCKET_NAME_RIL_DEBUG "' errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003369 exit(-1);
3370 }
3371
3372 ret = listen(s_fdDebug, 4);
3373
3374 if (ret < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003375 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003376 s_fdDebug, strerror(errno));
3377 exit(-1);
3378 }
3379
3380 ril_event_set (&s_debug_event, s_fdDebug, true,
3381 debugCallback, NULL);
3382
3383 rilEventAddWakeup (&s_debug_event);
3384#endif
3385
3386}
3387
3388static int
3389checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
3390 int ret = 0;
3391
3392 if (pRI == NULL) {
3393 return 0;
3394 }
3395
3396 pthread_mutex_lock(&s_pendingRequestsMutex);
3397
3398 for(RequestInfo **ppCur = &s_pendingRequests
3399 ; *ppCur != NULL
3400 ; ppCur = &((*ppCur)->p_next)
3401 ) {
3402 if (pRI == *ppCur) {
3403 ret = 1;
3404
3405 *ppCur = (*ppCur)->p_next;
3406 break;
3407 }
3408 }
3409
3410 pthread_mutex_unlock(&s_pendingRequestsMutex);
3411
3412 return ret;
3413}
3414
3415
3416extern "C" void
3417RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
3418 RequestInfo *pRI;
3419 int ret;
3420 size_t errorOffset;
3421
3422 pRI = (RequestInfo *)t;
3423
3424 if (!checkAndDequeueRequestInfo(pRI)) {
codeworkxafc051f2013-07-27 09:02:14 +02003425 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003426 return;
3427 }
3428
3429 if (pRI->local > 0) {
3430 // Locally issued command...void only!
3431 // response does not go back up the command socket
codeworkxafc051f2013-07-27 09:02:14 +02003432 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003433
3434 goto done;
3435 }
3436
3437 appendPrintBuf("[%04d]< %s",
3438 pRI->token, requestToString(pRI->pCI->requestNumber));
3439
3440 if (pRI->cancelled == 0) {
3441 Parcel p;
3442
3443 p.writeInt32 (RESPONSE_SOLICITED);
3444 p.writeInt32 (pRI->token);
3445 errorOffset = p.dataPosition();
3446
3447 p.writeInt32 (e);
3448
3449 if (response != NULL) {
3450 // there is a response payload, no matter success or not.
3451 ret = pRI->pCI->responseFunction(p, response, responselen);
3452
3453 /* if an error occurred, rewind and mark it */
3454 if (ret != 0) {
3455 p.setDataPosition(errorOffset);
3456 p.writeInt32 (ret);
3457 }
3458 }
3459
3460 if (e != RIL_E_SUCCESS) {
3461 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
3462 }
3463
3464 if (s_fdCommand < 0) {
codeworkxafc051f2013-07-27 09:02:14 +02003465 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003466 }
3467 sendResponse(p);
3468 }
3469
3470done:
3471 free(pRI);
3472}
3473
3474
3475static void
3476grabPartialWakeLock() {
3477 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
3478}
3479
3480static void
3481releaseWakeLock() {
3482 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
3483}
3484
3485/**
3486 * Timer callback to put us back to sleep before the default timeout
3487 */
3488static void
3489wakeTimeoutCallback (void *param) {
3490 // We're using "param != NULL" as a cancellation mechanism
3491 if (param == NULL) {
codeworkxafc051f2013-07-27 09:02:14 +02003492 //RLOGD("wakeTimeout: releasing wake lock");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003493
3494 releaseWakeLock();
3495 } else {
codeworkxafc051f2013-07-27 09:02:14 +02003496 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003497 }
3498}
3499
3500static int
3501decodeVoiceRadioTechnology (RIL_RadioState radioState) {
3502 switch (radioState) {
3503 case RADIO_STATE_SIM_NOT_READY:
3504 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3505 case RADIO_STATE_SIM_READY:
3506 return RADIO_TECH_UMTS;
3507
3508 case RADIO_STATE_RUIM_NOT_READY:
3509 case RADIO_STATE_RUIM_READY:
3510 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3511 case RADIO_STATE_NV_NOT_READY:
3512 case RADIO_STATE_NV_READY:
3513 return RADIO_TECH_1xRTT;
3514
3515 default:
codeworkxafc051f2013-07-27 09:02:14 +02003516 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003517 return -1;
3518 }
3519}
3520
3521static int
3522decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
3523 switch (radioState) {
3524 case RADIO_STATE_SIM_NOT_READY:
3525 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3526 case RADIO_STATE_SIM_READY:
3527 case RADIO_STATE_RUIM_NOT_READY:
3528 case RADIO_STATE_RUIM_READY:
3529 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3530 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
3531
3532 case RADIO_STATE_NV_NOT_READY:
3533 case RADIO_STATE_NV_READY:
3534 return CDMA_SUBSCRIPTION_SOURCE_NV;
3535
3536 default:
codeworkxafc051f2013-07-27 09:02:14 +02003537 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003538 return -1;
3539 }
3540}
3541
3542static int
3543decodeSimStatus (RIL_RadioState radioState) {
3544 switch (radioState) {
3545 case RADIO_STATE_SIM_NOT_READY:
3546 case RADIO_STATE_RUIM_NOT_READY:
3547 case RADIO_STATE_NV_NOT_READY:
3548 case RADIO_STATE_NV_READY:
3549 return -1;
3550 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
3551 case RADIO_STATE_SIM_READY:
3552 case RADIO_STATE_RUIM_READY:
3553 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
3554 return radioState;
3555 default:
codeworkxafc051f2013-07-27 09:02:14 +02003556 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003557 return -1;
3558 }
3559}
3560
3561static bool is3gpp2(int radioTech) {
3562 switch (radioTech) {
3563 case RADIO_TECH_IS95A:
3564 case RADIO_TECH_IS95B:
3565 case RADIO_TECH_1xRTT:
3566 case RADIO_TECH_EVDO_0:
3567 case RADIO_TECH_EVDO_A:
3568 case RADIO_TECH_EVDO_B:
3569 case RADIO_TECH_EHRPD:
3570 return true;
3571 default:
3572 return false;
3573 }
3574}
3575
3576/* If RIL sends SIM states or RUIM states, store the voice radio
3577 * technology and subscription source information so that they can be
3578 * returned when telephony framework requests them
3579 */
3580static RIL_RadioState
3581processRadioState(RIL_RadioState newRadioState) {
3582
3583 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
3584 int newVoiceRadioTech;
3585 int newCdmaSubscriptionSource;
3586 int newSimStatus;
3587
3588 /* This is old RIL. Decode Subscription source and Voice Radio Technology
3589 from Radio State and send change notifications if there has been a change */
3590 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
3591 if(newVoiceRadioTech != voiceRadioTech) {
3592 voiceRadioTech = newVoiceRadioTech;
3593 RIL_onUnsolicitedResponse (RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
3594 &voiceRadioTech, sizeof(voiceRadioTech));
3595 }
3596 if(is3gpp2(newVoiceRadioTech)) {
3597 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
3598 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
3599 cdmaSubscriptionSource = newCdmaSubscriptionSource;
3600 RIL_onUnsolicitedResponse (RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
3601 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource));
3602 }
3603 }
3604 newSimStatus = decodeSimStatus(newRadioState);
3605 if(newSimStatus != simRuimStatus) {
3606 simRuimStatus = newSimStatus;
3607 RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0);
3608 }
3609
3610 /* Send RADIO_ON to telephony */
3611 newRadioState = RADIO_STATE_ON;
3612 }
3613
3614 return newRadioState;
3615}
3616
3617extern "C"
3618void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
3619 size_t datalen)
3620{
3621 int unsolResponseIndex;
3622 int ret;
3623 int64_t timeReceived = 0;
3624 bool shouldScheduleTimeout = false;
3625 RIL_RadioState newState;
3626
3627 if (s_registerCalled == 0) {
3628 // Ignore RIL_onUnsolicitedResponse before RIL_register
codeworkxafc051f2013-07-27 09:02:14 +02003629 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003630 return;
3631 }
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02003632
3633 /* Hack to include Samsung responses */
3634 if (unsolResponse > SAMSUNG_UNSOL_RESPONSE_BASE) {
3635 unsolResponseIndex = unsolResponse - SAMSUNG_UNSOL_RESPONSE_BASE + MAX_RIL_UNSOL - RIL_UNSOL_RESPONSE_BASE;
3636 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, unsolResponseIndex);
3637 } else {
3638 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
3639 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003640
3641 if ((unsolResponseIndex < 0)
3642 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
codeworkxafc051f2013-07-27 09:02:14 +02003643 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003644 return;
3645 }
3646
3647 // Grab a wake lock if needed for this reponse,
3648 // as we exit we'll either release it immediately
3649 // or set a timer to release it later.
3650 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
3651 case WAKE_PARTIAL:
3652 grabPartialWakeLock();
3653 shouldScheduleTimeout = true;
3654 break;
3655
3656 case DONT_WAKE:
3657 default:
3658 // No wake lock is grabed so don't set timeout
3659 shouldScheduleTimeout = false;
3660 break;
3661 }
3662
3663 // Mark the time this was received, doing this
3664 // after grabing the wakelock incase getting
3665 // the elapsedRealTime might cause us to goto
3666 // sleep.
3667 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3668 timeReceived = elapsedRealtime();
3669 }
3670
3671 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
3672
3673 Parcel p;
3674
3675 p.writeInt32 (RESPONSE_UNSOLICITED);
3676 p.writeInt32 (unsolResponse);
3677
3678 ret = s_unsolResponses[unsolResponseIndex]
3679 .responseFunction(p, data, datalen);
3680 if (ret != 0) {
3681 // Problem with the response. Don't continue;
3682 goto error_exit;
3683 }
3684
3685 // some things get more payload
3686 switch(unsolResponse) {
3687 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
3688 newState = processRadioState(s_callbacks.onStateRequest());
3689 p.writeInt32(newState);
3690 appendPrintBuf("%s {%s}", printBuf,
3691 radioStateToString(s_callbacks.onStateRequest()));
3692 break;
3693
3694
3695 case RIL_UNSOL_NITZ_TIME_RECEIVED:
3696 // Store the time that this was received so the
3697 // handler of this message can account for
3698 // the time it takes to arrive and process. In
3699 // particular the system has been known to sleep
3700 // before this message can be processed.
3701 p.writeInt64(timeReceived);
3702 break;
3703 }
3704
3705 ret = sendResponse(p);
3706 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
3707
3708 // Unfortunately, NITZ time is not poll/update like everything
3709 // else in the system. So, if the upstream client isn't connected,
3710 // keep a copy of the last NITZ response (with receive time noted
3711 // above) around so we can deliver it when it is connected
3712
3713 if (s_lastNITZTimeData != NULL) {
3714 free (s_lastNITZTimeData);
3715 s_lastNITZTimeData = NULL;
3716 }
3717
3718 s_lastNITZTimeData = malloc(p.dataSize());
3719 s_lastNITZTimeDataSize = p.dataSize();
3720 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
3721 }
3722
3723 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
3724 // FIXME The java code should handshake here to release wake lock
3725
3726 if (shouldScheduleTimeout) {
3727 // Cancel the previous request
3728 if (s_last_wake_timeout_info != NULL) {
3729 s_last_wake_timeout_info->userParam = (void *)1;
3730 }
3731
3732 s_last_wake_timeout_info
3733 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
3734 &TIMEVAL_WAKE_TIMEOUT);
3735 }
3736
3737 // Normal exit
3738 return;
3739
3740error_exit:
3741 if (shouldScheduleTimeout) {
3742 releaseWakeLock();
3743 }
3744}
3745
3746/** FIXME generalize this if you track UserCAllbackInfo, clear it
3747 when the callback occurs
3748*/
3749static UserCallbackInfo *
3750internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
3751 const struct timeval *relativeTime)
3752{
3753 struct timeval myRelativeTime;
3754 UserCallbackInfo *p_info;
3755
3756 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
3757
3758 p_info->p_callback = callback;
3759 p_info->userParam = param;
3760
3761 if (relativeTime == NULL) {
3762 /* treat null parameter as a 0 relative time */
3763 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
3764 } else {
3765 /* FIXME I think event_add's tv param is really const anyway */
3766 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
3767 }
3768
3769 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
3770
3771 ril_timer_add(&(p_info->event), &myRelativeTime);
3772
3773 triggerEvLoop();
3774 return p_info;
3775}
3776
3777
3778extern "C" void
3779RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
3780 const struct timeval *relativeTime) {
3781 internalRequestTimedCallback (callback, param, relativeTime);
3782}
3783
3784const char *
3785failCauseToString(RIL_Errno e) {
3786 switch(e) {
3787 case RIL_E_SUCCESS: return "E_SUCCESS";
codeworkxafc051f2013-07-27 09:02:14 +02003788 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003789 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
3790 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
3791 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
3792 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
3793 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
3794 case RIL_E_CANCELLED: return "E_CANCELLED";
3795 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
3796 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
3797 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
3798 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
3799 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
3800#ifdef FEATURE_MULTIMODE_ANDROID
3801 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
3802 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
3803#endif
3804 default: return "<unknown error>";
3805 }
3806}
3807
3808const char *
3809radioStateToString(RIL_RadioState s) {
3810 switch(s) {
3811 case RADIO_STATE_OFF: return "RADIO_OFF";
3812 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
3813 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
3814 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
3815 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
3816 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
3817 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
3818 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
3819 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
3820 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
3821 case RADIO_STATE_ON:return"RADIO_ON";
3822 default: return "<unknown state>";
3823 }
3824}
3825
3826const char *
3827callStateToString(RIL_CallState s) {
3828 switch(s) {
3829 case RIL_CALL_ACTIVE : return "ACTIVE";
3830 case RIL_CALL_HOLDING: return "HOLDING";
3831 case RIL_CALL_DIALING: return "DIALING";
3832 case RIL_CALL_ALERTING: return "ALERTING";
3833 case RIL_CALL_INCOMING: return "INCOMING";
3834 case RIL_CALL_WAITING: return "WAITING";
3835 default: return "<unknown state>";
3836 }
3837}
3838
3839const char *
3840requestToString(int request) {
3841/*
3842 cat libs/telephony/ril_commands.h \
3843 | egrep "^ *{RIL_" \
3844 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
3845
3846
3847 cat libs/telephony/ril_unsol_commands.h \
3848 | egrep "^ *{RIL_" \
3849 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
3850
3851*/
3852 switch(request) {
3853 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
3854 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
3855 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
3856 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
3857 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
3858 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
3859 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
3860 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
3861 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
3862 case RIL_REQUEST_DIAL: return "DIAL";
3863 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
3864 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
3865 case RIL_REQUEST_HANGUP: return "HANGUP";
3866 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
3867 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
3868 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
3869 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
3870 case RIL_REQUEST_UDUB: return "UDUB";
3871 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
3872 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
3873 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
3874 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
3875 case RIL_REQUEST_OPERATOR: return "OPERATOR";
3876 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
3877 case RIL_REQUEST_DTMF: return "DTMF";
3878 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
3879 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
3880 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
3881 case RIL_REQUEST_SIM_IO: return "SIM_IO";
3882 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
3883 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
3884 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
3885 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
3886 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
3887 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
3888 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
3889 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
3890 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
3891 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
3892 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
3893 case RIL_REQUEST_ANSWER: return "ANSWER";
3894 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
3895 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
3896 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
3897 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
3898 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
3899 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
3900 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
3901 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
3902 case RIL_REQUEST_DTMF_START: return "DTMF_START";
3903 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
3904 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
3905 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
3906 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
3907 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
3908 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
3909 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
3910 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
3911 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
3912 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
3913 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
3914 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
3915 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
3916 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
3917 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
3918 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
3919 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
3920 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
3921 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
3922 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
3923 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
3924 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
3925 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
3926 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
codeworkxafc051f2013-07-27 09:02:14 +02003927 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003928 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
3929 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
3930 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
3931 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
3932 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
3933 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
3934 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
3935 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
3936 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
3937 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
3938 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
3939 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
3940 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
3941 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
3942 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
codeworkxafc051f2013-07-27 09:02:14 +02003943 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003944 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
3945 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
3946 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
3947 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
3948 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
3949 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
3950 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
3951 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
3952 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
3953 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
3954 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
3955 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
3956 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
3957 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
codeworkxafc051f2013-07-27 09:02:14 +02003958 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
3959 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05003960 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
3961 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
3962 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003963 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
3964 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
3965 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
3966 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
3967 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
3968 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
3969 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
3970 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
3971 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
3972 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
3973 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
3974 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
3975 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
3976 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
3977 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
3978 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
3979 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
3980 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
3981 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
3982 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
3983 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
3984 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
3985 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
3986 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
3987 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
3988 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
3989 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
3990 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
3991 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
3992 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
3993 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
3994 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
3995 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
3996 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
3997 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
codeworkxafc051f2013-07-27 09:02:14 +02003998 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05003999 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Daniel Hillenbranda22f51c2013-09-04 23:46:58 +02004000 case RIL_UNSOL_STK_SEND_SMS_RESULT: return "RIL_UNSOL_STK_SEND_SMS_RESULT";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004001 default: return "<unknown request>";
4002 }
4003}
4004
4005} /* namespace android */