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