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