blob: 45a06c056e7e0cd9092dcbd8e9dc6ac87e596284 [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** 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
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** 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
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080021#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070022#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080023#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070025#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080029#include <cutils/jstring.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080030#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070031#include <sys/limits.h>
Sanket Padawe4c05f352016-01-26 16:19:00 -080032#include <sys/system_properties.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080033#include <pwd.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080034#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>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080044#include <sys/un.h>
45#include <assert.h>
46#include <netinet/in.h>
47#include <cutils/properties.h>
Dheeraj Shetty27976c42014-07-02 21:27:57 +020048#include <RilSapSocket.h>
Amit Mahajan18fe36b2016-08-25 11:19:21 -070049#include <ril_service.h>
Amit Mahajanc2c71852016-11-29 16:48:54 -080050#include <sap_service.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080051
Dheeraj Shetty27976c42014-07-02 21:27:57 +020052extern "C" void
53RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Sanket Padawe6ff9a872016-01-27 15:09:12 -080054
55extern "C" void
56RIL_onRequestAck(RIL_Token t);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080057namespace android {
58
59#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020060#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080061
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080062#define ANDROID_WAKE_LOCK_NAME "radio-interface"
63
Nathan Harolda0153392015-07-28 14:54:58 -070064#define ANDROID_WAKE_LOCK_SECS 0
65#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080066
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
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080079/* Negative values for private RIL errno's */
Chih-Hung Hsieh434554c2016-05-12 10:01:16 -070080#define RIL_ERRNO_INVALID_RESPONSE (-1)
Robert Greenwalt78e2c9c2016-05-16 12:36:42 -070081#define RIL_ERRNO_NO_MEMORY (-12)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080082
83// request, response, and unsolicited msg print macro
84#define PRINTBUF_SIZE 8096
85
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080086enum WakeType {DONT_WAKE, WAKE_PARTIAL};
87
88typedef struct {
89 int requestNumber;
Amit Mahajan759786a2017-03-03 17:35:47 -080090 int (*responseFunction) (int slotId, int responseType, int token,
Amit Mahajan18fe36b2016-08-25 11:19:21 -070091 RIL_Errno e, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080092 WakeType wakeType;
93} UnsolResponseInfo;
94
Wink Saville3d54e742009-05-18 18:00:44 -070095typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080096 RIL_TimedCallback p_callback;
97 void *userParam;
98 struct ril_event event;
99 struct UserCallbackInfo *p_next;
100} UserCallbackInfo;
101
Etan Cohend3652192014-06-20 08:28:44 -0700102extern "C" const char * failCauseToString(RIL_Errno);
103extern "C" const char * callStateToString(RIL_CallState);
104extern "C" const char * radioStateToString(RIL_RadioState);
105extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
106
107extern "C"
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700108char ril_service_name_base[MAX_SERVICE_NAME_LENGTH] = RIL_SERVICE_NAME_BASE;
109extern "C"
110char ril_service_name[MAX_SERVICE_NAME_LENGTH] = RIL1_SERVICE_NAME;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800111/*******************************************************************/
112
113RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
114static int s_registerCalled = 0;
115
116static pthread_t s_tid_dispatch;
117static pthread_t s_tid_reader;
118static int s_started = 0;
119
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800120static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700121static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800122
123static int s_fdWakeupRead;
124static int s_fdWakeupWrite;
125
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800126int s_wakelock_count = 0;
127
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800128static struct ril_event s_wakeupfd_event;
Etan Cohend3652192014-06-20 08:28:44 -0700129
130static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
131static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800132static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700133static RequestInfo *s_pendingRequests = NULL;
134
135#if (SIM_COUNT >= 2)
Etan Cohend3652192014-06-20 08:28:44 -0700136static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
137static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
138static RequestInfo *s_pendingRequests_socket2 = NULL;
139#endif
140
141#if (SIM_COUNT >= 3)
Etan Cohend3652192014-06-20 08:28:44 -0700142static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
143static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
144static RequestInfo *s_pendingRequests_socket3 = NULL;
145#endif
146
147#if (SIM_COUNT >= 4)
Etan Cohend3652192014-06-20 08:28:44 -0700148static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
149static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
150static RequestInfo *s_pendingRequests_socket4 = NULL;
151#endif
152
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800153static struct ril_event s_wake_timeout_event;
154static struct ril_event s_debug_event;
155
156
Nathan Harolda0153392015-07-28 14:54:58 -0700157static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800158
Etan Cohend3652192014-06-20 08:28:44 -0700159
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800160static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
161static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
162
163static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
164static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
165
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800166static RequestInfo *s_toDispatchHead = NULL;
167static RequestInfo *s_toDispatchTail = NULL;
168
169static UserCallbackInfo *s_last_wake_timeout_info = NULL;
170
171static void *s_lastNITZTimeData = NULL;
172static size_t s_lastNITZTimeDataSize;
173
174#if RILC_LOG
175 static char printBuf[PRINTBUF_SIZE];
176#endif
177
178/*******************************************************************/
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800179static void grabPartialWakeLock();
Sanket Padawe85f952a2017-01-02 23:46:00 -0800180void releaseWakeLock();
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800181static void wakeTimeoutCallback(void *);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800182
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800183#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700184#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700185extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700186 size_t datalen, RIL_SOCKET_ID socket_id);
187#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700188extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800189 size_t datalen);
190#endif
Etan Cohend3652192014-06-20 08:28:44 -0700191#endif
192
193#if defined(ANDROID_MULTI_SIM)
194#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
195#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
196#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
197#else
198#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
199#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
200#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
201#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800202
Wink Saville7f856802009-06-09 10:23:37 -0700203static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700204 (RIL_TimedCallback callback, void *param,
205 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800206
207/** Index == requestNumber */
208static CommandInfo s_commands[] = {
209#include "ril_commands.h"
210};
211
212static UnsolResponseInfo s_unsolResponses[] = {
213#include "ril_unsol_commands.h"
214};
215
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700216char * RIL_getServiceName() {
217 return ril_service_name;
Etan Cohend3652192014-06-20 08:28:44 -0700218}
219
220extern "C"
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700221void RIL_setServiceName(const char * s) {
222 strncpy(ril_service_name, s, MAX_SERVICE_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -0700223}
224
Sanket Padawe85f952a2017-01-02 23:46:00 -0800225RequestInfo *
226addRequestToList(int serial, int slotId, int request) {
227 RequestInfo *pRI;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700228 int ret;
Sanket Padawe85f952a2017-01-02 23:46:00 -0800229 RIL_SOCKET_ID socket_id = (RIL_SOCKET_ID) slotId;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700230 /* Hook for current context */
231 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
232 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
233 /* pendingRequestsHook refer to &s_pendingRequests */
234 RequestInfo** pendingRequestsHook = &s_pendingRequests;
235
236#if (SIM_COUNT >= 2)
237 if (socket_id == RIL_SOCKET_2) {
238 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
239 pendingRequestsHook = &s_pendingRequests_socket2;
240 }
241#if (SIM_COUNT >= 3)
242 else if (socket_id == RIL_SOCKET_3) {
243 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
244 pendingRequestsHook = &s_pendingRequests_socket3;
245 }
246#endif
247#if (SIM_COUNT >= 4)
248 else if (socket_id == RIL_SOCKET_4) {
249 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
250 pendingRequestsHook = &s_pendingRequests_socket4;
251 }
252#endif
253#endif
254
Sanket Padawe85f952a2017-01-02 23:46:00 -0800255 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
256 if (pRI == NULL) {
257 RLOGE("Memory allocation failed for request %s", requestToString(request));
258 return NULL;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700259 }
260
Sanket Padawe85f952a2017-01-02 23:46:00 -0800261 pRI->token = serial;
262 pRI->pCI = &(s_commands[request]);
263 pRI->socket_id = socket_id;
264
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700265 ret = pthread_mutex_lock(pendingRequestsMutexHook);
266 assert (ret == 0);
267
268 pRI->p_next = *pendingRequestsHook;
269 *pendingRequestsHook = pRI;
270
271 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
272 assert (ret == 0);
273
Sanket Padawe85f952a2017-01-02 23:46:00 -0800274 return pRI;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700275}
276
Wink Saville3d54e742009-05-18 18:00:44 -0700277static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800278 int ret;
279 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
280 /* trigger event loop to wakeup. No reason to do this,
281 * if we're in the event loop thread */
282 do {
283 ret = write (s_fdWakeupWrite, " ", 1);
284 } while (ret < 0 && errno == EINTR);
285 }
286}
287
Wink Saville3d54e742009-05-18 18:00:44 -0700288static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800289 ril_event_add(ev);
290 triggerEvLoop();
291}
292
293/**
294 * A write on the wakeup fd is done just to pop us out of select()
295 * We empty the buffer here and then ril_event will reset the timers on the
296 * way back down
297 */
Wink Savillef4c4d362009-04-02 01:37:03 -0700298static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800299 char buff[16];
300 int ret;
301
Wink Saville8eb2a122012-11-19 16:05:13 -0800302 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800303
304 /* empty our wakeup socket out */
305 do {
306 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -0700307 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800308}
309
Weilun Dud2c30932017-02-09 12:32:42 -0800310static void resendLastNITZTimeData(RIL_SOCKET_ID socket_id) {
311 if (s_lastNITZTimeData != NULL) {
Weilun Dud2c30932017-02-09 12:32:42 -0800312 int responseType = (s_callbacks.version >= 13)
313 ? RESPONSE_UNSOLICITED_ACK_EXP
314 : RESPONSE_UNSOLICITED;
315 int ret = radio::nitzTimeReceivedInd(
Amit Mahajan759786a2017-03-03 17:35:47 -0800316 (int)socket_id, responseType, 0,
Weilun Dud2c30932017-02-09 12:32:42 -0800317 RIL_E_SUCCESS, s_lastNITZTimeData, s_lastNITZTimeDataSize);
318 if (ret == 0) {
319 free(s_lastNITZTimeData);
320 s_lastNITZTimeData = NULL;
321 }
322 }
323}
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800324
Amit Mahajanc7ad6262017-03-14 16:39:27 -0700325void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -0700326 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -0700327 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -0700328 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
329 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -0700330
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800331 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -0700332 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
333 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800334
335 // Send last NITZ time data, in case it was missed
336 if (s_lastNITZTimeData != NULL) {
Weilun Dud2c30932017-02-09 12:32:42 -0800337 resendLastNITZTimeData(socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800338 }
339
340 // Get version string
341 if (s_callbacks.getVersion != NULL) {
342 const char *version;
343 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -0800344 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -0700345
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800346 property_set(PROPERTY_RIL_IMPL, version);
347 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -0800348 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800349 property_set(PROPERTY_RIL_IMPL, "unavailable");
350 }
351
352}
353
Wink Savillef4c4d362009-04-02 01:37:03 -0700354static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800355 UserCallbackInfo *p_info;
356
357 p_info = (UserCallbackInfo *)param;
358
359 p_info->p_callback(p_info->userParam);
360
361
362 // FIXME generalize this...there should be a cancel mechanism
363 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
364 s_last_wake_timeout_info = NULL;
365 }
366
367 free(p_info);
368}
369
370
371static void *
Wink Savillef4c4d362009-04-02 01:37:03 -0700372eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800373 int ret;
374 int filedes[2];
375
376 ril_event_init();
377
378 pthread_mutex_lock(&s_startupMutex);
379
380 s_started = 1;
381 pthread_cond_broadcast(&s_startupCond);
382
383 pthread_mutex_unlock(&s_startupMutex);
384
385 ret = pipe(filedes);
386
387 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800388 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800389 return NULL;
390 }
391
392 s_fdWakeupRead = filedes[0];
393 s_fdWakeupWrite = filedes[1];
394
395 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
396
397 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
398 processWakeupCallback, NULL);
399
400 rilEventAddWakeup (&s_wakeupfd_event);
401
402 // Only returns on error
403 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -0800404 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -0500405 // kill self to restart on error
406 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800407
408 return NULL;
409}
410
Wink Saville7f856802009-06-09 10:23:37 -0700411extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -0700412RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800413 /* spin up eventLoop thread and wait for it to get started */
414 s_started = 0;
415 pthread_mutex_lock(&s_startupMutex);
416
Elliott Hughesc0d8dc62014-01-03 15:31:42 -0800417 pthread_attr_t attr;
418 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -0700419 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -0800420
Elliott Hughesfd81e712014-01-06 12:46:02 -0800421 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
422 if (result != 0) {
423 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -0800424 goto done;
425 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800426
427 while (s_started == 0) {
428 pthread_cond_wait(&s_startupCond, &s_startupMutex);
429 }
430
Elliott Hughesc0d8dc62014-01-03 15:31:42 -0800431done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800432 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433}
434
435// Used for testing purpose only.
436extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
437 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
438}
439
Wink Saville7f856802009-06-09 10:23:37 -0700440extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -0700441RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800442 int ret;
443 int flags;
444
Etan Cohend3652192014-06-20 08:28:44 -0700445 RLOGI("SIM_COUNT: %d", SIM_COUNT);
446
Wink Saville43808972011-01-13 17:39:51 -0800447 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800448 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800449 return;
450 }
Wink Saville43808972011-01-13 17:39:51 -0800451 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800452 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -0800453 callbacks->version, RIL_VERSION_MIN);
454 return;
Wink Saville3a4840b2010-04-07 13:29:58 -0700455 }
Sanket Padawe4c05f352016-01-26 16:19:00 -0800456
Wink Saville8eb2a122012-11-19 16:05:13 -0800457 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800458
459 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800460 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800461 "Subsequent call ignored");
462 return;
463 }
464
465 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
466
467 s_registerCalled = 1;
468
Etan Cohend3652192014-06-20 08:28:44 -0700469 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800470 // Little self-check
471
Wink Savillef4c4d362009-04-02 01:37:03 -0700472 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800473 assert(i == s_commands[i].requestNumber);
474 }
475
Wink Savillef4c4d362009-04-02 01:37:03 -0700476 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -0700477 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800478 == s_unsolResponses[i].requestNumber);
479 }
480
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700481 radio::registerService(&s_callbacks, s_commands);
482 RLOGI("RILHIDL called registerService");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800483
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800484}
485
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200486extern "C" void
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700487RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),
488 RIL_SOCKET_TYPE socketType, int argc, char **argv) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200489
490 RIL_RadioFunctions* UimFuncs = NULL;
491
492 if(Init) {
493 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
494
495 switch(socketType) {
496 case RIL_SAP_SOCKET:
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700497 RilSapSocket::initSapSocket(RIL1_SERVICE_NAME, UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200498
499#if (SIM_COUNT >= 2)
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700500 RilSapSocket::initSapSocket(RIL2_SERVICE_NAME, UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200501#endif
502
503#if (SIM_COUNT >= 3)
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700504 RilSapSocket::initSapSocket(RIL3_SERVICE_NAME, UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200505#endif
506
507#if (SIM_COUNT >= 4)
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700508 RilSapSocket::initSapSocket(RIL4_SERVICE_NAME, UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200509#endif
Meng Wangef966a32016-06-20 17:38:18 -0700510 break;
511 default:;
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200512 }
Amit Mahajanc2c71852016-11-29 16:48:54 -0800513
514 RLOGI("RIL_register_socket: calling registerService");
515 sap::registerService(UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200516 }
517}
518
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800519// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800520static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800521checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800522 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -0700523 /* Hook for current context
524 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
525 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
526 /* pendingRequestsHook refer to &s_pendingRequests */
527 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -0700528
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800529 if (pRI == NULL) {
530 return 0;
531 }
532
Etan Cohend3652192014-06-20 08:28:44 -0700533#if (SIM_COUNT >= 2)
534 if (pRI->socket_id == RIL_SOCKET_2) {
535 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
536 pendingRequestsHook = &s_pendingRequests_socket2;
537 }
538#if (SIM_COUNT >= 3)
539 if (pRI->socket_id == RIL_SOCKET_3) {
540 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
541 pendingRequestsHook = &s_pendingRequests_socket3;
542 }
543#endif
544#if (SIM_COUNT >= 4)
545 if (pRI->socket_id == RIL_SOCKET_4) {
546 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
547 pendingRequestsHook = &s_pendingRequests_socket4;
548 }
549#endif
550#endif
551 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800552
Etan Cohend3652192014-06-20 08:28:44 -0700553 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -0700554 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800555 ; ppCur = &((*ppCur)->p_next)
556 ) {
557 if (pRI == *ppCur) {
558 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800559 if (isAck) { // Async ack
560 if (pRI->wasAckSent == 1) {
561 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
562 } else {
563 pRI->wasAckSent = 1;
564 }
565 } else {
566 *ppCur = (*ppCur)->p_next;
567 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800568 break;
569 }
570 }
571
Etan Cohend3652192014-06-20 08:28:44 -0700572 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800573
574 return ret;
575}
576
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800577extern "C" void
578RIL_onRequestAck(RIL_Token t) {
579 RequestInfo *pRI;
Amit Mahajanc7ad6262017-03-14 16:39:27 -0700580 int ret;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800581
582 size_t errorOffset;
583 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
584
585 pRI = (RequestInfo *)t;
586
587 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
588 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
589 return;
590 }
591
592 socket_id = pRI->socket_id;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800593
594#if VDBG
595 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
596#endif
597
598 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
599
600 if (pRI->cancelled == 0) {
Jack Yubbd4b1b2017-02-13 11:21:00 -0800601 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(
602 (int) socket_id);
603 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
604 assert(rwlockRet == 0);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800605
Jack Yubbd4b1b2017-02-13 11:21:00 -0800606 radio::acknowledgeRequest((int) socket_id, pRI->token);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800607
Jack Yubbd4b1b2017-02-13 11:21:00 -0800608 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
609 assert(rwlockRet == 0);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800610 }
611}
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800612extern "C" void
613RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
614 RequestInfo *pRI;
615 int ret;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800616 size_t errorOffset;
617 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
618
619 pRI = (RequestInfo *)t;
620
621 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
622 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
623 return;
624 }
625
626 socket_id = pRI->socket_id;
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700627#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -0700628 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700629#endif
Etan Cohend3652192014-06-20 08:28:44 -0700630
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800631 if (pRI->local > 0) {
632 // Locally issued command...void only!
633 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -0800634 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800635
Jack Yubbd4b1b2017-02-13 11:21:00 -0800636 free(pRI);
637 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800638 }
639
640 appendPrintBuf("[%04d]< %s",
641 pRI->token, requestToString(pRI->pCI->requestNumber));
642
643 if (pRI->cancelled == 0) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700644 int responseType;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800645 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
646 // If ack was already sent, then this call is an asynchronous response. So we need to
647 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700648 responseType = RESPONSE_SOLICITED_ACK_EXP;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800649 grabPartialWakeLock();
650 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700651 responseType = RESPONSE_SOLICITED;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800652 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800653
Jack Yubbd4b1b2017-02-13 11:21:00 -0800654 // there is a response payload, no matter success or not.
Jayachandran C572f2f42017-03-25 14:30:13 -0700655#if VDBG
Jack Yubbd4b1b2017-02-13 11:21:00 -0800656 RLOGE ("Calling responseFunction() for token %d", pRI->token);
Jayachandran C572f2f42017-03-25 14:30:13 -0700657#endif
Sanket Padawe85f952a2017-01-02 23:46:00 -0800658
Jack Yubbd4b1b2017-02-13 11:21:00 -0800659 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock((int) socket_id);
660 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
661 assert(rwlockRet == 0);
Amit Mahajan32ec8a42017-01-24 05:45:02 -0800662
Amit Mahajan759786a2017-03-03 17:35:47 -0800663 ret = pRI->pCI->responseFunction((int) socket_id,
Jack Yubbd4b1b2017-02-13 11:21:00 -0800664 responseType, pRI->token, e, response, responselen);
Amit Mahajan32ec8a42017-01-24 05:45:02 -0800665
Jack Yubbd4b1b2017-02-13 11:21:00 -0800666 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
667 assert(rwlockRet == 0);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800668 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800669 free(pRI);
670}
671
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800672static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700673grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800674 if (s_callbacks.version >= 13) {
675 int ret;
676 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
677 assert(ret == 0);
678 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawe55227b52016-02-29 10:09:26 -0800679
680 UserCallbackInfo *p_info =
681 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
682 if (p_info == NULL) {
683 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
684 } else {
685 s_wakelock_count++;
686 if (s_last_wake_timeout_info != NULL) {
687 s_last_wake_timeout_info->userParam = (void *)1;
688 }
689 s_last_wake_timeout_info = p_info;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800690 }
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800691 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
692 assert(ret == 0);
693 } else {
694 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
695 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800696}
697
Sanket Padawe85f952a2017-01-02 23:46:00 -0800698void
Wink Savillef4c4d362009-04-02 01:37:03 -0700699releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800700 if (s_callbacks.version >= 13) {
701 int ret;
702 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
703 assert(ret == 0);
704
705 if (s_wakelock_count > 1) {
706 s_wakelock_count--;
707 } else {
708 s_wakelock_count = 0;
709 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
710 if (s_last_wake_timeout_info != NULL) {
711 s_last_wake_timeout_info->userParam = (void *)1;
712 }
713 }
714
715 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
716 assert(ret == 0);
717 } else {
718 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
719 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800720}
721
722/**
723 * Timer callback to put us back to sleep before the default timeout
724 */
725static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700726wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800727 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800728 if (s_callbacks.version >= 13) {
729 if (param == NULL) {
730 int ret;
731 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
732 assert(ret == 0);
733 s_wakelock_count = 0;
734 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
735 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
736 assert(ret == 0);
737 }
738 } else {
739 if (param == NULL) {
740 releaseWakeLock();
741 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800742 }
743}
744
Etan Cohend3652192014-06-20 08:28:44 -0700745#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800746extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +0100747void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700748 size_t datalen, RIL_SOCKET_ID socket_id)
749#else
750extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +0100751void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800752 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -0700753#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800754{
755 int unsolResponseIndex;
756 int ret;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800757 bool shouldScheduleTimeout = false;
Etan Cohend3652192014-06-20 08:28:44 -0700758 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
759
760#if defined(ANDROID_MULTI_SIM)
761 soc_id = socket_id;
762#endif
763
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800764
765 if (s_registerCalled == 0) {
766 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -0800767 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800768 return;
769 }
Wink Saville7f856802009-06-09 10:23:37 -0700770
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800771 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
772
773 if ((unsolResponseIndex < 0)
774 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800775 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800776 return;
777 }
778
779 // Grab a wake lock if needed for this reponse,
780 // as we exit we'll either release it immediately
781 // or set a timer to release it later.
782 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
783 case WAKE_PARTIAL:
784 grabPartialWakeLock();
785 shouldScheduleTimeout = true;
786 break;
787
788 case DONT_WAKE:
789 default:
790 // No wake lock is grabed so don't set timeout
791 shouldScheduleTimeout = false;
792 break;
793 }
794
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800795 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
796
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700797 int responseType;
Sanket Padawed8c0b462016-02-03 11:46:02 -0800798 if (s_callbacks.version >= 13
799 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700800 responseType = RESPONSE_UNSOLICITED_ACK_EXP;
Sanket Padawed8c0b462016-02-03 11:46:02 -0800801 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700802 responseType = RESPONSE_UNSOLICITED;
Sanket Padawed8c0b462016-02-03 11:46:02 -0800803 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800804
Amit Mahajan32ec8a42017-01-24 05:45:02 -0800805 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock((int) soc_id);
806 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
807 assert(rwlockRet == 0);
808
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700809 ret = s_unsolResponses[unsolResponseIndex].responseFunction(
Amit Mahajan759786a2017-03-03 17:35:47 -0800810 (int) soc_id, responseType, 0, RIL_E_SUCCESS, const_cast<void*>(data),
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700811 datalen);
Amit Mahajan32ec8a42017-01-24 05:45:02 -0800812
813 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
814 assert(rwlockRet == 0);
815
Sanket Padawe55227b52016-02-29 10:09:26 -0800816 if (s_callbacks.version < 13) {
817 if (shouldScheduleTimeout) {
818 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
819 &TIMEVAL_WAKE_TIMEOUT);
820
821 if (p_info == NULL) {
822 goto error_exit;
823 } else {
824 // Cancel the previous request
825 if (s_last_wake_timeout_info != NULL) {
826 s_last_wake_timeout_info->userParam = (void *)1;
827 }
828 s_last_wake_timeout_info = p_info;
829 }
830 }
831 }
832
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700833#if VDBG
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700834 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id),
Amit Mahajanc7ad6262017-03-14 16:39:27 -0700835 requestToString(unsolResponse), datalen);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700836#endif
Weilun Dud2c30932017-02-09 12:32:42 -0800837
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800838 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800839 // Unfortunately, NITZ time is not poll/update like everything
840 // else in the system. So, if the upstream client isn't connected,
841 // keep a copy of the last NITZ response (with receive time noted
842 // above) around so we can deliver it when it is connected
843
844 if (s_lastNITZTimeData != NULL) {
Weilun Dud2c30932017-02-09 12:32:42 -0800845 free(s_lastNITZTimeData);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800846 s_lastNITZTimeData = NULL;
847 }
848
Weilun Dud2c30932017-02-09 12:32:42 -0800849 s_lastNITZTimeData = calloc(datalen, 1);
Sanket Padawe55227b52016-02-29 10:09:26 -0800850 if (s_lastNITZTimeData == NULL) {
Weilun Dud2c30932017-02-09 12:32:42 -0800851 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
852 goto error_exit;
Sanket Padawe55227b52016-02-29 10:09:26 -0800853 }
Weilun Dud2c30932017-02-09 12:32:42 -0800854 s_lastNITZTimeDataSize = datalen;
855 memcpy(s_lastNITZTimeData, data, datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800856 }
857
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800858 // Normal exit
859 return;
860
861error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800862 if (shouldScheduleTimeout) {
863 releaseWakeLock();
864 }
865}
866
Wink Saville7f856802009-06-09 10:23:37 -0700867/** FIXME generalize this if you track UserCAllbackInfo, clear it
868 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869*/
870static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -0700871internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700872 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873{
874 struct timeval myRelativeTime;
875 UserCallbackInfo *p_info;
876
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800877 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800878 if (p_info == NULL) {
879 RLOGE("Memory allocation failed in internalRequestTimedCallback");
880 return p_info;
881
882 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800883
Wink Saville7f856802009-06-09 10:23:37 -0700884 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800885 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700886
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800887 if (relativeTime == NULL) {
888 /* treat null parameter as a 0 relative time */
889 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
890 } else {
891 /* FIXME I think event_add's tv param is really const anyway */
892 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
893 }
894
895 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
896
897 ril_timer_add(&(p_info->event), &myRelativeTime);
898
899 triggerEvLoop();
900 return p_info;
901}
902
Naveen Kalla7edd07c2010-06-21 18:54:47 -0700903
904extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700905RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
906 const struct timeval *relativeTime) {
907 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800908}
909
910const char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700911failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800912 switch(e) {
913 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -0700914 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800915 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
916 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
917 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
918 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
919 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
920 case RIL_E_CANCELLED: return "E_CANCELLED";
921 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
922 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
923 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -0700924 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -0700925 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -0700926#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -0700927 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
928 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
929#endif
Sanket Padaweb39e5c92016-02-08 14:28:59 -0800930 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
931 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
932 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
933 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
934 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
935 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
936 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
937 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
938 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
939 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
940 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
941 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
942 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
943 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
944 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
945 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
946 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
947 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
948 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
949 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
950 case RIL_E_SIM_ERR: return "E_SIM_ERR";
951 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
952 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
953 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
954 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
955 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
956 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
957 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.changdf7add02016-03-04 18:27:48 +0800958 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
959 case RIL_E_SIM_FULL: return "E_SIM_FULL";
960 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
961 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
962 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
Ajay Nambi68900f52016-03-11 12:02:55 -0800963 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
964 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
965 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
966 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
967 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
968 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
Ajay Nambi10345892016-03-19 09:02:28 -0700969 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
970 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
971 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
972 case RIL_E_ABORTED: return "E_ABORTED";
Sanket Padawe85f952a2017-01-02 23:46:00 -0800973 case RIL_E_INVALID_RESPONSE: return "INVALID_RESPONSE";
Sanket Padawe0106aed2016-02-09 09:56:31 -0800974 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
975 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
976 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
977 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
978 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
979 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
980 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
981 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
982 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
983 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
984 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
985 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
986 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
987 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
988 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
989 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
990 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
991 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
992 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
993 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
994 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
995 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
996 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
997 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
998 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800999 default: return "<unknown error>";
1000 }
1001}
1002
1003const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07001004radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001005 switch(s) {
1006 case RADIO_STATE_OFF: return "RADIO_OFF";
1007 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001008 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001009 default: return "<unknown state>";
1010 }
1011}
1012
1013const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07001014callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001015 switch(s) {
1016 case RIL_CALL_ACTIVE : return "ACTIVE";
1017 case RIL_CALL_HOLDING: return "HOLDING";
1018 case RIL_CALL_DIALING: return "DIALING";
1019 case RIL_CALL_ALERTING: return "ALERTING";
1020 case RIL_CALL_INCOMING: return "INCOMING";
1021 case RIL_CALL_WAITING: return "WAITING";
1022 default: return "<unknown state>";
1023 }
1024}
1025
1026const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07001027requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001028/*
1029 cat libs/telephony/ril_commands.h \
1030 | egrep "^ *{RIL_" \
1031 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
1032
1033
1034 cat libs/telephony/ril_unsol_commands.h \
1035 | egrep "^ *{RIL_" \
1036 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
1037
1038*/
1039 switch(request) {
1040 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
1041 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
1042 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
1043 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
1044 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
1045 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
1046 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
1047 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
1048 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
1049 case RIL_REQUEST_DIAL: return "DIAL";
1050 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
1051 case RIL_REQUEST_HANGUP: return "HANGUP";
1052 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
1053 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
1054 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
1055 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
1056 case RIL_REQUEST_UDUB: return "UDUB";
1057 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
1058 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08001059 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
1060 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001061 case RIL_REQUEST_OPERATOR: return "OPERATOR";
1062 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
1063 case RIL_REQUEST_DTMF: return "DTMF";
1064 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
1065 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07001066 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001067 case RIL_REQUEST_SIM_IO: return "SIM_IO";
1068 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
1069 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
1070 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
1071 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
1072 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
1073 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
1074 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
1075 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
1076 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
1077 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
1078 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
1079 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07001080 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001081 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
1082 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
1083 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
1084 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
1085 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
1086 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
Matt Mower897915e2015-04-08 23:16:03 -05001087 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: return "QUERY_AVAILABLE_NETWORKS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001088 case RIL_REQUEST_DTMF_START: return "DTMF_START";
1089 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
1090 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
1091 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001092 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
1093 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
1094 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07001095 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
1096 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001097 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
1098 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
1099 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Matt Mower897915e2015-04-08 23:16:03 -05001100 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
1101 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
1102 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
1103 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
Wink Savillef4c4d362009-04-02 01:37:03 -07001104 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
1105 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001106 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
1107 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
1108 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
1109 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
1110 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001111 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
Matt Mower897915e2015-04-08 23:16:03 -05001112 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
1113 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
1114 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001115 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Matt Mower897915e2015-04-08 23:16:03 -05001116 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE";
1117 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "CDMA_SET_ROAMING_PREFERENCE";
1118 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "CDMA_QUERY_ROAMING_PREFERENCE";
1119 case RIL_REQUEST_SET_TTY_MODE: return "SET_TTY_MODE";
1120 case RIL_REQUEST_QUERY_TTY_MODE: return "QUERY_TTY_MODE";
1121 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
1122 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
1123 case RIL_REQUEST_CDMA_FLASH: return "CDMA_FLASH";
1124 case RIL_REQUEST_CDMA_BURST_DTMF: return "CDMA_BURST_DTMF";
1125 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY";
1126 case RIL_REQUEST_CDMA_SEND_SMS: return "CDMA_SEND_SMS";
1127 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "CDMA_SMS_ACKNOWLEDGE";
1128 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: return "GSM_GET_BROADCAST_SMS_CONFIG";
1129 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: return "GSM_SET_BROADCAST_SMS_CONFIG";
1130 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: return "GSM_SMS_BROADCAST_ACTIVATION";
1131 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: return "CDMA_GET_BROADCAST_SMS_CONFIG";
1132 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: return "CDMA_SET_BROADCAST_SMS_CONFIG";
1133 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: return "CDMA_SMS_BROADCAST_ACTIVATION";
1134 case RIL_REQUEST_CDMA_SUBSCRIPTION: return "CDMA_SUBSCRIPTION";
Wink Savillef4c4d362009-04-02 01:37:03 -07001135 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
1136 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
1137 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07001138 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
1139 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
1140 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07001141 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07001142 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08001143 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07001144 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Matt Mower897915e2015-04-08 23:16:03 -05001145 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
1146 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001147 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Matt Mower897915e2015-04-08 23:16:03 -05001148 case RIL_REQUEST_GET_CELL_INFO_LIST: return "GET_CELL_INFO_LIST";
1149 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "SET_UNSOL_CELL_INFO_LIST_RATE";
1150 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001151 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
1152 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001153 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
1154 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
1155 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
1156 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Matt Mower897915e2015-04-08 23:16:03 -05001157 case RIL_REQUEST_NV_READ_ITEM: return "NV_READ_ITEM";
1158 case RIL_REQUEST_NV_WRITE_ITEM: return "NV_WRITE_ITEM";
1159 case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "NV_WRITE_CDMA_PRL";
1160 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
Etan Cohend3652192014-06-20 08:28:44 -07001161 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
1162 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07001163 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
1164 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07001165 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
1166 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00001167 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Matt Mower897915e2015-04-08 23:16:03 -05001168 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
1169 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "GET_RADIO_CAPABILITY";
1170 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "SET_RADIO_CAPABILITY";
1171 case RIL_REQUEST_START_LCE: return "START_LCE";
1172 case RIL_REQUEST_STOP_LCE: return "STOP_LCE";
1173 case RIL_REQUEST_PULL_LCEDATA: return "PULL_LCEDATA";
1174 case RIL_REQUEST_GET_ACTIVITY_INFO: return "GET_ACTIVITY_INFO";
Meng Wangb4e34312016-05-12 14:54:36 -07001175 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
1176 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
Matt Mower897915e2015-04-08 23:16:03 -05001177 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001178 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
1179 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08001180 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001181 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
1182 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
1183 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
1184 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
Matt Mower897915e2015-04-08 23:16:03 -05001185 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001186 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
1187 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Matt Mower897915e2015-04-08 23:16:03 -05001188 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
Sanket Padawe0eb4fba2016-01-26 17:28:38 -08001189 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001190 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
1191 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
1192 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
1193 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
Matt Mower897915e2015-04-08 23:16:03 -05001194 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001195 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001196 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07001197 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05001198 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
1199 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
Wink Savillef4c4d362009-04-02 01:37:03 -07001200 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07001201 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
1202 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
1203 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
1204 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
1205 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07001206 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07001207 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08001208 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07001209 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08001210 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
1211 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07001212 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001213 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07001214 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Matt Mower897915e2015-04-08 23:16:03 -05001215 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07001216 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
1217 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
Matt Mower897915e2015-04-08 23:16:03 -05001218 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "UNSOL_HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07001219 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05001220 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
Mark Salyzyn0078c8d2016-12-12 14:41:47 -08001221 case RIL_UNSOL_MODEM_RESTART: return "UNSOL_MODEM_RESTART";
Matt Mower897915e2015-04-08 23:16:03 -05001222 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
1223 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
1224 case RIL_UNSOL_LCEDATA_RECV: return "UNSOL_LCEDATA_RECV";
1225 case RIL_UNSOL_PCO_DATA: return "UNSOL_PCO_DATA";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001226 default: return "<unknown request>";
1227 }
1228}
1229
Etan Cohend3652192014-06-20 08:28:44 -07001230const char *
1231rilSocketIdToString(RIL_SOCKET_ID socket_id)
1232{
1233 switch(socket_id) {
1234 case RIL_SOCKET_1:
1235 return "RIL_SOCKET_1";
1236#if (SIM_COUNT >= 2)
1237 case RIL_SOCKET_2:
1238 return "RIL_SOCKET_2";
1239#endif
1240#if (SIM_COUNT >= 3)
1241 case RIL_SOCKET_3:
1242 return "RIL_SOCKET_3";
1243#endif
1244#if (SIM_COUNT >= 4)
1245 case RIL_SOCKET_4:
1246 return "RIL_SOCKET_4";
1247#endif
1248 default:
1249 return "not a valid RIL";
1250 }
1251}
1252
Amit Mahajanbd5595a2017-03-28 11:17:55 -07001253} /* namespace android */