blob: 3193d7c54164d6eaeeb8de60d716f9fdffb921d7 [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;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800117static int s_started = 0;
118
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800119static int s_fdWakeupRead;
120static int s_fdWakeupWrite;
121
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800122int s_wakelock_count = 0;
123
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800124static struct ril_event s_wakeupfd_event;
Etan Cohend3652192014-06-20 08:28:44 -0700125
126static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800127static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700128static RequestInfo *s_pendingRequests = NULL;
129
130#if (SIM_COUNT >= 2)
Etan Cohend3652192014-06-20 08:28:44 -0700131static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700132static RequestInfo *s_pendingRequests_socket2 = NULL;
133#endif
134
135#if (SIM_COUNT >= 3)
Etan Cohend3652192014-06-20 08:28:44 -0700136static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700137static RequestInfo *s_pendingRequests_socket3 = NULL;
138#endif
139
140#if (SIM_COUNT >= 4)
Etan Cohend3652192014-06-20 08:28:44 -0700141static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
Etan Cohend3652192014-06-20 08:28:44 -0700142static RequestInfo *s_pendingRequests_socket4 = NULL;
143#endif
144
Nathan Harolda0153392015-07-28 14:54:58 -0700145static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800146
Etan Cohend3652192014-06-20 08:28:44 -0700147
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800148static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
149static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
150
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800151static UserCallbackInfo *s_last_wake_timeout_info = NULL;
152
153static void *s_lastNITZTimeData = NULL;
154static size_t s_lastNITZTimeDataSize;
155
156#if RILC_LOG
157 static char printBuf[PRINTBUF_SIZE];
158#endif
159
160/*******************************************************************/
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800161static void grabPartialWakeLock();
Sanket Padawe85f952a2017-01-02 23:46:00 -0800162void releaseWakeLock();
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800163static void wakeTimeoutCallback(void *);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800164
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800165#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700166#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700167extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700168 size_t datalen, RIL_SOCKET_ID socket_id);
169#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700170extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800171 size_t datalen);
172#endif
Etan Cohend3652192014-06-20 08:28:44 -0700173#endif
174
175#if defined(ANDROID_MULTI_SIM)
176#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
177#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
178#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
179#else
180#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
181#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
182#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
183#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800184
Wink Saville7f856802009-06-09 10:23:37 -0700185static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700186 (RIL_TimedCallback callback, void *param,
187 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800188
189/** Index == requestNumber */
190static CommandInfo s_commands[] = {
191#include "ril_commands.h"
192};
193
194static UnsolResponseInfo s_unsolResponses[] = {
195#include "ril_unsol_commands.h"
196};
197
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700198char * RIL_getServiceName() {
199 return ril_service_name;
Etan Cohend3652192014-06-20 08:28:44 -0700200}
201
202extern "C"
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700203void RIL_setServiceName(const char * s) {
204 strncpy(ril_service_name, s, MAX_SERVICE_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -0700205}
206
Sanket Padawe85f952a2017-01-02 23:46:00 -0800207RequestInfo *
208addRequestToList(int serial, int slotId, int request) {
209 RequestInfo *pRI;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700210 int ret;
Sanket Padawe85f952a2017-01-02 23:46:00 -0800211 RIL_SOCKET_ID socket_id = (RIL_SOCKET_ID) slotId;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700212 /* Hook for current context */
213 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
214 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
215 /* pendingRequestsHook refer to &s_pendingRequests */
216 RequestInfo** pendingRequestsHook = &s_pendingRequests;
217
218#if (SIM_COUNT >= 2)
219 if (socket_id == RIL_SOCKET_2) {
220 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
221 pendingRequestsHook = &s_pendingRequests_socket2;
222 }
223#if (SIM_COUNT >= 3)
224 else if (socket_id == RIL_SOCKET_3) {
225 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
226 pendingRequestsHook = &s_pendingRequests_socket3;
227 }
228#endif
229#if (SIM_COUNT >= 4)
230 else if (socket_id == RIL_SOCKET_4) {
231 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
232 pendingRequestsHook = &s_pendingRequests_socket4;
233 }
234#endif
235#endif
236
Sanket Padawe85f952a2017-01-02 23:46:00 -0800237 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
238 if (pRI == NULL) {
239 RLOGE("Memory allocation failed for request %s", requestToString(request));
240 return NULL;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700241 }
242
Sanket Padawe85f952a2017-01-02 23:46:00 -0800243 pRI->token = serial;
244 pRI->pCI = &(s_commands[request]);
245 pRI->socket_id = socket_id;
246
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700247 ret = pthread_mutex_lock(pendingRequestsMutexHook);
248 assert (ret == 0);
249
250 pRI->p_next = *pendingRequestsHook;
251 *pendingRequestsHook = pRI;
252
253 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
254 assert (ret == 0);
255
Sanket Padawe85f952a2017-01-02 23:46:00 -0800256 return pRI;
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700257}
258
Wink Saville3d54e742009-05-18 18:00:44 -0700259static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800260 int ret;
261 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
262 /* trigger event loop to wakeup. No reason to do this,
263 * if we're in the event loop thread */
264 do {
265 ret = write (s_fdWakeupWrite, " ", 1);
266 } while (ret < 0 && errno == EINTR);
267 }
268}
269
Wink Saville3d54e742009-05-18 18:00:44 -0700270static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800271 ril_event_add(ev);
272 triggerEvLoop();
273}
274
275/**
276 * A write on the wakeup fd is done just to pop us out of select()
277 * We empty the buffer here and then ril_event will reset the timers on the
278 * way back down
279 */
Wink Savillef4c4d362009-04-02 01:37:03 -0700280static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800281 char buff[16];
282 int ret;
283
Wink Saville8eb2a122012-11-19 16:05:13 -0800284 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800285
286 /* empty our wakeup socket out */
287 do {
288 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -0700289 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800290}
291
Weilun Dud2c30932017-02-09 12:32:42 -0800292static void resendLastNITZTimeData(RIL_SOCKET_ID socket_id) {
293 if (s_lastNITZTimeData != NULL) {
Weilun Dud2c30932017-02-09 12:32:42 -0800294 int responseType = (s_callbacks.version >= 13)
295 ? RESPONSE_UNSOLICITED_ACK_EXP
296 : RESPONSE_UNSOLICITED;
297 int ret = radio::nitzTimeReceivedInd(
Amit Mahajan759786a2017-03-03 17:35:47 -0800298 (int)socket_id, responseType, 0,
Weilun Dud2c30932017-02-09 12:32:42 -0800299 RIL_E_SUCCESS, s_lastNITZTimeData, s_lastNITZTimeDataSize);
300 if (ret == 0) {
301 free(s_lastNITZTimeData);
302 s_lastNITZTimeData = NULL;
303 }
304 }
305}
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800306
Amit Mahajanc7ad6262017-03-14 16:39:27 -0700307void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -0700308 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -0700309 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -0700310 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
311 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -0700312
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800313 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -0700314 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
315 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800316
317 // Send last NITZ time data, in case it was missed
318 if (s_lastNITZTimeData != NULL) {
Weilun Dud2c30932017-02-09 12:32:42 -0800319 resendLastNITZTimeData(socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800320 }
321
322 // Get version string
323 if (s_callbacks.getVersion != NULL) {
324 const char *version;
325 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -0800326 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -0700327
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800328 property_set(PROPERTY_RIL_IMPL, version);
329 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -0800330 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800331 property_set(PROPERTY_RIL_IMPL, "unavailable");
332 }
333
334}
335
Wink Savillef4c4d362009-04-02 01:37:03 -0700336static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800337 UserCallbackInfo *p_info;
338
339 p_info = (UserCallbackInfo *)param;
340
341 p_info->p_callback(p_info->userParam);
342
343
344 // FIXME generalize this...there should be a cancel mechanism
345 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
346 s_last_wake_timeout_info = NULL;
347 }
348
349 free(p_info);
350}
351
352
353static void *
Wink Savillef4c4d362009-04-02 01:37:03 -0700354eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800355 int ret;
356 int filedes[2];
357
358 ril_event_init();
359
360 pthread_mutex_lock(&s_startupMutex);
361
362 s_started = 1;
363 pthread_cond_broadcast(&s_startupCond);
364
365 pthread_mutex_unlock(&s_startupMutex);
366
367 ret = pipe(filedes);
368
369 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800370 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800371 return NULL;
372 }
373
374 s_fdWakeupRead = filedes[0];
375 s_fdWakeupWrite = filedes[1];
376
377 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
378
379 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
380 processWakeupCallback, NULL);
381
382 rilEventAddWakeup (&s_wakeupfd_event);
383
384 // Only returns on error
385 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -0800386 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -0500387 // kill self to restart on error
388 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800389
390 return NULL;
391}
392
Wink Saville7f856802009-06-09 10:23:37 -0700393extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -0700394RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800395 /* spin up eventLoop thread and wait for it to get started */
396 s_started = 0;
397 pthread_mutex_lock(&s_startupMutex);
398
Elliott Hughesc0d8dc62014-01-03 15:31:42 -0800399 pthread_attr_t attr;
400 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -0700401 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -0800402
Elliott Hughesfd81e712014-01-06 12:46:02 -0800403 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
404 if (result != 0) {
405 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -0800406 goto done;
407 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800408
409 while (s_started == 0) {
410 pthread_cond_wait(&s_startupCond, &s_startupMutex);
411 }
412
Elliott Hughesc0d8dc62014-01-03 15:31:42 -0800413done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800414 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800415}
416
417// Used for testing purpose only.
418extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
419 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
420}
421
Wink Saville7f856802009-06-09 10:23:37 -0700422extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -0700423RIL_register (const RIL_RadioFunctions *callbacks) {
Etan Cohend3652192014-06-20 08:28:44 -0700424 RLOGI("SIM_COUNT: %d", SIM_COUNT);
425
Wink Saville43808972011-01-13 17:39:51 -0800426 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800427 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800428 return;
429 }
Wink Saville43808972011-01-13 17:39:51 -0800430 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800431 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -0800432 callbacks->version, RIL_VERSION_MIN);
433 return;
Wink Saville3a4840b2010-04-07 13:29:58 -0700434 }
Sanket Padawe4c05f352016-01-26 16:19:00 -0800435
Wink Saville8eb2a122012-11-19 16:05:13 -0800436 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800437
438 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800439 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800440 "Subsequent call ignored");
441 return;
442 }
443
444 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
445
446 s_registerCalled = 1;
447
Etan Cohend3652192014-06-20 08:28:44 -0700448 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800449 // Little self-check
450
Wink Savillef4c4d362009-04-02 01:37:03 -0700451 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800452 assert(i == s_commands[i].requestNumber);
453 }
454
Wink Savillef4c4d362009-04-02 01:37:03 -0700455 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -0700456 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800457 == s_unsolResponses[i].requestNumber);
458 }
459
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700460 radio::registerService(&s_callbacks, s_commands);
461 RLOGI("RILHIDL called registerService");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800462
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800463}
464
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200465extern "C" void
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700466RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),
467 RIL_SOCKET_TYPE socketType, int argc, char **argv) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200468
469 RIL_RadioFunctions* UimFuncs = NULL;
470
471 if(Init) {
472 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
473
474 switch(socketType) {
475 case RIL_SAP_SOCKET:
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700476 RilSapSocket::initSapSocket(RIL1_SERVICE_NAME, UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200477
478#if (SIM_COUNT >= 2)
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700479 RilSapSocket::initSapSocket(RIL2_SERVICE_NAME, UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200480#endif
481
482#if (SIM_COUNT >= 3)
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700483 RilSapSocket::initSapSocket(RIL3_SERVICE_NAME, UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200484#endif
485
486#if (SIM_COUNT >= 4)
Amit Mahajanbd5595a2017-03-28 11:17:55 -0700487 RilSapSocket::initSapSocket(RIL4_SERVICE_NAME, UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200488#endif
Meng Wangef966a32016-06-20 17:38:18 -0700489 break;
490 default:;
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200491 }
Amit Mahajanc2c71852016-11-29 16:48:54 -0800492
493 RLOGI("RIL_register_socket: calling registerService");
494 sap::registerService(UimFuncs);
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200495 }
496}
497
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800498// Check and remove RequestInfo if its a response and not just ack sent back
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800499static int
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800500checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800501 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -0700502 /* Hook for current context
503 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
504 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
505 /* pendingRequestsHook refer to &s_pendingRequests */
506 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -0700507
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800508 if (pRI == NULL) {
509 return 0;
510 }
511
Etan Cohend3652192014-06-20 08:28:44 -0700512#if (SIM_COUNT >= 2)
513 if (pRI->socket_id == RIL_SOCKET_2) {
514 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
515 pendingRequestsHook = &s_pendingRequests_socket2;
516 }
517#if (SIM_COUNT >= 3)
518 if (pRI->socket_id == RIL_SOCKET_3) {
519 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
520 pendingRequestsHook = &s_pendingRequests_socket3;
521 }
522#endif
523#if (SIM_COUNT >= 4)
524 if (pRI->socket_id == RIL_SOCKET_4) {
525 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
526 pendingRequestsHook = &s_pendingRequests_socket4;
527 }
528#endif
529#endif
530 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800531
Etan Cohend3652192014-06-20 08:28:44 -0700532 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -0700533 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800534 ; ppCur = &((*ppCur)->p_next)
535 ) {
536 if (pRI == *ppCur) {
537 ret = 1;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800538 if (isAck) { // Async ack
539 if (pRI->wasAckSent == 1) {
540 RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
541 } else {
542 pRI->wasAckSent = 1;
543 }
544 } else {
545 *ppCur = (*ppCur)->p_next;
546 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800547 break;
548 }
549 }
550
Etan Cohend3652192014-06-20 08:28:44 -0700551 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800552
553 return ret;
554}
555
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800556extern "C" void
557RIL_onRequestAck(RIL_Token t) {
558 RequestInfo *pRI;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800559
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800560 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
561
562 pRI = (RequestInfo *)t;
563
564 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
565 RLOGE ("RIL_onRequestAck: invalid RIL_Token");
566 return;
567 }
568
569 socket_id = pRI->socket_id;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800570
571#if VDBG
572 RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
573#endif
574
575 appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));
576
577 if (pRI->cancelled == 0) {
Jack Yubbd4b1b2017-02-13 11:21:00 -0800578 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(
579 (int) socket_id);
580 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
581 assert(rwlockRet == 0);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800582
Jack Yubbd4b1b2017-02-13 11:21:00 -0800583 radio::acknowledgeRequest((int) socket_id, pRI->token);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800584
Jack Yubbd4b1b2017-02-13 11:21:00 -0800585 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
586 assert(rwlockRet == 0);
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800587 }
588}
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800589extern "C" void
590RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
591 RequestInfo *pRI;
592 int ret;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800593 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
594
595 pRI = (RequestInfo *)t;
596
597 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
598 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
599 return;
600 }
601
602 socket_id = pRI->socket_id;
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700603#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -0700604 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700605#endif
Etan Cohend3652192014-06-20 08:28:44 -0700606
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800607 if (pRI->local > 0) {
608 // Locally issued command...void only!
609 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -0800610 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800611
Jack Yubbd4b1b2017-02-13 11:21:00 -0800612 free(pRI);
613 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800614 }
615
616 appendPrintBuf("[%04d]< %s",
617 pRI->token, requestToString(pRI->pCI->requestNumber));
618
619 if (pRI->cancelled == 0) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700620 int responseType;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800621 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
622 // If ack was already sent, then this call is an asynchronous response. So we need to
623 // send id indicating that we expect an ack from RIL.java as we acquire wakelock here.
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700624 responseType = RESPONSE_SOLICITED_ACK_EXP;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800625 grabPartialWakeLock();
626 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700627 responseType = RESPONSE_SOLICITED;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800628 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800629
Jack Yubbd4b1b2017-02-13 11:21:00 -0800630 // there is a response payload, no matter success or not.
Jayachandran C572f2f42017-03-25 14:30:13 -0700631#if VDBG
Jack Yubbd4b1b2017-02-13 11:21:00 -0800632 RLOGE ("Calling responseFunction() for token %d", pRI->token);
Jayachandran C572f2f42017-03-25 14:30:13 -0700633#endif
Sanket Padawe85f952a2017-01-02 23:46:00 -0800634
Jack Yubbd4b1b2017-02-13 11:21:00 -0800635 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock((int) socket_id);
636 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
637 assert(rwlockRet == 0);
Amit Mahajan32ec8a42017-01-24 05:45:02 -0800638
Amit Mahajan759786a2017-03-03 17:35:47 -0800639 ret = pRI->pCI->responseFunction((int) socket_id,
Jack Yubbd4b1b2017-02-13 11:21:00 -0800640 responseType, pRI->token, e, response, responselen);
Amit Mahajan32ec8a42017-01-24 05:45:02 -0800641
Jack Yubbd4b1b2017-02-13 11:21:00 -0800642 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
643 assert(rwlockRet == 0);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800644 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800645 free(pRI);
646}
647
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800648static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700649grabPartialWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800650 if (s_callbacks.version >= 13) {
651 int ret;
652 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
653 assert(ret == 0);
654 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
Sanket Padawe55227b52016-02-29 10:09:26 -0800655
656 UserCallbackInfo *p_info =
657 internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
658 if (p_info == NULL) {
659 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
660 } else {
661 s_wakelock_count++;
662 if (s_last_wake_timeout_info != NULL) {
663 s_last_wake_timeout_info->userParam = (void *)1;
664 }
665 s_last_wake_timeout_info = p_info;
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800666 }
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800667 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
668 assert(ret == 0);
669 } else {
670 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
671 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800672}
673
Sanket Padawe85f952a2017-01-02 23:46:00 -0800674void
Wink Savillef4c4d362009-04-02 01:37:03 -0700675releaseWakeLock() {
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800676 if (s_callbacks.version >= 13) {
677 int ret;
678 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
679 assert(ret == 0);
680
681 if (s_wakelock_count > 1) {
682 s_wakelock_count--;
683 } else {
684 s_wakelock_count = 0;
685 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
686 if (s_last_wake_timeout_info != NULL) {
687 s_last_wake_timeout_info->userParam = (void *)1;
688 }
689 }
690
691 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
692 assert(ret == 0);
693 } else {
694 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
695 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800696}
697
698/**
699 * Timer callback to put us back to sleep before the default timeout
700 */
701static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700702wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800703 // We're using "param != NULL" as a cancellation mechanism
Sanket Padawe6ff9a872016-01-27 15:09:12 -0800704 if (s_callbacks.version >= 13) {
705 if (param == NULL) {
706 int ret;
707 ret = pthread_mutex_lock(&s_wakeLockCountMutex);
708 assert(ret == 0);
709 s_wakelock_count = 0;
710 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
711 ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
712 assert(ret == 0);
713 }
714 } else {
715 if (param == NULL) {
716 releaseWakeLock();
717 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800718 }
719}
720
Etan Cohend3652192014-06-20 08:28:44 -0700721#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800722extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +0100723void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700724 size_t datalen, RIL_SOCKET_ID socket_id)
725#else
726extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +0100727void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800728 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -0700729#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800730{
731 int unsolResponseIndex;
732 int ret;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800733 bool shouldScheduleTimeout = false;
Etan Cohend3652192014-06-20 08:28:44 -0700734 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
735
736#if defined(ANDROID_MULTI_SIM)
737 soc_id = socket_id;
738#endif
739
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800740
741 if (s_registerCalled == 0) {
742 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -0800743 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800744 return;
745 }
Wink Saville7f856802009-06-09 10:23:37 -0700746
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800747 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
748
749 if ((unsolResponseIndex < 0)
750 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800751 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800752 return;
753 }
754
755 // Grab a wake lock if needed for this reponse,
756 // as we exit we'll either release it immediately
757 // or set a timer to release it later.
758 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
759 case WAKE_PARTIAL:
760 grabPartialWakeLock();
761 shouldScheduleTimeout = true;
762 break;
763
764 case DONT_WAKE:
765 default:
766 // No wake lock is grabed so don't set timeout
767 shouldScheduleTimeout = false;
768 break;
769 }
770
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800771 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
772
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700773 int responseType;
Sanket Padawed8c0b462016-02-03 11:46:02 -0800774 if (s_callbacks.version >= 13
775 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700776 responseType = RESPONSE_UNSOLICITED_ACK_EXP;
Sanket Padawed8c0b462016-02-03 11:46:02 -0800777 } else {
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700778 responseType = RESPONSE_UNSOLICITED;
Sanket Padawed8c0b462016-02-03 11:46:02 -0800779 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800780
Amit Mahajan32ec8a42017-01-24 05:45:02 -0800781 pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock((int) soc_id);
782 int rwlockRet = pthread_rwlock_rdlock(radioServiceRwlockPtr);
783 assert(rwlockRet == 0);
784
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700785 ret = s_unsolResponses[unsolResponseIndex].responseFunction(
Amit Mahajan759786a2017-03-03 17:35:47 -0800786 (int) soc_id, responseType, 0, RIL_E_SUCCESS, const_cast<void*>(data),
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700787 datalen);
Amit Mahajan32ec8a42017-01-24 05:45:02 -0800788
789 rwlockRet = pthread_rwlock_unlock(radioServiceRwlockPtr);
790 assert(rwlockRet == 0);
791
Sanket Padawe55227b52016-02-29 10:09:26 -0800792 if (s_callbacks.version < 13) {
793 if (shouldScheduleTimeout) {
794 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
795 &TIMEVAL_WAKE_TIMEOUT);
796
797 if (p_info == NULL) {
798 goto error_exit;
799 } else {
800 // Cancel the previous request
801 if (s_last_wake_timeout_info != NULL) {
802 s_last_wake_timeout_info->userParam = (void *)1;
803 }
804 s_last_wake_timeout_info = p_info;
805 }
806 }
807 }
808
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700809#if VDBG
Amit Mahajan18fe36b2016-08-25 11:19:21 -0700810 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id),
Amit Mahajanc7ad6262017-03-14 16:39:27 -0700811 requestToString(unsolResponse), datalen);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700812#endif
Weilun Dud2c30932017-02-09 12:32:42 -0800813
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800814 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800815 // Unfortunately, NITZ time is not poll/update like everything
816 // else in the system. So, if the upstream client isn't connected,
817 // keep a copy of the last NITZ response (with receive time noted
818 // above) around so we can deliver it when it is connected
819
820 if (s_lastNITZTimeData != NULL) {
Weilun Dud2c30932017-02-09 12:32:42 -0800821 free(s_lastNITZTimeData);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800822 s_lastNITZTimeData = NULL;
823 }
824
Weilun Dud2c30932017-02-09 12:32:42 -0800825 s_lastNITZTimeData = calloc(datalen, 1);
Sanket Padawe55227b52016-02-29 10:09:26 -0800826 if (s_lastNITZTimeData == NULL) {
Weilun Dud2c30932017-02-09 12:32:42 -0800827 RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
828 goto error_exit;
Sanket Padawe55227b52016-02-29 10:09:26 -0800829 }
Weilun Dud2c30932017-02-09 12:32:42 -0800830 s_lastNITZTimeDataSize = datalen;
831 memcpy(s_lastNITZTimeData, data, datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800832 }
833
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800834 // Normal exit
835 return;
836
837error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800838 if (shouldScheduleTimeout) {
839 releaseWakeLock();
840 }
841}
842
Wink Saville7f856802009-06-09 10:23:37 -0700843/** FIXME generalize this if you track UserCAllbackInfo, clear it
844 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800845*/
846static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -0700847internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700848 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800849{
850 struct timeval myRelativeTime;
851 UserCallbackInfo *p_info;
852
Sanket Padawe0cfc5532016-03-07 17:12:19 -0800853 p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
Sanket Padawe55227b52016-02-29 10:09:26 -0800854 if (p_info == NULL) {
855 RLOGE("Memory allocation failed in internalRequestTimedCallback");
856 return p_info;
857
858 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800859
Wink Saville7f856802009-06-09 10:23:37 -0700860 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800861 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700862
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863 if (relativeTime == NULL) {
864 /* treat null parameter as a 0 relative time */
865 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
866 } else {
867 /* FIXME I think event_add's tv param is really const anyway */
868 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
869 }
870
871 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
872
873 ril_timer_add(&(p_info->event), &myRelativeTime);
874
875 triggerEvLoop();
876 return p_info;
877}
878
Naveen Kalla7edd07c2010-06-21 18:54:47 -0700879
880extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700881RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
882 const struct timeval *relativeTime) {
883 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800884}
885
886const char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700887failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800888 switch(e) {
889 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -0700890 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800891 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
892 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
893 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
894 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
895 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
896 case RIL_E_CANCELLED: return "E_CANCELLED";
897 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
898 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
899 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -0700900 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -0700901 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -0700902#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -0700903 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
904 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
905#endif
Sanket Padaweb39e5c92016-02-08 14:28:59 -0800906 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
907 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
908 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
909 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
910 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
911 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
912 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
913 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
914 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
915 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
916 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
917 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
918 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
919 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
920 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
921 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
922 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
923 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
924 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
925 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
926 case RIL_E_SIM_ERR: return "E_SIM_ERR";
927 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
928 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
929 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
930 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
931 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
932 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
933 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
twen.changdf7add02016-03-04 18:27:48 +0800934 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
935 case RIL_E_SIM_FULL: return "E_SIM_FULL";
936 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
937 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
Tomasz Wasilczyk88961c22017-04-11 09:21:08 -0700938 case RIL_E_EMPTY_RECORD: return "E_EMPTY_RECORD";
Ajay Nambi68900f52016-03-11 12:02:55 -0800939 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
940 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
941 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
942 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
943 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
944 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
Ajay Nambi10345892016-03-19 09:02:28 -0700945 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
946 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
947 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
948 case RIL_E_ABORTED: return "E_ABORTED";
Sanket Padawe85f952a2017-01-02 23:46:00 -0800949 case RIL_E_INVALID_RESPONSE: return "INVALID_RESPONSE";
Sanket Padawe0106aed2016-02-09 09:56:31 -0800950 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
951 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
952 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
953 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
954 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
955 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
956 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
957 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
958 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
959 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
960 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
961 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
962 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
963 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
964 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
965 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
966 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
967 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
968 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
969 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
970 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
971 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
972 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
973 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
974 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800975 default: return "<unknown error>";
976 }
977}
978
979const char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700980radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800981 switch(s) {
982 case RADIO_STATE_OFF: return "RADIO_OFF";
983 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800984 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800985 default: return "<unknown state>";
986 }
987}
988
989const char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700990callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800991 switch(s) {
992 case RIL_CALL_ACTIVE : return "ACTIVE";
993 case RIL_CALL_HOLDING: return "HOLDING";
994 case RIL_CALL_DIALING: return "DIALING";
995 case RIL_CALL_ALERTING: return "ALERTING";
996 case RIL_CALL_INCOMING: return "INCOMING";
997 case RIL_CALL_WAITING: return "WAITING";
998 default: return "<unknown state>";
999 }
1000}
1001
1002const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07001003requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001004/*
1005 cat libs/telephony/ril_commands.h \
1006 | egrep "^ *{RIL_" \
1007 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
1008
1009
1010 cat libs/telephony/ril_unsol_commands.h \
1011 | egrep "^ *{RIL_" \
1012 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
1013
1014*/
1015 switch(request) {
1016 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
1017 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
1018 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
1019 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
1020 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
1021 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
1022 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
1023 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
1024 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
1025 case RIL_REQUEST_DIAL: return "DIAL";
1026 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
1027 case RIL_REQUEST_HANGUP: return "HANGUP";
1028 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
1029 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
1030 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
1031 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
1032 case RIL_REQUEST_UDUB: return "UDUB";
1033 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
1034 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08001035 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
1036 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001037 case RIL_REQUEST_OPERATOR: return "OPERATOR";
1038 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
1039 case RIL_REQUEST_DTMF: return "DTMF";
1040 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
1041 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07001042 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001043 case RIL_REQUEST_SIM_IO: return "SIM_IO";
1044 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
1045 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
1046 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
1047 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
1048 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
1049 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
1050 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
1051 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
1052 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
1053 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
1054 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
1055 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07001056 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001057 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
1058 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
1059 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
1060 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
1061 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
1062 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
Matt Mower897915e2015-04-08 23:16:03 -05001063 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: return "QUERY_AVAILABLE_NETWORKS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001064 case RIL_REQUEST_DTMF_START: return "DTMF_START";
1065 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
1066 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
1067 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001068 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
1069 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
1070 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07001071 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
1072 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001073 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
1074 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
1075 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Matt Mower897915e2015-04-08 23:16:03 -05001076 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
1077 case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: return "SET_SUPP_SVC_NOTIFICATION";
1078 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
1079 case RIL_REQUEST_DELETE_SMS_ON_SIM: return "DELETE_SMS_ON_SIM";
Wink Savillef4c4d362009-04-02 01:37:03 -07001080 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
1081 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001082 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
1083 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
1084 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
1085 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
1086 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 -08001087 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
Matt Mower897915e2015-04-08 23:16:03 -05001088 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
1089 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
1090 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001091 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Matt Mower897915e2015-04-08 23:16:03 -05001092 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: return "CDMA_SET_SUBSCRIPTION_SOURCE";
1093 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: return "CDMA_SET_ROAMING_PREFERENCE";
1094 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: return "CDMA_QUERY_ROAMING_PREFERENCE";
1095 case RIL_REQUEST_SET_TTY_MODE: return "SET_TTY_MODE";
1096 case RIL_REQUEST_QUERY_TTY_MODE: return "QUERY_TTY_MODE";
1097 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
1098 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: return "CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
1099 case RIL_REQUEST_CDMA_FLASH: return "CDMA_FLASH";
1100 case RIL_REQUEST_CDMA_BURST_DTMF: return "CDMA_BURST_DTMF";
1101 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return "CDMA_VALIDATE_AND_WRITE_AKEY";
1102 case RIL_REQUEST_CDMA_SEND_SMS: return "CDMA_SEND_SMS";
1103 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: return "CDMA_SMS_ACKNOWLEDGE";
1104 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG: return "GSM_GET_BROADCAST_SMS_CONFIG";
1105 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG: return "GSM_SET_BROADCAST_SMS_CONFIG";
1106 case RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION: return "GSM_SMS_BROADCAST_ACTIVATION";
1107 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG: return "CDMA_GET_BROADCAST_SMS_CONFIG";
1108 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG: return "CDMA_SET_BROADCAST_SMS_CONFIG";
1109 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION: return "CDMA_SMS_BROADCAST_ACTIVATION";
1110 case RIL_REQUEST_CDMA_SUBSCRIPTION: return "CDMA_SUBSCRIPTION";
Wink Savillef4c4d362009-04-02 01:37:03 -07001111 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
1112 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
1113 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07001114 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
1115 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
1116 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07001117 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07001118 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08001119 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07001120 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Matt Mower897915e2015-04-08 23:16:03 -05001121 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
1122 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001123 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Matt Mower897915e2015-04-08 23:16:03 -05001124 case RIL_REQUEST_GET_CELL_INFO_LIST: return "GET_CELL_INFO_LIST";
1125 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return "SET_UNSOL_CELL_INFO_LIST_RATE";
1126 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001127 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
1128 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08001129 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
1130 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
1131 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
1132 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Matt Mower897915e2015-04-08 23:16:03 -05001133 case RIL_REQUEST_NV_READ_ITEM: return "NV_READ_ITEM";
1134 case RIL_REQUEST_NV_WRITE_ITEM: return "NV_WRITE_ITEM";
1135 case RIL_REQUEST_NV_WRITE_CDMA_PRL: return "NV_WRITE_CDMA_PRL";
1136 case RIL_REQUEST_NV_RESET_CONFIG: return "NV_RESET_CONFIG";
Etan Cohend3652192014-06-20 08:28:44 -07001137 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
1138 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07001139 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
1140 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07001141 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
1142 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00001143 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Matt Mower897915e2015-04-08 23:16:03 -05001144 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
1145 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "GET_RADIO_CAPABILITY";
1146 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "SET_RADIO_CAPABILITY";
1147 case RIL_REQUEST_START_LCE: return "START_LCE";
1148 case RIL_REQUEST_STOP_LCE: return "STOP_LCE";
1149 case RIL_REQUEST_PULL_LCEDATA: return "PULL_LCEDATA";
1150 case RIL_REQUEST_GET_ACTIVITY_INFO: return "GET_ACTIVITY_INFO";
Meng Wangb4e34312016-05-12 14:54:36 -07001151 case RIL_REQUEST_SET_CARRIER_RESTRICTIONS: return "SET_CARRIER_RESTRICTIONS";
1152 case RIL_REQUEST_GET_CARRIER_RESTRICTIONS: return "GET_CARRIER_RESTRICTIONS";
Matt Mower897915e2015-04-08 23:16:03 -05001153 case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RESPONSE_ACKNOWLEDGEMENT";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001154 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
1155 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08001156 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 -08001157 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
1158 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
1159 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
1160 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
Matt Mower897915e2015-04-08 23:16:03 -05001161 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001162 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
1163 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Matt Mower897915e2015-04-08 23:16:03 -05001164 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
Sanket Padawe0eb4fba2016-01-26 17:28:38 -08001165 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001166 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
1167 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
1168 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
1169 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
Matt Mower897915e2015-04-08 23:16:03 -05001170 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FULL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001171 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001172 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07001173 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05001174 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_RESPONSE_CDMA_NEW_SMS";
1175 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_RESPONSE_NEW_BROADCAST_SMS";
Wink Savillef4c4d362009-04-02 01:37:03 -07001176 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07001177 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
1178 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
1179 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
1180 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
1181 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07001182 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07001183 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08001184 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07001185 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08001186 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
1187 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07001188 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001189 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07001190 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Matt Mower897915e2015-04-08 23:16:03 -05001191 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07001192 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
1193 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
Matt Mower897915e2015-04-08 23:16:03 -05001194 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "UNSOL_HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07001195 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Matt Mower897915e2015-04-08 23:16:03 -05001196 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
Mark Salyzyn0078c8d2016-12-12 14:41:47 -08001197 case RIL_UNSOL_MODEM_RESTART: return "UNSOL_MODEM_RESTART";
Matt Mower897915e2015-04-08 23:16:03 -05001198 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
1199 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
1200 case RIL_UNSOL_LCEDATA_RECV: return "UNSOL_LCEDATA_RECV";
1201 case RIL_UNSOL_PCO_DATA: return "UNSOL_PCO_DATA";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001202 default: return "<unknown request>";
1203 }
1204}
1205
Etan Cohend3652192014-06-20 08:28:44 -07001206const char *
1207rilSocketIdToString(RIL_SOCKET_ID socket_id)
1208{
1209 switch(socket_id) {
1210 case RIL_SOCKET_1:
1211 return "RIL_SOCKET_1";
1212#if (SIM_COUNT >= 2)
1213 case RIL_SOCKET_2:
1214 return "RIL_SOCKET_2";
1215#endif
1216#if (SIM_COUNT >= 3)
1217 case RIL_SOCKET_3:
1218 return "RIL_SOCKET_3";
1219#endif
1220#if (SIM_COUNT >= 4)
1221 case RIL_SOCKET_4:
1222 return "RIL_SOCKET_4";
1223#endif
1224 default:
1225 return "not a valid RIL";
1226 }
1227}
1228
Amit Mahajanbd5595a2017-03-28 11:17:55 -07001229} /* namespace android */