1 /* //guest/hals/ril/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 #include <guest/hals/ril/reference-libril/ril.h>
22 #include <telephony/ril_cdma_sms.h>
23 #include <cutils/sockets.h>
24 #include <telephony/record_stream.h>
25 #include <utils/Log.h>
26 #include <utils/SystemClock.h>
27 #include <pthread.h>
28 #include <sys/types.h>
29 #include <sys/limits.h>
30 #include <sys/system_properties.h>
31 #include <pwd.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 #include <time.h>
39 #include <errno.h>
40 #include <assert.h>
41 #include <ctype.h>
42 #include <sys/un.h>
43 #include <assert.h>
44 #include <netinet/in.h>
45 #include <cutils/properties.h>
46 #include <RilSapSocket.h>
47 #include <guest/hals/ril/reference-libril/ril_service.h>
48 #include <sap_service.h>
49
50 extern "C" void
51 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
52
53 extern "C" void
54 RIL_onRequestAck(RIL_Token t);
55 namespace android {
56
57 #define PHONE_PROCESS "radio"
58 #define BLUETOOTH_PROCESS "bluetooth"
59
60 #define ANDROID_WAKE_LOCK_NAME "radio-interface"
61
62 #define ANDROID_WAKE_LOCK_SECS 0
63 #define ANDROID_WAKE_LOCK_USECS 200000
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 /* Negative values for private RIL errno's */
78 #define RIL_ERRNO_INVALID_RESPONSE (-1)
79 #define RIL_ERRNO_NO_MEMORY (-12)
80
81 // request, response, and unsolicited msg print macro
82 #define PRINTBUF_SIZE 8096
83
84 enum WakeType {DONT_WAKE, WAKE_PARTIAL};
85
86 typedef struct {
87 int requestNumber;
88 int (*responseFunction) (int slotId, int responseType, int token,
89 RIL_Errno e, void *response, size_t responselen);
90 WakeType wakeType;
91 } UnsolResponseInfo;
92
93 typedef struct UserCallbackInfo {
94 RIL_TimedCallback p_callback;
95 void *userParam;
96 struct ril_event event;
97 struct UserCallbackInfo *p_next;
98 } UserCallbackInfo;
99
100 extern "C" const char * failCauseToString(RIL_Errno);
101 extern "C" const char * callStateToString(RIL_CallState);
102 extern "C" const char * radioStateToString(RIL_RadioState);
103 extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
104
105 extern "C"
106 char ril_service_name_base[MAX_SERVICE_NAME_LENGTH] = RIL_SERVICE_NAME_BASE;
107 extern "C"
108 char ril_service_name[MAX_SERVICE_NAME_LENGTH] = RIL1_SERVICE_NAME;
109 /*******************************************************************/
110
111 RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
112 static int s_registerCalled = 0;
113
114 static pthread_t s_tid_dispatch;
115 static int s_started = 0;
116
117 static int s_fdWakeupRead;
118 static int s_fdWakeupWrite;
119
120 int s_wakelock_count = 0;
121
122 static struct ril_event s_wakeupfd_event;
123
124 static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
125 static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
126 static RequestInfo *s_pendingRequests = NULL;
127
128 #if (SIM_COUNT >= 2)
129 static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
130 static RequestInfo *s_pendingRequests_socket2 = NULL;
131 #endif
132
133 #if (SIM_COUNT >= 3)
134 static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
135 static RequestInfo *s_pendingRequests_socket3 = NULL;
136 #endif
137
138 #if (SIM_COUNT >= 4)
139 static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
140 static RequestInfo *s_pendingRequests_socket4 = NULL;
141 #endif
142
143 static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
144
145
146 static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
147 static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
148
149 static UserCallbackInfo *s_last_wake_timeout_info = NULL;
150
151 static void *s_lastNITZTimeData = NULL;
152 static size_t s_lastNITZTimeDataSize;
153
154 #if RILC_LOG
155 static char printBuf[PRINTBUF_SIZE];
156 #endif
157
158 /*******************************************************************/
159 static void grabPartialWakeLock();
160 void releaseWakeLock();
161 static void wakeTimeoutCallback(void *);
162
163 #ifdef RIL_SHLIB
164 #if defined(ANDROID_MULTI_SIM)
165 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
166 size_t datalen, RIL_SOCKET_ID socket_id);
167 #else
168 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
169 size_t datalen);
170 #endif
171 #endif
172
173 #if defined(ANDROID_MULTI_SIM)
174 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
175 #else
176 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
177 #endif
178
179 static UserCallbackInfo * internalRequestTimedCallback
180 (RIL_TimedCallback callback, void *param,
181 const struct timeval *relativeTime);
182
183 /** Index == requestNumber */
184 static CommandInfo s_commands[] = {
185 #include "./ril_commands.h"
186 };
187
188 static UnsolResponseInfo s_unsolResponses[] = {
189 #include "./ril_unsol_commands.h"
190 };
191
192 /* Radio Config Request @{ */
193 static CommandInfo s_configCommands[] = {
194 #include "./ril_config_commands.h"
195 };
196
197 static UnsolResponseInfo s_configUnsolResponses[] = {
198 #include "./ril_config_unsol_commands.h"
199 };
200 /* }@ */
201
RIL_getServiceName()202 char * RIL_getServiceName() {
203 return ril_service_name;
204 }
205
206 RequestInfo *
addRequestToList(int serial,int slotId,int request)207 addRequestToList(int serial, int slotId, int request) {
208 RequestInfo *pRI = nullptr;
209 int ret;
210 RIL_SOCKET_ID socket_id = (RIL_SOCKET_ID) slotId;
211 /* Hook for current context */
212 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
213 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
214 /* pendingRequestsHook refer to &s_pendingRequests */
215 RequestInfo** pendingRequestsHook = &s_pendingRequests;
216
217 #if (SIM_COUNT >= 2)
218 if (socket_id == RIL_SOCKET_2) {
219 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
220 pendingRequestsHook = &s_pendingRequests_socket2;
221 }
222 #if (SIM_COUNT >= 3)
223 else if (socket_id == RIL_SOCKET_3) {
224 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
225 pendingRequestsHook = &s_pendingRequests_socket3;
226 }
227 #endif
228 #if (SIM_COUNT >= 4)
229 else if (socket_id == RIL_SOCKET_4) {
230 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
231 pendingRequestsHook = &s_pendingRequests_socket4;
232 }
233 #endif
234 #endif
235
236 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
237 if (pRI == NULL) {
238 RLOGE("Memory allocation failed for request %s", requestToString(request));
239 return NULL;
240 }
241
242 pRI->token = serial;
243 pRI->pCI = &(s_commands[request]);
244
245 if (request >= RIL_REQUEST_RADIO_CONFIG_BASE &&
246 request <= RIL_REQUEST_RADIO_CONFIG_LAST) {
247 request = request - RIL_REQUEST_RADIO_CONFIG_BASE;
248 pRI->pCI = &(s_configCommands[request]);
249 }
250
251 pRI->socket_id = socket_id;
252
253 ret = pthread_mutex_lock(pendingRequestsMutexHook);
254 assert (ret == 0);
255
256 pRI->p_next = *pendingRequestsHook;
257 *pendingRequestsHook = pRI;
258
259 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
260 assert (ret == 0);
261
262 return pRI;
263 }
264
triggerEvLoop()265 static void triggerEvLoop() {
266 int ret;
267 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
268 /* trigger event loop to wakeup. No reason to do this,
269 * if we're in the event loop thread */
270 do {
271 ret = write (s_fdWakeupWrite, " ", 1);
272 } while (ret < 0 && errno == EINTR);
273 }
274 }
275
rilEventAddWakeup(struct ril_event * ev)276 static void rilEventAddWakeup(struct ril_event *ev) {
277 ril_event_add(ev);
278 triggerEvLoop();
279 }
280
281 /**
282 * A write on the wakeup fd is done just to pop us out of select()
283 * We empty the buffer here and then ril_event will reset the timers on the
284 * way back down
285 */
processWakeupCallback(int fd,short flags,void * param)286 static void processWakeupCallback(int fd, short flags, void *param) {
287 char buff[16];
288 int ret;
289
290 RLOGV("processWakeupCallback");
291
292 /* empty our wakeup socket out */
293 do {
294 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
295 } while (ret > 0 || (ret < 0 && errno == EINTR));
296 }
297
resendLastNITZTimeData(RIL_SOCKET_ID socket_id)298 static void resendLastNITZTimeData(RIL_SOCKET_ID socket_id) {
299 if (s_lastNITZTimeData != NULL) {
300 int responseType = (s_callbacks.version >= 13)
301 ? RESPONSE_UNSOLICITED_ACK_EXP
302 : RESPONSE_UNSOLICITED;
303 // acquire read lock for the service before calling nitzTimeReceivedInd() since it reads
304 // nitzTimeReceived in ril_service
305 pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(
306 (int) socket_id);
307 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
308 assert(rwlockRet == 0);
309
310 int ret = radio_1_6::nitzTimeReceivedInd(
311 (int)socket_id, responseType, 0,
312 RIL_E_SUCCESS, s_lastNITZTimeData, s_lastNITZTimeDataSize);
313 if (ret == 0) {
314 free(s_lastNITZTimeData);
315 s_lastNITZTimeData = NULL;
316 }
317
318 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
319 assert(rwlockRet == 0);
320 }
321 }
322
onNewCommandConnect(RIL_SOCKET_ID socket_id)323 void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
324 // Inform we are connected and the ril version
325 int rilVer = s_callbacks.version;
326 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
327 &rilVer, sizeof(rilVer), socket_id);
328
329 // implicit radio state changed
330 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
331 NULL, 0, socket_id);
332
333 // Send last NITZ time data, in case it was missed
334 if (s_lastNITZTimeData != NULL) {
335 resendLastNITZTimeData(socket_id);
336 }
337
338 // Get version string
339 if (s_callbacks.getVersion != NULL) {
340 const char *version;
341 version = s_callbacks.getVersion();
342 RLOGI("RIL Daemon version: %s\n", version);
343
344 property_set(PROPERTY_RIL_IMPL, version);
345 } else {
346 RLOGI("RIL Daemon version: unavailable\n");
347 property_set(PROPERTY_RIL_IMPL, "unavailable");
348 }
349
350 }
351
userTimerCallback(int fd,short flags,void * param)352 static void userTimerCallback (int fd, short flags, void *param) {
353 UserCallbackInfo *p_info;
354
355 p_info = (UserCallbackInfo *)param;
356
357 p_info->p_callback(p_info->userParam);
358
359
360 // FIXME generalize this...there should be a cancel mechanism
361 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
362 s_last_wake_timeout_info = NULL;
363 }
364
365 free(p_info);
366 }
367
368
369 static void *
eventLoop(void * param)370 eventLoop(void *param) {
371 int ret;
372 int filedes[2];
373
374 ril_event_init();
375
376 pthread_mutex_lock(&s_startupMutex);
377
378 s_started = 1;
379 pthread_cond_broadcast(&s_startupCond);
380
381 pthread_mutex_unlock(&s_startupMutex);
382
383 ret = pipe(filedes);
384
385 if (ret < 0) {
386 RLOGE("Error in pipe() errno:%d", errno);
387 return NULL;
388 }
389
390 s_fdWakeupRead = filedes[0];
391 s_fdWakeupWrite = filedes[1];
392
393 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
394
395 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
396 processWakeupCallback, NULL);
397
398 rilEventAddWakeup (&s_wakeupfd_event);
399
400 // Only returns on error
401 ril_event_loop();
402 RLOGE ("error in event_loop_base errno:%d", errno);
403 // kill self to restart on error
404 kill(0, SIGKILL);
405
406 return NULL;
407 }
408
409 extern "C" void
RIL_startEventLoop(void)410 RIL_startEventLoop(void) {
411 /* spin up eventLoop thread and wait for it to get started */
412 s_started = 0;
413 pthread_mutex_lock(&s_startupMutex);
414
415 pthread_attr_t attr;
416 pthread_attr_init(&attr);
417 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
418
419 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
420 if (result != 0) {
421 RLOGE("Failed to create dispatch thread: %s", strerror(result));
422 goto done;
423 }
424
425 while (s_started == 0) {
426 pthread_cond_wait(&s_startupCond, &s_startupMutex);
427 }
428
429 done:
430 pthread_mutex_unlock(&s_startupMutex);
431 }
432
433 // Used for testing purpose only.
RIL_setcallbacks(const RIL_RadioFunctions * callbacks)434 extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
435 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
436 }
437
438 extern "C" void
RIL_register(const RIL_RadioFunctions * callbacks)439 RIL_register (const RIL_RadioFunctions *callbacks) {
440 RLOGI("SIM_COUNT: %d", SIM_COUNT);
441
442 if (callbacks == NULL) {
443 RLOGE("RIL_register: RIL_RadioFunctions * null");
444 return;
445 }
446 if (callbacks->version < RIL_VERSION_MIN) {
447 RLOGE("RIL_register: version %d is to old, min version is %d",
448 callbacks->version, RIL_VERSION_MIN);
449 return;
450 }
451
452 RLOGD("RIL_register: Vsoc RIL version %d", callbacks->version);
453
454 if (s_registerCalled > 0) {
455 RLOGE("RIL_register has been called more than once. "
456 "Subsequent call ignored");
457 return;
458 }
459
460 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
461
462 s_registerCalled = 1;
463
464 RLOGI("s_registerCalled flag set, %d", s_started);
465 // Little self-check
466
467 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
468 assert(i == s_commands[i].requestNumber);
469 }
470
471 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
472 assert(i + RIL_UNSOL_RESPONSE_BASE
473 == s_unsolResponses[i].requestNumber);
474 }
475
476 radio_1_6::registerService(&s_callbacks, s_commands);
477 RLOGI("RILHIDL called registerService");
478
479 /* Radio Config Request @{ */
480 for (int i = 1; i < (int)NUM_ELEMS(s_configCommands); i++) {
481 assert(i == s_configCommands[i].requestNumber -
482 RIL_REQUEST_RADIO_CONFIG_BASE);
483 }
484
485 for (int i = 0; i < (int)NUM_ELEMS(s_configUnsolResponses); i++) {
486 assert(i == s_configUnsolResponses[i].requestNumber -
487 RIL_UNSOL_RESPONSE_RADIO_CONFIG_BASE);
488 }
489 radio_1_6::registerConfigService(&s_callbacks, s_configCommands);
490 /* }@ */
491
492 sap::registerService(&s_callbacks);
493 }
494
495 extern "C" void
RIL_register_socket(const RIL_RadioFunctions * (* Init)(const struct RIL_Env *,int,char **),RIL_SOCKET_TYPE socketType,int argc,char ** argv)496 RIL_register_socket (const RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),
497 RIL_SOCKET_TYPE socketType, int argc, char **argv) {
498
499 const RIL_RadioFunctions* UimFuncs = NULL;
500
501 if(Init) {
502 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
503
504 switch(socketType) {
505 case RIL_SAP_SOCKET:
506 RilSapSocket::initSapSocket(RIL1_SERVICE_NAME, UimFuncs);
507
508 #if (SIM_COUNT >= 2)
509 RilSapSocket::initSapSocket(RIL2_SERVICE_NAME, UimFuncs);
510 #endif
511
512 #if (SIM_COUNT >= 3)
513 RilSapSocket::initSapSocket(RIL3_SERVICE_NAME, UimFuncs);
514 #endif
515
516 #if (SIM_COUNT >= 4)
517 RilSapSocket::initSapSocket(RIL4_SERVICE_NAME, UimFuncs);
518 #endif
519 break;
520 default:;
521 }
522
523 RLOGI("RIL_register_socket: calling registerService");
524 sap::registerService(UimFuncs);
525 }
526 }
527
528 // Check and remove RequestInfo if its a response and not just ack sent back
529 static int
checkAndDequeueRequestInfoIfAck(struct RequestInfo * pRI,bool isAck)530 checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
531 int ret = 0;
532 /* Hook for current context
533 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
534 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
535 /* pendingRequestsHook refer to &s_pendingRequests */
536 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
537
538 if (pRI == NULL) {
539 return 0;
540 }
541
542 #if (SIM_COUNT >= 2)
543 if (pRI->socket_id == RIL_SOCKET_2) {
544 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
545 pendingRequestsHook = &s_pendingRequests_socket2;
546 }
547 #if (SIM_COUNT >= 3)
548 if (pRI->socket_id == RIL_SOCKET_3) {
549 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
550 pendingRequestsHook = &s_pendingRequests_socket3;
551 }
552 #endif
553 #if (SIM_COUNT >= 4)
554 if (pRI->socket_id == RIL_SOCKET_4) {
555 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
556 pendingRequestsHook = &s_pendingRequests_socket4;
557 }
558 #endif
559 #endif
560 pthread_mutex_lock(pendingRequestsMutexHook);
561
562 for(RequestInfo **ppCur = pendingRequestsHook
563 ; *ppCur != NULL
564 ; ppCur = &((*ppCur)->p_next)
565 ) {
566 if (pRI == *ppCur) {
567 ret = 1;
568 if (isAck) { // Async ack
569 if (pRI->wasAckSent == 1) {
570 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
571 } else {
572 pRI->wasAckSent = 1;
573 }
574 } else {
575 *ppCur = (*ppCur)->p_next;
576 }
577 break;
578 }
579 }
580
581 pthread_mutex_unlock(pendingRequestsMutexHook);
582
583 return ret;
584 }
585
586 extern "C" void
RIL_onRequestAck(RIL_Token t)587 RIL_onRequestAck(RIL_Token t) {
588 RequestInfo *pRI;
589
590 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
591
592 pRI = (RequestInfo *)t;
593
594 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
595 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
596 return;
597 }
598
599 socket_id = pRI->socket_id;
600
601 #if VDBG
602 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
603 #endif
604
605 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
606
607 if (pRI->cancelled == 0) {
608 pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(
609 (int) socket_id);
610 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
611 assert(rwlockRet == 0);
612
613 radio_1_6::acknowledgeRequest((int) socket_id, pRI->token);
614
615 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
616 assert(rwlockRet == 0);
617 }
618 }
619 extern "C" void
RIL_onRequestComplete(RIL_Token t,RIL_Errno e,void * response,size_t responselen)620 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
621 RequestInfo* pRI;
622 int ret;
623 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
624
625 pRI = (RequestInfo *)t;
626
627 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
628 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
629 return;
630 }
631
632 socket_id = pRI->socket_id;
633
634 #if VDBG
635 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
636 #endif
637
638 if (pRI->local > 0) {
639 // Locally issued command...void only!
640 // response does not go back up the command socket
641 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
642
643 free(pRI);
644 return;
645 }
646
647 appendPrintBuf("[%04d]< %s",
648 pRI->token, requestToString(pRI->pCI->requestNumber));
649
650 if (pRI->cancelled == 0) {
651 int responseType;
652 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
653 // If ack was already sent, then this call is an asynchronous response. So we need to
654 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
655 responseType = RESPONSE_SOLICITED_ACK_EXP;
656 grabPartialWakeLock();
657 } else {
658 responseType = RESPONSE_SOLICITED;
659 }
660
661 // there is a response payload, no matter success or not.
662 #if VDBG
663 RLOGE ("Calling responseFunction() for token %d", pRI->token);
664 #endif
665
666 pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock((int) socket_id);
667 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
668 assert(rwlockRet == 0);
669
670 ret = pRI->pCI->responseFunction((int) socket_id,
671 responseType, pRI->token, e, response, responselen);
672
673 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
674 assert(rwlockRet == 0);
675 }
676 free(pRI);
677 }
678
679 static void
grabPartialWakeLock()680 grabPartialWakeLock() {
681 if (s_callbacks.version >= 13) {
682 int ret;
683 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
684 assert(ret == 0);
685 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
686
687 UserCallbackInfo *p_info =
688 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
689 if (p_info == NULL) {
690 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
691 } else {
692 s_wakelock_count++;
693 if (s_last_wake_timeout_info != NULL) {
694 s_last_wake_timeout_info->userParam = (void *)1;
695 }
696 s_last_wake_timeout_info = p_info;
697 }
698 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
699 assert(ret == 0);
700 } else {
701 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
702 }
703 }
704
705 void
releaseWakeLock()706 releaseWakeLock() {
707 if (s_callbacks.version >= 13) {
708 int ret;
709 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
710 assert(ret == 0);
711
712 if (s_wakelock_count > 1) {
713 s_wakelock_count--;
714 } else {
715 s_wakelock_count = 0;
716 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
717 if (s_last_wake_timeout_info != NULL) {
718 s_last_wake_timeout_info->userParam = (void *)1;
719 }
720 }
721
722 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
723 assert(ret == 0);
724 } else {
725 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
726 }
727 }
728
729 /**
730 * Timer callback to put us back to sleep before the default timeout
731 */
732 static void
wakeTimeoutCallback(void * param)733 wakeTimeoutCallback (void *param) {
734 // We're using "param != NULL" as a cancellation mechanism
735 if (s_callbacks.version >= 13) {
736 if (param == NULL) {
737 int ret;
738 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
739 assert(ret == 0);
740 s_wakelock_count = 0;
741 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
742 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
743 assert(ret == 0);
744 }
745 } else {
746 if (param == NULL) {
747 releaseWakeLock();
748 }
749 }
750 }
751
752 #if defined(ANDROID_MULTI_SIM)
753 extern "C"
RIL_onUnsolicitedResponse(int unsolResponse,const void * data,size_t datalen,RIL_SOCKET_ID socket_id)754 void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
755 size_t datalen, RIL_SOCKET_ID socket_id)
756 #else
757 extern "C"
758 void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
759 size_t datalen)
760 #endif
761 {
762 int unsolResponseIndex;
763 int ret;
764 bool shouldScheduleTimeout = false;
765 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
766 UnsolResponseInfo *pURI = NULL;
767
768 #if defined(ANDROID_MULTI_SIM)
769 soc_id = socket_id;
770 #endif
771
772
773 if (s_registerCalled == 0) {
774 // Ignore RIL_onUnsolicitedResponse before RIL_register
775 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
776 return;
777 }
778
779 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
780
781 if ((unsolResponse < RIL_UNSOL_RESPONSE_BASE)
782 || (unsolResponse > RIL_UNSOL_RESPONSE_LAST
783 && unsolResponse < RIL_UNSOL_RESPONSE_RADIO_CONFIG_BASE)
784 || (unsolResponse > RIL_UNSOL_RESPONSE_RADIO_CONFIG_LAST)) {
785 RLOGE("unsupported unsolicited response code %d", unsolResponse);
786 return;
787 }
788
789 if (unsolResponse >= RIL_UNSOL_RESPONSE_BASE
790 && unsolResponse <= RIL_UNSOL_RESPONSE_LAST) {
791 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
792 pURI = &(s_unsolResponses[unsolResponseIndex]);
793 } else if (unsolResponse >= RIL_UNSOL_RESPONSE_RADIO_CONFIG_BASE
794 && unsolResponse <= RIL_UNSOL_RESPONSE_RADIO_CONFIG_LAST) {
795 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_RADIO_CONFIG_BASE;
796 pURI = &(s_configUnsolResponses[unsolResponseIndex]);
797 }
798
799 // Grab a wake lock if needed for this response,
800 // as we exit we'll either release it immediately
801 // or set a timer to release it later.
802 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
803 case WAKE_PARTIAL:
804 grabPartialWakeLock();
805 shouldScheduleTimeout = true;
806 break;
807
808 case DONT_WAKE:
809 default:
810 // No wake lock is grabbed so don't set timeout
811 shouldScheduleTimeout = false;
812 break;
813 }
814
815 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
816
817 int responseType;
818 if (s_callbacks.version >= 13
819 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
820 responseType = RESPONSE_UNSOLICITED_ACK_EXP;
821 } else {
822 responseType = RESPONSE_UNSOLICITED;
823 }
824
825 pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock((int) soc_id);
826 int rwlockRet;
827
828 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
829 // get a write lock in caes of NITZ since setNitzTimeReceived() is called
830 rwlockRet = pthread_rwlock_wrlock(radioServiceRwlockPtr);
831 assert(rwlockRet == 0);
832 radio_1_6::setNitzTimeReceived((int) soc_id, android::elapsedRealtime());
833 } else {
834 rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
835 assert(rwlockRet == 0);
836 }
837
838 if (pURI != NULL && pURI->responseFunction != NULL) {
839 ret = pURI->responseFunction((int) soc_id, responseType, 0, RIL_E_SUCCESS,
840 const_cast<void*>(data), datalen);
841 } else {
842 RLOGW("No call responseFunction defined for UNSOLICITED");
843 }
844
845 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
846 assert(rwlockRet == 0);
847
848 if (s_callbacks.version < 13) {
849 if (shouldScheduleTimeout) {
850 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
851 &TIMEVAL_WAKE_TIMEOUT);
852
853 if (p_info == NULL) {
854 goto error_exit;
855 } else {
856 // Cancel the previous request
857 if (s_last_wake_timeout_info != NULL) {
858 s_last_wake_timeout_info->userParam = (void *)1;
859 }
860 s_last_wake_timeout_info = p_info;
861 }
862 }
863 }
864
865 #if VDBG
866 RLOGI("%s UNSOLICITED: %s length:%zu", rilSocketIdToString(soc_id),
867 requestToString(unsolResponse), datalen);
868 #endif
869
870 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
871 // Unfortunately, NITZ time is not poll/update like everything
872 // else in the system. So, if the upstream client isn't connected,
873 // keep a copy of the last NITZ response (with receive time noted
874 // above) around so we can deliver it when it is connected
875
876 if (s_lastNITZTimeData != NULL) {
877 free(s_lastNITZTimeData);
878 s_lastNITZTimeData = NULL;
879 }
880
881 s_lastNITZTimeData = calloc(datalen, 1);
882 if (s_lastNITZTimeData == NULL) {
883 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
884 goto error_exit;
885 }
886 s_lastNITZTimeDataSize = datalen;
887 memcpy(s_lastNITZTimeData, data, datalen);
888 }
889
890 // Normal exit
891 return;
892
893 error_exit:
894 if (shouldScheduleTimeout) {
895 releaseWakeLock();
896 }
897 }
898
899 /** FIXME generalize this if you track UserCAllbackInfo, clear it
900 when the callback occurs
901 */
902 static UserCallbackInfo *
internalRequestTimedCallback(RIL_TimedCallback callback,void * param,const struct timeval * relativeTime)903 internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
904 const struct timeval *relativeTime)
905 {
906 struct timeval myRelativeTime;
907 UserCallbackInfo *p_info;
908
909 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
910 if (p_info == NULL) {
911 RLOGE("Memory allocation failed in internalRequestTimedCallback");
912 return p_info;
913
914 }
915
916 p_info->p_callback = callback;
917 p_info->userParam = param;
918
919 if (relativeTime == NULL) {
920 /* treat null parameter as a 0 relative time */
921 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
922 } else {
923 /* FIXME I think event_add's tv param is really const anyway */
924 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
925 }
926
927 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
928
929 ril_timer_add(&(p_info->event), &myRelativeTime);
930
931 triggerEvLoop();
932 return p_info;
933 }
934
935
936 extern "C" void
RIL_requestTimedCallback(RIL_TimedCallback callback,void * param,const struct timeval * relativeTime)937 RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
938 const struct timeval *relativeTime) {
939 internalRequestTimedCallback (callback, param, relativeTime);
940 }
941
942 const char *
failCauseToString(RIL_Errno e)943 failCauseToString(RIL_Errno e) {
944 switch(e) {
945 case RIL_E_SUCCESS: return "E_SUCCESS";
946 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
947 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
948 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
949 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
950 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
951 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
952 case RIL_E_CANCELLED: return "E_CANCELLED";
953 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
954 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
955 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
956 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
957 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
958 #ifdef FEATURE_MULTIMODE_ANDROID
959 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
960 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
961 #endif
962 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
963 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
964 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
965 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
966 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
967 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
968 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
969 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
970 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
971 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
972 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
973 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
974 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
975 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
976 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
977 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
978 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
979 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
980 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
981 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
982 case RIL_E_SIM_ERR: return "E_SIM_ERR";
983 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
984 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
985 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
986 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
987 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
988 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
989 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
990 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
991 case RIL_E_SIM_FULL: return "E_SIM_FULL";
992 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
993 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
994 case RIL_E_EMPTY_RECORD: return "E_EMPTY_RECORD";
995 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
996 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
997 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
998 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
999 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
1000 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
1001 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
1002 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
1003 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
1004 case RIL_E_ABORTED: return "E_ABORTED";
1005 case RIL_E_INVALID_RESPONSE: return "INVALID_RESPONSE";
1006 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
1007 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
1008 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
1009 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
1010 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
1011 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
1012 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
1013 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
1014 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
1015 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
1016 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
1017 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
1018 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
1019 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
1020 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
1021 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
1022 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
1023 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
1024 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
1025 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
1026 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
1027 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
1028 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
1029 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
1030 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
1031 default: return "<unknown error>";
1032 }
1033 }
1034
1035 const char *
radioStateToString(RIL_RadioState s)1036 radioStateToString(RIL_RadioState s) {
1037 switch(s) {
1038 case RADIO_STATE_OFF: return "RADIO_OFF";
1039 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
1040 case RADIO_STATE_ON:return"RADIO_ON";
1041 default: return "<unknown state>";
1042 }
1043 }
1044
1045 const char *
callStateToString(RIL_CallState s)1046 callStateToString(RIL_CallState s) {
1047 switch(s) {
1048 case RIL_CALL_ACTIVE : return "ACTIVE";
1049 case RIL_CALL_HOLDING: return "HOLDING";
1050 case RIL_CALL_DIALING: return "DIALING";
1051 case RIL_CALL_ALERTING: return "ALERTING";
1052 case RIL_CALL_INCOMING: return "INCOMING";
1053 case RIL_CALL_WAITING: return "WAITING";
1054 default: return "<unknown state>";
1055 }
1056 }
1057
1058 const char *
requestToString(int request)1059 requestToString(int request) {
1060 /*
1061 cat guest/hals/ril/reference-libril/ril_commands.h \
1062 | egrep "^ *{RIL_" \
1063 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
1064
1065
1066 cat guest/hals/ril/reference-libril/ril_unsol_commands.h \
1067 | egrep "^ *{RIL_" \
1068 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
1069
1070 */
1071 switch(request) {
1072 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
1073 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
1074 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
1075 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
1076 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
1077 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
1078 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
1079 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
1080 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
1081 case RIL_REQUEST_DIAL: return "DIAL";
1082 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
1083 case RIL_REQUEST_HANGUP: return "HANGUP";
1084 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
1085 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
1086 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
1087 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
1088 case RIL_REQUEST_UDUB: return "UDUB";
1089 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
1090 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
1091 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
1092 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
1093 case RIL_REQUEST_OPERATOR: return "OPERATOR";
1094 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
1095 case RIL_REQUEST_DTMF: return "DTMF";
1096 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
1097 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
1098 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
1099 case RIL_REQUEST_SIM_IO: return "SIM_IO";
1100 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
1101 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
1102 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
1103 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
1104 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
1105 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
1106 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
1107 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
1108 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
1109 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
1110 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
1111 case RIL_REQUEST_ANSWER: return "ANSWER";
1112 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
1113 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
1114 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
1115 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
1116 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
1117 case RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS: return "RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS";
1118 case RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS: return "RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS";
1119 case RIL_REQUEST_START_NETWORK_SCAN: return "RIL_REQUEST_START_NETWORK_SCAN";
1120 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
1121 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
1122 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: return "QUERY_AVAILABLE_NETWORKS";
1123 case RIL_REQUEST_DTMF_START: return "DTMF_START";
1124 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
1125 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
1126 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
1127 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
1128 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
1129 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
1130 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
1131 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
1132 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
1133 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
1134 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
1135 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
1136 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
1137 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
1138 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
1139 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
1140 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
1141 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
1142 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
1143 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
1144 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
1145 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
1146 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
1147 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
1148 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
1149 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
1150 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
1151 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE";
1152 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "CDMA_SET_ROAMING_PREFERENCE";
1153 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "CDMA_QUERY_ROAMING_PREFERENCE";
1154 case RIL_REQUEST_SET_TTY_MODE: return "SET_TTY_MODE";
1155 case RIL_REQUEST_QUERY_TTY_MODE: return "QUERY_TTY_MODE";
1156 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
1157 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
1158 case RIL_REQUEST_CDMA_FLASH: return "CDMA_FLASH";
1159 case RIL_REQUEST_CDMA_BURST_DTMF: return "CDMA_BURST_DTMF";
1160 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY";
1161 case RIL_REQUEST_CDMA_SEND_SMS: return "CDMA_SEND_SMS";
1162 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "CDMA_SMS_ACKNOWLEDGE";
1163 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: return "GSM_GET_BROADCAST_SMS_CONFIG";
1164 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: return "GSM_SET_BROADCAST_SMS_CONFIG";
1165 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: return "GSM_SMS_BROADCAST_ACTIVATION";
1166 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: return "CDMA_GET_BROADCAST_SMS_CONFIG";
1167 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: return "CDMA_SET_BROADCAST_SMS_CONFIG";
1168 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: return "CDMA_SMS_BROADCAST_ACTIVATION";
1169 case RIL_REQUEST_CDMA_SUBSCRIPTION: return "CDMA_SUBSCRIPTION";
1170 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
1171 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
1172 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
1173 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
1174 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
1175 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
1176 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
1177 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
1178 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
1179 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
1180 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
1181 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "STK_SEND_ENVELOPE_WITH_STATUS";
1182 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
1183 case RIL_REQUEST_GET_CELL_INFO_LIST: return "GET_CELL_INFO_LIST";
1184 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "SET_UNSOL_CELL_INFO_LIST_RATE";
1185 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "SET_INITIAL_ATTACH_APN";
1186 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
1187 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
1188 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
1189 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
1190 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
1191 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
1192 case RIL_REQUEST_NV_READ_ITEM: return "NV_READ_ITEM";
1193 case RIL_REQUEST_NV_WRITE_ITEM: return "NV_WRITE_ITEM";
1194 case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "NV_WRITE_CDMA_PRL";
1195 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
1196 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
1197 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
1198 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
1199 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
1200 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
1201 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
1202 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
1203 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
1204 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "GET_RADIO_CAPABILITY";
1205 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "SET_RADIO_CAPABILITY";
1206 case RIL_REQUEST_START_LCE: return "START_LCE";
1207 case RIL_REQUEST_STOP_LCE: return "STOP_LCE";
1208 case RIL_REQUEST_PULL_LCEDATA: return "PULL_LCEDATA";
1209 case RIL_REQUEST_GET_ACTIVITY_INFO: return "GET_ACTIVITY_INFO";
1210 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
1211 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
1212 case RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION: return "SET_CARRIER_INFO_IMSI_ENCRYPTION";
1213 case RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA: return "SET_SIGNAL_STRENGTH_REPORTING_CRITERIA";
1214 case RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA: return "SET_LINK_CAPACITY_REPORTING_CRITERIA";
1215 case RIL_REQUEST_ENABLE_UICC_APPLICATIONS: return "ENABLE_UICC_APPLICATIONS";
1216 case RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED: return "ARE_UICC_APPLICATIONS_ENABLED";
1217 case RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION: return "ENTER_SIM_DEPERSONALIZATION";
1218 case RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE: return "CDMA_SEND_SMS_EXPECT_MORE";
1219 case RIL_REQUEST_GET_BARRING_INFO: return "GET_BARRING_INFO";
1220 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE_BITMAP: return "SET_PREFERRED_NETWORK_TYPE_BITMAP";
1221 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE_BITMAP: return "GET_PREFERRED_NETWORK_TYPE_BITMAP";
1222 case RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP: return "SET_ALLOWED_NETWORK_TYPES_BITMAP";
1223 case RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP: return "GET_ALLOWED_NETWORK_TYPES_BITMAP";
1224 case RIL_REQUEST_GET_SLICING_CONFIG: return "GET_SLICING_CONFIG";
1225 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT";
1226 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
1227 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
1228 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
1229 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
1230 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
1231 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
1232 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
1233 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
1234 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
1235 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
1236 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
1237 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
1238 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
1239 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
1240 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
1241 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
1242 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
1243 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
1244 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
1245 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
1246 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
1247 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
1248 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
1249 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
1250 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
1251 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
1252 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
1253 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
1254 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
1255 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
1256 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
1257 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
1258 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
1259 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
1260 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
1261 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
1262 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
1263 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
1264 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
1265 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
1266 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "UNSOL_HARDWARE_CONFIG_CHANGED";
1267 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
1268 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
1269 case RIL_UNSOL_MODEM_RESTART: return "UNSOL_MODEM_RESTART";
1270 case RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION: return "UNSOL_CARRIER_INFO_IMSI_ENCRYPTION";
1271 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
1272 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
1273 case RIL_UNSOL_LCEDATA_RECV: return "UNSOL_LCEDATA_RECV";
1274 case RIL_UNSOL_PCO_DATA: return "UNSOL_PCO_DATA";
1275 default: return "<unknown request>";
1276 }
1277 }
1278
1279 const char *
rilSocketIdToString(RIL_SOCKET_ID socket_id)1280 rilSocketIdToString(RIL_SOCKET_ID socket_id)
1281 {
1282 switch(socket_id) {
1283 case RIL_SOCKET_1:
1284 return "RIL_SOCKET_1";
1285 #if (SIM_COUNT >= 2)
1286 case RIL_SOCKET_2:
1287 return "RIL_SOCKET_2";
1288 #endif
1289 #if (SIM_COUNT >= 3)
1290 case RIL_SOCKET_3:
1291 return "RIL_SOCKET_3";
1292 #endif
1293 #if (SIM_COUNT >= 4)
1294 case RIL_SOCKET_4:
1295 return "RIL_SOCKET_4";
1296 #endif
1297 default:
1298 return "not a valid RIL";
1299 }
1300 }
1301
1302 } /* namespace android */
1303