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