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 <telephony/record_stream.h>
25 #include <utils/Log.h>
26 #include <utils/SystemClock.h>
27 #include <pthread.h>
28 #include <sys/types.h>
29 #include <sys/limits.h>
30 #include <sys/system_properties.h>
31 #include <pwd.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 #include <time.h>
39 #include <errno.h>
40 #include <assert.h>
41 #include <ctype.h>
42 #include <sys/un.h>
43 #include <assert.h>
44 #include <netinet/in.h>
45 #include <cutils/properties.h>
46 #include <RilSapSocket.h>
47 #include <guest/hals/ril/libril/ril_service.h>
48 #include <sap_service.h>
49
50 extern "C" void
51 RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
52
53 extern "C" void
54 RIL_onRequestAck(RIL_Token t);
55 namespace android {
56
57 #define PHONE_PROCESS "radio"
58 #define BLUETOOTH_PROCESS "bluetooth"
59
60 #define ANDROID_WAKE_LOCK_NAME "radio-interface"
61
62 #define ANDROID_WAKE_LOCK_SECS 0
63 #define ANDROID_WAKE_LOCK_USECS 200000
64
65 #define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
66
67 // match with constant in RIL.java
68 #define MAX_COMMAND_BYTES (8 * 1024)
69
70 // Basically: memset buffers that the client library
71 // shouldn't be using anymore in an attempt to find
72 // memory usage issues sooner.
73 #define MEMSET_FREED 1
74
75 #define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
76
77 /* Negative values for private RIL errno's */
78 #define RIL_ERRNO_INVALID_RESPONSE (-1)
79 #define RIL_ERRNO_NO_MEMORY (-12)
80
81 // request, response, and unsolicited msg print macro
82 #define PRINTBUF_SIZE 8096
83
84 enum WakeType {DONT_WAKE, WAKE_PARTIAL};
85
86 typedef struct {
87 int requestNumber;
88 int (*responseFunction) (int slotId, int responseType, int token,
89 RIL_Errno e, void *response, size_t responselen);
90 WakeType wakeType;
91 } UnsolResponseInfo;
92
93 typedef struct UserCallbackInfo {
94 RIL_TimedCallback p_callback;
95 void *userParam;
96 struct ril_event event;
97 struct UserCallbackInfo *p_next;
98 } UserCallbackInfo;
99
100 extern "C" const char * failCauseToString(RIL_Errno);
101 extern "C" const char * callStateToString(RIL_CallState);
102 extern "C" const char * radioStateToString(RIL_RadioState);
103 extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
104
105 extern "C"
106 char ril_service_name_base[MAX_SERVICE_NAME_LENGTH] = RIL_SERVICE_NAME_BASE;
107 extern "C"
108 char ril_service_name[MAX_SERVICE_NAME_LENGTH] = RIL1_SERVICE_NAME;
109 /*******************************************************************/
110
111 RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
112 static int s_registerCalled = 0;
113
114 static pthread_t s_tid_dispatch;
115 static int s_started = 0;
116
117 static int s_fdWakeupRead;
118 static int s_fdWakeupWrite;
119
120 int s_wakelock_count = 0;
121
122 static struct ril_event s_wakeupfd_event;
123
124 static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
125 static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
126 static RequestInfo *s_pendingRequests = NULL;
127
128 #if (SIM_COUNT >= 2)
129 static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
130 static RequestInfo *s_pendingRequests_socket2 = NULL;
131 #endif
132
133 #if (SIM_COUNT >= 3)
134 static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
135 static RequestInfo *s_pendingRequests_socket3 = NULL;
136 #endif
137
138 #if (SIM_COUNT >= 4)
139 static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
140 static RequestInfo *s_pendingRequests_socket4 = NULL;
141 #endif
142
143 static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
144
145
146 static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
147 static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
148
149 static UserCallbackInfo *s_last_wake_timeout_info = NULL;
150
151 static void *s_lastNITZTimeData = NULL;
152 static size_t s_lastNITZTimeDataSize;
153
154 #if RILC_LOG
155 static char printBuf[PRINTBUF_SIZE];
156 #endif
157
158 /*******************************************************************/
159 static void grabPartialWakeLock();
160 void releaseWakeLock();
161 static void wakeTimeoutCallback(void *);
162
163 #ifdef RIL_SHLIB
164 #if defined(ANDROID_MULTI_SIM)
165 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
166 size_t datalen, RIL_SOCKET_ID socket_id);
167 #else
168 extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
169 size_t datalen);
170 #endif
171 #endif
172
173 #if defined(ANDROID_MULTI_SIM)
174 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
175 #else
176 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
177 #endif
178
179 static UserCallbackInfo * internalRequestTimedCallback
180 (RIL_TimedCallback callback, void *param,
181 const struct timeval *relativeTime);
182
183 /** Index == requestNumber */
184 static CommandInfo s_commands[] = {
185 #include "ril_commands.h"
186 };
187
188 static UnsolResponseInfo s_unsolResponses[] = {
189 #include "ril_unsol_commands.h"
190 };
191
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_1_6::getRadioServiceRwlock(
289 (int) socket_id);
290 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
291 assert(rwlockRet == 0);
292
293 int ret = radio_1_6::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 RLOGD("RIL_register: Vsoc 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_1_6::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_1_6::getRadioServiceRwlock(
578 (int) socket_id);
579 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
580 assert(rwlockRet == 0);
581
582 radio_1_6::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
603 #if VDBG
604 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
605 #endif
606
607 if (pRI->local > 0) {
608 // Locally issued command...void only!
609 // response does not go back up the command socket
610 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
611
612 free(pRI);
613 return;
614 }
615
616 appendPrintBuf("[%04d]< %s",
617 pRI->token, requestToString(pRI->pCI->requestNumber));
618
619 if (pRI->cancelled == 0) {
620 int responseType;
621 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
622 // If ack was already sent, then this call is an asynchronous response. So we need to
623 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
624 responseType = RESPONSE_SOLICITED_ACK_EXP;
625 grabPartialWakeLock();
626 } else {
627 responseType = RESPONSE_SOLICITED;
628 }
629
630 // there is a response payload, no matter success or not.
631 #if VDBG
632 RLOGE ("Calling responseFunction() for token %d", pRI->token);
633 #endif
634
635 pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock((int) socket_id);
636 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
637 assert(rwlockRet == 0);
638
639 ret = pRI->pCI->responseFunction((int) socket_id,
640 responseType, pRI->token, e, response, responselen);
641
642 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
643 assert(rwlockRet == 0);
644 }
645 free(pRI);
646 }
647
648 static void
grabPartialWakeLock()649 grabPartialWakeLock() {
650 if (s_callbacks.version >= 13) {
651 int ret;
652 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
653 assert(ret == 0);
654 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
655
656 UserCallbackInfo *p_info =
657 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
658 if (p_info == NULL) {
659 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
660 } else {
661 s_wakelock_count++;
662 if (s_last_wake_timeout_info != NULL) {
663 s_last_wake_timeout_info->userParam = (void *)1;
664 }
665 s_last_wake_timeout_info = p_info;
666 }
667 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
668 assert(ret == 0);
669 } else {
670 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
671 }
672 }
673
674 void
releaseWakeLock()675 releaseWakeLock() {
676 if (s_callbacks.version >= 13) {
677 int ret;
678 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
679 assert(ret == 0);
680
681 if (s_wakelock_count > 1) {
682 s_wakelock_count--;
683 } else {
684 s_wakelock_count = 0;
685 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
686 if (s_last_wake_timeout_info != NULL) {
687 s_last_wake_timeout_info->userParam = (void *)1;
688 }
689 }
690
691 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
692 assert(ret == 0);
693 } else {
694 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
695 }
696 }
697
698 /**
699 * Timer callback to put us back to sleep before the default timeout
700 */
701 static void
wakeTimeoutCallback(void * param)702 wakeTimeoutCallback (void *param) {
703 // We're using "param != NULL" as a cancellation mechanism
704 if (s_callbacks.version >= 13) {
705 if (param == NULL) {
706 int ret;
707 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
708 assert(ret == 0);
709 s_wakelock_count = 0;
710 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
711 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
712 assert(ret == 0);
713 }
714 } else {
715 if (param == NULL) {
716 releaseWakeLock();
717 }
718 }
719 }
720
721 #if defined(ANDROID_MULTI_SIM)
722 extern "C"
RIL_onUnsolicitedResponse(int unsolResponse,const void * data,size_t datalen,RIL_SOCKET_ID socket_id)723 void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
724 size_t datalen, RIL_SOCKET_ID socket_id)
725 #else
726 extern "C"
727 void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
728 size_t datalen)
729 #endif
730 {
731 int unsolResponseIndex;
732 int ret;
733 bool shouldScheduleTimeout = false;
734 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
735
736 #if defined(ANDROID_MULTI_SIM)
737 soc_id = socket_id;
738 #endif
739
740
741 if (s_registerCalled == 0) {
742 // Ignore RIL_onUnsolicitedResponse before RIL_register
743 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
744 return;
745 }
746
747 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
748
749 if ((unsolResponseIndex < 0)
750 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
751 RLOGE("unsupported unsolicited response code %d", unsolResponse);
752 return;
753 }
754
755 // Grab a wake lock if needed for this reponse,
756 // as we exit we'll either release it immediately
757 // or set a timer to release it later.
758 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
759 case WAKE_PARTIAL:
760 grabPartialWakeLock();
761 shouldScheduleTimeout = true;
762 break;
763
764 case DONT_WAKE:
765 default:
766 // No wake lock is grabed so don't set timeout
767 shouldScheduleTimeout = false;
768 break;
769 }
770
771 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
772
773 int responseType;
774 if (s_callbacks.version >= 13
775 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
776 responseType = RESPONSE_UNSOLICITED_ACK_EXP;
777 } else {
778 responseType = RESPONSE_UNSOLICITED;
779 }
780
781 pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock((int) soc_id);
782 int rwlockRet;
783
784 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
785 // get a write lock in caes of NITZ since setNitzTimeReceived() is called
786 rwlockRet = pthread_rwlock_wrlock(radioServiceRwlockPtr);
787 assert(rwlockRet == 0);
788 radio_1_6::setNitzTimeReceived((int) soc_id, android::elapsedRealtime());
789 } else {
790 rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
791 assert(rwlockRet == 0);
792 }
793
794 if (s_unsolResponses[unsolResponseIndex].responseFunction) {
795 RLOGD("calling UNSOLICITED responseFunction for index %d", unsolResponseIndex);
796 ret = s_unsolResponses[unsolResponseIndex].responseFunction(
797 (int) soc_id, responseType, 0, RIL_E_SUCCESS, const_cast<void*>(data),
798 datalen);
799 } else {
800 RLOGW("No call responseFunction defined for UNSOLICITED");
801 }
802
803 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
804 assert(rwlockRet == 0);
805
806 if (s_callbacks.version < 13) {
807 if (shouldScheduleTimeout) {
808 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
809 &TIMEVAL_WAKE_TIMEOUT);
810
811 if (p_info == NULL) {
812 goto error_exit;
813 } else {
814 // Cancel the previous request
815 if (s_last_wake_timeout_info != NULL) {
816 s_last_wake_timeout_info->userParam = (void *)1;
817 }
818 s_last_wake_timeout_info = p_info;
819 }
820 }
821 }
822
823 #if VDBG
824 RLOGI("%s UNSOLICITED: %s length:%zu", rilSocketIdToString(soc_id),
825 requestToString(unsolResponse), datalen);
826 #endif
827
828 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
829 // Unfortunately, NITZ time is not poll/update like everything
830 // else in the system. So, if the upstream client isn't connected,
831 // keep a copy of the last NITZ response (with receive time noted
832 // above) around so we can deliver it when it is connected
833
834 if (s_lastNITZTimeData != NULL) {
835 free(s_lastNITZTimeData);
836 s_lastNITZTimeData = NULL;
837 }
838
839 s_lastNITZTimeData = calloc(datalen, 1);
840 if (s_lastNITZTimeData == NULL) {
841 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
842 goto error_exit;
843 }
844 s_lastNITZTimeDataSize = datalen;
845 memcpy(s_lastNITZTimeData, data, datalen);
846 }
847
848 // Normal exit
849 return;
850
851 error_exit:
852 if (shouldScheduleTimeout) {
853 releaseWakeLock();
854 }
855 }
856
857 /** FIXME generalize this if you track UserCAllbackInfo, clear it
858 when the callback occurs
859 */
860 static UserCallbackInfo *
internalRequestTimedCallback(RIL_TimedCallback callback,void * param,const struct timeval * relativeTime)861 internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
862 const struct timeval *relativeTime)
863 {
864 struct timeval myRelativeTime;
865 UserCallbackInfo *p_info;
866
867 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
868 if (p_info == NULL) {
869 RLOGE("Memory allocation failed in internalRequestTimedCallback");
870 return p_info;
871
872 }
873
874 p_info->p_callback = callback;
875 p_info->userParam = param;
876
877 if (relativeTime == NULL) {
878 /* treat null parameter as a 0 relative time */
879 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
880 } else {
881 /* FIXME I think event_add's tv param is really const anyway */
882 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
883 }
884
885 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
886
887 ril_timer_add(&(p_info->event), &myRelativeTime);
888
889 triggerEvLoop();
890 return p_info;
891 }
892
893
894 extern "C" void
RIL_requestTimedCallback(RIL_TimedCallback callback,void * param,const struct timeval * relativeTime)895 RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
896 const struct timeval *relativeTime) {
897 internalRequestTimedCallback (callback, param, relativeTime);
898 }
899
900 const char *
failCauseToString(RIL_Errno e)901 failCauseToString(RIL_Errno e) {
902 switch(e) {
903 case RIL_E_SUCCESS: return "E_SUCCESS";
904 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
905 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
906 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
907 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
908 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
909 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
910 case RIL_E_CANCELLED: return "E_CANCELLED";
911 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
912 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
913 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
914 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
915 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
916 #ifdef FEATURE_MULTIMODE_ANDROID
917 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
918 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
919 #endif
920 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
921 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
922 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
923 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
924 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
925 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
926 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
927 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
928 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
929 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
930 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
931 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
932 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
933 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
934 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
935 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
936 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
937 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
938 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
939 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
940 case RIL_E_SIM_ERR: return "E_SIM_ERR";
941 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
942 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
943 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
944 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
945 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
946 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
947 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
948 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
949 case RIL_E_SIM_FULL: return "E_SIM_FULL";
950 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
951 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
952 case RIL_E_EMPTY_RECORD: return "E_EMPTY_RECORD";
953 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
954 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
955 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
956 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
957 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
958 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
959 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
960 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
961 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
962 case RIL_E_ABORTED: return "E_ABORTED";
963 case RIL_E_INVALID_RESPONSE: return "INVALID_RESPONSE";
964 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
965 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
966 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
967 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
968 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
969 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
970 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
971 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
972 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
973 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
974 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
975 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
976 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
977 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
978 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
979 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
980 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
981 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
982 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
983 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
984 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
985 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
986 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
987 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
988 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
989 default: return "<unknown error>";
990 }
991 }
992
993 const char *
radioStateToString(RIL_RadioState s)994 radioStateToString(RIL_RadioState s) {
995 switch(s) {
996 case RADIO_STATE_OFF: return "RADIO_OFF";
997 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
998 case RADIO_STATE_ON:return"RADIO_ON";
999 default: return "<unknown state>";
1000 }
1001 }
1002
1003 const char *
callStateToString(RIL_CallState s)1004 callStateToString(RIL_CallState s) {
1005 switch(s) {
1006 case RIL_CALL_ACTIVE : return "ACTIVE";
1007 case RIL_CALL_HOLDING: return "HOLDING";
1008 case RIL_CALL_DIALING: return "DIALING";
1009 case RIL_CALL_ALERTING: return "ALERTING";
1010 case RIL_CALL_INCOMING: return "INCOMING";
1011 case RIL_CALL_WAITING: return "WAITING";
1012 default: return "<unknown state>";
1013 }
1014 }
1015
1016 const char *
requestToString(int request)1017 requestToString(int request) {
1018 /*
1019 cat guest/hals/ril/libril/ril_commands.h \
1020 | egrep "^ *{RIL_" \
1021 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
1022
1023
1024 cat guest/hals/ril/libril/ril_unsol_commands.h \
1025 | egrep "^ *{RIL_" \
1026 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
1027
1028 */
1029 switch(request) {
1030 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
1031 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
1032 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
1033 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
1034 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
1035 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
1036 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
1037 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
1038 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
1039 case RIL_REQUEST_DIAL: return "DIAL";
1040 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
1041 case RIL_REQUEST_HANGUP: return "HANGUP";
1042 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
1043 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
1044 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
1045 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
1046 case RIL_REQUEST_UDUB: return "UDUB";
1047 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
1048 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
1049 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
1050 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
1051 case RIL_REQUEST_OPERATOR: return "OPERATOR";
1052 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
1053 case RIL_REQUEST_DTMF: return "DTMF";
1054 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
1055 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
1056 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
1057 case RIL_REQUEST_SIM_IO: return "SIM_IO";
1058 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
1059 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
1060 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
1061 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
1062 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
1063 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
1064 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
1065 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
1066 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
1067 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
1068 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
1069 case RIL_REQUEST_ANSWER: return "ANSWER";
1070 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
1071 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
1072 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
1073 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
1074 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
1075 case RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS: return "RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS";
1076 case RIL_REQUEST_START_NETWORK_SCAN: return "RIL_REQUEST_START_NETWORK_SCAN";
1077 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
1078 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
1079 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: return "QUERY_AVAILABLE_NETWORKS";
1080 case RIL_REQUEST_DTMF_START: return "DTMF_START";
1081 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
1082 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
1083 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
1084 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
1085 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
1086 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
1087 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
1088 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
1089 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
1090 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
1091 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
1092 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
1093 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
1094 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
1095 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
1096 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
1097 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
1098 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
1099 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
1100 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
1101 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
1102 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
1103 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
1104 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
1105 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
1106 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
1107 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
1108 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE";
1109 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "CDMA_SET_ROAMING_PREFERENCE";
1110 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "CDMA_QUERY_ROAMING_PREFERENCE";
1111 case RIL_REQUEST_SET_TTY_MODE: return "SET_TTY_MODE";
1112 case RIL_REQUEST_QUERY_TTY_MODE: return "QUERY_TTY_MODE";
1113 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
1114 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
1115 case RIL_REQUEST_CDMA_FLASH: return "CDMA_FLASH";
1116 case RIL_REQUEST_CDMA_BURST_DTMF: return "CDMA_BURST_DTMF";
1117 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY";
1118 case RIL_REQUEST_CDMA_SEND_SMS: return "CDMA_SEND_SMS";
1119 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "CDMA_SMS_ACKNOWLEDGE";
1120 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: return "GSM_GET_BROADCAST_SMS_CONFIG";
1121 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: return "GSM_SET_BROADCAST_SMS_CONFIG";
1122 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: return "GSM_SMS_BROADCAST_ACTIVATION";
1123 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: return "CDMA_GET_BROADCAST_SMS_CONFIG";
1124 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: return "CDMA_SET_BROADCAST_SMS_CONFIG";
1125 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: return "CDMA_SMS_BROADCAST_ACTIVATION";
1126 case RIL_REQUEST_CDMA_SUBSCRIPTION: return "CDMA_SUBSCRIPTION";
1127 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
1128 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
1129 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
1130 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
1131 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
1132 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
1133 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
1134 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
1135 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
1136 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
1137 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
1138 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "STK_SEND_ENVELOPE_WITH_STATUS";
1139 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
1140 case RIL_REQUEST_GET_CELL_INFO_LIST: return "GET_CELL_INFO_LIST";
1141 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "SET_UNSOL_CELL_INFO_LIST_RATE";
1142 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "SET_INITIAL_ATTACH_APN";
1143 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
1144 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
1145 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
1146 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
1147 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
1148 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
1149 case RIL_REQUEST_NV_READ_ITEM: return "NV_READ_ITEM";
1150 case RIL_REQUEST_NV_WRITE_ITEM: return "NV_WRITE_ITEM";
1151 case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "NV_WRITE_CDMA_PRL";
1152 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
1153 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
1154 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
1155 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
1156 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
1157 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
1158 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
1159 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
1160 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
1161 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "GET_RADIO_CAPABILITY";
1162 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "SET_RADIO_CAPABILITY";
1163 case RIL_REQUEST_START_LCE: return "START_LCE";
1164 case RIL_REQUEST_STOP_LCE: return "STOP_LCE";
1165 case RIL_REQUEST_PULL_LCEDATA: return "PULL_LCEDATA";
1166 case RIL_REQUEST_GET_ACTIVITY_INFO: return "GET_ACTIVITY_INFO";
1167 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
1168 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
1169 case RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION: return "SET_CARRIER_INFO_IMSI_ENCRYPTION";
1170 case RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA: return "SET_SIGNAL_STRENGTH_REPORTING_CRITERIA";
1171 case RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA: return "SET_LINK_CAPACITY_REPORTING_CRITERIA";
1172 case RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION: return "ENTER_SIM_DEPERSONALIZATION";
1173 case RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE: return "CDMA_SEND_SMS_EXPECT_MORE";
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