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