The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1 | /* //device/libs/telephony/ril.cpp |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 8 | ** |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 10 | ** |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "RILC" |
| 19 | |
| 20 | #include <hardware_legacy/power.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 21 | #include <telephony/ril.h> |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 22 | #include <telephony/ril_cdma_sms.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 23 | #include <cutils/sockets.h> |
| 24 | #include <cutils/jstring.h> |
Dima Zavin | 622bf2b | 2013-05-22 11:29:34 -0700 | [diff] [blame] | 25 | #include <telephony/record_stream.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 26 | #include <utils/Log.h> |
| 27 | #include <utils/SystemClock.h> |
| 28 | #include <pthread.h> |
Mathias Agopian | 8a3c48c | 2009-05-19 19:11:50 -0700 | [diff] [blame] | 29 | #include <binder/Parcel.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 30 | #include <cutils/jstring.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 31 | #include <sys/types.h> |
Wink Saville | 18e4ab1 | 2013-04-07 17:31:04 -0700 | [diff] [blame] | 32 | #include <sys/limits.h> |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 33 | #include <sys/system_properties.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 34 | #include <pwd.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
| 37 | #include <stdarg.h> |
| 38 | #include <string.h> |
| 39 | #include <unistd.h> |
| 40 | #include <fcntl.h> |
| 41 | #include <time.h> |
| 42 | #include <errno.h> |
| 43 | #include <assert.h> |
| 44 | #include <ctype.h> |
| 45 | #include <alloca.h> |
| 46 | #include <sys/un.h> |
| 47 | #include <assert.h> |
| 48 | #include <netinet/in.h> |
| 49 | #include <cutils/properties.h> |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 50 | #include <RilSapSocket.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 51 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 52 | extern "C" void |
| 53 | RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen); |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 54 | |
| 55 | extern "C" void |
| 56 | RIL_onRequestAck(RIL_Token t); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 57 | namespace android { |
| 58 | |
| 59 | #define PHONE_PROCESS "radio" |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 60 | #define BLUETOOTH_PROCESS "bluetooth" |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 61 | |
| 62 | #define SOCKET_NAME_RIL "rild" |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 63 | #define SOCKET2_NAME_RIL "rild2" |
| 64 | #define SOCKET3_NAME_RIL "rild3" |
| 65 | #define SOCKET4_NAME_RIL "rild4" |
| 66 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 67 | #define SOCKET_NAME_RIL_DEBUG "rild-debug" |
| 68 | |
| 69 | #define ANDROID_WAKE_LOCK_NAME "radio-interface" |
| 70 | |
Nathan Harold | a015339 | 2015-07-28 14:54:58 -0700 | [diff] [blame] | 71 | #define ANDROID_WAKE_LOCK_SECS 0 |
| 72 | #define ANDROID_WAKE_LOCK_USECS 200000 |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 73 | |
| 74 | #define PROPERTY_RIL_IMPL "gsm.version.ril-impl" |
| 75 | |
| 76 | // match with constant in RIL.java |
| 77 | #define MAX_COMMAND_BYTES (8 * 1024) |
| 78 | |
| 79 | // Basically: memset buffers that the client library |
| 80 | // shouldn't be using anymore in an attempt to find |
| 81 | // memory usage issues sooner. |
| 82 | #define MEMSET_FREED 1 |
| 83 | |
| 84 | #define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0]) |
| 85 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 86 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) |
| 87 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 88 | /* Constants for response types */ |
| 89 | #define RESPONSE_SOLICITED 0 |
| 90 | #define RESPONSE_UNSOLICITED 1 |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 91 | #define RESPONSE_SOLICITED_ACK 2 |
| 92 | #define RESPONSE_SOLICITED_ACK_EXP 3 |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 93 | |
| 94 | /* Negative values for private RIL errno's */ |
| 95 | #define RIL_ERRNO_INVALID_RESPONSE -1 |
| 96 | |
| 97 | // request, response, and unsolicited msg print macro |
| 98 | #define PRINTBUF_SIZE 8096 |
| 99 | |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 100 | // Enable verbose logging |
| 101 | #define VDBG 0 |
| 102 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 103 | // Enable RILC log |
| 104 | #define RILC_LOG 0 |
| 105 | |
| 106 | #if RILC_LOG |
| 107 | #define startRequest sprintf(printBuf, "(") |
| 108 | #define closeRequest sprintf(printBuf, "%s)", printBuf) |
| 109 | #define printRequest(token, req) \ |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 110 | RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 111 | |
| 112 | #define startResponse sprintf(printBuf, "%s {", printBuf) |
| 113 | #define closeResponse sprintf(printBuf, "%s}", printBuf) |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 114 | #define printResponse RLOGD("%s", printBuf) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 115 | |
| 116 | #define clearPrintBuf printBuf[0] = 0 |
| 117 | #define removeLastChar printBuf[strlen(printBuf)-1] = 0 |
| 118 | #define appendPrintBuf(x...) sprintf(printBuf, x) |
| 119 | #else |
| 120 | #define startRequest |
| 121 | #define closeRequest |
| 122 | #define printRequest(token, req) |
| 123 | #define startResponse |
| 124 | #define closeResponse |
| 125 | #define printResponse |
| 126 | #define clearPrintBuf |
| 127 | #define removeLastChar |
| 128 | #define appendPrintBuf(x...) |
| 129 | #endif |
| 130 | |
| 131 | enum WakeType {DONT_WAKE, WAKE_PARTIAL}; |
| 132 | |
| 133 | typedef struct { |
| 134 | int requestNumber; |
| 135 | void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI); |
| 136 | int(*responseFunction) (Parcel &p, void *response, size_t responselen); |
| 137 | } CommandInfo; |
| 138 | |
| 139 | typedef struct { |
| 140 | int requestNumber; |
| 141 | int (*responseFunction) (Parcel &p, void *response, size_t responselen); |
| 142 | WakeType wakeType; |
| 143 | } UnsolResponseInfo; |
| 144 | |
| 145 | typedef struct RequestInfo { |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 146 | int32_t token; //this is not RIL_Token |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 147 | CommandInfo *pCI; |
| 148 | struct RequestInfo *p_next; |
| 149 | char cancelled; |
| 150 | char local; // responses to local commands do not go back to command process |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 151 | RIL_SOCKET_ID socket_id; |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 152 | int wasAckSent; // Indicates whether an ack was sent earlier |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 153 | } RequestInfo; |
| 154 | |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 155 | typedef struct UserCallbackInfo { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 156 | RIL_TimedCallback p_callback; |
| 157 | void *userParam; |
| 158 | struct ril_event event; |
| 159 | struct UserCallbackInfo *p_next; |
| 160 | } UserCallbackInfo; |
| 161 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 162 | extern "C" const char * requestToString(int request); |
| 163 | extern "C" const char * failCauseToString(RIL_Errno); |
| 164 | extern "C" const char * callStateToString(RIL_CallState); |
| 165 | extern "C" const char * radioStateToString(RIL_RadioState); |
| 166 | extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id); |
| 167 | |
| 168 | extern "C" |
| 169 | char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 170 | /*******************************************************************/ |
| 171 | |
| 172 | RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL}; |
| 173 | static int s_registerCalled = 0; |
| 174 | |
| 175 | static pthread_t s_tid_dispatch; |
| 176 | static pthread_t s_tid_reader; |
| 177 | static int s_started = 0; |
| 178 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 179 | static int s_fdDebug = -1; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 180 | static int s_fdDebug_socket2 = -1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 181 | |
| 182 | static int s_fdWakeupRead; |
| 183 | static int s_fdWakeupWrite; |
| 184 | |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 185 | int s_wakelock_count = 0; |
| 186 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 187 | static struct ril_event s_commands_event; |
| 188 | static struct ril_event s_wakeupfd_event; |
| 189 | static struct ril_event s_listen_event; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 190 | static SocketListenParam s_ril_param_socket; |
| 191 | |
| 192 | static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER; |
| 193 | static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER; |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 194 | static pthread_mutex_t s_wakeLockCountMutex = PTHREAD_MUTEX_INITIALIZER; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 195 | static RequestInfo *s_pendingRequests = NULL; |
| 196 | |
| 197 | #if (SIM_COUNT >= 2) |
| 198 | static struct ril_event s_commands_event_socket2; |
| 199 | static struct ril_event s_listen_event_socket2; |
| 200 | static SocketListenParam s_ril_param_socket2; |
| 201 | |
| 202 | static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER; |
| 203 | static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER; |
| 204 | static RequestInfo *s_pendingRequests_socket2 = NULL; |
| 205 | #endif |
| 206 | |
| 207 | #if (SIM_COUNT >= 3) |
| 208 | static struct ril_event s_commands_event_socket3; |
| 209 | static struct ril_event s_listen_event_socket3; |
| 210 | static SocketListenParam s_ril_param_socket3; |
| 211 | |
| 212 | static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER; |
| 213 | static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER; |
| 214 | static RequestInfo *s_pendingRequests_socket3 = NULL; |
| 215 | #endif |
| 216 | |
| 217 | #if (SIM_COUNT >= 4) |
| 218 | static struct ril_event s_commands_event_socket4; |
| 219 | static struct ril_event s_listen_event_socket4; |
| 220 | static SocketListenParam s_ril_param_socket4; |
| 221 | |
| 222 | static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER; |
| 223 | static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER; |
| 224 | static RequestInfo *s_pendingRequests_socket4 = NULL; |
| 225 | #endif |
| 226 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 227 | static struct ril_event s_wake_timeout_event; |
| 228 | static struct ril_event s_debug_event; |
| 229 | |
| 230 | |
Nathan Harold | a015339 | 2015-07-28 14:54:58 -0700 | [diff] [blame] | 231 | static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS}; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 232 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 233 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 234 | static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER; |
| 235 | static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER; |
| 236 | |
| 237 | static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER; |
| 238 | static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER; |
| 239 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 240 | static RequestInfo *s_toDispatchHead = NULL; |
| 241 | static RequestInfo *s_toDispatchTail = NULL; |
| 242 | |
| 243 | static UserCallbackInfo *s_last_wake_timeout_info = NULL; |
| 244 | |
| 245 | static void *s_lastNITZTimeData = NULL; |
| 246 | static size_t s_lastNITZTimeDataSize; |
| 247 | |
| 248 | #if RILC_LOG |
| 249 | static char printBuf[PRINTBUF_SIZE]; |
| 250 | #endif |
| 251 | |
| 252 | /*******************************************************************/ |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 253 | static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 254 | |
| 255 | static void dispatchVoid (Parcel& p, RequestInfo *pRI); |
| 256 | static void dispatchString (Parcel& p, RequestInfo *pRI); |
| 257 | static void dispatchStrings (Parcel& p, RequestInfo *pRI); |
| 258 | static void dispatchInts (Parcel& p, RequestInfo *pRI); |
| 259 | static void dispatchDial (Parcel& p, RequestInfo *pRI); |
| 260 | static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI); |
Shishir Agrawal | 2458d8d | 2013-11-27 14:53:05 -0800 | [diff] [blame] | 261 | static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 262 | static void dispatchCallForward(Parcel& p, RequestInfo *pRI); |
| 263 | static void dispatchRaw(Parcel& p, RequestInfo *pRI); |
| 264 | static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI); |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 265 | static void dispatchDataCall (Parcel& p, RequestInfo *pRI); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 266 | static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI); |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 267 | static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 268 | static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 269 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 270 | static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 271 | static void dispatchImsSms(Parcel &p, RequestInfo *pRI); |
| 272 | static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef); |
| 273 | static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 274 | static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 275 | static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 276 | static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI); |
| 277 | static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI); |
Jake Hamby | 8a4a233 | 2014-01-15 13:12:05 -0800 | [diff] [blame] | 278 | static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI); |
| 279 | static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 280 | static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI); |
Amit Mahajan | 90530a6 | 2014-07-01 15:54:08 -0700 | [diff] [blame] | 281 | static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI); |
Amit Mahajan | c796e22 | 2014-08-13 16:54:01 +0000 | [diff] [blame] | 282 | static void dispatchDataProfile(Parcel &p, RequestInfo *pRI); |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 283 | static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 284 | static int responseInts(Parcel &p, void *response, size_t responselen); |
Chao Liu | 548a81e | 2015-05-14 16:13:46 -0700 | [diff] [blame] | 285 | static int responseFailCause(Parcel &p, void *response, size_t responselen); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 286 | static int responseStrings(Parcel &p, void *response, size_t responselen); |
| 287 | static int responseString(Parcel &p, void *response, size_t responselen); |
| 288 | static int responseVoid(Parcel &p, void *response, size_t responselen); |
| 289 | static int responseCallList(Parcel &p, void *response, size_t responselen); |
| 290 | static int responseSMS(Parcel &p, void *response, size_t responselen); |
| 291 | static int responseSIM_IO(Parcel &p, void *response, size_t responselen); |
| 292 | static int responseCallForwards(Parcel &p, void *response, size_t responselen); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 293 | static int responseDataCallList(Parcel &p, void *response, size_t responselen); |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 294 | static int responseSetupDataCall(Parcel &p, void *response, size_t responselen); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 295 | static int responseRaw(Parcel &p, void *response, size_t responselen); |
| 296 | static int responseSsn(Parcel &p, void *response, size_t responselen); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 297 | static int responseSimStatus(Parcel &p, void *response, size_t responselen); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 298 | static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen); |
| 299 | static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 300 | static int responseCdmaSms(Parcel &p, void *response, size_t responselen); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 301 | static int responseCellList(Parcel &p, void *response, size_t responselen); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 302 | static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen); |
| 303 | static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen); |
| 304 | static int responseCallRing(Parcel &p, void *response, size_t responselen); |
| 305 | static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen); |
| 306 | static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen); |
Alex Yakavenka | 45e740e | 2012-01-31 11:48:27 -0800 | [diff] [blame] | 307 | static int responseSimRefresh(Parcel &p, void *response, size_t responselen); |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 308 | static int responseCellInfoList(Parcel &p, void *response, size_t responselen); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 309 | static int responseHardwareConfig(Parcel &p, void *response, size_t responselen); |
Wink Saville | c29360a | 2014-07-13 05:17:28 -0700 | [diff] [blame] | 310 | static int responseDcRtInfo(Parcel &p, void *response, size_t responselen); |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 311 | static int responseRadioCapability(Parcel &p, void *response, size_t responselen); |
Amit Mahajan | 54563d3 | 2014-11-22 00:54:49 +0000 | [diff] [blame] | 312 | static int responseSSData(Parcel &p, void *response, size_t responselen); |
fenglu | f740829 | 2015-04-14 14:53:55 -0700 | [diff] [blame] | 313 | static int responseLceStatus(Parcel &p, void *response, size_t responselen); |
| 314 | static int responseLceData(Parcel &p, void *response, size_t responselen); |
Prerepa Viswanadham | 7315749 | 2015-05-28 00:37:32 -0700 | [diff] [blame] | 315 | static int responseActivityData(Parcel &p, void *response, size_t responselen); |
Amit Mahajan | 54563d3 | 2014-11-22 00:54:49 +0000 | [diff] [blame] | 316 | |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 317 | static int decodeVoiceRadioTechnology (RIL_RadioState radioState); |
| 318 | static int decodeCdmaSubscriptionSource (RIL_RadioState radioState); |
| 319 | static RIL_RadioState processRadioState(RIL_RadioState newRadioState); |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 320 | static void grabPartialWakeLock(); |
| 321 | static void releaseWakeLock(); |
| 322 | static void wakeTimeoutCallback(void *); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 323 | |
Amit Mahajan | 54563d3 | 2014-11-22 00:54:49 +0000 | [diff] [blame] | 324 | static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType); |
| 325 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 326 | static bool isDebuggable(); |
| 327 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 328 | #ifdef RIL_SHLIB |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 329 | #if defined(ANDROID_MULTI_SIM) |
Vinit Deshpande | 1b1ec2d | 2015-04-15 13:31:05 -0700 | [diff] [blame] | 330 | extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 331 | size_t datalen, RIL_SOCKET_ID socket_id); |
| 332 | #else |
Vinit Deshpande | 1b1ec2d | 2015-04-15 13:31:05 -0700 | [diff] [blame] | 333 | extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 334 | size_t datalen); |
| 335 | #endif |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 336 | #endif |
| 337 | |
| 338 | #if defined(ANDROID_MULTI_SIM) |
| 339 | #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d)) |
| 340 | #define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e)) |
| 341 | #define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a) |
| 342 | #else |
| 343 | #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c)) |
| 344 | #define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d)) |
| 345 | #define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest() |
| 346 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 347 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 348 | static UserCallbackInfo * internalRequestTimedCallback |
Dianne Hackborn | 0d9f0c0 | 2010-06-25 16:50:46 -0700 | [diff] [blame] | 349 | (RIL_TimedCallback callback, void *param, |
| 350 | const struct timeval *relativeTime); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 351 | |
| 352 | /** Index == requestNumber */ |
| 353 | static CommandInfo s_commands[] = { |
| 354 | #include "ril_commands.h" |
| 355 | }; |
| 356 | |
| 357 | static UnsolResponseInfo s_unsolResponses[] = { |
| 358 | #include "ril_unsol_commands.h" |
| 359 | }; |
| 360 | |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 361 | /* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and |
| 362 | RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from |
| 363 | radio state message and store it. Every time there is a change in Radio State |
| 364 | check to see if voice radio tech changes and notify telephony |
| 365 | */ |
| 366 | int voiceRadioTech = -1; |
| 367 | |
| 368 | /* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE |
| 369 | and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription |
| 370 | source from radio state and store it. Every time there is a change in Radio State |
| 371 | check to see if subscription source changed and notify telephony |
| 372 | */ |
| 373 | int cdmaSubscriptionSource = -1; |
| 374 | |
| 375 | /* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the |
| 376 | SIM/RUIM state from radio state and store it. Every time there is a change in Radio State, |
| 377 | check to see if SIM/RUIM status changed and notify telephony |
| 378 | */ |
| 379 | int simRuimStatus = -1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 380 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 381 | static char * RIL_getRilSocketName() { |
| 382 | return rild; |
| 383 | } |
| 384 | |
| 385 | extern "C" |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 386 | void RIL_setRilSocketName(const char * s) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 387 | strncpy(rild, s, MAX_SOCKET_NAME_LENGTH); |
| 388 | } |
| 389 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 390 | static char * |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 391 | strdupReadString(Parcel &p) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 392 | size_t stringlen; |
| 393 | const char16_t *s16; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 394 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 395 | s16 = p.readString16Inplace(&stringlen); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 396 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 397 | return strndup16to8(s16, stringlen); |
| 398 | } |
| 399 | |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 400 | static status_t |
| 401 | readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) { |
| 402 | size_t s16Len; |
| 403 | const char16_t *s16; |
| 404 | |
| 405 | s16 = p.readString16Inplace(&s16Len); |
| 406 | if (s16 == NULL) { |
| 407 | return NO_MEMORY; |
| 408 | } |
| 409 | size_t strLen = strnlen16to8(s16, s16Len); |
| 410 | if ((strLen + 1) > maxLen) { |
| 411 | return NO_MEMORY; |
| 412 | } |
| 413 | if (strncpy16to8(str, s16, strLen) == NULL) { |
| 414 | return NO_MEMORY; |
| 415 | } else { |
| 416 | return NO_ERROR; |
| 417 | } |
| 418 | } |
| 419 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 420 | static void writeStringToParcel(Parcel &p, const char *s) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 421 | char16_t *s16; |
| 422 | size_t s16_len; |
| 423 | s16 = strdup8to16(s, &s16_len); |
| 424 | p.writeString16(s16, s16_len); |
| 425 | free(s16); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 430 | memsetString (char *s) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 431 | if (s != NULL) { |
| 432 | memset (s, 0, strlen(s)); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize, |
| 437 | const size_t* objects, size_t objectsSize, |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 438 | void* cookie) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 439 | // do nothing -- the data reference lives longer than the Parcel object |
| 440 | } |
| 441 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 442 | /** |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 443 | * To be called from dispatch thread |
| 444 | * Issue a single local request, ensuring that the response |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 445 | * is not sent back up to the command process |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 446 | */ |
| 447 | static void |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 448 | issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 449 | RequestInfo *pRI; |
| 450 | int ret; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 451 | /* Hook for current context */ |
| 452 | /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */ |
| 453 | pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex; |
| 454 | /* pendingRequestsHook refer to &s_pendingRequests */ |
| 455 | RequestInfo** pendingRequestsHook = &s_pendingRequests; |
| 456 | |
| 457 | #if (SIM_COUNT == 2) |
| 458 | if (socket_id == RIL_SOCKET_2) { |
| 459 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2; |
| 460 | pendingRequestsHook = &s_pendingRequests_socket2; |
| 461 | } |
| 462 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 463 | |
| 464 | pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 465 | |
| 466 | pRI->local = 1; |
| 467 | pRI->token = 0xffffffff; // token is not used in this context |
| 468 | pRI->pCI = &(s_commands[request]); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 469 | pRI->socket_id = socket_id; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 470 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 471 | ret = pthread_mutex_lock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 472 | assert (ret == 0); |
| 473 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 474 | pRI->p_next = *pendingRequestsHook; |
| 475 | *pendingRequestsHook = pRI; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 476 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 477 | ret = pthread_mutex_unlock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 478 | assert (ret == 0); |
| 479 | |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 480 | RLOGD("C[locl]> %s", requestToString(request)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 481 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 482 | CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | |
| 486 | |
| 487 | static int |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 488 | processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 489 | Parcel p; |
| 490 | status_t status; |
| 491 | int32_t request; |
| 492 | int32_t token; |
| 493 | RequestInfo *pRI; |
| 494 | int ret; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 495 | /* Hook for current context */ |
| 496 | /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */ |
| 497 | pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex; |
| 498 | /* pendingRequestsHook refer to &s_pendingRequests */ |
| 499 | RequestInfo** pendingRequestsHook = &s_pendingRequests; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 500 | |
| 501 | p.setData((uint8_t *) buffer, buflen); |
| 502 | |
| 503 | // status checked at end |
| 504 | status = p.readInt32(&request); |
| 505 | status = p.readInt32 (&token); |
| 506 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 507 | #if (SIM_COUNT >= 2) |
| 508 | if (socket_id == RIL_SOCKET_2) { |
| 509 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2; |
| 510 | pendingRequestsHook = &s_pendingRequests_socket2; |
| 511 | } |
| 512 | #if (SIM_COUNT >= 3) |
| 513 | else if (socket_id == RIL_SOCKET_3) { |
| 514 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3; |
| 515 | pendingRequestsHook = &s_pendingRequests_socket3; |
| 516 | } |
| 517 | #endif |
| 518 | #if (SIM_COUNT >= 4) |
| 519 | else if (socket_id == RIL_SOCKET_4) { |
| 520 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4; |
| 521 | pendingRequestsHook = &s_pendingRequests_socket4; |
| 522 | } |
| 523 | #endif |
| 524 | #endif |
| 525 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 526 | if (status != NO_ERROR) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 527 | RLOGE("invalid request block"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 532 | Parcel pErr; |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 533 | RLOGE("unsupported request code %d token %d", request, token); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 534 | // FIXME this should perhaps return a response |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 535 | pErr.writeInt32 (RESPONSE_SOLICITED); |
| 536 | pErr.writeInt32 (token); |
| 537 | pErr.writeInt32 (RIL_E_GENERIC_FAILURE); |
| 538 | |
| 539 | sendResponse(pErr, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 543 | // Received an Ack for the previous result sent to RIL.java, |
| 544 | // so release wakelock and exit |
| 545 | if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) { |
| 546 | releaseWakeLock(); |
| 547 | return 0; |
| 548 | } |
| 549 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 550 | |
| 551 | pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 552 | |
| 553 | pRI->token = token; |
| 554 | pRI->pCI = &(s_commands[request]); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 555 | pRI->socket_id = socket_id; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 556 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 557 | ret = pthread_mutex_lock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 558 | assert (ret == 0); |
| 559 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 560 | pRI->p_next = *pendingRequestsHook; |
| 561 | *pendingRequestsHook = pRI; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 562 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 563 | ret = pthread_mutex_unlock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 564 | assert (ret == 0); |
| 565 | |
| 566 | /* sLastDispatchedToken = token; */ |
| 567 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 568 | pRI->pCI->dispatchFunction(p, pRI); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 574 | invalidCommandBlock (RequestInfo *pRI) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 575 | RLOGE("invalid command block for token %d request %s", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 576 | pRI->token, requestToString(pRI->pCI->requestNumber)); |
| 577 | } |
| 578 | |
| 579 | /** Callee expects NULL */ |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 580 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 581 | dispatchVoid (Parcel& p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 582 | clearPrintBuf; |
| 583 | printRequest(pRI->token, pRI->pCI->requestNumber); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 584 | CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /** Callee expects const char * */ |
| 588 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 589 | dispatchString (Parcel& p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 590 | status_t status; |
| 591 | size_t datalen; |
| 592 | size_t stringlen; |
| 593 | char *string8 = NULL; |
| 594 | |
| 595 | string8 = strdupReadString(p); |
| 596 | |
| 597 | startRequest; |
| 598 | appendPrintBuf("%s%s", printBuf, string8); |
| 599 | closeRequest; |
| 600 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 601 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 602 | CALL_ONREQUEST(pRI->pCI->requestNumber, string8, |
| 603 | sizeof(char *), pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 604 | |
| 605 | #ifdef MEMSET_FREED |
| 606 | memsetString(string8); |
| 607 | #endif |
| 608 | |
| 609 | free(string8); |
| 610 | return; |
| 611 | invalid: |
| 612 | invalidCommandBlock(pRI); |
| 613 | return; |
| 614 | } |
| 615 | |
| 616 | /** Callee expects const char ** */ |
| 617 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 618 | dispatchStrings (Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 619 | int32_t countStrings; |
| 620 | status_t status; |
| 621 | size_t datalen; |
| 622 | char **pStrings; |
| 623 | |
| 624 | status = p.readInt32 (&countStrings); |
| 625 | |
| 626 | if (status != NO_ERROR) { |
| 627 | goto invalid; |
| 628 | } |
| 629 | |
| 630 | startRequest; |
| 631 | if (countStrings == 0) { |
| 632 | // just some non-null pointer |
| 633 | pStrings = (char **)alloca(sizeof(char *)); |
| 634 | datalen = 0; |
| 635 | } else if (((int)countStrings) == -1) { |
| 636 | pStrings = NULL; |
| 637 | datalen = 0; |
| 638 | } else { |
| 639 | datalen = sizeof(char *) * countStrings; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 640 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 641 | pStrings = (char **)alloca(datalen); |
| 642 | |
| 643 | for (int i = 0 ; i < countStrings ; i++) { |
| 644 | pStrings[i] = strdupReadString(p); |
| 645 | appendPrintBuf("%s%s,", printBuf, pStrings[i]); |
| 646 | } |
| 647 | } |
| 648 | removeLastChar; |
| 649 | closeRequest; |
| 650 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 651 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 652 | CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 653 | |
| 654 | if (pStrings != NULL) { |
| 655 | for (int i = 0 ; i < countStrings ; i++) { |
| 656 | #ifdef MEMSET_FREED |
| 657 | memsetString (pStrings[i]); |
| 658 | #endif |
| 659 | free(pStrings[i]); |
| 660 | } |
| 661 | |
| 662 | #ifdef MEMSET_FREED |
| 663 | memset(pStrings, 0, datalen); |
| 664 | #endif |
| 665 | } |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 666 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 667 | return; |
| 668 | invalid: |
| 669 | invalidCommandBlock(pRI); |
| 670 | return; |
| 671 | } |
| 672 | |
| 673 | /** Callee expects const int * */ |
| 674 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 675 | dispatchInts (Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 676 | int32_t count; |
| 677 | status_t status; |
| 678 | size_t datalen; |
| 679 | int *pInts; |
| 680 | |
| 681 | status = p.readInt32 (&count); |
| 682 | |
| 683 | if (status != NO_ERROR || count == 0) { |
| 684 | goto invalid; |
| 685 | } |
| 686 | |
| 687 | datalen = sizeof(int) * count; |
| 688 | pInts = (int *)alloca(datalen); |
| 689 | |
| 690 | startRequest; |
| 691 | for (int i = 0 ; i < count ; i++) { |
| 692 | int32_t t; |
| 693 | |
| 694 | status = p.readInt32(&t); |
| 695 | pInts[i] = (int)t; |
| 696 | appendPrintBuf("%s%d,", printBuf, t); |
| 697 | |
| 698 | if (status != NO_ERROR) { |
| 699 | goto invalid; |
| 700 | } |
| 701 | } |
| 702 | removeLastChar; |
| 703 | closeRequest; |
| 704 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 705 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 706 | CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts), |
| 707 | datalen, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 708 | |
| 709 | #ifdef MEMSET_FREED |
| 710 | memset(pInts, 0, datalen); |
| 711 | #endif |
| 712 | |
| 713 | return; |
| 714 | invalid: |
| 715 | invalidCommandBlock(pRI); |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 720 | /** |
| 721 | * Callee expects const RIL_SMS_WriteArgs * |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 722 | * Payload is: |
| 723 | * int32_t status |
| 724 | * String pdu |
| 725 | */ |
| 726 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 727 | dispatchSmsWrite (Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 728 | RIL_SMS_WriteArgs args; |
| 729 | int32_t t; |
| 730 | status_t status; |
| 731 | |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 732 | RLOGD("dispatchSmsWrite"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 733 | memset (&args, 0, sizeof(args)); |
| 734 | |
| 735 | status = p.readInt32(&t); |
| 736 | args.status = (int)t; |
| 737 | |
| 738 | args.pdu = strdupReadString(p); |
| 739 | |
| 740 | if (status != NO_ERROR || args.pdu == NULL) { |
| 741 | goto invalid; |
| 742 | } |
| 743 | |
| 744 | args.smsc = strdupReadString(p); |
| 745 | |
| 746 | startRequest; |
| 747 | appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status, |
| 748 | (char*)args.pdu, (char*)args.smsc); |
| 749 | closeRequest; |
| 750 | printRequest(pRI->token, pRI->pCI->requestNumber); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 751 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 752 | CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 753 | |
| 754 | #ifdef MEMSET_FREED |
| 755 | memsetString (args.pdu); |
| 756 | #endif |
| 757 | |
| 758 | free (args.pdu); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 759 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 760 | #ifdef MEMSET_FREED |
| 761 | memset(&args, 0, sizeof(args)); |
| 762 | #endif |
| 763 | |
| 764 | return; |
| 765 | invalid: |
| 766 | invalidCommandBlock(pRI); |
| 767 | return; |
| 768 | } |
| 769 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 770 | /** |
| 771 | * Callee expects const RIL_Dial * |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 772 | * Payload is: |
| 773 | * String address |
| 774 | * int32_t clir |
| 775 | */ |
| 776 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 777 | dispatchDial (Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 778 | RIL_Dial dial; |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 779 | RIL_UUS_Info uusInfo; |
Wink Saville | 7bce082 | 2010-01-08 15:20:12 -0800 | [diff] [blame] | 780 | int32_t sizeOfDial; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 781 | int32_t t; |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 782 | int32_t uusPresent; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 783 | status_t status; |
| 784 | |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 785 | RLOGD("dispatchDial"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 786 | memset (&dial, 0, sizeof(dial)); |
| 787 | |
| 788 | dial.address = strdupReadString(p); |
| 789 | |
| 790 | status = p.readInt32(&t); |
| 791 | dial.clir = (int)t; |
| 792 | |
| 793 | if (status != NO_ERROR || dial.address == NULL) { |
| 794 | goto invalid; |
| 795 | } |
| 796 | |
Wink Saville | 3a4840b | 2010-04-07 13:29:58 -0700 | [diff] [blame] | 797 | if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3 |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 798 | uusPresent = 0; |
Wink Saville | 7bce082 | 2010-01-08 15:20:12 -0800 | [diff] [blame] | 799 | sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *); |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 800 | } else { |
| 801 | status = p.readInt32(&uusPresent); |
| 802 | |
| 803 | if (status != NO_ERROR) { |
| 804 | goto invalid; |
| 805 | } |
| 806 | |
| 807 | if (uusPresent == 0) { |
| 808 | dial.uusInfo = NULL; |
| 809 | } else { |
| 810 | int32_t len; |
| 811 | |
| 812 | memset(&uusInfo, 0, sizeof(RIL_UUS_Info)); |
| 813 | |
| 814 | status = p.readInt32(&t); |
| 815 | uusInfo.uusType = (RIL_UUS_Type) t; |
| 816 | |
| 817 | status = p.readInt32(&t); |
| 818 | uusInfo.uusDcs = (RIL_UUS_DCS) t; |
| 819 | |
| 820 | status = p.readInt32(&len); |
| 821 | if (status != NO_ERROR) { |
| 822 | goto invalid; |
| 823 | } |
| 824 | |
| 825 | // The java code writes -1 for null arrays |
| 826 | if (((int) len) == -1) { |
| 827 | uusInfo.uusData = NULL; |
| 828 | len = 0; |
| 829 | } else { |
| 830 | uusInfo.uusData = (char*) p.readInplace(len); |
| 831 | } |
| 832 | |
| 833 | uusInfo.uusLength = len; |
| 834 | dial.uusInfo = &uusInfo; |
| 835 | } |
Wink Saville | 7bce082 | 2010-01-08 15:20:12 -0800 | [diff] [blame] | 836 | sizeOfDial = sizeof(dial); |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 837 | } |
| 838 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 839 | startRequest; |
| 840 | appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir); |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 841 | if (uusPresent) { |
| 842 | appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf, |
| 843 | dial.uusInfo->uusType, dial.uusInfo->uusDcs, |
| 844 | dial.uusInfo->uusLength); |
| 845 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 846 | closeRequest; |
| 847 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 848 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 849 | CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 850 | |
| 851 | #ifdef MEMSET_FREED |
| 852 | memsetString (dial.address); |
| 853 | #endif |
| 854 | |
| 855 | free (dial.address); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 856 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 857 | #ifdef MEMSET_FREED |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 858 | memset(&uusInfo, 0, sizeof(RIL_UUS_Info)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 859 | memset(&dial, 0, sizeof(dial)); |
| 860 | #endif |
| 861 | |
| 862 | return; |
| 863 | invalid: |
| 864 | invalidCommandBlock(pRI); |
| 865 | return; |
| 866 | } |
| 867 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 868 | /** |
| 869 | * Callee expects const RIL_SIM_IO * |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 870 | * Payload is: |
| 871 | * int32_t command |
| 872 | * int32_t fileid |
| 873 | * String path |
| 874 | * int32_t p1, p2, p3 |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 875 | * String data |
| 876 | * String pin2 |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 877 | * String aidPtr |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 878 | */ |
| 879 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 880 | dispatchSIM_IO (Parcel &p, RequestInfo *pRI) { |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 881 | union RIL_SIM_IO { |
| 882 | RIL_SIM_IO_v6 v6; |
| 883 | RIL_SIM_IO_v5 v5; |
| 884 | } simIO; |
| 885 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 886 | int32_t t; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 887 | int size; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 888 | status_t status; |
| 889 | |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 890 | #if VDBG |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 891 | RLOGD("dispatchSIM_IO"); |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 892 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 893 | memset (&simIO, 0, sizeof(simIO)); |
| 894 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 895 | // note we only check status at the end |
| 896 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 897 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 898 | simIO.v6.command = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 899 | |
| 900 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 901 | simIO.v6.fileid = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 902 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 903 | simIO.v6.path = strdupReadString(p); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 904 | |
| 905 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 906 | simIO.v6.p1 = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 907 | |
| 908 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 909 | simIO.v6.p2 = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 910 | |
| 911 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 912 | simIO.v6.p3 = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 913 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 914 | simIO.v6.data = strdupReadString(p); |
| 915 | simIO.v6.pin2 = strdupReadString(p); |
| 916 | simIO.v6.aidPtr = strdupReadString(p); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 917 | |
| 918 | startRequest; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 919 | appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf, |
| 920 | simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path, |
| 921 | simIO.v6.p1, simIO.v6.p2, simIO.v6.p3, |
| 922 | (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 923 | closeRequest; |
| 924 | printRequest(pRI->token, pRI->pCI->requestNumber); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 925 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 926 | if (status != NO_ERROR) { |
| 927 | goto invalid; |
| 928 | } |
| 929 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 930 | size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 931 | CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 932 | |
| 933 | #ifdef MEMSET_FREED |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 934 | memsetString (simIO.v6.path); |
| 935 | memsetString (simIO.v6.data); |
| 936 | memsetString (simIO.v6.pin2); |
| 937 | memsetString (simIO.v6.aidPtr); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 938 | #endif |
| 939 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 940 | free (simIO.v6.path); |
| 941 | free (simIO.v6.data); |
| 942 | free (simIO.v6.pin2); |
| 943 | free (simIO.v6.aidPtr); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 944 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 945 | #ifdef MEMSET_FREED |
| 946 | memset(&simIO, 0, sizeof(simIO)); |
| 947 | #endif |
| 948 | |
| 949 | return; |
| 950 | invalid: |
| 951 | invalidCommandBlock(pRI); |
| 952 | return; |
| 953 | } |
| 954 | |
| 955 | /** |
Shishir Agrawal | 2458d8d | 2013-11-27 14:53:05 -0800 | [diff] [blame] | 956 | * Callee expects const RIL_SIM_APDU * |
| 957 | * Payload is: |
| 958 | * int32_t sessionid |
| 959 | * int32_t cla |
| 960 | * int32_t instruction |
| 961 | * int32_t p1, p2, p3 |
| 962 | * String data |
| 963 | */ |
| 964 | static void |
| 965 | dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) { |
| 966 | int32_t t; |
| 967 | status_t status; |
| 968 | RIL_SIM_APDU apdu; |
| 969 | |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 970 | #if VDBG |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 971 | RLOGD("dispatchSIM_APDU"); |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 972 | #endif |
Shishir Agrawal | 2458d8d | 2013-11-27 14:53:05 -0800 | [diff] [blame] | 973 | memset (&apdu, 0, sizeof(RIL_SIM_APDU)); |
| 974 | |
| 975 | // Note we only check status at the end. Any single failure leads to |
| 976 | // subsequent reads filing. |
| 977 | status = p.readInt32(&t); |
| 978 | apdu.sessionid = (int)t; |
| 979 | |
| 980 | status = p.readInt32(&t); |
| 981 | apdu.cla = (int)t; |
| 982 | |
| 983 | status = p.readInt32(&t); |
| 984 | apdu.instruction = (int)t; |
| 985 | |
| 986 | status = p.readInt32(&t); |
| 987 | apdu.p1 = (int)t; |
| 988 | |
| 989 | status = p.readInt32(&t); |
| 990 | apdu.p2 = (int)t; |
| 991 | |
| 992 | status = p.readInt32(&t); |
| 993 | apdu.p3 = (int)t; |
| 994 | |
| 995 | apdu.data = strdupReadString(p); |
| 996 | |
| 997 | startRequest; |
| 998 | appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s", |
| 999 | printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2, |
| 1000 | apdu.p3, (char*)apdu.data); |
| 1001 | closeRequest; |
| 1002 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1003 | |
| 1004 | if (status != NO_ERROR) { |
| 1005 | goto invalid; |
| 1006 | } |
| 1007 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1008 | CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id); |
Shishir Agrawal | 2458d8d | 2013-11-27 14:53:05 -0800 | [diff] [blame] | 1009 | |
| 1010 | #ifdef MEMSET_FREED |
| 1011 | memsetString(apdu.data); |
| 1012 | #endif |
| 1013 | free(apdu.data); |
| 1014 | |
| 1015 | #ifdef MEMSET_FREED |
| 1016 | memset(&apdu, 0, sizeof(RIL_SIM_APDU)); |
| 1017 | #endif |
| 1018 | |
| 1019 | return; |
| 1020 | invalid: |
| 1021 | invalidCommandBlock(pRI); |
| 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | |
| 1026 | /** |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1027 | * Callee expects const RIL_CallForwardInfo * |
| 1028 | * Payload is: |
| 1029 | * int32_t status/action |
| 1030 | * int32_t reason |
| 1031 | * int32_t serviceCode |
| 1032 | * int32_t toa |
| 1033 | * String number (0 length -> null) |
| 1034 | * int32_t timeSeconds |
| 1035 | */ |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1036 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1037 | dispatchCallForward(Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1038 | RIL_CallForwardInfo cff; |
| 1039 | int32_t t; |
| 1040 | status_t status; |
| 1041 | |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 1042 | RLOGD("dispatchCallForward"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1043 | memset (&cff, 0, sizeof(cff)); |
| 1044 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1045 | // note we only check status at the end |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1046 | |
| 1047 | status = p.readInt32(&t); |
| 1048 | cff.status = (int)t; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1049 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1050 | status = p.readInt32(&t); |
| 1051 | cff.reason = (int)t; |
| 1052 | |
| 1053 | status = p.readInt32(&t); |
| 1054 | cff.serviceClass = (int)t; |
| 1055 | |
| 1056 | status = p.readInt32(&t); |
| 1057 | cff.toa = (int)t; |
| 1058 | |
| 1059 | cff.number = strdupReadString(p); |
| 1060 | |
| 1061 | status = p.readInt32(&t); |
| 1062 | cff.timeSeconds = (int)t; |
| 1063 | |
| 1064 | if (status != NO_ERROR) { |
| 1065 | goto invalid; |
| 1066 | } |
| 1067 | |
| 1068 | // special case: number 0-length fields is null |
| 1069 | |
| 1070 | if (cff.number != NULL && strlen (cff.number) == 0) { |
| 1071 | cff.number = NULL; |
| 1072 | } |
| 1073 | |
| 1074 | startRequest; |
| 1075 | appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf, |
| 1076 | cff.status, cff.reason, cff.serviceClass, cff.toa, |
| 1077 | (char*)cff.number, cff.timeSeconds); |
| 1078 | closeRequest; |
| 1079 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1080 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1081 | CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1082 | |
| 1083 | #ifdef MEMSET_FREED |
| 1084 | memsetString(cff.number); |
| 1085 | #endif |
| 1086 | |
| 1087 | free (cff.number); |
| 1088 | |
| 1089 | #ifdef MEMSET_FREED |
| 1090 | memset(&cff, 0, sizeof(cff)); |
| 1091 | #endif |
| 1092 | |
| 1093 | return; |
| 1094 | invalid: |
| 1095 | invalidCommandBlock(pRI); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1100 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1101 | dispatchRaw(Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1102 | int32_t len; |
| 1103 | status_t status; |
| 1104 | const void *data; |
| 1105 | |
| 1106 | status = p.readInt32(&len); |
| 1107 | |
| 1108 | if (status != NO_ERROR) { |
| 1109 | goto invalid; |
| 1110 | } |
| 1111 | |
| 1112 | // The java code writes -1 for null arrays |
| 1113 | if (((int)len) == -1) { |
| 1114 | data = NULL; |
| 1115 | len = 0; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1116 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1117 | |
| 1118 | data = p.readInplace(len); |
| 1119 | |
| 1120 | startRequest; |
| 1121 | appendPrintBuf("%sraw_size=%d", printBuf, len); |
| 1122 | closeRequest; |
| 1123 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1124 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1125 | CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1126 | |
| 1127 | return; |
| 1128 | invalid: |
| 1129 | invalidCommandBlock(pRI); |
| 1130 | return; |
| 1131 | } |
| 1132 | |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1133 | static status_t |
| 1134 | constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) { |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1135 | int32_t t; |
| 1136 | uint8_t ut; |
| 1137 | status_t status; |
| 1138 | int32_t digitCount; |
| 1139 | int digitLimit; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1140 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1141 | memset(&rcsm, 0, sizeof(rcsm)); |
| 1142 | |
| 1143 | status = p.readInt32(&t); |
| 1144 | rcsm.uTeleserviceID = (int) t; |
| 1145 | |
| 1146 | status = p.read(&ut,sizeof(ut)); |
| 1147 | rcsm.bIsServicePresent = (uint8_t) ut; |
| 1148 | |
| 1149 | status = p.readInt32(&t); |
| 1150 | rcsm.uServicecategory = (int) t; |
| 1151 | |
| 1152 | status = p.readInt32(&t); |
| 1153 | rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t; |
| 1154 | |
| 1155 | status = p.readInt32(&t); |
| 1156 | rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t; |
| 1157 | |
| 1158 | status = p.readInt32(&t); |
| 1159 | rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t; |
| 1160 | |
| 1161 | status = p.readInt32(&t); |
| 1162 | rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t; |
| 1163 | |
| 1164 | status = p.read(&ut,sizeof(ut)); |
| 1165 | rcsm.sAddress.number_of_digits= (uint8_t) ut; |
| 1166 | |
| 1167 | digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX); |
| 1168 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 1169 | status = p.read(&ut,sizeof(ut)); |
| 1170 | rcsm.sAddress.digits[digitCount] = (uint8_t) ut; |
| 1171 | } |
| 1172 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1173 | status = p.readInt32(&t); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1174 | rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t; |
| 1175 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1176 | status = p.read(&ut,sizeof(ut)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1177 | rcsm.sSubAddress.odd = (uint8_t) ut; |
| 1178 | |
| 1179 | status = p.read(&ut,sizeof(ut)); |
| 1180 | rcsm.sSubAddress.number_of_digits = (uint8_t) ut; |
| 1181 | |
| 1182 | digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1183 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 1184 | status = p.read(&ut,sizeof(ut)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1185 | rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut; |
| 1186 | } |
| 1187 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1188 | status = p.readInt32(&t); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1189 | rcsm.uBearerDataLen = (int) t; |
| 1190 | |
| 1191 | digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1192 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 1193 | status = p.read(&ut, sizeof(ut)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1194 | rcsm.aBearerData[digitCount] = (uint8_t) ut; |
| 1195 | } |
| 1196 | |
| 1197 | if (status != NO_ERROR) { |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1198 | return status; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | startRequest; |
| 1202 | appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \ |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1203 | sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ", |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1204 | printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory, |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1205 | rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1206 | closeRequest; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1207 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1208 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1209 | |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1210 | return status; |
| 1211 | } |
| 1212 | |
| 1213 | static void |
| 1214 | dispatchCdmaSms(Parcel &p, RequestInfo *pRI) { |
| 1215 | RIL_CDMA_SMS_Message rcsm; |
| 1216 | |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 1217 | RLOGD("dispatchCdmaSms"); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1218 | if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) { |
| 1219 | goto invalid; |
| 1220 | } |
| 1221 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1222 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1223 | |
| 1224 | #ifdef MEMSET_FREED |
| 1225 | memset(&rcsm, 0, sizeof(rcsm)); |
| 1226 | #endif |
| 1227 | |
| 1228 | return; |
| 1229 | |
| 1230 | invalid: |
| 1231 | invalidCommandBlock(pRI); |
| 1232 | return; |
| 1233 | } |
| 1234 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1235 | static void |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1236 | dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) { |
| 1237 | RIL_IMS_SMS_Message rism; |
| 1238 | RIL_CDMA_SMS_Message rcsm; |
| 1239 | |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 1240 | RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1241 | |
| 1242 | if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) { |
| 1243 | goto invalid; |
| 1244 | } |
| 1245 | memset(&rism, 0, sizeof(rism)); |
| 1246 | rism.tech = RADIO_TECH_3GPP2; |
| 1247 | rism.retry = retry; |
| 1248 | rism.messageRef = messageRef; |
| 1249 | rism.message.cdmaMessage = &rcsm; |
| 1250 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1251 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rism, |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1252 | sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t) |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1253 | +sizeof(rcsm),pRI, pRI->socket_id); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1254 | |
| 1255 | #ifdef MEMSET_FREED |
| 1256 | memset(&rcsm, 0, sizeof(rcsm)); |
| 1257 | memset(&rism, 0, sizeof(rism)); |
| 1258 | #endif |
| 1259 | |
| 1260 | return; |
| 1261 | |
| 1262 | invalid: |
| 1263 | invalidCommandBlock(pRI); |
| 1264 | return; |
| 1265 | } |
| 1266 | |
| 1267 | static void |
| 1268 | dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) { |
| 1269 | RIL_IMS_SMS_Message rism; |
| 1270 | int32_t countStrings; |
| 1271 | status_t status; |
| 1272 | size_t datalen; |
| 1273 | char **pStrings; |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 1274 | RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1275 | |
| 1276 | status = p.readInt32 (&countStrings); |
| 1277 | |
| 1278 | if (status != NO_ERROR) { |
| 1279 | goto invalid; |
| 1280 | } |
| 1281 | |
| 1282 | memset(&rism, 0, sizeof(rism)); |
| 1283 | rism.tech = RADIO_TECH_3GPP; |
| 1284 | rism.retry = retry; |
| 1285 | rism.messageRef = messageRef; |
| 1286 | |
| 1287 | startRequest; |
Etan Cohen | 5d891b7 | 2014-02-27 17:25:17 -0800 | [diff] [blame] | 1288 | appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf, |
| 1289 | (int)rism.tech, (int)rism.retry, rism.messageRef); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1290 | if (countStrings == 0) { |
| 1291 | // just some non-null pointer |
| 1292 | pStrings = (char **)alloca(sizeof(char *)); |
| 1293 | datalen = 0; |
| 1294 | } else if (((int)countStrings) == -1) { |
| 1295 | pStrings = NULL; |
| 1296 | datalen = 0; |
| 1297 | } else { |
| 1298 | datalen = sizeof(char *) * countStrings; |
| 1299 | |
| 1300 | pStrings = (char **)alloca(datalen); |
| 1301 | |
| 1302 | for (int i = 0 ; i < countStrings ; i++) { |
| 1303 | pStrings[i] = strdupReadString(p); |
| 1304 | appendPrintBuf("%s%s,", printBuf, pStrings[i]); |
| 1305 | } |
| 1306 | } |
| 1307 | removeLastChar; |
| 1308 | closeRequest; |
| 1309 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1310 | |
| 1311 | rism.message.gsmMessage = pStrings; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1312 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rism, |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1313 | sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t) |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1314 | +datalen, pRI, pRI->socket_id); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1315 | |
| 1316 | if (pStrings != NULL) { |
| 1317 | for (int i = 0 ; i < countStrings ; i++) { |
| 1318 | #ifdef MEMSET_FREED |
| 1319 | memsetString (pStrings[i]); |
| 1320 | #endif |
| 1321 | free(pStrings[i]); |
| 1322 | } |
| 1323 | |
| 1324 | #ifdef MEMSET_FREED |
| 1325 | memset(pStrings, 0, datalen); |
| 1326 | #endif |
| 1327 | } |
| 1328 | |
| 1329 | #ifdef MEMSET_FREED |
| 1330 | memset(&rism, 0, sizeof(rism)); |
| 1331 | #endif |
| 1332 | return; |
| 1333 | invalid: |
| 1334 | ALOGE("dispatchImsGsmSms invalid block"); |
| 1335 | invalidCommandBlock(pRI); |
| 1336 | return; |
| 1337 | } |
| 1338 | |
| 1339 | static void |
| 1340 | dispatchImsSms(Parcel &p, RequestInfo *pRI) { |
| 1341 | int32_t t; |
| 1342 | status_t status = p.readInt32(&t); |
| 1343 | RIL_RadioTechnologyFamily format; |
| 1344 | uint8_t retry; |
| 1345 | int32_t messageRef; |
| 1346 | |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 1347 | RLOGD("dispatchImsSms"); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1348 | if (status != NO_ERROR) { |
| 1349 | goto invalid; |
| 1350 | } |
| 1351 | format = (RIL_RadioTechnologyFamily) t; |
| 1352 | |
| 1353 | // read retry field |
| 1354 | status = p.read(&retry,sizeof(retry)); |
| 1355 | if (status != NO_ERROR) { |
| 1356 | goto invalid; |
| 1357 | } |
| 1358 | // read messageRef field |
| 1359 | status = p.read(&messageRef,sizeof(messageRef)); |
| 1360 | if (status != NO_ERROR) { |
| 1361 | goto invalid; |
| 1362 | } |
| 1363 | |
| 1364 | if (RADIO_TECH_3GPP == format) { |
| 1365 | dispatchImsGsmSms(p, pRI, retry, messageRef); |
| 1366 | } else if (RADIO_TECH_3GPP2 == format) { |
| 1367 | dispatchImsCdmaSms(p, pRI, retry, messageRef); |
| 1368 | } else { |
| 1369 | ALOGE("requestImsSendSMS invalid format value =%d", format); |
| 1370 | } |
| 1371 | |
| 1372 | return; |
| 1373 | |
| 1374 | invalid: |
| 1375 | invalidCommandBlock(pRI); |
| 1376 | return; |
| 1377 | } |
| 1378 | |
| 1379 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1380 | dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) { |
| 1381 | RIL_CDMA_SMS_Ack rcsa; |
| 1382 | int32_t t; |
| 1383 | status_t status; |
| 1384 | int32_t digitCount; |
| 1385 | |
Mark Salyzyn | dba2561 | 2015-04-09 07:18:35 -0700 | [diff] [blame] | 1386 | RLOGD("dispatchCdmaSmsAck"); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1387 | memset(&rcsa, 0, sizeof(rcsa)); |
| 1388 | |
| 1389 | status = p.readInt32(&t); |
| 1390 | rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t; |
| 1391 | |
| 1392 | status = p.readInt32(&t); |
| 1393 | rcsa.uSMSCauseCode = (int) t; |
| 1394 | |
| 1395 | if (status != NO_ERROR) { |
| 1396 | goto invalid; |
| 1397 | } |
| 1398 | |
| 1399 | startRequest; |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1400 | appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ", |
| 1401 | printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1402 | closeRequest; |
| 1403 | |
| 1404 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1405 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1406 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1407 | |
| 1408 | #ifdef MEMSET_FREED |
| 1409 | memset(&rcsa, 0, sizeof(rcsa)); |
| 1410 | #endif |
| 1411 | |
| 1412 | return; |
| 1413 | |
| 1414 | invalid: |
| 1415 | invalidCommandBlock(pRI); |
| 1416 | return; |
| 1417 | } |
| 1418 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1419 | static void |
| 1420 | dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) { |
| 1421 | int32_t t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1422 | status_t status; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1423 | int32_t num; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1424 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1425 | status = p.readInt32(&num); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1426 | if (status != NO_ERROR) { |
| 1427 | goto invalid; |
| 1428 | } |
| 1429 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1430 | { |
| 1431 | RIL_GSM_BroadcastSmsConfigInfo gsmBci[num]; |
| 1432 | RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num]; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1433 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1434 | startRequest; |
| 1435 | for (int i = 0 ; i < num ; i++ ) { |
| 1436 | gsmBciPtrs[i] = &gsmBci[i]; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1437 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1438 | status = p.readInt32(&t); |
| 1439 | gsmBci[i].fromServiceId = (int) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1440 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1441 | status = p.readInt32(&t); |
| 1442 | gsmBci[i].toServiceId = (int) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1443 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1444 | status = p.readInt32(&t); |
| 1445 | gsmBci[i].fromCodeScheme = (int) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1446 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1447 | status = p.readInt32(&t); |
| 1448 | gsmBci[i].toCodeScheme = (int) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1449 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1450 | status = p.readInt32(&t); |
| 1451 | gsmBci[i].selected = (uint8_t) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1452 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1453 | appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \ |
| 1454 | fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i, |
| 1455 | gsmBci[i].fromServiceId, gsmBci[i].toServiceId, |
| 1456 | gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme, |
| 1457 | gsmBci[i].selected); |
| 1458 | } |
| 1459 | closeRequest; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1460 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1461 | if (status != NO_ERROR) { |
| 1462 | goto invalid; |
| 1463 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1464 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1465 | CALL_ONREQUEST(pRI->pCI->requestNumber, |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1466 | gsmBciPtrs, |
| 1467 | num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *), |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1468 | pRI, pRI->socket_id); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1469 | |
| 1470 | #ifdef MEMSET_FREED |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1471 | memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo)); |
| 1472 | memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1473 | #endif |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1474 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1475 | |
| 1476 | return; |
| 1477 | |
| 1478 | invalid: |
| 1479 | invalidCommandBlock(pRI); |
| 1480 | return; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1481 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1482 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1483 | static void |
| 1484 | dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) { |
| 1485 | int32_t t; |
| 1486 | status_t status; |
| 1487 | int32_t num; |
| 1488 | |
| 1489 | status = p.readInt32(&num); |
| 1490 | if (status != NO_ERROR) { |
| 1491 | goto invalid; |
| 1492 | } |
| 1493 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1494 | { |
| 1495 | RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num]; |
| 1496 | RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num]; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1497 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1498 | startRequest; |
| 1499 | for (int i = 0 ; i < num ; i++ ) { |
| 1500 | cdmaBciPtrs[i] = &cdmaBci[i]; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1501 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1502 | status = p.readInt32(&t); |
| 1503 | cdmaBci[i].service_category = (int) t; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1504 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1505 | status = p.readInt32(&t); |
| 1506 | cdmaBci[i].language = (int) t; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1507 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1508 | status = p.readInt32(&t); |
| 1509 | cdmaBci[i].selected = (uint8_t) t; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1510 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1511 | appendPrintBuf("%s [%d: service_category=%d, language =%d, \ |
| 1512 | entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category, |
| 1513 | cdmaBci[i].language, cdmaBci[i].selected); |
| 1514 | } |
| 1515 | closeRequest; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1516 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1517 | if (status != NO_ERROR) { |
| 1518 | goto invalid; |
| 1519 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1520 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1521 | CALL_ONREQUEST(pRI->pCI->requestNumber, |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1522 | cdmaBciPtrs, |
| 1523 | num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *), |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1524 | pRI, pRI->socket_id); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1525 | |
| 1526 | #ifdef MEMSET_FREED |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1527 | memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo)); |
| 1528 | memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *)); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1529 | #endif |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1530 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1531 | |
| 1532 | return; |
| 1533 | |
| 1534 | invalid: |
| 1535 | invalidCommandBlock(pRI); |
| 1536 | return; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) { |
| 1540 | RIL_CDMA_SMS_WriteArgs rcsw; |
| 1541 | int32_t t; |
| 1542 | uint32_t ut; |
| 1543 | uint8_t uct; |
| 1544 | status_t status; |
| 1545 | int32_t digitCount; |
| 1546 | |
| 1547 | memset(&rcsw, 0, sizeof(rcsw)); |
| 1548 | |
| 1549 | status = p.readInt32(&t); |
| 1550 | rcsw.status = t; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1551 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1552 | status = p.readInt32(&t); |
| 1553 | rcsw.message.uTeleserviceID = (int) t; |
| 1554 | |
| 1555 | status = p.read(&uct,sizeof(uct)); |
| 1556 | rcsw.message.bIsServicePresent = (uint8_t) uct; |
| 1557 | |
| 1558 | status = p.readInt32(&t); |
| 1559 | rcsw.message.uServicecategory = (int) t; |
| 1560 | |
| 1561 | status = p.readInt32(&t); |
| 1562 | rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t; |
| 1563 | |
| 1564 | status = p.readInt32(&t); |
| 1565 | rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t; |
| 1566 | |
| 1567 | status = p.readInt32(&t); |
| 1568 | rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t; |
| 1569 | |
| 1570 | status = p.readInt32(&t); |
| 1571 | rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t; |
| 1572 | |
| 1573 | status = p.read(&uct,sizeof(uct)); |
| 1574 | rcsw.message.sAddress.number_of_digits = (uint8_t) uct; |
| 1575 | |
| 1576 | for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) { |
| 1577 | status = p.read(&uct,sizeof(uct)); |
| 1578 | rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct; |
| 1579 | } |
| 1580 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1581 | status = p.readInt32(&t); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1582 | rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t; |
| 1583 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1584 | status = p.read(&uct,sizeof(uct)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1585 | rcsw.message.sSubAddress.odd = (uint8_t) uct; |
| 1586 | |
| 1587 | status = p.read(&uct,sizeof(uct)); |
| 1588 | rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct; |
| 1589 | |
| 1590 | for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) { |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1591 | status = p.read(&uct,sizeof(uct)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1592 | rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct; |
| 1593 | } |
| 1594 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1595 | status = p.readInt32(&t); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1596 | rcsw.message.uBearerDataLen = (int) t; |
| 1597 | |
| 1598 | for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) { |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1599 | status = p.read(&uct, sizeof(uct)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1600 | rcsw.message.aBearerData[digitCount] = (uint8_t) uct; |
| 1601 | } |
| 1602 | |
| 1603 | if (status != NO_ERROR) { |
| 1604 | goto invalid; |
| 1605 | } |
| 1606 | |
| 1607 | startRequest; |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1608 | appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \ |
| 1609 | message.uServicecategory=%d, message.sAddress.digit_mode=%d, \ |
| 1610 | message.sAddress.number_mode=%d, \ |
| 1611 | message.sAddress.number_type=%d, ", |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1612 | printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent, |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1613 | rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode, |
| 1614 | rcsw.message.sAddress.number_mode, |
| 1615 | rcsw.message.sAddress.number_type); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1616 | closeRequest; |
| 1617 | |
| 1618 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1619 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1620 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1621 | |
| 1622 | #ifdef MEMSET_FREED |
| 1623 | memset(&rcsw, 0, sizeof(rcsw)); |
| 1624 | #endif |
| 1625 | |
| 1626 | return; |
| 1627 | |
| 1628 | invalid: |
| 1629 | invalidCommandBlock(pRI); |
| 1630 | return; |
| 1631 | |
| 1632 | } |
| 1633 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1634 | // For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL. |
| 1635 | // Version 4 of the RIL interface adds a new PDP type parameter to support |
| 1636 | // IPv6 and dual-stack PDP contexts. When dealing with a previous version of |
| 1637 | // RIL, remove the parameter from the request. |
| 1638 | static void dispatchDataCall(Parcel& p, RequestInfo *pRI) { |
| 1639 | // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters. |
| 1640 | const int numParamsRilV3 = 6; |
| 1641 | |
| 1642 | // The first bytes of the RIL parcel contain the request number and the |
| 1643 | // serial number - see processCommandBuffer(). Copy them over too. |
| 1644 | int pos = p.dataPosition(); |
| 1645 | |
| 1646 | int numParams = p.readInt32(); |
| 1647 | if (s_callbacks.version < 4 && numParams > numParamsRilV3) { |
| 1648 | Parcel p2; |
| 1649 | p2.appendFrom(&p, 0, pos); |
| 1650 | p2.writeInt32(numParamsRilV3); |
| 1651 | for(int i = 0; i < numParamsRilV3; i++) { |
| 1652 | p2.writeString16(p.readString16()); |
| 1653 | } |
| 1654 | p2.setDataPosition(pos); |
| 1655 | dispatchStrings(p2, pRI); |
| 1656 | } else { |
Lorenzo Colitti | 57ce1f2 | 2010-09-13 12:23:50 -0700 | [diff] [blame] | 1657 | p.setDataPosition(pos); |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1658 | dispatchStrings(p, pRI); |
| 1659 | } |
| 1660 | } |
| 1661 | |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 1662 | // For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH. |
| 1663 | // When all RILs handle this request, this function can be removed and |
| 1664 | // the request can be sent directly to the RIL using dispatchVoid. |
| 1665 | static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1666 | RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 1667 | |
| 1668 | if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) { |
| 1669 | RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0); |
| 1670 | } |
| 1671 | |
| 1672 | // RILs that support RADIO_STATE_ON should support this request. |
| 1673 | if (RADIO_STATE_ON == state) { |
| 1674 | dispatchVoid(p, pRI); |
| 1675 | return; |
| 1676 | } |
| 1677 | |
| 1678 | // For Older RILs, that do not support RADIO_STATE_ON, assume that they |
| 1679 | // will not support this new request either and decode Voice Radio Technology |
| 1680 | // from Radio State |
| 1681 | voiceRadioTech = decodeVoiceRadioTechnology(state); |
| 1682 | |
| 1683 | if (voiceRadioTech < 0) |
| 1684 | RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1685 | else |
| 1686 | RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int)); |
| 1687 | } |
| 1688 | |
| 1689 | // For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:. |
| 1690 | // When all RILs handle this request, this function can be removed and |
| 1691 | // the request can be sent directly to the RIL using dispatchVoid. |
| 1692 | static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1693 | RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 1694 | |
| 1695 | if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) { |
| 1696 | RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0); |
| 1697 | } |
| 1698 | |
| 1699 | // RILs that support RADIO_STATE_ON should support this request. |
| 1700 | if (RADIO_STATE_ON == state) { |
| 1701 | dispatchVoid(p, pRI); |
| 1702 | return; |
| 1703 | } |
| 1704 | |
| 1705 | // For Older RILs, that do not support RADIO_STATE_ON, assume that they |
| 1706 | // will not support this new request either and decode CDMA Subscription Source |
| 1707 | // from Radio State |
| 1708 | cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state); |
| 1709 | |
| 1710 | if (cdmaSubscriptionSource < 0) |
| 1711 | RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1712 | else |
| 1713 | RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int)); |
| 1714 | } |
| 1715 | |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 1716 | static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI) |
| 1717 | { |
| 1718 | RIL_InitialAttachApn pf; |
| 1719 | int32_t t; |
| 1720 | status_t status; |
| 1721 | |
| 1722 | memset(&pf, 0, sizeof(pf)); |
| 1723 | |
| 1724 | pf.apn = strdupReadString(p); |
| 1725 | pf.protocol = strdupReadString(p); |
| 1726 | |
| 1727 | status = p.readInt32(&t); |
| 1728 | pf.authtype = (int) t; |
| 1729 | |
| 1730 | pf.username = strdupReadString(p); |
| 1731 | pf.password = strdupReadString(p); |
| 1732 | |
| 1733 | startRequest; |
Etan Cohen | 5d891b7 | 2014-02-27 17:25:17 -0800 | [diff] [blame] | 1734 | appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s", |
| 1735 | printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password); |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 1736 | closeRequest; |
| 1737 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1738 | |
| 1739 | if (status != NO_ERROR) { |
| 1740 | goto invalid; |
| 1741 | } |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1742 | CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id); |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 1743 | |
| 1744 | #ifdef MEMSET_FREED |
| 1745 | memsetString(pf.apn); |
| 1746 | memsetString(pf.protocol); |
| 1747 | memsetString(pf.username); |
| 1748 | memsetString(pf.password); |
| 1749 | #endif |
| 1750 | |
| 1751 | free(pf.apn); |
| 1752 | free(pf.protocol); |
| 1753 | free(pf.username); |
| 1754 | free(pf.password); |
| 1755 | |
| 1756 | #ifdef MEMSET_FREED |
| 1757 | memset(&pf, 0, sizeof(pf)); |
| 1758 | #endif |
| 1759 | |
| 1760 | return; |
| 1761 | invalid: |
| 1762 | invalidCommandBlock(pRI); |
| 1763 | return; |
| 1764 | } |
| 1765 | |
Jake Hamby | 8a4a233 | 2014-01-15 13:12:05 -0800 | [diff] [blame] | 1766 | static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) { |
| 1767 | RIL_NV_ReadItem nvri; |
| 1768 | int32_t t; |
| 1769 | status_t status; |
| 1770 | |
| 1771 | memset(&nvri, 0, sizeof(nvri)); |
| 1772 | |
| 1773 | status = p.readInt32(&t); |
| 1774 | nvri.itemID = (RIL_NV_Item) t; |
| 1775 | |
| 1776 | if (status != NO_ERROR) { |
| 1777 | goto invalid; |
| 1778 | } |
| 1779 | |
| 1780 | startRequest; |
| 1781 | appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID); |
| 1782 | closeRequest; |
| 1783 | |
| 1784 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1785 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1786 | CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id); |
Jake Hamby | 8a4a233 | 2014-01-15 13:12:05 -0800 | [diff] [blame] | 1787 | |
| 1788 | #ifdef MEMSET_FREED |
| 1789 | memset(&nvri, 0, sizeof(nvri)); |
| 1790 | #endif |
| 1791 | |
| 1792 | return; |
| 1793 | |
| 1794 | invalid: |
| 1795 | invalidCommandBlock(pRI); |
| 1796 | return; |
| 1797 | } |
| 1798 | |
| 1799 | static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) { |
| 1800 | RIL_NV_WriteItem nvwi; |
| 1801 | int32_t t; |
| 1802 | status_t status; |
| 1803 | |
| 1804 | memset(&nvwi, 0, sizeof(nvwi)); |
| 1805 | |
| 1806 | status = p.readInt32(&t); |
| 1807 | nvwi.itemID = (RIL_NV_Item) t; |
| 1808 | |
| 1809 | nvwi.value = strdupReadString(p); |
| 1810 | |
| 1811 | if (status != NO_ERROR || nvwi.value == NULL) { |
| 1812 | goto invalid; |
| 1813 | } |
| 1814 | |
| 1815 | startRequest; |
| 1816 | appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID, |
| 1817 | nvwi.value); |
| 1818 | closeRequest; |
| 1819 | |
| 1820 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1821 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1822 | CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id); |
Jake Hamby | 8a4a233 | 2014-01-15 13:12:05 -0800 | [diff] [blame] | 1823 | |
| 1824 | #ifdef MEMSET_FREED |
| 1825 | memsetString(nvwi.value); |
| 1826 | #endif |
| 1827 | |
| 1828 | free(nvwi.value); |
| 1829 | |
| 1830 | #ifdef MEMSET_FREED |
| 1831 | memset(&nvwi, 0, sizeof(nvwi)); |
| 1832 | #endif |
| 1833 | |
| 1834 | return; |
| 1835 | |
| 1836 | invalid: |
| 1837 | invalidCommandBlock(pRI); |
| 1838 | return; |
| 1839 | } |
| 1840 | |
| 1841 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1842 | static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) { |
| 1843 | RIL_SelectUiccSub uicc_sub; |
| 1844 | status_t status; |
| 1845 | int32_t t; |
| 1846 | memset(&uicc_sub, 0, sizeof(uicc_sub)); |
| 1847 | |
| 1848 | status = p.readInt32(&t); |
| 1849 | if (status != NO_ERROR) { |
| 1850 | goto invalid; |
| 1851 | } |
| 1852 | uicc_sub.slot = (int) t; |
| 1853 | |
| 1854 | status = p.readInt32(&t); |
| 1855 | if (status != NO_ERROR) { |
| 1856 | goto invalid; |
| 1857 | } |
| 1858 | uicc_sub.app_index = (int) t; |
| 1859 | |
| 1860 | status = p.readInt32(&t); |
| 1861 | if (status != NO_ERROR) { |
| 1862 | goto invalid; |
| 1863 | } |
| 1864 | uicc_sub.sub_type = (RIL_SubscriptionType) t; |
| 1865 | |
| 1866 | status = p.readInt32(&t); |
| 1867 | if (status != NO_ERROR) { |
| 1868 | goto invalid; |
| 1869 | } |
| 1870 | uicc_sub.act_status = (RIL_UiccSubActStatus) t; |
| 1871 | |
| 1872 | startRequest; |
| 1873 | appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index, |
| 1874 | uicc_sub.act_status); |
| 1875 | RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, |
| 1876 | uicc_sub.app_index, uicc_sub.act_status); |
| 1877 | closeRequest; |
| 1878 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1879 | |
| 1880 | CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id); |
| 1881 | |
| 1882 | #ifdef MEMSET_FREED |
| 1883 | memset(&uicc_sub, 0, sizeof(uicc_sub)); |
| 1884 | #endif |
| 1885 | return; |
| 1886 | |
| 1887 | invalid: |
| 1888 | invalidCommandBlock(pRI); |
| 1889 | return; |
| 1890 | } |
| 1891 | |
Amit Mahajan | 90530a6 | 2014-07-01 15:54:08 -0700 | [diff] [blame] | 1892 | static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI) |
| 1893 | { |
| 1894 | RIL_SimAuthentication pf; |
| 1895 | int32_t t; |
| 1896 | status_t status; |
| 1897 | |
| 1898 | memset(&pf, 0, sizeof(pf)); |
| 1899 | |
| 1900 | status = p.readInt32(&t); |
| 1901 | pf.authContext = (int) t; |
| 1902 | pf.authData = strdupReadString(p); |
| 1903 | pf.aid = strdupReadString(p); |
| 1904 | |
| 1905 | startRequest; |
| 1906 | appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid); |
| 1907 | closeRequest; |
| 1908 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1909 | |
| 1910 | if (status != NO_ERROR) { |
| 1911 | goto invalid; |
| 1912 | } |
| 1913 | CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id); |
| 1914 | |
| 1915 | #ifdef MEMSET_FREED |
| 1916 | memsetString(pf.authData); |
| 1917 | memsetString(pf.aid); |
| 1918 | #endif |
| 1919 | |
| 1920 | free(pf.authData); |
| 1921 | free(pf.aid); |
| 1922 | |
| 1923 | #ifdef MEMSET_FREED |
| 1924 | memset(&pf, 0, sizeof(pf)); |
| 1925 | #endif |
| 1926 | |
| 1927 | return; |
| 1928 | invalid: |
| 1929 | invalidCommandBlock(pRI); |
| 1930 | return; |
| 1931 | } |
| 1932 | |
Amit Mahajan | c796e22 | 2014-08-13 16:54:01 +0000 | [diff] [blame] | 1933 | static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) { |
| 1934 | int32_t t; |
| 1935 | status_t status; |
| 1936 | int32_t num; |
| 1937 | |
| 1938 | status = p.readInt32(&num); |
| 1939 | if (status != NO_ERROR) { |
| 1940 | goto invalid; |
| 1941 | } |
| 1942 | |
| 1943 | { |
| 1944 | RIL_DataProfileInfo dataProfiles[num]; |
| 1945 | RIL_DataProfileInfo *dataProfilePtrs[num]; |
| 1946 | |
| 1947 | startRequest; |
| 1948 | for (int i = 0 ; i < num ; i++ ) { |
| 1949 | dataProfilePtrs[i] = &dataProfiles[i]; |
| 1950 | |
| 1951 | status = p.readInt32(&t); |
| 1952 | dataProfiles[i].profileId = (int) t; |
| 1953 | |
| 1954 | dataProfiles[i].apn = strdupReadString(p); |
| 1955 | dataProfiles[i].protocol = strdupReadString(p); |
| 1956 | status = p.readInt32(&t); |
| 1957 | dataProfiles[i].authType = (int) t; |
| 1958 | |
| 1959 | dataProfiles[i].user = strdupReadString(p); |
| 1960 | dataProfiles[i].password = strdupReadString(p); |
| 1961 | |
| 1962 | status = p.readInt32(&t); |
| 1963 | dataProfiles[i].type = (int) t; |
| 1964 | |
| 1965 | status = p.readInt32(&t); |
| 1966 | dataProfiles[i].maxConnsTime = (int) t; |
| 1967 | status = p.readInt32(&t); |
| 1968 | dataProfiles[i].maxConns = (int) t; |
| 1969 | status = p.readInt32(&t); |
| 1970 | dataProfiles[i].waitTime = (int) t; |
| 1971 | |
| 1972 | status = p.readInt32(&t); |
| 1973 | dataProfiles[i].enabled = (int) t; |
| 1974 | |
| 1975 | appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \ |
| 1976 | user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \ |
| 1977 | waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId, |
| 1978 | dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType, |
| 1979 | dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type, |
| 1980 | dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns, |
| 1981 | dataProfiles[i].waitTime, dataProfiles[i].enabled); |
| 1982 | } |
| 1983 | closeRequest; |
| 1984 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1985 | |
| 1986 | if (status != NO_ERROR) { |
| 1987 | goto invalid; |
| 1988 | } |
| 1989 | CALL_ONREQUEST(pRI->pCI->requestNumber, |
| 1990 | dataProfilePtrs, |
| 1991 | num * sizeof(RIL_DataProfileInfo *), |
| 1992 | pRI, pRI->socket_id); |
| 1993 | |
| 1994 | #ifdef MEMSET_FREED |
| 1995 | memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo)); |
| 1996 | memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *)); |
| 1997 | #endif |
| 1998 | } |
| 1999 | |
| 2000 | return; |
| 2001 | |
| 2002 | invalid: |
| 2003 | invalidCommandBlock(pRI); |
| 2004 | return; |
| 2005 | } |
| 2006 | |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 2007 | static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){ |
| 2008 | RIL_RadioCapability rc; |
| 2009 | int32_t t; |
| 2010 | status_t status; |
| 2011 | |
| 2012 | memset (&rc, 0, sizeof(RIL_RadioCapability)); |
| 2013 | |
| 2014 | status = p.readInt32(&t); |
| 2015 | rc.version = (int)t; |
| 2016 | if (status != NO_ERROR) { |
| 2017 | goto invalid; |
| 2018 | } |
| 2019 | |
| 2020 | status = p.readInt32(&t); |
| 2021 | rc.session= (int)t; |
| 2022 | if (status != NO_ERROR) { |
| 2023 | goto invalid; |
| 2024 | } |
| 2025 | |
| 2026 | status = p.readInt32(&t); |
| 2027 | rc.phase= (int)t; |
| 2028 | if (status != NO_ERROR) { |
| 2029 | goto invalid; |
| 2030 | } |
| 2031 | |
| 2032 | status = p.readInt32(&t); |
| 2033 | rc.rat = (int)t; |
| 2034 | if (status != NO_ERROR) { |
| 2035 | goto invalid; |
| 2036 | } |
| 2037 | |
| 2038 | status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid)); |
| 2039 | if (status != NO_ERROR) { |
| 2040 | goto invalid; |
| 2041 | } |
| 2042 | |
| 2043 | status = p.readInt32(&t); |
| 2044 | rc.status = (int)t; |
| 2045 | |
| 2046 | if (status != NO_ERROR) { |
| 2047 | goto invalid; |
| 2048 | } |
| 2049 | |
| 2050 | startRequest; |
| 2051 | appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \ |
Chih-Wei Huang | 8593f26 | 2015-10-02 15:09:52 +0800 | [diff] [blame] | 2052 | logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session, |
Legler Wu | 8caf06f | 2014-10-29 14:02:14 +0800 | [diff] [blame] | 2053 | rc.phase, rc.rat, rc.logicalModemUuid, rc.session); |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 2054 | |
| 2055 | closeRequest; |
| 2056 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 2057 | |
| 2058 | CALL_ONREQUEST(pRI->pCI->requestNumber, |
| 2059 | &rc, |
| 2060 | sizeof(RIL_RadioCapability), |
| 2061 | pRI, pRI->socket_id); |
| 2062 | return; |
| 2063 | invalid: |
| 2064 | invalidCommandBlock(pRI); |
| 2065 | return; |
| 2066 | } |
| 2067 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2068 | static int |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2069 | blockingWrite(int fd, const void *buffer, size_t len) { |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2070 | size_t writeOffset = 0; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2071 | const uint8_t *toWrite; |
| 2072 | |
| 2073 | toWrite = (const uint8_t *)buffer; |
| 2074 | |
| 2075 | while (writeOffset < len) { |
| 2076 | ssize_t written; |
| 2077 | do { |
| 2078 | written = write (fd, toWrite + writeOffset, |
| 2079 | len - writeOffset); |
Banavathu, Srinivas Naik | 3888490 | 2011-07-05 20:04:25 +0530 | [diff] [blame] | 2080 | } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN))); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2081 | |
| 2082 | if (written >= 0) { |
| 2083 | writeOffset += written; |
| 2084 | } else { // written < 0 |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2085 | RLOGE ("RIL Response: unexpected error on write errno:%d", errno); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2086 | close(fd); |
| 2087 | return -1; |
| 2088 | } |
| 2089 | } |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 2090 | #if VDBG |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 2091 | RLOGE("RIL Response bytes written:%d", writeOffset); |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 2092 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2093 | return 0; |
| 2094 | } |
| 2095 | |
| 2096 | static int |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2097 | sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) { |
| 2098 | int fd = s_ril_param_socket.fdCommand; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2099 | int ret; |
| 2100 | uint32_t header; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2101 | pthread_mutex_t * writeMutexHook = &s_writeMutex; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2102 | |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 2103 | #if VDBG |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2104 | RLOGE("Send Response to %s", rilSocketIdToString(socket_id)); |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 2105 | #endif |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2106 | |
| 2107 | #if (SIM_COUNT >= 2) |
| 2108 | if (socket_id == RIL_SOCKET_2) { |
| 2109 | fd = s_ril_param_socket2.fdCommand; |
| 2110 | writeMutexHook = &s_writeMutex_socket2; |
| 2111 | } |
| 2112 | #if (SIM_COUNT >= 3) |
| 2113 | else if (socket_id == RIL_SOCKET_3) { |
| 2114 | fd = s_ril_param_socket3.fdCommand; |
| 2115 | writeMutexHook = &s_writeMutex_socket3; |
| 2116 | } |
| 2117 | #endif |
| 2118 | #if (SIM_COUNT >= 4) |
| 2119 | else if (socket_id == RIL_SOCKET_4) { |
| 2120 | fd = s_ril_param_socket4.fdCommand; |
| 2121 | writeMutexHook = &s_writeMutex_socket4; |
| 2122 | } |
| 2123 | #endif |
| 2124 | #endif |
| 2125 | if (fd < 0) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2126 | return -1; |
| 2127 | } |
| 2128 | |
| 2129 | if (dataSize > MAX_COMMAND_BYTES) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2130 | RLOGE("RIL: packet larger than %u (%u)", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2131 | MAX_COMMAND_BYTES, (unsigned int )dataSize); |
| 2132 | |
| 2133 | return -1; |
| 2134 | } |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2135 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2136 | pthread_mutex_lock(writeMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2137 | |
| 2138 | header = htonl(dataSize); |
| 2139 | |
| 2140 | ret = blockingWrite(fd, (void *)&header, sizeof(header)); |
| 2141 | |
| 2142 | if (ret < 0) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2143 | pthread_mutex_unlock(writeMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2144 | return ret; |
| 2145 | } |
| 2146 | |
Kenny | ee1fadc | 2009-08-13 00:45:53 +0800 | [diff] [blame] | 2147 | ret = blockingWrite(fd, data, dataSize); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2148 | |
| 2149 | if (ret < 0) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2150 | pthread_mutex_unlock(writeMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2151 | return ret; |
| 2152 | } |
| 2153 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2154 | pthread_mutex_unlock(writeMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2155 | |
| 2156 | return 0; |
| 2157 | } |
| 2158 | |
| 2159 | static int |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2160 | sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2161 | printResponse; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2162 | return sendResponseRaw(p.data(), p.dataSize(), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2163 | } |
| 2164 | |
Mohamad Ayyash | 74f7e66 | 2014-04-18 11:43:28 -0700 | [diff] [blame] | 2165 | /** response is an int* pointing to an array of ints */ |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2166 | |
| 2167 | static int |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2168 | responseInts(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2169 | int numInts; |
| 2170 | |
| 2171 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2172 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2173 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2174 | } |
| 2175 | if (responselen % sizeof(int) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2176 | RLOGE("responseInts: invalid response length %d expected multiple of %d\n", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2177 | (int)responselen, (int)sizeof(int)); |
| 2178 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2179 | } |
| 2180 | |
| 2181 | int *p_int = (int *) response; |
| 2182 | |
Mohamad Ayyash | 74f7e66 | 2014-04-18 11:43:28 -0700 | [diff] [blame] | 2183 | numInts = responselen / sizeof(int); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2184 | p.writeInt32 (numInts); |
| 2185 | |
| 2186 | /* each int*/ |
| 2187 | startResponse; |
| 2188 | for (int i = 0 ; i < numInts ; i++) { |
| 2189 | appendPrintBuf("%s%d,", printBuf, p_int[i]); |
| 2190 | p.writeInt32(p_int[i]); |
| 2191 | } |
| 2192 | removeLastChar; |
| 2193 | closeResponse; |
| 2194 | |
| 2195 | return 0; |
| 2196 | } |
| 2197 | |
Chao Liu | 548a81e | 2015-05-14 16:13:46 -0700 | [diff] [blame] | 2198 | // Response is an int or RIL_LastCallFailCauseInfo. |
| 2199 | // Currently, only Shamu plans to use RIL_LastCallFailCauseInfo. |
| 2200 | // TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo. |
| 2201 | static int responseFailCause(Parcel &p, void *response, size_t responselen) { |
| 2202 | if (response == NULL && responselen != 0) { |
| 2203 | RLOGE("invalid response: NULL"); |
| 2204 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2205 | } |
| 2206 | |
| 2207 | if (responselen == sizeof(int)) { |
Sungmin Choi | a408c25 | 2015-07-01 16:22:46 +0900 | [diff] [blame] | 2208 | startResponse; |
| 2209 | int *p_int = (int *) response; |
| 2210 | appendPrintBuf("%s%d,", printBuf, p_int[0]); |
| 2211 | p.writeInt32(p_int[0]); |
| 2212 | removeLastChar; |
| 2213 | closeResponse; |
Chao Liu | 548a81e | 2015-05-14 16:13:46 -0700 | [diff] [blame] | 2214 | } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) { |
| 2215 | startResponse; |
| 2216 | RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response; |
| 2217 | appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code, |
| 2218 | p_fail_cause_info->vendor_cause); |
| 2219 | p.writeInt32(p_fail_cause_info->cause_code); |
| 2220 | writeStringToParcel(p, p_fail_cause_info->vendor_cause); |
| 2221 | removeLastChar; |
| 2222 | closeResponse; |
| 2223 | } else { |
| 2224 | RLOGE("responseFailCause: invalid response length %d expected an int or " |
| 2225 | "RIL_LastCallFailCauseInfo", (int)responselen); |
| 2226 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2227 | } |
| 2228 | |
| 2229 | return 0; |
| 2230 | } |
| 2231 | |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2232 | /** response is a char **, pointing to an array of char *'s |
| 2233 | The parcel will begin with the version */ |
| 2234 | static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) { |
| 2235 | p.writeInt32(version); |
| 2236 | return responseStrings(p, response, responselen); |
| 2237 | } |
| 2238 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2239 | /** response is a char **, pointing to an array of char *'s */ |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2240 | static int responseStrings(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2241 | int numStrings; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2242 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2243 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2244 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2245 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2246 | } |
| 2247 | if (responselen % sizeof(char *) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2248 | RLOGE("responseStrings: invalid response length %d expected multiple of %d\n", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2249 | (int)responselen, (int)sizeof(char *)); |
| 2250 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2251 | } |
| 2252 | |
| 2253 | if (response == NULL) { |
| 2254 | p.writeInt32 (0); |
| 2255 | } else { |
| 2256 | char **p_cur = (char **) response; |
| 2257 | |
| 2258 | numStrings = responselen / sizeof(char *); |
| 2259 | p.writeInt32 (numStrings); |
| 2260 | |
| 2261 | /* each string*/ |
| 2262 | startResponse; |
| 2263 | for (int i = 0 ; i < numStrings ; i++) { |
| 2264 | appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]); |
| 2265 | writeStringToParcel (p, p_cur[i]); |
| 2266 | } |
| 2267 | removeLastChar; |
| 2268 | closeResponse; |
| 2269 | } |
| 2270 | return 0; |
| 2271 | } |
| 2272 | |
| 2273 | |
| 2274 | /** |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2275 | * NULL strings are accepted |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2276 | * FIXME currently ignores responselen |
| 2277 | */ |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2278 | static int responseString(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2279 | /* one string only */ |
| 2280 | startResponse; |
| 2281 | appendPrintBuf("%s%s", printBuf, (char*)response); |
| 2282 | closeResponse; |
| 2283 | |
| 2284 | writeStringToParcel(p, (const char *)response); |
| 2285 | |
| 2286 | return 0; |
| 2287 | } |
| 2288 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2289 | static int responseVoid(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2290 | startResponse; |
| 2291 | removeLastChar; |
| 2292 | return 0; |
| 2293 | } |
| 2294 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2295 | static int responseCallList(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2296 | int num; |
| 2297 | |
| 2298 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2299 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2300 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2301 | } |
| 2302 | |
| 2303 | if (responselen % sizeof (RIL_Call *) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2304 | RLOGE("responseCallList: invalid response length %d expected multiple of %d\n", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2305 | (int)responselen, (int)sizeof (RIL_Call *)); |
| 2306 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2307 | } |
| 2308 | |
| 2309 | startResponse; |
| 2310 | /* number of call info's */ |
| 2311 | num = responselen / sizeof(RIL_Call *); |
| 2312 | p.writeInt32(num); |
| 2313 | |
| 2314 | for (int i = 0 ; i < num ; i++) { |
| 2315 | RIL_Call *p_cur = ((RIL_Call **) response)[i]; |
| 2316 | /* each call info */ |
| 2317 | p.writeInt32(p_cur->state); |
| 2318 | p.writeInt32(p_cur->index); |
| 2319 | p.writeInt32(p_cur->toa); |
| 2320 | p.writeInt32(p_cur->isMpty); |
| 2321 | p.writeInt32(p_cur->isMT); |
| 2322 | p.writeInt32(p_cur->als); |
| 2323 | p.writeInt32(p_cur->isVoice); |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 2324 | p.writeInt32(p_cur->isVoicePrivacy); |
| 2325 | writeStringToParcel(p, p_cur->number); |
John Wang | ff36874 | 2009-03-24 17:56:29 -0700 | [diff] [blame] | 2326 | p.writeInt32(p_cur->numberPresentation); |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 2327 | writeStringToParcel(p, p_cur->name); |
| 2328 | p.writeInt32(p_cur->namePresentation); |
Wink Saville | 3a4840b | 2010-04-07 13:29:58 -0700 | [diff] [blame] | 2329 | // Remove when partners upgrade to version 3 |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 2330 | if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) { |
| 2331 | p.writeInt32(0); /* UUS Information is absent */ |
| 2332 | } else { |
| 2333 | RIL_UUS_Info *uusInfo = p_cur->uusInfo; |
| 2334 | p.writeInt32(1); /* UUS Information is present */ |
| 2335 | p.writeInt32(uusInfo->uusType); |
| 2336 | p.writeInt32(uusInfo->uusDcs); |
| 2337 | p.writeInt32(uusInfo->uusLength); |
| 2338 | p.write(uusInfo->uusData, uusInfo->uusLength); |
| 2339 | } |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2340 | appendPrintBuf("%s[id=%d,%s,toa=%d,", |
John Wang | ff36874 | 2009-03-24 17:56:29 -0700 | [diff] [blame] | 2341 | printBuf, |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 2342 | p_cur->index, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2343 | callStateToString(p_cur->state), |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2344 | p_cur->toa); |
| 2345 | appendPrintBuf("%s%s,%s,als=%d,%s,%s,", |
| 2346 | printBuf, |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 2347 | (p_cur->isMpty)?"conf":"norm", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2348 | (p_cur->isMT)?"mt":"mo", |
| 2349 | p_cur->als, |
| 2350 | (p_cur->isVoice)?"voc":"nonvoc", |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2351 | (p_cur->isVoicePrivacy)?"evp":"noevp"); |
| 2352 | appendPrintBuf("%s%s,cli=%d,name='%s',%d]", |
| 2353 | printBuf, |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 2354 | p_cur->number, |
| 2355 | p_cur->numberPresentation, |
| 2356 | p_cur->name, |
| 2357 | p_cur->namePresentation); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2358 | } |
| 2359 | removeLastChar; |
| 2360 | closeResponse; |
| 2361 | |
| 2362 | return 0; |
| 2363 | } |
| 2364 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2365 | static int responseSMS(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2366 | if (response == NULL) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2367 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2368 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2369 | } |
| 2370 | |
| 2371 | if (responselen != sizeof (RIL_SMS_Response) ) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2372 | RLOGE("invalid response length %d expected %d", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2373 | (int)responselen, (int)sizeof (RIL_SMS_Response)); |
| 2374 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2375 | } |
| 2376 | |
| 2377 | RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response; |
| 2378 | |
| 2379 | p.writeInt32(p_cur->messageRef); |
| 2380 | writeStringToParcel(p, p_cur->ackPDU); |
Jaikumar Ganesh | 920c78f | 2009-06-04 10:53:15 -0700 | [diff] [blame] | 2381 | p.writeInt32(p_cur->errorCode); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2382 | |
| 2383 | startResponse; |
Jaikumar Ganesh | 920c78f | 2009-06-04 10:53:15 -0700 | [diff] [blame] | 2384 | appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef, |
| 2385 | (char*)p_cur->ackPDU, p_cur->errorCode); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2386 | closeResponse; |
| 2387 | |
| 2388 | return 0; |
| 2389 | } |
| 2390 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 2391 | static int responseDataCallListV4(Parcel &p, void *response, size_t responselen) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2392 | { |
| 2393 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2394 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2395 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2396 | } |
| 2397 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 2398 | if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2399 | RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d", |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 2400 | (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2401 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2402 | } |
| 2403 | |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2404 | // Write version |
| 2405 | p.writeInt32(4); |
| 2406 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 2407 | int num = responselen / sizeof(RIL_Data_Call_Response_v4); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2408 | p.writeInt32(num); |
| 2409 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 2410 | RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2411 | startResponse; |
| 2412 | int i; |
| 2413 | for (i = 0; i < num; i++) { |
| 2414 | p.writeInt32(p_cur[i].cid); |
| 2415 | p.writeInt32(p_cur[i].active); |
| 2416 | writeStringToParcel(p, p_cur[i].type); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 2417 | // apn is not used, so don't send. |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2418 | writeStringToParcel(p, p_cur[i].address); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 2419 | appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2420 | p_cur[i].cid, |
| 2421 | (p_cur[i].active==0)?"down":"up", |
| 2422 | (char*)p_cur[i].type, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2423 | (char*)p_cur[i].address); |
| 2424 | } |
| 2425 | removeLastChar; |
| 2426 | closeResponse; |
| 2427 | |
| 2428 | return 0; |
| 2429 | } |
| 2430 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2431 | static int responseDataCallListV6(Parcel &p, void *response, size_t responselen) |
| 2432 | { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2433 | if (response == NULL && responselen != 0) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2434 | RLOGE("invalid response: NULL"); |
| 2435 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2436 | } |
| 2437 | |
| 2438 | if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2439 | RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d", |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2440 | (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6)); |
| 2441 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2442 | } |
| 2443 | |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2444 | // Write version |
| 2445 | p.writeInt32(6); |
| 2446 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2447 | int num = responselen / sizeof(RIL_Data_Call_Response_v6); |
| 2448 | p.writeInt32(num); |
| 2449 | |
| 2450 | RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response; |
| 2451 | startResponse; |
| 2452 | int i; |
| 2453 | for (i = 0; i < num; i++) { |
| 2454 | p.writeInt32((int)p_cur[i].status); |
| 2455 | p.writeInt32(p_cur[i].suggestedRetryTime); |
| 2456 | p.writeInt32(p_cur[i].cid); |
| 2457 | p.writeInt32(p_cur[i].active); |
| 2458 | writeStringToParcel(p, p_cur[i].type); |
| 2459 | writeStringToParcel(p, p_cur[i].ifname); |
| 2460 | writeStringToParcel(p, p_cur[i].addresses); |
| 2461 | writeStringToParcel(p, p_cur[i].dnses); |
| 2462 | writeStringToParcel(p, p_cur[i].gateways); |
| 2463 | appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf, |
| 2464 | p_cur[i].status, |
| 2465 | p_cur[i].suggestedRetryTime, |
| 2466 | p_cur[i].cid, |
| 2467 | (p_cur[i].active==0)?"down":"up", |
| 2468 | (char*)p_cur[i].type, |
| 2469 | (char*)p_cur[i].ifname, |
| 2470 | (char*)p_cur[i].addresses, |
| 2471 | (char*)p_cur[i].dnses, |
| 2472 | (char*)p_cur[i].gateways); |
| 2473 | } |
| 2474 | removeLastChar; |
| 2475 | closeResponse; |
| 2476 | |
| 2477 | return 0; |
| 2478 | } |
| 2479 | |
Sukanya Rajkhowa | b44dda3 | 2014-06-02 14:03:44 -0700 | [diff] [blame] | 2480 | static int responseDataCallListV9(Parcel &p, void *response, size_t responselen) |
| 2481 | { |
| 2482 | if (response == NULL && responselen != 0) { |
| 2483 | RLOGE("invalid response: NULL"); |
| 2484 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2485 | } |
| 2486 | |
| 2487 | if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) { |
| 2488 | RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d", |
| 2489 | (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9)); |
| 2490 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2491 | } |
| 2492 | |
| 2493 | // Write version |
| 2494 | p.writeInt32(10); |
| 2495 | |
| 2496 | int num = responselen / sizeof(RIL_Data_Call_Response_v9); |
| 2497 | p.writeInt32(num); |
| 2498 | |
| 2499 | RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response; |
| 2500 | startResponse; |
| 2501 | int i; |
| 2502 | for (i = 0; i < num; i++) { |
| 2503 | p.writeInt32((int)p_cur[i].status); |
| 2504 | p.writeInt32(p_cur[i].suggestedRetryTime); |
| 2505 | p.writeInt32(p_cur[i].cid); |
| 2506 | p.writeInt32(p_cur[i].active); |
| 2507 | writeStringToParcel(p, p_cur[i].type); |
| 2508 | writeStringToParcel(p, p_cur[i].ifname); |
| 2509 | writeStringToParcel(p, p_cur[i].addresses); |
| 2510 | writeStringToParcel(p, p_cur[i].dnses); |
| 2511 | writeStringToParcel(p, p_cur[i].gateways); |
| 2512 | writeStringToParcel(p, p_cur[i].pcscf); |
| 2513 | appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf, |
| 2514 | p_cur[i].status, |
| 2515 | p_cur[i].suggestedRetryTime, |
| 2516 | p_cur[i].cid, |
| 2517 | (p_cur[i].active==0)?"down":"up", |
| 2518 | (char*)p_cur[i].type, |
| 2519 | (char*)p_cur[i].ifname, |
| 2520 | (char*)p_cur[i].addresses, |
| 2521 | (char*)p_cur[i].dnses, |
| 2522 | (char*)p_cur[i].gateways, |
| 2523 | (char*)p_cur[i].pcscf); |
| 2524 | } |
| 2525 | removeLastChar; |
| 2526 | closeResponse; |
| 2527 | |
| 2528 | return 0; |
| 2529 | } |
| 2530 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 2531 | static int responseDataCallListV11(Parcel &p, void *response, size_t responselen) { |
| 2532 | if (response == NULL && responselen != 0) { |
| 2533 | RLOGE("invalid response: NULL"); |
| 2534 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2535 | } |
| 2536 | |
| 2537 | if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) { |
| 2538 | RLOGE("invalid response length %d expected multiple of %d", |
| 2539 | (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11)); |
| 2540 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2541 | } |
| 2542 | |
| 2543 | // Write version |
| 2544 | p.writeInt32(11); |
| 2545 | |
| 2546 | int num = responselen / sizeof(RIL_Data_Call_Response_v11); |
| 2547 | p.writeInt32(num); |
| 2548 | |
| 2549 | RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response; |
| 2550 | startResponse; |
| 2551 | int i; |
| 2552 | for (i = 0; i < num; i++) { |
| 2553 | p.writeInt32((int)p_cur[i].status); |
| 2554 | p.writeInt32(p_cur[i].suggestedRetryTime); |
| 2555 | p.writeInt32(p_cur[i].cid); |
| 2556 | p.writeInt32(p_cur[i].active); |
| 2557 | writeStringToParcel(p, p_cur[i].type); |
| 2558 | writeStringToParcel(p, p_cur[i].ifname); |
| 2559 | writeStringToParcel(p, p_cur[i].addresses); |
| 2560 | writeStringToParcel(p, p_cur[i].dnses); |
| 2561 | writeStringToParcel(p, p_cur[i].gateways); |
| 2562 | writeStringToParcel(p, p_cur[i].pcscf); |
| 2563 | p.writeInt32(p_cur[i].mtu); |
| 2564 | appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf, |
| 2565 | p_cur[i].status, |
| 2566 | p_cur[i].suggestedRetryTime, |
| 2567 | p_cur[i].cid, |
| 2568 | (p_cur[i].active==0)?"down":"up", |
| 2569 | (char*)p_cur[i].type, |
| 2570 | (char*)p_cur[i].ifname, |
| 2571 | (char*)p_cur[i].addresses, |
| 2572 | (char*)p_cur[i].dnses, |
| 2573 | (char*)p_cur[i].gateways, |
| 2574 | (char*)p_cur[i].pcscf, |
| 2575 | p_cur[i].mtu); |
| 2576 | } |
| 2577 | removeLastChar; |
| 2578 | closeResponse; |
| 2579 | |
| 2580 | return 0; |
| 2581 | } |
Sukanya Rajkhowa | b44dda3 | 2014-06-02 14:03:44 -0700 | [diff] [blame] | 2582 | |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2583 | static int responseDataCallList(Parcel &p, void *response, size_t responselen) |
| 2584 | { |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 2585 | if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) { |
| 2586 | if (s_callbacks.version < 5) { |
| 2587 | RLOGD("responseDataCallList: v4"); |
| 2588 | return responseDataCallListV4(p, response, responselen); |
| 2589 | } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) { |
| 2590 | return responseDataCallListV6(p, response, responselen); |
| 2591 | } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) { |
| 2592 | return responseDataCallListV9(p, response, responselen); |
| 2593 | } else { |
| 2594 | return responseDataCallListV11(p, response, responselen); |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2595 | } |
Sanket Padawe | f53c5fa | 2016-01-27 10:00:38 -0800 | [diff] [blame] | 2596 | } else { // RIL version >= 13 |
Sukanya Rajkhowa | b44dda3 | 2014-06-02 14:03:44 -0700 | [diff] [blame] | 2597 | if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) { |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 2598 | RLOGE("Data structure expected is RIL_Data_Call_Response_v11"); |
| 2599 | if (!isDebuggable()) { |
| 2600 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2601 | } else { |
| 2602 | assert(0); |
| 2603 | } |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2604 | } |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 2605 | return responseDataCallListV11(p, response, responselen); |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2606 | } |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2607 | } |
| 2608 | |
| 2609 | static int responseSetupDataCall(Parcel &p, void *response, size_t responselen) |
| 2610 | { |
| 2611 | if (s_callbacks.version < 5) { |
| 2612 | return responseStringsWithVersion(s_callbacks.version, p, response, responselen); |
| 2613 | } else { |
| 2614 | return responseDataCallList(p, response, responselen); |
| 2615 | } |
| 2616 | } |
| 2617 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2618 | static int responseRaw(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2619 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2620 | RLOGE("invalid response: NULL with responselen != 0"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2621 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2622 | } |
| 2623 | |
| 2624 | // The java code reads -1 size as null byte array |
| 2625 | if (response == NULL) { |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2626 | p.writeInt32(-1); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2627 | } else { |
| 2628 | p.writeInt32(responselen); |
| 2629 | p.write(response, responselen); |
| 2630 | } |
| 2631 | |
| 2632 | return 0; |
| 2633 | } |
| 2634 | |
| 2635 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2636 | static int responseSIM_IO(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2637 | if (response == NULL) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2638 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2639 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2640 | } |
| 2641 | |
| 2642 | if (responselen != sizeof (RIL_SIM_IO_Response) ) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2643 | RLOGE("invalid response length was %d expected %d", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2644 | (int)responselen, (int)sizeof (RIL_SIM_IO_Response)); |
| 2645 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2646 | } |
| 2647 | |
| 2648 | RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response; |
| 2649 | p.writeInt32(p_cur->sw1); |
| 2650 | p.writeInt32(p_cur->sw2); |
| 2651 | writeStringToParcel(p, p_cur->simResponse); |
| 2652 | |
| 2653 | startResponse; |
| 2654 | appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2, |
| 2655 | (char*)p_cur->simResponse); |
| 2656 | closeResponse; |
| 2657 | |
| 2658 | |
| 2659 | return 0; |
| 2660 | } |
| 2661 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2662 | static int responseCallForwards(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2663 | int num; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2664 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2665 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2666 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2667 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2668 | } |
| 2669 | |
| 2670 | if (responselen % sizeof(RIL_CallForwardInfo *) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2671 | RLOGE("responseCallForwards: invalid response length %d expected multiple of %d", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2672 | (int)responselen, (int)sizeof(RIL_CallForwardInfo *)); |
| 2673 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2674 | } |
| 2675 | |
| 2676 | /* number of call info's */ |
| 2677 | num = responselen / sizeof(RIL_CallForwardInfo *); |
| 2678 | p.writeInt32(num); |
| 2679 | |
| 2680 | startResponse; |
| 2681 | for (int i = 0 ; i < num ; i++) { |
| 2682 | RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i]; |
| 2683 | |
| 2684 | p.writeInt32(p_cur->status); |
| 2685 | p.writeInt32(p_cur->reason); |
| 2686 | p.writeInt32(p_cur->serviceClass); |
| 2687 | p.writeInt32(p_cur->toa); |
| 2688 | writeStringToParcel(p, p_cur->number); |
| 2689 | p.writeInt32(p_cur->timeSeconds); |
| 2690 | appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf, |
| 2691 | (p_cur->status==1)?"enable":"disable", |
| 2692 | p_cur->reason, p_cur->serviceClass, p_cur->toa, |
| 2693 | (char*)p_cur->number, |
| 2694 | p_cur->timeSeconds); |
| 2695 | } |
| 2696 | removeLastChar; |
| 2697 | closeResponse; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2698 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2699 | return 0; |
| 2700 | } |
| 2701 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2702 | static int responseSsn(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2703 | if (response == NULL) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2704 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2705 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2706 | } |
| 2707 | |
| 2708 | if (responselen != sizeof(RIL_SuppSvcNotification)) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2709 | RLOGE("invalid response length was %d expected %d", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2710 | (int)responselen, (int)sizeof (RIL_SuppSvcNotification)); |
| 2711 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2712 | } |
| 2713 | |
| 2714 | RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response; |
| 2715 | p.writeInt32(p_cur->notificationType); |
| 2716 | p.writeInt32(p_cur->code); |
| 2717 | p.writeInt32(p_cur->index); |
| 2718 | p.writeInt32(p_cur->type); |
| 2719 | writeStringToParcel(p, p_cur->number); |
| 2720 | |
| 2721 | startResponse; |
| 2722 | appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf, |
| 2723 | (p_cur->notificationType==0)?"mo":"mt", |
| 2724 | p_cur->code, p_cur->index, p_cur->type, |
| 2725 | (char*)p_cur->number); |
| 2726 | closeResponse; |
| 2727 | |
| 2728 | return 0; |
| 2729 | } |
| 2730 | |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2731 | static int responseCellList(Parcel &p, void *response, size_t responselen) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2732 | int num; |
| 2733 | |
| 2734 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2735 | RLOGE("invalid response: NULL"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2736 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2737 | } |
| 2738 | |
| 2739 | if (responselen % sizeof (RIL_NeighboringCell *) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2740 | RLOGE("responseCellList: invalid response length %d expected multiple of %d\n", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2741 | (int)responselen, (int)sizeof (RIL_NeighboringCell *)); |
| 2742 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2743 | } |
| 2744 | |
| 2745 | startResponse; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2746 | /* number of records */ |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2747 | num = responselen / sizeof(RIL_NeighboringCell *); |
| 2748 | p.writeInt32(num); |
| 2749 | |
| 2750 | for (int i = 0 ; i < num ; i++) { |
| 2751 | RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i]; |
| 2752 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2753 | p.writeInt32(p_cur->rssi); |
| 2754 | writeStringToParcel (p, p_cur->cid); |
| 2755 | |
| 2756 | appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf, |
| 2757 | p_cur->cid, p_cur->rssi); |
| 2758 | } |
| 2759 | removeLastChar; |
| 2760 | closeResponse; |
| 2761 | |
| 2762 | return 0; |
| 2763 | } |
| 2764 | |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2765 | /** |
| 2766 | * Marshall the signalInfoRecord into the parcel if it exists. |
| 2767 | */ |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2768 | static void marshallSignalInfoRecord(Parcel &p, |
| 2769 | RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) { |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2770 | p.writeInt32(p_signalInfoRecord.isPresent); |
| 2771 | p.writeInt32(p_signalInfoRecord.signalType); |
| 2772 | p.writeInt32(p_signalInfoRecord.alertPitch); |
| 2773 | p.writeInt32(p_signalInfoRecord.signal); |
| 2774 | } |
| 2775 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2776 | static int responseCdmaInformationRecords(Parcel &p, |
| 2777 | void *response, size_t responselen) { |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2778 | int num; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2779 | char* string8 = NULL; |
| 2780 | int buffer_lenght; |
| 2781 | RIL_CDMA_InformationRecord *infoRec; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2782 | |
| 2783 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2784 | RLOGE("invalid response: NULL"); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2785 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2786 | } |
| 2787 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2788 | if (responselen != sizeof (RIL_CDMA_InformationRecords)) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 2789 | RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n", |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2790 | (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *)); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2791 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2792 | } |
| 2793 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2794 | RIL_CDMA_InformationRecords *p_cur = |
| 2795 | (RIL_CDMA_InformationRecords *) response; |
| 2796 | num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2797 | |
| 2798 | startResponse; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2799 | p.writeInt32(num); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2800 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2801 | for (int i = 0 ; i < num ; i++) { |
| 2802 | infoRec = &p_cur->infoRec[i]; |
| 2803 | p.writeInt32(infoRec->name); |
| 2804 | switch (infoRec->name) { |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2805 | case RIL_CDMA_DISPLAY_INFO_REC: |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2806 | case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC: |
| 2807 | if (infoRec->rec.display.alpha_len > |
| 2808 | CDMA_ALPHA_INFO_BUFFER_LENGTH) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2809 | RLOGE("invalid display info response length %d \ |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2810 | expected not more than %d\n", |
| 2811 | (int)infoRec->rec.display.alpha_len, |
| 2812 | CDMA_ALPHA_INFO_BUFFER_LENGTH); |
| 2813 | return RIL_ERRNO_INVALID_RESPONSE; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2814 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2815 | string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1) |
| 2816 | * sizeof(char) ); |
| 2817 | for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) { |
| 2818 | string8[i] = infoRec->rec.display.alpha_buf[i]; |
| 2819 | } |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2820 | string8[(int)infoRec->rec.display.alpha_len] = '\0'; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2821 | writeStringToParcel(p, (const char*)string8); |
| 2822 | free(string8); |
| 2823 | string8 = NULL; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2824 | break; |
| 2825 | case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC: |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2826 | case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC: |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2827 | case RIL_CDMA_CONNECTED_NUMBER_INFO_REC: |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2828 | if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2829 | RLOGE("invalid display info response length %d \ |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2830 | expected not more than %d\n", |
| 2831 | (int)infoRec->rec.number.len, |
| 2832 | CDMA_NUMBER_INFO_BUFFER_LENGTH); |
| 2833 | return RIL_ERRNO_INVALID_RESPONSE; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2834 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2835 | string8 = (char*) malloc((infoRec->rec.number.len + 1) |
| 2836 | * sizeof(char) ); |
| 2837 | for (int i = 0 ; i < infoRec->rec.number.len; i++) { |
| 2838 | string8[i] = infoRec->rec.number.buf[i]; |
| 2839 | } |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2840 | string8[(int)infoRec->rec.number.len] = '\0'; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2841 | writeStringToParcel(p, (const char*)string8); |
| 2842 | free(string8); |
| 2843 | string8 = NULL; |
| 2844 | p.writeInt32(infoRec->rec.number.number_type); |
| 2845 | p.writeInt32(infoRec->rec.number.number_plan); |
| 2846 | p.writeInt32(infoRec->rec.number.pi); |
| 2847 | p.writeInt32(infoRec->rec.number.si); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2848 | break; |
| 2849 | case RIL_CDMA_SIGNAL_INFO_REC: |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2850 | p.writeInt32(infoRec->rec.signal.isPresent); |
| 2851 | p.writeInt32(infoRec->rec.signal.signalType); |
| 2852 | p.writeInt32(infoRec->rec.signal.alertPitch); |
| 2853 | p.writeInt32(infoRec->rec.signal.signal); |
| 2854 | |
| 2855 | appendPrintBuf("%sisPresent=%X, signalType=%X, \ |
| 2856 | alertPitch=%X, signal=%X, ", |
| 2857 | printBuf, (int)infoRec->rec.signal.isPresent, |
| 2858 | (int)infoRec->rec.signal.signalType, |
| 2859 | (int)infoRec->rec.signal.alertPitch, |
| 2860 | (int)infoRec->rec.signal.signal); |
| 2861 | removeLastChar; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2862 | break; |
| 2863 | case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC: |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2864 | if (infoRec->rec.redir.redirectingNumber.len > |
| 2865 | CDMA_NUMBER_INFO_BUFFER_LENGTH) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2866 | RLOGE("invalid display info response length %d \ |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2867 | expected not more than %d\n", |
| 2868 | (int)infoRec->rec.redir.redirectingNumber.len, |
| 2869 | CDMA_NUMBER_INFO_BUFFER_LENGTH); |
| 2870 | return RIL_ERRNO_INVALID_RESPONSE; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2871 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2872 | string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber |
| 2873 | .len + 1) * sizeof(char) ); |
| 2874 | for (int i = 0; |
| 2875 | i < infoRec->rec.redir.redirectingNumber.len; |
| 2876 | i++) { |
| 2877 | string8[i] = infoRec->rec.redir.redirectingNumber.buf[i]; |
| 2878 | } |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 2879 | string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0'; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2880 | writeStringToParcel(p, (const char*)string8); |
| 2881 | free(string8); |
| 2882 | string8 = NULL; |
| 2883 | p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type); |
| 2884 | p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan); |
| 2885 | p.writeInt32(infoRec->rec.redir.redirectingNumber.pi); |
| 2886 | p.writeInt32(infoRec->rec.redir.redirectingNumber.si); |
| 2887 | p.writeInt32(infoRec->rec.redir.redirectingReason); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2888 | break; |
| 2889 | case RIL_CDMA_LINE_CONTROL_INFO_REC: |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2890 | p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded); |
| 2891 | p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle); |
| 2892 | p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse); |
| 2893 | p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial); |
| 2894 | |
| 2895 | appendPrintBuf("%slineCtrlPolarityIncluded=%d, \ |
| 2896 | lineCtrlToggle=%d, lineCtrlReverse=%d, \ |
| 2897 | lineCtrlPowerDenial=%d, ", printBuf, |
| 2898 | (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded, |
| 2899 | (int)infoRec->rec.lineCtrl.lineCtrlToggle, |
| 2900 | (int)infoRec->rec.lineCtrl.lineCtrlReverse, |
| 2901 | (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial); |
| 2902 | removeLastChar; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2903 | break; |
| 2904 | case RIL_CDMA_T53_CLIR_INFO_REC: |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2905 | p.writeInt32((int)(infoRec->rec.clir.cause)); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2906 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2907 | appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause); |
| 2908 | removeLastChar; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2909 | break; |
| 2910 | case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC: |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2911 | p.writeInt32(infoRec->rec.audioCtrl.upLink); |
| 2912 | p.writeInt32(infoRec->rec.audioCtrl.downLink); |
| 2913 | |
| 2914 | appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf, |
| 2915 | infoRec->rec.audioCtrl.upLink, |
| 2916 | infoRec->rec.audioCtrl.downLink); |
| 2917 | removeLastChar; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2918 | break; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2919 | case RIL_CDMA_T53_RELEASE_INFO_REC: |
| 2920 | // TODO(Moto): See David Krause, he has the answer:) |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2921 | RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE"); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2922 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2923 | default: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2924 | RLOGE("Incorrect name value"); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2925 | return RIL_ERRNO_INVALID_RESPONSE; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2926 | } |
| 2927 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2928 | closeResponse; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2929 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2930 | return 0; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2931 | } |
| 2932 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 2933 | static void responseRilSignalStrengthV5(Parcel &p, RIL_SignalStrength_v10 *p_cur) { |
| 2934 | p.writeInt32(p_cur->GW_SignalStrength.signalStrength); |
| 2935 | p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate); |
| 2936 | p.writeInt32(p_cur->CDMA_SignalStrength.dbm); |
| 2937 | p.writeInt32(p_cur->CDMA_SignalStrength.ecio); |
| 2938 | p.writeInt32(p_cur->EVDO_SignalStrength.dbm); |
| 2939 | p.writeInt32(p_cur->EVDO_SignalStrength.ecio); |
| 2940 | p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio); |
| 2941 | } |
| 2942 | |
| 2943 | static void responseRilSignalStrengthV6Extra(Parcel &p, RIL_SignalStrength_v10 *p_cur) { |
| 2944 | /* |
| 2945 | * Fixup LTE for backwards compatibility |
| 2946 | */ |
| 2947 | // signalStrength: -1 -> 99 |
| 2948 | if (p_cur->LTE_SignalStrength.signalStrength == -1) { |
| 2949 | p_cur->LTE_SignalStrength.signalStrength = 99; |
| 2950 | } |
| 2951 | // rsrp: -1 -> INT_MAX all other negative value to positive. |
| 2952 | // So remap here |
| 2953 | if (p_cur->LTE_SignalStrength.rsrp == -1) { |
| 2954 | p_cur->LTE_SignalStrength.rsrp = INT_MAX; |
| 2955 | } else if (p_cur->LTE_SignalStrength.rsrp < -1) { |
| 2956 | p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp; |
| 2957 | } |
| 2958 | // rsrq: -1 -> INT_MAX |
| 2959 | if (p_cur->LTE_SignalStrength.rsrq == -1) { |
| 2960 | p_cur->LTE_SignalStrength.rsrq = INT_MAX; |
| 2961 | } |
| 2962 | // Not remapping rssnr is already using INT_MAX |
| 2963 | |
| 2964 | // cqi: -1 -> INT_MAX |
| 2965 | if (p_cur->LTE_SignalStrength.cqi == -1) { |
| 2966 | p_cur->LTE_SignalStrength.cqi = INT_MAX; |
| 2967 | } |
| 2968 | |
| 2969 | p.writeInt32(p_cur->LTE_SignalStrength.signalStrength); |
| 2970 | p.writeInt32(p_cur->LTE_SignalStrength.rsrp); |
| 2971 | p.writeInt32(p_cur->LTE_SignalStrength.rsrq); |
| 2972 | p.writeInt32(p_cur->LTE_SignalStrength.rssnr); |
| 2973 | p.writeInt32(p_cur->LTE_SignalStrength.cqi); |
| 2974 | } |
| 2975 | |
| 2976 | static void responseRilSignalStrengthV10(Parcel &p, RIL_SignalStrength_v10 *p_cur) { |
| 2977 | responseRilSignalStrengthV5(p, p_cur); |
| 2978 | responseRilSignalStrengthV6Extra(p, p_cur); |
| 2979 | p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp); |
| 2980 | } |
| 2981 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 2982 | static int responseRilSignalStrength(Parcel &p, |
| 2983 | void *response, size_t responselen) { |
| 2984 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2985 | RLOGE("invalid response: NULL"); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2986 | return RIL_ERRNO_INVALID_RESPONSE; |
| 2987 | } |
| 2988 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 2989 | if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) { |
| 2990 | if (responselen >= sizeof (RIL_SignalStrength_v5)) { |
| 2991 | RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 2992 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 2993 | responseRilSignalStrengthV5(p, p_cur); |
Uma Maheswari Ramalingam | 9efcac5 | 2012-08-09 11:59:17 -0700 | [diff] [blame] | 2994 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 2995 | if (responselen >= sizeof (RIL_SignalStrength_v6)) { |
| 2996 | responseRilSignalStrengthV6Extra(p, p_cur); |
| 2997 | if (responselen >= sizeof (RIL_SignalStrength_v10)) { |
| 2998 | p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp); |
| 2999 | } else { |
| 3000 | p.writeInt32(INT_MAX); |
Wink Saville | 18e4ab1 | 2013-04-07 17:31:04 -0700 | [diff] [blame] | 3001 | } |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 3002 | } else { |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3003 | p.writeInt32(99); |
| 3004 | p.writeInt32(INT_MAX); |
| 3005 | p.writeInt32(INT_MAX); |
| 3006 | p.writeInt32(INT_MAX); |
| 3007 | p.writeInt32(INT_MAX); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 3008 | p.writeInt32(INT_MAX); |
| 3009 | } |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 3010 | } else { |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3011 | RLOGE("invalid response length"); |
| 3012 | return RIL_ERRNO_INVALID_RESPONSE; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 3013 | } |
Sanket Padawe | f53c5fa | 2016-01-27 10:00:38 -0800 | [diff] [blame] | 3014 | } else { // RIL version >= 13 |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3015 | if (responselen % sizeof(RIL_SignalStrength_v10) != 0) { |
| 3016 | RLOGE("Data structure expected is RIL_SignalStrength_v10"); |
| 3017 | if (!isDebuggable()) { |
| 3018 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3019 | } else { |
| 3020 | assert(0); |
| 3021 | } |
| 3022 | } |
| 3023 | RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response); |
| 3024 | responseRilSignalStrengthV10(p, p_cur); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3025 | } |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3026 | startResponse; |
| 3027 | appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\ |
| 3028 | CDMA_SS.dbm=%d,CDMA_SSecio=%d,\ |
| 3029 | EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\ |
| 3030 | EVDO_SS.signalNoiseRatio=%d,\ |
| 3031 | LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\ |
| 3032 | LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]", |
| 3033 | printBuf, |
| 3034 | p_cur->GW_SignalStrength.signalStrength, |
| 3035 | p_cur->GW_SignalStrength.bitErrorRate, |
| 3036 | p_cur->CDMA_SignalStrength.dbm, |
| 3037 | p_cur->CDMA_SignalStrength.ecio, |
| 3038 | p_cur->EVDO_SignalStrength.dbm, |
| 3039 | p_cur->EVDO_SignalStrength.ecio, |
| 3040 | p_cur->EVDO_SignalStrength.signalNoiseRatio, |
| 3041 | p_cur->LTE_SignalStrength.signalStrength, |
| 3042 | p_cur->LTE_SignalStrength.rsrp, |
| 3043 | p_cur->LTE_SignalStrength.rsrq, |
| 3044 | p_cur->LTE_SignalStrength.rssnr, |
| 3045 | p_cur->LTE_SignalStrength.cqi, |
| 3046 | p_cur->TD_SCDMA_SignalStrength.rscp); |
| 3047 | closeResponse; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3048 | return 0; |
| 3049 | } |
| 3050 | |
| 3051 | static int responseCallRing(Parcel &p, void *response, size_t responselen) { |
| 3052 | if ((response == NULL) || (responselen == 0)) { |
| 3053 | return responseVoid(p, response, responselen); |
| 3054 | } else { |
| 3055 | return responseCdmaSignalInfoRecord(p, response, responselen); |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) { |
| 3060 | if (response == NULL || responselen == 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3061 | RLOGE("invalid response: NULL"); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3062 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3063 | } |
| 3064 | |
| 3065 | if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3066 | RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n", |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3067 | (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord)); |
| 3068 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3069 | } |
| 3070 | |
| 3071 | startResponse; |
| 3072 | |
| 3073 | RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response); |
| 3074 | marshallSignalInfoRecord(p, *p_cur); |
| 3075 | |
| 3076 | appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\ |
| 3077 | signal=%d]", |
| 3078 | printBuf, |
| 3079 | p_cur->isPresent, |
| 3080 | p_cur->signalType, |
| 3081 | p_cur->alertPitch, |
| 3082 | p_cur->signal); |
| 3083 | |
| 3084 | closeResponse; |
| 3085 | return 0; |
| 3086 | } |
| 3087 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 3088 | static int responseCdmaCallWaiting(Parcel &p, void *response, |
| 3089 | size_t responselen) { |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3090 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3091 | RLOGE("invalid response: NULL"); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3092 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3093 | } |
| 3094 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 3095 | if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3096 | RLOGW("Upgrade to ril version %d\n", RIL_VERSION); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response); |
| 3100 | |
| 3101 | writeStringToParcel(p, p_cur->number); |
| 3102 | p.writeInt32(p_cur->numberPresentation); |
| 3103 | writeStringToParcel(p, p_cur->name); |
| 3104 | marshallSignalInfoRecord(p, p_cur->signalInfoRecord); |
| 3105 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3106 | if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) { |
| 3107 | if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) { |
| 3108 | p.writeInt32(p_cur->number_type); |
| 3109 | p.writeInt32(p_cur->number_plan); |
| 3110 | } else { |
| 3111 | p.writeInt32(0); |
| 3112 | p.writeInt32(0); |
| 3113 | } |
Sanket Padawe | f53c5fa | 2016-01-27 10:00:38 -0800 | [diff] [blame] | 3114 | } else { // RIL version >= 13 |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3115 | if (responselen % sizeof(RIL_CDMA_CallWaiting_v6) != 0) { |
| 3116 | RLOGE("Data structure expected is RIL_CDMA_CallWaiting_v6"); |
| 3117 | if (!isDebuggable()) { |
| 3118 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3119 | } else { |
| 3120 | assert(0); |
| 3121 | } |
| 3122 | } |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 3123 | p.writeInt32(p_cur->number_type); |
| 3124 | p.writeInt32(p_cur->number_plan); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | startResponse; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3128 | appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\ |
| 3129 | signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\ |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 3130 | signal=%d,number_type=%d,number_plan=%d]", |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3131 | printBuf, |
| 3132 | p_cur->number, |
| 3133 | p_cur->numberPresentation, |
| 3134 | p_cur->name, |
| 3135 | p_cur->signalInfoRecord.isPresent, |
| 3136 | p_cur->signalInfoRecord.signalType, |
| 3137 | p_cur->signalInfoRecord.alertPitch, |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 3138 | p_cur->signalInfoRecord.signal, |
| 3139 | p_cur->number_type, |
| 3140 | p_cur->number_plan); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3141 | closeResponse; |
| 3142 | |
| 3143 | return 0; |
| 3144 | } |
| 3145 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3146 | static void responseSimRefreshV7(Parcel &p, void *response) { |
| 3147 | RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response); |
| 3148 | p.writeInt32(p_cur->result); |
| 3149 | p.writeInt32(p_cur->ef_id); |
| 3150 | writeStringToParcel(p, p_cur->aid); |
| 3151 | |
| 3152 | appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s", |
| 3153 | printBuf, |
| 3154 | p_cur->result, |
| 3155 | p_cur->ef_id, |
| 3156 | p_cur->aid); |
| 3157 | |
| 3158 | } |
| 3159 | |
Alex Yakavenka | 45e740e | 2012-01-31 11:48:27 -0800 | [diff] [blame] | 3160 | static int responseSimRefresh(Parcel &p, void *response, size_t responselen) { |
| 3161 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3162 | RLOGE("responseSimRefresh: invalid response: NULL"); |
Alex Yakavenka | 45e740e | 2012-01-31 11:48:27 -0800 | [diff] [blame] | 3163 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3164 | } |
| 3165 | |
| 3166 | startResponse; |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3167 | if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) { |
Sanket Padawe | 41c94d0 | 2016-01-21 15:49:33 -0800 | [diff] [blame] | 3168 | if (s_callbacks.version >= 7) { |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3169 | responseSimRefreshV7(p, response); |
| 3170 | } else { |
| 3171 | int *p_cur = ((int *) response); |
| 3172 | p.writeInt32(p_cur[0]); |
| 3173 | p.writeInt32(p_cur[1]); |
| 3174 | writeStringToParcel(p, NULL); |
Alex Yakavenka | 45e740e | 2012-01-31 11:48:27 -0800 | [diff] [blame] | 3175 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3176 | appendPrintBuf("%sresult=%d, ef_id=%d", |
| 3177 | printBuf, |
| 3178 | p_cur[0], |
| 3179 | p_cur[1]); |
| 3180 | } |
Sanket Padawe | f53c5fa | 2016-01-27 10:00:38 -0800 | [diff] [blame] | 3181 | } else { // RIL version >= 13 |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3182 | if (responselen % sizeof(RIL_SimRefreshResponse_v7) != 0) { |
| 3183 | RLOGE("Data structure expected is RIL_SimRefreshResponse_v7"); |
| 3184 | if (!isDebuggable()) { |
| 3185 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3186 | } else { |
| 3187 | assert(0); |
| 3188 | } |
| 3189 | } |
| 3190 | responseSimRefreshV7(p, response); |
Alex Yakavenka | 45e740e | 2012-01-31 11:48:27 -0800 | [diff] [blame] | 3191 | |
Alex Yakavenka | 45e740e | 2012-01-31 11:48:27 -0800 | [diff] [blame] | 3192 | } |
| 3193 | closeResponse; |
| 3194 | |
| 3195 | return 0; |
| 3196 | } |
| 3197 | |
Sanket Padawe | f53c5fa | 2016-01-27 10:00:38 -0800 | [diff] [blame] | 3198 | static int responseCellInfoListV6(Parcel &p, void *response, size_t responselen) { |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 3199 | if (response == NULL && responselen != 0) { |
| 3200 | RLOGE("invalid response: NULL"); |
| 3201 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3202 | } |
| 3203 | |
| 3204 | if (responselen % sizeof(RIL_CellInfo) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 3205 | RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d", |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 3206 | (int)responselen, (int)sizeof(RIL_CellInfo)); |
| 3207 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3208 | } |
| 3209 | |
| 3210 | int num = responselen / sizeof(RIL_CellInfo); |
| 3211 | p.writeInt32(num); |
| 3212 | |
| 3213 | RIL_CellInfo *p_cur = (RIL_CellInfo *) response; |
| 3214 | startResponse; |
| 3215 | int i; |
| 3216 | for (i = 0; i < num; i++) { |
| 3217 | appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i, |
| 3218 | p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp); |
| 3219 | p.writeInt32((int)p_cur->cellInfoType); |
| 3220 | p.writeInt32(p_cur->registered); |
| 3221 | p.writeInt32(p_cur->timeStampType); |
| 3222 | p.writeInt64(p_cur->timeStamp); |
| 3223 | switch(p_cur->cellInfoType) { |
| 3224 | case RIL_CELL_INFO_TYPE_GSM: { |
Wink Saville | c57b3eb | 2013-04-17 12:51:41 -0700 | [diff] [blame] | 3225 | appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf, |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 3226 | p_cur->CellInfo.gsm.cellIdentityGsm.mcc, |
| 3227 | p_cur->CellInfo.gsm.cellIdentityGsm.mnc, |
| 3228 | p_cur->CellInfo.gsm.cellIdentityGsm.lac, |
Wink Saville | c57b3eb | 2013-04-17 12:51:41 -0700 | [diff] [blame] | 3229 | p_cur->CellInfo.gsm.cellIdentityGsm.cid); |
| 3230 | appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf, |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 3231 | p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength, |
| 3232 | p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate); |
| 3233 | |
| 3234 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc); |
| 3235 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc); |
| 3236 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac); |
| 3237 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid); |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 3238 | p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength); |
| 3239 | p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate); |
| 3240 | break; |
| 3241 | } |
Wink Saville | c57b3eb | 2013-04-17 12:51:41 -0700 | [diff] [blame] | 3242 | case RIL_CELL_INFO_TYPE_WCDMA: { |
| 3243 | appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf, |
| 3244 | p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc, |
| 3245 | p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc, |
| 3246 | p_cur->CellInfo.wcdma.cellIdentityWcdma.lac, |
| 3247 | p_cur->CellInfo.wcdma.cellIdentityWcdma.cid, |
| 3248 | p_cur->CellInfo.wcdma.cellIdentityWcdma.psc); |
| 3249 | appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf, |
| 3250 | p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength, |
| 3251 | p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate); |
| 3252 | |
| 3253 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc); |
| 3254 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc); |
| 3255 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac); |
| 3256 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid); |
| 3257 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc); |
| 3258 | p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength); |
| 3259 | p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate); |
| 3260 | break; |
| 3261 | } |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 3262 | case RIL_CELL_INFO_TYPE_CDMA: { |
| 3263 | appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf, |
| 3264 | p_cur->CellInfo.cdma.cellIdentityCdma.networkId, |
| 3265 | p_cur->CellInfo.cdma.cellIdentityCdma.systemId, |
| 3266 | p_cur->CellInfo.cdma.cellIdentityCdma.basestationId, |
| 3267 | p_cur->CellInfo.cdma.cellIdentityCdma.longitude, |
| 3268 | p_cur->CellInfo.cdma.cellIdentityCdma.latitude); |
| 3269 | |
| 3270 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId); |
| 3271 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId); |
| 3272 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId); |
| 3273 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude); |
| 3274 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude); |
| 3275 | |
| 3276 | appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf, |
| 3277 | p_cur->CellInfo.cdma.signalStrengthCdma.dbm, |
| 3278 | p_cur->CellInfo.cdma.signalStrengthCdma.ecio, |
| 3279 | p_cur->CellInfo.cdma.signalStrengthEvdo.dbm, |
| 3280 | p_cur->CellInfo.cdma.signalStrengthEvdo.ecio, |
| 3281 | p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio); |
| 3282 | |
| 3283 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm); |
| 3284 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio); |
| 3285 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm); |
| 3286 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio); |
| 3287 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio); |
| 3288 | break; |
| 3289 | } |
| 3290 | case RIL_CELL_INFO_TYPE_LTE: { |
| 3291 | appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf, |
| 3292 | p_cur->CellInfo.lte.cellIdentityLte.mcc, |
| 3293 | p_cur->CellInfo.lte.cellIdentityLte.mnc, |
| 3294 | p_cur->CellInfo.lte.cellIdentityLte.ci, |
| 3295 | p_cur->CellInfo.lte.cellIdentityLte.pci, |
| 3296 | p_cur->CellInfo.lte.cellIdentityLte.tac); |
| 3297 | |
| 3298 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc); |
| 3299 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc); |
| 3300 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci); |
| 3301 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci); |
| 3302 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac); |
| 3303 | |
| 3304 | appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf, |
| 3305 | p_cur->CellInfo.lte.signalStrengthLte.signalStrength, |
| 3306 | p_cur->CellInfo.lte.signalStrengthLte.rsrp, |
| 3307 | p_cur->CellInfo.lte.signalStrengthLte.rsrq, |
| 3308 | p_cur->CellInfo.lte.signalStrengthLte.rssnr, |
| 3309 | p_cur->CellInfo.lte.signalStrengthLte.cqi, |
| 3310 | p_cur->CellInfo.lte.signalStrengthLte.timingAdvance); |
| 3311 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength); |
| 3312 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp); |
| 3313 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq); |
| 3314 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr); |
| 3315 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi); |
| 3316 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance); |
| 3317 | break; |
| 3318 | } |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 3319 | case RIL_CELL_INFO_TYPE_TD_SCDMA: { |
| 3320 | appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf, |
| 3321 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc, |
| 3322 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc, |
| 3323 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac, |
| 3324 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid, |
| 3325 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid); |
| 3326 | appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf, |
| 3327 | p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp); |
| 3328 | |
| 3329 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc); |
| 3330 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc); |
| 3331 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac); |
| 3332 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid); |
| 3333 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid); |
| 3334 | p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp); |
| 3335 | break; |
| 3336 | } |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 3337 | } |
| 3338 | p_cur += 1; |
| 3339 | } |
| 3340 | removeLastChar; |
| 3341 | closeResponse; |
| 3342 | |
| 3343 | return 0; |
| 3344 | } |
| 3345 | |
Sanket Padawe | f53c5fa | 2016-01-27 10:00:38 -0800 | [diff] [blame] | 3346 | static int responseCellInfoListV12(Parcel &p, void *response, size_t responselen) { |
| 3347 | if (response == NULL && responselen != 0) { |
| 3348 | RLOGE("invalid response: NULL"); |
| 3349 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3350 | } |
| 3351 | |
| 3352 | if (responselen % sizeof(RIL_CellInfo_v12) != 0) { |
| 3353 | RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d", |
| 3354 | (int)responselen, (int)sizeof(RIL_CellInfo_v12)); |
| 3355 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3356 | } |
| 3357 | |
| 3358 | int num = responselen / sizeof(RIL_CellInfo_v12); |
| 3359 | p.writeInt32(num); |
| 3360 | |
| 3361 | RIL_CellInfo_v12 *p_cur = (RIL_CellInfo_v12 *) response; |
| 3362 | startResponse; |
| 3363 | int i; |
| 3364 | for (i = 0; i < num; i++) { |
| 3365 | appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i, |
| 3366 | p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp); |
| 3367 | RLOGE("[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", i, |
| 3368 | p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp); |
| 3369 | p.writeInt32((int)p_cur->cellInfoType); |
| 3370 | p.writeInt32(p_cur->registered); |
| 3371 | p.writeInt32(p_cur->timeStampType); |
| 3372 | p.writeInt64(p_cur->timeStamp); |
| 3373 | switch(p_cur->cellInfoType) { |
| 3374 | case RIL_CELL_INFO_TYPE_GSM: { |
| 3375 | appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", printBuf, |
| 3376 | p_cur->CellInfo.gsm.cellIdentityGsm.mcc, |
| 3377 | p_cur->CellInfo.gsm.cellIdentityGsm.mnc, |
| 3378 | p_cur->CellInfo.gsm.cellIdentityGsm.lac, |
| 3379 | p_cur->CellInfo.gsm.cellIdentityGsm.cid, |
| 3380 | p_cur->CellInfo.gsm.cellIdentityGsm.arfcn, |
| 3381 | p_cur->CellInfo.gsm.cellIdentityGsm.bsic); |
| 3382 | RLOGE("GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,arfcn=%d,bsic=%x", |
| 3383 | p_cur->CellInfo.gsm.cellIdentityGsm.mcc, |
| 3384 | p_cur->CellInfo.gsm.cellIdentityGsm.mnc, |
| 3385 | p_cur->CellInfo.gsm.cellIdentityGsm.lac, |
| 3386 | p_cur->CellInfo.gsm.cellIdentityGsm.cid, |
| 3387 | p_cur->CellInfo.gsm.cellIdentityGsm.arfcn, |
| 3388 | p_cur->CellInfo.gsm.cellIdentityGsm.bsic); |
| 3389 | RLOGE("gsmSS: ss=%d,ber=%d, ta=%d],", |
| 3390 | p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength, |
| 3391 | p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate, |
| 3392 | p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance); |
| 3393 | appendPrintBuf("%s gsmSS: ss=%d,ber=%d, ta=%d],", printBuf, |
| 3394 | p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength, |
| 3395 | p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate, |
| 3396 | p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance); |
| 3397 | |
| 3398 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc); |
| 3399 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc); |
| 3400 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac); |
| 3401 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid); |
| 3402 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.arfcn); |
| 3403 | p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.bsic); |
| 3404 | p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength); |
| 3405 | p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate); |
| 3406 | p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.timingAdvance); |
| 3407 | break; |
| 3408 | } |
| 3409 | case RIL_CELL_INFO_TYPE_WCDMA: { |
| 3410 | RLOGE("WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", |
| 3411 | p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc, |
| 3412 | p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc, |
| 3413 | p_cur->CellInfo.wcdma.cellIdentityWcdma.lac, |
| 3414 | p_cur->CellInfo.wcdma.cellIdentityWcdma.cid, |
| 3415 | p_cur->CellInfo.wcdma.cellIdentityWcdma.psc, |
| 3416 | p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn); |
| 3417 | RLOGE("wcdmaSS: ss=%d,ber=%d],", |
| 3418 | p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength, |
| 3419 | p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate); |
| 3420 | appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,uarfcn=%d", printBuf, |
| 3421 | p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc, |
| 3422 | p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc, |
| 3423 | p_cur->CellInfo.wcdma.cellIdentityWcdma.lac, |
| 3424 | p_cur->CellInfo.wcdma.cellIdentityWcdma.cid, |
| 3425 | p_cur->CellInfo.wcdma.cellIdentityWcdma.psc, |
| 3426 | p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn); |
| 3427 | appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf, |
| 3428 | p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength, |
| 3429 | p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate); |
| 3430 | |
| 3431 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc); |
| 3432 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc); |
| 3433 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac); |
| 3434 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid); |
| 3435 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc); |
| 3436 | p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.uarfcn); |
| 3437 | p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength); |
| 3438 | p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate); |
| 3439 | break; |
| 3440 | } |
| 3441 | case RIL_CELL_INFO_TYPE_CDMA: { |
| 3442 | RLOGE("CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", |
| 3443 | p_cur->CellInfo.cdma.cellIdentityCdma.networkId, |
| 3444 | p_cur->CellInfo.cdma.cellIdentityCdma.systemId, |
| 3445 | p_cur->CellInfo.cdma.cellIdentityCdma.basestationId, |
| 3446 | p_cur->CellInfo.cdma.cellIdentityCdma.longitude, |
| 3447 | p_cur->CellInfo.cdma.cellIdentityCdma.latitude); |
| 3448 | |
| 3449 | appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf, |
| 3450 | p_cur->CellInfo.cdma.cellIdentityCdma.networkId, |
| 3451 | p_cur->CellInfo.cdma.cellIdentityCdma.systemId, |
| 3452 | p_cur->CellInfo.cdma.cellIdentityCdma.basestationId, |
| 3453 | p_cur->CellInfo.cdma.cellIdentityCdma.longitude, |
| 3454 | p_cur->CellInfo.cdma.cellIdentityCdma.latitude); |
| 3455 | |
| 3456 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId); |
| 3457 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId); |
| 3458 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId); |
| 3459 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude); |
| 3460 | p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude); |
| 3461 | |
| 3462 | RLOGE("cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", |
| 3463 | p_cur->CellInfo.cdma.signalStrengthCdma.dbm, |
| 3464 | p_cur->CellInfo.cdma.signalStrengthCdma.ecio, |
| 3465 | p_cur->CellInfo.cdma.signalStrengthEvdo.dbm, |
| 3466 | p_cur->CellInfo.cdma.signalStrengthEvdo.ecio, |
| 3467 | p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio); |
| 3468 | |
| 3469 | appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf, |
| 3470 | p_cur->CellInfo.cdma.signalStrengthCdma.dbm, |
| 3471 | p_cur->CellInfo.cdma.signalStrengthCdma.ecio, |
| 3472 | p_cur->CellInfo.cdma.signalStrengthEvdo.dbm, |
| 3473 | p_cur->CellInfo.cdma.signalStrengthEvdo.ecio, |
| 3474 | p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio); |
| 3475 | |
| 3476 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm); |
| 3477 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio); |
| 3478 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm); |
| 3479 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio); |
| 3480 | p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio); |
| 3481 | break; |
| 3482 | } |
| 3483 | case RIL_CELL_INFO_TYPE_LTE: { |
| 3484 | RLOGE("LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", |
| 3485 | p_cur->CellInfo.lte.cellIdentityLte.mcc, |
| 3486 | p_cur->CellInfo.lte.cellIdentityLte.mnc, |
| 3487 | p_cur->CellInfo.lte.cellIdentityLte.ci, |
| 3488 | p_cur->CellInfo.lte.cellIdentityLte.pci, |
| 3489 | p_cur->CellInfo.lte.cellIdentityLte.tac, |
| 3490 | p_cur->CellInfo.lte.cellIdentityLte.earfcn); |
| 3491 | |
| 3492 | appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d,earfcn=%d", printBuf, |
| 3493 | p_cur->CellInfo.lte.cellIdentityLte.mcc, |
| 3494 | p_cur->CellInfo.lte.cellIdentityLte.mnc, |
| 3495 | p_cur->CellInfo.lte.cellIdentityLte.ci, |
| 3496 | p_cur->CellInfo.lte.cellIdentityLte.pci, |
| 3497 | p_cur->CellInfo.lte.cellIdentityLte.tac, |
| 3498 | p_cur->CellInfo.lte.cellIdentityLte.earfcn); |
| 3499 | |
| 3500 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc); |
| 3501 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc); |
| 3502 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci); |
| 3503 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci); |
| 3504 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac); |
| 3505 | p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.earfcn); |
| 3506 | |
| 3507 | RLOGE("lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", |
| 3508 | p_cur->CellInfo.lte.signalStrengthLte.signalStrength, |
| 3509 | p_cur->CellInfo.lte.signalStrengthLte.rsrp, |
| 3510 | p_cur->CellInfo.lte.signalStrengthLte.rsrq, |
| 3511 | p_cur->CellInfo.lte.signalStrengthLte.rssnr, |
| 3512 | p_cur->CellInfo.lte.signalStrengthLte.cqi, |
| 3513 | p_cur->CellInfo.lte.signalStrengthLte.timingAdvance); |
| 3514 | appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf, |
| 3515 | p_cur->CellInfo.lte.signalStrengthLte.signalStrength, |
| 3516 | p_cur->CellInfo.lte.signalStrengthLte.rsrp, |
| 3517 | p_cur->CellInfo.lte.signalStrengthLte.rsrq, |
| 3518 | p_cur->CellInfo.lte.signalStrengthLte.rssnr, |
| 3519 | p_cur->CellInfo.lte.signalStrengthLte.cqi, |
| 3520 | p_cur->CellInfo.lte.signalStrengthLte.timingAdvance); |
| 3521 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength); |
| 3522 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp); |
| 3523 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq); |
| 3524 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr); |
| 3525 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi); |
| 3526 | p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance); |
| 3527 | break; |
| 3528 | } |
| 3529 | case RIL_CELL_INFO_TYPE_TD_SCDMA: { |
| 3530 | appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf, |
| 3531 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc, |
| 3532 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc, |
| 3533 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac, |
| 3534 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid, |
| 3535 | p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid); |
| 3536 | appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf, |
| 3537 | p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp); |
| 3538 | |
| 3539 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc); |
| 3540 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc); |
| 3541 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac); |
| 3542 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid); |
| 3543 | p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid); |
| 3544 | p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp); |
| 3545 | break; |
| 3546 | } |
| 3547 | } |
| 3548 | p_cur += 1; |
| 3549 | } |
| 3550 | removeLastChar; |
| 3551 | closeResponse; |
| 3552 | return 0; |
| 3553 | } |
| 3554 | |
| 3555 | static int responseCellInfoList(Parcel &p, void *response, size_t responselen) |
| 3556 | { |
| 3557 | if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) { |
| 3558 | if (s_callbacks.version < 12) { |
| 3559 | RLOGD("responseCellInfoList: v6"); |
| 3560 | return responseCellInfoListV6(p, response, responselen); |
| 3561 | } else { |
| 3562 | RLOGD("responseCellInfoList: v12"); |
| 3563 | return responseCellInfoListV12(p, response, responselen); |
| 3564 | } |
| 3565 | } else { // RIL version >= 13 |
| 3566 | if (responselen % sizeof(RIL_CellInfo_v12) != 0) { |
| 3567 | RLOGE("Data structure expected is RIL_CellInfo_v12"); |
| 3568 | if (!isDebuggable()) { |
| 3569 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3570 | } else { |
| 3571 | assert(0); |
| 3572 | } |
| 3573 | } |
| 3574 | return responseCellInfoListV12(p, response, responselen); |
| 3575 | } |
| 3576 | |
| 3577 | return 0; |
| 3578 | } |
| 3579 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 3580 | static int responseHardwareConfig(Parcel &p, void *response, size_t responselen) |
| 3581 | { |
| 3582 | if (response == NULL && responselen != 0) { |
| 3583 | RLOGE("invalid response: NULL"); |
| 3584 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3585 | } |
| 3586 | |
| 3587 | if (responselen % sizeof(RIL_HardwareConfig) != 0) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 3588 | RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d", |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 3589 | (int)responselen, (int)sizeof(RIL_HardwareConfig)); |
| 3590 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3591 | } |
| 3592 | |
| 3593 | int num = responselen / sizeof(RIL_HardwareConfig); |
| 3594 | int i; |
| 3595 | RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response; |
| 3596 | |
| 3597 | p.writeInt32(num); |
| 3598 | |
| 3599 | startResponse; |
| 3600 | for (i = 0; i < num; i++) { |
| 3601 | switch (p_cur[i].type) { |
| 3602 | case RIL_HARDWARE_CONFIG_MODEM: { |
| 3603 | writeStringToParcel(p, p_cur[i].uuid); |
| 3604 | p.writeInt32((int)p_cur[i].state); |
| 3605 | p.writeInt32(p_cur[i].cfg.modem.rat); |
| 3606 | p.writeInt32(p_cur[i].cfg.modem.maxVoice); |
| 3607 | p.writeInt32(p_cur[i].cfg.modem.maxData); |
| 3608 | p.writeInt32(p_cur[i].cfg.modem.maxStandby); |
| 3609 | |
| 3610 | appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf, |
| 3611 | p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat, |
| 3612 | p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby); |
| 3613 | break; |
| 3614 | } |
| 3615 | case RIL_HARDWARE_CONFIG_SIM: { |
| 3616 | writeStringToParcel(p, p_cur[i].uuid); |
| 3617 | p.writeInt32((int)p_cur[i].state); |
| 3618 | writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid); |
| 3619 | |
| 3620 | appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf, |
| 3621 | p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid); |
| 3622 | break; |
| 3623 | } |
| 3624 | } |
| 3625 | } |
| 3626 | removeLastChar; |
| 3627 | closeResponse; |
| 3628 | return 0; |
| 3629 | } |
| 3630 | |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 3631 | static int responseRadioCapability(Parcel &p, void *response, size_t responselen) { |
| 3632 | if (response == NULL) { |
| 3633 | RLOGE("invalid response: NULL"); |
| 3634 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3635 | } |
| 3636 | |
| 3637 | if (responselen != sizeof (RIL_RadioCapability) ) { |
| 3638 | RLOGE("invalid response length was %d expected %d", |
| 3639 | (int)responselen, (int)sizeof (RIL_SIM_IO_Response)); |
| 3640 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3641 | } |
| 3642 | |
| 3643 | RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response; |
| 3644 | p.writeInt32(p_cur->version); |
| 3645 | p.writeInt32(p_cur->session); |
| 3646 | p.writeInt32(p_cur->phase); |
| 3647 | p.writeInt32(p_cur->rat); |
| 3648 | writeStringToParcel(p, p_cur->logicalModemUuid); |
| 3649 | p.writeInt32(p_cur->status); |
| 3650 | |
| 3651 | startResponse; |
| 3652 | appendPrintBuf("%s[version=%d,session=%d,phase=%d,\ |
Legler Wu | 8caf06f | 2014-10-29 14:02:14 +0800 | [diff] [blame] | 3653 | rat=%s,logicalModemUuid=%s,status=%d]", |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 3654 | printBuf, |
| 3655 | p_cur->version, |
| 3656 | p_cur->session, |
| 3657 | p_cur->phase, |
| 3658 | p_cur->rat, |
Legler Wu | 8caf06f | 2014-10-29 14:02:14 +0800 | [diff] [blame] | 3659 | p_cur->logicalModemUuid, |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 3660 | p_cur->status); |
| 3661 | closeResponse; |
| 3662 | return 0; |
| 3663 | } |
| 3664 | |
Amit Mahajan | 54563d3 | 2014-11-22 00:54:49 +0000 | [diff] [blame] | 3665 | static int responseSSData(Parcel &p, void *response, size_t responselen) { |
| 3666 | RLOGD("In responseSSData"); |
| 3667 | int num; |
| 3668 | |
| 3669 | if (response == NULL && responselen != 0) { |
| 3670 | RLOGE("invalid response length was %d expected %d", |
| 3671 | (int)responselen, (int)sizeof (RIL_SIM_IO_Response)); |
| 3672 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3673 | } |
| 3674 | |
| 3675 | if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) { |
| 3676 | RLOGE("invalid response length %d, expected %d", |
| 3677 | (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse)); |
| 3678 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3679 | } |
| 3680 | |
| 3681 | startResponse; |
| 3682 | RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response; |
| 3683 | p.writeInt32(p_cur->serviceType); |
| 3684 | p.writeInt32(p_cur->requestType); |
| 3685 | p.writeInt32(p_cur->teleserviceType); |
| 3686 | p.writeInt32(p_cur->serviceClass); |
| 3687 | p.writeInt32(p_cur->result); |
| 3688 | |
| 3689 | if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) { |
| 3690 | RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes); |
| 3691 | if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) { |
| 3692 | RLOGE("numValidIndexes is greater than max value %d, " |
| 3693 | "truncating it to max value", NUM_SERVICE_CLASSES); |
| 3694 | p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES; |
| 3695 | } |
| 3696 | /* number of call info's */ |
| 3697 | p.writeInt32(p_cur->cfData.numValidIndexes); |
| 3698 | |
| 3699 | for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) { |
| 3700 | RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i]; |
| 3701 | |
| 3702 | p.writeInt32(cf.status); |
| 3703 | p.writeInt32(cf.reason); |
| 3704 | p.writeInt32(cf.serviceClass); |
| 3705 | p.writeInt32(cf.toa); |
| 3706 | writeStringToParcel(p, cf.number); |
| 3707 | p.writeInt32(cf.timeSeconds); |
| 3708 | appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf, |
| 3709 | (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa, |
| 3710 | (char*)cf.number, cf.timeSeconds); |
| 3711 | RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status, |
| 3712 | cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds); |
| 3713 | } |
| 3714 | } else { |
| 3715 | p.writeInt32 (SS_INFO_MAX); |
| 3716 | |
| 3717 | /* each int*/ |
| 3718 | for (int i = 0; i < SS_INFO_MAX; i++) { |
| 3719 | appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]); |
| 3720 | RLOGD("Data: %d",p_cur->ssInfo[i]); |
| 3721 | p.writeInt32(p_cur->ssInfo[i]); |
| 3722 | } |
| 3723 | } |
| 3724 | removeLastChar; |
| 3725 | closeResponse; |
| 3726 | |
| 3727 | return 0; |
| 3728 | } |
| 3729 | |
| 3730 | static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) { |
| 3731 | if ((reqType == SS_INTERROGATION) && |
| 3732 | (serType == SS_CFU || |
| 3733 | serType == SS_CF_BUSY || |
| 3734 | serType == SS_CF_NO_REPLY || |
| 3735 | serType == SS_CF_NOT_REACHABLE || |
| 3736 | serType == SS_CF_ALL || |
| 3737 | serType == SS_CF_ALL_CONDITIONAL)) { |
| 3738 | return true; |
| 3739 | } |
| 3740 | return false; |
| 3741 | } |
| 3742 | |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3743 | static void triggerEvLoop() { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3744 | int ret; |
| 3745 | if (!pthread_equal(pthread_self(), s_tid_dispatch)) { |
| 3746 | /* trigger event loop to wakeup. No reason to do this, |
| 3747 | * if we're in the event loop thread */ |
| 3748 | do { |
| 3749 | ret = write (s_fdWakeupWrite, " ", 1); |
| 3750 | } while (ret < 0 && errno == EINTR); |
| 3751 | } |
| 3752 | } |
| 3753 | |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3754 | static void rilEventAddWakeup(struct ril_event *ev) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3755 | ril_event_add(ev); |
| 3756 | triggerEvLoop(); |
| 3757 | } |
| 3758 | |
Wink Saville | fd72937 | 2011-02-22 16:19:39 -0800 | [diff] [blame] | 3759 | static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) { |
| 3760 | p.writeInt32(num_apps); |
| 3761 | startResponse; |
| 3762 | for (int i = 0; i < num_apps; i++) { |
| 3763 | p.writeInt32(appStatus[i].app_type); |
| 3764 | p.writeInt32(appStatus[i].app_state); |
| 3765 | p.writeInt32(appStatus[i].perso_substate); |
| 3766 | writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr)); |
| 3767 | writeStringToParcel(p, (const char*) |
| 3768 | (appStatus[i].app_label_ptr)); |
| 3769 | p.writeInt32(appStatus[i].pin1_replaced); |
| 3770 | p.writeInt32(appStatus[i].pin1); |
| 3771 | p.writeInt32(appStatus[i].pin2); |
| 3772 | appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\ |
| 3773 | aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],", |
| 3774 | printBuf, |
| 3775 | appStatus[i].app_type, |
| 3776 | appStatus[i].app_state, |
| 3777 | appStatus[i].perso_substate, |
| 3778 | appStatus[i].aid_ptr, |
| 3779 | appStatus[i].app_label_ptr, |
| 3780 | appStatus[i].pin1_replaced, |
| 3781 | appStatus[i].pin1, |
| 3782 | appStatus[i].pin2); |
| 3783 | } |
| 3784 | closeResponse; |
| 3785 | } |
| 3786 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3787 | static void responseSimStatusV5(Parcel &p, void *response) { |
| 3788 | RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response); |
| 3789 | |
| 3790 | p.writeInt32(p_cur->card_state); |
| 3791 | p.writeInt32(p_cur->universal_pin_state); |
| 3792 | p.writeInt32(p_cur->gsm_umts_subscription_app_index); |
| 3793 | p.writeInt32(p_cur->cdma_subscription_app_index); |
| 3794 | |
| 3795 | sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications); |
| 3796 | } |
| 3797 | |
| 3798 | static void responseSimStatusV6(Parcel &p, void *response) { |
| 3799 | RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response); |
| 3800 | |
| 3801 | p.writeInt32(p_cur->card_state); |
| 3802 | p.writeInt32(p_cur->universal_pin_state); |
| 3803 | p.writeInt32(p_cur->gsm_umts_subscription_app_index); |
| 3804 | p.writeInt32(p_cur->cdma_subscription_app_index); |
| 3805 | p.writeInt32(p_cur->ims_subscription_app_index); |
| 3806 | |
| 3807 | sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications); |
| 3808 | } |
| 3809 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3810 | static int responseSimStatus(Parcel &p, void *response, size_t responselen) { |
| 3811 | int i; |
| 3812 | |
| 3813 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3814 | RLOGE("invalid response: NULL"); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3815 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3816 | } |
| 3817 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3818 | if (s_callbacks.version <= LAST_IMPRECISE_RIL_VERSION) { |
| 3819 | if (responselen == sizeof (RIL_CardStatus_v6)) { |
| 3820 | responseSimStatusV6(p, response); |
| 3821 | } else if (responselen == sizeof (RIL_CardStatus_v5)) { |
| 3822 | responseSimStatusV5(p, response); |
| 3823 | } else { |
| 3824 | RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n"); |
| 3825 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3826 | } |
Sanket Padawe | f53c5fa | 2016-01-27 10:00:38 -0800 | [diff] [blame] | 3827 | } else { // RIL version >= 13 |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 3828 | if (responselen % sizeof(RIL_CardStatus_v6) != 0) { |
| 3829 | RLOGE("Data structure expected is RIL_CardStatus_v6"); |
| 3830 | if (!isDebuggable()) { |
| 3831 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3832 | } else { |
| 3833 | assert(0); |
| 3834 | } |
| 3835 | } |
| 3836 | responseSimStatusV6(p, response); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3837 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3838 | |
| 3839 | return 0; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 3840 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3841 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 3842 | static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) { |
| 3843 | int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3844 | p.writeInt32(num); |
| 3845 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3846 | startResponse; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 3847 | RIL_GSM_BroadcastSmsConfigInfo **p_cur = |
| 3848 | (RIL_GSM_BroadcastSmsConfigInfo **) response; |
| 3849 | for (int i = 0; i < num; i++) { |
| 3850 | p.writeInt32(p_cur[i]->fromServiceId); |
| 3851 | p.writeInt32(p_cur[i]->toServiceId); |
| 3852 | p.writeInt32(p_cur[i]->fromCodeScheme); |
| 3853 | p.writeInt32(p_cur[i]->toCodeScheme); |
| 3854 | p.writeInt32(p_cur[i]->selected); |
| 3855 | |
| 3856 | appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \ |
| 3857 | fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", |
| 3858 | printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId, |
| 3859 | p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme, |
| 3860 | p_cur[i]->selected); |
| 3861 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3862 | closeResponse; |
| 3863 | |
| 3864 | return 0; |
| 3865 | } |
| 3866 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 3867 | static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) { |
| 3868 | RIL_CDMA_BroadcastSmsConfigInfo **p_cur = |
| 3869 | (RIL_CDMA_BroadcastSmsConfigInfo **) response; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3870 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 3871 | int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *); |
| 3872 | p.writeInt32(num); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3873 | |
| 3874 | startResponse; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 3875 | for (int i = 0 ; i < num ; i++ ) { |
| 3876 | p.writeInt32(p_cur[i]->service_category); |
| 3877 | p.writeInt32(p_cur[i]->language); |
| 3878 | p.writeInt32(p_cur[i]->selected); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3879 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 3880 | appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \ |
| 3881 | selected =%d], ", |
| 3882 | printBuf, i, p_cur[i]->service_category, p_cur[i]->language, |
| 3883 | p_cur[i]->selected); |
Wink Saville | f5903df | 2009-04-24 11:54:14 -0700 | [diff] [blame] | 3884 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 3885 | closeResponse; |
Wink Saville | f5903df | 2009-04-24 11:54:14 -0700 | [diff] [blame] | 3886 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3887 | return 0; |
| 3888 | } |
| 3889 | |
| 3890 | static int responseCdmaSms(Parcel &p, void *response, size_t responselen) { |
| 3891 | int num; |
| 3892 | int digitCount; |
| 3893 | int digitLimit; |
| 3894 | uint8_t uct; |
| 3895 | void* dest; |
| 3896 | |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3897 | RLOGD("Inside responseCdmaSms"); |
Wink Saville | f5903df | 2009-04-24 11:54:14 -0700 | [diff] [blame] | 3898 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3899 | if (response == NULL && responselen != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3900 | RLOGE("invalid response: NULL"); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3901 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3902 | } |
| 3903 | |
Wink Saville | f5903df | 2009-04-24 11:54:14 -0700 | [diff] [blame] | 3904 | if (responselen != sizeof(RIL_CDMA_SMS_Message)) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3905 | RLOGE("invalid response length was %d expected %d", |
Wink Saville | f5903df | 2009-04-24 11:54:14 -0700 | [diff] [blame] | 3906 | (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3907 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3908 | } |
| 3909 | |
| 3910 | RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response; |
| 3911 | p.writeInt32(p_cur->uTeleserviceID); |
| 3912 | p.write(&(p_cur->bIsServicePresent),sizeof(uct)); |
| 3913 | p.writeInt32(p_cur->uServicecategory); |
| 3914 | p.writeInt32(p_cur->sAddress.digit_mode); |
| 3915 | p.writeInt32(p_cur->sAddress.number_mode); |
| 3916 | p.writeInt32(p_cur->sAddress.number_type); |
| 3917 | p.writeInt32(p_cur->sAddress.number_plan); |
| 3918 | p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct)); |
| 3919 | digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX); |
| 3920 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 3921 | p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct)); |
| 3922 | } |
| 3923 | |
| 3924 | p.writeInt32(p_cur->sSubAddress.subaddressType); |
| 3925 | p.write(&(p_cur->sSubAddress.odd),sizeof(uct)); |
| 3926 | p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct)); |
| 3927 | digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX); |
| 3928 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 3929 | p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct)); |
| 3930 | } |
| 3931 | |
| 3932 | digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX); |
| 3933 | p.writeInt32(p_cur->uBearerDataLen); |
| 3934 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 3935 | p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct)); |
| 3936 | } |
| 3937 | |
| 3938 | startResponse; |
| 3939 | appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \ |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 3940 | sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ", |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3941 | printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory, |
| 3942 | p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type); |
| 3943 | closeResponse; |
| 3944 | |
| 3945 | return 0; |
| 3946 | } |
| 3947 | |
Wink Saville | c29360a | 2014-07-13 05:17:28 -0700 | [diff] [blame] | 3948 | static int responseDcRtInfo(Parcel &p, void *response, size_t responselen) |
| 3949 | { |
| 3950 | int num = responselen / sizeof(RIL_DcRtInfo); |
| 3951 | if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) { |
Amit Mahajan | 5250016 | 2014-07-29 17:36:48 -0700 | [diff] [blame] | 3952 | RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d", |
Wink Saville | c29360a | 2014-07-13 05:17:28 -0700 | [diff] [blame] | 3953 | (int)responselen, (int)sizeof(RIL_DcRtInfo)); |
| 3954 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3955 | } |
| 3956 | |
| 3957 | startResponse; |
| 3958 | RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response; |
| 3959 | p.writeInt64(pDcRtInfo->time); |
| 3960 | p.writeInt32(pDcRtInfo->powerState); |
| 3961 | appendPrintBuf("%s[time=%d,powerState=%d]", printBuf, |
| 3962 | pDcRtInfo->time, |
| 3963 | pDcRtInfo->powerState); |
| 3964 | closeResponse; |
| 3965 | |
| 3966 | return 0; |
| 3967 | } |
| 3968 | |
fenglu | f740829 | 2015-04-14 14:53:55 -0700 | [diff] [blame] | 3969 | static int responseLceStatus(Parcel &p, void *response, size_t responselen) { |
| 3970 | if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) { |
| 3971 | if (response == NULL) { |
| 3972 | RLOGE("invalid response: NULL"); |
| 3973 | } |
| 3974 | else { |
| 3975 | RLOGE("responseLceStatus: invalid response length %d expecting len: d%", |
| 3976 | sizeof(RIL_LceStatusInfo), responselen); |
| 3977 | } |
| 3978 | return RIL_ERRNO_INVALID_RESPONSE; |
| 3979 | } |
| 3980 | |
| 3981 | RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response; |
| 3982 | p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte. |
| 3983 | p.writeInt32(p_cur->actual_interval_ms); |
| 3984 | |
| 3985 | startResponse; |
| 3986 | appendPrintBuf("LCE Status: %d, actual_interval_ms: %d", |
| 3987 | p_cur->lce_status, p_cur->actual_interval_ms); |
| 3988 | closeResponse; |
| 3989 | |
| 3990 | return 0; |
| 3991 | } |
| 3992 | |
| 3993 | static int responseLceData(Parcel &p, void *response, size_t responselen) { |
| 3994 | if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) { |
| 3995 | if (response == NULL) { |
| 3996 | RLOGE("invalid response: NULL"); |
| 3997 | } |
| 3998 | else { |
| 3999 | RLOGE("responseLceData: invalid response length %d expecting len: d%", |
| 4000 | sizeof(RIL_LceDataInfo), responselen); |
| 4001 | } |
| 4002 | return RIL_ERRNO_INVALID_RESPONSE; |
| 4003 | } |
| 4004 | |
| 4005 | RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response; |
| 4006 | p.writeInt32(p_cur->last_hop_capacity_kbps); |
| 4007 | |
| 4008 | /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/ |
| 4009 | p.write((void *)&(p_cur->confidence_level), 1); |
| 4010 | p.write((void *)&(p_cur->lce_suspended), 1); |
| 4011 | |
| 4012 | startResponse; |
| 4013 | appendPrintBuf("LCE info received: capacity %d confidence level %d |
| 4014 | and suspended %d", |
| 4015 | p_cur->last_hop_capacity_kbps, p_cur->confidence_level, |
| 4016 | p_cur->lce_suspended); |
| 4017 | closeResponse; |
| 4018 | |
| 4019 | return 0; |
| 4020 | } |
| 4021 | |
Prerepa Viswanadham | 7315749 | 2015-05-28 00:37:32 -0700 | [diff] [blame] | 4022 | static int responseActivityData(Parcel &p, void *response, size_t responselen) { |
| 4023 | if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) { |
| 4024 | if (response == NULL) { |
| 4025 | RLOGE("invalid response: NULL"); |
| 4026 | } |
| 4027 | else { |
| 4028 | RLOGE("responseActivityData: invalid response length %d expecting len: d%", |
| 4029 | sizeof(RIL_ActivityStatsInfo), responselen); |
| 4030 | } |
| 4031 | return RIL_ERRNO_INVALID_RESPONSE; |
| 4032 | } |
| 4033 | |
| 4034 | RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response; |
| 4035 | p.writeInt32(p_cur->sleep_mode_time_ms); |
| 4036 | p.writeInt32(p_cur->idle_mode_time_ms); |
| 4037 | for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) { |
| 4038 | p.writeInt32(p_cur->tx_mode_time_ms[i]); |
| 4039 | } |
| 4040 | p.writeInt32(p_cur->rx_mode_time_ms); |
| 4041 | |
| 4042 | startResponse; |
| 4043 | appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d |
| 4044 | tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d", |
| 4045 | p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0], |
| 4046 | p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3], |
| 4047 | p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms); |
| 4048 | closeResponse; |
| 4049 | |
| 4050 | return 0; |
| 4051 | } |
| 4052 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4053 | /** |
| 4054 | * A write on the wakeup fd is done just to pop us out of select() |
| 4055 | * We empty the buffer here and then ril_event will reset the timers on the |
| 4056 | * way back down |
| 4057 | */ |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4058 | static void processWakeupCallback(int fd, short flags, void *param) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4059 | char buff[16]; |
| 4060 | int ret; |
| 4061 | |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4062 | RLOGV("processWakeupCallback"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4063 | |
| 4064 | /* empty our wakeup socket out */ |
| 4065 | do { |
| 4066 | ret = read(s_fdWakeupRead, &buff, sizeof(buff)); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4067 | } while (ret > 0 || (ret < 0 && errno == EINTR)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4068 | } |
| 4069 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4070 | static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4071 | int ret; |
| 4072 | RequestInfo *p_cur; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4073 | /* Hook for current context |
| 4074 | pendingRequestsMutextHook refer to &s_pendingRequestsMutex */ |
| 4075 | pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex; |
| 4076 | /* pendingRequestsHook refer to &s_pendingRequests */ |
| 4077 | RequestInfo ** pendingRequestsHook = &s_pendingRequests; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4078 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4079 | #if (SIM_COUNT >= 2) |
| 4080 | if (socket_id == RIL_SOCKET_2) { |
| 4081 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2; |
| 4082 | pendingRequestsHook = &s_pendingRequests_socket2; |
| 4083 | } |
| 4084 | #if (SIM_COUNT >= 3) |
| 4085 | else if (socket_id == RIL_SOCKET_3) { |
| 4086 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3; |
| 4087 | pendingRequestsHook = &s_pendingRequests_socket3; |
| 4088 | } |
| 4089 | #endif |
| 4090 | #if (SIM_COUNT >= 4) |
| 4091 | else if (socket_id == RIL_SOCKET_4) { |
| 4092 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4; |
| 4093 | pendingRequestsHook = &s_pendingRequests_socket4; |
| 4094 | } |
| 4095 | #endif |
| 4096 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4097 | /* mark pending requests as "cancelled" so we dont report responses */ |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4098 | ret = pthread_mutex_lock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4099 | assert (ret == 0); |
| 4100 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4101 | p_cur = *pendingRequestsHook; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4102 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4103 | for (p_cur = *pendingRequestsHook |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4104 | ; p_cur != NULL |
| 4105 | ; p_cur = p_cur->p_next |
| 4106 | ) { |
| 4107 | p_cur->cancelled = 1; |
| 4108 | } |
| 4109 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4110 | ret = pthread_mutex_unlock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4111 | assert (ret == 0); |
| 4112 | } |
| 4113 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4114 | static void processCommandsCallback(int fd, short flags, void *param) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4115 | RecordStream *p_rs; |
| 4116 | void *p_record; |
| 4117 | size_t recordlen; |
| 4118 | int ret; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4119 | SocketListenParam *p_info = (SocketListenParam *)param; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4120 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4121 | assert(fd == p_info->fdCommand); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4122 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4123 | p_rs = p_info->p_rs; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4124 | |
| 4125 | for (;;) { |
| 4126 | /* loop until EAGAIN/EINTR, end of stream, or other error */ |
| 4127 | ret = record_stream_get_next(p_rs, &p_record, &recordlen); |
| 4128 | |
| 4129 | if (ret == 0 && p_record == NULL) { |
| 4130 | /* end-of-stream */ |
| 4131 | break; |
| 4132 | } else if (ret < 0) { |
| 4133 | break; |
| 4134 | } else if (ret == 0) { /* && p_record != NULL */ |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4135 | processCommandBuffer(p_record, recordlen, p_info->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) { |
| 4140 | /* fatal error or end-of-stream */ |
| 4141 | if (ret != 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4142 | RLOGE("error on reading command socket errno:%d\n", errno); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4143 | } else { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4144 | RLOGW("EOS. Closing command socket."); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4145 | } |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4146 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4147 | close(fd); |
| 4148 | p_info->fdCommand = -1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4149 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4150 | ril_event_del(p_info->commands_event); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4151 | |
| 4152 | record_stream_free(p_rs); |
| 4153 | |
| 4154 | /* start listening for new connections again */ |
| 4155 | rilEventAddWakeup(&s_listen_event); |
| 4156 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4157 | onCommandsSocketClosed(p_info->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4162 | static void onNewCommandConnect(RIL_SOCKET_ID socket_id) { |
Wink Saville | 5b9df33 | 2011-04-06 16:24:21 -0700 | [diff] [blame] | 4163 | // Inform we are connected and the ril version |
Jake Hamby | a9c18d1 | 2011-04-12 23:32:08 -0700 | [diff] [blame] | 4164 | int rilVer = s_callbacks.version; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4165 | RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED, |
| 4166 | &rilVer, sizeof(rilVer), socket_id); |
Wink Saville | 5b9df33 | 2011-04-06 16:24:21 -0700 | [diff] [blame] | 4167 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4168 | // implicit radio state changed |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4169 | RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, |
| 4170 | NULL, 0, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4171 | |
| 4172 | // Send last NITZ time data, in case it was missed |
| 4173 | if (s_lastNITZTimeData != NULL) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4174 | sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4175 | |
| 4176 | free(s_lastNITZTimeData); |
| 4177 | s_lastNITZTimeData = NULL; |
| 4178 | } |
| 4179 | |
| 4180 | // Get version string |
| 4181 | if (s_callbacks.getVersion != NULL) { |
| 4182 | const char *version; |
| 4183 | version = s_callbacks.getVersion(); |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4184 | RLOGI("RIL Daemon version: %s\n", version); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4185 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4186 | property_set(PROPERTY_RIL_IMPL, version); |
| 4187 | } else { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4188 | RLOGI("RIL Daemon version: unavailable\n"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4189 | property_set(PROPERTY_RIL_IMPL, "unavailable"); |
| 4190 | } |
| 4191 | |
| 4192 | } |
| 4193 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4194 | static void listenCallback (int fd, short flags, void *param) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4195 | int ret; |
| 4196 | int err; |
| 4197 | int is_phone_socket; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4198 | int fdCommand = -1; |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4199 | char* processName; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4200 | RecordStream *p_rs; |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4201 | MySocketListenParam* listenParam; |
| 4202 | RilSocket *sapSocket = NULL; |
| 4203 | socketClient *sClient = NULL; |
| 4204 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4205 | SocketListenParam *p_info = (SocketListenParam *)param; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4206 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4207 | if(RIL_SAP_SOCKET == p_info->type) { |
| 4208 | listenParam = (MySocketListenParam *)param; |
| 4209 | sapSocket = listenParam->socket; |
| 4210 | } |
| 4211 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4212 | struct sockaddr_un peeraddr; |
| 4213 | socklen_t socklen = sizeof (peeraddr); |
| 4214 | |
| 4215 | struct ucred creds; |
| 4216 | socklen_t szCreds = sizeof(creds); |
| 4217 | |
| 4218 | struct passwd *pwd = NULL; |
| 4219 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4220 | if(NULL == sapSocket) { |
| 4221 | assert (*p_info->fdCommand < 0); |
| 4222 | assert (fd == *p_info->fdListen); |
| 4223 | processName = PHONE_PROCESS; |
| 4224 | } else { |
| 4225 | assert (sapSocket->commandFd < 0); |
| 4226 | assert (fd == sapSocket->listenFd); |
| 4227 | processName = BLUETOOTH_PROCESS; |
| 4228 | } |
| 4229 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4230 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4231 | fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4232 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4233 | if (fdCommand < 0 ) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4234 | RLOGE("Error on accept() errno:%d", errno); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4235 | /* start listening for new connections again */ |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4236 | if(NULL == sapSocket) { |
| 4237 | rilEventAddWakeup(p_info->listen_event); |
| 4238 | } else { |
| 4239 | rilEventAddWakeup(sapSocket->getListenEvent()); |
| 4240 | } |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4241 | return; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | /* check the credential of the other side and only accept socket from |
| 4245 | * phone process |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4246 | */ |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4247 | errno = 0; |
| 4248 | is_phone_socket = 0; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4249 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4250 | err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4251 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4252 | if (err == 0 && szCreds > 0) { |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4253 | errno = 0; |
| 4254 | pwd = getpwuid(creds.uid); |
| 4255 | if (pwd != NULL) { |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4256 | if (strcmp(pwd->pw_name, processName) == 0) { |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4257 | is_phone_socket = 1; |
| 4258 | } else { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4259 | RLOGE("RILD can't accept socket from process %s", pwd->pw_name); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4260 | } |
| 4261 | } else { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4262 | RLOGE("Error on getpwuid() errno: %d", errno); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4263 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4264 | } else { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4265 | RLOGD("Error on getsockopt() errno: %d", errno); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4266 | } |
| 4267 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4268 | if (!is_phone_socket) { |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4269 | RLOGE("RILD must accept socket from %s", processName); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4270 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4271 | close(fdCommand); |
| 4272 | fdCommand = -1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4273 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4274 | if(NULL == sapSocket) { |
| 4275 | onCommandsSocketClosed(p_info->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4276 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4277 | /* start listening for new connections again */ |
| 4278 | rilEventAddWakeup(p_info->listen_event); |
| 4279 | } else { |
| 4280 | sapSocket->onCommandsSocketClosed(); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4281 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4282 | /* start listening for new connections again */ |
| 4283 | rilEventAddWakeup(sapSocket->getListenEvent()); |
| 4284 | } |
| 4285 | |
| 4286 | return; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4287 | } |
| 4288 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4289 | ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4290 | |
| 4291 | if (ret < 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4292 | RLOGE ("Error setting O_NONBLOCK errno:%d", errno); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4293 | } |
| 4294 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4295 | if(NULL == sapSocket) { |
| 4296 | RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4297 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4298 | p_info->fdCommand = fdCommand; |
| 4299 | p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES); |
| 4300 | p_info->p_rs = p_rs; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4301 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4302 | ril_event_set (p_info->commands_event, p_info->fdCommand, 1, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4303 | p_info->processCommandsCallback, p_info); |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4304 | rilEventAddWakeup (p_info->commands_event); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4305 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4306 | onNewCommandConnect(p_info->socket_id); |
| 4307 | } else { |
| 4308 | RLOGI("libril: new connection"); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4309 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4310 | sapSocket->setCommandFd(fdCommand); |
| 4311 | p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES); |
| 4312 | sClient = new socketClient(sapSocket,p_rs); |
| 4313 | ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1, |
| 4314 | sapSocket->getCommandCb(), sClient); |
| 4315 | |
| 4316 | rilEventAddWakeup(sapSocket->getCallbackEvent()); |
| 4317 | sapSocket->onNewCommandConnect(); |
| 4318 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | static void freeDebugCallbackArgs(int number, char **args) { |
| 4322 | for (int i = 0; i < number; i++) { |
| 4323 | if (args[i] != NULL) { |
| 4324 | free(args[i]); |
| 4325 | } |
| 4326 | } |
| 4327 | free(args); |
| 4328 | } |
| 4329 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4330 | static void debugCallback (int fd, short flags, void *param) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4331 | int acceptFD, option; |
| 4332 | struct sockaddr_un peeraddr; |
| 4333 | socklen_t socklen = sizeof (peeraddr); |
| 4334 | int data; |
| 4335 | unsigned int qxdm_data[6]; |
| 4336 | const char *deactData[1] = {"1"}; |
| 4337 | char *actData[1]; |
| 4338 | RIL_Dial dialData; |
| 4339 | int hangupData[1] = {1}; |
| 4340 | int number; |
| 4341 | char **args; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4342 | RIL_SOCKET_ID socket_id = RIL_SOCKET_1; |
| 4343 | int sim_id = 0; |
| 4344 | |
| 4345 | RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4346 | |
| 4347 | acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen); |
| 4348 | |
| 4349 | if (acceptFD < 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4350 | RLOGE ("error accepting on debug port: %d\n", errno); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4351 | return; |
| 4352 | } |
| 4353 | |
| 4354 | if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4355 | RLOGE ("error reading on socket: number of Args: \n"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4356 | return; |
| 4357 | } |
| 4358 | args = (char **) malloc(sizeof(char*) * number); |
| 4359 | |
| 4360 | for (int i = 0; i < number; i++) { |
| 4361 | int len; |
| 4362 | if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4363 | RLOGE ("error reading on socket: Len of Args: \n"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4364 | freeDebugCallbackArgs(i, args); |
| 4365 | return; |
| 4366 | } |
| 4367 | // +1 for null-term |
| 4368 | args[i] = (char *) malloc((sizeof(char) * len) + 1); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4369 | if (recv(acceptFD, args[i], sizeof(char) * len, 0) |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 4370 | != (int)sizeof(char) * len) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4371 | RLOGE ("error reading on socket: Args[%d] \n", i); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4372 | freeDebugCallbackArgs(i, args); |
| 4373 | return; |
| 4374 | } |
| 4375 | char * buf = args[i]; |
| 4376 | buf[len] = 0; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4377 | if ((i+1) == number) { |
| 4378 | /* The last argument should be sim id 0(SIM1)~3(SIM4) */ |
| 4379 | sim_id = atoi(args[i]); |
| 4380 | switch (sim_id) { |
| 4381 | case 0: |
| 4382 | socket_id = RIL_SOCKET_1; |
| 4383 | break; |
| 4384 | #if (SIM_COUNT >= 2) |
| 4385 | case 1: |
| 4386 | socket_id = RIL_SOCKET_2; |
| 4387 | break; |
| 4388 | #endif |
| 4389 | #if (SIM_COUNT >= 3) |
| 4390 | case 2: |
| 4391 | socket_id = RIL_SOCKET_3; |
| 4392 | break; |
| 4393 | #endif |
| 4394 | #if (SIM_COUNT >= 4) |
| 4395 | case 3: |
| 4396 | socket_id = RIL_SOCKET_4; |
| 4397 | break; |
| 4398 | #endif |
| 4399 | default: |
| 4400 | socket_id = RIL_SOCKET_1; |
| 4401 | break; |
| 4402 | } |
| 4403 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | switch (atoi(args[0])) { |
| 4407 | case 0: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4408 | RLOGI ("Connection on debug port: issuing reset."); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4409 | issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4410 | break; |
| 4411 | case 1: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4412 | RLOGI ("Connection on debug port: issuing radio power off."); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4413 | data = 0; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4414 | issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4415 | // Close the socket |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4416 | if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) { |
| 4417 | close(s_ril_param_socket.fdCommand); |
| 4418 | s_ril_param_socket.fdCommand = -1; |
| 4419 | } |
| 4420 | #if (SIM_COUNT == 2) |
| 4421 | else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) { |
| 4422 | close(s_ril_param_socket2.fdCommand); |
| 4423 | s_ril_param_socket2.fdCommand = -1; |
| 4424 | } |
| 4425 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4426 | break; |
| 4427 | case 2: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4428 | RLOGI ("Debug port: issuing unsolicited voice network change."); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4429 | RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4430 | break; |
| 4431 | case 3: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4432 | RLOGI ("Debug port: QXDM log enable."); |
Xia Wang | d855ef4 | 2010-07-27 17:26:55 -0700 | [diff] [blame] | 4433 | qxdm_data[0] = 65536; // head.func_tag |
| 4434 | qxdm_data[1] = 16; // head.len |
| 4435 | qxdm_data[2] = 1; // mode: 1 for 'start logging' |
| 4436 | qxdm_data[3] = 32; // log_file_size: 32megabytes |
| 4437 | qxdm_data[4] = 0; // log_mask |
| 4438 | qxdm_data[5] = 8; // log_max_fileindex |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4439 | issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4440 | 6 * sizeof(int), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4441 | break; |
| 4442 | case 4: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4443 | RLOGI ("Debug port: QXDM log disable."); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4444 | qxdm_data[0] = 65536; |
| 4445 | qxdm_data[1] = 16; |
Xia Wang | d855ef4 | 2010-07-27 17:26:55 -0700 | [diff] [blame] | 4446 | qxdm_data[2] = 0; // mode: 0 for 'stop logging' |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4447 | qxdm_data[3] = 32; |
| 4448 | qxdm_data[4] = 0; |
Xia Wang | d855ef4 | 2010-07-27 17:26:55 -0700 | [diff] [blame] | 4449 | qxdm_data[5] = 8; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4450 | issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4451 | 6 * sizeof(int), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4452 | break; |
| 4453 | case 5: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4454 | RLOGI("Debug port: Radio On"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4455 | data = 1; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4456 | issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4457 | sleep(2); |
| 4458 | // Set network selection automatic. |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4459 | issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4460 | break; |
| 4461 | case 6: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4462 | RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4463 | actData[0] = args[1]; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4464 | issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4465 | sizeof(actData), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4466 | break; |
| 4467 | case 7: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4468 | RLOGI("Debug port: Deactivate Data Call"); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4469 | issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4470 | sizeof(deactData), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4471 | break; |
| 4472 | case 8: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4473 | RLOGI("Debug port: Dial Call"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4474 | dialData.clir = 0; |
| 4475 | dialData.address = args[1]; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4476 | issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4477 | break; |
| 4478 | case 9: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4479 | RLOGI("Debug port: Answer Call"); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4480 | issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4481 | break; |
| 4482 | case 10: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4483 | RLOGI("Debug port: End Call"); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4484 | issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4485 | sizeof(hangupData), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4486 | break; |
| 4487 | default: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4488 | RLOGE ("Invalid request"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4489 | break; |
| 4490 | } |
| 4491 | freeDebugCallbackArgs(number, args); |
| 4492 | close(acceptFD); |
| 4493 | } |
| 4494 | |
| 4495 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4496 | static void userTimerCallback (int fd, short flags, void *param) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4497 | UserCallbackInfo *p_info; |
| 4498 | |
| 4499 | p_info = (UserCallbackInfo *)param; |
| 4500 | |
| 4501 | p_info->p_callback(p_info->userParam); |
| 4502 | |
| 4503 | |
| 4504 | // FIXME generalize this...there should be a cancel mechanism |
| 4505 | if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) { |
| 4506 | s_last_wake_timeout_info = NULL; |
| 4507 | } |
| 4508 | |
| 4509 | free(p_info); |
| 4510 | } |
| 4511 | |
| 4512 | |
| 4513 | static void * |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4514 | eventLoop(void *param) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4515 | int ret; |
| 4516 | int filedes[2]; |
| 4517 | |
| 4518 | ril_event_init(); |
| 4519 | |
| 4520 | pthread_mutex_lock(&s_startupMutex); |
| 4521 | |
| 4522 | s_started = 1; |
| 4523 | pthread_cond_broadcast(&s_startupCond); |
| 4524 | |
| 4525 | pthread_mutex_unlock(&s_startupMutex); |
| 4526 | |
| 4527 | ret = pipe(filedes); |
| 4528 | |
| 4529 | if (ret < 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4530 | RLOGE("Error in pipe() errno:%d", errno); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4531 | return NULL; |
| 4532 | } |
| 4533 | |
| 4534 | s_fdWakeupRead = filedes[0]; |
| 4535 | s_fdWakeupWrite = filedes[1]; |
| 4536 | |
| 4537 | fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK); |
| 4538 | |
| 4539 | ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true, |
| 4540 | processWakeupCallback, NULL); |
| 4541 | |
| 4542 | rilEventAddWakeup (&s_wakeupfd_event); |
| 4543 | |
| 4544 | // Only returns on error |
| 4545 | ril_event_loop(); |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4546 | RLOGE ("error in event_loop_base errno:%d", errno); |
Kazuhiro Ondo | 5cdc135 | 2011-10-14 17:50:58 -0500 | [diff] [blame] | 4547 | // kill self to restart on error |
| 4548 | kill(0, SIGKILL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4549 | |
| 4550 | return NULL; |
| 4551 | } |
| 4552 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4553 | extern "C" void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4554 | RIL_startEventLoop(void) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4555 | /* spin up eventLoop thread and wait for it to get started */ |
| 4556 | s_started = 0; |
| 4557 | pthread_mutex_lock(&s_startupMutex); |
| 4558 | |
Elliott Hughes | c0d8dc6 | 2014-01-03 15:31:42 -0800 | [diff] [blame] | 4559 | pthread_attr_t attr; |
| 4560 | pthread_attr_init(&attr); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4561 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
Elliott Hughes | c0d8dc6 | 2014-01-03 15:31:42 -0800 | [diff] [blame] | 4562 | |
Elliott Hughes | fd81e71 | 2014-01-06 12:46:02 -0800 | [diff] [blame] | 4563 | int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL); |
| 4564 | if (result != 0) { |
| 4565 | RLOGE("Failed to create dispatch thread: %s", strerror(result)); |
Elliott Hughes | c0d8dc6 | 2014-01-03 15:31:42 -0800 | [diff] [blame] | 4566 | goto done; |
| 4567 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4568 | |
| 4569 | while (s_started == 0) { |
| 4570 | pthread_cond_wait(&s_startupCond, &s_startupMutex); |
| 4571 | } |
| 4572 | |
Elliott Hughes | c0d8dc6 | 2014-01-03 15:31:42 -0800 | [diff] [blame] | 4573 | done: |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4574 | pthread_mutex_unlock(&s_startupMutex); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4575 | } |
| 4576 | |
| 4577 | // Used for testing purpose only. |
| 4578 | extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) { |
| 4579 | memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions)); |
| 4580 | } |
| 4581 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4582 | static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) { |
| 4583 | int fdListen = -1; |
| 4584 | int ret; |
| 4585 | char socket_name[10]; |
| 4586 | |
| 4587 | memset(socket_name, 0, sizeof(char)*10); |
| 4588 | |
| 4589 | switch(socket_id) { |
| 4590 | case RIL_SOCKET_1: |
| 4591 | strncpy(socket_name, RIL_getRilSocketName(), 9); |
| 4592 | break; |
| 4593 | #if (SIM_COUNT >= 2) |
| 4594 | case RIL_SOCKET_2: |
| 4595 | strncpy(socket_name, SOCKET2_NAME_RIL, 9); |
| 4596 | break; |
| 4597 | #endif |
| 4598 | #if (SIM_COUNT >= 3) |
| 4599 | case RIL_SOCKET_3: |
| 4600 | strncpy(socket_name, SOCKET3_NAME_RIL, 9); |
| 4601 | break; |
| 4602 | #endif |
| 4603 | #if (SIM_COUNT >= 4) |
| 4604 | case RIL_SOCKET_4: |
| 4605 | strncpy(socket_name, SOCKET4_NAME_RIL, 9); |
| 4606 | break; |
| 4607 | #endif |
| 4608 | default: |
| 4609 | RLOGE("Socket id is wrong!!"); |
| 4610 | return; |
| 4611 | } |
| 4612 | |
| 4613 | RLOGI("Start to listen %s", rilSocketIdToString(socket_id)); |
| 4614 | |
| 4615 | fdListen = android_get_control_socket(socket_name); |
| 4616 | if (fdListen < 0) { |
| 4617 | RLOGE("Failed to get socket %s", socket_name); |
| 4618 | exit(-1); |
| 4619 | } |
| 4620 | |
| 4621 | ret = listen(fdListen, 4); |
| 4622 | |
| 4623 | if (ret < 0) { |
| 4624 | RLOGE("Failed to listen on control socket '%d': %s", |
| 4625 | fdListen, strerror(errno)); |
| 4626 | exit(-1); |
| 4627 | } |
| 4628 | socket_listen_p->fdListen = fdListen; |
| 4629 | |
| 4630 | /* note: non-persistent so we can accept only one connection at a time */ |
| 4631 | ril_event_set (socket_listen_p->listen_event, fdListen, false, |
| 4632 | listenCallback, socket_listen_p); |
| 4633 | |
| 4634 | rilEventAddWakeup (socket_listen_p->listen_event); |
| 4635 | } |
| 4636 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4637 | extern "C" void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4638 | RIL_register (const RIL_RadioFunctions *callbacks) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4639 | int ret; |
| 4640 | int flags; |
| 4641 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4642 | RLOGI("SIM_COUNT: %d", SIM_COUNT); |
| 4643 | |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 4644 | if (callbacks == NULL) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4645 | RLOGE("RIL_register: RIL_RadioFunctions * null"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4646 | return; |
| 4647 | } |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 4648 | if (callbacks->version < RIL_VERSION_MIN) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4649 | RLOGE("RIL_register: version %d is to old, min version is %d", |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 4650 | callbacks->version, RIL_VERSION_MIN); |
| 4651 | return; |
Wink Saville | 3a4840b | 2010-04-07 13:29:58 -0700 | [diff] [blame] | 4652 | } |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 4653 | |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4654 | RLOGE("RIL_register: RIL version %d", callbacks->version); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4655 | |
| 4656 | if (s_registerCalled > 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4657 | RLOGE("RIL_register has been called more than once. " |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4658 | "Subsequent call ignored"); |
| 4659 | return; |
| 4660 | } |
| 4661 | |
| 4662 | memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions)); |
| 4663 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4664 | /* Initialize socket1 parameters */ |
| 4665 | s_ril_param_socket = { |
| 4666 | RIL_SOCKET_1, /* socket_id */ |
| 4667 | -1, /* fdListen */ |
| 4668 | -1, /* fdCommand */ |
| 4669 | PHONE_PROCESS, /* processName */ |
| 4670 | &s_commands_event, /* commands_event */ |
| 4671 | &s_listen_event, /* listen_event */ |
| 4672 | processCommandsCallback, /* processCommandsCallback */ |
| 4673 | NULL /* p_rs */ |
| 4674 | }; |
| 4675 | |
| 4676 | #if (SIM_COUNT >= 2) |
| 4677 | s_ril_param_socket2 = { |
| 4678 | RIL_SOCKET_2, /* socket_id */ |
| 4679 | -1, /* fdListen */ |
| 4680 | -1, /* fdCommand */ |
| 4681 | PHONE_PROCESS, /* processName */ |
| 4682 | &s_commands_event_socket2, /* commands_event */ |
| 4683 | &s_listen_event_socket2, /* listen_event */ |
| 4684 | processCommandsCallback, /* processCommandsCallback */ |
| 4685 | NULL /* p_rs */ |
| 4686 | }; |
| 4687 | #endif |
| 4688 | |
| 4689 | #if (SIM_COUNT >= 3) |
| 4690 | s_ril_param_socket3 = { |
| 4691 | RIL_SOCKET_3, /* socket_id */ |
| 4692 | -1, /* fdListen */ |
| 4693 | -1, /* fdCommand */ |
| 4694 | PHONE_PROCESS, /* processName */ |
| 4695 | &s_commands_event_socket3, /* commands_event */ |
| 4696 | &s_listen_event_socket3, /* listen_event */ |
| 4697 | processCommandsCallback, /* processCommandsCallback */ |
| 4698 | NULL /* p_rs */ |
| 4699 | }; |
| 4700 | #endif |
| 4701 | |
| 4702 | #if (SIM_COUNT >= 4) |
| 4703 | s_ril_param_socket4 = { |
| 4704 | RIL_SOCKET_4, /* socket_id */ |
| 4705 | -1, /* fdListen */ |
| 4706 | -1, /* fdCommand */ |
| 4707 | PHONE_PROCESS, /* processName */ |
| 4708 | &s_commands_event_socket4, /* commands_event */ |
| 4709 | &s_listen_event_socket4, /* listen_event */ |
| 4710 | processCommandsCallback, /* processCommandsCallback */ |
| 4711 | NULL /* p_rs */ |
| 4712 | }; |
| 4713 | #endif |
| 4714 | |
| 4715 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4716 | s_registerCalled = 1; |
| 4717 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4718 | RLOGI("s_registerCalled flag set, %d", s_started); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4719 | // Little self-check |
| 4720 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4721 | for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4722 | assert(i == s_commands[i].requestNumber); |
| 4723 | } |
| 4724 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 4725 | for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) { |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4726 | assert(i + RIL_UNSOL_RESPONSE_BASE |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4727 | == s_unsolResponses[i].requestNumber); |
| 4728 | } |
| 4729 | |
| 4730 | // New rild impl calls RIL_startEventLoop() first |
| 4731 | // old standalone impl wants it here. |
| 4732 | |
| 4733 | if (s_started == 0) { |
| 4734 | RIL_startEventLoop(); |
| 4735 | } |
| 4736 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4737 | // start listen socket1 |
| 4738 | startListen(RIL_SOCKET_1, &s_ril_param_socket); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4739 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4740 | #if (SIM_COUNT >= 2) |
| 4741 | // start listen socket2 |
| 4742 | startListen(RIL_SOCKET_2, &s_ril_param_socket2); |
| 4743 | #endif /* (SIM_COUNT == 2) */ |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4744 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4745 | #if (SIM_COUNT >= 3) |
| 4746 | // start listen socket3 |
| 4747 | startListen(RIL_SOCKET_3, &s_ril_param_socket3); |
| 4748 | #endif /* (SIM_COUNT == 3) */ |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4749 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4750 | #if (SIM_COUNT >= 4) |
| 4751 | // start listen socket4 |
| 4752 | startListen(RIL_SOCKET_4, &s_ril_param_socket4); |
| 4753 | #endif /* (SIM_COUNT == 4) */ |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4754 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4755 | |
| 4756 | #if 1 |
| 4757 | // start debug interface socket |
| 4758 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4759 | char *inst = NULL; |
| 4760 | if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) { |
| 4761 | inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL); |
| 4762 | } |
| 4763 | |
| 4764 | char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG; |
| 4765 | if (inst != NULL) { |
Nick Kralevich | c52e45e | 2015-02-08 07:54:16 -0800 | [diff] [blame] | 4766 | strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4767 | } |
| 4768 | |
| 4769 | s_fdDebug = android_get_control_socket(rildebug); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4770 | if (s_fdDebug < 0) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4771 | RLOGE("Failed to get socket : %s errno:%d", rildebug, errno); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4772 | exit(-1); |
| 4773 | } |
| 4774 | |
| 4775 | ret = listen(s_fdDebug, 4); |
| 4776 | |
| 4777 | if (ret < 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4778 | RLOGE("Failed to listen on ril debug socket '%d': %s", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4779 | s_fdDebug, strerror(errno)); |
| 4780 | exit(-1); |
| 4781 | } |
| 4782 | |
| 4783 | ril_event_set (&s_debug_event, s_fdDebug, true, |
| 4784 | debugCallback, NULL); |
| 4785 | |
| 4786 | rilEventAddWakeup (&s_debug_event); |
| 4787 | #endif |
| 4788 | |
| 4789 | } |
| 4790 | |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 4791 | extern "C" void |
| 4792 | RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) { |
| 4793 | |
| 4794 | RIL_RadioFunctions* UimFuncs = NULL; |
| 4795 | |
| 4796 | if(Init) { |
| 4797 | UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv); |
| 4798 | |
| 4799 | switch(socketType) { |
| 4800 | case RIL_SAP_SOCKET: |
| 4801 | RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs); |
| 4802 | |
| 4803 | #if (SIM_COUNT >= 2) |
| 4804 | RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs); |
| 4805 | #endif |
| 4806 | |
| 4807 | #if (SIM_COUNT >= 3) |
| 4808 | RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs); |
| 4809 | #endif |
| 4810 | |
| 4811 | #if (SIM_COUNT >= 4) |
| 4812 | RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs); |
| 4813 | #endif |
| 4814 | } |
| 4815 | } |
| 4816 | } |
| 4817 | |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 4818 | // Check and remove RequestInfo if its a response and not just ack sent back |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4819 | static int |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 4820 | checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4821 | int ret = 0; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4822 | /* Hook for current context |
| 4823 | pendingRequestsMutextHook refer to &s_pendingRequestsMutex */ |
| 4824 | pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex; |
| 4825 | /* pendingRequestsHook refer to &s_pendingRequests */ |
| 4826 | RequestInfo ** pendingRequestsHook = &s_pendingRequests; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4827 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4828 | if (pRI == NULL) { |
| 4829 | return 0; |
| 4830 | } |
| 4831 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4832 | #if (SIM_COUNT >= 2) |
| 4833 | if (pRI->socket_id == RIL_SOCKET_2) { |
| 4834 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2; |
| 4835 | pendingRequestsHook = &s_pendingRequests_socket2; |
| 4836 | } |
| 4837 | #if (SIM_COUNT >= 3) |
| 4838 | if (pRI->socket_id == RIL_SOCKET_3) { |
| 4839 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3; |
| 4840 | pendingRequestsHook = &s_pendingRequests_socket3; |
| 4841 | } |
| 4842 | #endif |
| 4843 | #if (SIM_COUNT >= 4) |
| 4844 | if (pRI->socket_id == RIL_SOCKET_4) { |
| 4845 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4; |
| 4846 | pendingRequestsHook = &s_pendingRequests_socket4; |
| 4847 | } |
| 4848 | #endif |
| 4849 | #endif |
| 4850 | pthread_mutex_lock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4851 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4852 | for(RequestInfo **ppCur = pendingRequestsHook |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 4853 | ; *ppCur != NULL |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4854 | ; ppCur = &((*ppCur)->p_next) |
| 4855 | ) { |
| 4856 | if (pRI == *ppCur) { |
| 4857 | ret = 1; |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 4858 | if (isAck) { // Async ack |
| 4859 | if (pRI->wasAckSent == 1) { |
| 4860 | RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber)); |
| 4861 | } else { |
| 4862 | pRI->wasAckSent = 1; |
| 4863 | } |
| 4864 | } else { |
| 4865 | *ppCur = (*ppCur)->p_next; |
| 4866 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4867 | break; |
| 4868 | } |
| 4869 | } |
| 4870 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4871 | pthread_mutex_unlock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4872 | |
| 4873 | return ret; |
| 4874 | } |
| 4875 | |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 4876 | static int findFd(int socket_id) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4877 | int fd = s_ril_param_socket.fdCommand; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4878 | #if (SIM_COUNT >= 2) |
| 4879 | if (socket_id == RIL_SOCKET_2) { |
| 4880 | fd = s_ril_param_socket2.fdCommand; |
| 4881 | } |
| 4882 | #if (SIM_COUNT >= 3) |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 4883 | if (socket_id == RIL_SOCKET_3) { |
| 4884 | fd = s_ril_param_socket3.fdCommand; |
| 4885 | } |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4886 | #endif |
| 4887 | #if (SIM_COUNT >= 4) |
| 4888 | if (socket_id == RIL_SOCKET_4) { |
| 4889 | fd = s_ril_param_socket4.fdCommand; |
| 4890 | } |
| 4891 | #endif |
| 4892 | #endif |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 4893 | return fd; |
| 4894 | } |
| 4895 | |
| 4896 | extern "C" void |
| 4897 | RIL_onRequestAck(RIL_Token t) { |
| 4898 | RequestInfo *pRI; |
| 4899 | int ret, fd; |
| 4900 | |
| 4901 | size_t errorOffset; |
| 4902 | RIL_SOCKET_ID socket_id = RIL_SOCKET_1; |
| 4903 | |
| 4904 | pRI = (RequestInfo *)t; |
| 4905 | |
| 4906 | if (!checkAndDequeueRequestInfoIfAck(pRI, true)) { |
| 4907 | RLOGE ("RIL_onRequestAck: invalid RIL_Token"); |
| 4908 | return; |
| 4909 | } |
| 4910 | |
| 4911 | socket_id = pRI->socket_id; |
| 4912 | fd = findFd(socket_id); |
| 4913 | |
| 4914 | #if VDBG |
| 4915 | RLOGD("Request Ack, %s", rilSocketIdToString(socket_id)); |
| 4916 | #endif |
| 4917 | |
| 4918 | appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber)); |
| 4919 | |
| 4920 | if (pRI->cancelled == 0) { |
| 4921 | Parcel p; |
| 4922 | |
| 4923 | p.writeInt32 (RESPONSE_SOLICITED_ACK); |
| 4924 | p.writeInt32 (pRI->token); |
| 4925 | |
| 4926 | if (fd < 0) { |
| 4927 | RLOGD ("RIL onRequestComplete: Command channel closed"); |
| 4928 | } |
| 4929 | |
| 4930 | sendResponse(p, socket_id); |
| 4931 | } |
| 4932 | } |
| 4933 | |
| 4934 | extern "C" void |
| 4935 | RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) { |
| 4936 | RequestInfo *pRI; |
| 4937 | int ret; |
| 4938 | int fd; |
| 4939 | size_t errorOffset; |
| 4940 | RIL_SOCKET_ID socket_id = RIL_SOCKET_1; |
| 4941 | |
| 4942 | pRI = (RequestInfo *)t; |
| 4943 | |
| 4944 | if (!checkAndDequeueRequestInfoIfAck(pRI, false)) { |
| 4945 | RLOGE ("RIL_onRequestComplete: invalid RIL_Token"); |
| 4946 | return; |
| 4947 | } |
| 4948 | |
| 4949 | socket_id = pRI->socket_id; |
| 4950 | fd = findFd(socket_id); |
| 4951 | |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 4952 | #if VDBG |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4953 | RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id)); |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 4954 | #endif |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4955 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4956 | if (pRI->local > 0) { |
| 4957 | // Locally issued command...void only! |
| 4958 | // response does not go back up the command socket |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 4959 | RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4960 | |
| 4961 | goto done; |
| 4962 | } |
| 4963 | |
| 4964 | appendPrintBuf("[%04d]< %s", |
| 4965 | pRI->token, requestToString(pRI->pCI->requestNumber)); |
| 4966 | |
| 4967 | if (pRI->cancelled == 0) { |
| 4968 | Parcel p; |
| 4969 | |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 4970 | if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) { |
| 4971 | // If ack was already sent, then this call is an asynchronous response. So we need to |
| 4972 | // send id indicating that we expect an ack from RIL.java as we acquire wakelock here. |
| 4973 | p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP); |
| 4974 | grabPartialWakeLock(); |
| 4975 | } else { |
| 4976 | p.writeInt32 (RESPONSE_SOLICITED); |
| 4977 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4978 | p.writeInt32 (pRI->token); |
| 4979 | errorOffset = p.dataPosition(); |
| 4980 | |
| 4981 | p.writeInt32 (e); |
| 4982 | |
johnwang | b2a6184 | 2009-06-02 14:55:45 -0700 | [diff] [blame] | 4983 | if (response != NULL) { |
| 4984 | // there is a response payload, no matter success or not. |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4985 | ret = pRI->pCI->responseFunction(p, response, responselen); |
| 4986 | |
| 4987 | /* if an error occurred, rewind and mark it */ |
| 4988 | if (ret != 0) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4989 | RLOGE ("responseFunction error, ret %d", ret); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4990 | p.setDataPosition(errorOffset); |
| 4991 | p.writeInt32 (ret); |
| 4992 | } |
johnwang | b2a6184 | 2009-06-02 14:55:45 -0700 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | if (e != RIL_E_SUCCESS) { |
| 4996 | appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 4997 | } |
| 4998 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 4999 | if (fd < 0) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 5000 | RLOGD ("RIL onRequestComplete: Command channel closed"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5001 | } |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5002 | sendResponse(p, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | done: |
| 5006 | free(pRI); |
| 5007 | } |
| 5008 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5009 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5010 | grabPartialWakeLock() { |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 5011 | if (s_callbacks.version >= 13) { |
| 5012 | int ret; |
| 5013 | ret = pthread_mutex_lock(&s_wakeLockCountMutex); |
| 5014 | assert(ret == 0); |
| 5015 | acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME); |
| 5016 | s_wakelock_count++; |
| 5017 | if (s_last_wake_timeout_info != NULL) { |
| 5018 | s_last_wake_timeout_info->userParam = (void *)1; |
| 5019 | } |
| 5020 | |
| 5021 | s_last_wake_timeout_info |
| 5022 | = internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT); |
| 5023 | |
| 5024 | ret = pthread_mutex_unlock(&s_wakeLockCountMutex); |
| 5025 | assert(ret == 0); |
| 5026 | } else { |
| 5027 | acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME); |
| 5028 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5032 | releaseWakeLock() { |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 5033 | if (s_callbacks.version >= 13) { |
| 5034 | int ret; |
| 5035 | ret = pthread_mutex_lock(&s_wakeLockCountMutex); |
| 5036 | assert(ret == 0); |
| 5037 | |
| 5038 | if (s_wakelock_count > 1) { |
| 5039 | s_wakelock_count--; |
| 5040 | } else { |
| 5041 | s_wakelock_count = 0; |
| 5042 | release_wake_lock(ANDROID_WAKE_LOCK_NAME); |
| 5043 | if (s_last_wake_timeout_info != NULL) { |
| 5044 | s_last_wake_timeout_info->userParam = (void *)1; |
| 5045 | } |
| 5046 | } |
| 5047 | |
| 5048 | ret = pthread_mutex_unlock(&s_wakeLockCountMutex); |
| 5049 | assert(ret == 0); |
| 5050 | } else { |
| 5051 | release_wake_lock(ANDROID_WAKE_LOCK_NAME); |
| 5052 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | /** |
| 5056 | * Timer callback to put us back to sleep before the default timeout |
| 5057 | */ |
| 5058 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5059 | wakeTimeoutCallback (void *param) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5060 | // We're using "param != NULL" as a cancellation mechanism |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 5061 | if (s_callbacks.version >= 13) { |
| 5062 | if (param == NULL) { |
| 5063 | int ret; |
| 5064 | ret = pthread_mutex_lock(&s_wakeLockCountMutex); |
| 5065 | assert(ret == 0); |
| 5066 | s_wakelock_count = 0; |
| 5067 | release_wake_lock(ANDROID_WAKE_LOCK_NAME); |
| 5068 | ret = pthread_mutex_unlock(&s_wakeLockCountMutex); |
| 5069 | assert(ret == 0); |
| 5070 | } |
| 5071 | } else { |
| 5072 | if (param == NULL) { |
| 5073 | releaseWakeLock(); |
| 5074 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5075 | } |
| 5076 | } |
| 5077 | |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5078 | static int |
| 5079 | decodeVoiceRadioTechnology (RIL_RadioState radioState) { |
| 5080 | switch (radioState) { |
| 5081 | case RADIO_STATE_SIM_NOT_READY: |
| 5082 | case RADIO_STATE_SIM_LOCKED_OR_ABSENT: |
| 5083 | case RADIO_STATE_SIM_READY: |
| 5084 | return RADIO_TECH_UMTS; |
| 5085 | |
| 5086 | case RADIO_STATE_RUIM_NOT_READY: |
| 5087 | case RADIO_STATE_RUIM_READY: |
| 5088 | case RADIO_STATE_RUIM_LOCKED_OR_ABSENT: |
| 5089 | case RADIO_STATE_NV_NOT_READY: |
| 5090 | case RADIO_STATE_NV_READY: |
| 5091 | return RADIO_TECH_1xRTT; |
| 5092 | |
| 5093 | default: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 5094 | RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState"); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5095 | return -1; |
| 5096 | } |
| 5097 | } |
| 5098 | |
| 5099 | static int |
| 5100 | decodeCdmaSubscriptionSource (RIL_RadioState radioState) { |
| 5101 | switch (radioState) { |
| 5102 | case RADIO_STATE_SIM_NOT_READY: |
| 5103 | case RADIO_STATE_SIM_LOCKED_OR_ABSENT: |
| 5104 | case RADIO_STATE_SIM_READY: |
| 5105 | case RADIO_STATE_RUIM_NOT_READY: |
| 5106 | case RADIO_STATE_RUIM_READY: |
| 5107 | case RADIO_STATE_RUIM_LOCKED_OR_ABSENT: |
| 5108 | return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM; |
| 5109 | |
| 5110 | case RADIO_STATE_NV_NOT_READY: |
| 5111 | case RADIO_STATE_NV_READY: |
| 5112 | return CDMA_SUBSCRIPTION_SOURCE_NV; |
| 5113 | |
| 5114 | default: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 5115 | RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState"); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5116 | return -1; |
| 5117 | } |
| 5118 | } |
| 5119 | |
| 5120 | static int |
| 5121 | decodeSimStatus (RIL_RadioState radioState) { |
| 5122 | switch (radioState) { |
| 5123 | case RADIO_STATE_SIM_NOT_READY: |
| 5124 | case RADIO_STATE_RUIM_NOT_READY: |
| 5125 | case RADIO_STATE_NV_NOT_READY: |
| 5126 | case RADIO_STATE_NV_READY: |
| 5127 | return -1; |
| 5128 | case RADIO_STATE_SIM_LOCKED_OR_ABSENT: |
| 5129 | case RADIO_STATE_SIM_READY: |
| 5130 | case RADIO_STATE_RUIM_READY: |
| 5131 | case RADIO_STATE_RUIM_LOCKED_OR_ABSENT: |
| 5132 | return radioState; |
| 5133 | default: |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 5134 | RLOGD("decodeSimStatus: Invoked with incorrect RadioState"); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5135 | return -1; |
| 5136 | } |
| 5137 | } |
| 5138 | |
| 5139 | static bool is3gpp2(int radioTech) { |
| 5140 | switch (radioTech) { |
| 5141 | case RADIO_TECH_IS95A: |
| 5142 | case RADIO_TECH_IS95B: |
| 5143 | case RADIO_TECH_1xRTT: |
| 5144 | case RADIO_TECH_EVDO_0: |
| 5145 | case RADIO_TECH_EVDO_A: |
| 5146 | case RADIO_TECH_EVDO_B: |
| 5147 | case RADIO_TECH_EHRPD: |
| 5148 | return true; |
| 5149 | default: |
| 5150 | return false; |
| 5151 | } |
| 5152 | } |
| 5153 | |
| 5154 | /* If RIL sends SIM states or RUIM states, store the voice radio |
| 5155 | * technology and subscription source information so that they can be |
| 5156 | * returned when telephony framework requests them |
| 5157 | */ |
| 5158 | static RIL_RadioState |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5159 | processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) { |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5160 | |
| 5161 | if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) { |
| 5162 | int newVoiceRadioTech; |
| 5163 | int newCdmaSubscriptionSource; |
| 5164 | int newSimStatus; |
| 5165 | |
| 5166 | /* This is old RIL. Decode Subscription source and Voice Radio Technology |
| 5167 | from Radio State and send change notifications if there has been a change */ |
| 5168 | newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState); |
| 5169 | if(newVoiceRadioTech != voiceRadioTech) { |
| 5170 | voiceRadioTech = newVoiceRadioTech; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5171 | RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED, |
| 5172 | &voiceRadioTech, sizeof(voiceRadioTech), socket_id); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5173 | } |
| 5174 | if(is3gpp2(newVoiceRadioTech)) { |
| 5175 | newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState); |
| 5176 | if(newCdmaSubscriptionSource != cdmaSubscriptionSource) { |
| 5177 | cdmaSubscriptionSource = newCdmaSubscriptionSource; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5178 | RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED, |
| 5179 | &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5180 | } |
| 5181 | } |
| 5182 | newSimStatus = decodeSimStatus(newRadioState); |
| 5183 | if(newSimStatus != simRuimStatus) { |
| 5184 | simRuimStatus = newSimStatus; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5185 | RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | /* Send RADIO_ON to telephony */ |
| 5189 | newRadioState = RADIO_STATE_ON; |
| 5190 | } |
| 5191 | |
| 5192 | return newRadioState; |
| 5193 | } |
| 5194 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5195 | |
| 5196 | #if defined(ANDROID_MULTI_SIM) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5197 | extern "C" |
Bernhard Rosenkränzer | d613b96 | 2014-11-17 20:52:09 +0100 | [diff] [blame] | 5198 | void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5199 | size_t datalen, RIL_SOCKET_ID socket_id) |
| 5200 | #else |
| 5201 | extern "C" |
Bernhard Rosenkränzer | d613b96 | 2014-11-17 20:52:09 +0100 | [diff] [blame] | 5202 | void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5203 | size_t datalen) |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5204 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5205 | { |
| 5206 | int unsolResponseIndex; |
| 5207 | int ret; |
| 5208 | int64_t timeReceived = 0; |
| 5209 | bool shouldScheduleTimeout = false; |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5210 | RIL_RadioState newState; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5211 | RIL_SOCKET_ID soc_id = RIL_SOCKET_1; |
| 5212 | |
| 5213 | #if defined(ANDROID_MULTI_SIM) |
| 5214 | soc_id = socket_id; |
| 5215 | #endif |
| 5216 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5217 | |
| 5218 | if (s_registerCalled == 0) { |
| 5219 | // Ignore RIL_onUnsolicitedResponse before RIL_register |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 5220 | RLOGW("RIL_onUnsolicitedResponse called before RIL_register"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5221 | return; |
| 5222 | } |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 5223 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5224 | unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE; |
| 5225 | |
| 5226 | if ((unsolResponseIndex < 0) |
| 5227 | || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 5228 | RLOGE("unsupported unsolicited response code %d", unsolResponse); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5229 | return; |
| 5230 | } |
| 5231 | |
| 5232 | // Grab a wake lock if needed for this reponse, |
| 5233 | // as we exit we'll either release it immediately |
| 5234 | // or set a timer to release it later. |
| 5235 | switch (s_unsolResponses[unsolResponseIndex].wakeType) { |
| 5236 | case WAKE_PARTIAL: |
| 5237 | grabPartialWakeLock(); |
| 5238 | shouldScheduleTimeout = true; |
| 5239 | break; |
| 5240 | |
| 5241 | case DONT_WAKE: |
| 5242 | default: |
| 5243 | // No wake lock is grabed so don't set timeout |
| 5244 | shouldScheduleTimeout = false; |
| 5245 | break; |
| 5246 | } |
| 5247 | |
| 5248 | // Mark the time this was received, doing this |
| 5249 | // after grabing the wakelock incase getting |
| 5250 | // the elapsedRealTime might cause us to goto |
| 5251 | // sleep. |
| 5252 | if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) { |
| 5253 | timeReceived = elapsedRealtime(); |
| 5254 | } |
| 5255 | |
| 5256 | appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse)); |
| 5257 | |
| 5258 | Parcel p; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5259 | p.writeInt32 (RESPONSE_UNSOLICITED); |
| 5260 | p.writeInt32 (unsolResponse); |
| 5261 | |
| 5262 | ret = s_unsolResponses[unsolResponseIndex] |
Bernhard Rosenkränzer | 6e7c196 | 2013-12-12 10:01:10 +0100 | [diff] [blame] | 5263 | .responseFunction(p, const_cast<void*>(data), datalen); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5264 | if (ret != 0) { |
| 5265 | // Problem with the response. Don't continue; |
| 5266 | goto error_exit; |
| 5267 | } |
| 5268 | |
| 5269 | // some things get more payload |
| 5270 | switch(unsolResponse) { |
| 5271 | case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5272 | newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5273 | p.writeInt32(newState); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5274 | appendPrintBuf("%s {%s}", printBuf, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5275 | radioStateToString(CALL_ONSTATEREQUEST(soc_id))); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5276 | break; |
| 5277 | |
| 5278 | |
| 5279 | case RIL_UNSOL_NITZ_TIME_RECEIVED: |
| 5280 | // Store the time that this was received so the |
| 5281 | // handler of this message can account for |
| 5282 | // the time it takes to arrive and process. In |
| 5283 | // particular the system has been known to sleep |
| 5284 | // before this message can be processed. |
| 5285 | p.writeInt64(timeReceived); |
| 5286 | break; |
| 5287 | } |
| 5288 | |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 5289 | #if VDBG |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5290 | RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize()); |
Robert Greenwalt | 191e4dc | 2015-04-29 16:57:39 -0700 | [diff] [blame] | 5291 | #endif |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5292 | ret = sendResponse(p, soc_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5293 | if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) { |
| 5294 | |
| 5295 | // Unfortunately, NITZ time is not poll/update like everything |
| 5296 | // else in the system. So, if the upstream client isn't connected, |
| 5297 | // keep a copy of the last NITZ response (with receive time noted |
| 5298 | // above) around so we can deliver it when it is connected |
| 5299 | |
| 5300 | if (s_lastNITZTimeData != NULL) { |
| 5301 | free (s_lastNITZTimeData); |
| 5302 | s_lastNITZTimeData = NULL; |
| 5303 | } |
| 5304 | |
| 5305 | s_lastNITZTimeData = malloc(p.dataSize()); |
| 5306 | s_lastNITZTimeDataSize = p.dataSize(); |
| 5307 | memcpy(s_lastNITZTimeData, p.data(), p.dataSize()); |
| 5308 | } |
| 5309 | |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 5310 | if (s_callbacks.version < 13) { |
| 5311 | if (shouldScheduleTimeout) { |
| 5312 | // Cancel the previous request |
| 5313 | if (s_last_wake_timeout_info != NULL) { |
| 5314 | s_last_wake_timeout_info->userParam = (void *)1; |
| 5315 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5316 | |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 5317 | s_last_wake_timeout_info |
| 5318 | = internalRequestTimedCallback(wakeTimeoutCallback, NULL, |
| 5319 | &TIMEVAL_WAKE_TIMEOUT); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5320 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5321 | } |
| 5322 | |
| 5323 | // Normal exit |
| 5324 | return; |
| 5325 | |
| 5326 | error_exit: |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5327 | if (shouldScheduleTimeout) { |
| 5328 | releaseWakeLock(); |
| 5329 | } |
| 5330 | } |
| 5331 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 5332 | /** FIXME generalize this if you track UserCAllbackInfo, clear it |
| 5333 | when the callback occurs |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5334 | */ |
| 5335 | static UserCallbackInfo * |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 5336 | internalRequestTimedCallback (RIL_TimedCallback callback, void *param, |
Dianne Hackborn | 0d9f0c0 | 2010-06-25 16:50:46 -0700 | [diff] [blame] | 5337 | const struct timeval *relativeTime) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5338 | { |
| 5339 | struct timeval myRelativeTime; |
| 5340 | UserCallbackInfo *p_info; |
| 5341 | |
| 5342 | p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo)); |
| 5343 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 5344 | p_info->p_callback = callback; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5345 | p_info->userParam = param; |
Dianne Hackborn | 0d9f0c0 | 2010-06-25 16:50:46 -0700 | [diff] [blame] | 5346 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5347 | if (relativeTime == NULL) { |
| 5348 | /* treat null parameter as a 0 relative time */ |
| 5349 | memset (&myRelativeTime, 0, sizeof(myRelativeTime)); |
| 5350 | } else { |
| 5351 | /* FIXME I think event_add's tv param is really const anyway */ |
| 5352 | memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime)); |
| 5353 | } |
| 5354 | |
| 5355 | ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info); |
| 5356 | |
| 5357 | ril_timer_add(&(p_info->event), &myRelativeTime); |
| 5358 | |
| 5359 | triggerEvLoop(); |
| 5360 | return p_info; |
| 5361 | } |
| 5362 | |
Naveen Kalla | 7edd07c | 2010-06-21 18:54:47 -0700 | [diff] [blame] | 5363 | |
| 5364 | extern "C" void |
Dianne Hackborn | 0d9f0c0 | 2010-06-25 16:50:46 -0700 | [diff] [blame] | 5365 | RIL_requestTimedCallback (RIL_TimedCallback callback, void *param, |
| 5366 | const struct timeval *relativeTime) { |
| 5367 | internalRequestTimedCallback (callback, param, relativeTime); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | const char * |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5371 | failCauseToString(RIL_Errno e) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5372 | switch(e) { |
| 5373 | case RIL_E_SUCCESS: return "E_SUCCESS"; |
Robert Greenwalt | 2126ab2 | 2013-04-09 12:20:45 -0700 | [diff] [blame] | 5374 | case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5375 | case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE"; |
| 5376 | case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT"; |
| 5377 | case RIL_E_SIM_PIN2: return "E_SIM_PIN2"; |
| 5378 | case RIL_E_SIM_PUK2: return "E_SIM_PUK2"; |
| 5379 | case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED"; |
| 5380 | case RIL_E_CANCELLED: return "E_CANCELLED"; |
| 5381 | case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL"; |
| 5382 | case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW"; |
| 5383 | case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5384 | case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT"; |
John Wang | 7553447 | 2010-04-20 15:11:42 -0700 | [diff] [blame] | 5385 | case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME"; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 5386 | #ifdef FEATURE_MULTIMODE_ANDROID |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5387 | case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE"; |
| 5388 | case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED"; |
| 5389 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5390 | default: return "<unknown error>"; |
| 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | const char * |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5395 | radioStateToString(RIL_RadioState s) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5396 | switch(s) { |
| 5397 | case RADIO_STATE_OFF: return "RADIO_OFF"; |
| 5398 | case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE"; |
| 5399 | case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY"; |
| 5400 | case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT"; |
| 5401 | case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5402 | case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY"; |
| 5403 | case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY"; |
| 5404 | case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT"; |
| 5405 | case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY"; |
| 5406 | case RADIO_STATE_NV_READY:return"RADIO_NV_READY"; |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5407 | case RADIO_STATE_ON:return"RADIO_ON"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5408 | default: return "<unknown state>"; |
| 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | const char * |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5413 | callStateToString(RIL_CallState s) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5414 | switch(s) { |
| 5415 | case RIL_CALL_ACTIVE : return "ACTIVE"; |
| 5416 | case RIL_CALL_HOLDING: return "HOLDING"; |
| 5417 | case RIL_CALL_DIALING: return "DIALING"; |
| 5418 | case RIL_CALL_ALERTING: return "ALERTING"; |
| 5419 | case RIL_CALL_INCOMING: return "INCOMING"; |
| 5420 | case RIL_CALL_WAITING: return "WAITING"; |
| 5421 | default: return "<unknown state>"; |
| 5422 | } |
| 5423 | } |
| 5424 | |
| 5425 | const char * |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5426 | requestToString(int request) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5427 | /* |
| 5428 | cat libs/telephony/ril_commands.h \ |
| 5429 | | egrep "^ *{RIL_" \ |
| 5430 | | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/' |
| 5431 | |
| 5432 | |
| 5433 | cat libs/telephony/ril_unsol_commands.h \ |
| 5434 | | egrep "^ *{RIL_" \ |
| 5435 | | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/' |
| 5436 | |
| 5437 | */ |
| 5438 | switch(request) { |
| 5439 | case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS"; |
| 5440 | case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN"; |
| 5441 | case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK"; |
| 5442 | case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2"; |
| 5443 | case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2"; |
| 5444 | case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN"; |
| 5445 | case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2"; |
| 5446 | case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION"; |
| 5447 | case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS"; |
| 5448 | case RIL_REQUEST_DIAL: return "DIAL"; |
| 5449 | case RIL_REQUEST_GET_IMSI: return "GET_IMSI"; |
| 5450 | case RIL_REQUEST_HANGUP: return "HANGUP"; |
| 5451 | case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND"; |
| 5452 | case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND"; |
| 5453 | case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE"; |
| 5454 | case RIL_REQUEST_CONFERENCE: return "CONFERENCE"; |
| 5455 | case RIL_REQUEST_UDUB: return "UDUB"; |
| 5456 | case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE"; |
| 5457 | case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH"; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 5458 | case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE"; |
| 5459 | case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5460 | case RIL_REQUEST_OPERATOR: return "OPERATOR"; |
| 5461 | case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER"; |
| 5462 | case RIL_REQUEST_DTMF: return "DTMF"; |
| 5463 | case RIL_REQUEST_SEND_SMS: return "SEND_SMS"; |
| 5464 | case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5465 | case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5466 | case RIL_REQUEST_SIM_IO: return "SIM_IO"; |
| 5467 | case RIL_REQUEST_SEND_USSD: return "SEND_USSD"; |
| 5468 | case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD"; |
| 5469 | case RIL_REQUEST_GET_CLIR: return "GET_CLIR"; |
| 5470 | case RIL_REQUEST_SET_CLIR: return "SET_CLIR"; |
| 5471 | case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS"; |
| 5472 | case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD"; |
| 5473 | case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING"; |
| 5474 | case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING"; |
| 5475 | case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE"; |
| 5476 | case RIL_REQUEST_GET_IMEI: return "GET_IMEI"; |
| 5477 | case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV"; |
| 5478 | case RIL_REQUEST_ANSWER: return "ANSWER"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5479 | case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5480 | case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK"; |
| 5481 | case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK"; |
| 5482 | case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD"; |
| 5483 | case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE"; |
| 5484 | case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC"; |
| 5485 | case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL"; |
| 5486 | case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS "; |
| 5487 | case RIL_REQUEST_DTMF_START: return "DTMF_START"; |
| 5488 | case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP"; |
| 5489 | case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION"; |
| 5490 | case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION"; |
| 5491 | case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE"; |
| 5492 | case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE"; |
| 5493 | case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS"; |
| 5494 | case RIL_REQUEST_SET_MUTE: return "SET_MUTE"; |
| 5495 | case RIL_REQUEST_GET_MUTE: return "GET_MUTE"; |
| 5496 | case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5497 | case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE"; |
| 5498 | case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5499 | case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO"; |
| 5500 | case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW"; |
| 5501 | case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5502 | case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE"; |
| 5503 | case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5504 | case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE"; |
| 5505 | case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE"; |
| 5506 | case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND"; |
| 5507 | case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE"; |
| 5508 | case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM"; |
| 5509 | case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE"; |
| 5510 | case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER"; |
| 5511 | case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES"; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 5512 | case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5513 | case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE"; |
| 5514 | case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE"; |
| 5515 | case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE"; |
| 5516 | case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE"; |
| 5517 | case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE"; |
| 5518 | case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE"; |
| 5519 | case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH"; |
| 5520 | case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF"; |
| 5521 | case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS"; |
| 5522 | case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE"; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 5523 | case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG"; |
| 5524 | case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG"; |
| 5525 | case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG"; |
| 5526 | case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG"; |
| 5527 | case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION"; |
Naveen Kalla | 03c1edf | 2009-09-23 11:18:35 -0700 | [diff] [blame] | 5528 | case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5529 | case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION"; |
| 5530 | case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM"; |
| 5531 | case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM"; |
| 5532 | case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY"; |
jsh | 000a9fe | 2009-05-11 14:52:35 -0700 | [diff] [blame] | 5533 | case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE"; |
| 5534 | case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS"; |
| 5535 | case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS"; |
jsh | 09a68ba | 2009-06-10 11:56:38 -0700 | [diff] [blame] | 5536 | case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS"; |
jsh | 563fd72 | 2010-06-08 16:52:24 -0700 | [diff] [blame] | 5537 | case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING"; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 5538 | case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE"; |
Jake Hamby | fa8d584 | 2011-08-19 16:22:18 -0700 | [diff] [blame] | 5539 | case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION"; |
Jake Hamby | 300105d | 2011-09-26 01:01:44 -0700 | [diff] [blame] | 5540 | case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU"; |
| 5541 | case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS"; |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5542 | case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH"; |
Ajay Nambi | c27945d | 2011-11-15 11:19:30 -0800 | [diff] [blame] | 5543 | case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM"; |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 5544 | case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST"; |
| 5545 | case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE"; |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 5546 | case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN"; |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 5547 | case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE"; |
| 5548 | case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS"; |
Shishir Agrawal | 2458d8d | 2013-11-27 14:53:05 -0800 | [diff] [blame] | 5549 | case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC"; |
| 5550 | case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL"; |
| 5551 | case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL"; |
| 5552 | case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL"; |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 5553 | case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY"; |
| 5554 | case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY"; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5555 | case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION"; |
| 5556 | case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA"; |
Amit Mahajan | 2b77203 | 2014-06-26 14:20:11 -0700 | [diff] [blame] | 5557 | case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG"; |
| 5558 | case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION"; |
Wink Saville | c29360a | 2014-07-13 05:17:28 -0700 | [diff] [blame] | 5559 | case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO"; |
| 5560 | case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE"; |
Amit Mahajan | c796e22 | 2014-08-13 16:54:01 +0000 | [diff] [blame] | 5561 | case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5562 | case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED"; |
| 5563 | case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED"; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 5564 | case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5565 | case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS"; |
| 5566 | case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT"; |
| 5567 | case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM"; |
| 5568 | case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD"; |
| 5569 | case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)"; |
| 5570 | case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED"; |
| 5571 | case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH"; |
Ajay Nambi | c27945d | 2011-11-15 11:19:30 -0800 | [diff] [blame] | 5572 | case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5573 | case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END"; |
| 5574 | case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND"; |
| 5575 | case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY"; |
| 5576 | case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP"; |
| 5577 | case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL"; |
| 5578 | case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5579 | case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5580 | case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING"; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 5581 | case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED"; |
| 5582 | case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS"; |
| 5583 | case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS"; |
| 5584 | case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL"; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 5585 | case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED"; |
| 5586 | case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE"; |
| 5587 | case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING"; |
| 5588 | case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS"; |
| 5589 | case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC"; |
Jaikumar Ganesh | af6ecbf | 2009-04-29 13:27:51 -0700 | [diff] [blame] | 5590 | case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW"; |
John Wang | 5d621da | 2009-09-18 17:17:48 -0700 | [diff] [blame] | 5591 | case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE"; |
John Wang | 5909cf8 | 2010-01-29 00:18:54 -0800 | [diff] [blame] | 5592 | case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE"; |
Wink Saville | ee27458 | 2011-04-16 15:05:49 -0700 | [diff] [blame] | 5593 | case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED"; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 5594 | case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED"; |
| 5595 | case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE"; |
Wink Saville | 5b9df33 | 2011-04-06 16:24:21 -0700 | [diff] [blame] | 5596 | case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED"; |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 5597 | case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED"; |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 5598 | case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST"; |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 5599 | case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED"; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5600 | case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED"; |
| 5601 | case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY"; |
| 5602 | case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED"; |
Wink Saville | c29360a | 2014-07-13 05:17:28 -0700 | [diff] [blame] | 5603 | case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED"; |
Naveen Kalla | a65a16a | 2014-07-31 16:48:31 -0700 | [diff] [blame] | 5604 | case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN"; |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 5605 | case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY"; |
Sanket Padawe | 6ff9a87 | 2016-01-27 15:09:12 -0800 | [diff] [blame^] | 5606 | case RIL_RESPONSE_ACKNOWLEDGEMENT: return "RIL_RESPONSE_ACKNOWLEDGEMENT"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5607 | default: return "<unknown request>"; |
| 5608 | } |
| 5609 | } |
| 5610 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 5611 | const char * |
| 5612 | rilSocketIdToString(RIL_SOCKET_ID socket_id) |
| 5613 | { |
| 5614 | switch(socket_id) { |
| 5615 | case RIL_SOCKET_1: |
| 5616 | return "RIL_SOCKET_1"; |
| 5617 | #if (SIM_COUNT >= 2) |
| 5618 | case RIL_SOCKET_2: |
| 5619 | return "RIL_SOCKET_2"; |
| 5620 | #endif |
| 5621 | #if (SIM_COUNT >= 3) |
| 5622 | case RIL_SOCKET_3: |
| 5623 | return "RIL_SOCKET_3"; |
| 5624 | #endif |
| 5625 | #if (SIM_COUNT >= 4) |
| 5626 | case RIL_SOCKET_4: |
| 5627 | return "RIL_SOCKET_4"; |
| 5628 | #endif |
| 5629 | default: |
| 5630 | return "not a valid RIL"; |
| 5631 | } |
| 5632 | } |
| 5633 | |
Sanket Padawe | 88cf6a5 | 2016-01-11 12:45:43 -0800 | [diff] [blame] | 5634 | /* |
| 5635 | * Returns true for a debuggable build. |
| 5636 | */ |
| 5637 | static bool isDebuggable() { |
| 5638 | char debuggable[PROP_VALUE_MAX]; |
| 5639 | property_get("ro.debuggable", debuggable, "0"); |
| 5640 | if (strcmp(debuggable, "1") == 0) { |
| 5641 | return true; |
| 5642 | } |
| 5643 | return false; |
| 5644 | } |
| 5645 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 5646 | } /* namespace android */ |
Dheeraj Shetty | 27976c4 | 2014-07-02 21:27:57 +0200 | [diff] [blame] | 5647 | |
| 5648 | void rilEventAddWakeup_helper(struct ril_event *ev) { |
| 5649 | android::rilEventAddWakeup(ev); |
| 5650 | } |
| 5651 | |
| 5652 | void listenCallback_helper(int fd, short flags, void *param) { |
| 5653 | android::listenCallback(fd, flags, param); |
| 5654 | } |
| 5655 | |
| 5656 | int blockingWrite_helper(int fd, void *buffer, size_t len) { |
| 5657 | return android::blockingWrite(fd, buffer, len); |
| 5658 | } |