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