Martin Bouchet | 0d4bbaf | 2017-09-23 04:54:37 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "RIL_SAP" |
| 18 | |
| 19 | #include <android/hardware/radio/1.0/ISap.h> |
| 20 | |
| 21 | #include <hwbinder/IPCThreadState.h> |
| 22 | #include <hwbinder/ProcessState.h> |
| 23 | #include <sap_service.h> |
| 24 | #include "pb_decode.h" |
| 25 | #include "pb_encode.h" |
| 26 | |
| 27 | using namespace android::hardware::radio::V1_0; |
| 28 | using ::android::hardware::Return; |
| 29 | using ::android::hardware::hidl_vec; |
| 30 | using ::android::hardware::hidl_array; |
| 31 | using ::android::hardware::Void; |
| 32 | using android::CommandInfo; |
| 33 | using android::RequestInfo; |
| 34 | using android::requestToString; |
| 35 | using android::sp; |
| 36 | |
| 37 | struct SapImpl; |
| 38 | |
| 39 | #if (SIM_COUNT >= 2) |
| 40 | sp<SapImpl> sapService[SIM_COUNT]; |
| 41 | #else |
| 42 | sp<SapImpl> sapService[1]; |
| 43 | #endif |
| 44 | |
| 45 | struct SapImpl : public ISap { |
| 46 | int32_t slotId; |
| 47 | sp<ISapCallback> sapCallback; |
| 48 | RIL_SOCKET_ID rilSocketId; |
| 49 | |
| 50 | Return<void> setCallback(const ::android::sp<ISapCallback>& sapCallbackParam); |
| 51 | |
| 52 | Return<void> connectReq(int32_t token, int32_t maxMsgSize); |
| 53 | |
| 54 | Return<void> disconnectReq(int32_t token); |
| 55 | |
| 56 | Return<void> apduReq(int32_t token, SapApduType type, const hidl_vec<uint8_t>& command); |
| 57 | |
| 58 | Return<void> transferAtrReq(int32_t token); |
| 59 | |
| 60 | Return<void> powerReq(int32_t token, bool state); |
| 61 | |
| 62 | Return<void> resetSimReq(int32_t token); |
| 63 | |
| 64 | Return<void> transferCardReaderStatusReq(int32_t token); |
| 65 | |
| 66 | Return<void> setTransferProtocolReq(int32_t token, SapTransferProtocol transferProtocol); |
| 67 | |
| 68 | MsgHeader* createMsgHeader(MsgId msgId, int32_t token); |
| 69 | |
| 70 | Return<void> addPayloadAndDispatchRequest(MsgHeader *msg, uint16_t reqLen, uint8_t *reqPtr); |
| 71 | |
| 72 | void sendFailedResponse(MsgId msgId, int32_t token, int numPointers, ...); |
| 73 | |
| 74 | void checkReturnStatus(Return<void>& ret); |
| 75 | }; |
| 76 | |
| 77 | void SapImpl::checkReturnStatus(Return<void>& ret) { |
| 78 | if (ret.isOk() == false) { |
| 79 | RLOGE("checkReturnStatus: unable to call response/indication callback: %s", |
| 80 | ret.description().c_str()); |
| 81 | // Remote process (SapRilReceiver.java) hosting the callback must be dead. Reset the |
| 82 | // callback object; there's no other recovery to be done here. When the client process is |
| 83 | // back up, it will call setCallback() |
| 84 | sapCallback = NULL; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | Return<void> SapImpl::setCallback(const ::android::sp<ISapCallback>& sapCallbackParam) { |
| 89 | RLOGD("SapImpl::setCallback for slotId %d", slotId); |
| 90 | sapCallback = sapCallbackParam; |
| 91 | return Void(); |
| 92 | } |
| 93 | |
| 94 | MsgHeader* SapImpl::createMsgHeader(MsgId msgId, int32_t token) { |
| 95 | // Memory for msg will be freed by RilSapSocket::onRequestComplete() |
| 96 | MsgHeader *msg = (MsgHeader *)calloc(1, sizeof(MsgHeader)); |
| 97 | if (msg == NULL) { |
| 98 | return NULL; |
| 99 | } |
| 100 | msg->token = token; |
| 101 | msg->type = MsgType_REQUEST; |
| 102 | msg->id = msgId; |
| 103 | msg->error = Error_RIL_E_SUCCESS; |
| 104 | return msg; |
| 105 | } |
| 106 | |
| 107 | Return<void> SapImpl::addPayloadAndDispatchRequest(MsgHeader *msg, uint16_t reqLen, |
| 108 | uint8_t *reqPtr) { |
| 109 | msg->payload = (pb_bytes_array_t *)malloc(sizeof(pb_bytes_array_t) - 1 + reqLen); |
| 110 | if (msg->payload == NULL) { |
| 111 | sendFailedResponse(msg->id, msg->token, 2, reqPtr, msg); |
| 112 | return Void(); |
| 113 | } |
| 114 | msg->payload->size = reqLen; |
| 115 | memcpy(msg->payload->bytes, reqPtr, reqLen); |
| 116 | |
| 117 | RilSapSocket *sapSocket = RilSapSocket::getSocketById(rilSocketId); |
| 118 | if (sapSocket) { |
| 119 | RLOGD("SapImpl::addPayloadAndDispatchRequest: calling dispatchRequest"); |
| 120 | sapSocket->dispatchRequest(msg); |
| 121 | } else { |
| 122 | RLOGE("SapImpl::addPayloadAndDispatchRequest: sapSocket is null"); |
| 123 | sendFailedResponse(msg->id, msg->token, 3, msg->payload, reqPtr, msg); |
| 124 | return Void(); |
| 125 | } |
| 126 | free(msg->payload); |
| 127 | free(reqPtr); |
| 128 | return Void(); |
| 129 | } |
| 130 | |
| 131 | void SapImpl::sendFailedResponse(MsgId msgId, int32_t token, int numPointers, ...) { |
| 132 | va_list ap; |
| 133 | va_start(ap, numPointers); |
| 134 | for (int i = 0; i < numPointers; i++) { |
| 135 | void *ptr = va_arg(ap, void *); |
| 136 | if (ptr) free(ptr); |
| 137 | } |
| 138 | va_end(ap); |
| 139 | Return<void> retStatus; |
| 140 | switch(msgId) { |
| 141 | case MsgId_RIL_SIM_SAP_CONNECT: |
| 142 | retStatus = sapCallback->connectResponse(token, SapConnectRsp::CONNECT_FAILURE, 0); |
| 143 | break; |
| 144 | |
| 145 | case MsgId_RIL_SIM_SAP_DISCONNECT: |
| 146 | retStatus = sapCallback->disconnectResponse(token); |
| 147 | break; |
| 148 | |
| 149 | case MsgId_RIL_SIM_SAP_APDU: { |
| 150 | hidl_vec<uint8_t> apduRsp; |
| 151 | retStatus = sapCallback->apduResponse(token, SapResultCode::GENERIC_FAILURE, apduRsp); |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | case MsgId_RIL_SIM_SAP_TRANSFER_ATR: { |
| 156 | hidl_vec<uint8_t> atr; |
| 157 | retStatus = sapCallback->transferAtrResponse(token, SapResultCode::GENERIC_FAILURE, |
| 158 | atr); |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | case MsgId_RIL_SIM_SAP_POWER: |
| 163 | retStatus = sapCallback->powerResponse(token, SapResultCode::GENERIC_FAILURE); |
| 164 | break; |
| 165 | |
| 166 | case MsgId_RIL_SIM_SAP_RESET_SIM: |
| 167 | retStatus = sapCallback->resetSimResponse(token, SapResultCode::GENERIC_FAILURE); |
| 168 | break; |
| 169 | |
| 170 | case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS: |
| 171 | retStatus = sapCallback->transferCardReaderStatusResponse(token, |
| 172 | SapResultCode::GENERIC_FAILURE, 0); |
| 173 | break; |
| 174 | |
| 175 | case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL: |
| 176 | retStatus = sapCallback->transferProtocolResponse(token, SapResultCode::NOT_SUPPORTED); |
| 177 | break; |
| 178 | |
| 179 | default: |
| 180 | return; |
| 181 | } |
| 182 | sapService[slotId]->checkReturnStatus(retStatus); |
| 183 | } |
| 184 | |
| 185 | Return<void> SapImpl::connectReq(int32_t token, int32_t maxMsgSize) { |
| 186 | RLOGD("SapImpl::connectReq"); |
| 187 | MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_CONNECT, token); |
| 188 | if (msg == NULL) { |
| 189 | RLOGE("SapImpl::connectReq: Error allocating memory for msg"); |
| 190 | sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 0); |
| 191 | return Void(); |
| 192 | } |
| 193 | |
| 194 | /***** Encode RIL_SIM_SAP_CONNECT_REQ *****/ |
| 195 | RIL_SIM_SAP_CONNECT_REQ req; |
| 196 | memset(&req, 0, sizeof(RIL_SIM_SAP_CONNECT_REQ)); |
| 197 | req.max_message_size = maxMsgSize; |
| 198 | |
| 199 | size_t encodedSize = 0; |
| 200 | if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_CONNECT_REQ_fields, &req)) { |
| 201 | RLOGE("SapImpl::connectReq: Error getting encoded size for RIL_SIM_SAP_CONNECT_REQ"); |
| 202 | sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 1, msg); |
| 203 | return Void(); |
| 204 | } |
| 205 | |
| 206 | uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); |
| 207 | if (buffer == NULL) { |
| 208 | RLOGE("SapImpl::connectReq: Error allocating memory for buffer"); |
| 209 | sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 1, msg); |
| 210 | return Void(); |
| 211 | } |
| 212 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); |
| 213 | |
| 214 | RLOGD("SapImpl::connectReq calling pb_encode"); |
| 215 | if (!pb_encode(&stream, RIL_SIM_SAP_CONNECT_REQ_fields, &req)) { |
| 216 | RLOGE("SapImpl::connectReq: Error encoding RIL_SIM_SAP_CONNECT_REQ"); |
| 217 | sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 2, buffer, msg); |
| 218 | return Void(); |
| 219 | } |
| 220 | /***** Encode RIL_SIM_SAP_CONNECT_REQ done *****/ |
| 221 | |
| 222 | /* encoded req is payload */ |
| 223 | return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); |
| 224 | } |
| 225 | |
| 226 | Return<void> SapImpl::disconnectReq(int32_t token) { |
| 227 | RLOGD("SapImpl::disconnectReq"); |
| 228 | MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_DISCONNECT, token); |
| 229 | if (msg == NULL) { |
| 230 | RLOGE("SapImpl::disconnectReq: Error allocating memory for msg"); |
| 231 | sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 0); |
| 232 | return Void(); |
| 233 | } |
| 234 | |
| 235 | /***** Encode RIL_SIM_SAP_DISCONNECT_REQ *****/ |
| 236 | RIL_SIM_SAP_DISCONNECT_REQ req; |
| 237 | memset(&req, 0, sizeof(RIL_SIM_SAP_DISCONNECT_REQ)); |
| 238 | |
| 239 | size_t encodedSize = 0; |
| 240 | if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_DISCONNECT_REQ_fields, &req)) { |
| 241 | RLOGE("SapImpl::disconnectReq: Error getting encoded size for RIL_SIM_SAP_DISCONNECT_REQ"); |
| 242 | sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 1, msg); |
| 243 | return Void(); |
| 244 | } |
| 245 | |
| 246 | uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); |
| 247 | if (buffer == NULL) { |
| 248 | RLOGE("SapImpl::disconnectReq: Error allocating memory for buffer"); |
| 249 | sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 1, msg); |
| 250 | return Void(); |
| 251 | } |
| 252 | |
| 253 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); |
| 254 | |
| 255 | RLOGD("SapImpl::disconnectReq calling pb_encode"); |
| 256 | if (!pb_encode(&stream, RIL_SIM_SAP_DISCONNECT_REQ_fields, &req)) { |
| 257 | RLOGE("SapImpl::disconnectReq: Error encoding RIL_SIM_SAP_DISCONNECT_REQ"); |
| 258 | sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 2, buffer, msg); |
| 259 | return Void(); |
| 260 | } |
| 261 | /***** Encode RIL_SIM_SAP_DISCONNECT_REQ done *****/ |
| 262 | |
| 263 | /* encoded req is payload */ |
| 264 | return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); |
| 265 | } |
| 266 | |
| 267 | Return<void> SapImpl::apduReq(int32_t token, SapApduType type, const hidl_vec<uint8_t>& command) { |
| 268 | RLOGD("SapImpl::apduReq"); |
| 269 | MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_APDU, token); |
| 270 | if (msg == NULL) { |
| 271 | RLOGE("SapImpl::apduReq: Error allocating memory for msg"); |
| 272 | sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 0); |
| 273 | return Void(); |
| 274 | } |
| 275 | |
| 276 | /***** Encode RIL_SIM_SAP_APDU_REQ *****/ |
| 277 | RIL_SIM_SAP_APDU_REQ req; |
| 278 | memset(&req, 0, sizeof(RIL_SIM_SAP_APDU_REQ)); |
| 279 | req.type = (RIL_SIM_SAP_APDU_REQ_Type)type; |
| 280 | |
| 281 | if (command.size() > 0) { |
| 282 | req.command = (pb_bytes_array_t *)malloc(sizeof(pb_bytes_array_t) - 1 + command.size()); |
| 283 | if (req.command == NULL) { |
| 284 | RLOGE("SapImpl::apduReq: Error allocating memory for req.command"); |
| 285 | sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 1, msg); |
| 286 | return Void(); |
| 287 | } |
| 288 | req.command->size = command.size(); |
| 289 | memcpy(req.command->bytes, command.data(), command.size()); |
| 290 | } |
| 291 | |
| 292 | size_t encodedSize = 0; |
| 293 | if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_APDU_REQ_fields, &req)) { |
| 294 | RLOGE("SapImpl::apduReq: Error getting encoded size for RIL_SIM_SAP_APDU_REQ"); |
| 295 | sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 2, req.command, msg); |
| 296 | return Void(); |
| 297 | } |
| 298 | |
| 299 | uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); |
| 300 | if (buffer == NULL) { |
| 301 | RLOGE("SapImpl::apduReq: Error allocating memory for buffer"); |
| 302 | sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 2, req.command, msg); |
| 303 | return Void(); |
| 304 | } |
| 305 | |
| 306 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); |
| 307 | |
| 308 | RLOGD("SapImpl::apduReq calling pb_encode"); |
| 309 | if (!pb_encode(&stream, RIL_SIM_SAP_APDU_REQ_fields, &req)) { |
| 310 | RLOGE("SapImpl::apduReq: Error encoding RIL_SIM_SAP_APDU_REQ"); |
| 311 | sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 3, req.command, buffer, msg); |
| 312 | return Void(); |
| 313 | } |
| 314 | /***** Encode RIL_SIM_SAP_APDU_REQ done *****/ |
| 315 | |
| 316 | /* encoded req is payload */ |
| 317 | return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); |
| 318 | } |
| 319 | |
| 320 | Return<void> SapImpl::transferAtrReq(int32_t token) { |
| 321 | RLOGD("SapImpl::transferAtrReq"); |
| 322 | MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token); |
| 323 | if (msg == NULL) { |
| 324 | RLOGE("SapImpl::transferAtrReq: Error allocating memory for msg"); |
| 325 | sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 0); |
| 326 | return Void(); |
| 327 | } |
| 328 | |
| 329 | /***** Encode RIL_SIM_SAP_TRANSFER_ATR_REQ *****/ |
| 330 | RIL_SIM_SAP_TRANSFER_ATR_REQ req; |
| 331 | memset(&req, 0, sizeof(RIL_SIM_SAP_TRANSFER_ATR_REQ)); |
| 332 | |
| 333 | size_t encodedSize = 0; |
| 334 | if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_TRANSFER_ATR_REQ_fields, &req)) { |
| 335 | RLOGE("SapImpl::transferAtrReq: Error getting encoded size for " |
| 336 | "RIL_SIM_SAP_TRANSFER_ATR_REQ"); |
| 337 | sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 1, msg); |
| 338 | return Void(); |
| 339 | } |
| 340 | |
| 341 | uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); |
| 342 | if (buffer == NULL) { |
| 343 | RLOGE("SapImpl::transferAtrReq: Error allocating memory for buffer"); |
| 344 | sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 1, msg); |
| 345 | return Void(); |
| 346 | } |
| 347 | |
| 348 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); |
| 349 | |
| 350 | RLOGD("SapImpl::transferAtrReq calling pb_encode"); |
| 351 | if (!pb_encode(&stream, RIL_SIM_SAP_TRANSFER_ATR_REQ_fields, &req)) { |
| 352 | RLOGE("SapImpl::transferAtrReq: Error encoding RIL_SIM_SAP_TRANSFER_ATR_REQ"); |
| 353 | sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 2, buffer, msg); |
| 354 | return Void(); |
| 355 | } |
| 356 | /***** Encode RIL_SIM_SAP_TRANSFER_ATR_REQ done *****/ |
| 357 | |
| 358 | /* encoded req is payload */ |
| 359 | return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); |
| 360 | } |
| 361 | |
| 362 | Return<void> SapImpl::powerReq(int32_t token, bool state) { |
| 363 | RLOGD("SapImpl::powerReq"); |
| 364 | MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_POWER, token); |
| 365 | if (msg == NULL) { |
| 366 | RLOGE("SapImpl::powerReq: Error allocating memory for msg"); |
| 367 | sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 0); |
| 368 | return Void(); |
| 369 | } |
| 370 | |
| 371 | /***** Encode RIL_SIM_SAP_POWER_REQ *****/ |
| 372 | RIL_SIM_SAP_POWER_REQ req; |
| 373 | memset(&req, 0, sizeof(RIL_SIM_SAP_POWER_REQ)); |
| 374 | req.state = state; |
| 375 | |
| 376 | size_t encodedSize = 0; |
| 377 | if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_POWER_REQ_fields, &req)) { |
| 378 | RLOGE("SapImpl::powerReq: Error getting encoded size for RIL_SIM_SAP_POWER_REQ"); |
| 379 | sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 1, msg); |
| 380 | return Void(); |
| 381 | } |
| 382 | |
| 383 | uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); |
| 384 | if (buffer == NULL) { |
| 385 | RLOGE("SapImpl::powerReq: Error allocating memory for buffer"); |
| 386 | sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 1, msg); |
| 387 | return Void(); |
| 388 | } |
| 389 | |
| 390 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); |
| 391 | |
| 392 | RLOGD("SapImpl::powerReq calling pb_encode"); |
| 393 | if (!pb_encode(&stream, RIL_SIM_SAP_POWER_REQ_fields, &req)) { |
| 394 | RLOGE("SapImpl::powerReq: Error encoding RIL_SIM_SAP_POWER_REQ"); |
| 395 | sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 2, buffer, msg); |
| 396 | return Void(); |
| 397 | } |
| 398 | /***** Encode RIL_SIM_SAP_POWER_REQ done *****/ |
| 399 | |
| 400 | /* encoded req is payload */ |
| 401 | return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); |
| 402 | } |
| 403 | |
| 404 | Return<void> SapImpl::resetSimReq(int32_t token) { |
| 405 | RLOGD("SapImpl::resetSimReq"); |
| 406 | MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_RESET_SIM, token); |
| 407 | if (msg == NULL) { |
| 408 | RLOGE("SapImpl::resetSimReq: Error allocating memory for msg"); |
| 409 | sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 0); |
| 410 | return Void(); |
| 411 | } |
| 412 | |
| 413 | /***** Encode RIL_SIM_SAP_RESET_SIM_REQ *****/ |
| 414 | RIL_SIM_SAP_RESET_SIM_REQ req; |
| 415 | memset(&req, 0, sizeof(RIL_SIM_SAP_RESET_SIM_REQ)); |
| 416 | |
| 417 | size_t encodedSize = 0; |
| 418 | if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_RESET_SIM_REQ_fields, &req)) { |
| 419 | RLOGE("SapImpl::resetSimReq: Error getting encoded size for RIL_SIM_SAP_RESET_SIM_REQ"); |
| 420 | sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 1, msg); |
| 421 | return Void(); |
| 422 | } |
| 423 | |
| 424 | uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); |
| 425 | if (buffer == NULL) { |
| 426 | RLOGE("SapImpl::resetSimReq: Error allocating memory for buffer"); |
| 427 | sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 1, msg); |
| 428 | return Void(); |
| 429 | } |
| 430 | |
| 431 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); |
| 432 | |
| 433 | RLOGD("SapImpl::resetSimReq calling pb_encode"); |
| 434 | if (!pb_encode(&stream, RIL_SIM_SAP_RESET_SIM_REQ_fields, &req)) { |
| 435 | RLOGE("SapImpl::resetSimReq: Error encoding RIL_SIM_SAP_RESET_SIM_REQ"); |
| 436 | sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 2, buffer, msg); |
| 437 | return Void(); |
| 438 | } |
| 439 | /***** Encode RIL_SIM_SAP_RESET_SIM_REQ done *****/ |
| 440 | |
| 441 | /* encoded req is payload */ |
| 442 | return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); |
| 443 | } |
| 444 | |
| 445 | Return<void> SapImpl::transferCardReaderStatusReq(int32_t token) { |
| 446 | RLOGD("SapImpl::transferCardReaderStatusReq"); |
| 447 | MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token); |
| 448 | if (msg == NULL) { |
| 449 | RLOGE("SapImpl::transferCardReaderStatusReq: Error allocating memory for msg"); |
| 450 | sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 0); |
| 451 | return Void(); |
| 452 | } |
| 453 | |
| 454 | /***** Encode RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ *****/ |
| 455 | RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ req; |
| 456 | memset(&req, 0, sizeof(RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ)); |
| 457 | |
| 458 | size_t encodedSize = 0; |
| 459 | if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ_fields, |
| 460 | &req)) { |
| 461 | RLOGE("SapImpl::transferCardReaderStatusReq: Error getting encoded size for " |
| 462 | "RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ"); |
| 463 | sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 1, msg); |
| 464 | return Void(); |
| 465 | } |
| 466 | |
| 467 | uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); |
| 468 | if (buffer == NULL) { |
| 469 | RLOGE("SapImpl::transferCardReaderStatusReq: Error allocating memory for buffer"); |
| 470 | sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 1, msg); |
| 471 | return Void(); |
| 472 | } |
| 473 | |
| 474 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); |
| 475 | |
| 476 | RLOGD("SapImpl::transferCardReaderStatusReq calling pb_encode"); |
| 477 | if (!pb_encode(&stream, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ_fields, &req)) { |
| 478 | RLOGE("SapImpl::transferCardReaderStatusReq: Error encoding " |
| 479 | "RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ"); |
| 480 | sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 2, buffer, msg); |
| 481 | return Void(); |
| 482 | } |
| 483 | /***** Encode RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ done *****/ |
| 484 | |
| 485 | /* encoded req is payload */ |
| 486 | return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); |
| 487 | } |
| 488 | |
| 489 | Return<void> SapImpl::setTransferProtocolReq(int32_t token, SapTransferProtocol transferProtocol) { |
| 490 | RLOGD("SapImpl::setTransferProtocolReq"); |
| 491 | MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token); |
| 492 | if (msg == NULL) { |
| 493 | RLOGE("SapImpl::setTransferProtocolReq: Error allocating memory for msg"); |
| 494 | sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 0); |
| 495 | return Void(); |
| 496 | } |
| 497 | |
| 498 | /***** Encode RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ *****/ |
| 499 | RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ req; |
| 500 | memset(&req, 0, sizeof(RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ)); |
| 501 | req.protocol = (RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_Protocol)transferProtocol; |
| 502 | |
| 503 | size_t encodedSize = 0; |
| 504 | if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_fields, &req)) { |
| 505 | RLOGE("SapImpl::setTransferProtocolReq: Error getting encoded size for " |
| 506 | "RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ"); |
| 507 | sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 1, msg); |
| 508 | return Void(); |
| 509 | } |
| 510 | |
| 511 | uint8_t *buffer = (uint8_t *)calloc(1, encodedSize); |
| 512 | if (buffer == NULL) { |
| 513 | RLOGE("SapImpl::setTransferProtocolReq: Error allocating memory for buffer"); |
| 514 | sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 1, msg); |
| 515 | return Void(); |
| 516 | } |
| 517 | |
| 518 | pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize); |
| 519 | |
| 520 | RLOGD("SapImpl::setTransferProtocolReq calling pb_encode"); |
| 521 | if (!pb_encode(&stream, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_fields, &req)) { |
| 522 | RLOGE("SapImpl::setTransferProtocolReq: Error encoding " |
| 523 | "RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ"); |
| 524 | sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 2, buffer, msg); |
| 525 | return Void(); |
| 526 | } |
| 527 | /***** Encode RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ done *****/ |
| 528 | |
| 529 | /* encoded req is payload */ |
| 530 | return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer); |
| 531 | } |
| 532 | |
| 533 | void *sapDecodeMessage(MsgId msgId, MsgType msgType, uint8_t *payloadPtr, size_t payloadLen) { |
| 534 | void *responsePtr = NULL; |
Martin Bouchet | 0d4bbaf | 2017-09-23 04:54:37 -0300 | [diff] [blame] | 535 | pb_istream_t stream; |
| 536 | |
| 537 | /* Create the stream */ |
| 538 | stream = pb_istream_from_buffer((uint8_t *)payloadPtr, payloadLen); |
| 539 | |
| 540 | /* Decode based on the message id */ |
| 541 | switch (msgId) |
| 542 | { |
| 543 | case MsgId_RIL_SIM_SAP_CONNECT: |
| 544 | responsePtr = malloc(sizeof(RIL_SIM_SAP_CONNECT_RSP)); |
| 545 | if (responsePtr) { |
| 546 | if (!pb_decode(&stream, RIL_SIM_SAP_CONNECT_RSP_fields, responsePtr)) { |
| 547 | RLOGE("Error decoding RIL_SIM_SAP_CONNECT_RSP"); |
| 548 | return NULL; |
| 549 | } |
| 550 | } |
| 551 | break; |
| 552 | |
| 553 | case MsgId_RIL_SIM_SAP_DISCONNECT: |
| 554 | if (msgType == MsgType_RESPONSE) { |
| 555 | responsePtr = malloc(sizeof(RIL_SIM_SAP_DISCONNECT_RSP)); |
| 556 | if (responsePtr) { |
| 557 | if (!pb_decode(&stream, RIL_SIM_SAP_DISCONNECT_RSP_fields, responsePtr)) { |
| 558 | RLOGE("Error decoding RIL_SIM_SAP_DISCONNECT_RSP"); |
| 559 | return NULL; |
| 560 | } |
| 561 | } |
| 562 | } else { |
| 563 | responsePtr = malloc(sizeof(RIL_SIM_SAP_DISCONNECT_IND)); |
| 564 | if (responsePtr) { |
| 565 | if (!pb_decode(&stream, RIL_SIM_SAP_DISCONNECT_IND_fields, responsePtr)) { |
| 566 | RLOGE("Error decoding RIL_SIM_SAP_DISCONNECT_IND"); |
| 567 | return NULL; |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | break; |
| 572 | |
| 573 | case MsgId_RIL_SIM_SAP_APDU: |
| 574 | responsePtr = malloc(sizeof(RIL_SIM_SAP_APDU_RSP)); |
| 575 | if (responsePtr) { |
| 576 | if (!pb_decode(&stream, RIL_SIM_SAP_APDU_RSP_fields, responsePtr)) { |
| 577 | RLOGE("Error decoding RIL_SIM_SAP_APDU_RSP"); |
| 578 | return NULL; |
| 579 | } |
| 580 | } |
| 581 | break; |
| 582 | |
| 583 | case MsgId_RIL_SIM_SAP_TRANSFER_ATR: |
| 584 | responsePtr = malloc(sizeof(RIL_SIM_SAP_TRANSFER_ATR_RSP)); |
| 585 | if (responsePtr) { |
| 586 | if (!pb_decode(&stream, RIL_SIM_SAP_TRANSFER_ATR_RSP_fields, responsePtr)) { |
| 587 | RLOGE("Error decoding RIL_SIM_SAP_TRANSFER_ATR_RSP"); |
| 588 | return NULL; |
| 589 | } |
| 590 | } |
| 591 | break; |
| 592 | |
| 593 | case MsgId_RIL_SIM_SAP_POWER: |
| 594 | responsePtr = malloc(sizeof(RIL_SIM_SAP_POWER_RSP)); |
| 595 | if (responsePtr) { |
| 596 | if (!pb_decode(&stream, RIL_SIM_SAP_POWER_RSP_fields, responsePtr)) { |
| 597 | RLOGE("Error decoding RIL_SIM_SAP_POWER_RSP"); |
| 598 | return NULL; |
| 599 | } |
| 600 | } |
| 601 | break; |
| 602 | |
| 603 | case MsgId_RIL_SIM_SAP_RESET_SIM: |
| 604 | responsePtr = malloc(sizeof(RIL_SIM_SAP_RESET_SIM_RSP)); |
| 605 | if (responsePtr) { |
| 606 | if (!pb_decode(&stream, RIL_SIM_SAP_RESET_SIM_RSP_fields, responsePtr)) { |
| 607 | RLOGE("Error decoding RIL_SIM_SAP_RESET_SIM_RSP"); |
| 608 | return NULL; |
| 609 | } |
| 610 | } |
| 611 | break; |
| 612 | |
| 613 | case MsgId_RIL_SIM_SAP_STATUS: |
| 614 | responsePtr = malloc(sizeof(RIL_SIM_SAP_STATUS_IND)); |
| 615 | if (responsePtr) { |
| 616 | if (!pb_decode(&stream, RIL_SIM_SAP_STATUS_IND_fields, responsePtr)) { |
| 617 | RLOGE("Error decoding RIL_SIM_SAP_STATUS_IND"); |
| 618 | return NULL; |
| 619 | } |
| 620 | } |
| 621 | break; |
| 622 | |
| 623 | case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS: |
| 624 | responsePtr = malloc(sizeof(RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP)); |
| 625 | if (responsePtr) { |
| 626 | if (!pb_decode(&stream, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_fields, |
| 627 | responsePtr)) { |
| 628 | RLOGE("Error decoding RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP"); |
| 629 | return NULL; |
| 630 | } |
| 631 | } |
| 632 | break; |
| 633 | |
| 634 | case MsgId_RIL_SIM_SAP_ERROR_RESP: |
| 635 | responsePtr = malloc(sizeof(RIL_SIM_SAP_ERROR_RSP)); |
| 636 | if (responsePtr) { |
| 637 | if (!pb_decode(&stream, RIL_SIM_SAP_ERROR_RSP_fields, responsePtr)) { |
| 638 | RLOGE("Error decoding RIL_SIM_SAP_ERROR_RSP"); |
| 639 | return NULL; |
| 640 | } |
| 641 | } |
| 642 | break; |
| 643 | |
| 644 | case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL: |
| 645 | responsePtr = malloc(sizeof(RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP)); |
| 646 | if (responsePtr) { |
| 647 | if (!pb_decode(&stream, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP_fields, |
| 648 | responsePtr)) { |
| 649 | RLOGE("Error decoding RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP"); |
| 650 | return NULL; |
| 651 | } |
| 652 | } |
| 653 | break; |
| 654 | |
| 655 | default: |
| 656 | break; |
| 657 | } |
| 658 | return responsePtr; |
| 659 | } /* sapDecodeMessage */ |
| 660 | |
| 661 | sp<SapImpl> getSapImpl(RilSapSocket *sapSocket) { |
| 662 | switch (sapSocket->getSocketId()) { |
| 663 | case RIL_SOCKET_1: |
| 664 | RLOGD("getSapImpl: returning sapService[0]"); |
| 665 | return sapService[0]; |
| 666 | #if (SIM_COUNT >= 2) |
| 667 | case RIL_SOCKET_2: |
| 668 | return sapService[1]; |
| 669 | #if (SIM_COUNT >= 3) |
| 670 | case RIL_SOCKET_3: |
| 671 | return sapService[2]; |
| 672 | #if (SIM_COUNT >= 4) |
| 673 | case RIL_SOCKET_4: |
| 674 | return sapService[3]; |
| 675 | #endif |
| 676 | #endif |
| 677 | #endif |
| 678 | default: |
| 679 | return NULL; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | SapResultCode convertApduResponseProtoToHal(RIL_SIM_SAP_APDU_RSP_Response responseProto) { |
| 684 | switch(responseProto) { |
| 685 | case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SUCCESS: |
| 686 | return SapResultCode::SUCCESS; |
| 687 | case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_GENERIC_FAILURE: |
| 688 | return SapResultCode::GENERIC_FAILURE; |
| 689 | case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_NOT_READY: |
| 690 | return SapResultCode::CARD_NOT_ACCESSSIBLE; |
| 691 | case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF: |
| 692 | return SapResultCode::CARD_ALREADY_POWERED_OFF; |
| 693 | case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_ABSENT: |
| 694 | return SapResultCode::CARD_REMOVED; |
| 695 | default: |
| 696 | return SapResultCode::GENERIC_FAILURE; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | SapResultCode convertTransferAtrResponseProtoToHal( |
| 701 | RIL_SIM_SAP_TRANSFER_ATR_RSP_Response responseProto) { |
| 702 | switch(responseProto) { |
| 703 | case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SUCCESS: |
| 704 | return SapResultCode::SUCCESS; |
| 705 | case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_GENERIC_FAILURE: |
| 706 | return SapResultCode::GENERIC_FAILURE; |
| 707 | case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF: |
| 708 | return SapResultCode::CARD_ALREADY_POWERED_OFF; |
| 709 | case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_ABSENT: |
| 710 | return SapResultCode::CARD_REMOVED; |
| 711 | case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_DATA_NOT_AVAILABLE: |
| 712 | return SapResultCode::DATA_NOT_AVAILABLE; |
| 713 | default: |
| 714 | return SapResultCode::GENERIC_FAILURE; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | SapResultCode convertPowerResponseProtoToHal(RIL_SIM_SAP_POWER_RSP_Response responseProto) { |
| 719 | switch(responseProto) { |
| 720 | case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SUCCESS: |
| 721 | return SapResultCode::SUCCESS; |
| 722 | case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_GENERIC_FAILURE: |
| 723 | return SapResultCode::GENERIC_FAILURE; |
| 724 | case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ABSENT: |
| 725 | return SapResultCode::CARD_REMOVED; |
| 726 | case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF: |
| 727 | return SapResultCode::CARD_ALREADY_POWERED_OFF; |
| 728 | case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ALREADY_POWERED_ON: |
| 729 | return SapResultCode::CARD_ALREADY_POWERED_ON; |
| 730 | default: |
| 731 | return SapResultCode::GENERIC_FAILURE; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | SapResultCode convertResetSimResponseProtoToHal(RIL_SIM_SAP_RESET_SIM_RSP_Response responseProto) { |
| 736 | switch(responseProto) { |
| 737 | case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SUCCESS: |
| 738 | return SapResultCode::SUCCESS; |
| 739 | case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_GENERIC_FAILURE: |
| 740 | return SapResultCode::GENERIC_FAILURE; |
| 741 | case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_ABSENT: |
| 742 | return SapResultCode::CARD_REMOVED; |
| 743 | case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_NOT_READY: |
| 744 | return SapResultCode::CARD_NOT_ACCESSSIBLE; |
| 745 | case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF: |
| 746 | return SapResultCode::CARD_ALREADY_POWERED_OFF; |
| 747 | } |
| 748 | return SapResultCode::GENERIC_FAILURE; |
| 749 | } |
| 750 | |
| 751 | SapResultCode convertTransferCardReaderStatusResponseProtoToHal( |
| 752 | RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response responseProto) { |
| 753 | switch(responseProto) { |
| 754 | case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_SUCCESS: |
| 755 | return SapResultCode::SUCCESS; |
| 756 | case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_GENERIC_FAILURE: |
| 757 | return SapResultCode::GENERIC_FAILURE; |
| 758 | case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_SIM_DATA_NOT_AVAILABLE: |
| 759 | return SapResultCode::DATA_NOT_AVAILABLE; |
| 760 | } |
| 761 | return SapResultCode::GENERIC_FAILURE; |
| 762 | } |
| 763 | |
| 764 | void processResponse(MsgHeader *rsp, RilSapSocket *sapSocket, MsgType msgType) { |
| 765 | MsgId msgId = rsp->id; |
| 766 | uint8_t *data = rsp->payload->bytes; |
| 767 | size_t dataLen = rsp->payload->size; |
| 768 | |
| 769 | void *messagePtr = sapDecodeMessage(msgId, msgType, data, dataLen); |
| 770 | |
| 771 | sp<SapImpl> sapImpl = getSapImpl(sapSocket); |
| 772 | if (sapImpl->sapCallback == NULL) { |
| 773 | RLOGE("processResponse: sapCallback == NULL; msgId = %d; msgType = %d", |
| 774 | msgId, msgType); |
| 775 | return; |
| 776 | } |
| 777 | |
| 778 | RLOGD("processResponse: sapCallback != NULL; msgId = %d; msgType = %d", |
| 779 | msgId, msgType); |
| 780 | |
| 781 | Return<void> retStatus; |
| 782 | switch (msgId) { |
| 783 | case MsgId_RIL_SIM_SAP_CONNECT: { |
| 784 | RIL_SIM_SAP_CONNECT_RSP *connectRsp = (RIL_SIM_SAP_CONNECT_RSP *)messagePtr; |
| 785 | RLOGD("processResponse: calling sapCallback->connectResponse %d %d %d", |
| 786 | rsp->token, |
| 787 | connectRsp->response, |
| 788 | connectRsp->max_message_size); |
| 789 | retStatus = sapImpl->sapCallback->connectResponse(rsp->token, |
| 790 | (SapConnectRsp)connectRsp->response, |
| 791 | connectRsp->max_message_size); |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | case MsgId_RIL_SIM_SAP_DISCONNECT: |
| 796 | if (msgType == MsgType_RESPONSE) { |
| 797 | RLOGD("processResponse: calling sapCallback->disconnectResponse %d", rsp->token); |
| 798 | retStatus = sapImpl->sapCallback->disconnectResponse(rsp->token); |
| 799 | } else { |
| 800 | RIL_SIM_SAP_DISCONNECT_IND *disconnectInd = |
| 801 | (RIL_SIM_SAP_DISCONNECT_IND *)messagePtr; |
| 802 | RLOGD("processResponse: calling sapCallback->disconnectIndication %d %d", |
| 803 | rsp->token, disconnectInd->disconnectType); |
| 804 | retStatus = sapImpl->sapCallback->disconnectIndication(rsp->token, |
| 805 | (SapDisconnectType)disconnectInd->disconnectType); |
| 806 | } |
| 807 | break; |
| 808 | |
| 809 | case MsgId_RIL_SIM_SAP_APDU: { |
| 810 | RIL_SIM_SAP_APDU_RSP *apduRsp = (RIL_SIM_SAP_APDU_RSP *)messagePtr; |
| 811 | SapResultCode apduResponse = convertApduResponseProtoToHal(apduRsp->response); |
| 812 | RLOGD("processResponse: calling sapCallback->apduResponse %d %d", |
| 813 | rsp->token, apduResponse); |
| 814 | hidl_vec<uint8_t> apduRspVec; |
| 815 | if (apduRsp->apduResponse != NULL && apduRsp->apduResponse->size > 0) { |
| 816 | apduRspVec.setToExternal(apduRsp->apduResponse->bytes, apduRsp->apduResponse->size); |
| 817 | } |
| 818 | retStatus = sapImpl->sapCallback->apduResponse(rsp->token, apduResponse, apduRspVec); |
| 819 | break; |
| 820 | } |
| 821 | |
| 822 | case MsgId_RIL_SIM_SAP_TRANSFER_ATR: { |
| 823 | RIL_SIM_SAP_TRANSFER_ATR_RSP *transferAtrRsp = |
| 824 | (RIL_SIM_SAP_TRANSFER_ATR_RSP *)messagePtr; |
| 825 | SapResultCode transferAtrResponse = |
| 826 | convertTransferAtrResponseProtoToHal(transferAtrRsp->response); |
| 827 | RLOGD("processResponse: calling sapCallback->transferAtrResponse %d %d", |
| 828 | rsp->token, transferAtrResponse); |
| 829 | hidl_vec<uint8_t> transferAtrRspVec; |
| 830 | if (transferAtrRsp->atr != NULL && transferAtrRsp->atr->size > 0) { |
| 831 | transferAtrRspVec.setToExternal(transferAtrRsp->atr->bytes, |
| 832 | transferAtrRsp->atr->size); |
| 833 | } |
| 834 | retStatus = sapImpl->sapCallback->transferAtrResponse(rsp->token, transferAtrResponse, |
| 835 | transferAtrRspVec); |
| 836 | break; |
| 837 | } |
| 838 | |
| 839 | case MsgId_RIL_SIM_SAP_POWER: { |
| 840 | SapResultCode powerResponse = convertPowerResponseProtoToHal( |
| 841 | ((RIL_SIM_SAP_POWER_RSP *)messagePtr)->response); |
| 842 | RLOGD("processResponse: calling sapCallback->powerResponse %d %d", |
| 843 | rsp->token, powerResponse); |
| 844 | retStatus = sapImpl->sapCallback->powerResponse(rsp->token, powerResponse); |
| 845 | break; |
| 846 | } |
| 847 | |
| 848 | case MsgId_RIL_SIM_SAP_RESET_SIM: { |
| 849 | SapResultCode resetSimResponse = convertResetSimResponseProtoToHal( |
| 850 | ((RIL_SIM_SAP_RESET_SIM_RSP *)messagePtr)->response); |
| 851 | RLOGD("processResponse: calling sapCallback->resetSimResponse %d %d", |
| 852 | rsp->token, resetSimResponse); |
| 853 | retStatus = sapImpl->sapCallback->resetSimResponse(rsp->token, resetSimResponse); |
| 854 | break; |
| 855 | } |
| 856 | |
| 857 | case MsgId_RIL_SIM_SAP_STATUS: { |
| 858 | RIL_SIM_SAP_STATUS_IND *statusInd = (RIL_SIM_SAP_STATUS_IND *)messagePtr; |
| 859 | RLOGD("processResponse: calling sapCallback->statusIndication %d %d", |
| 860 | rsp->token, statusInd->statusChange); |
| 861 | retStatus = sapImpl->sapCallback->statusIndication(rsp->token, |
| 862 | (SapStatus)statusInd->statusChange); |
| 863 | break; |
| 864 | } |
| 865 | |
| 866 | case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS: { |
| 867 | RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP *transferStatusRsp = |
| 868 | (RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP *)messagePtr; |
| 869 | SapResultCode transferCardReaderStatusResponse = |
| 870 | convertTransferCardReaderStatusResponseProtoToHal( |
| 871 | transferStatusRsp->response); |
| 872 | RLOGD("processResponse: calling sapCallback->transferCardReaderStatusResponse %d %d %d", |
| 873 | rsp->token, |
| 874 | transferCardReaderStatusResponse, |
| 875 | transferStatusRsp->CardReaderStatus); |
| 876 | retStatus = sapImpl->sapCallback->transferCardReaderStatusResponse(rsp->token, |
| 877 | transferCardReaderStatusResponse, |
| 878 | transferStatusRsp->CardReaderStatus); |
| 879 | break; |
| 880 | } |
| 881 | |
| 882 | case MsgId_RIL_SIM_SAP_ERROR_RESP: { |
| 883 | RLOGD("processResponse: calling sapCallback->errorResponse %d", rsp->token); |
| 884 | retStatus = sapImpl->sapCallback->errorResponse(rsp->token); |
| 885 | break; |
| 886 | } |
| 887 | |
| 888 | case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL: { |
| 889 | SapResultCode setTransferProtocolResponse; |
| 890 | if (((RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP *)messagePtr)->response == |
| 891 | RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP_Response_RIL_E_SUCCESS) { |
| 892 | setTransferProtocolResponse = SapResultCode::SUCCESS; |
| 893 | } else { |
| 894 | setTransferProtocolResponse = SapResultCode::NOT_SUPPORTED; |
| 895 | } |
| 896 | RLOGD("processResponse: calling sapCallback->transferProtocolResponse %d %d", |
| 897 | rsp->token, setTransferProtocolResponse); |
| 898 | retStatus = sapImpl->sapCallback->transferProtocolResponse(rsp->token, |
| 899 | setTransferProtocolResponse); |
| 900 | break; |
| 901 | } |
| 902 | |
| 903 | default: |
| 904 | return; |
| 905 | } |
| 906 | sapImpl->checkReturnStatus(retStatus); |
| 907 | } |
| 908 | |
| 909 | void sap::processResponse(MsgHeader *rsp, RilSapSocket *sapSocket) { |
| 910 | processResponse(rsp, sapSocket, MsgType_RESPONSE); |
| 911 | } |
| 912 | |
| 913 | void sap::processUnsolResponse(MsgHeader *rsp, RilSapSocket *sapSocket) { |
| 914 | processResponse(rsp, sapSocket, MsgType_UNSOL_RESPONSE); |
| 915 | } |
| 916 | |
| 917 | void sap::registerService(RIL_RadioFunctions *callbacks) { |
| 918 | using namespace android::hardware; |
| 919 | int simCount = 1; |
| 920 | const char *serviceNames[] = { |
| 921 | android::RIL_getServiceName() |
| 922 | #if (SIM_COUNT >= 2) |
| 923 | , RIL2_SERVICE_NAME |
| 924 | #if (SIM_COUNT >= 3) |
| 925 | , RIL3_SERVICE_NAME |
| 926 | #if (SIM_COUNT >= 4) |
| 927 | , RIL4_SERVICE_NAME |
| 928 | #endif |
| 929 | #endif |
| 930 | #endif |
| 931 | }; |
| 932 | |
| 933 | RIL_SOCKET_ID socketIds[] = { |
| 934 | RIL_SOCKET_1 |
| 935 | #if (SIM_COUNT >= 2) |
| 936 | , RIL_SOCKET_2 |
| 937 | #if (SIM_COUNT >= 3) |
| 938 | , RIL_SOCKET_3 |
| 939 | #if (SIM_COUNT >= 4) |
| 940 | , RIL_SOCKET_4 |
| 941 | #endif |
| 942 | #endif |
| 943 | #endif |
| 944 | }; |
| 945 | #if (SIM_COUNT >= 2) |
| 946 | simCount = SIM_COUNT; |
| 947 | #endif |
| 948 | |
| 949 | for (int i = 0; i < simCount; i++) { |
| 950 | sapService[i] = new SapImpl; |
| 951 | sapService[i]->slotId = i; |
| 952 | sapService[i]->rilSocketId = socketIds[i]; |
| 953 | RLOGD("registerService: starting ISap %s for slotId %d", serviceNames[i], i); |
| 954 | android::status_t status = sapService[i]->registerAsService(serviceNames[i]); |
| 955 | RLOGD("registerService: started ISap %s status %d", serviceNames[i], status); |
| 956 | } |
| 957 | } |