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> |
| 21 | |
| 22 | #include <telephony/ril.h> |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 23 | #include <telephony/ril_cdma_sms.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 24 | #include <cutils/sockets.h> |
| 25 | #include <cutils/jstring.h> |
Dima Zavin | 622bf2b | 2013-05-22 11:29:34 -0700 | [diff] [blame] | 26 | #include <telephony/record_stream.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 27 | #include <utils/Log.h> |
| 28 | #include <utils/SystemClock.h> |
| 29 | #include <pthread.h> |
Mathias Agopian | 8a3c48c | 2009-05-19 19:11:50 -0700 | [diff] [blame] | 30 | #include <binder/Parcel.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 31 | #include <cutils/jstring.h> |
| 32 | |
| 33 | #include <sys/types.h> |
Wink Saville | 18e4ab1 | 2013-04-07 17:31:04 -0700 | [diff] [blame] | 34 | #include <sys/limits.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 35 | #include <pwd.h> |
| 36 | |
| 37 | #include <stdio.h> |
| 38 | #include <stdlib.h> |
| 39 | #include <stdarg.h> |
| 40 | #include <string.h> |
| 41 | #include <unistd.h> |
| 42 | #include <fcntl.h> |
| 43 | #include <time.h> |
| 44 | #include <errno.h> |
| 45 | #include <assert.h> |
| 46 | #include <ctype.h> |
| 47 | #include <alloca.h> |
| 48 | #include <sys/un.h> |
| 49 | #include <assert.h> |
| 50 | #include <netinet/in.h> |
| 51 | #include <cutils/properties.h> |
| 52 | |
| 53 | #include <ril_event.h> |
| 54 | |
| 55 | namespace android { |
| 56 | |
| 57 | #define PHONE_PROCESS "radio" |
| 58 | |
| 59 | #define SOCKET_NAME_RIL "rild" |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 60 | #define SOCKET2_NAME_RIL "rild2" |
| 61 | #define SOCKET3_NAME_RIL "rild3" |
| 62 | #define SOCKET4_NAME_RIL "rild4" |
| 63 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 64 | #define SOCKET_NAME_RIL_DEBUG "rild-debug" |
| 65 | |
| 66 | #define ANDROID_WAKE_LOCK_NAME "radio-interface" |
| 67 | |
| 68 | |
| 69 | #define PROPERTY_RIL_IMPL "gsm.version.ril-impl" |
| 70 | |
| 71 | // match with constant in RIL.java |
| 72 | #define MAX_COMMAND_BYTES (8 * 1024) |
| 73 | |
| 74 | // Basically: memset buffers that the client library |
| 75 | // shouldn't be using anymore in an attempt to find |
| 76 | // memory usage issues sooner. |
| 77 | #define MEMSET_FREED 1 |
| 78 | |
| 79 | #define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0]) |
| 80 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 81 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) |
| 82 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 83 | /* Constants for response types */ |
| 84 | #define RESPONSE_SOLICITED 0 |
| 85 | #define RESPONSE_UNSOLICITED 1 |
| 86 | |
| 87 | /* Negative values for private RIL errno's */ |
| 88 | #define RIL_ERRNO_INVALID_RESPONSE -1 |
| 89 | |
| 90 | // request, response, and unsolicited msg print macro |
| 91 | #define PRINTBUF_SIZE 8096 |
| 92 | |
| 93 | // Enable RILC log |
| 94 | #define RILC_LOG 0 |
| 95 | |
| 96 | #if RILC_LOG |
| 97 | #define startRequest sprintf(printBuf, "(") |
| 98 | #define closeRequest sprintf(printBuf, "%s)", printBuf) |
| 99 | #define printRequest(token, req) \ |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 100 | RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 101 | |
| 102 | #define startResponse sprintf(printBuf, "%s {", printBuf) |
| 103 | #define closeResponse sprintf(printBuf, "%s}", printBuf) |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 104 | #define printResponse RLOGD("%s", printBuf) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 105 | |
| 106 | #define clearPrintBuf printBuf[0] = 0 |
| 107 | #define removeLastChar printBuf[strlen(printBuf)-1] = 0 |
| 108 | #define appendPrintBuf(x...) sprintf(printBuf, x) |
| 109 | #else |
| 110 | #define startRequest |
| 111 | #define closeRequest |
| 112 | #define printRequest(token, req) |
| 113 | #define startResponse |
| 114 | #define closeResponse |
| 115 | #define printResponse |
| 116 | #define clearPrintBuf |
| 117 | #define removeLastChar |
| 118 | #define appendPrintBuf(x...) |
| 119 | #endif |
| 120 | |
| 121 | enum WakeType {DONT_WAKE, WAKE_PARTIAL}; |
| 122 | |
| 123 | typedef struct { |
| 124 | int requestNumber; |
| 125 | void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI); |
| 126 | int(*responseFunction) (Parcel &p, void *response, size_t responselen); |
| 127 | } CommandInfo; |
| 128 | |
| 129 | typedef struct { |
| 130 | int requestNumber; |
| 131 | int (*responseFunction) (Parcel &p, void *response, size_t responselen); |
| 132 | WakeType wakeType; |
| 133 | } UnsolResponseInfo; |
| 134 | |
| 135 | typedef struct RequestInfo { |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 136 | int32_t token; //this is not RIL_Token |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 137 | CommandInfo *pCI; |
| 138 | struct RequestInfo *p_next; |
| 139 | char cancelled; |
| 140 | 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] | 141 | RIL_SOCKET_ID socket_id; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 142 | } RequestInfo; |
| 143 | |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 144 | typedef struct UserCallbackInfo { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 145 | RIL_TimedCallback p_callback; |
| 146 | void *userParam; |
| 147 | struct ril_event event; |
| 148 | struct UserCallbackInfo *p_next; |
| 149 | } UserCallbackInfo; |
| 150 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 151 | typedef struct SocketListenParam { |
| 152 | RIL_SOCKET_ID socket_id; |
| 153 | int fdListen; |
| 154 | int fdCommand; |
| 155 | char* processName; |
| 156 | struct ril_event* commands_event; |
| 157 | struct ril_event* listen_event; |
| 158 | void (*processCommandsCallback)(int fd, short flags, void *param); |
| 159 | RecordStream *p_rs; |
| 160 | } SocketListenParam; |
Dianne Hackborn | 0d9f0c0 | 2010-06-25 16:50:46 -0700 | [diff] [blame] | 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 | |
| 185 | static struct ril_event s_commands_event; |
| 186 | static struct ril_event s_wakeupfd_event; |
| 187 | static struct ril_event s_listen_event; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 188 | static SocketListenParam s_ril_param_socket; |
| 189 | |
| 190 | static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER; |
| 191 | static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER; |
| 192 | static RequestInfo *s_pendingRequests = NULL; |
| 193 | |
| 194 | #if (SIM_COUNT >= 2) |
| 195 | static struct ril_event s_commands_event_socket2; |
| 196 | static struct ril_event s_listen_event_socket2; |
| 197 | static SocketListenParam s_ril_param_socket2; |
| 198 | |
| 199 | static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER; |
| 200 | static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER; |
| 201 | static RequestInfo *s_pendingRequests_socket2 = NULL; |
| 202 | #endif |
| 203 | |
| 204 | #if (SIM_COUNT >= 3) |
| 205 | static struct ril_event s_commands_event_socket3; |
| 206 | static struct ril_event s_listen_event_socket3; |
| 207 | static SocketListenParam s_ril_param_socket3; |
| 208 | |
| 209 | static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER; |
| 210 | static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER; |
| 211 | static RequestInfo *s_pendingRequests_socket3 = NULL; |
| 212 | #endif |
| 213 | |
| 214 | #if (SIM_COUNT >= 4) |
| 215 | static struct ril_event s_commands_event_socket4; |
| 216 | static struct ril_event s_listen_event_socket4; |
| 217 | static SocketListenParam s_ril_param_socket4; |
| 218 | |
| 219 | static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER; |
| 220 | static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER; |
| 221 | static RequestInfo *s_pendingRequests_socket4 = NULL; |
| 222 | #endif |
| 223 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 224 | static struct ril_event s_wake_timeout_event; |
| 225 | static struct ril_event s_debug_event; |
| 226 | |
| 227 | |
| 228 | static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0}; |
| 229 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 230 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 231 | static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER; |
| 232 | static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER; |
| 233 | |
| 234 | static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER; |
| 235 | static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER; |
| 236 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 237 | static RequestInfo *s_toDispatchHead = NULL; |
| 238 | static RequestInfo *s_toDispatchTail = NULL; |
| 239 | |
| 240 | static UserCallbackInfo *s_last_wake_timeout_info = NULL; |
| 241 | |
| 242 | static void *s_lastNITZTimeData = NULL; |
| 243 | static size_t s_lastNITZTimeDataSize; |
| 244 | |
| 245 | #if RILC_LOG |
| 246 | static char printBuf[PRINTBUF_SIZE]; |
| 247 | #endif |
| 248 | |
| 249 | /*******************************************************************/ |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 250 | 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] | 251 | |
| 252 | static void dispatchVoid (Parcel& p, RequestInfo *pRI); |
| 253 | static void dispatchString (Parcel& p, RequestInfo *pRI); |
| 254 | static void dispatchStrings (Parcel& p, RequestInfo *pRI); |
| 255 | static void dispatchInts (Parcel& p, RequestInfo *pRI); |
| 256 | static void dispatchDial (Parcel& p, RequestInfo *pRI); |
| 257 | static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI); |
Shishir Agrawal | 2458d8d | 2013-11-27 14:53:05 -0800 | [diff] [blame] | 258 | static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 259 | static void dispatchCallForward(Parcel& p, RequestInfo *pRI); |
| 260 | static void dispatchRaw(Parcel& p, RequestInfo *pRI); |
| 261 | static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI); |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 262 | static void dispatchDataCall (Parcel& p, RequestInfo *pRI); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 263 | static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI); |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 264 | static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 265 | static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 266 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 267 | static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 268 | static void dispatchImsSms(Parcel &p, RequestInfo *pRI); |
| 269 | static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef); |
| 270 | 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] | 271 | static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 272 | static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 273 | static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI); |
| 274 | static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI); |
Jake Hamby | 8a4a233 | 2014-01-15 13:12:05 -0800 | [diff] [blame] | 275 | static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI); |
| 276 | static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 277 | static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI); |
Amit Mahajan | 90530a6 | 2014-07-01 15:54:08 -0700 | [diff] [blame] | 278 | static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI); |
Amit Mahajan | c796e22 | 2014-08-13 16:54:01 +0000 | [diff] [blame] | 279 | static void dispatchDataProfile(Parcel &p, RequestInfo *pRI); |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 280 | static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 281 | static int responseInts(Parcel &p, void *response, size_t responselen); |
| 282 | static int responseStrings(Parcel &p, void *response, size_t responselen); |
| 283 | static int responseString(Parcel &p, void *response, size_t responselen); |
| 284 | static int responseVoid(Parcel &p, void *response, size_t responselen); |
| 285 | static int responseCallList(Parcel &p, void *response, size_t responselen); |
| 286 | static int responseSMS(Parcel &p, void *response, size_t responselen); |
| 287 | static int responseSIM_IO(Parcel &p, void *response, size_t responselen); |
| 288 | static int responseCallForwards(Parcel &p, void *response, size_t responselen); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 289 | static int responseDataCallList(Parcel &p, void *response, size_t responselen); |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 290 | 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] | 291 | static int responseRaw(Parcel &p, void *response, size_t responselen); |
| 292 | static int responseSsn(Parcel &p, void *response, size_t responselen); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 293 | static int responseSimStatus(Parcel &p, void *response, size_t responselen); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 294 | static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen); |
| 295 | static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 296 | 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] | 297 | static int responseCellList(Parcel &p, void *response, size_t responselen); |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 298 | static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen); |
| 299 | static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen); |
| 300 | static int responseCallRing(Parcel &p, void *response, size_t responselen); |
| 301 | static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen); |
| 302 | static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen); |
Alex Yakavenka | 45e740e | 2012-01-31 11:48:27 -0800 | [diff] [blame] | 303 | static int responseSimRefresh(Parcel &p, void *response, size_t responselen); |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 304 | static int responseCellInfoList(Parcel &p, void *response, size_t responselen); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 305 | static int responseHardwareConfig(Parcel &p, void *response, size_t responselen); |
Wink Saville | c29360a | 2014-07-13 05:17:28 -0700 | [diff] [blame] | 306 | static int responseDcRtInfo(Parcel &p, void *response, size_t responselen); |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 307 | static int responseRadioCapability(Parcel &p, void *response, size_t responselen); |
Amit Mahajan | 54563d3 | 2014-11-22 00:54:49 +0000 | [diff] [blame^] | 308 | static int responseSSData(Parcel &p, void *response, size_t responselen); |
| 309 | |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 310 | static int decodeVoiceRadioTechnology (RIL_RadioState radioState); |
| 311 | static int decodeCdmaSubscriptionSource (RIL_RadioState radioState); |
| 312 | static RIL_RadioState processRadioState(RIL_RadioState newRadioState); |
| 313 | |
Amit Mahajan | 54563d3 | 2014-11-22 00:54:49 +0000 | [diff] [blame^] | 314 | static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType); |
| 315 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 316 | #ifdef RIL_SHLIB |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 317 | #if defined(ANDROID_MULTI_SIM) |
| 318 | extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data, |
| 319 | size_t datalen, RIL_SOCKET_ID socket_id); |
| 320 | #else |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 321 | extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 322 | size_t datalen); |
| 323 | #endif |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 324 | #endif |
| 325 | |
| 326 | #if defined(ANDROID_MULTI_SIM) |
| 327 | #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d)) |
| 328 | #define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e)) |
| 329 | #define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a) |
| 330 | #else |
| 331 | #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c)) |
| 332 | #define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d)) |
| 333 | #define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest() |
| 334 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 335 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 336 | static UserCallbackInfo * internalRequestTimedCallback |
Dianne Hackborn | 0d9f0c0 | 2010-06-25 16:50:46 -0700 | [diff] [blame] | 337 | (RIL_TimedCallback callback, void *param, |
| 338 | const struct timeval *relativeTime); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 339 | |
| 340 | /** Index == requestNumber */ |
| 341 | static CommandInfo s_commands[] = { |
| 342 | #include "ril_commands.h" |
| 343 | }; |
| 344 | |
| 345 | static UnsolResponseInfo s_unsolResponses[] = { |
| 346 | #include "ril_unsol_commands.h" |
| 347 | }; |
| 348 | |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 349 | /* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and |
| 350 | RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from |
| 351 | radio state message and store it. Every time there is a change in Radio State |
| 352 | check to see if voice radio tech changes and notify telephony |
| 353 | */ |
| 354 | int voiceRadioTech = -1; |
| 355 | |
| 356 | /* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE |
| 357 | and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription |
| 358 | source from radio state and store it. Every time there is a change in Radio State |
| 359 | check to see if subscription source changed and notify telephony |
| 360 | */ |
| 361 | int cdmaSubscriptionSource = -1; |
| 362 | |
| 363 | /* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the |
| 364 | SIM/RUIM state from radio state and store it. Every time there is a change in Radio State, |
| 365 | check to see if SIM/RUIM status changed and notify telephony |
| 366 | */ |
| 367 | int simRuimStatus = -1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 368 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 369 | static char * RIL_getRilSocketName() { |
| 370 | return rild; |
| 371 | } |
| 372 | |
| 373 | extern "C" |
| 374 | void RIL_setRilSocketName(char * s) { |
| 375 | strncpy(rild, s, MAX_SOCKET_NAME_LENGTH); |
| 376 | } |
| 377 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 378 | static char * |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 379 | strdupReadString(Parcel &p) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 380 | size_t stringlen; |
| 381 | const char16_t *s16; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 382 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 383 | s16 = p.readString16Inplace(&stringlen); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 384 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 385 | return strndup16to8(s16, stringlen); |
| 386 | } |
| 387 | |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 388 | static status_t |
| 389 | readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) { |
| 390 | size_t s16Len; |
| 391 | const char16_t *s16; |
| 392 | |
| 393 | s16 = p.readString16Inplace(&s16Len); |
| 394 | if (s16 == NULL) { |
| 395 | return NO_MEMORY; |
| 396 | } |
| 397 | size_t strLen = strnlen16to8(s16, s16Len); |
| 398 | if ((strLen + 1) > maxLen) { |
| 399 | return NO_MEMORY; |
| 400 | } |
| 401 | if (strncpy16to8(str, s16, strLen) == NULL) { |
| 402 | return NO_MEMORY; |
| 403 | } else { |
| 404 | return NO_ERROR; |
| 405 | } |
| 406 | } |
| 407 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 408 | static void writeStringToParcel(Parcel &p, const char *s) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 409 | char16_t *s16; |
| 410 | size_t s16_len; |
| 411 | s16 = strdup8to16(s, &s16_len); |
| 412 | p.writeString16(s16, s16_len); |
| 413 | free(s16); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 418 | memsetString (char *s) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 419 | if (s != NULL) { |
| 420 | memset (s, 0, strlen(s)); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize, |
| 425 | const size_t* objects, size_t objectsSize, |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 426 | void* cookie) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 427 | // do nothing -- the data reference lives longer than the Parcel object |
| 428 | } |
| 429 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 430 | /** |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 431 | * To be called from dispatch thread |
| 432 | * Issue a single local request, ensuring that the response |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 433 | * is not sent back up to the command process |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 434 | */ |
| 435 | static void |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 436 | 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] | 437 | RequestInfo *pRI; |
| 438 | int ret; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 439 | /* Hook for current context */ |
| 440 | /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */ |
| 441 | pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex; |
| 442 | /* pendingRequestsHook refer to &s_pendingRequests */ |
| 443 | RequestInfo** pendingRequestsHook = &s_pendingRequests; |
| 444 | |
| 445 | #if (SIM_COUNT == 2) |
| 446 | if (socket_id == RIL_SOCKET_2) { |
| 447 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2; |
| 448 | pendingRequestsHook = &s_pendingRequests_socket2; |
| 449 | } |
| 450 | #endif |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 451 | |
| 452 | pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 453 | |
| 454 | pRI->local = 1; |
| 455 | pRI->token = 0xffffffff; // token is not used in this context |
| 456 | pRI->pCI = &(s_commands[request]); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 457 | pRI->socket_id = socket_id; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 458 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 459 | ret = pthread_mutex_lock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 460 | assert (ret == 0); |
| 461 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 462 | pRI->p_next = *pendingRequestsHook; |
| 463 | *pendingRequestsHook = pRI; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 464 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 465 | ret = pthread_mutex_unlock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 466 | assert (ret == 0); |
| 467 | |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 468 | RLOGD("C[locl]> %s", requestToString(request)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 469 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 470 | CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | |
| 474 | |
| 475 | static int |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 476 | 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] | 477 | Parcel p; |
| 478 | status_t status; |
| 479 | int32_t request; |
| 480 | int32_t token; |
| 481 | RequestInfo *pRI; |
| 482 | int ret; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 483 | /* Hook for current context */ |
| 484 | /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */ |
| 485 | pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex; |
| 486 | /* pendingRequestsHook refer to &s_pendingRequests */ |
| 487 | RequestInfo** pendingRequestsHook = &s_pendingRequests; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 488 | |
| 489 | p.setData((uint8_t *) buffer, buflen); |
| 490 | |
| 491 | // status checked at end |
| 492 | status = p.readInt32(&request); |
| 493 | status = p.readInt32 (&token); |
| 494 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 495 | RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen); |
| 496 | |
| 497 | #if (SIM_COUNT >= 2) |
| 498 | if (socket_id == RIL_SOCKET_2) { |
| 499 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2; |
| 500 | pendingRequestsHook = &s_pendingRequests_socket2; |
| 501 | } |
| 502 | #if (SIM_COUNT >= 3) |
| 503 | else if (socket_id == RIL_SOCKET_3) { |
| 504 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3; |
| 505 | pendingRequestsHook = &s_pendingRequests_socket3; |
| 506 | } |
| 507 | #endif |
| 508 | #if (SIM_COUNT >= 4) |
| 509 | else if (socket_id == RIL_SOCKET_4) { |
| 510 | pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4; |
| 511 | pendingRequestsHook = &s_pendingRequests_socket4; |
| 512 | } |
| 513 | #endif |
| 514 | #endif |
| 515 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 516 | if (status != NO_ERROR) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 517 | RLOGE("invalid request block"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 522 | Parcel pErr; |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 523 | RLOGE("unsupported request code %d token %d", request, token); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 524 | // FIXME this should perhaps return a response |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 525 | pErr.writeInt32 (RESPONSE_SOLICITED); |
| 526 | pErr.writeInt32 (token); |
| 527 | pErr.writeInt32 (RIL_E_GENERIC_FAILURE); |
| 528 | |
| 529 | sendResponse(pErr, socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | |
| 534 | pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo)); |
| 535 | |
| 536 | pRI->token = token; |
| 537 | pRI->pCI = &(s_commands[request]); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 538 | pRI->socket_id = socket_id; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 539 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 540 | ret = pthread_mutex_lock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 541 | assert (ret == 0); |
| 542 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 543 | pRI->p_next = *pendingRequestsHook; |
| 544 | *pendingRequestsHook = pRI; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 545 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 546 | ret = pthread_mutex_unlock(pendingRequestsMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 547 | assert (ret == 0); |
| 548 | |
| 549 | /* sLastDispatchedToken = token; */ |
| 550 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 551 | pRI->pCI->dispatchFunction(p, pRI); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 557 | invalidCommandBlock (RequestInfo *pRI) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 558 | RLOGE("invalid command block for token %d request %s", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 559 | pRI->token, requestToString(pRI->pCI->requestNumber)); |
| 560 | } |
| 561 | |
| 562 | /** Callee expects NULL */ |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 563 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 564 | dispatchVoid (Parcel& p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 565 | clearPrintBuf; |
| 566 | printRequest(pRI->token, pRI->pCI->requestNumber); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 567 | 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] | 568 | } |
| 569 | |
| 570 | /** Callee expects const char * */ |
| 571 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 572 | dispatchString (Parcel& p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 573 | status_t status; |
| 574 | size_t datalen; |
| 575 | size_t stringlen; |
| 576 | char *string8 = NULL; |
| 577 | |
| 578 | string8 = strdupReadString(p); |
| 579 | |
| 580 | startRequest; |
| 581 | appendPrintBuf("%s%s", printBuf, string8); |
| 582 | closeRequest; |
| 583 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 584 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 585 | CALL_ONREQUEST(pRI->pCI->requestNumber, string8, |
| 586 | sizeof(char *), pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 587 | |
| 588 | #ifdef MEMSET_FREED |
| 589 | memsetString(string8); |
| 590 | #endif |
| 591 | |
| 592 | free(string8); |
| 593 | return; |
| 594 | invalid: |
| 595 | invalidCommandBlock(pRI); |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | /** Callee expects const char ** */ |
| 600 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 601 | dispatchStrings (Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 602 | int32_t countStrings; |
| 603 | status_t status; |
| 604 | size_t datalen; |
| 605 | char **pStrings; |
| 606 | |
| 607 | status = p.readInt32 (&countStrings); |
| 608 | |
| 609 | if (status != NO_ERROR) { |
| 610 | goto invalid; |
| 611 | } |
| 612 | |
| 613 | startRequest; |
| 614 | if (countStrings == 0) { |
| 615 | // just some non-null pointer |
| 616 | pStrings = (char **)alloca(sizeof(char *)); |
| 617 | datalen = 0; |
| 618 | } else if (((int)countStrings) == -1) { |
| 619 | pStrings = NULL; |
| 620 | datalen = 0; |
| 621 | } else { |
| 622 | datalen = sizeof(char *) * countStrings; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 623 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 624 | pStrings = (char **)alloca(datalen); |
| 625 | |
| 626 | for (int i = 0 ; i < countStrings ; i++) { |
| 627 | pStrings[i] = strdupReadString(p); |
| 628 | appendPrintBuf("%s%s,", printBuf, pStrings[i]); |
| 629 | } |
| 630 | } |
| 631 | removeLastChar; |
| 632 | closeRequest; |
| 633 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 634 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 635 | 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] | 636 | |
| 637 | if (pStrings != NULL) { |
| 638 | for (int i = 0 ; i < countStrings ; i++) { |
| 639 | #ifdef MEMSET_FREED |
| 640 | memsetString (pStrings[i]); |
| 641 | #endif |
| 642 | free(pStrings[i]); |
| 643 | } |
| 644 | |
| 645 | #ifdef MEMSET_FREED |
| 646 | memset(pStrings, 0, datalen); |
| 647 | #endif |
| 648 | } |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 649 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 650 | return; |
| 651 | invalid: |
| 652 | invalidCommandBlock(pRI); |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | /** Callee expects const int * */ |
| 657 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 658 | dispatchInts (Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 659 | int32_t count; |
| 660 | status_t status; |
| 661 | size_t datalen; |
| 662 | int *pInts; |
| 663 | |
| 664 | status = p.readInt32 (&count); |
| 665 | |
| 666 | if (status != NO_ERROR || count == 0) { |
| 667 | goto invalid; |
| 668 | } |
| 669 | |
| 670 | datalen = sizeof(int) * count; |
| 671 | pInts = (int *)alloca(datalen); |
| 672 | |
| 673 | startRequest; |
| 674 | for (int i = 0 ; i < count ; i++) { |
| 675 | int32_t t; |
| 676 | |
| 677 | status = p.readInt32(&t); |
| 678 | pInts[i] = (int)t; |
| 679 | appendPrintBuf("%s%d,", printBuf, t); |
| 680 | |
| 681 | if (status != NO_ERROR) { |
| 682 | goto invalid; |
| 683 | } |
| 684 | } |
| 685 | removeLastChar; |
| 686 | closeRequest; |
| 687 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 688 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 689 | CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts), |
| 690 | datalen, pRI, pRI->socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 691 | |
| 692 | #ifdef MEMSET_FREED |
| 693 | memset(pInts, 0, datalen); |
| 694 | #endif |
| 695 | |
| 696 | return; |
| 697 | invalid: |
| 698 | invalidCommandBlock(pRI); |
| 699 | return; |
| 700 | } |
| 701 | |
| 702 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 703 | /** |
| 704 | * Callee expects const RIL_SMS_WriteArgs * |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 705 | * Payload is: |
| 706 | * int32_t status |
| 707 | * String pdu |
| 708 | */ |
| 709 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 710 | dispatchSmsWrite (Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 711 | RIL_SMS_WriteArgs args; |
| 712 | int32_t t; |
| 713 | status_t status; |
| 714 | |
| 715 | memset (&args, 0, sizeof(args)); |
| 716 | |
| 717 | status = p.readInt32(&t); |
| 718 | args.status = (int)t; |
| 719 | |
| 720 | args.pdu = strdupReadString(p); |
| 721 | |
| 722 | if (status != NO_ERROR || args.pdu == NULL) { |
| 723 | goto invalid; |
| 724 | } |
| 725 | |
| 726 | args.smsc = strdupReadString(p); |
| 727 | |
| 728 | startRequest; |
| 729 | appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status, |
| 730 | (char*)args.pdu, (char*)args.smsc); |
| 731 | closeRequest; |
| 732 | printRequest(pRI->token, pRI->pCI->requestNumber); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 733 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 734 | 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] | 735 | |
| 736 | #ifdef MEMSET_FREED |
| 737 | memsetString (args.pdu); |
| 738 | #endif |
| 739 | |
| 740 | free (args.pdu); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 741 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 742 | #ifdef MEMSET_FREED |
| 743 | memset(&args, 0, sizeof(args)); |
| 744 | #endif |
| 745 | |
| 746 | return; |
| 747 | invalid: |
| 748 | invalidCommandBlock(pRI); |
| 749 | return; |
| 750 | } |
| 751 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 752 | /** |
| 753 | * Callee expects const RIL_Dial * |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 754 | * Payload is: |
| 755 | * String address |
| 756 | * int32_t clir |
| 757 | */ |
| 758 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 759 | dispatchDial (Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 760 | RIL_Dial dial; |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 761 | RIL_UUS_Info uusInfo; |
Wink Saville | 7bce082 | 2010-01-08 15:20:12 -0800 | [diff] [blame] | 762 | int32_t sizeOfDial; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 763 | int32_t t; |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 764 | int32_t uusPresent; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 765 | status_t status; |
| 766 | |
| 767 | memset (&dial, 0, sizeof(dial)); |
| 768 | |
| 769 | dial.address = strdupReadString(p); |
| 770 | |
| 771 | status = p.readInt32(&t); |
| 772 | dial.clir = (int)t; |
| 773 | |
| 774 | if (status != NO_ERROR || dial.address == NULL) { |
| 775 | goto invalid; |
| 776 | } |
| 777 | |
Wink Saville | 3a4840b | 2010-04-07 13:29:58 -0700 | [diff] [blame] | 778 | if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3 |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 779 | uusPresent = 0; |
Wink Saville | 7bce082 | 2010-01-08 15:20:12 -0800 | [diff] [blame] | 780 | sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *); |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 781 | } else { |
| 782 | status = p.readInt32(&uusPresent); |
| 783 | |
| 784 | if (status != NO_ERROR) { |
| 785 | goto invalid; |
| 786 | } |
| 787 | |
| 788 | if (uusPresent == 0) { |
| 789 | dial.uusInfo = NULL; |
| 790 | } else { |
| 791 | int32_t len; |
| 792 | |
| 793 | memset(&uusInfo, 0, sizeof(RIL_UUS_Info)); |
| 794 | |
| 795 | status = p.readInt32(&t); |
| 796 | uusInfo.uusType = (RIL_UUS_Type) t; |
| 797 | |
| 798 | status = p.readInt32(&t); |
| 799 | uusInfo.uusDcs = (RIL_UUS_DCS) t; |
| 800 | |
| 801 | status = p.readInt32(&len); |
| 802 | if (status != NO_ERROR) { |
| 803 | goto invalid; |
| 804 | } |
| 805 | |
| 806 | // The java code writes -1 for null arrays |
| 807 | if (((int) len) == -1) { |
| 808 | uusInfo.uusData = NULL; |
| 809 | len = 0; |
| 810 | } else { |
| 811 | uusInfo.uusData = (char*) p.readInplace(len); |
| 812 | } |
| 813 | |
| 814 | uusInfo.uusLength = len; |
| 815 | dial.uusInfo = &uusInfo; |
| 816 | } |
Wink Saville | 7bce082 | 2010-01-08 15:20:12 -0800 | [diff] [blame] | 817 | sizeOfDial = sizeof(dial); |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 818 | } |
| 819 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 820 | startRequest; |
| 821 | appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir); |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 822 | if (uusPresent) { |
| 823 | appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf, |
| 824 | dial.uusInfo->uusType, dial.uusInfo->uusDcs, |
| 825 | dial.uusInfo->uusLength); |
| 826 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 827 | closeRequest; |
| 828 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 829 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 830 | 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] | 831 | |
| 832 | #ifdef MEMSET_FREED |
| 833 | memsetString (dial.address); |
| 834 | #endif |
| 835 | |
| 836 | free (dial.address); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 837 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 838 | #ifdef MEMSET_FREED |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 839 | memset(&uusInfo, 0, sizeof(RIL_UUS_Info)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 840 | memset(&dial, 0, sizeof(dial)); |
| 841 | #endif |
| 842 | |
| 843 | return; |
| 844 | invalid: |
| 845 | invalidCommandBlock(pRI); |
| 846 | return; |
| 847 | } |
| 848 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 849 | /** |
| 850 | * Callee expects const RIL_SIM_IO * |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 851 | * Payload is: |
| 852 | * int32_t command |
| 853 | * int32_t fileid |
| 854 | * String path |
| 855 | * int32_t p1, p2, p3 |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 856 | * String data |
| 857 | * String pin2 |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 858 | * String aidPtr |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 859 | */ |
| 860 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 861 | dispatchSIM_IO (Parcel &p, RequestInfo *pRI) { |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 862 | union RIL_SIM_IO { |
| 863 | RIL_SIM_IO_v6 v6; |
| 864 | RIL_SIM_IO_v5 v5; |
| 865 | } simIO; |
| 866 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 867 | int32_t t; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 868 | int size; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 869 | status_t status; |
| 870 | |
| 871 | memset (&simIO, 0, sizeof(simIO)); |
| 872 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 873 | // note we only check status at the end |
| 874 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 875 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 876 | simIO.v6.command = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 877 | |
| 878 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 879 | simIO.v6.fileid = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 880 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 881 | simIO.v6.path = strdupReadString(p); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 882 | |
| 883 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 884 | simIO.v6.p1 = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 885 | |
| 886 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 887 | simIO.v6.p2 = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 888 | |
| 889 | status = p.readInt32(&t); |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 890 | simIO.v6.p3 = (int)t; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 891 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 892 | simIO.v6.data = strdupReadString(p); |
| 893 | simIO.v6.pin2 = strdupReadString(p); |
| 894 | simIO.v6.aidPtr = strdupReadString(p); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 895 | |
| 896 | startRequest; |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 897 | appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf, |
| 898 | simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path, |
| 899 | simIO.v6.p1, simIO.v6.p2, simIO.v6.p3, |
| 900 | (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] | 901 | closeRequest; |
| 902 | printRequest(pRI->token, pRI->pCI->requestNumber); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 903 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 904 | if (status != NO_ERROR) { |
| 905 | goto invalid; |
| 906 | } |
| 907 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 908 | size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6); |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 909 | 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] | 910 | |
| 911 | #ifdef MEMSET_FREED |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 912 | memsetString (simIO.v6.path); |
| 913 | memsetString (simIO.v6.data); |
| 914 | memsetString (simIO.v6.pin2); |
| 915 | memsetString (simIO.v6.aidPtr); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 916 | #endif |
| 917 | |
Wink Saville | c0114b3 | 2011-02-18 10:14:07 -0800 | [diff] [blame] | 918 | free (simIO.v6.path); |
| 919 | free (simIO.v6.data); |
| 920 | free (simIO.v6.pin2); |
| 921 | free (simIO.v6.aidPtr); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 922 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 923 | #ifdef MEMSET_FREED |
| 924 | memset(&simIO, 0, sizeof(simIO)); |
| 925 | #endif |
| 926 | |
| 927 | return; |
| 928 | invalid: |
| 929 | invalidCommandBlock(pRI); |
| 930 | return; |
| 931 | } |
| 932 | |
| 933 | /** |
Shishir Agrawal | 2458d8d | 2013-11-27 14:53:05 -0800 | [diff] [blame] | 934 | * Callee expects const RIL_SIM_APDU * |
| 935 | * Payload is: |
| 936 | * int32_t sessionid |
| 937 | * int32_t cla |
| 938 | * int32_t instruction |
| 939 | * int32_t p1, p2, p3 |
| 940 | * String data |
| 941 | */ |
| 942 | static void |
| 943 | dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) { |
| 944 | int32_t t; |
| 945 | status_t status; |
| 946 | RIL_SIM_APDU apdu; |
| 947 | |
| 948 | memset (&apdu, 0, sizeof(RIL_SIM_APDU)); |
| 949 | |
| 950 | // Note we only check status at the end. Any single failure leads to |
| 951 | // subsequent reads filing. |
| 952 | status = p.readInt32(&t); |
| 953 | apdu.sessionid = (int)t; |
| 954 | |
| 955 | status = p.readInt32(&t); |
| 956 | apdu.cla = (int)t; |
| 957 | |
| 958 | status = p.readInt32(&t); |
| 959 | apdu.instruction = (int)t; |
| 960 | |
| 961 | status = p.readInt32(&t); |
| 962 | apdu.p1 = (int)t; |
| 963 | |
| 964 | status = p.readInt32(&t); |
| 965 | apdu.p2 = (int)t; |
| 966 | |
| 967 | status = p.readInt32(&t); |
| 968 | apdu.p3 = (int)t; |
| 969 | |
| 970 | apdu.data = strdupReadString(p); |
| 971 | |
| 972 | startRequest; |
| 973 | appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s", |
| 974 | printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2, |
| 975 | apdu.p3, (char*)apdu.data); |
| 976 | closeRequest; |
| 977 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 978 | |
| 979 | if (status != NO_ERROR) { |
| 980 | goto invalid; |
| 981 | } |
| 982 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 983 | 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] | 984 | |
| 985 | #ifdef MEMSET_FREED |
| 986 | memsetString(apdu.data); |
| 987 | #endif |
| 988 | free(apdu.data); |
| 989 | |
| 990 | #ifdef MEMSET_FREED |
| 991 | memset(&apdu, 0, sizeof(RIL_SIM_APDU)); |
| 992 | #endif |
| 993 | |
| 994 | return; |
| 995 | invalid: |
| 996 | invalidCommandBlock(pRI); |
| 997 | return; |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | /** |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1002 | * Callee expects const RIL_CallForwardInfo * |
| 1003 | * Payload is: |
| 1004 | * int32_t status/action |
| 1005 | * int32_t reason |
| 1006 | * int32_t serviceCode |
| 1007 | * int32_t toa |
| 1008 | * String number (0 length -> null) |
| 1009 | * int32_t timeSeconds |
| 1010 | */ |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1011 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1012 | dispatchCallForward(Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1013 | RIL_CallForwardInfo cff; |
| 1014 | int32_t t; |
| 1015 | status_t status; |
| 1016 | |
| 1017 | memset (&cff, 0, sizeof(cff)); |
| 1018 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1019 | // note we only check status at the end |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1020 | |
| 1021 | status = p.readInt32(&t); |
| 1022 | cff.status = (int)t; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1023 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1024 | status = p.readInt32(&t); |
| 1025 | cff.reason = (int)t; |
| 1026 | |
| 1027 | status = p.readInt32(&t); |
| 1028 | cff.serviceClass = (int)t; |
| 1029 | |
| 1030 | status = p.readInt32(&t); |
| 1031 | cff.toa = (int)t; |
| 1032 | |
| 1033 | cff.number = strdupReadString(p); |
| 1034 | |
| 1035 | status = p.readInt32(&t); |
| 1036 | cff.timeSeconds = (int)t; |
| 1037 | |
| 1038 | if (status != NO_ERROR) { |
| 1039 | goto invalid; |
| 1040 | } |
| 1041 | |
| 1042 | // special case: number 0-length fields is null |
| 1043 | |
| 1044 | if (cff.number != NULL && strlen (cff.number) == 0) { |
| 1045 | cff.number = NULL; |
| 1046 | } |
| 1047 | |
| 1048 | startRequest; |
| 1049 | appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf, |
| 1050 | cff.status, cff.reason, cff.serviceClass, cff.toa, |
| 1051 | (char*)cff.number, cff.timeSeconds); |
| 1052 | closeRequest; |
| 1053 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1054 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1055 | 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] | 1056 | |
| 1057 | #ifdef MEMSET_FREED |
| 1058 | memsetString(cff.number); |
| 1059 | #endif |
| 1060 | |
| 1061 | free (cff.number); |
| 1062 | |
| 1063 | #ifdef MEMSET_FREED |
| 1064 | memset(&cff, 0, sizeof(cff)); |
| 1065 | #endif |
| 1066 | |
| 1067 | return; |
| 1068 | invalid: |
| 1069 | invalidCommandBlock(pRI); |
| 1070 | return; |
| 1071 | } |
| 1072 | |
| 1073 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1074 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1075 | dispatchRaw(Parcel &p, RequestInfo *pRI) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1076 | int32_t len; |
| 1077 | status_t status; |
| 1078 | const void *data; |
| 1079 | |
| 1080 | status = p.readInt32(&len); |
| 1081 | |
| 1082 | if (status != NO_ERROR) { |
| 1083 | goto invalid; |
| 1084 | } |
| 1085 | |
| 1086 | // The java code writes -1 for null arrays |
| 1087 | if (((int)len) == -1) { |
| 1088 | data = NULL; |
| 1089 | len = 0; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1090 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1091 | |
| 1092 | data = p.readInplace(len); |
| 1093 | |
| 1094 | startRequest; |
| 1095 | appendPrintBuf("%sraw_size=%d", printBuf, len); |
| 1096 | closeRequest; |
| 1097 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1098 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1099 | 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] | 1100 | |
| 1101 | return; |
| 1102 | invalid: |
| 1103 | invalidCommandBlock(pRI); |
| 1104 | return; |
| 1105 | } |
| 1106 | |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1107 | static status_t |
| 1108 | constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) { |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1109 | int32_t t; |
| 1110 | uint8_t ut; |
| 1111 | status_t status; |
| 1112 | int32_t digitCount; |
| 1113 | int digitLimit; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1114 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1115 | memset(&rcsm, 0, sizeof(rcsm)); |
| 1116 | |
| 1117 | status = p.readInt32(&t); |
| 1118 | rcsm.uTeleserviceID = (int) t; |
| 1119 | |
| 1120 | status = p.read(&ut,sizeof(ut)); |
| 1121 | rcsm.bIsServicePresent = (uint8_t) ut; |
| 1122 | |
| 1123 | status = p.readInt32(&t); |
| 1124 | rcsm.uServicecategory = (int) t; |
| 1125 | |
| 1126 | status = p.readInt32(&t); |
| 1127 | rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t; |
| 1128 | |
| 1129 | status = p.readInt32(&t); |
| 1130 | rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t; |
| 1131 | |
| 1132 | status = p.readInt32(&t); |
| 1133 | rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t; |
| 1134 | |
| 1135 | status = p.readInt32(&t); |
| 1136 | rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t; |
| 1137 | |
| 1138 | status = p.read(&ut,sizeof(ut)); |
| 1139 | rcsm.sAddress.number_of_digits= (uint8_t) ut; |
| 1140 | |
| 1141 | digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX); |
| 1142 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 1143 | status = p.read(&ut,sizeof(ut)); |
| 1144 | rcsm.sAddress.digits[digitCount] = (uint8_t) ut; |
| 1145 | } |
| 1146 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1147 | status = p.readInt32(&t); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1148 | rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t; |
| 1149 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1150 | status = p.read(&ut,sizeof(ut)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1151 | rcsm.sSubAddress.odd = (uint8_t) ut; |
| 1152 | |
| 1153 | status = p.read(&ut,sizeof(ut)); |
| 1154 | rcsm.sSubAddress.number_of_digits = (uint8_t) ut; |
| 1155 | |
| 1156 | digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1157 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 1158 | status = p.read(&ut,sizeof(ut)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1159 | rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut; |
| 1160 | } |
| 1161 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1162 | status = p.readInt32(&t); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1163 | rcsm.uBearerDataLen = (int) t; |
| 1164 | |
| 1165 | digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX); |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1166 | for(digitCount =0 ; digitCount < digitLimit; digitCount ++) { |
| 1167 | status = p.read(&ut, sizeof(ut)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1168 | rcsm.aBearerData[digitCount] = (uint8_t) ut; |
| 1169 | } |
| 1170 | |
| 1171 | if (status != NO_ERROR) { |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1172 | return status; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | startRequest; |
| 1176 | appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \ |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1177 | sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ", |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1178 | printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory, |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1179 | rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1180 | closeRequest; |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1181 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1182 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1183 | |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1184 | return status; |
| 1185 | } |
| 1186 | |
| 1187 | static void |
| 1188 | dispatchCdmaSms(Parcel &p, RequestInfo *pRI) { |
| 1189 | RIL_CDMA_SMS_Message rcsm; |
| 1190 | |
| 1191 | ALOGD("dispatchCdmaSms"); |
| 1192 | if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) { |
| 1193 | goto invalid; |
| 1194 | } |
| 1195 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1196 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1197 | |
| 1198 | #ifdef MEMSET_FREED |
| 1199 | memset(&rcsm, 0, sizeof(rcsm)); |
| 1200 | #endif |
| 1201 | |
| 1202 | return; |
| 1203 | |
| 1204 | invalid: |
| 1205 | invalidCommandBlock(pRI); |
| 1206 | return; |
| 1207 | } |
| 1208 | |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 1209 | static void |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1210 | dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) { |
| 1211 | RIL_IMS_SMS_Message rism; |
| 1212 | RIL_CDMA_SMS_Message rcsm; |
| 1213 | |
| 1214 | ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef); |
| 1215 | |
| 1216 | if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) { |
| 1217 | goto invalid; |
| 1218 | } |
| 1219 | memset(&rism, 0, sizeof(rism)); |
| 1220 | rism.tech = RADIO_TECH_3GPP2; |
| 1221 | rism.retry = retry; |
| 1222 | rism.messageRef = messageRef; |
| 1223 | rism.message.cdmaMessage = &rcsm; |
| 1224 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1225 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rism, |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1226 | sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t) |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1227 | +sizeof(rcsm),pRI, pRI->socket_id); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1228 | |
| 1229 | #ifdef MEMSET_FREED |
| 1230 | memset(&rcsm, 0, sizeof(rcsm)); |
| 1231 | memset(&rism, 0, sizeof(rism)); |
| 1232 | #endif |
| 1233 | |
| 1234 | return; |
| 1235 | |
| 1236 | invalid: |
| 1237 | invalidCommandBlock(pRI); |
| 1238 | return; |
| 1239 | } |
| 1240 | |
| 1241 | static void |
| 1242 | dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) { |
| 1243 | RIL_IMS_SMS_Message rism; |
| 1244 | int32_t countStrings; |
| 1245 | status_t status; |
| 1246 | size_t datalen; |
| 1247 | char **pStrings; |
| 1248 | ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef); |
| 1249 | |
| 1250 | status = p.readInt32 (&countStrings); |
| 1251 | |
| 1252 | if (status != NO_ERROR) { |
| 1253 | goto invalid; |
| 1254 | } |
| 1255 | |
| 1256 | memset(&rism, 0, sizeof(rism)); |
| 1257 | rism.tech = RADIO_TECH_3GPP; |
| 1258 | rism.retry = retry; |
| 1259 | rism.messageRef = messageRef; |
| 1260 | |
| 1261 | startRequest; |
Etan Cohen | 5d891b7 | 2014-02-27 17:25:17 -0800 | [diff] [blame] | 1262 | appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf, |
| 1263 | (int)rism.tech, (int)rism.retry, rism.messageRef); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1264 | if (countStrings == 0) { |
| 1265 | // just some non-null pointer |
| 1266 | pStrings = (char **)alloca(sizeof(char *)); |
| 1267 | datalen = 0; |
| 1268 | } else if (((int)countStrings) == -1) { |
| 1269 | pStrings = NULL; |
| 1270 | datalen = 0; |
| 1271 | } else { |
| 1272 | datalen = sizeof(char *) * countStrings; |
| 1273 | |
| 1274 | pStrings = (char **)alloca(datalen); |
| 1275 | |
| 1276 | for (int i = 0 ; i < countStrings ; i++) { |
| 1277 | pStrings[i] = strdupReadString(p); |
| 1278 | appendPrintBuf("%s%s,", printBuf, pStrings[i]); |
| 1279 | } |
| 1280 | } |
| 1281 | removeLastChar; |
| 1282 | closeRequest; |
| 1283 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1284 | |
| 1285 | rism.message.gsmMessage = pStrings; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1286 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rism, |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1287 | sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t) |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1288 | +datalen, pRI, pRI->socket_id); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1289 | |
| 1290 | if (pStrings != NULL) { |
| 1291 | for (int i = 0 ; i < countStrings ; i++) { |
| 1292 | #ifdef MEMSET_FREED |
| 1293 | memsetString (pStrings[i]); |
| 1294 | #endif |
| 1295 | free(pStrings[i]); |
| 1296 | } |
| 1297 | |
| 1298 | #ifdef MEMSET_FREED |
| 1299 | memset(pStrings, 0, datalen); |
| 1300 | #endif |
| 1301 | } |
| 1302 | |
| 1303 | #ifdef MEMSET_FREED |
| 1304 | memset(&rism, 0, sizeof(rism)); |
| 1305 | #endif |
| 1306 | return; |
| 1307 | invalid: |
| 1308 | ALOGE("dispatchImsGsmSms invalid block"); |
| 1309 | invalidCommandBlock(pRI); |
| 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | static void |
| 1314 | dispatchImsSms(Parcel &p, RequestInfo *pRI) { |
| 1315 | int32_t t; |
| 1316 | status_t status = p.readInt32(&t); |
| 1317 | RIL_RadioTechnologyFamily format; |
| 1318 | uint8_t retry; |
| 1319 | int32_t messageRef; |
| 1320 | |
| 1321 | ALOGD("dispatchImsSms"); |
| 1322 | if (status != NO_ERROR) { |
| 1323 | goto invalid; |
| 1324 | } |
| 1325 | format = (RIL_RadioTechnologyFamily) t; |
| 1326 | |
| 1327 | // read retry field |
| 1328 | status = p.read(&retry,sizeof(retry)); |
| 1329 | if (status != NO_ERROR) { |
| 1330 | goto invalid; |
| 1331 | } |
| 1332 | // read messageRef field |
| 1333 | status = p.read(&messageRef,sizeof(messageRef)); |
| 1334 | if (status != NO_ERROR) { |
| 1335 | goto invalid; |
| 1336 | } |
| 1337 | |
| 1338 | if (RADIO_TECH_3GPP == format) { |
| 1339 | dispatchImsGsmSms(p, pRI, retry, messageRef); |
| 1340 | } else if (RADIO_TECH_3GPP2 == format) { |
| 1341 | dispatchImsCdmaSms(p, pRI, retry, messageRef); |
| 1342 | } else { |
| 1343 | ALOGE("requestImsSendSMS invalid format value =%d", format); |
| 1344 | } |
| 1345 | |
| 1346 | return; |
| 1347 | |
| 1348 | invalid: |
| 1349 | invalidCommandBlock(pRI); |
| 1350 | return; |
| 1351 | } |
| 1352 | |
| 1353 | static void |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1354 | dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) { |
| 1355 | RIL_CDMA_SMS_Ack rcsa; |
| 1356 | int32_t t; |
| 1357 | status_t status; |
| 1358 | int32_t digitCount; |
| 1359 | |
| 1360 | memset(&rcsa, 0, sizeof(rcsa)); |
| 1361 | |
| 1362 | status = p.readInt32(&t); |
| 1363 | rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t; |
| 1364 | |
| 1365 | status = p.readInt32(&t); |
| 1366 | rcsa.uSMSCauseCode = (int) t; |
| 1367 | |
| 1368 | if (status != NO_ERROR) { |
| 1369 | goto invalid; |
| 1370 | } |
| 1371 | |
| 1372 | startRequest; |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1373 | appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ", |
| 1374 | printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1375 | closeRequest; |
| 1376 | |
| 1377 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1378 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1379 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1380 | |
| 1381 | #ifdef MEMSET_FREED |
| 1382 | memset(&rcsa, 0, sizeof(rcsa)); |
| 1383 | #endif |
| 1384 | |
| 1385 | return; |
| 1386 | |
| 1387 | invalid: |
| 1388 | invalidCommandBlock(pRI); |
| 1389 | return; |
| 1390 | } |
| 1391 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1392 | static void |
| 1393 | dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) { |
| 1394 | int32_t t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1395 | status_t status; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1396 | int32_t num; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1397 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1398 | status = p.readInt32(&num); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1399 | if (status != NO_ERROR) { |
| 1400 | goto invalid; |
| 1401 | } |
| 1402 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1403 | { |
| 1404 | RIL_GSM_BroadcastSmsConfigInfo gsmBci[num]; |
| 1405 | RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num]; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1406 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1407 | startRequest; |
| 1408 | for (int i = 0 ; i < num ; i++ ) { |
| 1409 | gsmBciPtrs[i] = &gsmBci[i]; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1410 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1411 | status = p.readInt32(&t); |
| 1412 | gsmBci[i].fromServiceId = (int) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1413 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1414 | status = p.readInt32(&t); |
| 1415 | gsmBci[i].toServiceId = (int) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1416 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1417 | status = p.readInt32(&t); |
| 1418 | gsmBci[i].fromCodeScheme = (int) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1419 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1420 | status = p.readInt32(&t); |
| 1421 | gsmBci[i].toCodeScheme = (int) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1422 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1423 | status = p.readInt32(&t); |
| 1424 | gsmBci[i].selected = (uint8_t) t; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1425 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1426 | appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \ |
| 1427 | fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i, |
| 1428 | gsmBci[i].fromServiceId, gsmBci[i].toServiceId, |
| 1429 | gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme, |
| 1430 | gsmBci[i].selected); |
| 1431 | } |
| 1432 | closeRequest; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1433 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1434 | if (status != NO_ERROR) { |
| 1435 | goto invalid; |
| 1436 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1437 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1438 | CALL_ONREQUEST(pRI->pCI->requestNumber, |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1439 | gsmBciPtrs, |
| 1440 | num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *), |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1441 | pRI, pRI->socket_id); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1442 | |
| 1443 | #ifdef MEMSET_FREED |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1444 | memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo)); |
| 1445 | memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1446 | #endif |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1447 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1448 | |
| 1449 | return; |
| 1450 | |
| 1451 | invalid: |
| 1452 | invalidCommandBlock(pRI); |
| 1453 | return; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1454 | } |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1455 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1456 | static void |
| 1457 | dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) { |
| 1458 | int32_t t; |
| 1459 | status_t status; |
| 1460 | int32_t num; |
| 1461 | |
| 1462 | status = p.readInt32(&num); |
| 1463 | if (status != NO_ERROR) { |
| 1464 | goto invalid; |
| 1465 | } |
| 1466 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1467 | { |
| 1468 | RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num]; |
| 1469 | RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num]; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1470 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1471 | startRequest; |
| 1472 | for (int i = 0 ; i < num ; i++ ) { |
| 1473 | cdmaBciPtrs[i] = &cdmaBci[i]; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1474 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1475 | status = p.readInt32(&t); |
| 1476 | cdmaBci[i].service_category = (int) t; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1477 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1478 | status = p.readInt32(&t); |
| 1479 | cdmaBci[i].language = (int) t; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1480 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1481 | status = p.readInt32(&t); |
| 1482 | cdmaBci[i].selected = (uint8_t) t; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1483 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1484 | appendPrintBuf("%s [%d: service_category=%d, language =%d, \ |
| 1485 | entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category, |
| 1486 | cdmaBci[i].language, cdmaBci[i].selected); |
| 1487 | } |
| 1488 | closeRequest; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1489 | |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1490 | if (status != NO_ERROR) { |
| 1491 | goto invalid; |
| 1492 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1493 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1494 | CALL_ONREQUEST(pRI->pCI->requestNumber, |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1495 | cdmaBciPtrs, |
| 1496 | num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *), |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1497 | pRI, pRI->socket_id); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1498 | |
| 1499 | #ifdef MEMSET_FREED |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1500 | memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo)); |
| 1501 | memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *)); |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1502 | #endif |
Kevin Schoedel | 96dcdbc | 2012-05-25 17:00:17 -0400 | [diff] [blame] | 1503 | } |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1504 | |
| 1505 | return; |
| 1506 | |
| 1507 | invalid: |
| 1508 | invalidCommandBlock(pRI); |
| 1509 | return; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) { |
| 1513 | RIL_CDMA_SMS_WriteArgs rcsw; |
| 1514 | int32_t t; |
| 1515 | uint32_t ut; |
| 1516 | uint8_t uct; |
| 1517 | status_t status; |
| 1518 | int32_t digitCount; |
| 1519 | |
| 1520 | memset(&rcsw, 0, sizeof(rcsw)); |
| 1521 | |
| 1522 | status = p.readInt32(&t); |
| 1523 | rcsw.status = t; |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1524 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1525 | status = p.readInt32(&t); |
| 1526 | rcsw.message.uTeleserviceID = (int) t; |
| 1527 | |
| 1528 | status = p.read(&uct,sizeof(uct)); |
| 1529 | rcsw.message.bIsServicePresent = (uint8_t) uct; |
| 1530 | |
| 1531 | status = p.readInt32(&t); |
| 1532 | rcsw.message.uServicecategory = (int) t; |
| 1533 | |
| 1534 | status = p.readInt32(&t); |
| 1535 | rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t; |
| 1536 | |
| 1537 | status = p.readInt32(&t); |
| 1538 | rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t; |
| 1539 | |
| 1540 | status = p.readInt32(&t); |
| 1541 | rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t; |
| 1542 | |
| 1543 | status = p.readInt32(&t); |
| 1544 | rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t; |
| 1545 | |
| 1546 | status = p.read(&uct,sizeof(uct)); |
| 1547 | rcsw.message.sAddress.number_of_digits = (uint8_t) uct; |
| 1548 | |
| 1549 | for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) { |
| 1550 | status = p.read(&uct,sizeof(uct)); |
| 1551 | rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct; |
| 1552 | } |
| 1553 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1554 | status = p.readInt32(&t); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1555 | rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t; |
| 1556 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1557 | status = p.read(&uct,sizeof(uct)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1558 | rcsw.message.sSubAddress.odd = (uint8_t) uct; |
| 1559 | |
| 1560 | status = p.read(&uct,sizeof(uct)); |
| 1561 | rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct; |
| 1562 | |
| 1563 | for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) { |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1564 | status = p.read(&uct,sizeof(uct)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1565 | rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct; |
| 1566 | } |
| 1567 | |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1568 | status = p.readInt32(&t); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1569 | rcsw.message.uBearerDataLen = (int) t; |
| 1570 | |
| 1571 | for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) { |
Wink Saville | a592eeb | 2009-05-22 13:26:36 -0700 | [diff] [blame] | 1572 | status = p.read(&uct, sizeof(uct)); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1573 | rcsw.message.aBearerData[digitCount] = (uint8_t) uct; |
| 1574 | } |
| 1575 | |
| 1576 | if (status != NO_ERROR) { |
| 1577 | goto invalid; |
| 1578 | } |
| 1579 | |
| 1580 | startRequest; |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1581 | appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \ |
| 1582 | message.uServicecategory=%d, message.sAddress.digit_mode=%d, \ |
| 1583 | message.sAddress.number_mode=%d, \ |
| 1584 | message.sAddress.number_type=%d, ", |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1585 | printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent, |
Wink Saville | 1b5fd23 | 2009-04-22 14:50:00 -0700 | [diff] [blame] | 1586 | rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode, |
| 1587 | rcsw.message.sAddress.number_mode, |
| 1588 | rcsw.message.sAddress.number_type); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1589 | closeRequest; |
| 1590 | |
| 1591 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1592 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1593 | CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1594 | |
| 1595 | #ifdef MEMSET_FREED |
| 1596 | memset(&rcsw, 0, sizeof(rcsw)); |
| 1597 | #endif |
| 1598 | |
| 1599 | return; |
| 1600 | |
| 1601 | invalid: |
| 1602 | invalidCommandBlock(pRI); |
| 1603 | return; |
| 1604 | |
| 1605 | } |
| 1606 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1607 | // For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL. |
| 1608 | // Version 4 of the RIL interface adds a new PDP type parameter to support |
| 1609 | // IPv6 and dual-stack PDP contexts. When dealing with a previous version of |
| 1610 | // RIL, remove the parameter from the request. |
| 1611 | static void dispatchDataCall(Parcel& p, RequestInfo *pRI) { |
| 1612 | // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters. |
| 1613 | const int numParamsRilV3 = 6; |
| 1614 | |
| 1615 | // The first bytes of the RIL parcel contain the request number and the |
| 1616 | // serial number - see processCommandBuffer(). Copy them over too. |
| 1617 | int pos = p.dataPosition(); |
| 1618 | |
| 1619 | int numParams = p.readInt32(); |
| 1620 | if (s_callbacks.version < 4 && numParams > numParamsRilV3) { |
| 1621 | Parcel p2; |
| 1622 | p2.appendFrom(&p, 0, pos); |
| 1623 | p2.writeInt32(numParamsRilV3); |
| 1624 | for(int i = 0; i < numParamsRilV3; i++) { |
| 1625 | p2.writeString16(p.readString16()); |
| 1626 | } |
| 1627 | p2.setDataPosition(pos); |
| 1628 | dispatchStrings(p2, pRI); |
| 1629 | } else { |
Lorenzo Colitti | 57ce1f2 | 2010-09-13 12:23:50 -0700 | [diff] [blame] | 1630 | p.setDataPosition(pos); |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1631 | dispatchStrings(p, pRI); |
| 1632 | } |
| 1633 | } |
| 1634 | |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 1635 | // For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH. |
| 1636 | // When all RILs handle this request, this function can be removed and |
| 1637 | // the request can be sent directly to the RIL using dispatchVoid. |
| 1638 | static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1639 | RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id); |
Naveen Kalla | 2bc78d6 | 2011-12-07 16:22:53 -0800 | [diff] [blame] | 1640 | |
| 1641 | if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) { |
| 1642 | RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0); |
| 1643 | } |
| 1644 | |
| 1645 | // RILs that support RADIO_STATE_ON should support this request. |
| 1646 | if (RADIO_STATE_ON == state) { |
| 1647 | dispatchVoid(p, pRI); |
| 1648 | return; |
| 1649 | } |
| 1650 | |
| 1651 | // For Older RILs, that do not support RADIO_STATE_ON, assume that they |
| 1652 | // will not support this new request either and decode Voice Radio Technology |
| 1653 | // from Radio State |
| 1654 | voiceRadioTech = decodeVoiceRadioTechnology(state); |
| 1655 | |
| 1656 | if (voiceRadioTech < 0) |
| 1657 | RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1658 | else |
| 1659 | RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int)); |
| 1660 | } |
| 1661 | |
| 1662 | // For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:. |
| 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 dispatchCdmaSubscriptionSource(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 CDMA Subscription Source |
| 1680 | // from Radio State |
| 1681 | cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state); |
| 1682 | |
| 1683 | if (cdmaSubscriptionSource < 0) |
| 1684 | RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1685 | else |
| 1686 | RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int)); |
| 1687 | } |
| 1688 | |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 1689 | static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI) |
| 1690 | { |
| 1691 | RIL_InitialAttachApn pf; |
| 1692 | int32_t t; |
| 1693 | status_t status; |
| 1694 | |
| 1695 | memset(&pf, 0, sizeof(pf)); |
| 1696 | |
| 1697 | pf.apn = strdupReadString(p); |
| 1698 | pf.protocol = strdupReadString(p); |
| 1699 | |
| 1700 | status = p.readInt32(&t); |
| 1701 | pf.authtype = (int) t; |
| 1702 | |
| 1703 | pf.username = strdupReadString(p); |
| 1704 | pf.password = strdupReadString(p); |
| 1705 | |
| 1706 | startRequest; |
Etan Cohen | 5d891b7 | 2014-02-27 17:25:17 -0800 | [diff] [blame] | 1707 | appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s", |
| 1708 | printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password); |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 1709 | closeRequest; |
| 1710 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1711 | |
| 1712 | if (status != NO_ERROR) { |
| 1713 | goto invalid; |
| 1714 | } |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1715 | CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id); |
Sungmin Choi | 7569753 | 2013-04-26 15:04:45 -0700 | [diff] [blame] | 1716 | |
| 1717 | #ifdef MEMSET_FREED |
| 1718 | memsetString(pf.apn); |
| 1719 | memsetString(pf.protocol); |
| 1720 | memsetString(pf.username); |
| 1721 | memsetString(pf.password); |
| 1722 | #endif |
| 1723 | |
| 1724 | free(pf.apn); |
| 1725 | free(pf.protocol); |
| 1726 | free(pf.username); |
| 1727 | free(pf.password); |
| 1728 | |
| 1729 | #ifdef MEMSET_FREED |
| 1730 | memset(&pf, 0, sizeof(pf)); |
| 1731 | #endif |
| 1732 | |
| 1733 | return; |
| 1734 | invalid: |
| 1735 | invalidCommandBlock(pRI); |
| 1736 | return; |
| 1737 | } |
| 1738 | |
Jake Hamby | 8a4a233 | 2014-01-15 13:12:05 -0800 | [diff] [blame] | 1739 | static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) { |
| 1740 | RIL_NV_ReadItem nvri; |
| 1741 | int32_t t; |
| 1742 | status_t status; |
| 1743 | |
| 1744 | memset(&nvri, 0, sizeof(nvri)); |
| 1745 | |
| 1746 | status = p.readInt32(&t); |
| 1747 | nvri.itemID = (RIL_NV_Item) t; |
| 1748 | |
| 1749 | if (status != NO_ERROR) { |
| 1750 | goto invalid; |
| 1751 | } |
| 1752 | |
| 1753 | startRequest; |
| 1754 | appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID); |
| 1755 | closeRequest; |
| 1756 | |
| 1757 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1758 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1759 | CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id); |
Jake Hamby | 8a4a233 | 2014-01-15 13:12:05 -0800 | [diff] [blame] | 1760 | |
| 1761 | #ifdef MEMSET_FREED |
| 1762 | memset(&nvri, 0, sizeof(nvri)); |
| 1763 | #endif |
| 1764 | |
| 1765 | return; |
| 1766 | |
| 1767 | invalid: |
| 1768 | invalidCommandBlock(pRI); |
| 1769 | return; |
| 1770 | } |
| 1771 | |
| 1772 | static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) { |
| 1773 | RIL_NV_WriteItem nvwi; |
| 1774 | int32_t t; |
| 1775 | status_t status; |
| 1776 | |
| 1777 | memset(&nvwi, 0, sizeof(nvwi)); |
| 1778 | |
| 1779 | status = p.readInt32(&t); |
| 1780 | nvwi.itemID = (RIL_NV_Item) t; |
| 1781 | |
| 1782 | nvwi.value = strdupReadString(p); |
| 1783 | |
| 1784 | if (status != NO_ERROR || nvwi.value == NULL) { |
| 1785 | goto invalid; |
| 1786 | } |
| 1787 | |
| 1788 | startRequest; |
| 1789 | appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID, |
| 1790 | nvwi.value); |
| 1791 | closeRequest; |
| 1792 | |
| 1793 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1794 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1795 | CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id); |
Jake Hamby | 8a4a233 | 2014-01-15 13:12:05 -0800 | [diff] [blame] | 1796 | |
| 1797 | #ifdef MEMSET_FREED |
| 1798 | memsetString(nvwi.value); |
| 1799 | #endif |
| 1800 | |
| 1801 | free(nvwi.value); |
| 1802 | |
| 1803 | #ifdef MEMSET_FREED |
| 1804 | memset(&nvwi, 0, sizeof(nvwi)); |
| 1805 | #endif |
| 1806 | |
| 1807 | return; |
| 1808 | |
| 1809 | invalid: |
| 1810 | invalidCommandBlock(pRI); |
| 1811 | return; |
| 1812 | } |
| 1813 | |
| 1814 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1815 | static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) { |
| 1816 | RIL_SelectUiccSub uicc_sub; |
| 1817 | status_t status; |
| 1818 | int32_t t; |
| 1819 | memset(&uicc_sub, 0, sizeof(uicc_sub)); |
| 1820 | |
| 1821 | status = p.readInt32(&t); |
| 1822 | if (status != NO_ERROR) { |
| 1823 | goto invalid; |
| 1824 | } |
| 1825 | uicc_sub.slot = (int) t; |
| 1826 | |
| 1827 | status = p.readInt32(&t); |
| 1828 | if (status != NO_ERROR) { |
| 1829 | goto invalid; |
| 1830 | } |
| 1831 | uicc_sub.app_index = (int) t; |
| 1832 | |
| 1833 | status = p.readInt32(&t); |
| 1834 | if (status != NO_ERROR) { |
| 1835 | goto invalid; |
| 1836 | } |
| 1837 | uicc_sub.sub_type = (RIL_SubscriptionType) t; |
| 1838 | |
| 1839 | status = p.readInt32(&t); |
| 1840 | if (status != NO_ERROR) { |
| 1841 | goto invalid; |
| 1842 | } |
| 1843 | uicc_sub.act_status = (RIL_UiccSubActStatus) t; |
| 1844 | |
| 1845 | startRequest; |
| 1846 | appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index, |
| 1847 | uicc_sub.act_status); |
| 1848 | RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, |
| 1849 | uicc_sub.app_index, uicc_sub.act_status); |
| 1850 | closeRequest; |
| 1851 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1852 | |
| 1853 | CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id); |
| 1854 | |
| 1855 | #ifdef MEMSET_FREED |
| 1856 | memset(&uicc_sub, 0, sizeof(uicc_sub)); |
| 1857 | #endif |
| 1858 | return; |
| 1859 | |
| 1860 | invalid: |
| 1861 | invalidCommandBlock(pRI); |
| 1862 | return; |
| 1863 | } |
| 1864 | |
Amit Mahajan | 90530a6 | 2014-07-01 15:54:08 -0700 | [diff] [blame] | 1865 | static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI) |
| 1866 | { |
| 1867 | RIL_SimAuthentication pf; |
| 1868 | int32_t t; |
| 1869 | status_t status; |
| 1870 | |
| 1871 | memset(&pf, 0, sizeof(pf)); |
| 1872 | |
| 1873 | status = p.readInt32(&t); |
| 1874 | pf.authContext = (int) t; |
| 1875 | pf.authData = strdupReadString(p); |
| 1876 | pf.aid = strdupReadString(p); |
| 1877 | |
| 1878 | startRequest; |
| 1879 | appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid); |
| 1880 | closeRequest; |
| 1881 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1882 | |
| 1883 | if (status != NO_ERROR) { |
| 1884 | goto invalid; |
| 1885 | } |
| 1886 | CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id); |
| 1887 | |
| 1888 | #ifdef MEMSET_FREED |
| 1889 | memsetString(pf.authData); |
| 1890 | memsetString(pf.aid); |
| 1891 | #endif |
| 1892 | |
| 1893 | free(pf.authData); |
| 1894 | free(pf.aid); |
| 1895 | |
| 1896 | #ifdef MEMSET_FREED |
| 1897 | memset(&pf, 0, sizeof(pf)); |
| 1898 | #endif |
| 1899 | |
| 1900 | return; |
| 1901 | invalid: |
| 1902 | invalidCommandBlock(pRI); |
| 1903 | return; |
| 1904 | } |
| 1905 | |
Amit Mahajan | c796e22 | 2014-08-13 16:54:01 +0000 | [diff] [blame] | 1906 | static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) { |
| 1907 | int32_t t; |
| 1908 | status_t status; |
| 1909 | int32_t num; |
| 1910 | |
| 1911 | status = p.readInt32(&num); |
| 1912 | if (status != NO_ERROR) { |
| 1913 | goto invalid; |
| 1914 | } |
| 1915 | |
| 1916 | { |
| 1917 | RIL_DataProfileInfo dataProfiles[num]; |
| 1918 | RIL_DataProfileInfo *dataProfilePtrs[num]; |
| 1919 | |
| 1920 | startRequest; |
| 1921 | for (int i = 0 ; i < num ; i++ ) { |
| 1922 | dataProfilePtrs[i] = &dataProfiles[i]; |
| 1923 | |
| 1924 | status = p.readInt32(&t); |
| 1925 | dataProfiles[i].profileId = (int) t; |
| 1926 | |
| 1927 | dataProfiles[i].apn = strdupReadString(p); |
| 1928 | dataProfiles[i].protocol = strdupReadString(p); |
| 1929 | status = p.readInt32(&t); |
| 1930 | dataProfiles[i].authType = (int) t; |
| 1931 | |
| 1932 | dataProfiles[i].user = strdupReadString(p); |
| 1933 | dataProfiles[i].password = strdupReadString(p); |
| 1934 | |
| 1935 | status = p.readInt32(&t); |
| 1936 | dataProfiles[i].type = (int) t; |
| 1937 | |
| 1938 | status = p.readInt32(&t); |
| 1939 | dataProfiles[i].maxConnsTime = (int) t; |
| 1940 | status = p.readInt32(&t); |
| 1941 | dataProfiles[i].maxConns = (int) t; |
| 1942 | status = p.readInt32(&t); |
| 1943 | dataProfiles[i].waitTime = (int) t; |
| 1944 | |
| 1945 | status = p.readInt32(&t); |
| 1946 | dataProfiles[i].enabled = (int) t; |
| 1947 | |
| 1948 | appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \ |
| 1949 | user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \ |
| 1950 | waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId, |
| 1951 | dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType, |
| 1952 | dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type, |
| 1953 | dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns, |
| 1954 | dataProfiles[i].waitTime, dataProfiles[i].enabled); |
| 1955 | } |
| 1956 | closeRequest; |
| 1957 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 1958 | |
| 1959 | if (status != NO_ERROR) { |
| 1960 | goto invalid; |
| 1961 | } |
| 1962 | CALL_ONREQUEST(pRI->pCI->requestNumber, |
| 1963 | dataProfilePtrs, |
| 1964 | num * sizeof(RIL_DataProfileInfo *), |
| 1965 | pRI, pRI->socket_id); |
| 1966 | |
| 1967 | #ifdef MEMSET_FREED |
| 1968 | memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo)); |
| 1969 | memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *)); |
| 1970 | #endif |
| 1971 | } |
| 1972 | |
| 1973 | return; |
| 1974 | |
| 1975 | invalid: |
| 1976 | invalidCommandBlock(pRI); |
| 1977 | return; |
| 1978 | } |
| 1979 | |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 1980 | static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){ |
| 1981 | RIL_RadioCapability rc; |
| 1982 | int32_t t; |
| 1983 | status_t status; |
| 1984 | |
| 1985 | memset (&rc, 0, sizeof(RIL_RadioCapability)); |
| 1986 | |
| 1987 | status = p.readInt32(&t); |
| 1988 | rc.version = (int)t; |
| 1989 | if (status != NO_ERROR) { |
| 1990 | goto invalid; |
| 1991 | } |
| 1992 | |
| 1993 | status = p.readInt32(&t); |
| 1994 | rc.session= (int)t; |
| 1995 | if (status != NO_ERROR) { |
| 1996 | goto invalid; |
| 1997 | } |
| 1998 | |
| 1999 | status = p.readInt32(&t); |
| 2000 | rc.phase= (int)t; |
| 2001 | if (status != NO_ERROR) { |
| 2002 | goto invalid; |
| 2003 | } |
| 2004 | |
| 2005 | status = p.readInt32(&t); |
| 2006 | rc.rat = (int)t; |
| 2007 | if (status != NO_ERROR) { |
| 2008 | goto invalid; |
| 2009 | } |
| 2010 | |
| 2011 | status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid)); |
| 2012 | if (status != NO_ERROR) { |
| 2013 | goto invalid; |
| 2014 | } |
| 2015 | |
| 2016 | status = p.readInt32(&t); |
| 2017 | rc.status = (int)t; |
| 2018 | |
| 2019 | if (status != NO_ERROR) { |
| 2020 | goto invalid; |
| 2021 | } |
| 2022 | |
| 2023 | startRequest; |
| 2024 | appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \ |
Legler Wu | 8caf06f | 2014-10-29 14:02:14 +0800 | [diff] [blame] | 2025 | logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session |
| 2026 | rc.phase, rc.rat, rc.logicalModemUuid, rc.session); |
Wink Saville | 8b4e4f7 | 2014-10-17 15:01:45 -0700 | [diff] [blame] | 2027 | |
| 2028 | closeRequest; |
| 2029 | printRequest(pRI->token, pRI->pCI->requestNumber); |
| 2030 | |
| 2031 | CALL_ONREQUEST(pRI->pCI->requestNumber, |
| 2032 | &rc, |
| 2033 | sizeof(RIL_RadioCapability), |
| 2034 | pRI, pRI->socket_id); |
| 2035 | return; |
| 2036 | invalid: |
| 2037 | invalidCommandBlock(pRI); |
| 2038 | return; |
| 2039 | } |
| 2040 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2041 | static int |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2042 | blockingWrite(int fd, const void *buffer, size_t len) { |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2043 | size_t writeOffset = 0; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2044 | const uint8_t *toWrite; |
| 2045 | |
| 2046 | toWrite = (const uint8_t *)buffer; |
| 2047 | |
| 2048 | while (writeOffset < len) { |
| 2049 | ssize_t written; |
| 2050 | do { |
| 2051 | written = write (fd, toWrite + writeOffset, |
| 2052 | len - writeOffset); |
Banavathu, Srinivas Naik | 3888490 | 2011-07-05 20:04:25 +0530 | [diff] [blame] | 2053 | } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN))); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2054 | |
| 2055 | if (written >= 0) { |
| 2056 | writeOffset += written; |
| 2057 | } else { // written < 0 |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2058 | 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] | 2059 | close(fd); |
| 2060 | return -1; |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
| 2067 | static int |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2068 | sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) { |
| 2069 | int fd = s_ril_param_socket.fdCommand; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2070 | int ret; |
| 2071 | uint32_t header; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2072 | pthread_mutex_t * writeMutexHook = &s_writeMutex; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2073 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2074 | RLOGE("Send Response to %s", rilSocketIdToString(socket_id)); |
| 2075 | |
| 2076 | #if (SIM_COUNT >= 2) |
| 2077 | if (socket_id == RIL_SOCKET_2) { |
| 2078 | fd = s_ril_param_socket2.fdCommand; |
| 2079 | writeMutexHook = &s_writeMutex_socket2; |
| 2080 | } |
| 2081 | #if (SIM_COUNT >= 3) |
| 2082 | else if (socket_id == RIL_SOCKET_3) { |
| 2083 | fd = s_ril_param_socket3.fdCommand; |
| 2084 | writeMutexHook = &s_writeMutex_socket3; |
| 2085 | } |
| 2086 | #endif |
| 2087 | #if (SIM_COUNT >= 4) |
| 2088 | else if (socket_id == RIL_SOCKET_4) { |
| 2089 | fd = s_ril_param_socket4.fdCommand; |
| 2090 | writeMutexHook = &s_writeMutex_socket4; |
| 2091 | } |
| 2092 | #endif |
| 2093 | #endif |
| 2094 | if (fd < 0) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2095 | return -1; |
| 2096 | } |
| 2097 | |
| 2098 | if (dataSize > MAX_COMMAND_BYTES) { |
Wink Saville | 8eb2a12 | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2099 | RLOGE("RIL: packet larger than %u (%u)", |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2100 | MAX_COMMAND_BYTES, (unsigned int )dataSize); |
| 2101 | |
| 2102 | return -1; |
| 2103 | } |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 2104 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2105 | pthread_mutex_lock(writeMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2106 | |
| 2107 | header = htonl(dataSize); |
| 2108 | |
| 2109 | ret = blockingWrite(fd, (void *)&header, sizeof(header)); |
| 2110 | |
| 2111 | if (ret < 0) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2112 | pthread_mutex_unlock(writeMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2113 | return ret; |
| 2114 | } |
| 2115 | |
Kenny | ee1fadc | 2009-08-13 00:45:53 +0800 | [diff] [blame] | 2116 | ret = blockingWrite(fd, data, dataSize); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2117 | |
| 2118 | if (ret < 0) { |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2119 | pthread_mutex_unlock(writeMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2120 | return ret; |
| 2121 | } |
| 2122 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2123 | pthread_mutex_unlock(writeMutexHook); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2124 | |
| 2125 | return 0; |
| 2126 | } |
| 2127 | |
| 2128 | static int |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2129 | sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2130 | printResponse; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2131 | return sendResponseRaw(p.data(), p.dataSize(), socket_id); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2132 | } |
| 2133 | |
Mohamad Ayyash | 74f7e66 | 2014-04-18 11:43:28 -0700 | [diff] [blame] | |