Home | History | Annotate | Download | only in libril
      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 "RILC"
     18 
     19 #include <android/hardware/radio/1.1/IRadio.h>
     20 #include <android/hardware/radio/1.1/IRadioResponse.h>
     21 #include <android/hardware/radio/1.1/IRadioIndication.h>
     22 #include <android/hardware/radio/1.1/types.h>
     23 
     24 #include <android/hardware/radio/deprecated/1.0/IOemHook.h>
     25 
     26 #include <hwbinder/IPCThreadState.h>
     27 #include <hwbinder/ProcessState.h>
     28 #include <ril_service.h>
     29 #include <hidl/HidlTransportSupport.h>
     30 #include <utils/SystemClock.h>
     31 #include <inttypes.h>
     32 
     33 #define INVALID_HEX_CHAR 16
     34 
     35 using namespace android::hardware::radio;
     36 using namespace android::hardware::radio::V1_0;
     37 using namespace android::hardware::radio::deprecated::V1_0;
     38 using ::android::hardware::configureRpcThreadpool;
     39 using ::android::hardware::joinRpcThreadpool;
     40 using ::android::hardware::Return;
     41 using ::android::hardware::hidl_string;
     42 using ::android::hardware::hidl_vec;
     43 using ::android::hardware::hidl_array;
     44 using ::android::hardware::Void;
     45 using android::CommandInfo;
     46 using android::RequestInfo;
     47 using android::requestToString;
     48 using android::sp;
     49 
     50 #define BOOL_TO_INT(x) (x ? 1 : 0)
     51 #define ATOI_NULL_HANDLED(x) (x ? atoi(x) : -1)
     52 #define ATOI_NULL_HANDLED_DEF(x, defaultVal) (x ? atoi(x) : defaultVal)
     53 
     54 #if defined(ANDROID_MULTI_SIM)
     55 #define CALL_ONREQUEST(a, b, c, d, e) \
     56         s_vendorFunctions->onRequest((a), (b), (c), (d), ((RIL_SOCKET_ID)(e)))
     57 #define CALL_ONSTATEREQUEST(a) s_vendorFunctions->onStateRequest((RIL_SOCKET_ID)(a))
     58 #else
     59 #define CALL_ONREQUEST(a, b, c, d, e) s_vendorFunctions->onRequest((a), (b), (c), (d))
     60 #define CALL_ONSTATEREQUEST(a) s_vendorFunctions->onStateRequest()
     61 #endif
     62 
     63 #ifdef OEM_HOOK_DISABLED
     64 constexpr bool kOemHookEnabled = false;
     65 #else
     66 constexpr bool kOemHookEnabled = true;
     67 #endif
     68 
     69 RIL_RadioFunctions *s_vendorFunctions = NULL;
     70 static CommandInfo *s_commands;
     71 
     72 struct RadioImpl;
     73 struct OemHookImpl;
     74 
     75 #if (SIM_COUNT >= 2)
     76 sp<RadioImpl> radioService[SIM_COUNT];
     77 sp<OemHookImpl> oemHookService[SIM_COUNT];
     78 int64_t nitzTimeReceived[SIM_COUNT];
     79 // counter used for synchronization. It is incremented every time response callbacks are updated.
     80 volatile int32_t mCounterRadio[SIM_COUNT];
     81 volatile int32_t mCounterOemHook[SIM_COUNT];
     82 #else
     83 sp<RadioImpl> radioService[1];
     84 sp<OemHookImpl> oemHookService[1];
     85 int64_t nitzTimeReceived[1];
     86 // counter used for synchronization. It is incremented every time response callbacks are updated.
     87 volatile int32_t mCounterRadio[1];
     88 volatile int32_t mCounterOemHook[1];
     89 #endif
     90 
     91 static pthread_rwlock_t radioServiceRwlock = PTHREAD_RWLOCK_INITIALIZER;
     92 
     93 #if (SIM_COUNT >= 2)
     94 static pthread_rwlock_t radioServiceRwlock2 = PTHREAD_RWLOCK_INITIALIZER;
     95 #if (SIM_COUNT >= 3)
     96 static pthread_rwlock_t radioServiceRwlock3 = PTHREAD_RWLOCK_INITIALIZER;
     97 #if (SIM_COUNT >= 4)
     98 static pthread_rwlock_t radioServiceRwlock4 = PTHREAD_RWLOCK_INITIALIZER;
     99 #endif
    100 #endif
    101 #endif
    102 
    103 void convertRilHardwareConfigListToHal(void *response, size_t responseLen,
    104         hidl_vec<HardwareConfig>& records);
    105 
    106 void convertRilRadioCapabilityToHal(void *response, size_t responseLen, RadioCapability& rc);
    107 
    108 void convertRilLceDataInfoToHal(void *response, size_t responseLen, LceDataInfo& lce);
    109 
    110 void convertRilSignalStrengthToHal(void *response, size_t responseLen,
    111         SignalStrength& signalStrength);
    112 
    113 void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse,
    114         SetupDataCallResult& dcResult);
    115 
    116 void convertRilDataCallListToHal(void *response, size_t responseLen,
    117         hidl_vec<SetupDataCallResult>& dcResultList);
    118 
    119 void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<CellInfo>& records);
    120 
    121 struct RadioImpl : public V1_1::IRadio {
    122     int32_t mSlotId;
    123     sp<IRadioResponse> mRadioResponse;
    124     sp<IRadioIndication> mRadioIndication;
    125     sp<V1_1::IRadioResponse> mRadioResponseV1_1;
    126     sp<V1_1::IRadioIndication> mRadioIndicationV1_1;
    127 
    128     Return<void> setResponseFunctions(
    129             const ::android::sp<IRadioResponse>& radioResponse,
    130             const ::android::sp<IRadioIndication>& radioIndication);
    131 
    132     Return<void> getIccCardStatus(int32_t serial);
    133 
    134     Return<void> supplyIccPinForApp(int32_t serial, const hidl_string& pin,
    135             const hidl_string& aid);
    136 
    137     Return<void> supplyIccPukForApp(int32_t serial, const hidl_string& puk,
    138             const hidl_string& pin, const hidl_string& aid);
    139 
    140     Return<void> supplyIccPin2ForApp(int32_t serial,
    141             const hidl_string& pin2,
    142             const hidl_string& aid);
    143 
    144     Return<void> supplyIccPuk2ForApp(int32_t serial, const hidl_string& puk2,
    145             const hidl_string& pin2, const hidl_string& aid);
    146 
    147     Return<void> changeIccPinForApp(int32_t serial, const hidl_string& oldPin,
    148             const hidl_string& newPin, const hidl_string& aid);
    149 
    150     Return<void> changeIccPin2ForApp(int32_t serial, const hidl_string& oldPin2,
    151             const hidl_string& newPin2, const hidl_string& aid);
    152 
    153     Return<void> supplyNetworkDepersonalization(int32_t serial, const hidl_string& netPin);
    154 
    155     Return<void> getCurrentCalls(int32_t serial);
    156 
    157     Return<void> dial(int32_t serial, const Dial& dialInfo);
    158 
    159     Return<void> getImsiForApp(int32_t serial,
    160             const ::android::hardware::hidl_string& aid);
    161 
    162     Return<void> hangup(int32_t serial, int32_t gsmIndex);
    163 
    164     Return<void> hangupWaitingOrBackground(int32_t serial);
    165 
    166     Return<void> hangupForegroundResumeBackground(int32_t serial);
    167 
    168     Return<void> switchWaitingOrHoldingAndActive(int32_t serial);
    169 
    170     Return<void> conference(int32_t serial);
    171 
    172     Return<void> rejectCall(int32_t serial);
    173 
    174     Return<void> getLastCallFailCause(int32_t serial);
    175 
    176     Return<void> getSignalStrength(int32_t serial);
    177 
    178     Return<void> getVoiceRegistrationState(int32_t serial);
    179 
    180     Return<void> getDataRegistrationState(int32_t serial);
    181 
    182     Return<void> getOperator(int32_t serial);
    183 
    184     Return<void> setRadioPower(int32_t serial, bool on);
    185 
    186     Return<void> sendDtmf(int32_t serial,
    187             const ::android::hardware::hidl_string& s);
    188 
    189     Return<void> sendSms(int32_t serial, const GsmSmsMessage& message);
    190 
    191     Return<void> sendSMSExpectMore(int32_t serial, const GsmSmsMessage& message);
    192 
    193     Return<void> setupDataCall(int32_t serial,
    194             RadioTechnology radioTechnology,
    195             const DataProfileInfo& profileInfo,
    196             bool modemCognitive,
    197             bool roamingAllowed,
    198             bool isRoaming);
    199 
    200     Return<void> iccIOForApp(int32_t serial,
    201             const IccIo& iccIo);
    202 
    203     Return<void> sendUssd(int32_t serial,
    204             const ::android::hardware::hidl_string& ussd);
    205 
    206     Return<void> cancelPendingUssd(int32_t serial);
    207 
    208     Return<void> getClir(int32_t serial);
    209 
    210     Return<void> setClir(int32_t serial, int32_t status);
    211 
    212     Return<void> getCallForwardStatus(int32_t serial,
    213             const CallForwardInfo& callInfo);
    214 
    215     Return<void> setCallForward(int32_t serial,
    216             const CallForwardInfo& callInfo);
    217 
    218     Return<void> getCallWaiting(int32_t serial, int32_t serviceClass);
    219 
    220     Return<void> setCallWaiting(int32_t serial, bool enable, int32_t serviceClass);
    221 
    222     Return<void> acknowledgeLastIncomingGsmSms(int32_t serial,
    223             bool success, SmsAcknowledgeFailCause cause);
    224 
    225     Return<void> acceptCall(int32_t serial);
    226 
    227     Return<void> deactivateDataCall(int32_t serial,
    228             int32_t cid, bool reasonRadioShutDown);
    229 
    230     Return<void> getFacilityLockForApp(int32_t serial,
    231             const ::android::hardware::hidl_string& facility,
    232             const ::android::hardware::hidl_string& password,
    233             int32_t serviceClass,
    234             const ::android::hardware::hidl_string& appId);
    235 
    236     Return<void> setFacilityLockForApp(int32_t serial,
    237             const ::android::hardware::hidl_string& facility,
    238             bool lockState,
    239             const ::android::hardware::hidl_string& password,
    240             int32_t serviceClass,
    241             const ::android::hardware::hidl_string& appId);
    242 
    243     Return<void> setBarringPassword(int32_t serial,
    244             const ::android::hardware::hidl_string& facility,
    245             const ::android::hardware::hidl_string& oldPassword,
    246             const ::android::hardware::hidl_string& newPassword);
    247 
    248     Return<void> getNetworkSelectionMode(int32_t serial);
    249 
    250     Return<void> setNetworkSelectionModeAutomatic(int32_t serial);
    251 
    252     Return<void> setNetworkSelectionModeManual(int32_t serial,
    253             const ::android::hardware::hidl_string& operatorNumeric);
    254 
    255     Return<void> getAvailableNetworks(int32_t serial);
    256 
    257     Return<void> startNetworkScan(int32_t serial, const V1_1::NetworkScanRequest& request);
    258 
    259     Return<void> stopNetworkScan(int32_t serial);
    260 
    261     Return<void> startDtmf(int32_t serial,
    262             const ::android::hardware::hidl_string& s);
    263 
    264     Return<void> stopDtmf(int32_t serial);
    265 
    266     Return<void> getBasebandVersion(int32_t serial);
    267 
    268     Return<void> separateConnection(int32_t serial, int32_t gsmIndex);
    269 
    270     Return<void> setMute(int32_t serial, bool enable);
    271 
    272     Return<void> getMute(int32_t serial);
    273 
    274     Return<void> getClip(int32_t serial);
    275 
    276     Return<void> getDataCallList(int32_t serial);
    277 
    278     Return<void> setSuppServiceNotifications(int32_t serial, bool enable);
    279 
    280     Return<void> writeSmsToSim(int32_t serial,
    281             const SmsWriteArgs& smsWriteArgs);
    282 
    283     Return<void> deleteSmsOnSim(int32_t serial, int32_t index);
    284 
    285     Return<void> setBandMode(int32_t serial, RadioBandMode mode);
    286 
    287     Return<void> getAvailableBandModes(int32_t serial);
    288 
    289     Return<void> sendEnvelope(int32_t serial,
    290             const ::android::hardware::hidl_string& command);
    291 
    292     Return<void> sendTerminalResponseToSim(int32_t serial,
    293             const ::android::hardware::hidl_string& commandResponse);
    294 
    295     Return<void> handleStkCallSetupRequestFromSim(int32_t serial, bool accept);
    296 
    297     Return<void> explicitCallTransfer(int32_t serial);
    298 
    299     Return<void> setPreferredNetworkType(int32_t serial, PreferredNetworkType nwType);
    300 
    301     Return<void> getPreferredNetworkType(int32_t serial);
    302 
    303     Return<void> getNeighboringCids(int32_t serial);
    304 
    305     Return<void> setLocationUpdates(int32_t serial, bool enable);
    306 
    307     Return<void> setCdmaSubscriptionSource(int32_t serial,
    308             CdmaSubscriptionSource cdmaSub);
    309 
    310     Return<void> setCdmaRoamingPreference(int32_t serial, CdmaRoamingType type);
    311 
    312     Return<void> getCdmaRoamingPreference(int32_t serial);
    313 
    314     Return<void> setTTYMode(int32_t serial, TtyMode mode);
    315 
    316     Return<void> getTTYMode(int32_t serial);
    317 
    318     Return<void> setPreferredVoicePrivacy(int32_t serial, bool enable);
    319 
    320     Return<void> getPreferredVoicePrivacy(int32_t serial);
    321 
    322     Return<void> sendCDMAFeatureCode(int32_t serial,
    323             const ::android::hardware::hidl_string& featureCode);
    324 
    325     Return<void> sendBurstDtmf(int32_t serial,
    326             const ::android::hardware::hidl_string& dtmf,
    327             int32_t on,
    328             int32_t off);
    329 
    330     Return<void> sendCdmaSms(int32_t serial, const CdmaSmsMessage& sms);
    331 
    332     Return<void> acknowledgeLastIncomingCdmaSms(int32_t serial,
    333             const CdmaSmsAck& smsAck);
    334 
    335     Return<void> getGsmBroadcastConfig(int32_t serial);
    336 
    337     Return<void> setGsmBroadcastConfig(int32_t serial,
    338             const hidl_vec<GsmBroadcastSmsConfigInfo>& configInfo);
    339 
    340     Return<void> setGsmBroadcastActivation(int32_t serial, bool activate);
    341 
    342     Return<void> getCdmaBroadcastConfig(int32_t serial);
    343 
    344     Return<void> setCdmaBroadcastConfig(int32_t serial,
    345             const hidl_vec<CdmaBroadcastSmsConfigInfo>& configInfo);
    346 
    347     Return<void> setCdmaBroadcastActivation(int32_t serial, bool activate);
    348 
    349     Return<void> getCDMASubscription(int32_t serial);
    350 
    351     Return<void> writeSmsToRuim(int32_t serial, const CdmaSmsWriteArgs& cdmaSms);
    352 
    353     Return<void> deleteSmsOnRuim(int32_t serial, int32_t index);
    354 
    355     Return<void> getDeviceIdentity(int32_t serial);
    356 
    357     Return<void> exitEmergencyCallbackMode(int32_t serial);
    358 
    359     Return<void> getSmscAddress(int32_t serial);
    360 
    361     Return<void> setSmscAddress(int32_t serial,
    362             const ::android::hardware::hidl_string& smsc);
    363 
    364     Return<void> reportSmsMemoryStatus(int32_t serial, bool available);
    365 
    366     Return<void> reportStkServiceIsRunning(int32_t serial);
    367 
    368     Return<void> getCdmaSubscriptionSource(int32_t serial);
    369 
    370     Return<void> requestIsimAuthentication(int32_t serial,
    371             const ::android::hardware::hidl_string& challenge);
    372 
    373     Return<void> acknowledgeIncomingGsmSmsWithPdu(int32_t serial,
    374             bool success,
    375             const ::android::hardware::hidl_string& ackPdu);
    376 
    377     Return<void> sendEnvelopeWithStatus(int32_t serial,
    378             const ::android::hardware::hidl_string& contents);
    379 
    380     Return<void> getVoiceRadioTechnology(int32_t serial);
    381 
    382     Return<void> getCellInfoList(int32_t serial);
    383 
    384     Return<void> setCellInfoListRate(int32_t serial, int32_t rate);
    385 
    386     Return<void> setInitialAttachApn(int32_t serial, const DataProfileInfo& dataProfileInfo,
    387             bool modemCognitive, bool isRoaming);
    388 
    389     Return<void> getImsRegistrationState(int32_t serial);
    390 
    391     Return<void> sendImsSms(int32_t serial, const ImsSmsMessage& message);
    392 
    393     Return<void> iccTransmitApduBasicChannel(int32_t serial, const SimApdu& message);
    394 
    395     Return<void> iccOpenLogicalChannel(int32_t serial,
    396             const ::android::hardware::hidl_string& aid, int32_t p2);
    397 
    398     Return<void> iccCloseLogicalChannel(int32_t serial, int32_t channelId);
    399 
    400     Return<void> iccTransmitApduLogicalChannel(int32_t serial, const SimApdu& message);
    401 
    402     Return<void> nvReadItem(int32_t serial, NvItem itemId);
    403 
    404     Return<void> nvWriteItem(int32_t serial, const NvWriteItem& item);
    405 
    406     Return<void> nvWriteCdmaPrl(int32_t serial,
    407             const ::android::hardware::hidl_vec<uint8_t>& prl);
    408 
    409     Return<void> nvResetConfig(int32_t serial, ResetNvType resetType);
    410 
    411     Return<void> setUiccSubscription(int32_t serial, const SelectUiccSub& uiccSub);
    412 
    413     Return<void> setDataAllowed(int32_t serial, bool allow);
    414 
    415     Return<void> getHardwareConfig(int32_t serial);
    416 
    417     Return<void> requestIccSimAuthentication(int32_t serial,
    418             int32_t authContext,
    419             const ::android::hardware::hidl_string& authData,
    420             const ::android::hardware::hidl_string& aid);
    421 
    422     Return<void> setDataProfile(int32_t serial,
    423             const ::android::hardware::hidl_vec<DataProfileInfo>& profiles, bool isRoaming);
    424 
    425     Return<void> requestShutdown(int32_t serial);
    426 
    427     Return<void> getRadioCapability(int32_t serial);
    428 
    429     Return<void> setRadioCapability(int32_t serial, const RadioCapability& rc);
    430 
    431     Return<void> startLceService(int32_t serial, int32_t reportInterval, bool pullMode);
    432 
    433     Return<void> stopLceService(int32_t serial);
    434 
    435     Return<void> pullLceData(int32_t serial);
    436 
    437     Return<void> getModemActivityInfo(int32_t serial);
    438 
    439     Return<void> setAllowedCarriers(int32_t serial,
    440             bool allAllowed,
    441             const CarrierRestrictions& carriers);
    442 
    443     Return<void> getAllowedCarriers(int32_t serial);
    444 
    445     Return<void> sendDeviceState(int32_t serial, DeviceStateType deviceStateType, bool state);
    446 
    447     Return<void> setIndicationFilter(int32_t serial, int32_t indicationFilter);
    448 
    449     Return<void> startKeepalive(int32_t serial, const V1_1::KeepaliveRequest& keepalive);
    450 
    451     Return<void> stopKeepalive(int32_t serial, int32_t sessionHandle);
    452 
    453     Return<void> setSimCardPower(int32_t serial, bool powerUp);
    454     Return<void> setSimCardPower_1_1(int32_t serial,
    455             const V1_1::CardPowerState state);
    456 
    457     Return<void> responseAcknowledgement();
    458 
    459     Return<void> setCarrierInfoForImsiEncryption(int32_t serial,
    460             const V1_1::ImsiEncryptionInfo& message);
    461 
    462     void checkReturnStatus(Return<void>& ret);
    463 };
    464 
    465 struct OemHookImpl : public IOemHook {
    466     int32_t mSlotId;
    467     sp<IOemHookResponse> mOemHookResponse;
    468     sp<IOemHookIndication> mOemHookIndication;
    469 
    470     Return<void> setResponseFunctions(
    471             const ::android::sp<IOemHookResponse>& oemHookResponse,
    472             const ::android::sp<IOemHookIndication>& oemHookIndication);
    473 
    474     Return<void> sendRequestRaw(int32_t serial,
    475             const ::android::hardware::hidl_vec<uint8_t>& data);
    476 
    477     Return<void> sendRequestStrings(int32_t serial,
    478             const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& data);
    479 };
    480 
    481 void memsetAndFreeStrings(int numPointers, ...) {
    482     va_list ap;
    483     va_start(ap, numPointers);
    484     for (int i = 0; i < numPointers; i++) {
    485         char *ptr = va_arg(ap, char *);
    486         if (ptr) {
    487 #ifdef MEMSET_FREED
    488 #define MAX_STRING_LENGTH 4096
    489             memset(ptr, 0, strnlen(ptr, MAX_STRING_LENGTH));
    490 #endif
    491             free(ptr);
    492         }
    493     }
    494     va_end(ap);
    495 }
    496 
    497 void sendErrorResponse(RequestInfo *pRI, RIL_Errno err) {
    498     pRI->pCI->responseFunction((int) pRI->socket_id,
    499             (int) RadioResponseType::SOLICITED, pRI->token, err, NULL, 0);
    500 }
    501 
    502 /**
    503  * Copies over src to dest. If memory allocation fails, responseFunction() is called for the
    504  * request with error RIL_E_NO_MEMORY.
    505  * Returns true on success, and false on failure.
    506  */
    507 bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI, bool allowEmpty) {
    508     size_t len = src.size();
    509     if (len == 0 && !allowEmpty) {
    510         *dest = NULL;
    511         return true;
    512     }
    513     *dest = (char *) calloc(len + 1, sizeof(char));
    514     if (*dest == NULL) {
    515         RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
    516         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
    517         return false;
    518     }
    519     strncpy(*dest, src.c_str(), len + 1);
    520     return true;
    521 }
    522 
    523 bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI) {
    524     return copyHidlStringToRil(dest, src, pRI, false);
    525 }
    526 
    527 hidl_string convertCharPtrToHidlString(const char *ptr) {
    528     hidl_string ret;
    529     if (ptr != NULL) {
    530         // TODO: replace this with strnlen
    531         ret.setToExternal(ptr, strlen(ptr));
    532     }
    533     return ret;
    534 }
    535 
    536 bool dispatchVoid(int serial, int slotId, int request) {
    537     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
    538     if (pRI == NULL) {
    539         return false;
    540     }
    541     CALL_ONREQUEST(request, NULL, 0, pRI, slotId);
    542     return true;
    543 }
    544 
    545 bool dispatchString(int serial, int slotId, int request, const char * str) {
    546     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
    547     if (pRI == NULL) {
    548         return false;
    549     }
    550 
    551     char *pString;
    552     if (!copyHidlStringToRil(&pString, str, pRI)) {
    553         return false;
    554     }
    555 
    556     CALL_ONREQUEST(request, pString, sizeof(char *), pRI, slotId);
    557 
    558     memsetAndFreeStrings(1, pString);
    559     return true;
    560 }
    561 
    562 bool dispatchStrings(int serial, int slotId, int request, bool allowEmpty, int countStrings, ...) {
    563     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
    564     if (pRI == NULL) {
    565         return false;
    566     }
    567 
    568     char **pStrings;
    569     pStrings = (char **)calloc(countStrings, sizeof(char *));
    570     if (pStrings == NULL) {
    571         RLOGE("Memory allocation failed for request %s", requestToString(request));
    572         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
    573         return false;
    574     }
    575     va_list ap;
    576     va_start(ap, countStrings);
    577     for (int i = 0; i < countStrings; i++) {
    578         const char* str = va_arg(ap, const char *);
    579         if (!copyHidlStringToRil(&pStrings[i], hidl_string(str), pRI, allowEmpty)) {
    580             va_end(ap);
    581             for (int j = 0; j < i; j++) {
    582                 memsetAndFreeStrings(1, pStrings[j]);
    583             }
    584             free(pStrings);
    585             return false;
    586         }
    587     }
    588     va_end(ap);
    589 
    590     CALL_ONREQUEST(request, pStrings, countStrings * sizeof(char *), pRI, slotId);
    591 
    592     if (pStrings != NULL) {
    593         for (int i = 0 ; i < countStrings ; i++) {
    594             memsetAndFreeStrings(1, pStrings[i]);
    595         }
    596 
    597 #ifdef MEMSET_FREED
    598         memset(pStrings, 0, countStrings * sizeof(char *));
    599 #endif
    600         free(pStrings);
    601     }
    602     return true;
    603 }
    604 
    605 bool dispatchStrings(int serial, int slotId, int request, const hidl_vec<hidl_string>& data) {
    606     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
    607     if (pRI == NULL) {
    608         return false;
    609     }
    610 
    611     int countStrings = data.size();
    612     char **pStrings;
    613     pStrings = (char **)calloc(countStrings, sizeof(char *));
    614     if (pStrings == NULL) {
    615         RLOGE("Memory allocation failed for request %s", requestToString(request));
    616         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
    617         return false;
    618     }
    619 
    620     for (int i = 0; i < countStrings; i++) {
    621         if (!copyHidlStringToRil(&pStrings[i], data[i], pRI)) {
    622             for (int j = 0; j < i; j++) {
    623                 memsetAndFreeStrings(1, pStrings[j]);
    624             }
    625             free(pStrings);
    626             return false;
    627         }
    628     }
    629 
    630     CALL_ONREQUEST(request, pStrings, countStrings * sizeof(char *), pRI, slotId);
    631 
    632     if (pStrings != NULL) {
    633         for (int i = 0 ; i < countStrings ; i++) {
    634             memsetAndFreeStrings(1, pStrings[i]);
    635         }
    636 
    637 #ifdef MEMSET_FREED
    638         memset(pStrings, 0, countStrings * sizeof(char *));
    639 #endif
    640         free(pStrings);
    641     }
    642     return true;
    643 }
    644 
    645 bool dispatchInts(int serial, int slotId, int request, int countInts, ...) {
    646     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
    647     if (pRI == NULL) {
    648         return false;
    649     }
    650 
    651     int *pInts = (int *)calloc(countInts, sizeof(int));
    652 
    653     if (pInts == NULL) {
    654         RLOGE("Memory allocation failed for request %s", requestToString(request));
    655         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
    656         return false;
    657     }
    658     va_list ap;
    659     va_start(ap, countInts);
    660     for (int i = 0; i < countInts; i++) {
    661         pInts[i] = va_arg(ap, int);
    662     }
    663     va_end(ap);
    664 
    665     CALL_ONREQUEST(request, pInts, countInts * sizeof(int), pRI, slotId);
    666 
    667     if (pInts != NULL) {
    668 #ifdef MEMSET_FREED
    669         memset(pInts, 0, countInts * sizeof(int));
    670 #endif
    671         free(pInts);
    672     }
    673     return true;
    674 }
    675 
    676 bool dispatchCallForwardStatus(int serial, int slotId, int request,
    677                               const CallForwardInfo& callInfo) {
    678     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
    679     if (pRI == NULL) {
    680         return false;
    681     }
    682 
    683     RIL_CallForwardInfo cf;
    684     cf.status = (int) callInfo.status;
    685     cf.reason = callInfo.reason;
    686     cf.serviceClass = callInfo.serviceClass;
    687     cf.toa = callInfo.toa;
    688     cf.timeSeconds = callInfo.timeSeconds;
    689 
    690     if (!copyHidlStringToRil(&cf.number, callInfo.number, pRI)) {
    691         return false;
    692     }
    693 
    694     CALL_ONREQUEST(request, &cf, sizeof(cf), pRI, slotId);
    695 
    696     memsetAndFreeStrings(1, cf.number);
    697 
    698     return true;
    699 }
    700 
    701 bool dispatchRaw(int serial, int slotId, int request, const hidl_vec<uint8_t>& rawBytes) {
    702     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
    703     if (pRI == NULL) {
    704         return false;
    705     }
    706 
    707     const uint8_t *uData = rawBytes.data();
    708 
    709     CALL_ONREQUEST(request, (void *) uData, rawBytes.size(), pRI, slotId);
    710 
    711     return true;
    712 }
    713 
    714 bool dispatchIccApdu(int serial, int slotId, int request, const SimApdu& message) {
    715     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
    716     if (pRI == NULL) {
    717         return false;
    718     }
    719 
    720     RIL_SIM_APDU apdu = {};
    721 
    722     apdu.sessionid = message.sessionId;
    723     apdu.cla = message.cla;
    724     apdu.instruction = message.instruction;
    725     apdu.p1 = message.p1;
    726     apdu.p2 = message.p2;
    727     apdu.p3 = message.p3;
    728 
    729     if (!copyHidlStringToRil(&apdu.data, message.data, pRI)) {
    730         return false;
    731     }
    732 
    733     CALL_ONREQUEST(request, &apdu, sizeof(apdu), pRI, slotId);
    734 
    735     memsetAndFreeStrings(1, apdu.data);
    736 
    737     return true;
    738 }
    739 
    740 void checkReturnStatus(int32_t slotId, Return<void>& ret, bool isRadioService) {
    741     if (ret.isOk() == false) {
    742         RLOGE("checkReturnStatus: unable to call response/indication callback");
    743         // Remote process hosting the callbacks must be dead. Reset the callback objects;
    744         // there's no other recovery to be done here. When the client process is back up, it will
    745         // call setResponseFunctions()
    746 
    747         // Caller should already hold rdlock, release that first
    748         // note the current counter to avoid overwriting updates made by another thread before
    749         // write lock is acquired.
    750         int counter = isRadioService ? mCounterRadio[slotId] : mCounterOemHook[slotId];
    751         pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(slotId);
    752         int ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
    753         assert(ret == 0);
    754 
    755         // acquire wrlock
    756         ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
    757         assert(ret == 0);
    758 
    759         // make sure the counter value has not changed
    760         if (counter == (isRadioService ? mCounterRadio[slotId] : mCounterOemHook[slotId])) {
    761             if (isRadioService) {
    762                 radioService[slotId]->mRadioResponse = NULL;
    763                 radioService[slotId]->mRadioIndication = NULL;
    764                 radioService[slotId]->mRadioResponseV1_1 = NULL;
    765                 radioService[slotId]->mRadioIndicationV1_1 = NULL;
    766             } else {
    767                 oemHookService[slotId]->mOemHookResponse = NULL;
    768                 oemHookService[slotId]->mOemHookIndication = NULL;
    769             }
    770             isRadioService ? mCounterRadio[slotId]++ : mCounterOemHook[slotId]++;
    771         } else {
    772             RLOGE("checkReturnStatus: not resetting responseFunctions as they likely "
    773                     "got updated on another thread");
    774         }
    775 
    776         // release wrlock
    777         ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
    778         assert(ret == 0);
    779 
    780         // Reacquire rdlock
    781         ret = pthread_rwlock_rdlock(radioServiceRwlockPtr);
    782         assert(ret == 0);
    783     }
    784 }
    785 
    786 void RadioImpl::checkReturnStatus(Return<void>& ret) {
    787     ::checkReturnStatus(mSlotId, ret, true);
    788 }
    789 
    790 Return<void> RadioImpl::setResponseFunctions(
    791         const ::android::sp<IRadioResponse>& radioResponseParam,
    792         const ::android::sp<IRadioIndication>& radioIndicationParam) {
    793     RLOGD("setResponseFunctions");
    794 
    795     pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(mSlotId);
    796     int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
    797     assert(ret == 0);
    798 
    799     mRadioResponse = radioResponseParam;
    800     mRadioIndication = radioIndicationParam;
    801     mRadioResponseV1_1 = V1_1::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
    802     mRadioIndicationV1_1 = V1_1::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
    803     if (mRadioResponseV1_1 == nullptr || mRadioIndicationV1_1 == nullptr) {
    804         mRadioResponseV1_1 = nullptr;
    805         mRadioIndicationV1_1 = nullptr;
    806     }
    807 
    808     mCounterRadio[mSlotId]++;
    809 
    810     ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
    811     assert(ret == 0);
    812 
    813     // client is connected. Send initial indications.
    814     android::onNewCommandConnect((RIL_SOCKET_ID) mSlotId);
    815 
    816     return Void();
    817 }
    818 
    819 Return<void> RadioImpl::getIccCardStatus(int32_t serial) {
    820 #if VDBG
    821     RLOGD("getIccCardStatus: serial %d", serial);
    822 #endif
    823     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SIM_STATUS);
    824     return Void();
    825 }
    826 
    827 Return<void> RadioImpl::supplyIccPinForApp(int32_t serial, const hidl_string& pin,
    828         const hidl_string& aid) {
    829 #if VDBG
    830     RLOGD("supplyIccPinForApp: serial %d", serial);
    831 #endif
    832     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN, true,
    833             2, pin.c_str(), aid.c_str());
    834     return Void();
    835 }
    836 
    837 Return<void> RadioImpl::supplyIccPukForApp(int32_t serial, const hidl_string& puk,
    838                                            const hidl_string& pin, const hidl_string& aid) {
    839 #if VDBG
    840     RLOGD("supplyIccPukForApp: serial %d", serial);
    841 #endif
    842     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK, true,
    843             3, puk.c_str(), pin.c_str(), aid.c_str());
    844     return Void();
    845 }
    846 
    847 Return<void> RadioImpl::supplyIccPin2ForApp(int32_t serial, const hidl_string& pin2,
    848                                             const hidl_string& aid) {
    849 #if VDBG
    850     RLOGD("supplyIccPin2ForApp: serial %d", serial);
    851 #endif
    852     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN2, true,
    853             2, pin2.c_str(), aid.c_str());
    854     return Void();
    855 }
    856 
    857 Return<void> RadioImpl::supplyIccPuk2ForApp(int32_t serial, const hidl_string& puk2,
    858                                             const hidl_string& pin2, const hidl_string& aid) {
    859 #if VDBG
    860     RLOGD("supplyIccPuk2ForApp: serial %d", serial);
    861 #endif
    862     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK2, true,
    863             3, puk2.c_str(), pin2.c_str(), aid.c_str());
    864     return Void();
    865 }
    866 
    867 Return<void> RadioImpl::changeIccPinForApp(int32_t serial, const hidl_string& oldPin,
    868                                            const hidl_string& newPin, const hidl_string& aid) {
    869 #if VDBG
    870     RLOGD("changeIccPinForApp: serial %d", serial);
    871 #endif
    872     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN, true,
    873             3, oldPin.c_str(), newPin.c_str(), aid.c_str());
    874     return Void();
    875 }
    876 
    877 Return<void> RadioImpl::changeIccPin2ForApp(int32_t serial, const hidl_string& oldPin2,
    878                                             const hidl_string& newPin2, const hidl_string& aid) {
    879 #if VDBG
    880     RLOGD("changeIccPin2ForApp: serial %d", serial);
    881 #endif
    882     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN2, true,
    883             3, oldPin2.c_str(), newPin2.c_str(), aid.c_str());
    884     return Void();
    885 }
    886 
    887 Return<void> RadioImpl::supplyNetworkDepersonalization(int32_t serial,
    888                                                        const hidl_string& netPin) {
    889 #if VDBG
    890     RLOGD("supplyNetworkDepersonalization: serial %d", serial);
    891 #endif
    892     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, true,
    893             1, netPin.c_str());
    894     return Void();
    895 }
    896 
    897 Return<void> RadioImpl::getCurrentCalls(int32_t serial) {
    898 #if VDBG
    899     RLOGD("getCurrentCalls: serial %d", serial);
    900 #endif
    901     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CURRENT_CALLS);
    902     return Void();
    903 }
    904 
    905 Return<void> RadioImpl::dial(int32_t serial, const Dial& dialInfo) {
    906 #if VDBG
    907     RLOGD("dial: serial %d", serial);
    908 #endif
    909     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_DIAL);
    910     if (pRI == NULL) {
    911         return Void();
    912     }
    913     RIL_Dial dial = {};
    914     RIL_UUS_Info uusInfo = {};
    915     int32_t sizeOfDial = sizeof(dial);
    916 
    917     if (!copyHidlStringToRil(&dial.address, dialInfo.address, pRI)) {
    918         return Void();
    919     }
    920     dial.clir = (int) dialInfo.clir;
    921 
    922     if (dialInfo.uusInfo.size() != 0) {
    923         uusInfo.uusType = (RIL_UUS_Type) dialInfo.uusInfo[0].uusType;
    924         uusInfo.uusDcs = (RIL_UUS_DCS) dialInfo.uusInfo[0].uusDcs;
    925 
    926         if (dialInfo.uusInfo[0].uusData.size() == 0) {
    927             uusInfo.uusData = NULL;
    928             uusInfo.uusLength = 0;
    929         } else {
    930             if (!copyHidlStringToRil(&uusInfo.uusData, dialInfo.uusInfo[0].uusData, pRI)) {
    931                 memsetAndFreeStrings(1, dial.address);
    932                 return Void();
    933             }
    934             uusInfo.uusLength = dialInfo.uusInfo[0].uusData.size();
    935         }
    936 
    937         dial.uusInfo = &uusInfo;
    938     }
    939 
    940     CALL_ONREQUEST(RIL_REQUEST_DIAL, &dial, sizeOfDial, pRI, mSlotId);
    941 
    942     memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
    943 
    944     return Void();
    945 }
    946 
    947 Return<void> RadioImpl::getImsiForApp(int32_t serial, const hidl_string& aid) {
    948 #if VDBG
    949     RLOGD("getImsiForApp: serial %d", serial);
    950 #endif
    951     dispatchStrings(serial, mSlotId, RIL_REQUEST_GET_IMSI, false,
    952             1, aid.c_str());
    953     return Void();
    954 }
    955 
    956 Return<void> RadioImpl::hangup(int32_t serial, int32_t gsmIndex) {
    957 #if VDBG
    958     RLOGD("hangup: serial %d", serial);
    959 #endif
    960     dispatchInts(serial, mSlotId, RIL_REQUEST_HANGUP, 1, gsmIndex);
    961     return Void();
    962 }
    963 
    964 Return<void> RadioImpl::hangupWaitingOrBackground(int32_t serial) {
    965 #if VDBG
    966     RLOGD("hangupWaitingOrBackground: serial %d", serial);
    967 #endif
    968     dispatchVoid(serial, mSlotId, RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND);
    969     return Void();
    970 }
    971 
    972 Return<void> RadioImpl::hangupForegroundResumeBackground(int32_t serial) {
    973 #if VDBG
    974     RLOGD("hangupForegroundResumeBackground: serial %d", serial);
    975 #endif
    976     dispatchVoid(serial, mSlotId, RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND);
    977     return Void();
    978 }
    979 
    980 Return<void> RadioImpl::switchWaitingOrHoldingAndActive(int32_t serial) {
    981 #if VDBG
    982     RLOGD("switchWaitingOrHoldingAndActive: serial %d", serial);
    983 #endif
    984     dispatchVoid(serial, mSlotId, RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE);
    985     return Void();
    986 }
    987 
    988 Return<void> RadioImpl::conference(int32_t serial) {
    989 #if VDBG
    990     RLOGD("conference: serial %d", serial);
    991 #endif
    992     dispatchVoid(serial, mSlotId, RIL_REQUEST_CONFERENCE);
    993     return Void();
    994 }
    995 
    996 Return<void> RadioImpl::rejectCall(int32_t serial) {
    997 #if VDBG
    998     RLOGD("rejectCall: serial %d", serial);
    999 #endif
   1000     dispatchVoid(serial, mSlotId, RIL_REQUEST_UDUB);
   1001     return Void();
   1002 }
   1003 
   1004 Return<void> RadioImpl::getLastCallFailCause(int32_t serial) {
   1005 #if VDBG
   1006     RLOGD("getLastCallFailCause: serial %d", serial);
   1007 #endif
   1008     dispatchVoid(serial, mSlotId, RIL_REQUEST_LAST_CALL_FAIL_CAUSE);
   1009     return Void();
   1010 }
   1011 
   1012 Return<void> RadioImpl::getSignalStrength(int32_t serial) {
   1013 #if VDBG
   1014     RLOGD("getSignalStrength: serial %d", serial);
   1015 #endif
   1016     dispatchVoid(serial, mSlotId, RIL_REQUEST_SIGNAL_STRENGTH);
   1017     return Void();
   1018 }
   1019 
   1020 Return<void> RadioImpl::getVoiceRegistrationState(int32_t serial) {
   1021 #if VDBG
   1022     RLOGD("getVoiceRegistrationState: serial %d", serial);
   1023 #endif
   1024     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_REGISTRATION_STATE);
   1025     return Void();
   1026 }
   1027 
   1028 Return<void> RadioImpl::getDataRegistrationState(int32_t serial) {
   1029 #if VDBG
   1030     RLOGD("getDataRegistrationState: serial %d", serial);
   1031 #endif
   1032     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_REGISTRATION_STATE);
   1033     return Void();
   1034 }
   1035 
   1036 Return<void> RadioImpl::getOperator(int32_t serial) {
   1037 #if VDBG
   1038     RLOGD("getOperator: serial %d", serial);
   1039 #endif
   1040     dispatchVoid(serial, mSlotId, RIL_REQUEST_OPERATOR);
   1041     return Void();
   1042 }
   1043 
   1044 Return<void> RadioImpl::setRadioPower(int32_t serial, bool on) {
   1045     RLOGD("setRadioPower: serial %d on %d", serial, on);
   1046     dispatchInts(serial, mSlotId, RIL_REQUEST_RADIO_POWER, 1, BOOL_TO_INT(on));
   1047     return Void();
   1048 }
   1049 
   1050 Return<void> RadioImpl::sendDtmf(int32_t serial, const hidl_string& s) {
   1051 #if VDBG
   1052     RLOGD("sendDtmf: serial %d", serial);
   1053 #endif
   1054     dispatchString(serial, mSlotId, RIL_REQUEST_DTMF, s.c_str());
   1055     return Void();
   1056 }
   1057 
   1058 Return<void> RadioImpl::sendSms(int32_t serial, const GsmSmsMessage& message) {
   1059 #if VDBG
   1060     RLOGD("sendSms: serial %d", serial);
   1061 #endif
   1062     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS, false,
   1063             2, message.smscPdu.c_str(), message.pdu.c_str());
   1064     return Void();
   1065 }
   1066 
   1067 Return<void> RadioImpl::sendSMSExpectMore(int32_t serial, const GsmSmsMessage& message) {
   1068 #if VDBG
   1069     RLOGD("sendSMSExpectMore: serial %d", serial);
   1070 #endif
   1071     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS_EXPECT_MORE, false,
   1072             2, message.smscPdu.c_str(), message.pdu.c_str());
   1073     return Void();
   1074 }
   1075 
   1076 static bool convertMvnoTypeToString(MvnoType type, char *&str) {
   1077     switch (type) {
   1078         case MvnoType::IMSI:
   1079             str = (char *)"imsi";
   1080             return true;
   1081         case MvnoType::GID:
   1082             str = (char *)"gid";
   1083             return true;
   1084         case MvnoType::SPN:
   1085             str = (char *)"spn";
   1086             return true;
   1087         case MvnoType::NONE:
   1088             str = (char *)"";
   1089             return true;
   1090     }
   1091     return false;
   1092 }
   1093 
   1094 Return<void> RadioImpl::setupDataCall(int32_t serial, RadioTechnology radioTechnology,
   1095                                       const DataProfileInfo& dataProfileInfo, bool modemCognitive,
   1096                                       bool roamingAllowed, bool isRoaming) {
   1097 
   1098 #if VDBG
   1099     RLOGD("setupDataCall: serial %d", serial);
   1100 #endif
   1101 
   1102     if (s_vendorFunctions->version >= 4 && s_vendorFunctions->version <= 14) {
   1103         const hidl_string &protocol =
   1104                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
   1105         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 7,
   1106             std::to_string((int) radioTechnology + 2).c_str(),
   1107             std::to_string((int) dataProfileInfo.profileId).c_str(),
   1108             dataProfileInfo.apn.c_str(),
   1109             dataProfileInfo.user.c_str(),
   1110             dataProfileInfo.password.c_str(),
   1111             std::to_string((int) dataProfileInfo.authType).c_str(),
   1112             protocol.c_str());
   1113     } else if (s_vendorFunctions->version >= 15) {
   1114         char *mvnoTypeStr = NULL;
   1115         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) {
   1116             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   1117                     RIL_REQUEST_SETUP_DATA_CALL);
   1118             if (pRI != NULL) {
   1119                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   1120             }
   1121             return Void();
   1122         }
   1123         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15,
   1124             std::to_string((int) radioTechnology + 2).c_str(),
   1125             std::to_string((int) dataProfileInfo.profileId).c_str(),
   1126             dataProfileInfo.apn.c_str(),
   1127             dataProfileInfo.user.c_str(),
   1128             dataProfileInfo.password.c_str(),
   1129             std::to_string((int) dataProfileInfo.authType).c_str(),
   1130             dataProfileInfo.protocol.c_str(),
   1131             dataProfileInfo.roamingProtocol.c_str(),
   1132             std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
   1133             std::to_string(dataProfileInfo.bearerBitmap).c_str(),
   1134             modemCognitive ? "1" : "0",
   1135             std::to_string(dataProfileInfo.mtu).c_str(),
   1136             mvnoTypeStr,
   1137             dataProfileInfo.mvnoMatchData.c_str(),
   1138             roamingAllowed ? "1" : "0");
   1139     } else {
   1140         RLOGE("Unsupported RIL version %d, min version expected 4", s_vendorFunctions->version);
   1141         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   1142                 RIL_REQUEST_SETUP_DATA_CALL);
   1143         if (pRI != NULL) {
   1144             sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
   1145         }
   1146     }
   1147     return Void();
   1148 }
   1149 
   1150 Return<void> RadioImpl::iccIOForApp(int32_t serial, const IccIo& iccIo) {
   1151 #if VDBG
   1152     RLOGD("iccIOForApp: serial %d", serial);
   1153 #endif
   1154     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_IO);
   1155     if (pRI == NULL) {
   1156         return Void();
   1157     }
   1158 
   1159     RIL_SIM_IO_v6 rilIccIo = {};
   1160     rilIccIo.command = iccIo.command;
   1161     rilIccIo.fileid = iccIo.fileId;
   1162     if (!copyHidlStringToRil(&rilIccIo.path, iccIo.path, pRI)) {
   1163         return Void();
   1164     }
   1165 
   1166     rilIccIo.p1 = iccIo.p1;
   1167     rilIccIo.p2 = iccIo.p2;
   1168     rilIccIo.p3 = iccIo.p3;
   1169 
   1170     if (!copyHidlStringToRil(&rilIccIo.data, iccIo.data, pRI)) {
   1171         memsetAndFreeStrings(1, rilIccIo.path);
   1172         return Void();
   1173     }
   1174 
   1175     if (!copyHidlStringToRil(&rilIccIo.pin2, iccIo.pin2, pRI)) {
   1176         memsetAndFreeStrings(2, rilIccIo.path, rilIccIo.data);
   1177         return Void();
   1178     }
   1179 
   1180     if (!copyHidlStringToRil(&rilIccIo.aidPtr, iccIo.aid, pRI)) {
   1181         memsetAndFreeStrings(3, rilIccIo.path, rilIccIo.data, rilIccIo.pin2);
   1182         return Void();
   1183     }
   1184 
   1185     CALL_ONREQUEST(RIL_REQUEST_SIM_IO, &rilIccIo, sizeof(rilIccIo), pRI, mSlotId);
   1186 
   1187     memsetAndFreeStrings(4, rilIccIo.path, rilIccIo.data, rilIccIo.pin2, rilIccIo.aidPtr);
   1188 
   1189     return Void();
   1190 }
   1191 
   1192 Return<void> RadioImpl::sendUssd(int32_t serial, const hidl_string& ussd) {
   1193 #if VDBG
   1194     RLOGD("sendUssd: serial %d", serial);
   1195 #endif
   1196     dispatchString(serial, mSlotId, RIL_REQUEST_SEND_USSD, ussd.c_str());
   1197     return Void();
   1198 }
   1199 
   1200 Return<void> RadioImpl::cancelPendingUssd(int32_t serial) {
   1201 #if VDBG
   1202     RLOGD("cancelPendingUssd: serial %d", serial);
   1203 #endif
   1204     dispatchVoid(serial, mSlotId, RIL_REQUEST_CANCEL_USSD);
   1205     return Void();
   1206 }
   1207 
   1208 Return<void> RadioImpl::getClir(int32_t serial) {
   1209 #if VDBG
   1210     RLOGD("getClir: serial %d", serial);
   1211 #endif
   1212     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CLIR);
   1213     return Void();
   1214 }
   1215 
   1216 Return<void> RadioImpl::setClir(int32_t serial, int32_t status) {
   1217 #if VDBG
   1218     RLOGD("setClir: serial %d", serial);
   1219 #endif
   1220     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_CLIR, 1, status);
   1221     return Void();
   1222 }
   1223 
   1224 Return<void> RadioImpl::getCallForwardStatus(int32_t serial, const CallForwardInfo& callInfo) {
   1225 #if VDBG
   1226     RLOGD("getCallForwardStatus: serial %d", serial);
   1227 #endif
   1228     dispatchCallForwardStatus(serial, mSlotId, RIL_REQUEST_QUERY_CALL_FORWARD_STATUS,
   1229             callInfo);
   1230     return Void();
   1231 }
   1232 
   1233 Return<void> RadioImpl::setCallForward(int32_t serial, const CallForwardInfo& callInfo) {
   1234 #if VDBG
   1235     RLOGD("setCallForward: serial %d", serial);
   1236 #endif
   1237     dispatchCallForwardStatus(serial, mSlotId, RIL_REQUEST_SET_CALL_FORWARD,
   1238             callInfo);
   1239     return Void();
   1240 }
   1241 
   1242 Return<void> RadioImpl::getCallWaiting(int32_t serial, int32_t serviceClass) {
   1243 #if VDBG
   1244     RLOGD("getCallWaiting: serial %d", serial);
   1245 #endif
   1246     dispatchInts(serial, mSlotId, RIL_REQUEST_QUERY_CALL_WAITING, 1, serviceClass);
   1247     return Void();
   1248 }
   1249 
   1250 Return<void> RadioImpl::setCallWaiting(int32_t serial, bool enable, int32_t serviceClass) {
   1251 #if VDBG
   1252     RLOGD("setCallWaiting: serial %d", serial);
   1253 #endif
   1254     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_CALL_WAITING, 2, BOOL_TO_INT(enable),
   1255             serviceClass);
   1256     return Void();
   1257 }
   1258 
   1259 Return<void> RadioImpl::acknowledgeLastIncomingGsmSms(int32_t serial,
   1260                                                       bool success, SmsAcknowledgeFailCause cause) {
   1261 #if VDBG
   1262     RLOGD("acknowledgeLastIncomingGsmSms: serial %d", serial);
   1263 #endif
   1264     dispatchInts(serial, mSlotId, RIL_REQUEST_SMS_ACKNOWLEDGE, 2, BOOL_TO_INT(success),
   1265             cause);
   1266     return Void();
   1267 }
   1268 
   1269 Return<void> RadioImpl::acceptCall(int32_t serial) {
   1270 #if VDBG
   1271     RLOGD("acceptCall: serial %d", serial);
   1272 #endif
   1273     dispatchVoid(serial, mSlotId, RIL_REQUEST_ANSWER);
   1274     return Void();
   1275 }
   1276 
   1277 Return<void> RadioImpl::deactivateDataCall(int32_t serial,
   1278                                            int32_t cid, bool reasonRadioShutDown) {
   1279 #if VDBG
   1280     RLOGD("deactivateDataCall: serial %d", serial);
   1281 #endif
   1282     dispatchStrings(serial, mSlotId, RIL_REQUEST_DEACTIVATE_DATA_CALL, false,
   1283             2, (std::to_string(cid)).c_str(), reasonRadioShutDown ? "1" : "0");
   1284     return Void();
   1285 }
   1286 
   1287 Return<void> RadioImpl::getFacilityLockForApp(int32_t serial, const hidl_string& facility,
   1288                                               const hidl_string& password, int32_t serviceClass,
   1289                                               const hidl_string& appId) {
   1290 #if VDBG
   1291     RLOGD("getFacilityLockForApp: serial %d", serial);
   1292 #endif
   1293     dispatchStrings(serial, mSlotId, RIL_REQUEST_QUERY_FACILITY_LOCK, true,
   1294             4, facility.c_str(), password.c_str(),
   1295             (std::to_string(serviceClass)).c_str(), appId.c_str());
   1296     return Void();
   1297 }
   1298 
   1299 Return<void> RadioImpl::setFacilityLockForApp(int32_t serial, const hidl_string& facility,
   1300                                               bool lockState, const hidl_string& password,
   1301                                               int32_t serviceClass, const hidl_string& appId) {
   1302 #if VDBG
   1303     RLOGD("setFacilityLockForApp: serial %d", serial);
   1304 #endif
   1305     dispatchStrings(serial, mSlotId, RIL_REQUEST_SET_FACILITY_LOCK, true,
   1306             5, facility.c_str(), lockState ? "1" : "0", password.c_str(),
   1307             (std::to_string(serviceClass)).c_str(), appId.c_str() );
   1308     return Void();
   1309 }
   1310 
   1311 Return<void> RadioImpl::setBarringPassword(int32_t serial, const hidl_string& facility,
   1312                                            const hidl_string& oldPassword,
   1313                                            const hidl_string& newPassword) {
   1314 #if VDBG
   1315     RLOGD("setBarringPassword: serial %d", serial);
   1316 #endif
   1317     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_BARRING_PASSWORD, true,
   1318             3, facility.c_str(), oldPassword.c_str(), newPassword.c_str());
   1319     return Void();
   1320 }
   1321 
   1322 Return<void> RadioImpl::getNetworkSelectionMode(int32_t serial) {
   1323 #if VDBG
   1324     RLOGD("getNetworkSelectionMode: serial %d", serial);
   1325 #endif
   1326     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE);
   1327     return Void();
   1328 }
   1329 
   1330 Return<void> RadioImpl::setNetworkSelectionModeAutomatic(int32_t serial) {
   1331 #if VDBG
   1332     RLOGD("setNetworkSelectionModeAutomatic: serial %d", serial);
   1333 #endif
   1334     dispatchVoid(serial, mSlotId, RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC);
   1335     return Void();
   1336 }
   1337 
   1338 Return<void> RadioImpl::setNetworkSelectionModeManual(int32_t serial,
   1339                                                       const hidl_string& operatorNumeric) {
   1340 #if VDBG
   1341     RLOGD("setNetworkSelectionModeManual: serial %d", serial);
   1342 #endif
   1343     dispatchString(serial, mSlotId, RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL,
   1344             operatorNumeric.c_str());
   1345     return Void();
   1346 }
   1347 
   1348 Return<void> RadioImpl::getAvailableNetworks(int32_t serial) {
   1349 #if VDBG
   1350     RLOGD("getAvailableNetworks: serial %d", serial);
   1351 #endif
   1352     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_AVAILABLE_NETWORKS);
   1353     return Void();
   1354 }
   1355 
   1356 Return<void> RadioImpl::startNetworkScan(int32_t serial, const V1_1::NetworkScanRequest& request) {
   1357 #if VDBG
   1358     RLOGD("startNetworkScan: serial %d", serial);
   1359 #endif
   1360 
   1361     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
   1362     if (pRI == NULL) {
   1363         return Void();
   1364     }
   1365 
   1366     if (request.specifiers.size() > MAX_RADIO_ACCESS_NETWORKS) {
   1367         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   1368         return Void();
   1369     }
   1370 
   1371     RIL_NetworkScanRequest scan_request = {};
   1372 
   1373     scan_request.type = (RIL_ScanType) request.type;
   1374     scan_request.interval = request.interval;
   1375     scan_request.specifiers_length = request.specifiers.size();
   1376     for (size_t i = 0; i < request.specifiers.size(); ++i) {
   1377         if (request.specifiers[i].geranBands.size() > MAX_BANDS ||
   1378             request.specifiers[i].utranBands.size() > MAX_BANDS ||
   1379             request.specifiers[i].eutranBands.size() > MAX_BANDS ||
   1380             request.specifiers[i].channels.size() > MAX_CHANNELS) {
   1381             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   1382             return Void();
   1383         }
   1384         const V1_1::RadioAccessSpecifier& ras_from =
   1385                 request.specifiers[i];
   1386         RIL_RadioAccessSpecifier& ras_to = scan_request.specifiers[i];
   1387 
   1388         ras_to.radio_access_network = (RIL_RadioAccessNetworks) ras_from.radioAccessNetwork;
   1389         ras_to.channels_length = ras_from.channels.size();
   1390 
   1391         std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
   1392         const std::vector<uint32_t> * bands = nullptr;
   1393         switch (request.specifiers[i].radioAccessNetwork) {
   1394             case V1_1::RadioAccessNetworks::GERAN:
   1395                 ras_to.bands_length = ras_from.geranBands.size();
   1396                 bands = (std::vector<uint32_t> *) &ras_from.geranBands;
   1397                 break;
   1398             case V1_1::RadioAccessNetworks::UTRAN:
   1399                 ras_to.bands_length = ras_from.utranBands.size();
   1400                 bands = (std::vector<uint32_t> *) &ras_from.utranBands;
   1401                 break;
   1402             case V1_1::RadioAccessNetworks::EUTRAN:
   1403                 ras_to.bands_length = ras_from.eutranBands.size();
   1404                 bands = (std::vector<uint32_t> *) &ras_from.eutranBands;
   1405                 break;
   1406             default:
   1407                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   1408                 return Void();
   1409         }
   1410         // safe to copy to geran_bands because it's a union member
   1411         for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
   1412             ras_to.bands.geran_bands[idx] = (RIL_GeranBands) (*bands)[idx];
   1413         }
   1414     }
   1415 
   1416     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
   1417             mSlotId);
   1418 
   1419     return Void();
   1420 }
   1421 
   1422 Return<void> RadioImpl::stopNetworkScan(int32_t serial) {
   1423 #if VDBG
   1424     RLOGD("stopNetworkScan: serial %d", serial);
   1425 #endif
   1426     dispatchVoid(serial, mSlotId, RIL_REQUEST_STOP_NETWORK_SCAN);
   1427     return Void();
   1428 }
   1429 
   1430 Return<void> RadioImpl::startDtmf(int32_t serial, const hidl_string& s) {
   1431 #if VDBG
   1432     RLOGD("startDtmf: serial %d", serial);
   1433 #endif
   1434     dispatchString(serial, mSlotId, RIL_REQUEST_DTMF_START,
   1435             s.c_str());
   1436     return Void();
   1437 }
   1438 
   1439 Return<void> RadioImpl::stopDtmf(int32_t serial) {
   1440 #if VDBG
   1441     RLOGD("stopDtmf: serial %d", serial);
   1442 #endif
   1443     dispatchVoid(serial, mSlotId, RIL_REQUEST_DTMF_STOP);
   1444     return Void();
   1445 }
   1446 
   1447 Return<void> RadioImpl::getBasebandVersion(int32_t serial) {
   1448 #if VDBG
   1449     RLOGD("getBasebandVersion: serial %d", serial);
   1450 #endif
   1451     dispatchVoid(serial, mSlotId, RIL_REQUEST_BASEBAND_VERSION);
   1452     return Void();
   1453 }
   1454 
   1455 Return<void> RadioImpl::separateConnection(int32_t serial, int32_t gsmIndex) {
   1456 #if VDBG
   1457     RLOGD("separateConnection: serial %d", serial);
   1458 #endif
   1459     dispatchInts(serial, mSlotId, RIL_REQUEST_SEPARATE_CONNECTION, 1, gsmIndex);
   1460     return Void();
   1461 }
   1462 
   1463 Return<void> RadioImpl::setMute(int32_t serial, bool enable) {
   1464 #if VDBG
   1465     RLOGD("setMute: serial %d", serial);
   1466 #endif
   1467     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_MUTE, 1, BOOL_TO_INT(enable));
   1468     return Void();
   1469 }
   1470 
   1471 Return<void> RadioImpl::getMute(int32_t serial) {
   1472 #if VDBG
   1473     RLOGD("getMute: serial %d", serial);
   1474 #endif
   1475     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_MUTE);
   1476     return Void();
   1477 }
   1478 
   1479 Return<void> RadioImpl::getClip(int32_t serial) {
   1480 #if VDBG
   1481     RLOGD("getClip: serial %d", serial);
   1482 #endif
   1483     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_CLIP);
   1484     return Void();
   1485 }
   1486 
   1487 Return<void> RadioImpl::getDataCallList(int32_t serial) {
   1488 #if VDBG
   1489     RLOGD("getDataCallList: serial %d", serial);
   1490 #endif
   1491     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_CALL_LIST);
   1492     return Void();
   1493 }
   1494 
   1495 Return<void> RadioImpl::setSuppServiceNotifications(int32_t serial, bool enable) {
   1496 #if VDBG
   1497     RLOGD("setSuppServiceNotifications: serial %d", serial);
   1498 #endif
   1499     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, 1,
   1500             BOOL_TO_INT(enable));
   1501     return Void();
   1502 }
   1503 
   1504 Return<void> RadioImpl::writeSmsToSim(int32_t serial, const SmsWriteArgs& smsWriteArgs) {
   1505 #if VDBG
   1506     RLOGD("writeSmsToSim: serial %d", serial);
   1507 #endif
   1508     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_WRITE_SMS_TO_SIM);
   1509     if (pRI == NULL) {
   1510         return Void();
   1511     }
   1512 
   1513     RIL_SMS_WriteArgs args;
   1514     args.status = (int) smsWriteArgs.status;
   1515 
   1516     if (!copyHidlStringToRil(&args.pdu, smsWriteArgs.pdu, pRI)) {
   1517         return Void();
   1518     }
   1519 
   1520     if (!copyHidlStringToRil(&args.smsc, smsWriteArgs.smsc, pRI)) {
   1521         memsetAndFreeStrings(1, args.pdu);
   1522         return Void();
   1523     }
   1524 
   1525     CALL_ONREQUEST(RIL_REQUEST_WRITE_SMS_TO_SIM, &args, sizeof(args), pRI, mSlotId);
   1526 
   1527     memsetAndFreeStrings(2, args.smsc, args.pdu);
   1528 
   1529     return Void();
   1530 }
   1531 
   1532 Return<void> RadioImpl::deleteSmsOnSim(int32_t serial, int32_t index) {
   1533 #if VDBG
   1534     RLOGD("deleteSmsOnSim: serial %d", serial);
   1535 #endif
   1536     dispatchInts(serial, mSlotId, RIL_REQUEST_DELETE_SMS_ON_SIM, 1, index);
   1537     return Void();
   1538 }
   1539 
   1540 Return<void> RadioImpl::setBandMode(int32_t serial, RadioBandMode mode) {
   1541 #if VDBG
   1542     RLOGD("setBandMode: serial %d", serial);
   1543 #endif
   1544     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_BAND_MODE, 1, mode);
   1545     return Void();
   1546 }
   1547 
   1548 Return<void> RadioImpl::getAvailableBandModes(int32_t serial) {
   1549 #if VDBG
   1550     RLOGD("getAvailableBandModes: serial %d", serial);
   1551 #endif
   1552     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE);
   1553     return Void();
   1554 }
   1555 
   1556 Return<void> RadioImpl::sendEnvelope(int32_t serial, const hidl_string& command) {
   1557 #if VDBG
   1558     RLOGD("sendEnvelope: serial %d", serial);
   1559 #endif
   1560     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND,
   1561             command.c_str());
   1562     return Void();
   1563 }
   1564 
   1565 Return<void> RadioImpl::sendTerminalResponseToSim(int32_t serial,
   1566                                                   const hidl_string& commandResponse) {
   1567 #if VDBG
   1568     RLOGD("sendTerminalResponseToSim: serial %d", serial);
   1569 #endif
   1570     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE,
   1571             commandResponse.c_str());
   1572     return Void();
   1573 }
   1574 
   1575 Return<void> RadioImpl::handleStkCallSetupRequestFromSim(int32_t serial, bool accept) {
   1576 #if VDBG
   1577     RLOGD("handleStkCallSetupRequestFromSim: serial %d", serial);
   1578 #endif
   1579     dispatchInts(serial, mSlotId, RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,
   1580             1, BOOL_TO_INT(accept));
   1581     return Void();
   1582 }
   1583 
   1584 Return<void> RadioImpl::explicitCallTransfer(int32_t serial) {
   1585 #if VDBG
   1586     RLOGD("explicitCallTransfer: serial %d", serial);
   1587 #endif
   1588     dispatchVoid(serial, mSlotId, RIL_REQUEST_EXPLICIT_CALL_TRANSFER);
   1589     return Void();
   1590 }
   1591 
   1592 Return<void> RadioImpl::setPreferredNetworkType(int32_t serial, PreferredNetworkType nwType) {
   1593 #if VDBG
   1594     RLOGD("setPreferredNetworkType: serial %d", serial);
   1595 #endif
   1596     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, 1, nwType);
   1597     return Void();
   1598 }
   1599 
   1600 Return<void> RadioImpl::getPreferredNetworkType(int32_t serial) {
   1601 #if VDBG
   1602     RLOGD("getPreferredNetworkType: serial %d", serial);
   1603 #endif
   1604     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE);
   1605     return Void();
   1606 }
   1607 
   1608 Return<void> RadioImpl::getNeighboringCids(int32_t serial) {
   1609 #if VDBG
   1610     RLOGD("getNeighboringCids: serial %d", serial);
   1611 #endif
   1612     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_NEIGHBORING_CELL_IDS);
   1613     return Void();
   1614 }
   1615 
   1616 Return<void> RadioImpl::setLocationUpdates(int32_t serial, bool enable) {
   1617 #if VDBG
   1618     RLOGD("setLocationUpdates: serial %d", serial);
   1619 #endif
   1620     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_LOCATION_UPDATES, 1, BOOL_TO_INT(enable));
   1621     return Void();
   1622 }
   1623 
   1624 Return<void> RadioImpl::setCdmaSubscriptionSource(int32_t serial, CdmaSubscriptionSource cdmaSub) {
   1625 #if VDBG
   1626     RLOGD("setCdmaSubscriptionSource: serial %d", serial);
   1627 #endif
   1628     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, 1, cdmaSub);
   1629     return Void();
   1630 }
   1631 
   1632 Return<void> RadioImpl::setCdmaRoamingPreference(int32_t serial, CdmaRoamingType type) {
   1633 #if VDBG
   1634     RLOGD("setCdmaRoamingPreference: serial %d", serial);
   1635 #endif
   1636     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, 1, type);
   1637     return Void();
   1638 }
   1639 
   1640 Return<void> RadioImpl::getCdmaRoamingPreference(int32_t serial) {
   1641 #if VDBG
   1642     RLOGD("getCdmaRoamingPreference: serial %d", serial);
   1643 #endif
   1644     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE);
   1645     return Void();
   1646 }
   1647 
   1648 Return<void> RadioImpl::setTTYMode(int32_t serial, TtyMode mode) {
   1649 #if VDBG
   1650     RLOGD("setTTYMode: serial %d", serial);
   1651 #endif
   1652     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_TTY_MODE, 1, mode);
   1653     return Void();
   1654 }
   1655 
   1656 Return<void> RadioImpl::getTTYMode(int32_t serial) {
   1657 #if VDBG
   1658     RLOGD("getTTYMode: serial %d", serial);
   1659 #endif
   1660     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_TTY_MODE);
   1661     return Void();
   1662 }
   1663 
   1664 Return<void> RadioImpl::setPreferredVoicePrivacy(int32_t serial, bool enable) {
   1665 #if VDBG
   1666     RLOGD("setPreferredVoicePrivacy: serial %d", serial);
   1667 #endif
   1668     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE,
   1669             1, BOOL_TO_INT(enable));
   1670     return Void();
   1671 }
   1672 
   1673 Return<void> RadioImpl::getPreferredVoicePrivacy(int32_t serial) {
   1674 #if VDBG
   1675     RLOGD("getPreferredVoicePrivacy: serial %d", serial);
   1676 #endif
   1677     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE);
   1678     return Void();
   1679 }
   1680 
   1681 Return<void> RadioImpl::sendCDMAFeatureCode(int32_t serial, const hidl_string& featureCode) {
   1682 #if VDBG
   1683     RLOGD("sendCDMAFeatureCode: serial %d", serial);
   1684 #endif
   1685     dispatchString(serial, mSlotId, RIL_REQUEST_CDMA_FLASH,
   1686             featureCode.c_str());
   1687     return Void();
   1688 }
   1689 
   1690 Return<void> RadioImpl::sendBurstDtmf(int32_t serial, const hidl_string& dtmf, int32_t on,
   1691                                       int32_t off) {
   1692 #if VDBG
   1693     RLOGD("sendBurstDtmf: serial %d", serial);
   1694 #endif
   1695     dispatchStrings(serial, mSlotId, RIL_REQUEST_CDMA_BURST_DTMF, false,
   1696             3, dtmf.c_str(), (std::to_string(on)).c_str(),
   1697             (std::to_string(off)).c_str());
   1698     return Void();
   1699 }
   1700 
   1701 void constructCdmaSms(RIL_CDMA_SMS_Message &rcsm, const CdmaSmsMessage& sms) {
   1702     rcsm.uTeleserviceID = sms.teleserviceId;
   1703     rcsm.bIsServicePresent = BOOL_TO_INT(sms.isServicePresent);
   1704     rcsm.uServicecategory = sms.serviceCategory;
   1705     rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) sms.address.digitMode;
   1706     rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) sms.address.numberMode;
   1707     rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) sms.address.numberType;
   1708     rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) sms.address.numberPlan;
   1709 
   1710     rcsm.sAddress.number_of_digits = sms.address.digits.size();
   1711     int digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
   1712     for (int i = 0; i < digitLimit; i++) {
   1713         rcsm.sAddress.digits[i] = sms.address.digits[i];
   1714     }
   1715 
   1716     rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) sms.subAddress.subaddressType;
   1717     rcsm.sSubAddress.odd = BOOL_TO_INT(sms.subAddress.odd);
   1718 
   1719     rcsm.sSubAddress.number_of_digits = sms.subAddress.digits.size();
   1720     digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
   1721     for (int i = 0; i < digitLimit; i++) {
   1722         rcsm.sSubAddress.digits[i] = sms.subAddress.digits[i];
   1723     }
   1724 
   1725     rcsm.uBearerDataLen = sms.bearerData.size();
   1726     digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
   1727     for (int i = 0; i < digitLimit; i++) {
   1728         rcsm.aBearerData[i] = sms.bearerData[i];
   1729     }
   1730 }
   1731 
   1732 Return<void> RadioImpl::sendCdmaSms(int32_t serial, const CdmaSmsMessage& sms) {
   1733 #if VDBG
   1734     RLOGD("sendCdmaSms: serial %d", serial);
   1735 #endif
   1736     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SEND_SMS);
   1737     if (pRI == NULL) {
   1738         return Void();
   1739     }
   1740 
   1741     RIL_CDMA_SMS_Message rcsm = {};
   1742     constructCdmaSms(rcsm, sms);
   1743 
   1744     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
   1745     return Void();
   1746 }
   1747 
   1748 Return<void> RadioImpl::acknowledgeLastIncomingCdmaSms(int32_t serial, const CdmaSmsAck& smsAck) {
   1749 #if VDBG
   1750     RLOGD("acknowledgeLastIncomingCdmaSms: serial %d", serial);
   1751 #endif
   1752     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE);
   1753     if (pRI == NULL) {
   1754         return Void();
   1755     }
   1756 
   1757     RIL_CDMA_SMS_Ack rcsa = {};
   1758 
   1759     rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) smsAck.errorClass;
   1760     rcsa.uSMSCauseCode = smsAck.smsCauseCode;
   1761 
   1762     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa), pRI, mSlotId);
   1763     return Void();
   1764 }
   1765 
   1766 Return<void> RadioImpl::getGsmBroadcastConfig(int32_t serial) {
   1767 #if VDBG
   1768     RLOGD("getGsmBroadcastConfig: serial %d", serial);
   1769 #endif
   1770     dispatchVoid(serial, mSlotId, RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG);
   1771     return Void();
   1772 }
   1773 
   1774 Return<void> RadioImpl::setGsmBroadcastConfig(int32_t serial,
   1775                                               const hidl_vec<GsmBroadcastSmsConfigInfo>&
   1776                                               configInfo) {
   1777 #if VDBG
   1778     RLOGD("setGsmBroadcastConfig: serial %d", serial);
   1779 #endif
   1780     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   1781             RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG);
   1782     if (pRI == NULL) {
   1783         return Void();
   1784     }
   1785 
   1786     int num = configInfo.size();
   1787     RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
   1788     RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
   1789 
   1790     for (int i = 0 ; i < num ; i++ ) {
   1791         gsmBciPtrs[i] = &gsmBci[i];
   1792         gsmBci[i].fromServiceId = configInfo[i].fromServiceId;
   1793         gsmBci[i].toServiceId = configInfo[i].toServiceId;
   1794         gsmBci[i].fromCodeScheme = configInfo[i].fromCodeScheme;
   1795         gsmBci[i].toCodeScheme = configInfo[i].toCodeScheme;
   1796         gsmBci[i].selected = BOOL_TO_INT(configInfo[i].selected);
   1797     }
   1798 
   1799     CALL_ONREQUEST(pRI->pCI->requestNumber, gsmBciPtrs,
   1800             num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *), pRI, mSlotId);
   1801     return Void();
   1802 }
   1803 
   1804 Return<void> RadioImpl::setGsmBroadcastActivation(int32_t serial, bool activate) {
   1805 #if VDBG
   1806     RLOGD("setGsmBroadcastActivation: serial %d", serial);
   1807 #endif
   1808     dispatchInts(serial, mSlotId, RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION,
   1809             1, BOOL_TO_INT(!activate));
   1810     return Void();
   1811 }
   1812 
   1813 Return<void> RadioImpl::getCdmaBroadcastConfig(int32_t serial) {
   1814 #if VDBG
   1815     RLOGD("getCdmaBroadcastConfig: serial %d", serial);
   1816 #endif
   1817     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG);
   1818     return Void();
   1819 }
   1820 
   1821 Return<void> RadioImpl::setCdmaBroadcastConfig(int32_t serial,
   1822                                                const hidl_vec<CdmaBroadcastSmsConfigInfo>&
   1823                                                configInfo) {
   1824 #if VDBG
   1825     RLOGD("setCdmaBroadcastConfig: serial %d", serial);
   1826 #endif
   1827     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   1828             RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG);
   1829     if (pRI == NULL) {
   1830         return Void();
   1831     }
   1832 
   1833     int num = configInfo.size();
   1834     RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
   1835     RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
   1836 
   1837     for (int i = 0 ; i < num ; i++ ) {
   1838         cdmaBciPtrs[i] = &cdmaBci[i];
   1839         cdmaBci[i].service_category = configInfo[i].serviceCategory;
   1840         cdmaBci[i].language = configInfo[i].language;
   1841         cdmaBci[i].selected = BOOL_TO_INT(configInfo[i].selected);
   1842     }
   1843 
   1844     CALL_ONREQUEST(pRI->pCI->requestNumber, cdmaBciPtrs,
   1845             num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *), pRI, mSlotId);
   1846     return Void();
   1847 }
   1848 
   1849 Return<void> RadioImpl::setCdmaBroadcastActivation(int32_t serial, bool activate) {
   1850 #if VDBG
   1851     RLOGD("setCdmaBroadcastActivation: serial %d", serial);
   1852 #endif
   1853     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION,
   1854             1, BOOL_TO_INT(!activate));
   1855     return Void();
   1856 }
   1857 
   1858 Return<void> RadioImpl::getCDMASubscription(int32_t serial) {
   1859 #if VDBG
   1860     RLOGD("getCDMASubscription: serial %d", serial);
   1861 #endif
   1862     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_SUBSCRIPTION);
   1863     return Void();
   1864 }
   1865 
   1866 Return<void> RadioImpl::writeSmsToRuim(int32_t serial, const CdmaSmsWriteArgs& cdmaSms) {
   1867 #if VDBG
   1868     RLOGD("writeSmsToRuim: serial %d", serial);
   1869 #endif
   1870     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   1871             RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM);
   1872     if (pRI == NULL) {
   1873         return Void();
   1874     }
   1875 
   1876     RIL_CDMA_SMS_WriteArgs rcsw = {};
   1877     rcsw.status = (int) cdmaSms.status;
   1878     constructCdmaSms(rcsw.message, cdmaSms.message);
   1879 
   1880     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw), pRI, mSlotId);
   1881     return Void();
   1882 }
   1883 
   1884 Return<void> RadioImpl::deleteSmsOnRuim(int32_t serial, int32_t index) {
   1885 #if VDBG
   1886     RLOGD("deleteSmsOnRuim: serial %d", serial);
   1887 #endif
   1888     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, 1, index);
   1889     return Void();
   1890 }
   1891 
   1892 Return<void> RadioImpl::getDeviceIdentity(int32_t serial) {
   1893 #if VDBG
   1894     RLOGD("getDeviceIdentity: serial %d", serial);
   1895 #endif
   1896     dispatchVoid(serial, mSlotId, RIL_REQUEST_DEVICE_IDENTITY);
   1897     return Void();
   1898 }
   1899 
   1900 Return<void> RadioImpl::exitEmergencyCallbackMode(int32_t serial) {
   1901 #if VDBG
   1902     RLOGD("exitEmergencyCallbackMode: serial %d", serial);
   1903 #endif
   1904     dispatchVoid(serial, mSlotId, RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE);
   1905     return Void();
   1906 }
   1907 
   1908 Return<void> RadioImpl::getSmscAddress(int32_t serial) {
   1909 #if VDBG
   1910     RLOGD("getSmscAddress: serial %d", serial);
   1911 #endif
   1912     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SMSC_ADDRESS);
   1913     return Void();
   1914 }
   1915 
   1916 Return<void> RadioImpl::setSmscAddress(int32_t serial, const hidl_string& smsc) {
   1917 #if VDBG
   1918     RLOGD("setSmscAddress: serial %d", serial);
   1919 #endif
   1920     dispatchString(serial, mSlotId, RIL_REQUEST_SET_SMSC_ADDRESS,
   1921             smsc.c_str());
   1922     return Void();
   1923 }
   1924 
   1925 Return<void> RadioImpl::reportSmsMemoryStatus(int32_t serial, bool available) {
   1926 #if VDBG
   1927     RLOGD("reportSmsMemoryStatus: serial %d", serial);
   1928 #endif
   1929     dispatchInts(serial, mSlotId, RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, 1,
   1930             BOOL_TO_INT(available));
   1931     return Void();
   1932 }
   1933 
   1934 Return<void> RadioImpl::reportStkServiceIsRunning(int32_t serial) {
   1935 #if VDBG
   1936     RLOGD("reportStkServiceIsRunning: serial %d", serial);
   1937 #endif
   1938     dispatchVoid(serial, mSlotId, RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING);
   1939     return Void();
   1940 }
   1941 
   1942 Return<void> RadioImpl::getCdmaSubscriptionSource(int32_t serial) {
   1943 #if VDBG
   1944     RLOGD("getCdmaSubscriptionSource: serial %d", serial);
   1945 #endif
   1946     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE);
   1947     return Void();
   1948 }
   1949 
   1950 Return<void> RadioImpl::requestIsimAuthentication(int32_t serial, const hidl_string& challenge) {
   1951 #if VDBG
   1952     RLOGD("requestIsimAuthentication: serial %d", serial);
   1953 #endif
   1954     dispatchString(serial, mSlotId, RIL_REQUEST_ISIM_AUTHENTICATION,
   1955             challenge.c_str());
   1956     return Void();
   1957 }
   1958 
   1959 Return<void> RadioImpl::acknowledgeIncomingGsmSmsWithPdu(int32_t serial, bool success,
   1960                                                          const hidl_string& ackPdu) {
   1961 #if VDBG
   1962     RLOGD("acknowledgeIncomingGsmSmsWithPdu: serial %d", serial);
   1963 #endif
   1964     dispatchStrings(serial, mSlotId, RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, false,
   1965             2, success ? "1" : "0", ackPdu.c_str());
   1966     return Void();
   1967 }
   1968 
   1969 Return<void> RadioImpl::sendEnvelopeWithStatus(int32_t serial, const hidl_string& contents) {
   1970 #if VDBG
   1971     RLOGD("sendEnvelopeWithStatus: serial %d", serial);
   1972 #endif
   1973     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS,
   1974             contents.c_str());
   1975     return Void();
   1976 }
   1977 
   1978 Return<void> RadioImpl::getVoiceRadioTechnology(int32_t serial) {
   1979 #if VDBG
   1980     RLOGD("getVoiceRadioTechnology: serial %d", serial);
   1981 #endif
   1982     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_RADIO_TECH);
   1983     return Void();
   1984 }
   1985 
   1986 Return<void> RadioImpl::getCellInfoList(int32_t serial) {
   1987 #if VDBG
   1988     RLOGD("getCellInfoList: serial %d", serial);
   1989 #endif
   1990     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CELL_INFO_LIST);
   1991     return Void();
   1992 }
   1993 
   1994 Return<void> RadioImpl::setCellInfoListRate(int32_t serial, int32_t rate) {
   1995 #if VDBG
   1996     RLOGD("setCellInfoListRate: serial %d", serial);
   1997 #endif
   1998     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, 1, rate);
   1999     return Void();
   2000 }
   2001 
   2002 Return<void> RadioImpl::setInitialAttachApn(int32_t serial, const DataProfileInfo& dataProfileInfo,
   2003                                             bool modemCognitive, bool isRoaming) {
   2004 #if VDBG
   2005     RLOGD("setInitialAttachApn: serial %d", serial);
   2006 #endif
   2007     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   2008             RIL_REQUEST_SET_INITIAL_ATTACH_APN);
   2009     if (pRI == NULL) {
   2010         return Void();
   2011     }
   2012 
   2013     if (s_vendorFunctions->version <= 14) {
   2014         RIL_InitialAttachApn iaa = {};
   2015 
   2016         if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) {
   2017             return Void();
   2018         }
   2019 
   2020         const hidl_string &protocol =
   2021                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
   2022 
   2023         if (!copyHidlStringToRil(&iaa.protocol, protocol, pRI)) {
   2024             memsetAndFreeStrings(1, iaa.apn);
   2025             return Void();
   2026         }
   2027         iaa.authtype = (int) dataProfileInfo.authType;
   2028         if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) {
   2029             memsetAndFreeStrings(2, iaa.apn, iaa.protocol);
   2030             return Void();
   2031         }
   2032         if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) {
   2033             memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.username);
   2034             return Void();
   2035         }
   2036 
   2037         CALL_ONREQUEST(RIL_REQUEST_SET_INITIAL_ATTACH_APN, &iaa, sizeof(iaa), pRI, mSlotId);
   2038 
   2039         memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.username, iaa.password);
   2040     } else {
   2041         RIL_InitialAttachApn_v15 iaa = {};
   2042 
   2043         if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) {
   2044             return Void();
   2045         }
   2046 
   2047         if (!copyHidlStringToRil(&iaa.protocol, dataProfileInfo.protocol, pRI)) {
   2048             memsetAndFreeStrings(1, iaa.apn);
   2049             return Void();
   2050         }
   2051         if (!copyHidlStringToRil(&iaa.roamingProtocol, dataProfileInfo.roamingProtocol, pRI)) {
   2052             memsetAndFreeStrings(2, iaa.apn, iaa.protocol);
   2053             return Void();
   2054         }
   2055         iaa.authtype = (int) dataProfileInfo.authType;
   2056         if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) {
   2057             memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.roamingProtocol);
   2058             return Void();
   2059         }
   2060         if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) {
   2061             memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username);
   2062             return Void();
   2063         }
   2064         iaa.supportedTypesBitmask = dataProfileInfo.supportedApnTypesBitmap;
   2065         iaa.bearerBitmask = dataProfileInfo.bearerBitmap;
   2066         iaa.modemCognitive = BOOL_TO_INT(modemCognitive);
   2067         iaa.mtu = dataProfileInfo.mtu;
   2068 
   2069         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, iaa.mvnoType)) {
   2070             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   2071             memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
   2072                     iaa.password);
   2073             return Void();
   2074         }
   2075 
   2076         if (!copyHidlStringToRil(&iaa.mvnoMatchData, dataProfileInfo.mvnoMatchData, pRI)) {
   2077             memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
   2078                     iaa.password);
   2079             return Void();
   2080         }
   2081 
   2082         CALL_ONREQUEST(RIL_REQUEST_SET_INITIAL_ATTACH_APN, &iaa, sizeof(iaa), pRI, mSlotId);
   2083 
   2084         memsetAndFreeStrings(6, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
   2085                 iaa.password, iaa.mvnoMatchData);
   2086     }
   2087 
   2088     return Void();
   2089 }
   2090 
   2091 Return<void> RadioImpl::getImsRegistrationState(int32_t serial) {
   2092 #if VDBG
   2093     RLOGD("getImsRegistrationState: serial %d", serial);
   2094 #endif
   2095     dispatchVoid(serial, mSlotId, RIL_REQUEST_IMS_REGISTRATION_STATE);
   2096     return Void();
   2097 }
   2098 
   2099 bool dispatchImsGsmSms(const ImsSmsMessage& message, RequestInfo *pRI) {
   2100     RIL_IMS_SMS_Message rism = {};
   2101     char **pStrings;
   2102     int countStrings = 2;
   2103     int dataLen = sizeof(char *) * countStrings;
   2104 
   2105     rism.tech = RADIO_TECH_3GPP;
   2106     rism.retry = BOOL_TO_INT(message.retry);
   2107     rism.messageRef = message.messageRef;
   2108 
   2109     if (message.gsmMessage.size() != 1) {
   2110         RLOGE("dispatchImsGsmSms: Invalid len %s", requestToString(pRI->pCI->requestNumber));
   2111         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   2112         return false;
   2113     }
   2114 
   2115     pStrings = (char **)calloc(countStrings, sizeof(char *));
   2116     if (pStrings == NULL) {
   2117         RLOGE("dispatchImsGsmSms: Memory allocation failed for request %s",
   2118                 requestToString(pRI->pCI->requestNumber));
   2119         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
   2120         return false;
   2121     }
   2122 
   2123     if (!copyHidlStringToRil(&pStrings[0], message.gsmMessage[0].smscPdu, pRI)) {
   2124 #ifdef MEMSET_FREED
   2125         memset(pStrings, 0, dataLen);
   2126 #endif
   2127         free(pStrings);
   2128         return false;
   2129     }
   2130 
   2131     if (!copyHidlStringToRil(&pStrings[1], message.gsmMessage[0].pdu, pRI)) {
   2132         memsetAndFreeStrings(1, pStrings[0]);
   2133 #ifdef MEMSET_FREED
   2134         memset(pStrings, 0, dataLen);
   2135 #endif
   2136         free(pStrings);
   2137         return false;
   2138     }
   2139 
   2140     rism.message.gsmMessage = pStrings;
   2141     CALL_ONREQUEST(pRI->pCI->requestNumber, &rism, sizeof(RIL_RadioTechnologyFamily) +
   2142             sizeof(uint8_t) + sizeof(int32_t) + dataLen, pRI, pRI->socket_id);
   2143 
   2144     for (int i = 0 ; i < countStrings ; i++) {
   2145         memsetAndFreeStrings(1, pStrings[i]);
   2146     }
   2147 
   2148 #ifdef MEMSET_FREED
   2149     memset(pStrings, 0, dataLen);
   2150 #endif
   2151     free(pStrings);
   2152 
   2153     return true;
   2154 }
   2155 
   2156 struct ImsCdmaSms {
   2157     RIL_IMS_SMS_Message imsSms;
   2158     RIL_CDMA_SMS_Message cdmaSms;
   2159 };
   2160 
   2161 bool dispatchImsCdmaSms(const ImsSmsMessage& message, RequestInfo *pRI) {
   2162     ImsCdmaSms temp = {};
   2163 
   2164     if (message.cdmaMessage.size() != 1) {
   2165         RLOGE("dispatchImsCdmaSms: Invalid len %s", requestToString(pRI->pCI->requestNumber));
   2166         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   2167         return false;
   2168     }
   2169 
   2170     temp.imsSms.tech = RADIO_TECH_3GPP2;
   2171     temp.imsSms.retry = BOOL_TO_INT(message.retry);
   2172     temp.imsSms.messageRef = message.messageRef;
   2173     temp.imsSms.message.cdmaMessage = &temp.cdmaSms;
   2174 
   2175     constructCdmaSms(temp.cdmaSms, message.cdmaMessage[0]);
   2176 
   2177     // Vendor code expects payload length to include actual msg payload
   2178     // (sizeof(RIL_CDMA_SMS_Message)) instead of (RIL_CDMA_SMS_Message *) + size of other fields in
   2179     // RIL_IMS_SMS_Message
   2180     int payloadLen = sizeof(RIL_RadioTechnologyFamily) + sizeof(uint8_t) + sizeof(int32_t)
   2181             + sizeof(RIL_CDMA_SMS_Message);
   2182 
   2183     CALL_ONREQUEST(pRI->pCI->requestNumber, &temp.imsSms, payloadLen, pRI, pRI->socket_id);
   2184 
   2185     return true;
   2186 }
   2187 
   2188 Return<void> RadioImpl::sendImsSms(int32_t serial, const ImsSmsMessage& message) {
   2189 #if VDBG
   2190     RLOGD("sendImsSms: serial %d", serial);
   2191 #endif
   2192     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_IMS_SEND_SMS);
   2193     if (pRI == NULL) {
   2194         return Void();
   2195     }
   2196 
   2197     RIL_RadioTechnologyFamily format = (RIL_RadioTechnologyFamily) message.tech;
   2198 
   2199     if (RADIO_TECH_3GPP == format) {
   2200         dispatchImsGsmSms(message, pRI);
   2201     } else if (RADIO_TECH_3GPP2 == format) {
   2202         dispatchImsCdmaSms(message, pRI);
   2203     } else {
   2204         RLOGE("sendImsSms: Invalid radio tech %s",
   2205                 requestToString(pRI->pCI->requestNumber));
   2206         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   2207     }
   2208     return Void();
   2209 }
   2210 
   2211 Return<void> RadioImpl::iccTransmitApduBasicChannel(int32_t serial, const SimApdu& message) {
   2212 #if VDBG
   2213     RLOGD("iccTransmitApduBasicChannel: serial %d", serial);
   2214 #endif
   2215     dispatchIccApdu(serial, mSlotId, RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, message);
   2216     return Void();
   2217 }
   2218 
   2219 Return<void> RadioImpl::iccOpenLogicalChannel(int32_t serial, const hidl_string& aid, int32_t p2) {
   2220 #if VDBG
   2221     RLOGD("iccOpenLogicalChannel: serial %d", serial);
   2222 #endif
   2223     if (s_vendorFunctions->version < 15) {
   2224         dispatchString(serial, mSlotId, RIL_REQUEST_SIM_OPEN_CHANNEL, aid.c_str());
   2225     } else {
   2226         RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_OPEN_CHANNEL);
   2227         if (pRI == NULL) {
   2228             return Void();
   2229         }
   2230 
   2231         RIL_OpenChannelParams params = {};
   2232 
   2233         params.p2 = p2;
   2234 
   2235         if (!copyHidlStringToRil(&params.aidPtr, aid, pRI)) {
   2236             return Void();
   2237         }
   2238 
   2239         CALL_ONREQUEST(pRI->pCI->requestNumber, &params, sizeof(params), pRI, mSlotId);
   2240 
   2241         memsetAndFreeStrings(1, params.aidPtr);
   2242     }
   2243     return Void();
   2244 }
   2245 
   2246 Return<void> RadioImpl::iccCloseLogicalChannel(int32_t serial, int32_t channelId) {
   2247 #if VDBG
   2248     RLOGD("iccCloseLogicalChannel: serial %d", serial);
   2249 #endif
   2250     dispatchInts(serial, mSlotId, RIL_REQUEST_SIM_CLOSE_CHANNEL, 1, channelId);
   2251     return Void();
   2252 }
   2253 
   2254 Return<void> RadioImpl::iccTransmitApduLogicalChannel(int32_t serial, const SimApdu& message) {
   2255 #if VDBG
   2256     RLOGD("iccTransmitApduLogicalChannel: serial %d", serial);
   2257 #endif
   2258     dispatchIccApdu(serial, mSlotId, RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, message);
   2259     return Void();
   2260 }
   2261 
   2262 Return<void> RadioImpl::nvReadItem(int32_t serial, NvItem itemId) {
   2263 #if VDBG
   2264     RLOGD("nvReadItem: serial %d", serial);
   2265 #endif
   2266     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_NV_READ_ITEM);
   2267     if (pRI == NULL) {
   2268         return Void();
   2269     }
   2270 
   2271     RIL_NV_ReadItem nvri = {};
   2272     nvri.itemID = (RIL_NV_Item) itemId;
   2273 
   2274     CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, mSlotId);
   2275     return Void();
   2276 }
   2277 
   2278 Return<void> RadioImpl::nvWriteItem(int32_t serial, const NvWriteItem& item) {
   2279 #if VDBG
   2280     RLOGD("nvWriteItem: serial %d", serial);
   2281 #endif
   2282     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_NV_WRITE_ITEM);
   2283     if (pRI == NULL) {
   2284         return Void();
   2285     }
   2286 
   2287     RIL_NV_WriteItem nvwi = {};
   2288 
   2289     nvwi.itemID = (RIL_NV_Item) item.itemId;
   2290 
   2291     if (!copyHidlStringToRil(&nvwi.value, item.value, pRI)) {
   2292         return Void();
   2293     }
   2294 
   2295     CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, mSlotId);
   2296 
   2297     memsetAndFreeStrings(1, nvwi.value);
   2298     return Void();
   2299 }
   2300 
   2301 Return<void> RadioImpl::nvWriteCdmaPrl(int32_t serial, const hidl_vec<uint8_t>& prl) {
   2302 #if VDBG
   2303     RLOGD("nvWriteCdmaPrl: serial %d", serial);
   2304 #endif
   2305     dispatchRaw(serial, mSlotId, RIL_REQUEST_NV_WRITE_CDMA_PRL, prl);
   2306     return Void();
   2307 }
   2308 
   2309 Return<void> RadioImpl::nvResetConfig(int32_t serial, ResetNvType resetType) {
   2310     int rilResetType = -1;
   2311 #if VDBG
   2312     RLOGD("nvResetConfig: serial %d", serial);
   2313 #endif
   2314     /* Convert ResetNvType to RIL.h values
   2315      * RIL_REQUEST_NV_RESET_CONFIG
   2316      * 1 - reload all NV items
   2317      * 2 - erase NV reset (SCRTN)
   2318      * 3 - factory reset (RTN)
   2319      */
   2320     switch(resetType) {
   2321       case ResetNvType::RELOAD:
   2322         rilResetType = 1;
   2323         break;
   2324       case ResetNvType::ERASE:
   2325         rilResetType = 2;
   2326         break;
   2327       case ResetNvType::FACTORY_RESET:
   2328         rilResetType = 3;
   2329         break;
   2330     }
   2331     dispatchInts(serial, mSlotId, RIL_REQUEST_NV_RESET_CONFIG, 1, rilResetType);
   2332     return Void();
   2333 }
   2334 
   2335 Return<void> RadioImpl::setUiccSubscription(int32_t serial, const SelectUiccSub& uiccSub) {
   2336 #if VDBG
   2337     RLOGD("setUiccSubscription: serial %d", serial);
   2338 #endif
   2339     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   2340             RIL_REQUEST_SET_UICC_SUBSCRIPTION);
   2341     if (pRI == NULL) {
   2342         return Void();
   2343     }
   2344 
   2345     RIL_SelectUiccSub rilUiccSub = {};
   2346 
   2347     rilUiccSub.slot = uiccSub.slot;
   2348     rilUiccSub.app_index = uiccSub.appIndex;
   2349     rilUiccSub.sub_type = (RIL_SubscriptionType) uiccSub.subType;
   2350     rilUiccSub.act_status = (RIL_UiccSubActStatus) uiccSub.actStatus;
   2351 
   2352     CALL_ONREQUEST(pRI->pCI->requestNumber, &rilUiccSub, sizeof(rilUiccSub), pRI, mSlotId);
   2353     return Void();
   2354 }
   2355 
   2356 Return<void> RadioImpl::setDataAllowed(int32_t serial, bool allow) {
   2357 #if VDBG
   2358     RLOGD("setDataAllowed: serial %d", serial);
   2359 #endif
   2360     dispatchInts(serial, mSlotId, RIL_REQUEST_ALLOW_DATA, 1, BOOL_TO_INT(allow));
   2361     return Void();
   2362 }
   2363 
   2364 Return<void> RadioImpl::getHardwareConfig(int32_t serial) {
   2365 #if VDBG
   2366     RLOGD("getHardwareConfig: serial %d", serial);
   2367 #endif
   2368     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_HARDWARE_CONFIG);
   2369     return Void();
   2370 }
   2371 
   2372 Return<void> RadioImpl::requestIccSimAuthentication(int32_t serial, int32_t authContext,
   2373         const hidl_string& authData, const hidl_string& aid) {
   2374 #if VDBG
   2375     RLOGD("requestIccSimAuthentication: serial %d", serial);
   2376 #endif
   2377     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_AUTHENTICATION);
   2378     if (pRI == NULL) {
   2379         return Void();
   2380     }
   2381 
   2382     RIL_SimAuthentication pf = {};
   2383 
   2384     pf.authContext = authContext;
   2385 
   2386     if (!copyHidlStringToRil(&pf.authData, authData, pRI)) {
   2387         return Void();
   2388     }
   2389 
   2390     if (!copyHidlStringToRil(&pf.aid, aid, pRI)) {
   2391         memsetAndFreeStrings(1, pf.authData);
   2392         return Void();
   2393     }
   2394 
   2395     CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, mSlotId);
   2396 
   2397     memsetAndFreeStrings(2, pf.authData, pf.aid);
   2398     return Void();
   2399 }
   2400 
   2401 /**
   2402  * @param numProfiles number of data profile
   2403  * @param dataProfiles the pointer to the actual data profiles. The acceptable type is
   2404           RIL_DataProfileInfo or RIL_DataProfileInfo_v15.
   2405  * @param dataProfilePtrs the pointer to the pointers that point to each data profile structure
   2406  * @param numfields number of string-type member in the data profile structure
   2407  * @param ... the variadic parameters are pointers to each string-type member
   2408  **/
   2409 template <typename T>
   2410 void freeSetDataProfileData(int numProfiles, T *dataProfiles, T **dataProfilePtrs,
   2411                             int numfields, ...) {
   2412     va_list args;
   2413     va_start(args, numfields);
   2414 
   2415     // Iterate through each string-type field that need to be free.
   2416     for (int i = 0; i < numfields; i++) {
   2417         // Iterate through each data profile and free that specific string-type field.
   2418         // The type 'char *T::*' is a type of pointer to a 'char *' member inside T structure.
   2419         char *T::*ptr = va_arg(args, char *T::*);
   2420         for (int j = 0; j < numProfiles; j++) {
   2421             memsetAndFreeStrings(1, dataProfiles[j].*ptr);
   2422         }
   2423     }
   2424 
   2425     va_end(args);
   2426 
   2427 #ifdef MEMSET_FREED
   2428     memset(dataProfiles, 0, numProfiles * sizeof(T));
   2429     memset(dataProfilePtrs, 0, numProfiles * sizeof(T *));
   2430 #endif
   2431     free(dataProfiles);
   2432     free(dataProfilePtrs);
   2433 }
   2434 
   2435 Return<void> RadioImpl::setDataProfile(int32_t serial, const hidl_vec<DataProfileInfo>& profiles,
   2436                                        bool isRoaming) {
   2437 #if VDBG
   2438     RLOGD("setDataProfile: serial %d", serial);
   2439 #endif
   2440     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SET_DATA_PROFILE);
   2441     if (pRI == NULL) {
   2442         return Void();
   2443     }
   2444 
   2445     size_t num = profiles.size();
   2446     bool success = false;
   2447 
   2448     if (s_vendorFunctions->version <= 14) {
   2449 
   2450         RIL_DataProfileInfo *dataProfiles =
   2451             (RIL_DataProfileInfo *) calloc(num, sizeof(RIL_DataProfileInfo));
   2452 
   2453         if (dataProfiles == NULL) {
   2454             RLOGE("Memory allocation failed for request %s",
   2455                     requestToString(pRI->pCI->requestNumber));
   2456             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
   2457             return Void();
   2458         }
   2459 
   2460         RIL_DataProfileInfo **dataProfilePtrs =
   2461             (RIL_DataProfileInfo **) calloc(num, sizeof(RIL_DataProfileInfo *));
   2462         if (dataProfilePtrs == NULL) {
   2463             RLOGE("Memory allocation failed for request %s",
   2464                     requestToString(pRI->pCI->requestNumber));
   2465             free(dataProfiles);
   2466             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
   2467             return Void();
   2468         }
   2469 
   2470         for (size_t i = 0; i < num; i++) {
   2471             dataProfilePtrs[i] = &dataProfiles[i];
   2472 
   2473             success = copyHidlStringToRil(&dataProfiles[i].apn, profiles[i].apn, pRI, true);
   2474 
   2475             const hidl_string &protocol =
   2476                     (isRoaming ? profiles[i].roamingProtocol : profiles[i].protocol);
   2477 
   2478             if (success && !copyHidlStringToRil(&dataProfiles[i].protocol, protocol, pRI, true)) {
   2479                 success = false;
   2480             }
   2481 
   2482             if (success && !copyHidlStringToRil(&dataProfiles[i].user, profiles[i].user, pRI,
   2483                     true)) {
   2484                 success = false;
   2485             }
   2486             if (success && !copyHidlStringToRil(&dataProfiles[i].password, profiles[i].password,
   2487                     pRI, true)) {
   2488                 success = false;
   2489             }
   2490 
   2491             if (!success) {
   2492                 freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 4,
   2493                     &RIL_DataProfileInfo::apn, &RIL_DataProfileInfo::protocol,
   2494                     &RIL_DataProfileInfo::user, &RIL_DataProfileInfo::password);
   2495                 return Void();
   2496             }
   2497 
   2498             dataProfiles[i].profileId = (RIL_DataProfile) profiles[i].profileId;
   2499             dataProfiles[i].authType = (int) profiles[i].authType;
   2500             dataProfiles[i].type = (int) profiles[i].type;
   2501             dataProfiles[i].maxConnsTime = profiles[i].maxConnsTime;
   2502             dataProfiles[i].maxConns = profiles[i].maxConns;
   2503             dataProfiles[i].waitTime = profiles[i].waitTime;
   2504             dataProfiles[i].enabled = BOOL_TO_INT(profiles[i].enabled);
   2505         }
   2506 
   2507         CALL_ONREQUEST(RIL_REQUEST_SET_DATA_PROFILE, dataProfilePtrs,
   2508                 num * sizeof(RIL_DataProfileInfo *), pRI, mSlotId);
   2509 
   2510         freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 4,
   2511                 &RIL_DataProfileInfo::apn, &RIL_DataProfileInfo::protocol,
   2512                 &RIL_DataProfileInfo::user, &RIL_DataProfileInfo::password);
   2513     } else {
   2514         RIL_DataProfileInfo_v15 *dataProfiles =
   2515             (RIL_DataProfileInfo_v15 *) calloc(num, sizeof(RIL_DataProfileInfo_v15));
   2516 
   2517         if (dataProfiles == NULL) {
   2518             RLOGE("Memory allocation failed for request %s",
   2519                     requestToString(pRI->pCI->requestNumber));
   2520             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
   2521             return Void();
   2522         }
   2523 
   2524         RIL_DataProfileInfo_v15 **dataProfilePtrs =
   2525             (RIL_DataProfileInfo_v15 **) calloc(num, sizeof(RIL_DataProfileInfo_v15 *));
   2526         if (dataProfilePtrs == NULL) {
   2527             RLOGE("Memory allocation failed for request %s",
   2528                     requestToString(pRI->pCI->requestNumber));
   2529             free(dataProfiles);
   2530             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
   2531             return Void();
   2532         }
   2533 
   2534         for (size_t i = 0; i < num; i++) {
   2535             dataProfilePtrs[i] = &dataProfiles[i];
   2536 
   2537             success = copyHidlStringToRil(&dataProfiles[i].apn, profiles[i].apn, pRI, true);
   2538             if (success && !copyHidlStringToRil(&dataProfiles[i].protocol, profiles[i].protocol,
   2539                     pRI)) {
   2540                 success = false;
   2541             }
   2542             if (success && !copyHidlStringToRil(&dataProfiles[i].roamingProtocol,
   2543                     profiles[i].roamingProtocol, pRI, true)) {
   2544                 success = false;
   2545             }
   2546             if (success && !copyHidlStringToRil(&dataProfiles[i].user, profiles[i].user, pRI,
   2547                     true)) {
   2548                 success = false;
   2549             }
   2550             if (success && !copyHidlStringToRil(&dataProfiles[i].password, profiles[i].password,
   2551                     pRI, true)) {
   2552                 success = false;
   2553             }
   2554             if (success && !copyHidlStringToRil(&dataProfiles[i].mvnoMatchData,
   2555                     profiles[i].mvnoMatchData, pRI, true)) {
   2556                 success = false;
   2557             }
   2558 
   2559             if (success && !convertMvnoTypeToString(profiles[i].mvnoType,
   2560                     dataProfiles[i].mvnoType)) {
   2561                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   2562                 success = false;
   2563             }
   2564 
   2565             if (!success) {
   2566                 freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 6,
   2567                     &RIL_DataProfileInfo_v15::apn, &RIL_DataProfileInfo_v15::protocol,
   2568                     &RIL_DataProfileInfo_v15::roamingProtocol, &RIL_DataProfileInfo_v15::user,
   2569                     &RIL_DataProfileInfo_v15::password, &RIL_DataProfileInfo_v15::mvnoMatchData);
   2570                 return Void();
   2571             }
   2572 
   2573             dataProfiles[i].profileId = (RIL_DataProfile) profiles[i].profileId;
   2574             dataProfiles[i].authType = (int) profiles[i].authType;
   2575             dataProfiles[i].type = (int) profiles[i].type;
   2576             dataProfiles[i].maxConnsTime = profiles[i].maxConnsTime;
   2577             dataProfiles[i].maxConns = profiles[i].maxConns;
   2578             dataProfiles[i].waitTime = profiles[i].waitTime;
   2579             dataProfiles[i].enabled = BOOL_TO_INT(profiles[i].enabled);
   2580             dataProfiles[i].supportedTypesBitmask = profiles[i].supportedApnTypesBitmap;
   2581             dataProfiles[i].bearerBitmask = profiles[i].bearerBitmap;
   2582             dataProfiles[i].mtu = profiles[i].mtu;
   2583         }
   2584 
   2585         CALL_ONREQUEST(RIL_REQUEST_SET_DATA_PROFILE, dataProfilePtrs,
   2586                 num * sizeof(RIL_DataProfileInfo_v15 *), pRI, mSlotId);
   2587 
   2588         freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 6,
   2589                 &RIL_DataProfileInfo_v15::apn, &RIL_DataProfileInfo_v15::protocol,
   2590                 &RIL_DataProfileInfo_v15::roamingProtocol, &RIL_DataProfileInfo_v15::user,
   2591                 &RIL_DataProfileInfo_v15::password, &RIL_DataProfileInfo_v15::mvnoMatchData);
   2592     }
   2593 
   2594     return Void();
   2595 }
   2596 
   2597 Return<void> RadioImpl::requestShutdown(int32_t serial) {
   2598 #if VDBG
   2599     RLOGD("requestShutdown: serial %d", serial);
   2600 #endif
   2601     dispatchVoid(serial, mSlotId, RIL_REQUEST_SHUTDOWN);
   2602     return Void();
   2603 }
   2604 
   2605 Return<void> RadioImpl::getRadioCapability(int32_t serial) {
   2606 #if VDBG
   2607     RLOGD("getRadioCapability: serial %d", serial);
   2608 #endif
   2609     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_RADIO_CAPABILITY);
   2610     return Void();
   2611 }
   2612 
   2613 Return<void> RadioImpl::setRadioCapability(int32_t serial, const RadioCapability& rc) {
   2614 #if VDBG
   2615     RLOGD("setRadioCapability: serial %d", serial);
   2616 #endif
   2617     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SET_RADIO_CAPABILITY);
   2618     if (pRI == NULL) {
   2619         return Void();
   2620     }
   2621 
   2622     RIL_RadioCapability rilRc = {};
   2623 
   2624     // TODO : set rilRc.version using HIDL version ?
   2625     rilRc.session = rc.session;
   2626     rilRc.phase = (int) rc.phase;
   2627     rilRc.rat = (int) rc.raf;
   2628     rilRc.status = (int) rc.status;
   2629     strncpy(rilRc.logicalModemUuid, rc.logicalModemUuid.c_str(), MAX_UUID_LENGTH);
   2630 
   2631     CALL_ONREQUEST(pRI->pCI->requestNumber, &rilRc, sizeof(rilRc), pRI, mSlotId);
   2632 
   2633     return Void();
   2634 }
   2635 
   2636 Return<void> RadioImpl::startLceService(int32_t serial, int32_t reportInterval, bool pullMode) {
   2637 #if VDBG
   2638     RLOGD("startLceService: serial %d", serial);
   2639 #endif
   2640     dispatchInts(serial, mSlotId, RIL_REQUEST_START_LCE, 2, reportInterval,
   2641             BOOL_TO_INT(pullMode));
   2642     return Void();
   2643 }
   2644 
   2645 Return<void> RadioImpl::stopLceService(int32_t serial) {
   2646 #if VDBG
   2647     RLOGD("stopLceService: serial %d", serial);
   2648 #endif
   2649     dispatchVoid(serial, mSlotId, RIL_REQUEST_STOP_LCE);
   2650     return Void();
   2651 }
   2652 
   2653 Return<void> RadioImpl::pullLceData(int32_t serial) {
   2654 #if VDBG
   2655     RLOGD("pullLceData: serial %d", serial);
   2656 #endif
   2657     dispatchVoid(serial, mSlotId, RIL_REQUEST_PULL_LCEDATA);
   2658     return Void();
   2659 }
   2660 
   2661 Return<void> RadioImpl::getModemActivityInfo(int32_t serial) {
   2662 #if VDBG
   2663     RLOGD("getModemActivityInfo: serial %d", serial);
   2664 #endif
   2665     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_ACTIVITY_INFO);
   2666     return Void();
   2667 }
   2668 
   2669 Return<void> RadioImpl::setAllowedCarriers(int32_t serial, bool allAllowed,
   2670                                            const CarrierRestrictions& carriers) {
   2671 #if VDBG
   2672     RLOGD("setAllowedCarriers: serial %d", serial);
   2673 #endif
   2674     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   2675             RIL_REQUEST_SET_CARRIER_RESTRICTIONS);
   2676     if (pRI == NULL) {
   2677         return Void();
   2678     }
   2679 
   2680     RIL_CarrierRestrictions cr = {};
   2681     RIL_Carrier *allowedCarriers = NULL;
   2682     RIL_Carrier *excludedCarriers = NULL;
   2683 
   2684     cr.len_allowed_carriers = carriers.allowedCarriers.size();
   2685     allowedCarriers = (RIL_Carrier *)calloc(cr.len_allowed_carriers, sizeof(RIL_Carrier));
   2686     if (allowedCarriers == NULL) {
   2687         RLOGE("setAllowedCarriers: Memory allocation failed for request %s",
   2688                 requestToString(pRI->pCI->requestNumber));
   2689         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
   2690         return Void();
   2691     }
   2692     cr.allowed_carriers = allowedCarriers;
   2693 
   2694     cr.len_excluded_carriers = carriers.excludedCarriers.size();
   2695     excludedCarriers = (RIL_Carrier *)calloc(cr.len_excluded_carriers, sizeof(RIL_Carrier));
   2696     if (excludedCarriers == NULL) {
   2697         RLOGE("setAllowedCarriers: Memory allocation failed for request %s",
   2698                 requestToString(pRI->pCI->requestNumber));
   2699         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
   2700 #ifdef MEMSET_FREED
   2701         memset(allowedCarriers, 0, cr.len_allowed_carriers * sizeof(RIL_Carrier));
   2702 #endif
   2703         free(allowedCarriers);
   2704         return Void();
   2705     }
   2706     cr.excluded_carriers = excludedCarriers;
   2707 
   2708     for (int i = 0; i < cr.len_allowed_carriers; i++) {
   2709         allowedCarriers[i].mcc = carriers.allowedCarriers[i].mcc.c_str();
   2710         allowedCarriers[i].mnc = carriers.allowedCarriers[i].mnc.c_str();
   2711         allowedCarriers[i].match_type = (RIL_CarrierMatchType) carriers.allowedCarriers[i].matchType;
   2712         allowedCarriers[i].match_data = carriers.allowedCarriers[i].matchData.c_str();
   2713     }
   2714 
   2715     for (int i = 0; i < cr.len_excluded_carriers; i++) {
   2716         excludedCarriers[i].mcc = carriers.excludedCarriers[i].mcc.c_str();
   2717         excludedCarriers[i].mnc = carriers.excludedCarriers[i].mnc.c_str();
   2718         excludedCarriers[i].match_type =
   2719                 (RIL_CarrierMatchType) carriers.excludedCarriers[i].matchType;
   2720         excludedCarriers[i].match_data = carriers.excludedCarriers[i].matchData.c_str();
   2721     }
   2722 
   2723     CALL_ONREQUEST(pRI->pCI->requestNumber, &cr, sizeof(RIL_CarrierRestrictions), pRI, mSlotId);
   2724 
   2725 #ifdef MEMSET_FREED
   2726     memset(allowedCarriers, 0, cr.len_allowed_carriers * sizeof(RIL_Carrier));
   2727     memset(excludedCarriers, 0, cr.len_excluded_carriers * sizeof(RIL_Carrier));
   2728 #endif
   2729     free(allowedCarriers);
   2730     free(excludedCarriers);
   2731     return Void();
   2732 }
   2733 
   2734 Return<void> RadioImpl::getAllowedCarriers(int32_t serial) {
   2735 #if VDBG
   2736     RLOGD("getAllowedCarriers: serial %d", serial);
   2737 #endif
   2738     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CARRIER_RESTRICTIONS);
   2739     return Void();
   2740 }
   2741 
   2742 Return<void> RadioImpl::sendDeviceState(int32_t serial, DeviceStateType deviceStateType,
   2743                                         bool state) {
   2744 #if VDBG
   2745     RLOGD("sendDeviceState: serial %d", serial);
   2746 #endif
   2747     if (s_vendorFunctions->version < 15) {
   2748         if (deviceStateType ==  DeviceStateType::LOW_DATA_EXPECTED) {
   2749             RLOGD("sendDeviceState: calling screen state %d", BOOL_TO_INT(!state));
   2750             dispatchInts(serial, mSlotId, RIL_REQUEST_SCREEN_STATE, 1, BOOL_TO_INT(!state));
   2751         } else {
   2752             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   2753                     RIL_REQUEST_SEND_DEVICE_STATE);
   2754             sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
   2755         }
   2756         return Void();
   2757     }
   2758     dispatchInts(serial, mSlotId, RIL_REQUEST_SEND_DEVICE_STATE, 2, (int) deviceStateType,
   2759             BOOL_TO_INT(state));
   2760     return Void();
   2761 }
   2762 
   2763 Return<void> RadioImpl::setIndicationFilter(int32_t serial, int32_t indicationFilter) {
   2764 #if VDBG
   2765     RLOGD("setIndicationFilter: serial %d", serial);
   2766 #endif
   2767     if (s_vendorFunctions->version < 15) {
   2768         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
   2769                 RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER);
   2770         sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
   2771         return Void();
   2772     }
   2773     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, 1, indicationFilter);
   2774     return Void();
   2775 }
   2776 
   2777 Return<void> RadioImpl::setSimCardPower(int32_t serial, bool powerUp) {
   2778 #if VDBG
   2779     RLOGD("setSimCardPower: serial %d", serial);
   2780 #endif
   2781     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, BOOL_TO_INT(powerUp));
   2782     return Void();
   2783 }
   2784 
   2785 Return<void> RadioImpl::setSimCardPower_1_1(int32_t serial, const V1_1::CardPowerState state) {
   2786 #if VDBG
   2787     RLOGD("setSimCardPower_1_1: serial %d state %d", serial, state);
   2788 #endif
   2789     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, state);
   2790     return Void();
   2791 }
   2792 
   2793 Return<void> RadioImpl::setCarrierInfoForImsiEncryption(int32_t serial,
   2794         const V1_1::ImsiEncryptionInfo& data) {
   2795 #if VDBG
   2796     RLOGD("setCarrierInfoForImsiEncryption: serial %d", serial);
   2797 #endif
   2798     RequestInfo *pRI = android::addRequestToList(
   2799             serial, mSlotId, RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION);
   2800     if (pRI == NULL) {
   2801         return Void();
   2802     }
   2803 
   2804     RIL_CarrierInfoForImsiEncryption imsiEncryption = {};
   2805 
   2806     if (!copyHidlStringToRil(&imsiEncryption.mnc, data.mnc, pRI)) {
   2807         return Void();
   2808     }
   2809     if (!copyHidlStringToRil(&imsiEncryption.mcc, data.mcc, pRI)) {
   2810         memsetAndFreeStrings(1, imsiEncryption.mnc);
   2811         return Void();
   2812     }
   2813     if (!copyHidlStringToRil(&imsiEncryption.keyIdentifier, data.keyIdentifier, pRI)) {
   2814         memsetAndFreeStrings(2, imsiEncryption.mnc, imsiEncryption.mcc);
   2815         return Void();
   2816     }
   2817     imsiEncryption.carrierKeyLength = data.carrierKey.size();
   2818     imsiEncryption.carrierKey = new uint8_t[imsiEncryption.carrierKeyLength];
   2819     memcpy(imsiEncryption.carrierKey, data.carrierKey.data(), imsiEncryption.carrierKeyLength);
   2820     imsiEncryption.expirationTime = data.expirationTime;
   2821     CALL_ONREQUEST(pRI->pCI->requestNumber, &imsiEncryption,
   2822             sizeof(RIL_CarrierInfoForImsiEncryption), pRI, mSlotId);
   2823     delete(imsiEncryption.carrierKey);
   2824     return Void();
   2825 }
   2826 
   2827 Return<void> RadioImpl::startKeepalive(int32_t serial, const V1_1::KeepaliveRequest& keepalive) {
   2828 #if VDBG
   2829     RLOGD("%s(): %d", __FUNCTION__, serial);
   2830 #endif
   2831     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_KEEPALIVE);
   2832     if (pRI == NULL) {
   2833         return Void();
   2834     }
   2835 
   2836     RIL_KeepaliveRequest kaReq = {};
   2837 
   2838     kaReq.type = static_cast<RIL_KeepaliveType>(keepalive.type);
   2839     switch(kaReq.type) {
   2840         case NATT_IPV4:
   2841             if (keepalive.sourceAddress.size() != 4 ||
   2842                     keepalive.destinationAddress.size() != 4) {
   2843                 RLOGE("Invalid address for keepalive!");
   2844                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   2845                 return Void();
   2846             }
   2847             break;
   2848         case NATT_IPV6:
   2849             if (keepalive.sourceAddress.size() != 16 ||
   2850                     keepalive.destinationAddress.size() != 16) {
   2851                 RLOGE("Invalid address for keepalive!");
   2852                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   2853                 return Void();
   2854             }
   2855             break;
   2856         default:
   2857             RLOGE("Unknown packet keepalive type!");
   2858             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
   2859             return Void();
   2860     }
   2861 
   2862     ::memcpy(kaReq.sourceAddress, keepalive.sourceAddress.data(), keepalive.sourceAddress.size());
   2863     kaReq.sourcePort = keepalive.sourcePort;
   2864 
   2865     ::memcpy(kaReq.destinationAddress,
   2866             keepalive.destinationAddress.data(), keepalive.destinationAddress.size());
   2867     kaReq.destinationPort = keepalive.destinationPort;
   2868 
   2869     kaReq.maxKeepaliveIntervalMillis = keepalive.maxKeepaliveIntervalMillis;
   2870     kaReq.cid = keepalive.cid; // This is the context ID of the data call
   2871 
   2872     CALL_ONREQUEST(pRI->pCI->requestNumber, &kaReq, sizeof(RIL_KeepaliveRequest), pRI, mSlotId);
   2873     return Void();
   2874 }
   2875 
   2876 Return<void> RadioImpl::stopKeepalive(int32_t serial, int32_t sessionHandle) {
   2877 #if VDBG
   2878     RLOGD("%s(): %d", __FUNCTION__, serial);
   2879 #endif
   2880     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_STOP_KEEPALIVE);
   2881     if (pRI == NULL) {
   2882         return Void();
   2883     }
   2884 
   2885     CALL_ONREQUEST(pRI->pCI->requestNumber, &sessionHandle, sizeof(uint32_t), pRI, mSlotId);
   2886     return Void();
   2887 }
   2888 
   2889 Return<void> RadioImpl::responseAcknowledgement() {
   2890     android::releaseWakeLock();
   2891     return Void();
   2892 }
   2893 
   2894 Return<void> OemHookImpl::setResponseFunctions(
   2895         const ::android::sp<IOemHookResponse>& oemHookResponseParam,
   2896         const ::android::sp<IOemHookIndication>& oemHookIndicationParam) {
   2897 #if VDBG
   2898     RLOGD("OemHookImpl::setResponseFunctions");
   2899 #endif
   2900 
   2901     pthread_rwlock_t *radioServiceRwlockPtr = radio::getRadioServiceRwlock(mSlotId);
   2902     int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
   2903     assert(ret == 0);
   2904 
   2905     mOemHookResponse = oemHookResponseParam;
   2906     mOemHookIndication = oemHookIndicationParam;
   2907     mCounterOemHook[mSlotId]++;
   2908 
   2909     ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
   2910     assert(ret == 0);
   2911 
   2912     return Void();
   2913 }
   2914 
   2915 Return<void> OemHookImpl::sendRequestRaw(int32_t serial, const hidl_vec<uint8_t>& data) {
   2916 #if VDBG
   2917     RLOGD("OemHookImpl::sendRequestRaw: serial %d", serial);
   2918 #endif
   2919     dispatchRaw(serial, mSlotId, RIL_REQUEST_OEM_HOOK_RAW, data);
   2920     return Void();
   2921 }
   2922 
   2923 Return<void> OemHookImpl::sendRequestStrings(int32_t serial,
   2924         const hidl_vec<hidl_string>& data) {
   2925 #if VDBG
   2926     RLOGD("OemHookImpl::sendRequestStrings: serial %d", serial);
   2927 #endif
   2928     dispatchStrings(serial, mSlotId, RIL_REQUEST_OEM_HOOK_STRINGS, data);
   2929     return Void();
   2930 }
   2931 
   2932 /***************************************************************************************************
   2933  * RESPONSE FUNCTIONS
   2934  * Functions above are used for requests going from framework to vendor code. The ones below are
   2935  * responses for those requests coming back from the vendor code.
   2936  **************************************************************************************************/
   2937 
   2938 void radio::acknowledgeRequest(int slotId, int serial) {
   2939     if (radioService[slotId]->mRadioResponse != NULL) {
   2940         Return<void> retStatus = radioService[slotId]->mRadioResponse->acknowledgeRequest(serial);
   2941         radioService[slotId]->checkReturnStatus(retStatus);
   2942     } else {
   2943         RLOGE("acknowledgeRequest: radioService[%d]->mRadioResponse == NULL", slotId);
   2944     }
   2945 }
   2946 
   2947 void populateResponseInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
   2948                          RIL_Errno e) {
   2949     responseInfo.serial = serial;
   2950     switch (responseType) {
   2951         case RESPONSE_SOLICITED:
   2952             responseInfo.type = RadioResponseType::SOLICITED;
   2953             break;
   2954         case RESPONSE_SOLICITED_ACK_EXP:
   2955             responseInfo.type = RadioResponseType::SOLICITED_ACK_EXP;
   2956             break;
   2957     }
   2958     responseInfo.error = (RadioError) e;
   2959 }
   2960 
   2961 int responseIntOrEmpty(RadioResponseInfo& responseInfo, int serial, int responseType, RIL_Errno e,
   2962                void *response, size_t responseLen) {
   2963     populateResponseInfo(responseInfo, serial, responseType, e);
   2964     int ret = -1;
   2965 
   2966     if (response == NULL && responseLen == 0) {
   2967         // Earlier RILs did not send a response for some cases although the interface
   2968         // expected an integer as response. Do not return error if response is empty. Instead
   2969         // Return -1 in those cases to maintain backward compatibility.
   2970     } else if (response == NULL || responseLen != sizeof(int)) {
   2971         RLOGE("responseIntOrEmpty: Invalid response");
   2972         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   2973     } else {
   2974         int *p_int = (int *) response;
   2975         ret = p_int[0];
   2976     }
   2977     return ret;
   2978 }
   2979 
   2980 int responseInt(RadioResponseInfo& responseInfo, int serial, int responseType, RIL_Errno e,
   2981                void *response, size_t responseLen) {
   2982     populateResponseInfo(responseInfo, serial, responseType, e);
   2983     int ret = -1;
   2984 
   2985     if (response == NULL || responseLen != sizeof(int)) {
   2986         RLOGE("responseInt: Invalid response");
   2987         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   2988     } else {
   2989         int *p_int = (int *) response;
   2990         ret = p_int[0];
   2991     }
   2992     return ret;
   2993 }
   2994 
   2995 int radio::getIccCardStatusResponse(int slotId,
   2996                                    int responseType, int serial, RIL_Errno e,
   2997                                    void *response, size_t responseLen) {
   2998     if (radioService[slotId]->mRadioResponse != NULL) {
   2999         RadioResponseInfo responseInfo = {};
   3000         populateResponseInfo(responseInfo, serial, responseType, e);
   3001         CardStatus cardStatus = {};
   3002         RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
   3003         if (response == NULL || responseLen != sizeof(RIL_CardStatus_v6)
   3004                 || p_cur->gsm_umts_subscription_app_index >= p_cur->num_applications
   3005                 || p_cur->cdma_subscription_app_index >= p_cur->num_applications
   3006                 || p_cur->ims_subscription_app_index >= p_cur->num_applications) {
   3007             RLOGE("getIccCardStatusResponse: Invalid response");
   3008             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3009         } else {
   3010             cardStatus.cardState = (CardState) p_cur->card_state;
   3011             cardStatus.universalPinState = (PinState) p_cur->universal_pin_state;
   3012             cardStatus.gsmUmtsSubscriptionAppIndex = p_cur->gsm_umts_subscription_app_index;
   3013             cardStatus.cdmaSubscriptionAppIndex = p_cur->cdma_subscription_app_index;
   3014             cardStatus.imsSubscriptionAppIndex = p_cur->ims_subscription_app_index;
   3015 
   3016             RIL_AppStatus *rilAppStatus = p_cur->applications;
   3017             cardStatus.applications.resize(p_cur->num_applications);
   3018             AppStatus *appStatus = cardStatus.applications.data();
   3019 #if VDBG
   3020             RLOGD("getIccCardStatusResponse: num_applications %d", p_cur->num_applications);
   3021 #endif
   3022             for (int i = 0; i < p_cur->num_applications; i++) {
   3023                 appStatus[i].appType = (AppType) rilAppStatus[i].app_type;
   3024                 appStatus[i].appState = (AppState) rilAppStatus[i].app_state;
   3025                 appStatus[i].persoSubstate = (PersoSubstate) rilAppStatus[i].perso_substate;
   3026                 appStatus[i].aidPtr = convertCharPtrToHidlString(rilAppStatus[i].aid_ptr);
   3027                 appStatus[i].appLabelPtr = convertCharPtrToHidlString(
   3028                         rilAppStatus[i].app_label_ptr);
   3029                 appStatus[i].pin1Replaced = rilAppStatus[i].pin1_replaced;
   3030                 appStatus[i].pin1 = (PinState) rilAppStatus[i].pin1;
   3031                 appStatus[i].pin2 = (PinState) rilAppStatus[i].pin2;
   3032             }
   3033         }
   3034 
   3035         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   3036                 getIccCardStatusResponse(responseInfo, cardStatus);
   3037         radioService[slotId]->checkReturnStatus(retStatus);
   3038     } else {
   3039         RLOGE("getIccCardStatusResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   3040     }
   3041 
   3042     return 0;
   3043 }
   3044 
   3045 int radio::supplyIccPinForAppResponse(int slotId,
   3046                                      int responseType, int serial, RIL_Errno e,
   3047                                      void *response, size_t responseLen) {
   3048 #if VDBG
   3049     RLOGD("supplyIccPinForAppResponse: serial %d", serial);
   3050 #endif
   3051 
   3052     if (radioService[slotId]->mRadioResponse != NULL) {
   3053         RadioResponseInfo responseInfo = {};
   3054         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
   3055         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   3056                 supplyIccPinForAppResponse(responseInfo, ret);
   3057         RLOGE("supplyIccPinForAppResponse: amit ret %d", ret);
   3058         radioService[slotId]->checkReturnStatus(retStatus);
   3059     } else {
   3060         RLOGE("supplyIccPinForAppResponse: radioService[%d]->mRadioResponse == NULL",
   3061                 slotId);
   3062     }
   3063 
   3064     return 0;
   3065 }
   3066 
   3067 int radio::supplyIccPukForAppResponse(int slotId,
   3068                                      int responseType, int serial, RIL_Errno e,
   3069                                      void *response, size_t responseLen) {
   3070 #if VDBG
   3071     RLOGD("supplyIccPukForAppResponse: serial %d", serial);
   3072 #endif
   3073 
   3074     if (radioService[slotId]->mRadioResponse != NULL) {
   3075         RadioResponseInfo responseInfo = {};
   3076         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
   3077         Return<void> retStatus = radioService[slotId]->mRadioResponse->supplyIccPukForAppResponse(
   3078                 responseInfo, ret);
   3079         radioService[slotId]->checkReturnStatus(retStatus);
   3080     } else {
   3081         RLOGE("supplyIccPukForAppResponse: radioService[%d]->mRadioResponse == NULL",
   3082                 slotId);
   3083     }
   3084 
   3085     return 0;
   3086 }
   3087 
   3088 int radio::supplyIccPin2ForAppResponse(int slotId,
   3089                                       int responseType, int serial, RIL_Errno e,
   3090                                       void *response, size_t responseLen) {
   3091 #if VDBG
   3092     RLOGD("supplyIccPin2ForAppResponse: serial %d", serial);
   3093 #endif
   3094 
   3095     if (radioService[slotId]->mRadioResponse != NULL) {
   3096         RadioResponseInfo responseInfo = {};
   3097         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
   3098         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   3099                 supplyIccPin2ForAppResponse(responseInfo, ret);
   3100         radioService[slotId]->checkReturnStatus(retStatus);
   3101     } else {
   3102         RLOGE("supplyIccPin2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
   3103                 slotId);
   3104     }
   3105 
   3106     return 0;
   3107 }
   3108 
   3109 int radio::supplyIccPuk2ForAppResponse(int slotId,
   3110                                       int responseType, int serial, RIL_Errno e,
   3111                                       void *response, size_t responseLen) {
   3112 #if VDBG
   3113     RLOGD("supplyIccPuk2ForAppResponse: serial %d", serial);
   3114 #endif
   3115 
   3116     if (radioService[slotId]->mRadioResponse != NULL) {
   3117         RadioResponseInfo responseInfo = {};
   3118         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
   3119         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   3120                 supplyIccPuk2ForAppResponse(responseInfo, ret);
   3121         radioService[slotId]->checkReturnStatus(retStatus);
   3122     } else {
   3123         RLOGE("supplyIccPuk2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
   3124                 slotId);
   3125     }
   3126 
   3127     return 0;
   3128 }
   3129 
   3130 int radio::changeIccPinForAppResponse(int slotId,
   3131                                      int responseType, int serial, RIL_Errno e,
   3132                                      void *response, size_t responseLen) {
   3133 #if VDBG
   3134     RLOGD("changeIccPinForAppResponse: serial %d", serial);
   3135 #endif
   3136 
   3137     if (radioService[slotId]->mRadioResponse != NULL) {
   3138         RadioResponseInfo responseInfo = {};
   3139         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
   3140         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   3141                 changeIccPinForAppResponse(responseInfo, ret);
   3142         radioService[slotId]->checkReturnStatus(retStatus);
   3143     } else {
   3144         RLOGE("changeIccPinForAppResponse: radioService[%d]->mRadioResponse == NULL",
   3145                 slotId);
   3146     }
   3147 
   3148     return 0;
   3149 }
   3150 
   3151 int radio::changeIccPin2ForAppResponse(int slotId,
   3152                                       int responseType, int serial, RIL_Errno e,
   3153                                       void *response, size_t responseLen) {
   3154 #if VDBG
   3155     RLOGD("changeIccPin2ForAppResponse: serial %d", serial);
   3156 #endif
   3157 
   3158     if (radioService[slotId]->mRadioResponse != NULL) {
   3159         RadioResponseInfo responseInfo = {};
   3160         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
   3161         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   3162                 changeIccPin2ForAppResponse(responseInfo, ret);
   3163         radioService[slotId]->checkReturnStatus(retStatus);
   3164     } else {
   3165         RLOGE("changeIccPin2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
   3166                 slotId);
   3167     }
   3168 
   3169     return 0;
   3170 }
   3171 
   3172 int radio::supplyNetworkDepersonalizationResponse(int slotId,
   3173                                                  int responseType, int serial, RIL_Errno e,
   3174                                                  void *response, size_t responseLen) {
   3175 #if VDBG
   3176     RLOGD("supplyNetworkDepersonalizationResponse: serial %d", serial);
   3177 #endif
   3178 
   3179     if (radioService[slotId]->mRadioResponse != NULL) {
   3180         RadioResponseInfo responseInfo = {};
   3181         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
   3182         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   3183                 supplyNetworkDepersonalizationResponse(responseInfo, ret);
   3184         radioService[slotId]->checkReturnStatus(retStatus);
   3185     } else {
   3186         RLOGE("supplyNetworkDepersonalizationResponse: radioService[%d]->mRadioResponse == "
   3187                 "NULL", slotId);
   3188     }
   3189 
   3190     return 0;
   3191 }
   3192 
   3193 int radio::getCurrentCallsResponse(int slotId,
   3194                                   int responseType, int serial, RIL_Errno e,
   3195                                   void *response, size_t responseLen) {
   3196 #if VDBG
   3197     RLOGD("getCurrentCallsResponse: serial %d", serial);
   3198 #endif
   3199 
   3200     if (radioService[slotId]->mRadioResponse != NULL) {
   3201         RadioResponseInfo responseInfo = {};
   3202         populateResponseInfo(responseInfo, serial, responseType, e);
   3203 
   3204         hidl_vec<Call> calls;
   3205         if ((response == NULL && responseLen != 0)
   3206                 || (responseLen % sizeof(RIL_Call *)) != 0) {
   3207             RLOGE("getCurrentCallsResponse: Invalid response");
   3208             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3209         } else {
   3210             int num = responseLen / sizeof(RIL_Call *);
   3211             calls.resize(num);
   3212 
   3213             for (int i = 0 ; i < num ; i++) {
   3214                 RIL_Call *p_cur = ((RIL_Call **) response)[i];
   3215                 /* each call info */
   3216                 calls[i].state = (CallState) p_cur->state;
   3217                 calls[i].index = p_cur->index;
   3218                 calls[i].toa = p_cur->toa;
   3219                 calls[i].isMpty = p_cur->isMpty;
   3220                 calls[i].isMT = p_cur->isMT;
   3221                 calls[i].als = p_cur->als;
   3222                 calls[i].isVoice = p_cur->isVoice;
   3223                 calls[i].isVoicePrivacy = p_cur->isVoicePrivacy;
   3224                 calls[i].number = convertCharPtrToHidlString(p_cur->number);
   3225                 calls[i].numberPresentation = (CallPresentation) p_cur->numberPresentation;
   3226                 calls[i].name = convertCharPtrToHidlString(p_cur->name);
   3227                 calls[i].namePresentation = (CallPresentation) p_cur->namePresentation;
   3228                 if (p_cur->uusInfo != NULL && p_cur->uusInfo->uusData != NULL) {
   3229                     RIL_UUS_Info *uusInfo = p_cur->uusInfo;
   3230                     calls[i].uusInfo.resize(1);
   3231                     calls[i].uusInfo[0].uusType = (UusType) uusInfo->uusType;
   3232                     calls[i].uusInfo[0].uusDcs = (UusDcs) uusInfo->uusDcs;
   3233                     // convert uusInfo->uusData to a null-terminated string
   3234                     char *nullTermStr = strndup(uusInfo->uusData, uusInfo->uusLength);
   3235                     calls[i].uusInfo[0].uusData = nullTermStr;
   3236                     free(nullTermStr);
   3237                 }
   3238             }
   3239         }
   3240 
   3241         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   3242                 getCurrentCallsResponse(responseInfo, calls);
   3243         radioService[slotId]->checkReturnStatus(retStatus);
   3244     } else {
   3245         RLOGE("getCurrentCallsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   3246     }
   3247 
   3248     return 0;
   3249 }
   3250 
   3251 int radio::dialResponse(int slotId,
   3252                        int responseType, int serial, RIL_Errno e, void *response,
   3253                        size_t responseLen) {
   3254 #if VDBG
   3255     RLOGD("dialResponse: serial %d", serial);
   3256 #endif
   3257 
   3258     if (radioService[slotId]->mRadioResponse != NULL) {
   3259         RadioResponseInfo responseInfo = {};
   3260         populateResponseInfo(responseInfo, serial, responseType, e);
   3261         Return<void> retStatus = radioService[slotId]->mRadioResponse->dialResponse(responseInfo);
   3262         radioService[slotId]->checkReturnStatus(retStatus);
   3263     } else {
   3264         RLOGE("dialResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   3265     }
   3266 
   3267     return 0;
   3268 }
   3269 
   3270 int radio::getIMSIForAppResponse(int slotId,
   3271                                 int responseType, int serial, RIL_Errno e, void *response,
   3272                                 size_t responseLen) {
   3273 #if VDBG
   3274     RLOGD("getIMSIForAppResponse: serial %d", serial);
   3275 #endif
   3276 
   3277     if (radioService[slotId]->mRadioResponse != NULL) {
   3278         RadioResponseInfo responseInfo = {};
   3279         populateResponseInfo(responseInfo, serial, responseType, e);
   3280         Return<void> retStatus = radioService[slotId]->mRadioResponse->getIMSIForAppResponse(
   3281                 responseInfo, convertCharPtrToHidlString((char *) response));
   3282         radioService[slotId]->checkReturnStatus(retStatus);
   3283     } else {
   3284         RLOGE("getIMSIForAppResponse: radioService[%d]->mRadioResponse == NULL",
   3285                 slotId);
   3286     }
   3287 
   3288     return 0;
   3289 }
   3290 
   3291 int radio::hangupConnectionResponse(int slotId,
   3292                                    int responseType, int serial, RIL_Errno e,
   3293                                    void *response, size_t responseLen) {
   3294 #if VDBG
   3295     RLOGD("hangupConnectionResponse: serial %d", serial);
   3296 #endif
   3297 
   3298     if (radioService[slotId]->mRadioResponse != NULL) {
   3299         RadioResponseInfo responseInfo = {};
   3300         populateResponseInfo(responseInfo, serial, responseType, e);
   3301         Return<void> retStatus = radioService[slotId]->mRadioResponse->hangupConnectionResponse(
   3302                 responseInfo);
   3303         radioService[slotId]->checkReturnStatus(retStatus);
   3304     } else {
   3305         RLOGE("hangupConnectionResponse: radioService[%d]->mRadioResponse == NULL",
   3306                 slotId);
   3307     }
   3308 
   3309     return 0;
   3310 }
   3311 
   3312 int radio::hangupWaitingOrBackgroundResponse(int slotId,
   3313                                             int responseType, int serial, RIL_Errno e,
   3314                                             void *response, size_t responseLen) {
   3315 #if VDBG
   3316     RLOGD("hangupWaitingOrBackgroundResponse: serial %d", serial);
   3317 #endif
   3318 
   3319     if (radioService[slotId]->mRadioResponse != NULL) {
   3320         RadioResponseInfo responseInfo = {};
   3321         populateResponseInfo(responseInfo, serial, responseType, e);
   3322         Return<void> retStatus =
   3323                 radioService[slotId]->mRadioResponse->hangupWaitingOrBackgroundResponse(
   3324                 responseInfo);
   3325         radioService[slotId]->checkReturnStatus(retStatus);
   3326     } else {
   3327         RLOGE("hangupWaitingOrBackgroundResponse: radioService[%d]->mRadioResponse == NULL",
   3328                 slotId);
   3329     }
   3330 
   3331     return 0;
   3332 }
   3333 
   3334 int radio::hangupForegroundResumeBackgroundResponse(int slotId, int responseType, int serial,
   3335                                                     RIL_Errno e, void *response,
   3336                                                     size_t responseLen) {
   3337 #if VDBG
   3338     RLOGD("hangupWaitingOrBackgroundResponse: serial %d", serial);
   3339 #endif
   3340 
   3341     if (radioService[slotId]->mRadioResponse != NULL) {
   3342         RadioResponseInfo responseInfo = {};
   3343         populateResponseInfo(responseInfo, serial, responseType, e);
   3344         Return<void> retStatus =
   3345                 radioService[slotId]->mRadioResponse->hangupWaitingOrBackgroundResponse(
   3346                 responseInfo);
   3347         radioService[slotId]->checkReturnStatus(retStatus);
   3348     } else {
   3349         RLOGE("hangupWaitingOrBackgroundResponse: radioService[%d]->mRadioResponse == NULL",
   3350                 slotId);
   3351     }
   3352 
   3353     return 0;
   3354 }
   3355 
   3356 int radio::switchWaitingOrHoldingAndActiveResponse(int slotId, int responseType, int serial,
   3357                                                    RIL_Errno e, void *response,
   3358                                                    size_t responseLen) {
   3359 #if VDBG
   3360     RLOGD("switchWaitingOrHoldingAndActiveResponse: serial %d", serial);
   3361 #endif
   3362 
   3363     if (radioService[slotId]->mRadioResponse != NULL) {
   3364         RadioResponseInfo responseInfo = {};
   3365         populateResponseInfo(responseInfo, serial, responseType, e);
   3366         Return<void> retStatus =
   3367                 radioService[slotId]->mRadioResponse->switchWaitingOrHoldingAndActiveResponse(
   3368                 responseInfo);
   3369         radioService[slotId]->checkReturnStatus(retStatus);
   3370     } else {
   3371         RLOGE("switchWaitingOrHoldingAndActiveResponse: radioService[%d]->mRadioResponse "
   3372                 "== NULL", slotId);
   3373     }
   3374 
   3375     return 0;
   3376 }
   3377 
   3378 int radio::conferenceResponse(int slotId, int responseType,
   3379                              int serial, RIL_Errno e, void *response, size_t responseLen) {
   3380 #if VDBG
   3381     RLOGD("conferenceResponse: serial %d", serial);
   3382 #endif
   3383 
   3384     if (radioService[slotId]->mRadioResponse != NULL) {
   3385         RadioResponseInfo responseInfo = {};
   3386         populateResponseInfo(responseInfo, serial, responseType, e);
   3387         Return<void> retStatus = radioService[slotId]->mRadioResponse->conferenceResponse(
   3388                 responseInfo);
   3389         radioService[slotId]->checkReturnStatus(retStatus);
   3390     } else {
   3391         RLOGE("conferenceResponse: radioService[%d]->mRadioResponse == NULL",
   3392                 slotId);
   3393     }
   3394 
   3395     return 0;
   3396 }
   3397 
   3398 int radio::rejectCallResponse(int slotId, int responseType,
   3399                              int serial, RIL_Errno e, void *response, size_t responseLen) {
   3400 #if VDBG
   3401     RLOGD("rejectCallResponse: serial %d", serial);
   3402 #endif
   3403 
   3404     if (radioService[slotId]->mRadioResponse != NULL) {
   3405         RadioResponseInfo responseInfo = {};
   3406         populateResponseInfo(responseInfo, serial, responseType, e);
   3407         Return<void> retStatus = radioService[slotId]->mRadioResponse->rejectCallResponse(
   3408                 responseInfo);
   3409         radioService[slotId]->checkReturnStatus(retStatus);
   3410     } else {
   3411         RLOGE("rejectCallResponse: radioService[%d]->mRadioResponse == NULL",
   3412                 slotId);
   3413     }
   3414 
   3415     return 0;
   3416 }
   3417 
   3418 int radio::getLastCallFailCauseResponse(int slotId,
   3419                                        int responseType, int serial, RIL_Errno e, void *response,
   3420                                        size_t responseLen) {
   3421 #if VDBG
   3422     RLOGD("getLastCallFailCauseResponse: serial %d", serial);
   3423 #endif
   3424 
   3425     if (radioService[slotId]->mRadioResponse != NULL) {
   3426         RadioResponseInfo responseInfo = {};
   3427         populateResponseInfo(responseInfo, serial, responseType, e);
   3428 
   3429         LastCallFailCauseInfo info = {};
   3430         info.vendorCause = hidl_string();
   3431         if (response == NULL) {
   3432             RLOGE("getCurrentCallsResponse Invalid response: NULL");
   3433             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3434         } else if (responseLen == sizeof(int)) {
   3435             int *pInt = (int *) response;
   3436             info.causeCode = (LastCallFailCause) pInt[0];
   3437         } else if (responseLen == sizeof(RIL_LastCallFailCauseInfo))  {
   3438             RIL_LastCallFailCauseInfo *pFailCauseInfo = (RIL_LastCallFailCauseInfo *) response;
   3439             info.causeCode = (LastCallFailCause) pFailCauseInfo->cause_code;
   3440             info.vendorCause = convertCharPtrToHidlString(pFailCauseInfo->vendor_cause);
   3441         } else {
   3442             RLOGE("getCurrentCallsResponse Invalid response: NULL");
   3443             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3444         }
   3445 
   3446         Return<void> retStatus = radioService[slotId]->mRadioResponse->getLastCallFailCauseResponse(
   3447                 responseInfo, info);
   3448         radioService[slotId]->checkReturnStatus(retStatus);
   3449     } else {
   3450         RLOGE("getLastCallFailCauseResponse: radioService[%d]->mRadioResponse == NULL",
   3451                 slotId);
   3452     }
   3453 
   3454     return 0;
   3455 }
   3456 
   3457 int radio::getSignalStrengthResponse(int slotId,
   3458                                      int responseType, int serial, RIL_Errno e,
   3459                                      void *response, size_t responseLen) {
   3460 #if VDBG
   3461     RLOGD("getSignalStrengthResponse: serial %d", serial);
   3462 #endif
   3463 
   3464     if (radioService[slotId]->mRadioResponse != NULL) {
   3465         RadioResponseInfo responseInfo = {};
   3466         populateResponseInfo(responseInfo, serial, responseType, e);
   3467         SignalStrength signalStrength = {};
   3468         if (response == NULL || responseLen != sizeof(RIL_SignalStrength_v10)) {
   3469             RLOGE("getSignalStrengthResponse: Invalid response");
   3470             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3471         } else {
   3472             convertRilSignalStrengthToHal(response, responseLen, signalStrength);
   3473         }
   3474 
   3475         Return<void> retStatus = radioService[slotId]->mRadioResponse->getSignalStrengthResponse(
   3476                 responseInfo, signalStrength);
   3477         radioService[slotId]->checkReturnStatus(retStatus);
   3478     } else {
   3479         RLOGE("getSignalStrengthResponse: radioService[%d]->mRadioResponse == NULL",
   3480                 slotId);
   3481     }
   3482 
   3483     return 0;
   3484 }
   3485 
   3486 RIL_CellInfoType getCellInfoTypeRadioTechnology(char *rat) {
   3487     if (rat == NULL) {
   3488         return RIL_CELL_INFO_TYPE_NONE;
   3489     }
   3490 
   3491     int radioTech = atoi(rat);
   3492 
   3493     switch(radioTech) {
   3494 
   3495         case RADIO_TECH_GPRS:
   3496         case RADIO_TECH_EDGE:
   3497         case RADIO_TECH_GSM: {
   3498             return RIL_CELL_INFO_TYPE_GSM;
   3499         }
   3500 
   3501         case RADIO_TECH_UMTS:
   3502         case RADIO_TECH_HSDPA:
   3503         case RADIO_TECH_HSUPA:
   3504         case RADIO_TECH_HSPA:
   3505         case RADIO_TECH_HSPAP: {
   3506             return RIL_CELL_INFO_TYPE_WCDMA;
   3507         }
   3508 
   3509         case RADIO_TECH_IS95A:
   3510         case RADIO_TECH_IS95B:
   3511         case RADIO_TECH_1xRTT:
   3512         case RADIO_TECH_EVDO_0:
   3513         case RADIO_TECH_EVDO_A:
   3514         case RADIO_TECH_EVDO_B:
   3515         case RADIO_TECH_EHRPD: {
   3516             return RIL_CELL_INFO_TYPE_CDMA;
   3517         }
   3518 
   3519         case RADIO_TECH_LTE:
   3520         case RADIO_TECH_LTE_CA: {
   3521             return RIL_CELL_INFO_TYPE_LTE;
   3522         }
   3523 
   3524         case RADIO_TECH_TD_SCDMA: {
   3525             return RIL_CELL_INFO_TYPE_TD_SCDMA;
   3526         }
   3527 
   3528         default: {
   3529             break;
   3530         }
   3531     }
   3532 
   3533     return RIL_CELL_INFO_TYPE_NONE;
   3534 
   3535 }
   3536 
   3537 void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 &rilCellIdentity) {
   3538 
   3539     cellIdentity.cellIdentityGsm.resize(0);
   3540     cellIdentity.cellIdentityWcdma.resize(0);
   3541     cellIdentity.cellIdentityCdma.resize(0);
   3542     cellIdentity.cellIdentityTdscdma.resize(0);
   3543     cellIdentity.cellIdentityLte.resize(0);
   3544     cellIdentity.cellInfoType = (CellInfoType)rilCellIdentity.cellInfoType;
   3545     switch(rilCellIdentity.cellInfoType) {
   3546 
   3547         case RIL_CELL_INFO_TYPE_GSM: {
   3548             cellIdentity.cellIdentityGsm.resize(1);
   3549             cellIdentity.cellIdentityGsm[0].mcc =
   3550                     std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
   3551             cellIdentity.cellIdentityGsm[0].mnc =
   3552                     std::to_string(rilCellIdentity.cellIdentityGsm.mnc);
   3553             cellIdentity.cellIdentityGsm[0].lac = rilCellIdentity.cellIdentityGsm.lac;
   3554             cellIdentity.cellIdentityGsm[0].cid = rilCellIdentity.cellIdentityGsm.cid;
   3555             cellIdentity.cellIdentityGsm[0].arfcn = rilCellIdentity.cellIdentityGsm.arfcn;
   3556             cellIdentity.cellIdentityGsm[0].bsic = rilCellIdentity.cellIdentityGsm.bsic;
   3557             break;
   3558         }
   3559 
   3560         case RIL_CELL_INFO_TYPE_WCDMA: {
   3561             cellIdentity.cellIdentityWcdma.resize(1);
   3562             cellIdentity.cellIdentityWcdma[0].mcc =
   3563                     std::to_string(rilCellIdentity.cellIdentityWcdma.mcc);
   3564             cellIdentity.cellIdentityWcdma[0].mnc =
   3565                     std::to_string(rilCellIdentity.cellIdentityWcdma.mnc);
   3566             cellIdentity.cellIdentityWcdma[0].lac = rilCellIdentity.cellIdentityWcdma.lac;
   3567             cellIdentity.cellIdentityWcdma[0].cid = rilCellIdentity.cellIdentityWcdma.cid;
   3568             cellIdentity.cellIdentityWcdma[0].psc = rilCellIdentity.cellIdentityWcdma.psc;
   3569             cellIdentity.cellIdentityWcdma[0].uarfcn = rilCellIdentity.cellIdentityWcdma.uarfcn;
   3570             break;
   3571         }
   3572 
   3573         case RIL_CELL_INFO_TYPE_CDMA: {
   3574             cellIdentity.cellIdentityCdma.resize(1);
   3575             cellIdentity.cellIdentityCdma[0].networkId = rilCellIdentity.cellIdentityCdma.networkId;
   3576             cellIdentity.cellIdentityCdma[0].systemId = rilCellIdentity.cellIdentityCdma.systemId;
   3577             cellIdentity.cellIdentityCdma[0].baseStationId =
   3578                     rilCellIdentity.cellIdentityCdma.basestationId;
   3579             cellIdentity.cellIdentityCdma[0].longitude = rilCellIdentity.cellIdentityCdma.longitude;
   3580             cellIdentity.cellIdentityCdma[0].latitude = rilCellIdentity.cellIdentityCdma.latitude;
   3581             break;
   3582         }
   3583 
   3584         case RIL_CELL_INFO_TYPE_LTE: {
   3585             cellIdentity.cellIdentityLte.resize(1);
   3586             cellIdentity.cellIdentityLte[0].mcc =
   3587                     std::to_string(rilCellIdentity.cellIdentityLte.mcc);
   3588             cellIdentity.cellIdentityLte[0].mnc =
   3589                     std::to_string(rilCellIdentity.cellIdentityLte.mnc);
   3590             cellIdentity.cellIdentityLte[0].ci = rilCellIdentity.cellIdentityLte.ci;
   3591             cellIdentity.cellIdentityLte[0].pci = rilCellIdentity.cellIdentityLte.pci;
   3592             cellIdentity.cellIdentityLte[0].tac = rilCellIdentity.cellIdentityLte.tac;
   3593             cellIdentity.cellIdentityLte[0].earfcn = rilCellIdentity.cellIdentityLte.earfcn;
   3594             break;
   3595         }
   3596 
   3597         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
   3598             cellIdentity.cellIdentityTdscdma.resize(1);
   3599             cellIdentity.cellIdentityTdscdma[0].mcc =
   3600                     std::to_string(rilCellIdentity.cellIdentityTdscdma.mcc);
   3601             cellIdentity.cellIdentityTdscdma[0].mnc =
   3602                     std::to_string(rilCellIdentity.cellIdentityTdscdma.mnc);
   3603             cellIdentity.cellIdentityTdscdma[0].lac = rilCellIdentity.cellIdentityTdscdma.lac;
   3604             cellIdentity.cellIdentityTdscdma[0].cid = rilCellIdentity.cellIdentityTdscdma.cid;
   3605             cellIdentity.cellIdentityTdscdma[0].cpid = rilCellIdentity.cellIdentityTdscdma.cpid;
   3606             break;
   3607         }
   3608 
   3609         default: {
   3610             break;
   3611         }
   3612     }
   3613 }
   3614 
   3615 int convertResponseStringEntryToInt(char **response, int index, int numStrings) {
   3616     if ((response != NULL) &&  (numStrings > index) && (response[index] != NULL)) {
   3617         return atoi(response[index]);
   3618     }
   3619 
   3620     return -1;
   3621 }
   3622 
   3623 int convertResponseHexStringEntryToInt(char **response, int index, int numStrings) {
   3624     const int hexBase = 16;
   3625     if ((response != NULL) &&  (numStrings > index) && (response[index] != NULL)) {
   3626         return strtol(response[index], NULL, hexBase);
   3627     }
   3628 
   3629     return -1;
   3630 }
   3631 
   3632 /* Fill Cell Identity info from Voice Registration State Response.
   3633  * This fucntion is applicable only for RIL Version < 15.
   3634  * Response is a  "char **".
   3635  * First and Second entries are in hex string format
   3636  * and rest are integers represented in ascii format. */
   3637 void fillCellIdentityFromVoiceRegStateResponseString(CellIdentity &cellIdentity,
   3638         int numStrings, char** response) {
   3639 
   3640     RIL_CellIdentity_v16 rilCellIdentity;
   3641     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
   3642 
   3643     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
   3644     switch(rilCellIdentity.cellInfoType) {
   3645 
   3646         case RIL_CELL_INFO_TYPE_GSM: {
   3647             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
   3648             rilCellIdentity.cellIdentityGsm.lac =
   3649                     convertResponseHexStringEntryToInt(response, 1, numStrings);
   3650 
   3651             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
   3652             rilCellIdentity.cellIdentityGsm.cid =
   3653                     convertResponseHexStringEntryToInt(response, 2, numStrings);
   3654             break;
   3655         }
   3656 
   3657         case RIL_CELL_INFO_TYPE_WCDMA: {
   3658             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
   3659             rilCellIdentity.cellIdentityWcdma.lac =
   3660                     convertResponseHexStringEntryToInt(response, 1, numStrings);
   3661 
   3662             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
   3663             rilCellIdentity.cellIdentityWcdma.cid =
   3664                     convertResponseHexStringEntryToInt(response, 2, numStrings);
   3665             rilCellIdentity.cellIdentityWcdma.psc =
   3666                     convertResponseStringEntryToInt(response, 14, numStrings);
   3667             break;
   3668         }
   3669 
   3670         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
   3671             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
   3672             rilCellIdentity.cellIdentityTdscdma.lac =
   3673                     convertResponseHexStringEntryToInt(response, 1, numStrings);
   3674 
   3675             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
   3676             rilCellIdentity.cellIdentityTdscdma.cid =
   3677                     convertResponseHexStringEntryToInt(response, 2, numStrings);
   3678             break;
   3679         }
   3680 
   3681         case RIL_CELL_INFO_TYPE_CDMA:{
   3682             rilCellIdentity.cellIdentityCdma.basestationId =
   3683                     convertResponseStringEntryToInt(response, 4, numStrings);
   3684             /* Order of Lat. and Long. swapped between RIL and HIDL interface versions. */
   3685             rilCellIdentity.cellIdentityCdma.latitude =
   3686                     convertResponseStringEntryToInt(response, 5, numStrings);
   3687             rilCellIdentity.cellIdentityCdma.longitude =
   3688                     convertResponseStringEntryToInt(response, 6, numStrings);
   3689             rilCellIdentity.cellIdentityCdma.systemId =
   3690                     convertResponseStringEntryToInt(response, 8, numStrings);
   3691             rilCellIdentity.cellIdentityCdma.networkId =
   3692                     convertResponseStringEntryToInt(response, 9, numStrings);
   3693             break;
   3694         }
   3695 
   3696         case RIL_CELL_INFO_TYPE_LTE:{
   3697             /* valid TAC are hexstrings in the range 0x0000 - 0xffff */
   3698             rilCellIdentity.cellIdentityLte.tac =
   3699                     convertResponseHexStringEntryToInt(response, 1, numStrings);
   3700 
   3701             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
   3702             rilCellIdentity.cellIdentityLte.ci =
   3703                     convertResponseHexStringEntryToInt(response, 2, numStrings);
   3704             break;
   3705         }
   3706 
   3707         default: {
   3708             break;
   3709         }
   3710     }
   3711 
   3712     fillCellIdentityResponse(cellIdentity, rilCellIdentity);
   3713 }
   3714 
   3715 /* Fill Cell Identity info from Data Registration State Response.
   3716  * This fucntion is applicable only for RIL Version < 15.
   3717  * Response is a  "char **".
   3718  * First and Second entries are in hex string format
   3719  * and rest are integers represented in ascii format. */
   3720 void fillCellIdentityFromDataRegStateResponseString(CellIdentity &cellIdentity,
   3721         int numStrings, char** response) {
   3722 
   3723     RIL_CellIdentity_v16 rilCellIdentity;
   3724     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
   3725 
   3726     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
   3727     switch(rilCellIdentity.cellInfoType) {
   3728         case RIL_CELL_INFO_TYPE_GSM: {
   3729             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
   3730             rilCellIdentity.cellIdentityGsm.lac =
   3731                     convertResponseHexStringEntryToInt(response, 1, numStrings);
   3732 
   3733             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
   3734             rilCellIdentity.cellIdentityGsm.cid =
   3735                     convertResponseHexStringEntryToInt(response, 2, numStrings);
   3736             break;
   3737         }
   3738         case RIL_CELL_INFO_TYPE_WCDMA: {
   3739             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
   3740             rilCellIdentity.cellIdentityWcdma.lac =
   3741                     convertResponseHexStringEntryToInt(response, 1, numStrings);
   3742 
   3743             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
   3744             rilCellIdentity.cellIdentityWcdma.cid =
   3745                     convertResponseHexStringEntryToInt(response, 2, numStrings);
   3746             break;
   3747         }
   3748         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
   3749             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
   3750             rilCellIdentity.cellIdentityTdscdma.lac =
   3751                     convertResponseHexStringEntryToInt(response, 1, numStrings);
   3752 
   3753             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
   3754             rilCellIdentity.cellIdentityTdscdma.cid =
   3755                     convertResponseHexStringEntryToInt(response, 2, numStrings);
   3756             break;
   3757         }
   3758         case RIL_CELL_INFO_TYPE_LTE: {
   3759             rilCellIdentity.cellIdentityLte.tac =
   3760                     convertResponseStringEntryToInt(response, 6, numStrings);
   3761             rilCellIdentity.cellIdentityLte.pci =
   3762                     convertResponseStringEntryToInt(response, 7, numStrings);
   3763             rilCellIdentity.cellIdentityLte.ci =
   3764                     convertResponseStringEntryToInt(response, 8, numStrings);
   3765             break;
   3766         }
   3767         default: {
   3768             break;
   3769         }
   3770     }
   3771 
   3772     fillCellIdentityResponse(cellIdentity, rilCellIdentity);
   3773 }
   3774 
   3775 int radio::getVoiceRegistrationStateResponse(int slotId,
   3776                                             int responseType, int serial, RIL_Errno e,
   3777                                             void *response, size_t responseLen) {
   3778 #if VDBG
   3779     RLOGD("getVoiceRegistrationStateResponse: serial %d", serial);
   3780 #endif
   3781 
   3782     if (radioService[slotId]->mRadioResponse != NULL) {
   3783         RadioResponseInfo responseInfo = {};
   3784         populateResponseInfo(responseInfo, serial, responseType, e);
   3785 
   3786         VoiceRegStateResult voiceRegResponse = {};
   3787         int numStrings = responseLen / sizeof(char *);
   3788         if (response == NULL) {
   3789                RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
   3790                if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3791         } else if (s_vendorFunctions->version <= 14) {
   3792             if (numStrings != 15) {
   3793                 RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
   3794                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3795             } else {
   3796                 char **resp = (char **) response;
   3797                 voiceRegResponse.regState = (RegState) ATOI_NULL_HANDLED_DEF(resp[0], 4);
   3798                 voiceRegResponse.rat = ATOI_NULL_HANDLED(resp[3]);
   3799                 voiceRegResponse.cssSupported = ATOI_NULL_HANDLED_DEF(resp[7], 0);
   3800                 voiceRegResponse.roamingIndicator = ATOI_NULL_HANDLED(resp[10]);
   3801                 voiceRegResponse.systemIsInPrl = ATOI_NULL_HANDLED_DEF(resp[11], 0);
   3802                 voiceRegResponse.defaultRoamingIndicator = ATOI_NULL_HANDLED_DEF(resp[12], 0);
   3803                 voiceRegResponse.reasonForDenial = ATOI_NULL_HANDLED_DEF(resp[13], 0);
   3804                 fillCellIdentityFromVoiceRegStateResponseString(voiceRegResponse.cellIdentity,
   3805                         numStrings, resp);
   3806             }
   3807         } else {
   3808             RIL_VoiceRegistrationStateResponse *voiceRegState =
   3809                     (RIL_VoiceRegistrationStateResponse *)response;
   3810 
   3811             if (responseLen != sizeof(RIL_VoiceRegistrationStateResponse)) {
   3812                 RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
   3813                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3814             } else {
   3815                 voiceRegResponse.regState = (RegState) voiceRegState->regState;
   3816                 voiceRegResponse.rat = voiceRegState->rat;;
   3817                 voiceRegResponse.cssSupported = voiceRegState->cssSupported;
   3818                 voiceRegResponse.roamingIndicator = voiceRegState->roamingIndicator;
   3819                 voiceRegResponse.systemIsInPrl = voiceRegState->systemIsInPrl;
   3820                 voiceRegResponse.defaultRoamingIndicator = voiceRegState->defaultRoamingIndicator;
   3821                 voiceRegResponse.reasonForDenial = voiceRegState->reasonForDenial;
   3822                 fillCellIdentityResponse(voiceRegResponse.cellIdentity,
   3823                         voiceRegState->cellIdentity);
   3824             }
   3825         }
   3826 
   3827         Return<void> retStatus =
   3828                 radioService[slotId]->mRadioResponse->getVoiceRegistrationStateResponse(
   3829                 responseInfo, voiceRegResponse);
   3830         radioService[slotId]->checkReturnStatus(retStatus);
   3831     } else {
   3832         RLOGE("getVoiceRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
   3833                 slotId);
   3834     }
   3835 
   3836     return 0;
   3837 }
   3838 
   3839 int radio::getDataRegistrationStateResponse(int slotId,
   3840                                            int responseType, int serial, RIL_Errno e,
   3841                                            void *response, size_t responseLen) {
   3842 #if VDBG
   3843     RLOGD("getDataRegistrationStateResponse: serial %d", serial);
   3844 #endif
   3845 
   3846     if (radioService[slotId]->mRadioResponse != NULL) {
   3847         RadioResponseInfo responseInfo = {};
   3848         populateResponseInfo(responseInfo, serial, responseType, e);
   3849         DataRegStateResult dataRegResponse = {};
   3850         if (response == NULL) {
   3851             RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
   3852             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3853         } else if (s_vendorFunctions->version <= 14) {
   3854             int numStrings = responseLen / sizeof(char *);
   3855             if ((numStrings != 6) && (numStrings != 11)) {
   3856                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
   3857                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3858             } else {
   3859                 char **resp = (char **) response;
   3860                 dataRegResponse.regState = (RegState) ATOI_NULL_HANDLED_DEF(resp[0], 4);
   3861                 dataRegResponse.rat =  ATOI_NULL_HANDLED_DEF(resp[3], 0);
   3862                 dataRegResponse.reasonDataDenied =  ATOI_NULL_HANDLED(resp[4]);
   3863                 dataRegResponse.maxDataCalls =  ATOI_NULL_HANDLED_DEF(resp[5], 1);
   3864                 fillCellIdentityFromDataRegStateResponseString(dataRegResponse.cellIdentity,
   3865                         numStrings, resp);
   3866             }
   3867         } else {
   3868             RIL_DataRegistrationStateResponse *dataRegState =
   3869                     (RIL_DataRegistrationStateResponse *)response;
   3870 
   3871             if (responseLen != sizeof(RIL_DataRegistrationStateResponse)) {
   3872                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
   3873                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3874             } else {
   3875                 dataRegResponse.regState = (RegState) dataRegState->regState;
   3876                 dataRegResponse.rat = dataRegState->rat;;
   3877                 dataRegResponse.reasonDataDenied = dataRegState->reasonDataDenied;
   3878                 dataRegResponse.maxDataCalls = dataRegState->maxDataCalls;
   3879                 fillCellIdentityResponse(dataRegResponse.cellIdentity, dataRegState->cellIdentity);
   3880             }
   3881         }
   3882 
   3883         Return<void> retStatus =
   3884                 radioService[slotId]->mRadioResponse->getDataRegistrationStateResponse(responseInfo,
   3885                 dataRegResponse);
   3886         radioService[slotId]->checkReturnStatus(retStatus);
   3887     } else {
   3888         RLOGE("getDataRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
   3889                 slotId);
   3890     }
   3891 
   3892     return 0;
   3893 }
   3894 
   3895 int radio::getOperatorResponse(int slotId,
   3896                               int responseType, int serial, RIL_Errno e, void *response,
   3897                               size_t responseLen) {
   3898 #if VDBG
   3899     RLOGD("getOperatorResponse: serial %d", serial);
   3900 #endif
   3901 
   3902     if (radioService[slotId]->mRadioResponse != NULL) {
   3903         RadioResponseInfo responseInfo = {};
   3904         populateResponseInfo(responseInfo, serial, responseType, e);
   3905         hidl_string longName;
   3906         hidl_string shortName;
   3907         hidl_string numeric;
   3908         int numStrings = responseLen / sizeof(char *);
   3909         if (response == NULL || numStrings != 3) {
   3910             RLOGE("getOperatorResponse Invalid response: NULL");
   3911             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3912 
   3913         } else {
   3914             char **resp = (char **) response;
   3915             longName = convertCharPtrToHidlString(resp[0]);
   3916             shortName = convertCharPtrToHidlString(resp[1]);
   3917             numeric = convertCharPtrToHidlString(resp[2]);
   3918         }
   3919         Return<void> retStatus = radioService[slotId]->mRadioResponse->getOperatorResponse(
   3920                 responseInfo, longName, shortName, numeric);
   3921         radioService[slotId]->checkReturnStatus(retStatus);
   3922     } else {
   3923         RLOGE("getOperatorResponse: radioService[%d]->mRadioResponse == NULL",
   3924                 slotId);
   3925     }
   3926 
   3927     return 0;
   3928 }
   3929 
   3930 int radio::setRadioPowerResponse(int slotId,
   3931                                 int responseType, int serial, RIL_Errno e, void *response,
   3932                                 size_t responseLen) {
   3933     RLOGD("setRadioPowerResponse: serial %d", serial);
   3934 
   3935     if (radioService[slotId]->mRadioResponse != NULL) {
   3936         RadioResponseInfo responseInfo = {};
   3937         populateResponseInfo(responseInfo, serial, responseType, e);
   3938         Return<void> retStatus = radioService[slotId]->mRadioResponse->setRadioPowerResponse(
   3939                 responseInfo);
   3940         radioService[slotId]->checkReturnStatus(retStatus);
   3941     } else {
   3942         RLOGE("setRadioPowerResponse: radioService[%d]->mRadioResponse == NULL",
   3943                 slotId);
   3944     }
   3945 
   3946     return 0;
   3947 }
   3948 
   3949 int radio::sendDtmfResponse(int slotId,
   3950                            int responseType, int serial, RIL_Errno e, void *response,
   3951                            size_t responseLen) {
   3952 #if VDBG
   3953     RLOGD("sendDtmfResponse: serial %d", serial);
   3954 #endif
   3955 
   3956     if (radioService[slotId]->mRadioResponse != NULL) {
   3957         RadioResponseInfo responseInfo = {};
   3958         populateResponseInfo(responseInfo, serial, responseType, e);
   3959         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendDtmfResponse(
   3960                 responseInfo);
   3961         radioService[slotId]->checkReturnStatus(retStatus);
   3962     } else {
   3963         RLOGE("sendDtmfResponse: radioService[%d]->mRadioResponse == NULL",
   3964                 slotId);
   3965     }
   3966 
   3967     return 0;
   3968 }
   3969 
   3970 SendSmsResult makeSendSmsResult(RadioResponseInfo& responseInfo, int serial, int responseType,
   3971                                 RIL_Errno e, void *response, size_t responseLen) {
   3972     populateResponseInfo(responseInfo, serial, responseType, e);
   3973     SendSmsResult result = {};
   3974 
   3975     if (response == NULL || responseLen != sizeof(RIL_SMS_Response)) {
   3976         RLOGE("Invalid response: NULL");
   3977         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   3978         result.ackPDU = hidl_string();
   3979     } else {
   3980         RIL_SMS_Response *resp = (RIL_SMS_Response *) response;
   3981         result.messageRef = resp->messageRef;
   3982         result.ackPDU = convertCharPtrToHidlString(resp->ackPDU);
   3983         result.errorCode = resp->errorCode;
   3984     }
   3985     return result;
   3986 }
   3987 
   3988 int radio::sendSmsResponse(int slotId,
   3989                           int responseType, int serial, RIL_Errno e, void *response,
   3990                           size_t responseLen) {
   3991 #if VDBG
   3992     RLOGD("sendSmsResponse: serial %d", serial);
   3993 #endif
   3994 
   3995     if (radioService[slotId]->mRadioResponse != NULL) {
   3996         RadioResponseInfo responseInfo = {};
   3997         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
   3998                 responseLen);
   3999 
   4000         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendSmsResponse(responseInfo,
   4001                 result);
   4002         radioService[slotId]->checkReturnStatus(retStatus);
   4003     } else {
   4004         RLOGE("sendSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4005     }
   4006 
   4007     return 0;
   4008 }
   4009 
   4010 int radio::sendSMSExpectMoreResponse(int slotId,
   4011                                     int responseType, int serial, RIL_Errno e, void *response,
   4012                                     size_t responseLen) {
   4013 #if VDBG
   4014     RLOGD("sendSMSExpectMoreResponse: serial %d", serial);
   4015 #endif
   4016 
   4017     if (radioService[slotId]->mRadioResponse != NULL) {
   4018         RadioResponseInfo responseInfo = {};
   4019         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
   4020                 responseLen);
   4021 
   4022         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendSMSExpectMoreResponse(
   4023                 responseInfo, result);
   4024         radioService[slotId]->checkReturnStatus(retStatus);
   4025     } else {
   4026         RLOGE("sendSMSExpectMoreResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4027     }
   4028 
   4029     return 0;
   4030 }
   4031 
   4032 int radio::setupDataCallResponse(int slotId,
   4033                                  int responseType, int serial, RIL_Errno e, void *response,
   4034                                  size_t responseLen) {
   4035 #if VDBG
   4036     RLOGD("setupDataCallResponse: serial %d", serial);
   4037 #endif
   4038 
   4039     if (radioService[slotId]->mRadioResponse != NULL) {
   4040         RadioResponseInfo responseInfo = {};
   4041         populateResponseInfo(responseInfo, serial, responseType, e);
   4042 
   4043         SetupDataCallResult result = {};
   4044         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
   4045             if (response != NULL) {
   4046                 RLOGE("setupDataCallResponse: Invalid response");
   4047                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4048             }
   4049             result.status = DataCallFailCause::ERROR_UNSPECIFIED;
   4050             result.type = hidl_string();
   4051             result.ifname = hidl_string();
   4052             result.addresses = hidl_string();
   4053             result.dnses = hidl_string();
   4054             result.gateways = hidl_string();
   4055             result.pcscf = hidl_string();
   4056         } else {
   4057             convertRilDataCallToHal((RIL_Data_Call_Response_v11 *) response, result);
   4058         }
   4059 
   4060         Return<void> retStatus = radioService[slotId]->mRadioResponse->setupDataCallResponse(
   4061                 responseInfo, result);
   4062         radioService[slotId]->checkReturnStatus(retStatus);
   4063     } else {
   4064         RLOGE("setupDataCallResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4065     }
   4066 
   4067     return 0;
   4068 }
   4069 
   4070 IccIoResult responseIccIo(RadioResponseInfo& responseInfo, int serial, int responseType,
   4071                            RIL_Errno e, void *response, size_t responseLen) {
   4072     populateResponseInfo(responseInfo, serial, responseType, e);
   4073     IccIoResult result = {};
   4074 
   4075     if (response == NULL || responseLen != sizeof(RIL_SIM_IO_Response)) {
   4076         RLOGE("Invalid response: NULL");
   4077         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4078         result.simResponse = hidl_string();
   4079     } else {
   4080         RIL_SIM_IO_Response *resp = (RIL_SIM_IO_Response *) response;
   4081         result.sw1 = resp->sw1;
   4082         result.sw2 = resp->sw2;
   4083         result.simResponse = convertCharPtrToHidlString(resp->simResponse);
   4084     }
   4085     return result;
   4086 }
   4087 
   4088 int radio::iccIOForAppResponse(int slotId,
   4089                       int responseType, int serial, RIL_Errno e, void *response,
   4090                       size_t responseLen) {
   4091 #if VDBG
   4092     RLOGD("iccIOForAppResponse: serial %d", serial);
   4093 #endif
   4094 
   4095     if (radioService[slotId]->mRadioResponse != NULL) {
   4096         RadioResponseInfo responseInfo = {};
   4097         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
   4098                 responseLen);
   4099 
   4100         Return<void> retStatus = radioService[slotId]->mRadioResponse->iccIOForAppResponse(
   4101                 responseInfo, result);
   4102         radioService[slotId]->checkReturnStatus(retStatus);
   4103     } else {
   4104         RLOGE("iccIOForAppResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4105     }
   4106 
   4107     return 0;
   4108 }
   4109 
   4110 int radio::sendUssdResponse(int slotId,
   4111                            int responseType, int serial, RIL_Errno e, void *response,
   4112                            size_t responseLen) {
   4113 #if VDBG
   4114     RLOGD("sendUssdResponse: serial %d", serial);
   4115 #endif
   4116 
   4117     if (radioService[slotId]->mRadioResponse != NULL) {
   4118         RadioResponseInfo responseInfo = {};
   4119         populateResponseInfo(responseInfo, serial, responseType, e);
   4120         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendUssdResponse(
   4121                 responseInfo);
   4122         radioService[slotId]->checkReturnStatus(retStatus);
   4123     } else {
   4124         RLOGE("sendUssdResponse: radioService[%d]->mRadioResponse == NULL",
   4125                 slotId);
   4126     }
   4127 
   4128     return 0;
   4129 }
   4130 
   4131 int radio::cancelPendingUssdResponse(int slotId,
   4132                                     int responseType, int serial, RIL_Errno e, void *response,
   4133                                     size_t responseLen) {
   4134 #if VDBG
   4135     RLOGD("cancelPendingUssdResponse: serial %d", serial);
   4136 #endif
   4137 
   4138     if (radioService[slotId]->mRadioResponse != NULL) {
   4139         RadioResponseInfo responseInfo = {};
   4140         populateResponseInfo(responseInfo, serial, responseType, e);
   4141         Return<void> retStatus = radioService[slotId]->mRadioResponse->cancelPendingUssdResponse(
   4142                 responseInfo);
   4143         radioService[slotId]->checkReturnStatus(retStatus);
   4144     } else {
   4145         RLOGE("cancelPendingUssdResponse: radioService[%d]->mRadioResponse == NULL",
   4146                 slotId);
   4147     }
   4148 
   4149     return 0;
   4150 }
   4151 
   4152 int radio::getClirResponse(int slotId,
   4153                               int responseType, int serial, RIL_Errno e, void *response,
   4154                               size_t responseLen) {
   4155 #if VDBG
   4156     RLOGD("getClirResponse: serial %d", serial);
   4157 #endif
   4158 
   4159     if (radioService[slotId]->mRadioResponse != NULL) {
   4160         RadioResponseInfo responseInfo = {};
   4161         populateResponseInfo(responseInfo, serial, responseType, e);
   4162         int n = -1, m = -1;
   4163         int numInts = responseLen / sizeof(int);
   4164         if (response == NULL || numInts != 2) {
   4165             RLOGE("getClirResponse Invalid response: NULL");
   4166             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4167         } else {
   4168             int *pInt = (int *) response;
   4169             n = pInt[0];
   4170             m = pInt[1];
   4171         }
   4172         Return<void> retStatus = radioService[slotId]->mRadioResponse->getClirResponse(responseInfo,
   4173                 n, m);
   4174         radioService[slotId]->checkReturnStatus(retStatus);
   4175     } else {
   4176         RLOGE("getClirResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4177     }
   4178 
   4179     return 0;
   4180 }
   4181 
   4182 int radio::setClirResponse(int slotId,
   4183                           int responseType, int serial, RIL_Errno e, void *response,
   4184                           size_t responseLen) {
   4185 #if VDBG
   4186     RLOGD("setClirResponse: serial %d", serial);
   4187 #endif
   4188 
   4189     if (radioService[slotId]->mRadioResponse != NULL) {
   4190         RadioResponseInfo responseInfo = {};
   4191         populateResponseInfo(responseInfo, serial, responseType, e);
   4192         Return<void> retStatus = radioService[slotId]->mRadioResponse->setClirResponse(
   4193                 responseInfo);
   4194         radioService[slotId]->checkReturnStatus(retStatus);
   4195     } else {
   4196         RLOGE("setClirResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4197     }
   4198 
   4199     return 0;
   4200 }
   4201 
   4202 int radio::getCallForwardStatusResponse(int slotId,
   4203                                        int responseType, int serial, RIL_Errno e,
   4204                                        void *response, size_t responseLen) {
   4205 #if VDBG
   4206     RLOGD("getCallForwardStatusResponse: serial %d", serial);
   4207 #endif
   4208 
   4209     if (radioService[slotId]->mRadioResponse != NULL) {
   4210         RadioResponseInfo responseInfo = {};
   4211         populateResponseInfo(responseInfo, serial, responseType, e);
   4212         hidl_vec<CallForwardInfo> callForwardInfos;
   4213 
   4214         if ((response == NULL && responseLen != 0)
   4215                 || responseLen % sizeof(RIL_CallForwardInfo *) != 0) {
   4216             RLOGE("getCallForwardStatusResponse Invalid response: NULL");
   4217             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4218         } else {
   4219             int num = responseLen / sizeof(RIL_CallForwardInfo *);
   4220             callForwardInfos.resize(num);
   4221             for (int i = 0 ; i < num; i++) {
   4222                 RIL_CallForwardInfo *resp = ((RIL_CallForwardInfo **) response)[i];
   4223                 callForwardInfos[i].status = (CallForwardInfoStatus) resp->status;
   4224                 callForwardInfos[i].reason = resp->reason;
   4225                 callForwardInfos[i].serviceClass = resp->serviceClass;
   4226                 callForwardInfos[i].toa = resp->toa;
   4227                 callForwardInfos[i].number = convertCharPtrToHidlString(resp->number);
   4228                 callForwardInfos[i].timeSeconds = resp->timeSeconds;
   4229             }
   4230         }
   4231 
   4232         Return<void> retStatus = radioService[slotId]->mRadioResponse->getCallForwardStatusResponse(
   4233                 responseInfo, callForwardInfos);
   4234         radioService[slotId]->checkReturnStatus(retStatus);
   4235     } else {
   4236         RLOGE("getCallForwardStatusResponse: radioService[%d]->mRadioResponse == NULL",
   4237                 slotId);
   4238     }
   4239 
   4240     return 0;
   4241 }
   4242 
   4243 int radio::setCallForwardResponse(int slotId,
   4244                                  int responseType, int serial, RIL_Errno e, void *response,
   4245                                  size_t responseLen) {
   4246 #if VDBG
   4247     RLOGD("setCallForwardResponse: serial %d", serial);
   4248 #endif
   4249 
   4250     if (radioService[slotId]->mRadioResponse != NULL) {
   4251         RadioResponseInfo responseInfo = {};
   4252         populateResponseInfo(responseInfo, serial, responseType, e);
   4253         Return<void> retStatus = radioService[slotId]->mRadioResponse->setCallForwardResponse(
   4254                 responseInfo);
   4255         radioService[slotId]->checkReturnStatus(retStatus);
   4256     } else {
   4257         RLOGE("setCallForwardResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4258     }
   4259 
   4260     return 0;
   4261 }
   4262 
   4263 int radio::getCallWaitingResponse(int slotId,
   4264                                  int responseType, int serial, RIL_Errno e, void *response,
   4265                                  size_t responseLen) {
   4266 #if VDBG
   4267     RLOGD("getCallWaitingResponse: serial %d", serial);
   4268 #endif
   4269 
   4270     if (radioService[slotId]->mRadioResponse != NULL) {
   4271         RadioResponseInfo responseInfo = {};
   4272         populateResponseInfo(responseInfo, serial, responseType, e);
   4273         bool enable = false;
   4274         int serviceClass = -1;
   4275         int numInts = responseLen / sizeof(int);
   4276         if (response == NULL || numInts != 2) {
   4277             RLOGE("getCallWaitingResponse Invalid response: NULL");
   4278             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4279         } else {
   4280             int *pInt = (int *) response;
   4281             enable = pInt[0] == 1 ? true : false;
   4282             serviceClass = pInt[1];
   4283         }
   4284         Return<void> retStatus = radioService[slotId]->mRadioResponse->getCallWaitingResponse(
   4285                 responseInfo, enable, serviceClass);
   4286         radioService[slotId]->checkReturnStatus(retStatus);
   4287     } else {
   4288         RLOGE("getCallWaitingResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4289     }
   4290 
   4291     return 0;
   4292 }
   4293 
   4294 int radio::setCallWaitingResponse(int slotId,
   4295                                  int responseType, int serial, RIL_Errno e, void *response,
   4296                                  size_t responseLen) {
   4297 #if VDBG
   4298     RLOGD("setCallWaitingResponse: serial %d", serial);
   4299 #endif
   4300 
   4301     if (radioService[slotId]->mRadioResponse != NULL) {
   4302         RadioResponseInfo responseInfo = {};
   4303         populateResponseInfo(responseInfo, serial, responseType, e);
   4304         Return<void> retStatus = radioService[slotId]->mRadioResponse->setCallWaitingResponse(
   4305                 responseInfo);
   4306         radioService[slotId]->checkReturnStatus(retStatus);
   4307     } else {
   4308         RLOGE("setCallWaitingResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4309     }
   4310 
   4311     return 0;
   4312 }
   4313 
   4314 int radio::acknowledgeLastIncomingGsmSmsResponse(int slotId,
   4315                                                 int responseType, int serial, RIL_Errno e,
   4316                                                 void *response, size_t responseLen) {
   4317 #if VDBG
   4318     RLOGD("acknowledgeLastIncomingGsmSmsResponse: serial %d", serial);
   4319 #endif
   4320 
   4321     if (radioService[slotId]->mRadioResponse != NULL) {
   4322         RadioResponseInfo responseInfo = {};
   4323         populateResponseInfo(responseInfo, serial, responseType, e);
   4324         Return<void> retStatus =
   4325                 radioService[slotId]->mRadioResponse->acknowledgeLastIncomingGsmSmsResponse(
   4326                 responseInfo);
   4327         radioService[slotId]->checkReturnStatus(retStatus);
   4328     } else {
   4329         RLOGE("acknowledgeLastIncomingGsmSmsResponse: radioService[%d]->mRadioResponse "
   4330                 "== NULL", slotId);
   4331     }
   4332 
   4333     return 0;
   4334 }
   4335 
   4336 int radio::acceptCallResponse(int slotId,
   4337                              int responseType, int serial, RIL_Errno e,
   4338                              void *response, size_t responseLen) {
   4339 #if VDBG
   4340     RLOGD("acceptCallResponse: serial %d", serial);
   4341 #endif
   4342 
   4343     if (radioService[slotId]->mRadioResponse != NULL) {
   4344         RadioResponseInfo responseInfo = {};
   4345         populateResponseInfo(responseInfo, serial, responseType, e);
   4346         Return<void> retStatus = radioService[slotId]->mRadioResponse->acceptCallResponse(
   4347                 responseInfo);
   4348         radioService[slotId]->checkReturnStatus(retStatus);
   4349     } else {
   4350         RLOGE("acceptCallResponse: radioService[%d]->mRadioResponse == NULL",
   4351                 slotId);
   4352     }
   4353 
   4354     return 0;
   4355 }
   4356 
   4357 int radio::deactivateDataCallResponse(int slotId,
   4358                                                 int responseType, int serial, RIL_Errno e,
   4359                                                 void *response, size_t responseLen) {
   4360 #if VDBG
   4361     RLOGD("deactivateDataCallResponse: serial %d", serial);
   4362 #endif
   4363 
   4364     if (radioService[slotId]->mRadioResponse != NULL) {
   4365         RadioResponseInfo responseInfo = {};
   4366         populateResponseInfo(responseInfo, serial, responseType, e);
   4367         Return<void> retStatus = radioService[slotId]->mRadioResponse->deactivateDataCallResponse(
   4368                 responseInfo);
   4369         radioService[slotId]->checkReturnStatus(retStatus);
   4370     } else {
   4371         RLOGE("deactivateDataCallResponse: radioService[%d]->mRadioResponse == NULL",
   4372                 slotId);
   4373     }
   4374 
   4375     return 0;
   4376 }
   4377 
   4378 int radio::getFacilityLockForAppResponse(int slotId,
   4379                                         int responseType, int serial, RIL_Errno e,
   4380                                         void *response, size_t responseLen) {
   4381 #if VDBG
   4382     RLOGD("getFacilityLockForAppResponse: serial %d", serial);
   4383 #endif
   4384 
   4385     if (radioService[slotId]->mRadioResponse != NULL) {
   4386         RadioResponseInfo responseInfo = {};
   4387         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   4388         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   4389                 getFacilityLockForAppResponse(responseInfo, ret);
   4390         radioService[slotId]->checkReturnStatus(retStatus);
   4391     } else {
   4392         RLOGE("getFacilityLockForAppResponse: radioService[%d]->mRadioResponse == NULL",
   4393                 slotId);
   4394     }
   4395 
   4396     return 0;
   4397 }
   4398 
   4399 int radio::setFacilityLockForAppResponse(int slotId,
   4400                                       int responseType, int serial, RIL_Errno e,
   4401                                       void *response, size_t responseLen) {
   4402 #if VDBG
   4403     RLOGD("setFacilityLockForAppResponse: serial %d", serial);
   4404 #endif
   4405 
   4406     if (radioService[slotId]->mRadioResponse != NULL) {
   4407         RadioResponseInfo responseInfo = {};
   4408         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
   4409         Return<void> retStatus
   4410                 = radioService[slotId]->mRadioResponse->setFacilityLockForAppResponse(responseInfo,
   4411                 ret);
   4412         radioService[slotId]->checkReturnStatus(retStatus);
   4413     } else {
   4414         RLOGE("setFacilityLockForAppResponse: radioService[%d]->mRadioResponse == NULL",
   4415                 slotId);
   4416     }
   4417 
   4418     return 0;
   4419 }
   4420 
   4421 int radio::setBarringPasswordResponse(int slotId,
   4422                              int responseType, int serial, RIL_Errno e,
   4423                              void *response, size_t responseLen) {
   4424 #if VDBG
   4425     RLOGD("acceptCallResponse: serial %d", serial);
   4426 #endif
   4427 
   4428     if (radioService[slotId]->mRadioResponse != NULL) {
   4429         RadioResponseInfo responseInfo = {};
   4430         populateResponseInfo(responseInfo, serial, responseType, e);
   4431         Return<void> retStatus
   4432                 = radioService[slotId]->mRadioResponse->setBarringPasswordResponse(responseInfo);
   4433         radioService[slotId]->checkReturnStatus(retStatus);
   4434     } else {
   4435         RLOGE("setBarringPasswordResponse: radioService[%d]->mRadioResponse == NULL",
   4436                 slotId);
   4437     }
   4438 
   4439     return 0;
   4440 }
   4441 
   4442 int radio::getNetworkSelectionModeResponse(int slotId,
   4443                                           int responseType, int serial, RIL_Errno e, void *response,
   4444                                           size_t responseLen) {
   4445 #if VDBG
   4446     RLOGD("getNetworkSelectionModeResponse: serial %d", serial);
   4447 #endif
   4448 
   4449     if (radioService[slotId]->mRadioResponse != NULL) {
   4450         RadioResponseInfo responseInfo = {};
   4451         populateResponseInfo(responseInfo, serial, responseType, e);
   4452         bool manual = false;
   4453         if (response == NULL || responseLen != sizeof(int)) {
   4454             RLOGE("getNetworkSelectionModeResponse Invalid response: NULL");
   4455             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4456         } else {
   4457             int *pInt = (int *) response;
   4458             manual = pInt[0] == 1 ? true : false;
   4459         }
   4460         Return<void> retStatus
   4461                 = radioService[slotId]->mRadioResponse->getNetworkSelectionModeResponse(
   4462                 responseInfo,
   4463                 manual);
   4464         radioService[slotId]->checkReturnStatus(retStatus);
   4465     } else {
   4466         RLOGE("getNetworkSelectionModeResponse: radioService[%d]->mRadioResponse == NULL",
   4467                 slotId);
   4468     }
   4469 
   4470     return 0;
   4471 }
   4472 
   4473 int radio::setNetworkSelectionModeAutomaticResponse(int slotId, int responseType, int serial,
   4474                                                     RIL_Errno e, void *response,
   4475                                                     size_t responseLen) {
   4476 #if VDBG
   4477     RLOGD("setNetworkSelectionModeAutomaticResponse: serial %d", serial);
   4478 #endif
   4479 
   4480     if (radioService[slotId]->mRadioResponse != NULL) {
   4481         RadioResponseInfo responseInfo = {};
   4482         populateResponseInfo(responseInfo, serial, responseType, e);
   4483         Return<void> retStatus
   4484                 = radioService[slotId]->mRadioResponse->setNetworkSelectionModeAutomaticResponse(
   4485                 responseInfo);
   4486         radioService[slotId]->checkReturnStatus(retStatus);
   4487     } else {
   4488         RLOGE("setNetworkSelectionModeAutomaticResponse: radioService[%d]->mRadioResponse "
   4489                 "== NULL", slotId);
   4490     }
   4491 
   4492     return 0;
   4493 }
   4494 
   4495 int radio::setNetworkSelectionModeManualResponse(int slotId,
   4496                              int responseType, int serial, RIL_Errno e,
   4497                              void *response, size_t responseLen) {
   4498 #if VDBG
   4499     RLOGD("setNetworkSelectionModeManualResponse: serial %d", serial);
   4500 #endif
   4501 
   4502     if (radioService[slotId]->mRadioResponse != NULL) {
   4503         RadioResponseInfo responseInfo = {};
   4504         populateResponseInfo(responseInfo, serial, responseType, e);
   4505         Return<void> retStatus
   4506                 = radioService[slotId]->mRadioResponse->setNetworkSelectionModeManualResponse(
   4507                 responseInfo);
   4508         radioService[slotId]->checkReturnStatus(retStatus);
   4509     } else {
   4510         RLOGE("acceptCallResponse: radioService[%d]->setNetworkSelectionModeManualResponse "
   4511                 "== NULL", slotId);
   4512     }
   4513 
   4514     return 0;
   4515 }
   4516 
   4517 int convertOperatorStatusToInt(const char *str) {
   4518     if (strncmp("unknown", str, 9) == 0) {
   4519         return (int) OperatorStatus::UNKNOWN;
   4520     } else if (strncmp("available", str, 9) == 0) {
   4521         return (int) OperatorStatus::AVAILABLE;
   4522     } else if (strncmp("current", str, 9) == 0) {
   4523         return (int) OperatorStatus::CURRENT;
   4524     } else if (strncmp("forbidden", str, 9) == 0) {
   4525         return (int) OperatorStatus::FORBIDDEN;
   4526     } else {
   4527         return -1;
   4528     }
   4529 }
   4530 
   4531 int radio::getAvailableNetworksResponse(int slotId,
   4532                               int responseType, int serial, RIL_Errno e, void *response,
   4533                               size_t responseLen) {
   4534 #if VDBG
   4535     RLOGD("getAvailableNetworksResponse: serial %d", serial);
   4536 #endif
   4537 
   4538     if (radioService[slotId]->mRadioResponse != NULL) {
   4539         RadioResponseInfo responseInfo = {};
   4540         populateResponseInfo(responseInfo, serial, responseType, e);
   4541         hidl_vec<OperatorInfo> networks;
   4542         if ((response == NULL && responseLen != 0)
   4543                 || responseLen % (4 * sizeof(char *))!= 0) {
   4544             RLOGE("getAvailableNetworksResponse Invalid response: NULL");
   4545             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4546         } else {
   4547             char **resp = (char **) response;
   4548             int numStrings = responseLen / sizeof(char *);
   4549             networks.resize(numStrings/4);
   4550             for (int i = 0, j = 0; i < numStrings; i = i + 4, j++) {
   4551                 networks[j].alphaLong = convertCharPtrToHidlString(resp[i]);
   4552                 networks[j].alphaShort = convertCharPtrToHidlString(resp[i + 1]);
   4553                 networks[j].operatorNumeric = convertCharPtrToHidlString(resp[i + 2]);
   4554                 int status = convertOperatorStatusToInt(resp[i + 3]);
   4555                 if (status == -1) {
   4556                     if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4557                 } else {
   4558                     networks[j].status = (OperatorStatus) status;
   4559                 }
   4560             }
   4561         }
   4562         Return<void> retStatus
   4563                 = radioService[slotId]->mRadioResponse->getAvailableNetworksResponse(responseInfo,
   4564                 networks);
   4565         radioService[slotId]->checkReturnStatus(retStatus);
   4566     } else {
   4567         RLOGE("getAvailableNetworksResponse: radioService[%d]->mRadioResponse == NULL",
   4568                 slotId);
   4569     }
   4570 
   4571     return 0;
   4572 }
   4573 
   4574 int radio::startDtmfResponse(int slotId,
   4575                             int responseType, int serial, RIL_Errno e,
   4576                             void *response, size_t responseLen) {
   4577 #if VDBG
   4578     RLOGD("startDtmfResponse: serial %d", serial);
   4579 #endif
   4580 
   4581     if (radioService[slotId]->mRadioResponse != NULL) {
   4582         RadioResponseInfo responseInfo = {};
   4583         populateResponseInfo(responseInfo, serial, responseType, e);
   4584         Return<void> retStatus
   4585                 = radioService[slotId]->mRadioResponse->startDtmfResponse(responseInfo);
   4586         radioService[slotId]->checkReturnStatus(retStatus);
   4587     } else {
   4588         RLOGE("startDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4589     }
   4590 
   4591     return 0;
   4592 }
   4593 
   4594 int radio::stopDtmfResponse(int slotId,
   4595                            int responseType, int serial, RIL_Errno e,
   4596                            void *response, size_t responseLen) {
   4597 #if VDBG
   4598     RLOGD("stopDtmfResponse: serial %d", serial);
   4599 #endif
   4600 
   4601     if (radioService[slotId]->mRadioResponse != NULL) {
   4602         RadioResponseInfo responseInfo = {};
   4603         populateResponseInfo(responseInfo, serial, responseType, e);
   4604         Return<void> retStatus
   4605                 = radioService[slotId]->mRadioResponse->stopDtmfResponse(responseInfo);
   4606         radioService[slotId]->checkReturnStatus(retStatus);
   4607     } else {
   4608         RLOGE("stopDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4609     }
   4610 
   4611     return 0;
   4612 }
   4613 
   4614 int radio::getBasebandVersionResponse(int slotId,
   4615                                      int responseType, int serial, RIL_Errno e,
   4616                                      void *response, size_t responseLen) {
   4617 #if VDBG
   4618     RLOGD("getBasebandVersionResponse: serial %d", serial);
   4619 #endif
   4620 
   4621     if (radioService[slotId]->mRadioResponse != NULL) {
   4622         RadioResponseInfo responseInfo = {};
   4623         populateResponseInfo(responseInfo, serial, responseType, e);
   4624         Return<void> retStatus
   4625                 = radioService[slotId]->mRadioResponse->getBasebandVersionResponse(responseInfo,
   4626                 convertCharPtrToHidlString((char *) response));
   4627         radioService[slotId]->checkReturnStatus(retStatus);
   4628     } else {
   4629         RLOGE("getBasebandVersionResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4630     }
   4631 
   4632     return 0;
   4633 }
   4634 
   4635 int radio::separateConnectionResponse(int slotId,
   4636                                      int responseType, int serial, RIL_Errno e,
   4637                                      void *response, size_t responseLen) {
   4638 #if VDBG
   4639     RLOGD("separateConnectionResponse: serial %d", serial);
   4640 #endif
   4641 
   4642     if (radioService[slotId]->mRadioResponse != NULL) {
   4643         RadioResponseInfo responseInfo = {};
   4644         populateResponseInfo(responseInfo, serial, responseType, e);
   4645         Return<void> retStatus
   4646                 = radioService[slotId]->mRadioResponse->separateConnectionResponse(responseInfo);
   4647         radioService[slotId]->checkReturnStatus(retStatus);
   4648     } else {
   4649         RLOGE("separateConnectionResponse: radioService[%d]->mRadioResponse == NULL",
   4650                 slotId);
   4651     }
   4652 
   4653     return 0;
   4654 }
   4655 
   4656 int radio::setMuteResponse(int slotId,
   4657                           int responseType, int serial, RIL_Errno e,
   4658                           void *response, size_t responseLen) {
   4659 #if VDBG
   4660     RLOGD("setMuteResponse: serial %d", serial);
   4661 #endif
   4662 
   4663     if (radioService[slotId]->mRadioResponse != NULL) {
   4664         RadioResponseInfo responseInfo = {};
   4665         populateResponseInfo(responseInfo, serial, responseType, e);
   4666         Return<void> retStatus
   4667                 = radioService[slotId]->mRadioResponse->setMuteResponse(responseInfo);
   4668         radioService[slotId]->checkReturnStatus(retStatus);
   4669     } else {
   4670         RLOGE("setMuteResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4671     }
   4672 
   4673     return 0;
   4674 }
   4675 
   4676 int radio::getMuteResponse(int slotId,
   4677                           int responseType, int serial, RIL_Errno e, void *response,
   4678                           size_t responseLen) {
   4679 #if VDBG
   4680     RLOGD("getMuteResponse: serial %d", serial);
   4681 #endif
   4682 
   4683     if (radioService[slotId]->mRadioResponse != NULL) {
   4684         RadioResponseInfo responseInfo = {};
   4685         populateResponseInfo(responseInfo, serial, responseType, e);
   4686         bool enable = false;
   4687         if (response == NULL || responseLen != sizeof(int)) {
   4688             RLOGE("getMuteResponse Invalid response: NULL");
   4689             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4690         } else {
   4691             int *pInt = (int *) response;
   4692             enable = pInt[0] == 1 ? true : false;
   4693         }
   4694         Return<void> retStatus = radioService[slotId]->mRadioResponse->getMuteResponse(responseInfo,
   4695                 enable);
   4696         radioService[slotId]->checkReturnStatus(retStatus);
   4697     } else {
   4698         RLOGE("getMuteResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4699     }
   4700 
   4701     return 0;
   4702 }
   4703 
   4704 int radio::getClipResponse(int slotId,
   4705                           int responseType, int serial, RIL_Errno e,
   4706                           void *response, size_t responseLen) {
   4707 #if VDBG
   4708     RLOGD("getClipResponse: serial %d", serial);
   4709 #endif
   4710 
   4711     if (radioService[slotId]->mRadioResponse != NULL) {
   4712         RadioResponseInfo responseInfo = {};
   4713         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   4714         Return<void> retStatus = radioService[slotId]->mRadioResponse->getClipResponse(responseInfo,
   4715                 (ClipStatus) ret);
   4716         radioService[slotId]->checkReturnStatus(retStatus);
   4717     } else {
   4718         RLOGE("getClipResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4719     }
   4720 
   4721     return 0;
   4722 }
   4723 
   4724 int radio::getDataCallListResponse(int slotId,
   4725                                    int responseType, int serial, RIL_Errno e,
   4726                                    void *response, size_t responseLen) {
   4727 #if VDBG
   4728     RLOGD("getDataCallListResponse: serial %d", serial);
   4729 #endif
   4730 
   4731     if (radioService[slotId]->mRadioResponse != NULL) {
   4732         RadioResponseInfo responseInfo = {};
   4733         populateResponseInfo(responseInfo, serial, responseType, e);
   4734 
   4735         hidl_vec<SetupDataCallResult> ret;
   4736         if ((response == NULL && responseLen != 0)
   4737                 || responseLen % sizeof(RIL_Data_Call_Response_v11) != 0) {
   4738             RLOGE("getDataCallListResponse: invalid response");
   4739             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4740         } else {
   4741             convertRilDataCallListToHal(response, responseLen, ret);
   4742         }
   4743 
   4744         Return<void> retStatus = radioService[slotId]->mRadioResponse->getDataCallListResponse(
   4745                 responseInfo, ret);
   4746         radioService[slotId]->checkReturnStatus(retStatus);
   4747     } else {
   4748         RLOGE("getDataCallListResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4749     }
   4750 
   4751     return 0;
   4752 }
   4753 
   4754 int radio::setSuppServiceNotificationsResponse(int slotId,
   4755                                               int responseType, int serial, RIL_Errno e,
   4756                                               void *response, size_t responseLen) {
   4757 #if VDBG
   4758     RLOGD("setSuppServiceNotificationsResponse: serial %d", serial);
   4759 #endif
   4760 
   4761     if (radioService[slotId]->mRadioResponse != NULL) {
   4762         RadioResponseInfo responseInfo = {};
   4763         populateResponseInfo(responseInfo, serial, responseType, e);
   4764         Return<void> retStatus
   4765                 = radioService[slotId]->mRadioResponse->setSuppServiceNotificationsResponse(
   4766                 responseInfo);
   4767         radioService[slotId]->checkReturnStatus(retStatus);
   4768     } else {
   4769         RLOGE("setSuppServiceNotificationsResponse: radioService[%d]->mRadioResponse "
   4770                 "== NULL", slotId);
   4771     }
   4772 
   4773     return 0;
   4774 }
   4775 
   4776 int radio::deleteSmsOnSimResponse(int slotId,
   4777                                  int responseType, int serial, RIL_Errno e,
   4778                                  void *response, size_t responseLen) {
   4779 #if VDBG
   4780     RLOGD("deleteSmsOnSimResponse: serial %d", serial);
   4781 #endif
   4782 
   4783     if (radioService[slotId]->mRadioResponse != NULL) {
   4784         RadioResponseInfo responseInfo = {};
   4785         populateResponseInfo(responseInfo, serial, responseType, e);
   4786         Return<void> retStatus
   4787                 = radioService[slotId]->mRadioResponse->deleteSmsOnSimResponse(responseInfo);
   4788         radioService[slotId]->checkReturnStatus(retStatus);
   4789     } else {
   4790         RLOGE("deleteSmsOnSimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4791     }
   4792 
   4793     return 0;
   4794 }
   4795 
   4796 int radio::setBandModeResponse(int slotId,
   4797                               int responseType, int serial, RIL_Errno e,
   4798                               void *response, size_t responseLen) {
   4799 #if VDBG
   4800     RLOGD("setBandModeResponse: serial %d", serial);
   4801 #endif
   4802 
   4803     if (radioService[slotId]->mRadioResponse != NULL) {
   4804         RadioResponseInfo responseInfo = {};
   4805         populateResponseInfo(responseInfo, serial, responseType, e);
   4806         Return<void> retStatus
   4807                 = radioService[slotId]->mRadioResponse->setBandModeResponse(responseInfo);
   4808         radioService[slotId]->checkReturnStatus(retStatus);
   4809     } else {
   4810         RLOGE("setBandModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4811     }
   4812 
   4813     return 0;
   4814 }
   4815 
   4816 int radio::writeSmsToSimResponse(int slotId,
   4817                                 int responseType, int serial, RIL_Errno e,
   4818                                 void *response, size_t responseLen) {
   4819 #if VDBG
   4820     RLOGD("writeSmsToSimResponse: serial %d", serial);
   4821 #endif
   4822 
   4823     if (radioService[slotId]->mRadioResponse != NULL) {
   4824         RadioResponseInfo responseInfo = {};
   4825         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   4826         Return<void> retStatus
   4827                 = radioService[slotId]->mRadioResponse->writeSmsToSimResponse(responseInfo, ret);
   4828         radioService[slotId]->checkReturnStatus(retStatus);
   4829     } else {
   4830         RLOGE("writeSmsToSimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4831     }
   4832 
   4833     return 0;
   4834 }
   4835 
   4836 int radio::getAvailableBandModesResponse(int slotId,
   4837                                         int responseType, int serial, RIL_Errno e, void *response,
   4838                                         size_t responseLen) {
   4839 #if VDBG
   4840     RLOGD("getAvailableBandModesResponse: serial %d", serial);
   4841 #endif
   4842 
   4843     if (radioService[slotId]->mRadioResponse != NULL) {
   4844         RadioResponseInfo responseInfo = {};
   4845         populateResponseInfo(responseInfo, serial, responseType, e);
   4846         hidl_vec<RadioBandMode> modes;
   4847         if ((response == NULL && responseLen != 0)|| responseLen % sizeof(int) != 0) {
   4848             RLOGE("getAvailableBandModesResponse Invalid response: NULL");
   4849             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   4850         } else {
   4851             int *pInt = (int *) response;
   4852             int numInts = responseLen / sizeof(int);
   4853             modes.resize(numInts);
   4854             for (int i = 0; i < numInts; i++) {
   4855                 modes[i] = (RadioBandMode) pInt[i];
   4856             }
   4857         }
   4858         Return<void> retStatus
   4859                 = radioService[slotId]->mRadioResponse->getAvailableBandModesResponse(responseInfo,
   4860                 modes);
   4861         radioService[slotId]->checkReturnStatus(retStatus);
   4862     } else {
   4863         RLOGE("getAvailableBandModesResponse: radioService[%d]->mRadioResponse == NULL",
   4864                 slotId);
   4865     }
   4866 
   4867     return 0;
   4868 }
   4869 
   4870 int radio::sendEnvelopeResponse(int slotId,
   4871                                int responseType, int serial, RIL_Errno e,
   4872                                void *response, size_t responseLen) {
   4873 #if VDBG
   4874     RLOGD("sendEnvelopeResponse: serial %d", serial);
   4875 #endif
   4876 
   4877     if (radioService[slotId]->mRadioResponse != NULL) {
   4878         RadioResponseInfo responseInfo = {};
   4879         populateResponseInfo(responseInfo, serial, responseType, e);
   4880         Return<void> retStatus
   4881                 = radioService[slotId]->mRadioResponse->sendEnvelopeResponse(responseInfo,
   4882                 convertCharPtrToHidlString((char *) response));
   4883         radioService[slotId]->checkReturnStatus(retStatus);
   4884     } else {
   4885         RLOGE("sendEnvelopeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   4886     }
   4887 
   4888     return 0;
   4889 }
   4890 
   4891 int radio::sendTerminalResponseToSimResponse(int slotId,
   4892                                             int responseType, int serial, RIL_Errno e,
   4893                                             void *response, size_t responseLen) {
   4894 #if VDBG
   4895     RLOGD("sendTerminalResponseToSimResponse: serial %d", serial);
   4896 #endif
   4897 
   4898     if (radioService[slotId]->mRadioResponse != NULL) {
   4899         RadioResponseInfo responseInfo = {};
   4900         populateResponseInfo(responseInfo, serial, responseType, e);
   4901         Return<void> retStatus
   4902                 = radioService[slotId]->mRadioResponse->sendTerminalResponseToSimResponse(
   4903                 responseInfo);
   4904         radioService[slotId]->checkReturnStatus(retStatus);
   4905     } else {
   4906         RLOGE("sendTerminalResponseToSimResponse: radioService[%d]->mRadioResponse == NULL",
   4907                 slotId);
   4908     }
   4909 
   4910     return 0;
   4911 }
   4912 
   4913 int radio::handleStkCallSetupRequestFromSimResponse(int slotId,
   4914                                                    int responseType, int serial,
   4915                                                    RIL_Errno e, void *response,
   4916                                                    size_t responseLen) {
   4917 #if VDBG
   4918     RLOGD("handleStkCallSetupRequestFromSimResponse: serial %d", serial);
   4919 #endif
   4920 
   4921     if (radioService[slotId]->mRadioResponse != NULL) {
   4922         RadioResponseInfo responseInfo = {};
   4923         populateResponseInfo(responseInfo, serial, responseType, e);
   4924         Return<void> retStatus
   4925                 = radioService[slotId]->mRadioResponse->handleStkCallSetupRequestFromSimResponse(
   4926                 responseInfo);
   4927         radioService[slotId]->checkReturnStatus(retStatus);
   4928     } else {
   4929         RLOGE("handleStkCallSetupRequestFromSimResponse: radioService[%d]->mRadioResponse "
   4930                 "== NULL", slotId);
   4931     }
   4932 
   4933     return 0;
   4934 }
   4935 
   4936 int radio::explicitCallTransferResponse(int slotId,
   4937                                        int responseType, int serial, RIL_Errno e,
   4938                                        void *response, size_t responseLen) {
   4939 #if VDBG
   4940     RLOGD("explicitCallTransferResponse: serial %d", serial);
   4941 #endif
   4942 
   4943     if (radioService[slotId]->mRadioResponse != NULL) {
   4944         RadioResponseInfo responseInfo = {};
   4945         populateResponseInfo(responseInfo, serial, responseType, e);
   4946         Return<void> retStatus
   4947                 = radioService[slotId]->mRadioResponse->explicitCallTransferResponse(responseInfo);
   4948         radioService[slotId]->checkReturnStatus(retStatus);
   4949     } else {
   4950         RLOGE("explicitCallTransferResponse: radioService[%d]->mRadioResponse == NULL",
   4951                 slotId);
   4952     }
   4953 
   4954     return 0;
   4955 }
   4956 
   4957 int radio::setPreferredNetworkTypeResponse(int slotId,
   4958                                  int responseType, int serial, RIL_Errno e,
   4959                                  void *response, size_t responseLen) {
   4960 #if VDBG
   4961     RLOGD("setPreferredNetworkTypeResponse: serial %d", serial);
   4962 #endif
   4963 
   4964     if (radioService[slotId]->mRadioResponse != NULL) {
   4965         RadioResponseInfo responseInfo = {};
   4966         populateResponseInfo(responseInfo, serial, responseType, e);
   4967         Return<void> retStatus
   4968                 = radioService[slotId]->mRadioResponse->setPreferredNetworkTypeResponse(
   4969                 responseInfo);
   4970         radioService[slotId]->checkReturnStatus(retStatus);
   4971     } else {
   4972         RLOGE("setPreferredNetworkTypeResponse: radioService[%d]->mRadioResponse == NULL",
   4973                 slotId);
   4974     }
   4975 
   4976     return 0;
   4977 }
   4978 
   4979 
   4980 int radio::getPreferredNetworkTypeResponse(int slotId,
   4981                                           int responseType, int serial, RIL_Errno e,
   4982                                           void *response, size_t responseLen) {
   4983 #if VDBG
   4984     RLOGD("getPreferredNetworkTypeResponse: serial %d", serial);
   4985 #endif
   4986 
   4987     if (radioService[slotId]->mRadioResponse != NULL) {
   4988         RadioResponseInfo responseInfo = {};
   4989         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   4990         Return<void> retStatus
   4991                 = radioService[slotId]->mRadioResponse->getPreferredNetworkTypeResponse(
   4992                 responseInfo, (PreferredNetworkType) ret);
   4993         radioService[slotId]->checkReturnStatus(retStatus);
   4994     } else {
   4995         RLOGE("getPreferredNetworkTypeResponse: radioService[%d]->mRadioResponse == NULL",
   4996                 slotId);
   4997     }
   4998 
   4999     return 0;
   5000 }
   5001 
   5002 int radio::getNeighboringCidsResponse(int slotId,
   5003                                      int responseType, int serial, RIL_Errno e,
   5004                                      void *response, size_t responseLen) {
   5005 #if VDBG
   5006     RLOGD("getNeighboringCidsResponse: serial %d", serial);
   5007 #endif
   5008 
   5009     if (radioService[slotId]->mRadioResponse != NULL) {
   5010         RadioResponseInfo responseInfo = {};
   5011         populateResponseInfo(responseInfo, serial, responseType, e);
   5012         hidl_vec<NeighboringCell> cells;
   5013 
   5014         if ((response == NULL && responseLen != 0)
   5015                 || responseLen % sizeof(RIL_NeighboringCell *) != 0) {
   5016             RLOGE("getNeighboringCidsResponse Invalid response: NULL");
   5017             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5018         } else {
   5019             int num = responseLen / sizeof(RIL_NeighboringCell *);
   5020             cells.resize(num);
   5021             for (int i = 0 ; i < num; i++) {
   5022                 RIL_NeighboringCell *resp = ((RIL_NeighboringCell **) response)[i];
   5023                 cells[i].cid = convertCharPtrToHidlString(resp->cid);
   5024                 cells[i].rssi = resp->rssi;
   5025             }
   5026         }
   5027 
   5028         Return<void> retStatus
   5029                 = radioService[slotId]->mRadioResponse->getNeighboringCidsResponse(responseInfo,
   5030                 cells);
   5031         radioService[slotId]->checkReturnStatus(retStatus);
   5032     } else {
   5033         RLOGE("getNeighboringCidsResponse: radioService[%d]->mRadioResponse == NULL",
   5034                 slotId);
   5035     }
   5036 
   5037     return 0;
   5038 }
   5039 
   5040 int radio::setLocationUpdatesResponse(int slotId,
   5041                                      int responseType, int serial, RIL_Errno e,
   5042                                      void *response, size_t responseLen) {
   5043 #if VDBG
   5044     RLOGD("setLocationUpdatesResponse: serial %d", serial);
   5045 #endif
   5046 
   5047     if (radioService[slotId]->mRadioResponse != NULL) {
   5048         RadioResponseInfo responseInfo = {};
   5049         populateResponseInfo(responseInfo, serial, responseType, e);
   5050         Return<void> retStatus
   5051                 = radioService[slotId]->mRadioResponse->setLocationUpdatesResponse(responseInfo);
   5052         radioService[slotId]->checkReturnStatus(retStatus);
   5053     } else {
   5054         RLOGE("setLocationUpdatesResponse: radioService[%d]->mRadioResponse == NULL",
   5055                 slotId);
   5056     }
   5057 
   5058     return 0;
   5059 }
   5060 
   5061 int radio::setCdmaSubscriptionSourceResponse(int slotId,
   5062                                  int responseType, int serial, RIL_Errno e,
   5063                                  void *response, size_t responseLen) {
   5064 #if VDBG
   5065     RLOGD("setCdmaSubscriptionSourceResponse: serial %d", serial);
   5066 #endif
   5067 
   5068     if (radioService[slotId]->mRadioResponse != NULL) {
   5069         RadioResponseInfo responseInfo = {};
   5070         populateResponseInfo(responseInfo, serial, responseType, e);
   5071         Return<void> retStatus
   5072                 = radioService[slotId]->mRadioResponse->setCdmaSubscriptionSourceResponse(
   5073                 responseInfo);
   5074         radioService[slotId]->checkReturnStatus(retStatus);
   5075     } else {
   5076         RLOGE("setCdmaSubscriptionSourceResponse: radioService[%d]->mRadioResponse == NULL",
   5077                 slotId);
   5078     }
   5079 
   5080     return 0;
   5081 }
   5082 
   5083 int radio::setCdmaRoamingPreferenceResponse(int slotId,
   5084                                  int responseType, int serial, RIL_Errno e,
   5085                                  void *response, size_t responseLen) {
   5086 #if VDBG
   5087     RLOGD("setCdmaRoamingPreferenceResponse: serial %d", serial);
   5088 #endif
   5089 
   5090     if (radioService[slotId]->mRadioResponse != NULL) {
   5091         RadioResponseInfo responseInfo = {};
   5092         populateResponseInfo(responseInfo, serial, responseType, e);
   5093         Return<void> retStatus
   5094                 = radioService[slotId]->mRadioResponse->setCdmaRoamingPreferenceResponse(
   5095                 responseInfo);
   5096         radioService[slotId]->checkReturnStatus(retStatus);
   5097     } else {
   5098         RLOGE("setCdmaRoamingPreferenceResponse: radioService[%d]->mRadioResponse == NULL",
   5099                 slotId);
   5100     }
   5101 
   5102     return 0;
   5103 }
   5104 
   5105 int radio::getCdmaRoamingPreferenceResponse(int slotId,
   5106                                            int responseType, int serial, RIL_Errno e,
   5107                                            void *response, size_t responseLen) {
   5108 #if VDBG
   5109     RLOGD("getCdmaRoamingPreferenceResponse: serial %d", serial);
   5110 #endif
   5111 
   5112     if (radioService[slotId]->mRadioResponse != NULL) {
   5113         RadioResponseInfo responseInfo = {};
   5114         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   5115         Return<void> retStatus
   5116                 = radioService[slotId]->mRadioResponse->getCdmaRoamingPreferenceResponse(
   5117                 responseInfo, (CdmaRoamingType) ret);
   5118         radioService[slotId]->checkReturnStatus(retStatus);
   5119     } else {
   5120         RLOGE("getCdmaRoamingPreferenceResponse: radioService[%d]->mRadioResponse == NULL",
   5121                 slotId);
   5122     }
   5123 
   5124     return 0;
   5125 }
   5126 
   5127 int radio::setTTYModeResponse(int slotId,
   5128                              int responseType, int serial, RIL_Errno e,
   5129                              void *response, size_t responseLen) {
   5130 #if VDBG
   5131     RLOGD("setTTYModeResponse: serial %d", serial);
   5132 #endif
   5133 
   5134     if (radioService[slotId]->mRadioResponse != NULL) {
   5135         RadioResponseInfo responseInfo = {};
   5136         populateResponseInfo(responseInfo, serial, responseType, e);
   5137         Return<void> retStatus
   5138                 = radioService[slotId]->mRadioResponse->setTTYModeResponse(responseInfo);
   5139         radioService[slotId]->checkReturnStatus(retStatus);
   5140     } else {
   5141         RLOGE("setTTYModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5142     }
   5143 
   5144     return 0;
   5145 }
   5146 
   5147 int radio::getTTYModeResponse(int slotId,
   5148                              int responseType, int serial, RIL_Errno e,
   5149                              void *response, size_t responseLen) {
   5150 #if VDBG
   5151     RLOGD("getTTYModeResponse: serial %d", serial);
   5152 #endif
   5153 
   5154     if (radioService[slotId]->mRadioResponse != NULL) {
   5155         RadioResponseInfo responseInfo = {};
   5156         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   5157         Return<void> retStatus
   5158                 = radioService[slotId]->mRadioResponse->getTTYModeResponse(responseInfo,
   5159                 (TtyMode) ret);
   5160         radioService[slotId]->checkReturnStatus(retStatus);
   5161     } else {
   5162         RLOGE("getTTYModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5163     }
   5164 
   5165     return 0;
   5166 }
   5167 
   5168 int radio::setPreferredVoicePrivacyResponse(int slotId,
   5169                                  int responseType, int serial, RIL_Errno e,
   5170                                  void *response, size_t responseLen) {
   5171 #if VDBG
   5172     RLOGD("setPreferredVoicePrivacyResponse: serial %d", serial);
   5173 #endif
   5174 
   5175     if (radioService[slotId]->mRadioResponse != NULL) {
   5176         RadioResponseInfo responseInfo = {};
   5177         populateResponseInfo(responseInfo, serial, responseType, e);
   5178         Return<void> retStatus
   5179                 = radioService[slotId]->mRadioResponse->setPreferredVoicePrivacyResponse(
   5180                 responseInfo);
   5181         radioService[slotId]->checkReturnStatus(retStatus);
   5182     } else {
   5183         RLOGE("setPreferredVoicePrivacyResponse: radioService[%d]->mRadioResponse == NULL",
   5184                 slotId);
   5185     }
   5186 
   5187     return 0;
   5188 }
   5189 
   5190 int radio::getPreferredVoicePrivacyResponse(int slotId,
   5191                                            int responseType, int serial, RIL_Errno e,
   5192                                            void *response, size_t responseLen) {
   5193 #if VDBG
   5194     RLOGD("getPreferredVoicePrivacyResponse: serial %d", serial);
   5195 #endif
   5196 
   5197     if (radioService[slotId]->mRadioResponse != NULL) {
   5198         RadioResponseInfo responseInfo = {};
   5199         populateResponseInfo(responseInfo, serial, responseType, e);
   5200         bool enable = false;
   5201         int numInts = responseLen / sizeof(int);
   5202         if (response == NULL || numInts != 1) {
   5203             RLOGE("getPreferredVoicePrivacyResponse Invalid response: NULL");
   5204             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5205         } else {
   5206             int *pInt = (int *) response;
   5207             enable = pInt[0] == 1 ? true : false;
   5208         }
   5209         Return<void> retStatus
   5210                 = radioService[slotId]->mRadioResponse->getPreferredVoicePrivacyResponse(
   5211                 responseInfo, enable);
   5212         radioService[slotId]->checkReturnStatus(retStatus);
   5213     } else {
   5214         RLOGE("getPreferredVoicePrivacyResponse: radioService[%d]->mRadioResponse == NULL",
   5215                 slotId);
   5216     }
   5217 
   5218     return 0;
   5219 }
   5220 
   5221 int radio::sendCDMAFeatureCodeResponse(int slotId,
   5222                                  int responseType, int serial, RIL_Errno e,
   5223                                  void *response, size_t responseLen) {
   5224 #if VDBG
   5225     RLOGD("sendCDMAFeatureCodeResponse: serial %d", serial);
   5226 #endif
   5227 
   5228     if (radioService[slotId]->mRadioResponse != NULL) {
   5229         RadioResponseInfo responseInfo = {};
   5230         populateResponseInfo(responseInfo, serial, responseType, e);
   5231         Return<void> retStatus
   5232                 = radioService[slotId]->mRadioResponse->sendCDMAFeatureCodeResponse(responseInfo);
   5233         radioService[slotId]->checkReturnStatus(retStatus);
   5234     } else {
   5235         RLOGE("sendCDMAFeatureCodeResponse: radioService[%d]->mRadioResponse == NULL",
   5236                 slotId);
   5237     }
   5238 
   5239     return 0;
   5240 }
   5241 
   5242 int radio::sendBurstDtmfResponse(int slotId,
   5243                                  int responseType, int serial, RIL_Errno e,
   5244                                  void *response, size_t responseLen) {
   5245 #if VDBG
   5246     RLOGD("sendBurstDtmfResponse: serial %d", serial);
   5247 #endif
   5248 
   5249     if (radioService[slotId]->mRadioResponse != NULL) {
   5250         RadioResponseInfo responseInfo = {};
   5251         populateResponseInfo(responseInfo, serial, responseType, e);
   5252         Return<void> retStatus
   5253                 = radioService[slotId]->mRadioResponse->sendBurstDtmfResponse(responseInfo);
   5254         radioService[slotId]->checkReturnStatus(retStatus);
   5255     } else {
   5256         RLOGE("sendBurstDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5257     }
   5258 
   5259     return 0;
   5260 }
   5261 
   5262 int radio::sendCdmaSmsResponse(int slotId,
   5263                               int responseType, int serial, RIL_Errno e, void *response,
   5264                               size_t responseLen) {
   5265 #if VDBG
   5266     RLOGD("sendCdmaSmsResponse: serial %d", serial);
   5267 #endif
   5268 
   5269     if (radioService[slotId]->mRadioResponse != NULL) {
   5270         RadioResponseInfo responseInfo = {};
   5271         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
   5272                 responseLen);
   5273 
   5274         Return<void> retStatus
   5275                 = radioService[slotId]->mRadioResponse->sendCdmaSmsResponse(responseInfo, result);
   5276         radioService[slotId]->checkReturnStatus(retStatus);
   5277     } else {
   5278         RLOGE("sendCdmaSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5279     }
   5280 
   5281     return 0;
   5282 }
   5283 
   5284 int radio::acknowledgeLastIncomingCdmaSmsResponse(int slotId,
   5285                                                  int responseType, int serial, RIL_Errno e,
   5286                                                  void *response, size_t responseLen) {
   5287 #if VDBG
   5288     RLOGD("acknowledgeLastIncomingCdmaSmsResponse: serial %d", serial);
   5289 #endif
   5290 
   5291     if (radioService[slotId]->mRadioResponse != NULL) {
   5292         RadioResponseInfo responseInfo = {};
   5293         populateResponseInfo(responseInfo, serial, responseType, e);
   5294         Return<void> retStatus
   5295                 = radioService[slotId]->mRadioResponse->acknowledgeLastIncomingCdmaSmsResponse(
   5296                 responseInfo);
   5297         radioService[slotId]->checkReturnStatus(retStatus);
   5298     } else {
   5299         RLOGE("acknowledgeLastIncomingCdmaSmsResponse: radioService[%d]->mRadioResponse "
   5300                 "== NULL", slotId);
   5301     }
   5302 
   5303     return 0;
   5304 }
   5305 
   5306 int radio::getGsmBroadcastConfigResponse(int slotId,
   5307                                         int responseType, int serial, RIL_Errno e,
   5308                                         void *response, size_t responseLen) {
   5309 #if VDBG
   5310     RLOGD("getGsmBroadcastConfigResponse: serial %d", serial);
   5311 #endif
   5312 
   5313     if (radioService[slotId]->mRadioResponse != NULL) {
   5314         RadioResponseInfo responseInfo = {};
   5315         populateResponseInfo(responseInfo, serial, responseType, e);
   5316         hidl_vec<GsmBroadcastSmsConfigInfo> configs;
   5317 
   5318         if ((response == NULL && responseLen != 0)
   5319                 || responseLen % sizeof(RIL_GSM_BroadcastSmsConfigInfo *) != 0) {
   5320             RLOGE("getGsmBroadcastConfigResponse Invalid response: NULL");
   5321             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5322         } else {
   5323             int num = responseLen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
   5324             configs.resize(num);
   5325             for (int i = 0 ; i < num; i++) {
   5326                 RIL_GSM_BroadcastSmsConfigInfo *resp =
   5327                         ((RIL_GSM_BroadcastSmsConfigInfo **) response)[i];
   5328                 configs[i].fromServiceId = resp->fromServiceId;
   5329                 configs[i].toServiceId = resp->toServiceId;
   5330                 configs[i].fromCodeScheme = resp->fromCodeScheme;
   5331                 configs[i].toCodeScheme = resp->toCodeScheme;
   5332                 configs[i].selected = resp->selected == 1 ? true : false;
   5333             }
   5334         }
   5335 
   5336         Return<void> retStatus
   5337                 = radioService[slotId]->mRadioResponse->getGsmBroadcastConfigResponse(responseInfo,
   5338                 configs);
   5339         radioService[slotId]->checkReturnStatus(retStatus);
   5340     } else {
   5341         RLOGE("getGsmBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
   5342                 slotId);
   5343     }
   5344 
   5345     return 0;
   5346 }
   5347 
   5348 int radio::setGsmBroadcastConfigResponse(int slotId,
   5349                                         int responseType, int serial, RIL_Errno e,
   5350                                         void *response, size_t responseLen) {
   5351 #if VDBG
   5352     RLOGD("setGsmBroadcastConfigResponse: serial %d", serial);
   5353 #endif
   5354 
   5355     if (radioService[slotId]->mRadioResponse != NULL) {
   5356         RadioResponseInfo responseInfo = {};
   5357         populateResponseInfo(responseInfo, serial, responseType, e);
   5358         Return<void> retStatus
   5359                 = radioService[slotId]->mRadioResponse->setGsmBroadcastConfigResponse(responseInfo);
   5360         radioService[slotId]->checkReturnStatus(retStatus);
   5361     } else {
   5362         RLOGE("setGsmBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
   5363                 slotId);
   5364     }
   5365 
   5366     return 0;
   5367 }
   5368 
   5369 int radio::setGsmBroadcastActivationResponse(int slotId,
   5370                                             int responseType, int serial, RIL_Errno e,
   5371                                             void *response, size_t responseLen) {
   5372 #if VDBG
   5373     RLOGD("setGsmBroadcastActivationResponse: serial %d", serial);
   5374 #endif
   5375 
   5376     if (radioService[slotId]->mRadioResponse != NULL) {
   5377         RadioResponseInfo responseInfo = {};
   5378         populateResponseInfo(responseInfo, serial, responseType, e);
   5379         Return<void> retStatus
   5380                 = radioService[slotId]->mRadioResponse->setGsmBroadcastActivationResponse(
   5381                 responseInfo);
   5382         radioService[slotId]->checkReturnStatus(retStatus);
   5383     } else {
   5384         RLOGE("setGsmBroadcastActivationResponse: radioService[%d]->mRadioResponse == NULL",
   5385                 slotId);
   5386     }
   5387 
   5388     return 0;
   5389 }
   5390 
   5391 int radio::getCdmaBroadcastConfigResponse(int slotId,
   5392                                          int responseType, int serial, RIL_Errno e,
   5393                                          void *response, size_t responseLen) {
   5394 #if VDBG
   5395     RLOGD("getCdmaBroadcastConfigResponse: serial %d", serial);
   5396 #endif
   5397 
   5398     if (radioService[slotId]->mRadioResponse != NULL) {
   5399         RadioResponseInfo responseInfo = {};
   5400         populateResponseInfo(responseInfo, serial, responseType, e);
   5401         hidl_vec<CdmaBroadcastSmsConfigInfo> configs;
   5402 
   5403         if ((response == NULL && responseLen != 0)
   5404                 || responseLen % sizeof(RIL_CDMA_BroadcastSmsConfigInfo *) != 0) {
   5405             RLOGE("getCdmaBroadcastConfigResponse Invalid response: NULL");
   5406             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5407         } else {
   5408             int num = responseLen / sizeof(RIL_CDMA_BroadcastSmsConfigInfo *);
   5409             configs.resize(num);
   5410             for (int i = 0 ; i < num; i++) {
   5411                 RIL_CDMA_BroadcastSmsConfigInfo *resp =
   5412                         ((RIL_CDMA_BroadcastSmsConfigInfo **) response)[i];
   5413                 configs[i].serviceCategory = resp->service_category;
   5414                 configs[i].language = resp->language;
   5415                 configs[i].selected = resp->selected == 1 ? true : false;
   5416             }
   5417         }
   5418 
   5419         Return<void> retStatus
   5420                 = radioService[slotId]->mRadioResponse->getCdmaBroadcastConfigResponse(responseInfo,
   5421                 configs);
   5422         radioService[slotId]->checkReturnStatus(retStatus);
   5423     } else {
   5424         RLOGE("getCdmaBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
   5425                 slotId);
   5426     }
   5427 
   5428     return 0;
   5429 }
   5430 
   5431 int radio::setCdmaBroadcastConfigResponse(int slotId,
   5432                                          int responseType, int serial, RIL_Errno e,
   5433                                          void *response, size_t responseLen) {
   5434 #if VDBG
   5435     RLOGD("setCdmaBroadcastConfigResponse: serial %d", serial);
   5436 #endif
   5437 
   5438     if (radioService[slotId]->mRadioResponse != NULL) {
   5439         RadioResponseInfo responseInfo = {};
   5440         populateResponseInfo(responseInfo, serial, responseType, e);
   5441         Return<void> retStatus
   5442                 = radioService[slotId]->mRadioResponse->setCdmaBroadcastConfigResponse(
   5443                 responseInfo);
   5444         radioService[slotId]->checkReturnStatus(retStatus);
   5445     } else {
   5446         RLOGE("setCdmaBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
   5447                 slotId);
   5448     }
   5449 
   5450     return 0;
   5451 }
   5452 
   5453 int radio::setCdmaBroadcastActivationResponse(int slotId,
   5454                                              int responseType, int serial, RIL_Errno e,
   5455                                              void *response, size_t responseLen) {
   5456 #if VDBG
   5457     RLOGD("setCdmaBroadcastActivationResponse: serial %d", serial);
   5458 #endif
   5459 
   5460     if (radioService[slotId]->mRadioResponse != NULL) {
   5461         RadioResponseInfo responseInfo = {};
   5462         populateResponseInfo(responseInfo, serial, responseType, e);
   5463         Return<void> retStatus
   5464                 = radioService[slotId]->mRadioResponse->setCdmaBroadcastActivationResponse(
   5465                 responseInfo);
   5466         radioService[slotId]->checkReturnStatus(retStatus);
   5467     } else {
   5468         RLOGE("setCdmaBroadcastActivationResponse: radioService[%d]->mRadioResponse == NULL",
   5469                 slotId);
   5470     }
   5471 
   5472     return 0;
   5473 }
   5474 
   5475 int radio::getCDMASubscriptionResponse(int slotId,
   5476                                       int responseType, int serial, RIL_Errno e, void *response,
   5477                                       size_t responseLen) {
   5478 #if VDBG
   5479     RLOGD("getCDMASubscriptionResponse: serial %d", serial);
   5480 #endif
   5481 
   5482     if (radioService[slotId]->mRadioResponse != NULL) {
   5483         RadioResponseInfo responseInfo = {};
   5484         populateResponseInfo(responseInfo, serial, responseType, e);
   5485 
   5486         int numStrings = responseLen / sizeof(char *);
   5487         hidl_string emptyString;
   5488         if (response == NULL || numStrings != 5) {
   5489             RLOGE("getOperatorResponse Invalid response: NULL");
   5490             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5491             Return<void> retStatus
   5492                     = radioService[slotId]->mRadioResponse->getCDMASubscriptionResponse(
   5493                     responseInfo, emptyString, emptyString, emptyString, emptyString, emptyString);
   5494             radioService[slotId]->checkReturnStatus(retStatus);
   5495         } else {
   5496             char **resp = (char **) response;
   5497             Return<void> retStatus
   5498                     = radioService[slotId]->mRadioResponse->getCDMASubscriptionResponse(
   5499                     responseInfo,
   5500                     convertCharPtrToHidlString(resp[0]),
   5501                     convertCharPtrToHidlString(resp[1]),
   5502                     convertCharPtrToHidlString(resp[2]),
   5503                     convertCharPtrToHidlString(resp[3]),
   5504                     convertCharPtrToHidlString(resp[4]));
   5505             radioService[slotId]->checkReturnStatus(retStatus);
   5506         }
   5507     } else {
   5508         RLOGE("getCDMASubscriptionResponse: radioService[%d]->mRadioResponse == NULL",
   5509                 slotId);
   5510     }
   5511 
   5512     return 0;
   5513 }
   5514 
   5515 int radio::writeSmsToRuimResponse(int slotId,
   5516                                  int responseType, int serial, RIL_Errno e,
   5517                                  void *response, size_t responseLen) {
   5518 #if VDBG
   5519     RLOGD("writeSmsToRuimResponse: serial %d", serial);
   5520 #endif
   5521 
   5522     if (radioService[slotId]->mRadioResponse != NULL) {
   5523         RadioResponseInfo responseInfo = {};
   5524         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   5525         Return<void> retStatus
   5526                 = radioService[slotId]->mRadioResponse->writeSmsToRuimResponse(responseInfo, ret);
   5527         radioService[slotId]->checkReturnStatus(retStatus);
   5528     } else {
   5529         RLOGE("writeSmsToRuimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5530     }
   5531 
   5532     return 0;
   5533 }
   5534 
   5535 int radio::deleteSmsOnRuimResponse(int slotId,
   5536                                   int responseType, int serial, RIL_Errno e,
   5537                                   void *response, size_t responseLen) {
   5538 #if VDBG
   5539     RLOGD("deleteSmsOnRuimResponse: serial %d", serial);
   5540 #endif
   5541 
   5542     if (radioService[slotId]->mRadioResponse != NULL) {
   5543         RadioResponseInfo responseInfo = {};
   5544         populateResponseInfo(responseInfo, serial, responseType, e);
   5545         Return<void> retStatus
   5546                 = radioService[slotId]->mRadioResponse->deleteSmsOnRuimResponse(responseInfo);
   5547         radioService[slotId]->checkReturnStatus(retStatus);
   5548     } else {
   5549         RLOGE("deleteSmsOnRuimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5550     }
   5551 
   5552     return 0;
   5553 }
   5554 
   5555 int radio::getDeviceIdentityResponse(int slotId,
   5556                                     int responseType, int serial, RIL_Errno e, void *response,
   5557                                     size_t responseLen) {
   5558 #if VDBG
   5559     RLOGD("getDeviceIdentityResponse: serial %d", serial);
   5560 #endif
   5561 
   5562     if (radioService[slotId]->mRadioResponse != NULL) {
   5563         RadioResponseInfo responseInfo = {};
   5564         populateResponseInfo(responseInfo, serial, responseType, e);
   5565 
   5566         int numStrings = responseLen / sizeof(char *);
   5567         hidl_string emptyString;
   5568         if (response == NULL || numStrings != 4) {
   5569             RLOGE("getDeviceIdentityResponse Invalid response: NULL");
   5570             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5571             Return<void> retStatus
   5572                     = radioService[slotId]->mRadioResponse->getDeviceIdentityResponse(responseInfo,
   5573                     emptyString, emptyString, emptyString, emptyString);
   5574             radioService[slotId]->checkReturnStatus(retStatus);
   5575         } else {
   5576             char **resp = (char **) response;
   5577             Return<void> retStatus
   5578                     = radioService[slotId]->mRadioResponse->getDeviceIdentityResponse(responseInfo,
   5579                     convertCharPtrToHidlString(resp[0]),
   5580                     convertCharPtrToHidlString(resp[1]),
   5581                     convertCharPtrToHidlString(resp[2]),
   5582                     convertCharPtrToHidlString(resp[3]));
   5583             radioService[slotId]->checkReturnStatus(retStatus);
   5584         }
   5585     } else {
   5586         RLOGE("getDeviceIdentityResponse: radioService[%d]->mRadioResponse == NULL",
   5587                 slotId);
   5588     }
   5589 
   5590     return 0;
   5591 }
   5592 
   5593 int radio::exitEmergencyCallbackModeResponse(int slotId,
   5594                                             int responseType, int serial, RIL_Errno e,
   5595                                             void *response, size_t responseLen) {
   5596 #if VDBG
   5597     RLOGD("exitEmergencyCallbackModeResponse: serial %d", serial);
   5598 #endif
   5599 
   5600     if (radioService[slotId]->mRadioResponse != NULL) {
   5601         RadioResponseInfo responseInfo = {};
   5602         populateResponseInfo(responseInfo, serial, responseType, e);
   5603         Return<void> retStatus
   5604                 = radioService[slotId]->mRadioResponse->exitEmergencyCallbackModeResponse(
   5605                 responseInfo);
   5606         radioService[slotId]->checkReturnStatus(retStatus);
   5607     } else {
   5608         RLOGE("exitEmergencyCallbackModeResponse: radioService[%d]->mRadioResponse == NULL",
   5609                 slotId);
   5610     }
   5611 
   5612     return 0;
   5613 }
   5614 
   5615 int radio::getSmscAddressResponse(int slotId,
   5616                                   int responseType, int serial, RIL_Errno e,
   5617                                   void *response, size_t responseLen) {
   5618 #if VDBG
   5619     RLOGD("getSmscAddressResponse: serial %d", serial);
   5620 #endif
   5621 
   5622     if (radioService[slotId]->mRadioResponse != NULL) {
   5623         RadioResponseInfo responseInfo = {};
   5624         populateResponseInfo(responseInfo, serial, responseType, e);
   5625         Return<void> retStatus
   5626                 = radioService[slotId]->mRadioResponse->getSmscAddressResponse(responseInfo,
   5627                 convertCharPtrToHidlString((char *) response));
   5628         radioService[slotId]->checkReturnStatus(retStatus);
   5629     } else {
   5630         RLOGE("getSmscAddressResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5631     }
   5632 
   5633     return 0;
   5634 }
   5635 
   5636 int radio::setSmscAddressResponse(int slotId,
   5637                                              int responseType, int serial, RIL_Errno e,
   5638                                              void *response, size_t responseLen) {
   5639 #if VDBG
   5640     RLOGD("setSmscAddressResponse: serial %d", serial);
   5641 #endif
   5642 
   5643     if (radioService[slotId]->mRadioResponse != NULL) {
   5644         RadioResponseInfo responseInfo = {};
   5645         populateResponseInfo(responseInfo, serial, responseType, e);
   5646         Return<void> retStatus
   5647                 = radioService[slotId]->mRadioResponse->setSmscAddressResponse(responseInfo);
   5648         radioService[slotId]->checkReturnStatus(retStatus);
   5649     } else {
   5650         RLOGE("setSmscAddressResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5651     }
   5652 
   5653     return 0;
   5654 }
   5655 
   5656 int radio::reportSmsMemoryStatusResponse(int slotId,
   5657                                         int responseType, int serial, RIL_Errno e,
   5658                                         void *response, size_t responseLen) {
   5659 #if VDBG
   5660     RLOGD("reportSmsMemoryStatusResponse: serial %d", serial);
   5661 #endif
   5662 
   5663     if (radioService[slotId]->mRadioResponse != NULL) {
   5664         RadioResponseInfo responseInfo = {};
   5665         populateResponseInfo(responseInfo, serial, responseType, e);
   5666         Return<void> retStatus
   5667                 = radioService[slotId]->mRadioResponse->reportSmsMemoryStatusResponse(responseInfo);
   5668         radioService[slotId]->checkReturnStatus(retStatus);
   5669     } else {
   5670         RLOGE("reportSmsMemoryStatusResponse: radioService[%d]->mRadioResponse == NULL",
   5671                 slotId);
   5672     }
   5673 
   5674     return 0;
   5675 }
   5676 
   5677 int radio::reportStkServiceIsRunningResponse(int slotId,
   5678                                              int responseType, int serial, RIL_Errno e,
   5679                                              void *response, size_t responseLen) {
   5680 #if VDBG
   5681     RLOGD("reportStkServiceIsRunningResponse: serial %d", serial);
   5682 #endif
   5683 
   5684     if (radioService[slotId]->mRadioResponse != NULL) {
   5685         RadioResponseInfo responseInfo = {};
   5686         populateResponseInfo(responseInfo, serial, responseType, e);
   5687         Return<void> retStatus = radioService[slotId]->mRadioResponse->
   5688                 reportStkServiceIsRunningResponse(responseInfo);
   5689         radioService[slotId]->checkReturnStatus(retStatus);
   5690     } else {
   5691         RLOGE("reportStkServiceIsRunningResponse: radioService[%d]->mRadioResponse == NULL",
   5692                 slotId);
   5693     }
   5694 
   5695     return 0;
   5696 }
   5697 
   5698 int radio::getCdmaSubscriptionSourceResponse(int slotId,
   5699                                             int responseType, int serial, RIL_Errno e,
   5700                                             void *response, size_t responseLen) {
   5701 #if VDBG
   5702     RLOGD("getCdmaSubscriptionSourceResponse: serial %d", serial);
   5703 #endif
   5704 
   5705     if (radioService[slotId]->mRadioResponse != NULL) {
   5706         RadioResponseInfo responseInfo = {};
   5707         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   5708         Return<void> retStatus
   5709                 = radioService[slotId]->mRadioResponse->getCdmaSubscriptionSourceResponse(
   5710                 responseInfo, (CdmaSubscriptionSource) ret);
   5711         radioService[slotId]->checkReturnStatus(retStatus);
   5712     } else {
   5713         RLOGE("getCdmaSubscriptionSourceResponse: radioService[%d]->mRadioResponse == NULL",
   5714                 slotId);
   5715     }
   5716 
   5717     return 0;
   5718 }
   5719 
   5720 int radio::requestIsimAuthenticationResponse(int slotId,
   5721                                             int responseType, int serial, RIL_Errno e,
   5722                                             void *response, size_t responseLen) {
   5723 #if VDBG
   5724     RLOGD("requestIsimAuthenticationResponse: serial %d", serial);
   5725 #endif
   5726 
   5727     if (radioService[slotId]->mRadioResponse != NULL) {
   5728         RadioResponseInfo responseInfo = {};
   5729         populateResponseInfo(responseInfo, serial, responseType, e);
   5730         Return<void> retStatus
   5731                 = radioService[slotId]->mRadioResponse->requestIsimAuthenticationResponse(
   5732                 responseInfo,
   5733                 convertCharPtrToHidlString((char *) response));
   5734         radioService[slotId]->checkReturnStatus(retStatus);
   5735     } else {
   5736         RLOGE("requestIsimAuthenticationResponse: radioService[%d]->mRadioResponse == NULL",
   5737                 slotId);
   5738     }
   5739 
   5740     return 0;
   5741 }
   5742 
   5743 int radio::acknowledgeIncomingGsmSmsWithPduResponse(int slotId,
   5744                                                    int responseType,
   5745                                                    int serial, RIL_Errno e, void *response,
   5746                                                    size_t responseLen) {
   5747 #if VDBG
   5748     RLOGD("acknowledgeIncomingGsmSmsWithPduResponse: serial %d", serial);
   5749 #endif
   5750 
   5751     if (radioService[slotId]->mRadioResponse != NULL) {
   5752         RadioResponseInfo responseInfo = {};
   5753         populateResponseInfo(responseInfo, serial, responseType, e);
   5754         Return<void> retStatus
   5755                 = radioService[slotId]->mRadioResponse->acknowledgeIncomingGsmSmsWithPduResponse(
   5756                 responseInfo);
   5757         radioService[slotId]->checkReturnStatus(retStatus);
   5758     } else {
   5759         RLOGE("acknowledgeIncomingGsmSmsWithPduResponse: radioService[%d]->mRadioResponse "
   5760                 "== NULL", slotId);
   5761     }
   5762 
   5763     return 0;
   5764 }
   5765 
   5766 int radio::sendEnvelopeWithStatusResponse(int slotId,
   5767                                          int responseType, int serial, RIL_Errno e, void *response,
   5768                                          size_t responseLen) {
   5769 #if VDBG
   5770     RLOGD("sendEnvelopeWithStatusResponse: serial %d", serial);
   5771 #endif
   5772 
   5773     if (radioService[slotId]->mRadioResponse != NULL) {
   5774         RadioResponseInfo responseInfo = {};
   5775         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e,
   5776                 response, responseLen);
   5777 
   5778         Return<void> retStatus
   5779                 = radioService[slotId]->mRadioResponse->sendEnvelopeWithStatusResponse(responseInfo,
   5780                 result);
   5781         radioService[slotId]->checkReturnStatus(retStatus);
   5782     } else {
   5783         RLOGE("sendEnvelopeWithStatusResponse: radioService[%d]->mRadioResponse == NULL",
   5784                 slotId);
   5785     }
   5786 
   5787     return 0;
   5788 }
   5789 
   5790 int radio::getVoiceRadioTechnologyResponse(int slotId,
   5791                                           int responseType, int serial, RIL_Errno e,
   5792                                           void *response, size_t responseLen) {
   5793 #if VDBG
   5794     RLOGD("getVoiceRadioTechnologyResponse: serial %d", serial);
   5795 #endif
   5796 
   5797     if (radioService[slotId]->mRadioResponse != NULL) {
   5798         RadioResponseInfo responseInfo = {};
   5799         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   5800         Return<void> retStatus
   5801                 = radioService[slotId]->mRadioResponse->getVoiceRadioTechnologyResponse(
   5802                 responseInfo, (RadioTechnology) ret);
   5803         radioService[slotId]->checkReturnStatus(retStatus);
   5804     } else {
   5805         RLOGE("getVoiceRadioTechnologyResponse: radioService[%d]->mRadioResponse == NULL",
   5806                 slotId);
   5807     }
   5808 
   5809     return 0;
   5810 }
   5811 
   5812 int radio::getCellInfoListResponse(int slotId,
   5813                                    int responseType,
   5814                                    int serial, RIL_Errno e, void *response,
   5815                                    size_t responseLen) {
   5816 #if VDBG
   5817     RLOGD("getCellInfoListResponse: serial %d", serial);
   5818 #endif
   5819 
   5820     if (radioService[slotId]->mRadioResponse != NULL) {
   5821         RadioResponseInfo responseInfo = {};
   5822         populateResponseInfo(responseInfo, serial, responseType, e);
   5823 
   5824         hidl_vec<CellInfo> ret;
   5825         if ((response == NULL && responseLen != 0)
   5826                 || responseLen % sizeof(RIL_CellInfo_v12) != 0) {
   5827             RLOGE("getCellInfoListResponse: Invalid response");
   5828             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5829         } else {
   5830             convertRilCellInfoListToHal(response, responseLen, ret);
   5831         }
   5832 
   5833         Return<void> retStatus = radioService[slotId]->mRadioResponse->getCellInfoListResponse(
   5834                 responseInfo, ret);
   5835         radioService[slotId]->checkReturnStatus(retStatus);
   5836     } else {
   5837         RLOGE("getCellInfoListResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5838     }
   5839 
   5840     return 0;
   5841 }
   5842 
   5843 int radio::setCellInfoListRateResponse(int slotId,
   5844                                        int responseType,
   5845                                        int serial, RIL_Errno e, void *response,
   5846                                        size_t responseLen) {
   5847 #if VDBG
   5848     RLOGD("setCellInfoListRateResponse: serial %d", serial);
   5849 #endif
   5850 
   5851     if (radioService[slotId]->mRadioResponse != NULL) {
   5852         RadioResponseInfo responseInfo = {};
   5853         populateResponseInfo(responseInfo, serial, responseType, e);
   5854         Return<void> retStatus
   5855                 = radioService[slotId]->mRadioResponse->setCellInfoListRateResponse(responseInfo);
   5856         radioService[slotId]->checkReturnStatus(retStatus);
   5857     } else {
   5858         RLOGE("setCellInfoListRateResponse: radioService[%d]->mRadioResponse == NULL",
   5859                 slotId);
   5860     }
   5861 
   5862     return 0;
   5863 }
   5864 
   5865 int radio::setInitialAttachApnResponse(int slotId,
   5866                                        int responseType, int serial, RIL_Errno e,
   5867                                        void *response, size_t responseLen) {
   5868 #if VDBG
   5869     RLOGD("setInitialAttachApnResponse: serial %d", serial);
   5870 #endif
   5871 
   5872     if (radioService[slotId]->mRadioResponse != NULL) {
   5873         RadioResponseInfo responseInfo = {};
   5874         populateResponseInfo(responseInfo, serial, responseType, e);
   5875         Return<void> retStatus
   5876                 = radioService[slotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo);
   5877         radioService[slotId]->checkReturnStatus(retStatus);
   5878     } else {
   5879         RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL",
   5880                 slotId);
   5881     }
   5882 
   5883     return 0;
   5884 }
   5885 
   5886 int radio::getImsRegistrationStateResponse(int slotId,
   5887                                            int responseType, int serial, RIL_Errno e,
   5888                                            void *response, size_t responseLen) {
   5889 #if VDBG
   5890     RLOGD("getImsRegistrationStateResponse: serial %d", serial);
   5891 #endif
   5892 
   5893     if (radioService[slotId]->mRadioResponse != NULL) {
   5894         RadioResponseInfo responseInfo = {};
   5895         populateResponseInfo(responseInfo, serial, responseType, e);
   5896         bool isRegistered = false;
   5897         int ratFamily = 0;
   5898         int numInts = responseLen / sizeof(int);
   5899         if (response == NULL || numInts != 2) {
   5900             RLOGE("getImsRegistrationStateResponse Invalid response: NULL");
   5901             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5902         } else {
   5903             int *pInt = (int *) response;
   5904             isRegistered = pInt[0] == 1 ? true : false;
   5905             ratFamily = pInt[1];
   5906         }
   5907         Return<void> retStatus
   5908                 = radioService[slotId]->mRadioResponse->getImsRegistrationStateResponse(
   5909                 responseInfo, isRegistered, (RadioTechnologyFamily) ratFamily);
   5910         radioService[slotId]->checkReturnStatus(retStatus);
   5911     } else {
   5912         RLOGE("getImsRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
   5913                 slotId);
   5914     }
   5915 
   5916     return 0;
   5917 }
   5918 
   5919 int radio::sendImsSmsResponse(int slotId,
   5920                               int responseType, int serial, RIL_Errno e, void *response,
   5921                               size_t responseLen) {
   5922 #if VDBG
   5923     RLOGD("sendImsSmsResponse: serial %d", serial);
   5924 #endif
   5925 
   5926     if (radioService[slotId]->mRadioResponse != NULL) {
   5927         RadioResponseInfo responseInfo = {};
   5928         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
   5929                 responseLen);
   5930 
   5931         Return<void> retStatus
   5932                 = radioService[slotId]->mRadioResponse->sendImsSmsResponse(responseInfo, result);
   5933         radioService[slotId]->checkReturnStatus(retStatus);
   5934     } else {
   5935         RLOGE("sendSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   5936     }
   5937 
   5938     return 0;
   5939 }
   5940 
   5941 int radio::iccTransmitApduBasicChannelResponse(int slotId,
   5942                                                int responseType, int serial, RIL_Errno e,
   5943                                                void *response, size_t responseLen) {
   5944 #if VDBG
   5945     RLOGD("iccTransmitApduBasicChannelResponse: serial %d", serial);
   5946 #endif
   5947 
   5948     if (radioService[slotId]->mRadioResponse != NULL) {
   5949         RadioResponseInfo responseInfo = {};
   5950         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
   5951                 responseLen);
   5952 
   5953         Return<void> retStatus
   5954                 = radioService[slotId]->mRadioResponse->iccTransmitApduBasicChannelResponse(
   5955                 responseInfo, result);
   5956         radioService[slotId]->checkReturnStatus(retStatus);
   5957     } else {
   5958         RLOGE("iccTransmitApduBasicChannelResponse: radioService[%d]->mRadioResponse "
   5959                 "== NULL", slotId);
   5960     }
   5961 
   5962     return 0;
   5963 }
   5964 
   5965 int radio::iccOpenLogicalChannelResponse(int slotId,
   5966                                          int responseType, int serial, RIL_Errno e, void *response,
   5967                                          size_t responseLen) {
   5968 #if VDBG
   5969     RLOGD("iccOpenLogicalChannelResponse: serial %d", serial);
   5970 #endif
   5971 
   5972     if (radioService[slotId]->mRadioResponse != NULL) {
   5973         RadioResponseInfo responseInfo = {};
   5974         populateResponseInfo(responseInfo, serial, responseType, e);
   5975         int channelId = -1;
   5976         hidl_vec<int8_t> selectResponse;
   5977         int numInts = responseLen / sizeof(int);
   5978         if (response == NULL || responseLen % sizeof(int) != 0) {
   5979             RLOGE("iccOpenLogicalChannelResponse Invalid response: NULL");
   5980             if (response != NULL) {
   5981                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   5982             }
   5983         } else {
   5984             int *pInt = (int *) response;
   5985             channelId = pInt[0];
   5986             selectResponse.resize(numInts - 1);
   5987             for (int i = 1; i < numInts; i++) {
   5988                 selectResponse[i - 1] = (int8_t) pInt[i];
   5989             }
   5990         }
   5991         Return<void> retStatus
   5992                 = radioService[slotId]->mRadioResponse->iccOpenLogicalChannelResponse(responseInfo,
   5993                 channelId, selectResponse);
   5994         radioService[slotId]->checkReturnStatus(retStatus);
   5995     } else {
   5996         RLOGE("iccOpenLogicalChannelResponse: radioService[%d]->mRadioResponse == NULL",
   5997                 slotId);
   5998     }
   5999 
   6000     return 0;
   6001 }
   6002 
   6003 int radio::iccCloseLogicalChannelResponse(int slotId,
   6004                                           int responseType, int serial, RIL_Errno e,
   6005                                           void *response, size_t responseLen) {
   6006 #if VDBG
   6007     RLOGD("iccCloseLogicalChannelResponse: serial %d", serial);
   6008 #endif
   6009 
   6010     if (radioService[slotId]->mRadioResponse != NULL) {
   6011         RadioResponseInfo responseInfo = {};
   6012         populateResponseInfo(responseInfo, serial, responseType, e);
   6013         Return<void> retStatus
   6014                 = radioService[slotId]->mRadioResponse->iccCloseLogicalChannelResponse(
   6015                 responseInfo);
   6016         radioService[slotId]->checkReturnStatus(retStatus);
   6017     } else {
   6018         RLOGE("iccCloseLogicalChannelResponse: radioService[%d]->mRadioResponse == NULL",
   6019                 slotId);
   6020     }
   6021 
   6022     return 0;
   6023 }
   6024 
   6025 int radio::iccTransmitApduLogicalChannelResponse(int slotId,
   6026                                                  int responseType, int serial, RIL_Errno e,
   6027                                                  void *response, size_t responseLen) {
   6028 #if VDBG
   6029     RLOGD("iccTransmitApduLogicalChannelResponse: serial %d", serial);
   6030 #endif
   6031 
   6032     if (radioService[slotId]->mRadioResponse != NULL) {
   6033         RadioResponseInfo responseInfo = {};
   6034         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
   6035                 responseLen);
   6036 
   6037         Return<void> retStatus
   6038                 = radioService[slotId]->mRadioResponse->iccTransmitApduLogicalChannelResponse(
   6039                 responseInfo, result);
   6040         radioService[slotId]->checkReturnStatus(retStatus);
   6041     } else {
   6042         RLOGE("iccTransmitApduLogicalChannelResponse: radioService[%d]->mRadioResponse "
   6043                 "== NULL", slotId);
   6044     }
   6045 
   6046     return 0;
   6047 }
   6048 
   6049 int radio::nvReadItemResponse(int slotId,
   6050                               int responseType, int serial, RIL_Errno e,
   6051                               void *response, size_t responseLen) {
   6052 #if VDBG
   6053     RLOGD("nvReadItemResponse: serial %d", serial);
   6054 #endif
   6055 
   6056     if (radioService[slotId]->mRadioResponse != NULL) {
   6057         RadioResponseInfo responseInfo = {};
   6058         populateResponseInfo(responseInfo, serial, responseType, e);
   6059         Return<void> retStatus = radioService[slotId]->mRadioResponse->nvReadItemResponse(
   6060                 responseInfo,
   6061                 convertCharPtrToHidlString((char *) response));
   6062         radioService[slotId]->checkReturnStatus(retStatus);
   6063     } else {
   6064         RLOGE("nvReadItemResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6065     }
   6066 
   6067     return 0;
   6068 }
   6069 
   6070 int radio::nvWriteItemResponse(int slotId,
   6071                                int responseType, int serial, RIL_Errno e,
   6072                                void *response, size_t responseLen) {
   6073 #if VDBG
   6074     RLOGD("nvWriteItemResponse: serial %d", serial);
   6075 #endif
   6076 
   6077     if (radioService[slotId]->mRadioResponse != NULL) {
   6078         RadioResponseInfo responseInfo = {};
   6079         populateResponseInfo(responseInfo, serial, responseType, e);
   6080         Return<void> retStatus
   6081                 = radioService[slotId]->mRadioResponse->nvWriteItemResponse(responseInfo);
   6082         radioService[slotId]->checkReturnStatus(retStatus);
   6083     } else {
   6084         RLOGE("nvWriteItemResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6085     }
   6086 
   6087     return 0;
   6088 }
   6089 
   6090 int radio::nvWriteCdmaPrlResponse(int slotId,
   6091                                   int responseType, int serial, RIL_Errno e,
   6092                                   void *response, size_t responseLen) {
   6093 #if VDBG
   6094     RLOGD("nvWriteCdmaPrlResponse: serial %d", serial);
   6095 #endif
   6096 
   6097     if (radioService[slotId]->mRadioResponse != NULL) {
   6098         RadioResponseInfo responseInfo = {};
   6099         populateResponseInfo(responseInfo, serial, responseType, e);
   6100         Return<void> retStatus
   6101                 = radioService[slotId]->mRadioResponse->nvWriteCdmaPrlResponse(responseInfo);
   6102         radioService[slotId]->checkReturnStatus(retStatus);
   6103     } else {
   6104         RLOGE("nvWriteCdmaPrlResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6105     }
   6106 
   6107     return 0;
   6108 }
   6109 
   6110 int radio::nvResetConfigResponse(int slotId,
   6111                                  int responseType, int serial, RIL_Errno e,
   6112                                  void *response, size_t responseLen) {
   6113 #if VDBG
   6114     RLOGD("nvResetConfigResponse: serial %d", serial);
   6115 #endif
   6116 
   6117     if (radioService[slotId]->mRadioResponse != NULL) {
   6118         RadioResponseInfo responseInfo = {};
   6119         populateResponseInfo(responseInfo, serial, responseType, e);
   6120         Return<void> retStatus
   6121                 = radioService[slotId]->mRadioResponse->nvResetConfigResponse(responseInfo);
   6122         radioService[slotId]->checkReturnStatus(retStatus);
   6123     } else {
   6124         RLOGE("nvResetConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6125     }
   6126 
   6127     return 0;
   6128 }
   6129 
   6130 int radio::setUiccSubscriptionResponse(int slotId,
   6131                                        int responseType, int serial, RIL_Errno e,
   6132                                        void *response, size_t responseLen) {
   6133 #if VDBG
   6134     RLOGD("setUiccSubscriptionResponse: serial %d", serial);
   6135 #endif
   6136 
   6137     if (radioService[slotId]->mRadioResponse != NULL) {
   6138         RadioResponseInfo responseInfo = {};
   6139         populateResponseInfo(responseInfo, serial, responseType, e);
   6140         Return<void> retStatus
   6141                 = radioService[slotId]->mRadioResponse->setUiccSubscriptionResponse(responseInfo);
   6142         radioService[slotId]->checkReturnStatus(retStatus);
   6143     } else {
   6144         RLOGE("setUiccSubscriptionResponse: radioService[%d]->mRadioResponse == NULL",
   6145                 slotId);
   6146     }
   6147 
   6148     return 0;
   6149 }
   6150 
   6151 int radio::setDataAllowedResponse(int slotId,
   6152                                   int responseType, int serial, RIL_Errno e,
   6153                                   void *response, size_t responseLen) {
   6154 #if VDBG
   6155     RLOGD("setDataAllowedResponse: serial %d", serial);
   6156 #endif
   6157 
   6158     if (radioService[slotId]->mRadioResponse != NULL) {
   6159         RadioResponseInfo responseInfo = {};
   6160         populateResponseInfo(responseInfo, serial, responseType, e);
   6161         Return<void> retStatus
   6162                 = radioService[slotId]->mRadioResponse->setDataAllowedResponse(responseInfo);
   6163         radioService[slotId]->checkReturnStatus(retStatus);
   6164     } else {
   6165         RLOGE("setDataAllowedResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6166     }
   6167 
   6168     return 0;
   6169 }
   6170 
   6171 int radio::getHardwareConfigResponse(int slotId,
   6172                                      int responseType, int serial, RIL_Errno e,
   6173                                      void *response, size_t responseLen) {
   6174 #if VDBG
   6175     RLOGD("getHardwareConfigResponse: serial %d", serial);
   6176 #endif
   6177 
   6178     if (radioService[slotId]->mRadioResponse != NULL) {
   6179         RadioResponseInfo responseInfo = {};
   6180         populateResponseInfo(responseInfo, serial, responseType, e);
   6181 
   6182         hidl_vec<HardwareConfig> result;
   6183         if ((response == NULL && responseLen != 0)
   6184                 || responseLen % sizeof(RIL_HardwareConfig) != 0) {
   6185             RLOGE("hardwareConfigChangedInd: invalid response");
   6186             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6187         } else {
   6188             convertRilHardwareConfigListToHal(response, responseLen, result);
   6189         }
   6190 
   6191         Return<void> retStatus = radioService[slotId]->mRadioResponse->getHardwareConfigResponse(
   6192                 responseInfo, result);
   6193         radioService[slotId]->checkReturnStatus(retStatus);
   6194     } else {
   6195         RLOGE("getHardwareConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6196     }
   6197 
   6198     return 0;
   6199 }
   6200 
   6201 int radio::requestIccSimAuthenticationResponse(int slotId,
   6202                                                int responseType, int serial, RIL_Errno e,
   6203                                                void *response, size_t responseLen) {
   6204 #if VDBG
   6205     RLOGD("requestIccSimAuthenticationResponse: serial %d", serial);
   6206 #endif
   6207 
   6208     if (radioService[slotId]->mRadioResponse != NULL) {
   6209         RadioResponseInfo responseInfo = {};
   6210         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
   6211                 responseLen);
   6212 
   6213         Return<void> retStatus
   6214                 = radioService[slotId]->mRadioResponse->requestIccSimAuthenticationResponse(
   6215                 responseInfo, result);
   6216         radioService[slotId]->checkReturnStatus(retStatus);
   6217     } else {
   6218         RLOGE("requestIccSimAuthenticationResponse: radioService[%d]->mRadioResponse "
   6219                 "== NULL", slotId);
   6220     }
   6221 
   6222     return 0;
   6223 }
   6224 
   6225 int radio::setDataProfileResponse(int slotId,
   6226                                   int responseType, int serial, RIL_Errno e,
   6227                                   void *response, size_t responseLen) {
   6228 #if VDBG
   6229     RLOGD("setDataProfileResponse: serial %d", serial);
   6230 #endif
   6231 
   6232     if (radioService[slotId]->mRadioResponse != NULL) {
   6233         RadioResponseInfo responseInfo = {};
   6234         populateResponseInfo(responseInfo, serial, responseType, e);
   6235         Return<void> retStatus
   6236                 = radioService[slotId]->mRadioResponse->setDataProfileResponse(responseInfo);
   6237         radioService[slotId]->checkReturnStatus(retStatus);
   6238     } else {
   6239         RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6240     }
   6241 
   6242     return 0;
   6243 }
   6244 
   6245 int radio::requestShutdownResponse(int slotId,
   6246                                   int responseType, int serial, RIL_Errno e,
   6247                                   void *response, size_t responseLen) {
   6248 #if VDBG
   6249     RLOGD("requestShutdownResponse: serial %d", serial);
   6250 #endif
   6251 
   6252     if (radioService[slotId]->mRadioResponse != NULL) {
   6253         RadioResponseInfo responseInfo = {};
   6254         populateResponseInfo(responseInfo, serial, responseType, e);
   6255         Return<void> retStatus
   6256                 = radioService[slotId]->mRadioResponse->requestShutdownResponse(responseInfo);
   6257         radioService[slotId]->checkReturnStatus(retStatus);
   6258     } else {
   6259         RLOGE("requestShutdownResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6260     }
   6261 
   6262     return 0;
   6263 }
   6264 
   6265 void responseRadioCapability(RadioResponseInfo& responseInfo, int serial,
   6266         int responseType, RIL_Errno e, void *response, size_t responseLen, RadioCapability& rc) {
   6267     populateResponseInfo(responseInfo, serial, responseType, e);
   6268 
   6269     if (response == NULL || responseLen != sizeof(RIL_RadioCapability)) {
   6270         RLOGE("responseRadioCapability: Invalid response");
   6271         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6272         rc.logicalModemUuid = hidl_string();
   6273     } else {
   6274         convertRilRadioCapabilityToHal(response, responseLen, rc);
   6275     }
   6276 }
   6277 
   6278 int radio::getRadioCapabilityResponse(int slotId,
   6279                                      int responseType, int serial, RIL_Errno e,
   6280                                      void *response, size_t responseLen) {
   6281 #if VDBG
   6282     RLOGD("getRadioCapabilityResponse: serial %d", serial);
   6283 #endif
   6284 
   6285     if (radioService[slotId]->mRadioResponse != NULL) {
   6286         RadioResponseInfo responseInfo = {};
   6287         RadioCapability result = {};
   6288         responseRadioCapability(responseInfo, serial, responseType, e, response, responseLen,
   6289                 result);
   6290         Return<void> retStatus = radioService[slotId]->mRadioResponse->getRadioCapabilityResponse(
   6291                 responseInfo, result);
   6292         radioService[slotId]->checkReturnStatus(retStatus);
   6293     } else {
   6294         RLOGE("getRadioCapabilityResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6295     }
   6296 
   6297     return 0;
   6298 }
   6299 
   6300 int radio::setRadioCapabilityResponse(int slotId,
   6301                                      int responseType, int serial, RIL_Errno e,
   6302                                      void *response, size_t responseLen) {
   6303 #if VDBG
   6304     RLOGD("setRadioCapabilityResponse: serial %d", serial);
   6305 #endif
   6306 
   6307     if (radioService[slotId]->mRadioResponse != NULL) {
   6308         RadioResponseInfo responseInfo = {};
   6309         RadioCapability result = {};
   6310         responseRadioCapability(responseInfo, serial, responseType, e, response, responseLen,
   6311                 result);
   6312         Return<void> retStatus = radioService[slotId]->mRadioResponse->setRadioCapabilityResponse(
   6313                 responseInfo, result);
   6314         radioService[slotId]->checkReturnStatus(retStatus);
   6315     } else {
   6316         RLOGE("setRadioCapabilityResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6317     }
   6318 
   6319     return 0;
   6320 }
   6321 
   6322 LceStatusInfo responseLceStatusInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
   6323                                     RIL_Errno e, void *response, size_t responseLen) {
   6324     populateResponseInfo(responseInfo, serial, responseType, e);
   6325     LceStatusInfo result = {};
   6326 
   6327     if (response == NULL || responseLen != sizeof(RIL_LceStatusInfo)) {
   6328         RLOGE("Invalid response: NULL");
   6329         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6330     } else {
   6331         RIL_LceStatusInfo *resp = (RIL_LceStatusInfo *) response;
   6332         result.lceStatus = (LceStatus) resp->lce_status;
   6333         result.actualIntervalMs = (uint8_t) resp->actual_interval_ms;
   6334     }
   6335     return result;
   6336 }
   6337 
   6338 int radio::startLceServiceResponse(int slotId,
   6339                                    int responseType, int serial, RIL_Errno e,
   6340                                    void *response, size_t responseLen) {
   6341 #if VDBG
   6342     RLOGD("startLceServiceResponse: serial %d", serial);
   6343 #endif
   6344 
   6345     if (radioService[slotId]->mRadioResponse != NULL) {
   6346         RadioResponseInfo responseInfo = {};
   6347         LceStatusInfo result = responseLceStatusInfo(responseInfo, serial, responseType, e,
   6348                 response, responseLen);
   6349 
   6350         Return<void> retStatus
   6351                 = radioService[slotId]->mRadioResponse->startLceServiceResponse(responseInfo,
   6352                 result);
   6353         radioService[slotId]->checkReturnStatus(retStatus);
   6354     } else {
   6355         RLOGE("startLceServiceResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6356     }
   6357 
   6358     return 0;
   6359 }
   6360 
   6361 int radio::stopLceServiceResponse(int slotId,
   6362                                   int responseType, int serial, RIL_Errno e,
   6363                                   void *response, size_t responseLen) {
   6364 #if VDBG
   6365     RLOGD("stopLceServiceResponse: serial %d", serial);
   6366 #endif
   6367 
   6368     if (radioService[slotId]->mRadioResponse != NULL) {
   6369         RadioResponseInfo responseInfo = {};
   6370         LceStatusInfo result = responseLceStatusInfo(responseInfo, serial, responseType, e,
   6371                 response, responseLen);
   6372 
   6373         Return<void> retStatus
   6374                 = radioService[slotId]->mRadioResponse->stopLceServiceResponse(responseInfo,
   6375                 result);
   6376         radioService[slotId]->checkReturnStatus(retStatus);
   6377     } else {
   6378         RLOGE("stopLceServiceResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6379     }
   6380 
   6381     return 0;
   6382 }
   6383 
   6384 int radio::pullLceDataResponse(int slotId,
   6385                                int responseType, int serial, RIL_Errno e,
   6386                                void *response, size_t responseLen) {
   6387 #if VDBG
   6388     RLOGD("pullLceDataResponse: serial %d", serial);
   6389 #endif
   6390 
   6391     if (radioService[slotId]->mRadioResponse != NULL) {
   6392         RadioResponseInfo responseInfo = {};
   6393         populateResponseInfo(responseInfo, serial, responseType, e);
   6394 
   6395         LceDataInfo result = {};
   6396         if (response == NULL || responseLen != sizeof(RIL_LceDataInfo)) {
   6397             RLOGE("pullLceDataResponse: Invalid response");
   6398             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6399         } else {
   6400             convertRilLceDataInfoToHal(response, responseLen, result);
   6401         }
   6402 
   6403         Return<void> retStatus = radioService[slotId]->mRadioResponse->pullLceDataResponse(
   6404                 responseInfo, result);
   6405         radioService[slotId]->checkReturnStatus(retStatus);
   6406     } else {
   6407         RLOGE("pullLceDataResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6408     }
   6409 
   6410     return 0;
   6411 }
   6412 
   6413 int radio::getModemActivityInfoResponse(int slotId,
   6414                                         int responseType, int serial, RIL_Errno e,
   6415                                         void *response, size_t responseLen) {
   6416 #if VDBG
   6417     RLOGD("getModemActivityInfoResponse: serial %d", serial);
   6418 #endif
   6419 
   6420     if (radioService[slotId]->mRadioResponse != NULL) {
   6421         RadioResponseInfo responseInfo = {};
   6422         populateResponseInfo(responseInfo, serial, responseType, e);
   6423         ActivityStatsInfo info;
   6424         if (response == NULL || responseLen != sizeof(RIL_ActivityStatsInfo)) {
   6425             RLOGE("getModemActivityInfoResponse Invalid response: NULL");
   6426             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6427         } else {
   6428             RIL_ActivityStatsInfo *resp = (RIL_ActivityStatsInfo *)response;
   6429             info.sleepModeTimeMs = resp->sleep_mode_time_ms;
   6430             info.idleModeTimeMs = resp->idle_mode_time_ms;
   6431             for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
   6432                 info.txmModetimeMs[i] = resp->tx_mode_time_ms[i];
   6433             }
   6434             info.rxModeTimeMs = resp->rx_mode_time_ms;
   6435         }
   6436 
   6437         Return<void> retStatus
   6438                 = radioService[slotId]->mRadioResponse->getModemActivityInfoResponse(responseInfo,
   6439                 info);
   6440         radioService[slotId]->checkReturnStatus(retStatus);
   6441     } else {
   6442         RLOGE("getModemActivityInfoResponse: radioService[%d]->mRadioResponse == NULL",
   6443                 slotId);
   6444     }
   6445 
   6446     return 0;
   6447 }
   6448 
   6449 int radio::setAllowedCarriersResponse(int slotId,
   6450                                       int responseType, int serial, RIL_Errno e,
   6451                                       void *response, size_t responseLen) {
   6452 #if VDBG
   6453     RLOGD("setAllowedCarriersResponse: serial %d", serial);
   6454 #endif
   6455 
   6456     if (radioService[slotId]->mRadioResponse != NULL) {
   6457         RadioResponseInfo responseInfo = {};
   6458         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
   6459         Return<void> retStatus
   6460                 = radioService[slotId]->mRadioResponse->setAllowedCarriersResponse(responseInfo,
   6461                 ret);
   6462         radioService[slotId]->checkReturnStatus(retStatus);
   6463     } else {
   6464         RLOGE("setAllowedCarriersResponse: radioService[%d]->mRadioResponse == NULL",
   6465                 slotId);
   6466     }
   6467 
   6468     return 0;
   6469 }
   6470 
   6471 int radio::getAllowedCarriersResponse(int slotId,
   6472                                       int responseType, int serial, RIL_Errno e,
   6473                                       void *response, size_t responseLen) {
   6474 #if VDBG
   6475     RLOGD("getAllowedCarriersResponse: serial %d", serial);
   6476 #endif
   6477 
   6478     if (radioService[slotId]->mRadioResponse != NULL) {
   6479         RadioResponseInfo responseInfo = {};
   6480         populateResponseInfo(responseInfo, serial, responseType, e);
   6481         CarrierRestrictions carrierInfo = {};
   6482         bool allAllowed = true;
   6483         if (response == NULL) {
   6484 #if VDBG
   6485             RLOGD("getAllowedCarriersResponse response is NULL: all allowed");
   6486 #endif
   6487             carrierInfo.allowedCarriers.resize(0);
   6488             carrierInfo.excludedCarriers.resize(0);
   6489         } else if (responseLen != sizeof(RIL_CarrierRestrictions)) {
   6490             RLOGE("getAllowedCarriersResponse Invalid response");
   6491             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6492         } else {
   6493             RIL_CarrierRestrictions *pCr = (RIL_CarrierRestrictions *)response;
   6494             if (pCr->len_allowed_carriers > 0 || pCr->len_excluded_carriers > 0) {
   6495                 allAllowed = false;
   6496             }
   6497 
   6498             carrierInfo.allowedCarriers.resize(pCr->len_allowed_carriers);
   6499             for(int i = 0; i < pCr->len_allowed_carriers; i++) {
   6500                 RIL_Carrier *carrier = pCr->allowed_carriers + i;
   6501                 carrierInfo.allowedCarriers[i].mcc = convertCharPtrToHidlString(carrier->mcc);
   6502                 carrierInfo.allowedCarriers[i].mnc = convertCharPtrToHidlString(carrier->mnc);
   6503                 carrierInfo.allowedCarriers[i].matchType = (CarrierMatchType) carrier->match_type;
   6504                 carrierInfo.allowedCarriers[i].matchData =
   6505                         convertCharPtrToHidlString(carrier->match_data);
   6506             }
   6507 
   6508             carrierInfo.excludedCarriers.resize(pCr->len_excluded_carriers);
   6509             for(int i = 0; i < pCr->len_excluded_carriers; i++) {
   6510                 RIL_Carrier *carrier = pCr->excluded_carriers + i;
   6511                 carrierInfo.excludedCarriers[i].mcc = convertCharPtrToHidlString(carrier->mcc);
   6512                 carrierInfo.excludedCarriers[i].mnc = convertCharPtrToHidlString(carrier->mnc);
   6513                 carrierInfo.excludedCarriers[i].matchType = (CarrierMatchType) carrier->match_type;
   6514                 carrierInfo.excludedCarriers[i].matchData =
   6515                         convertCharPtrToHidlString(carrier->match_data);
   6516             }
   6517         }
   6518 
   6519         Return<void> retStatus
   6520                 = radioService[slotId]->mRadioResponse->getAllowedCarriersResponse(responseInfo,
   6521                 allAllowed, carrierInfo);
   6522         radioService[slotId]->checkReturnStatus(retStatus);
   6523     } else {
   6524         RLOGE("getAllowedCarriersResponse: radioService[%d]->mRadioResponse == NULL",
   6525                 slotId);
   6526     }
   6527 
   6528     return 0;
   6529 }
   6530 
   6531 int radio::sendDeviceStateResponse(int slotId,
   6532                               int responseType, int serial, RIL_Errno e,
   6533                               void *response, size_t responselen) {
   6534 #if VDBG
   6535     RLOGD("sendDeviceStateResponse: serial %d", serial);
   6536 #endif
   6537 
   6538     if (radioService[slotId]->mRadioResponse != NULL) {
   6539         RadioResponseInfo responseInfo = {};
   6540         populateResponseInfo(responseInfo, serial, responseType, e);
   6541         Return<void> retStatus
   6542                 = radioService[slotId]->mRadioResponse->sendDeviceStateResponse(responseInfo);
   6543         radioService[slotId]->checkReturnStatus(retStatus);
   6544     } else {
   6545         RLOGE("sendDeviceStateResponse: radioService[%d]->mRadioResponse == NULL", slotId);
   6546     }
   6547 
   6548     return 0;
   6549 }
   6550 
   6551 int radio::setCarrierInfoForImsiEncryptionResponse(int slotId,
   6552                                int responseType, int serial, RIL_Errno e,
   6553                                void *response, size_t responseLen) {
   6554     RLOGD("setCarrierInfoForImsiEncryptionResponse: serial %d", serial);
   6555     if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
   6556         RadioResponseInfo responseInfo = {};
   6557         populateResponseInfo(responseInfo, serial, responseType, e);
   6558         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_1->
   6559                 setCarrierInfoForImsiEncryptionResponse(responseInfo);
   6560         radioService[slotId]->checkReturnStatus(retStatus);
   6561     } else {
   6562         RLOGE("setCarrierInfoForImsiEncryptionResponse: radioService[%d]->mRadioResponseV1_1 == "
   6563                 "NULL", slotId);
   6564     }
   6565     return 0;
   6566 }
   6567 
   6568 int radio::setIndicationFilterResponse(int slotId,
   6569                               int responseType, int serial, RIL_Errno e,
   6570                               void *response, size_t responselen) {
   6571 #if VDBG
   6572     RLOGD("setIndicationFilterResponse: serial %d", serial);
   6573 #endif
   6574 
   6575     if (radioService[slotId]->mRadioResponse != NULL) {
   6576         RadioResponseInfo responseInfo = {};
   6577         populateResponseInfo(responseInfo, serial, responseType, e);
   6578         Return<void> retStatus
   6579                 = radioService[slotId]->mRadioResponse->setIndicationFilterResponse(responseInfo);
   6580         radioService[slotId]->checkReturnStatus(retStatus);
   6581     } else {
   6582         RLOGE("setIndicationFilterResponse: radioService[%d]->mRadioResponse == NULL",
   6583                 slotId);
   6584     }
   6585 
   6586     return 0;
   6587 }
   6588 
   6589 int radio::setSimCardPowerResponse(int slotId,
   6590                                    int responseType, int serial, RIL_Errno e,
   6591                                    void *response, size_t responseLen) {
   6592 #if VDBG
   6593     RLOGD("setSimCardPowerResponse: serial %d", serial);
   6594 #endif
   6595 
   6596     if (radioService[slotId]->mRadioResponse != NULL
   6597             || radioService[slotId]->mRadioResponseV1_1 != NULL) {
   6598         RadioResponseInfo responseInfo = {};
   6599         populateResponseInfo(responseInfo, serial, responseType, e);
   6600         if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
   6601             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_1->
   6602                     setSimCardPowerResponse_1_1(responseInfo);
   6603             radioService[slotId]->checkReturnStatus(retStatus);
   6604         } else {
   6605             RLOGD("setSimCardPowerResponse: radioService[%d]->mRadioResponseV1_1 == NULL",
   6606                     slotId);
   6607             Return<void> retStatus
   6608                     = radioService[slotId]->mRadioResponse->setSimCardPowerResponse(responseInfo);
   6609             radioService[slotId]->checkReturnStatus(retStatus);
   6610         }
   6611     } else {
   6612         RLOGE("setSimCardPowerResponse: radioService[%d]->mRadioResponse == NULL && "
   6613                 "radioService[%d]->mRadioResponseV1_1 == NULL", slotId, slotId);
   6614     }
   6615     return 0;
   6616 }
   6617 
   6618 int radio::startNetworkScanResponse(int slotId, int responseType, int serial, RIL_Errno e,
   6619                                     void *response, size_t responseLen) {
   6620 #if VDBG
   6621     RLOGD("startNetworkScanResponse: serial %d", serial);
   6622 #endif
   6623 
   6624     if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
   6625         RadioResponseInfo responseInfo = {};
   6626         populateResponseInfo(responseInfo, serial, responseType, e);
   6627         Return<void> retStatus
   6628                 = radioService[slotId]->mRadioResponseV1_1->startNetworkScanResponse(responseInfo);
   6629         radioService[slotId]->checkReturnStatus(retStatus);
   6630     } else {
   6631         RLOGE("startNetworkScanResponse: radioService[%d]->mRadioResponseV1_1 == NULL", slotId);
   6632     }
   6633 
   6634     return 0;
   6635 }
   6636 
   6637 int radio::stopNetworkScanResponse(int slotId, int responseType, int serial, RIL_Errno e,
   6638                                    void *response, size_t responseLen) {
   6639 #if VDBG
   6640     RLOGD("stopNetworkScanResponse: serial %d", serial);
   6641 #endif
   6642 
   6643     if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
   6644         RadioResponseInfo responseInfo = {};
   6645         populateResponseInfo(responseInfo, serial, responseType, e);
   6646         Return<void> retStatus
   6647                 = radioService[slotId]->mRadioResponseV1_1->stopNetworkScanResponse(responseInfo);
   6648         radioService[slotId]->checkReturnStatus(retStatus);
   6649     } else {
   6650         RLOGE("stopNetworkScanResponse: radioService[%d]->mRadioResponseV1_1 == NULL", slotId);
   6651     }
   6652 
   6653     return 0;
   6654 }
   6655 
   6656 void convertRilKeepaliveStatusToHal(const RIL_KeepaliveStatus *rilStatus,
   6657         V1_1::KeepaliveStatus& halStatus) {
   6658     halStatus.sessionHandle = rilStatus->sessionHandle;
   6659     halStatus.code = static_cast<V1_1::KeepaliveStatusCode>(rilStatus->code);
   6660 }
   6661 
   6662 int radio::startKeepaliveResponse(int slotId, int responseType, int serial, RIL_Errno e,
   6663                                     void *response, size_t responseLen) {
   6664 #if VDBG
   6665     RLOGD("%s(): %d", __FUNCTION__, serial);
   6666 #endif
   6667     RadioResponseInfo responseInfo = {};
   6668     populateResponseInfo(responseInfo, serial, responseType, e);
   6669 
   6670     // If we don't have a radio service, there's nothing we can do
   6671     if (radioService[slotId]->mRadioResponseV1_1 == NULL) {
   6672         RLOGE("%s: radioService[%d]->mRadioResponseV1_1 == NULL", __FUNCTION__, slotId);
   6673         return 0;
   6674     }
   6675 
   6676     V1_1::KeepaliveStatus ks = {};
   6677     if (response == NULL || responseLen != sizeof(V1_1::KeepaliveStatus)) {
   6678         RLOGE("%s: invalid response - %d", __FUNCTION__, static_cast<int>(e));
   6679         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6680     } else {
   6681         convertRilKeepaliveStatusToHal(static_cast<RIL_KeepaliveStatus*>(response), ks);
   6682     }
   6683 
   6684     Return<void> retStatus =
   6685             radioService[slotId]->mRadioResponseV1_1->startKeepaliveResponse(responseInfo, ks);
   6686     radioService[slotId]->checkReturnStatus(retStatus);
   6687     return 0;
   6688 }
   6689 
   6690 int radio::stopKeepaliveResponse(int slotId, int responseType, int serial, RIL_Errno e,
   6691                                     void *response, size_t responseLen) {
   6692 #if VDBG
   6693     RLOGD("%s(): %d", __FUNCTION__, serial);
   6694 #endif
   6695     RadioResponseInfo responseInfo = {};
   6696     populateResponseInfo(responseInfo, serial, responseType, e);
   6697 
   6698     // If we don't have a radio service, there's nothing we can do
   6699     if (radioService[slotId]->mRadioResponseV1_1 == NULL) {
   6700         RLOGE("%s: radioService[%d]->mRadioResponseV1_1 == NULL", __FUNCTION__, slotId);
   6701         return 0;
   6702     }
   6703 
   6704     Return<void> retStatus =
   6705             radioService[slotId]->mRadioResponseV1_1->stopKeepaliveResponse(responseInfo);
   6706     radioService[slotId]->checkReturnStatus(retStatus);
   6707     return 0;
   6708 }
   6709 
   6710 int radio::sendRequestRawResponse(int slotId,
   6711                                   int responseType, int serial, RIL_Errno e,
   6712                                   void *response, size_t responseLen) {
   6713 #if VDBG
   6714    RLOGD("sendRequestRawResponse: serial %d", serial);
   6715 #endif
   6716 
   6717     if (!kOemHookEnabled) return 0;
   6718 
   6719     if (oemHookService[slotId]->mOemHookResponse != NULL) {
   6720         RadioResponseInfo responseInfo = {};
   6721         populateResponseInfo(responseInfo, serial, responseType, e);
   6722         hidl_vec<uint8_t> data;
   6723 
   6724         if (response == NULL) {
   6725             RLOGE("sendRequestRawResponse: Invalid response");
   6726             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6727         } else {
   6728             data.setToExternal((uint8_t *) response, responseLen);
   6729         }
   6730         Return<void> retStatus = oemHookService[slotId]->mOemHookResponse->
   6731                 sendRequestRawResponse(responseInfo, data);
   6732         checkReturnStatus(slotId, retStatus, false);
   6733     } else {
   6734         RLOGE("sendRequestRawResponse: oemHookService[%d]->mOemHookResponse == NULL",
   6735                 slotId);
   6736     }
   6737 
   6738     return 0;
   6739 }
   6740 
   6741 int radio::sendRequestStringsResponse(int slotId,
   6742                                       int responseType, int serial, RIL_Errno e,
   6743                                       void *response, size_t responseLen) {
   6744 #if VDBG
   6745     RLOGD("sendRequestStringsResponse: serial %d", serial);
   6746 #endif
   6747 
   6748     if (!kOemHookEnabled) return 0;
   6749 
   6750     if (oemHookService[slotId]->mOemHookResponse != NULL) {
   6751         RadioResponseInfo responseInfo = {};
   6752         populateResponseInfo(responseInfo, serial, responseType, e);
   6753         hidl_vec<hidl_string> data;
   6754 
   6755         if ((response == NULL && responseLen != 0) || responseLen % sizeof(char *) != 0) {
   6756             RLOGE("sendRequestStringsResponse Invalid response: NULL");
   6757             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
   6758         } else {
   6759             char **resp = (char **) response;
   6760             int numStrings = responseLen / sizeof(char *);
   6761             data.resize(numStrings);
   6762             for (int i = 0; i < numStrings; i++) {
   6763                 data[i] = convertCharPtrToHidlString(resp[i]);
   6764             }
   6765         }
   6766         Return<void> retStatus
   6767                 = oemHookService[slotId]->mOemHookResponse->sendRequestStringsResponse(
   6768                 responseInfo, data);
   6769         checkReturnStatus(slotId, retStatus, false);
   6770     } else {
   6771         RLOGE("sendRequestStringsResponse: oemHookService[%d]->mOemHookResponse == "
   6772                 "NULL", slotId);
   6773     }
   6774 
   6775     return 0;
   6776 }
   6777 
   6778 /***************************************************************************************************
   6779  * INDICATION FUNCTIONS
   6780  * The below function handle unsolicited messages coming from the Radio
   6781  * (messages for which there is no pending request)
   6782  **************************************************************************************************/
   6783 
   6784 RadioIndicationType convertIntToRadioIndicationType(int indicationType) {
   6785     return indicationType == RESPONSE_UNSOLICITED ? (RadioIndicationType::UNSOLICITED) :
   6786             (RadioIndicationType::UNSOLICITED_ACK_EXP);
   6787 }
   6788 
   6789 int radio::radioStateChangedInd(int slotId,
   6790                                  int indicationType, int token, RIL_Errno e, void *response,
   6791                                  size_t responseLen) {
   6792     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   6793         RadioState radioState =
   6794                 (RadioState) CALL_ONSTATEREQUEST(slotId);
   6795         RLOGD("radioStateChangedInd: radioState %d", radioState);
   6796         Return<void> retStatus = radioService[slotId]->mRadioIndication->radioStateChanged(
   6797                 convertIntToRadioIndicationType(indicationType), radioState);
   6798         radioService[slotId]->checkReturnStatus(retStatus);
   6799     } else {
   6800         RLOGE("radioStateChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
   6801     }
   6802 
   6803     return 0;
   6804 }
   6805 
   6806 int radio::callStateChangedInd(int slotId,
   6807                                int indicationType, int token, RIL_Errno e, void *response,
   6808                                size_t responseLen) {
   6809     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   6810 #if VDBG
   6811         RLOGD("callStateChangedInd");
   6812 #endif
   6813         Return<void> retStatus = radioService[slotId]->mRadioIndication->callStateChanged(
   6814                 convertIntToRadioIndicationType(indicationType));
   6815         radioService[slotId]->checkReturnStatus(retStatus);
   6816     } else {
   6817         RLOGE("callStateChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
   6818     }
   6819 
   6820     return 0;
   6821 }
   6822 
   6823 int radio::networkStateChangedInd(int slotId,
   6824                                   int indicationType, int token, RIL_Errno e, void *response,
   6825                                   size_t responseLen) {
   6826     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   6827 #if VDBG
   6828         RLOGD("networkStateChangedInd");
   6829 #endif
   6830         Return<void> retStatus = radioService[slotId]->mRadioIndication->networkStateChanged(
   6831                 convertIntToRadioIndicationType(indicationType));
   6832         radioService[slotId]->checkReturnStatus(retStatus);
   6833     } else {
   6834         RLOGE("networkStateChangedInd: radioService[%d]->mRadioIndication == NULL",
   6835                 slotId);
   6836     }
   6837 
   6838     return 0;
   6839 }
   6840 
   6841 uint8_t hexCharToInt(uint8_t c) {
   6842     if (c >= '0' && c <= '9') return (c - '0');
   6843     if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
   6844     if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
   6845 
   6846     return INVALID_HEX_CHAR;
   6847 }
   6848 
   6849 uint8_t * convertHexStringToBytes(void *response, size_t responseLen) {
   6850     if (responseLen % 2 != 0) {
   6851         return NULL;
   6852     }
   6853 
   6854     uint8_t *bytes = (uint8_t *)calloc(responseLen/2, sizeof(uint8_t));
   6855     if (bytes == NULL) {
   6856         RLOGE("convertHexStringToBytes: cannot allocate memory for bytes string");
   6857         return NULL;
   6858     }
   6859     uint8_t *hexString = (uint8_t *)response;
   6860 
   6861     for (size_t i = 0; i < responseLen; i += 2) {
   6862         uint8_t hexChar1 = hexCharToInt(hexString[i]);
   6863         uint8_t hexChar2 = hexCharToInt(hexString[i + 1]);
   6864 
   6865         if (hexChar1 == INVALID_HEX_CHAR || hexChar2 == INVALID_HEX_CHAR) {
   6866             RLOGE("convertHexStringToBytes: invalid hex char %d %d",
   6867                     hexString[i], hexString[i + 1]);
   6868             free(bytes);
   6869             return NULL;
   6870         }
   6871         bytes[i/2] = ((hexChar1 << 4) | hexChar2);
   6872     }
   6873 
   6874     return bytes;
   6875 }
   6876 
   6877 int radio::newSmsInd(int slotId, int indicationType,
   6878                      int token, RIL_Errno e, void *response, size_t responseLen) {
   6879     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   6880         if (response == NULL || responseLen == 0) {
   6881             RLOGE("newSmsInd: invalid response");
   6882             return 0;
   6883         }
   6884 
   6885         uint8_t *bytes = convertHexStringToBytes(response, responseLen);
   6886         if (bytes == NULL) {
   6887             RLOGE("newSmsInd: convertHexStringToBytes failed");
   6888             return 0;
   6889         }
   6890 
   6891         hidl_vec<uint8_t> pdu;
   6892         pdu.setToExternal(bytes, responseLen/2);
   6893 #if VDBG
   6894         RLOGD("newSmsInd");
   6895 #endif
   6896         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSms(
   6897                 convertIntToRadioIndicationType(indicationType), pdu);
   6898         radioService[slotId]->checkReturnStatus(retStatus);
   6899         free(bytes);
   6900     } else {
   6901         RLOGE("newSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
   6902     }
   6903 
   6904     return 0;
   6905 }
   6906 
   6907 int radio::newSmsStatusReportInd(int slotId,
   6908                                  int indicationType, int token, RIL_Errno e, void *response,
   6909                                  size_t responseLen) {
   6910     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   6911         if (response == NULL || responseLen == 0) {
   6912             RLOGE("newSmsStatusReportInd: invalid response");
   6913             return 0;
   6914         }
   6915 
   6916         uint8_t *bytes = convertHexStringToBytes(response, responseLen);
   6917         if (bytes == NULL) {
   6918             RLOGE("newSmsStatusReportInd: convertHexStringToBytes failed");
   6919             return 0;
   6920         }
   6921 
   6922         hidl_vec<uint8_t> pdu;
   6923         pdu.setToExternal(bytes, responseLen/2);
   6924 #if VDBG
   6925         RLOGD("newSmsStatusReportInd");
   6926 #endif
   6927         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSmsStatusReport(
   6928                 convertIntToRadioIndicationType(indicationType), pdu);
   6929         radioService[slotId]->checkReturnStatus(retStatus);
   6930         free(bytes);
   6931     } else {
   6932         RLOGE("newSmsStatusReportInd: radioService[%d]->mRadioIndication == NULL", slotId);
   6933     }
   6934 
   6935     return 0;
   6936 }
   6937 
   6938 int radio::newSmsOnSimInd(int slotId, int indicationType,
   6939                           int token, RIL_Errno e, void *response, size_t responseLen) {
   6940     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   6941         if (response == NULL || responseLen != sizeof(int)) {
   6942             RLOGE("newSmsOnSimInd: invalid response");
   6943             return 0;
   6944         }
   6945         int32_t recordNumber = ((int32_t *) response)[0];
   6946 #if VDBG
   6947         RLOGD("newSmsOnSimInd: slotIndex %d", recordNumber);
   6948 #endif
   6949         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSmsOnSim(
   6950                 convertIntToRadioIndicationType(indicationType), recordNumber);
   6951         radioService[slotId]->checkReturnStatus(retStatus);
   6952     } else {
   6953         RLOGE("newSmsOnSimInd: radioService[%d]->mRadioIndication == NULL", slotId);
   6954     }
   6955 
   6956     return 0;
   6957 }
   6958 
   6959 int radio::onUssdInd(int slotId, int indicationType,
   6960                      int token, RIL_Errno e, void *response, size_t responseLen) {
   6961     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   6962         if (response == NULL || responseLen != 2 * sizeof(char *)) {
   6963             RLOGE("onUssdInd: invalid response");
   6964             return 0;
   6965         }
   6966         char **strings = (char **) response;
   6967         char *mode = strings[0];
   6968         hidl_string msg = convertCharPtrToHidlString(strings[1]);
   6969         UssdModeType modeType = (UssdModeType) atoi(mode);
   6970 #if VDBG
   6971         RLOGD("onUssdInd: mode %s", mode);
   6972 #endif
   6973         Return<void> retStatus = radioService[slotId]->mRadioIndication->onUssd(
   6974                 convertIntToRadioIndicationType(indicationType), modeType, msg);
   6975         radioService[slotId]->checkReturnStatus(retStatus);
   6976     } else {
   6977         RLOGE("onUssdInd: radioService[%d]->mRadioIndication == NULL", slotId);
   6978     }
   6979 
   6980     return 0;
   6981 }
   6982 
   6983 int radio::nitzTimeReceivedInd(int slotId,
   6984                                int indicationType, int token, RIL_Errno e, void *response,
   6985                                size_t responseLen) {
   6986     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   6987         if (response == NULL || responseLen == 0) {
   6988             RLOGE("nitzTimeReceivedInd: invalid response");
   6989             return 0;
   6990         }
   6991         hidl_string nitzTime = convertCharPtrToHidlString((char *) response);
   6992 #if VDBG
   6993         RLOGD("nitzTimeReceivedInd: nitzTime %s receivedTime %" PRId64, nitzTime.c_str(),
   6994                 nitzTimeReceived[slotId]);
   6995 #endif
   6996         Return<void> retStatus = radioService[slotId]->mRadioIndication->nitzTimeReceived(
   6997                 convertIntToRadioIndicationType(indicationType), nitzTime,
   6998                 nitzTimeReceived[slotId]);
   6999         radioService[slotId]->checkReturnStatus(retStatus);
   7000     } else {
   7001         RLOGE("nitzTimeReceivedInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7002         return -1;
   7003     }
   7004 
   7005     return 0;
   7006 }
   7007 
   7008 void convertRilSignalStrengthToHal(void *response, size_t responseLen,
   7009         SignalStrength& signalStrength) {
   7010     RIL_SignalStrength_v10 *rilSignalStrength = (RIL_SignalStrength_v10 *) response;
   7011 
   7012     // Fixup LTE for backwards compatibility
   7013     // signalStrength: -1 -> 99
   7014     if (rilSignalStrength->LTE_SignalStrength.signalStrength == -1) {
   7015         rilSignalStrength->LTE_SignalStrength.signalStrength = 99;
   7016     }
   7017     // rsrp: -1 -> INT_MAX all other negative value to positive.
   7018     // So remap here
   7019     if (rilSignalStrength->LTE_SignalStrength.rsrp == -1) {
   7020         rilSignalStrength->LTE_SignalStrength.rsrp = INT_MAX;
   7021     } else if (rilSignalStrength->LTE_SignalStrength.rsrp < -1) {
   7022         rilSignalStrength->LTE_SignalStrength.rsrp = -rilSignalStrength->LTE_SignalStrength.rsrp;
   7023     }
   7024     // rsrq: -1 -> INT_MAX
   7025     if (rilSignalStrength->LTE_SignalStrength.rsrq == -1) {
   7026         rilSignalStrength->LTE_SignalStrength.rsrq = INT_MAX;
   7027     }
   7028     // Not remapping rssnr is already using INT_MAX
   7029     // cqi: -1 -> INT_MAX
   7030     if (rilSignalStrength->LTE_SignalStrength.cqi == -1) {
   7031         rilSignalStrength->LTE_SignalStrength.cqi = INT_MAX;
   7032     }
   7033 
   7034     signalStrength.gw.signalStrength = rilSignalStrength->GW_SignalStrength.signalStrength;
   7035     signalStrength.gw.bitErrorRate = rilSignalStrength->GW_SignalStrength.bitErrorRate;
   7036     signalStrength.cdma.dbm = rilSignalStrength->CDMA_SignalStrength.dbm;
   7037     signalStrength.cdma.ecio = rilSignalStrength->CDMA_SignalStrength.ecio;
   7038     signalStrength.evdo.dbm = rilSignalStrength->EVDO_SignalStrength.dbm;
   7039     signalStrength.evdo.ecio = rilSignalStrength->EVDO_SignalStrength.ecio;
   7040     signalStrength.evdo.signalNoiseRatio =
   7041             rilSignalStrength->EVDO_SignalStrength.signalNoiseRatio;
   7042     signalStrength.lte.signalStrength = rilSignalStrength->LTE_SignalStrength.signalStrength;
   7043     signalStrength.lte.rsrp = rilSignalStrength->LTE_SignalStrength.rsrp;
   7044     signalStrength.lte.rsrq = rilSignalStrength->LTE_SignalStrength.rsrq;
   7045     signalStrength.lte.rssnr = rilSignalStrength->LTE_SignalStrength.rssnr;
   7046     signalStrength.lte.cqi = rilSignalStrength->LTE_SignalStrength.cqi;
   7047     signalStrength.lte.timingAdvance = rilSignalStrength->LTE_SignalStrength.timingAdvance;
   7048     signalStrength.tdScdma.rscp = rilSignalStrength->TD_SCDMA_SignalStrength.rscp;
   7049 }
   7050 
   7051 int radio::currentSignalStrengthInd(int slotId,
   7052                                     int indicationType, int token, RIL_Errno e,
   7053                                     void *response, size_t responseLen) {
   7054     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7055         if (response == NULL || responseLen != sizeof(RIL_SignalStrength_v10)) {
   7056             RLOGE("currentSignalStrengthInd: invalid response");
   7057             return 0;
   7058         }
   7059 
   7060         SignalStrength signalStrength = {};
   7061         convertRilSignalStrengthToHal(response, responseLen, signalStrength);
   7062 
   7063 #if VDBG
   7064         RLOGD("currentSignalStrengthInd");
   7065 #endif
   7066         Return<void> retStatus = radioService[slotId]->mRadioIndication->currentSignalStrength(
   7067                 convertIntToRadioIndicationType(indicationType), signalStrength);
   7068         radioService[slotId]->checkReturnStatus(retStatus);
   7069     } else {
   7070         RLOGE("currentSignalStrengthInd: radioService[%d]->mRadioIndication == NULL",
   7071                 slotId);
   7072     }
   7073 
   7074     return 0;
   7075 }
   7076 
   7077 void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse,
   7078         SetupDataCallResult& dcResult) {
   7079     dcResult.status = (DataCallFailCause) dcResponse->status;
   7080     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
   7081     dcResult.cid = dcResponse->cid;
   7082     dcResult.active = dcResponse->active;
   7083     dcResult.type = convertCharPtrToHidlString(dcResponse->type);
   7084     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
   7085     dcResult.addresses = convertCharPtrToHidlString(dcResponse->addresses);
   7086     dcResult.dnses = convertCharPtrToHidlString(dcResponse->dnses);
   7087     dcResult.gateways = convertCharPtrToHidlString(dcResponse->gateways);
   7088     dcResult.pcscf = convertCharPtrToHidlString(dcResponse->pcscf);
   7089     dcResult.mtu = dcResponse->mtu;
   7090 }
   7091 
   7092 void convertRilDataCallListToHal(void *response, size_t responseLen,
   7093         hidl_vec<SetupDataCallResult>& dcResultList) {
   7094     int num = responseLen / sizeof(RIL_Data_Call_Response_v11);
   7095 
   7096     RIL_Data_Call_Response_v11 *dcResponse = (RIL_Data_Call_Response_v11 *) response;
   7097     dcResultList.resize(num);
   7098     for (int i = 0; i < num; i++) {
   7099         convertRilDataCallToHal(&dcResponse[i], dcResultList[i]);
   7100     }
   7101 }
   7102 
   7103 int radio::dataCallListChangedInd(int slotId,
   7104                                   int indicationType, int token, RIL_Errno e, void *response,
   7105                                   size_t responseLen) {
   7106     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7107         if ((response == NULL && responseLen != 0)
   7108                 || responseLen % sizeof(RIL_Data_Call_Response_v11) != 0) {
   7109             RLOGE("dataCallListChangedInd: invalid response");
   7110             return 0;
   7111         }
   7112         hidl_vec<SetupDataCallResult> dcList;
   7113         convertRilDataCallListToHal(response, responseLen, dcList);
   7114 #if VDBG
   7115         RLOGD("dataCallListChangedInd");
   7116 #endif
   7117         Return<void> retStatus = radioService[slotId]->mRadioIndication->dataCallListChanged(
   7118                 convertIntToRadioIndicationType(indicationType), dcList);
   7119         radioService[slotId]->checkReturnStatus(retStatus);
   7120     } else {
   7121         RLOGE("dataCallListChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7122     }
   7123 
   7124     return 0;
   7125 }
   7126 
   7127 int radio::suppSvcNotifyInd(int slotId, int indicationType,
   7128                             int token, RIL_Errno e, void *response, size_t responseLen) {
   7129     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7130         if (response == NULL || responseLen != sizeof(RIL_SuppSvcNotification)) {
   7131             RLOGE("suppSvcNotifyInd: invalid response");
   7132             return 0;
   7133         }
   7134 
   7135         SuppSvcNotification suppSvc = {};
   7136         RIL_SuppSvcNotification *ssn = (RIL_SuppSvcNotification *) response;
   7137         suppSvc.isMT = ssn->notificationType;
   7138         suppSvc.code = ssn->code;
   7139         suppSvc.index = ssn->index;
   7140         suppSvc.type = ssn->type;
   7141         suppSvc.number = convertCharPtrToHidlString(ssn->number);
   7142 
   7143 #if VDBG
   7144         RLOGD("suppSvcNotifyInd: isMT %d code %d index %d type %d",
   7145                 suppSvc.isMT, suppSvc.code, suppSvc.index, suppSvc.type);
   7146 #endif
   7147         Return<void> retStatus = radioService[slotId]->mRadioIndication->suppSvcNotify(
   7148                 convertIntToRadioIndicationType(indicationType), suppSvc);
   7149         radioService[slotId]->checkReturnStatus(retStatus);
   7150     } else {
   7151         RLOGE("suppSvcNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7152     }
   7153 
   7154     return 0;
   7155 }
   7156 
   7157 int radio::stkSessionEndInd(int slotId, int indicationType,
   7158                             int token, RIL_Errno e, void *response, size_t responseLen) {
   7159     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7160 #if VDBG
   7161         RLOGD("stkSessionEndInd");
   7162 #endif
   7163         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkSessionEnd(
   7164                 convertIntToRadioIndicationType(indicationType));
   7165         radioService[slotId]->checkReturnStatus(retStatus);
   7166     } else {
   7167         RLOGE("stkSessionEndInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7168     }
   7169 
   7170     return 0;
   7171 }
   7172 
   7173 int radio::stkProactiveCommandInd(int slotId,
   7174                                   int indicationType, int token, RIL_Errno e, void *response,
   7175                                   size_t responseLen) {
   7176     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7177         if (response == NULL || responseLen == 0) {
   7178             RLOGE("stkProactiveCommandInd: invalid response");
   7179             return 0;
   7180         }
   7181 #if VDBG
   7182         RLOGD("stkProactiveCommandInd");
   7183 #endif
   7184         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkProactiveCommand(
   7185                 convertIntToRadioIndicationType(indicationType),
   7186                 convertCharPtrToHidlString((char *) response));
   7187         radioService[slotId]->checkReturnStatus(retStatus);
   7188     } else {
   7189         RLOGE("stkProactiveCommandInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7190     }
   7191 
   7192     return 0;
   7193 }
   7194 
   7195 int radio::stkEventNotifyInd(int slotId, int indicationType,
   7196                              int token, RIL_Errno e, void *response, size_t responseLen) {
   7197     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7198         if (response == NULL || responseLen == 0) {
   7199             RLOGE("stkEventNotifyInd: invalid response");
   7200             return 0;
   7201         }
   7202 #if VDBG
   7203         RLOGD("stkEventNotifyInd");
   7204 #endif
   7205         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkEventNotify(
   7206                 convertIntToRadioIndicationType(indicationType),
   7207                 convertCharPtrToHidlString((char *) response));
   7208         radioService[slotId]->checkReturnStatus(retStatus);
   7209     } else {
   7210         RLOGE("stkEventNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7211     }
   7212 
   7213     return 0;
   7214 }
   7215 
   7216 int radio::stkCallSetupInd(int slotId, int indicationType,
   7217                            int token, RIL_Errno e, void *response, size_t responseLen) {
   7218     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7219         if (response == NULL || responseLen != sizeof(int)) {
   7220             RLOGE("stkCallSetupInd: invalid response");
   7221             return 0;
   7222         }
   7223         int32_t timeout = ((int32_t *) response)[0];
   7224 #if VDBG
   7225         RLOGD("stkCallSetupInd: timeout %d", timeout);
   7226 #endif
   7227         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkCallSetup(
   7228                 convertIntToRadioIndicationType(indicationType), timeout);
   7229         radioService[slotId]->checkReturnStatus(retStatus);
   7230     } else {
   7231         RLOGE("stkCallSetupInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7232     }
   7233 
   7234     return 0;
   7235 }
   7236 
   7237 int radio::simSmsStorageFullInd(int slotId,
   7238                                 int indicationType, int token, RIL_Errno e, void *response,
   7239                                 size_t responseLen) {
   7240     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7241 #if VDBG
   7242         RLOGD("simSmsStorageFullInd");
   7243 #endif
   7244         Return<void> retStatus = radioService[slotId]->mRadioIndication->simSmsStorageFull(
   7245                 convertIntToRadioIndicationType(indicationType));
   7246         radioService[slotId]->checkReturnStatus(retStatus);
   7247     } else {
   7248         RLOGE("simSmsStorageFullInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7249     }
   7250 
   7251     return 0;
   7252 }
   7253 
   7254 int radio::simRefreshInd(int slotId, int indicationType,
   7255                          int token, RIL_Errno e, void *response, size_t responseLen) {
   7256     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7257         if (response == NULL || responseLen != sizeof(RIL_SimRefreshResponse_v7)) {
   7258             RLOGE("simRefreshInd: invalid response");
   7259             return 0;
   7260         }
   7261 
   7262         SimRefreshResult refreshResult = {};
   7263         RIL_SimRefreshResponse_v7 *simRefreshResponse = ((RIL_SimRefreshResponse_v7 *) response);
   7264         refreshResult.type =
   7265                 (V1_0::SimRefreshType) simRefreshResponse->result;
   7266         refreshResult.efId = simRefreshResponse->ef_id;
   7267         refreshResult.aid = convertCharPtrToHidlString(simRefreshResponse->aid);
   7268 
   7269 #if VDBG
   7270         RLOGD("simRefreshInd: type %d efId %d", refreshResult.type, refreshResult.efId);
   7271 #endif
   7272         Return<void> retStatus = radioService[slotId]->mRadioIndication->simRefresh(
   7273                 convertIntToRadioIndicationType(indicationType), refreshResult);
   7274         radioService[slotId]->checkReturnStatus(retStatus);
   7275     } else {
   7276         RLOGE("simRefreshInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7277     }
   7278 
   7279     return 0;
   7280 }
   7281 
   7282 void convertRilCdmaSignalInfoRecordToHal(RIL_CDMA_SignalInfoRecord *signalInfoRecord,
   7283         CdmaSignalInfoRecord& record) {
   7284     record.isPresent = signalInfoRecord->isPresent;
   7285     record.signalType = signalInfoRecord->signalType;
   7286     record.alertPitch = signalInfoRecord->alertPitch;
   7287     record.signal = signalInfoRecord->signal;
   7288 }
   7289 
   7290 int radio::callRingInd(int slotId, int indicationType,
   7291                        int token, RIL_Errno e, void *response, size_t responseLen) {
   7292     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7293         bool isGsm;
   7294         CdmaSignalInfoRecord record = {};
   7295         if (response == NULL || responseLen == 0) {
   7296             isGsm = true;
   7297         } else {
   7298             isGsm = false;
   7299             if (responseLen != sizeof (RIL_CDMA_SignalInfoRecord)) {
   7300                 RLOGE("callRingInd: invalid response");
   7301                 return 0;
   7302             }
   7303             convertRilCdmaSignalInfoRecordToHal((RIL_CDMA_SignalInfoRecord *) response, record);
   7304         }
   7305 
   7306 #if VDBG
   7307         RLOGD("callRingInd: isGsm %d", isGsm);
   7308 #endif
   7309         Return<void> retStatus = radioService[slotId]->mRadioIndication->callRing(
   7310                 convertIntToRadioIndicationType(indicationType), isGsm, record);
   7311         radioService[slotId]->checkReturnStatus(retStatus);
   7312     } else {
   7313         RLOGE("callRingInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7314     }
   7315 
   7316     return 0;
   7317 }
   7318 
   7319 int radio::simStatusChangedInd(int slotId,
   7320                                int indicationType, int token, RIL_Errno e, void *response,
   7321                                size_t responseLen) {
   7322     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7323 #if VDBG
   7324         RLOGD("simStatusChangedInd");
   7325 #endif
   7326         Return<void> retStatus = radioService[slotId]->mRadioIndication->simStatusChanged(
   7327                 convertIntToRadioIndicationType(indicationType));
   7328         radioService[slotId]->checkReturnStatus(retStatus);
   7329     } else {
   7330         RLOGE("simStatusChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7331     }
   7332 
   7333     return 0;
   7334 }
   7335 
   7336 int radio::cdmaNewSmsInd(int slotId, int indicationType,
   7337                          int token, RIL_Errno e, void *response, size_t responseLen) {
   7338     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7339         if (response == NULL || responseLen != sizeof(RIL_CDMA_SMS_Message)) {
   7340             RLOGE("cdmaNewSmsInd: invalid response");
   7341             return 0;
   7342         }
   7343 
   7344         CdmaSmsMessage msg = {};
   7345         RIL_CDMA_SMS_Message *rilMsg = (RIL_CDMA_SMS_Message *) response;
   7346         msg.teleserviceId = rilMsg->uTeleserviceID;
   7347         msg.isServicePresent = rilMsg->bIsServicePresent;
   7348         msg.serviceCategory = rilMsg->uServicecategory;
   7349         msg.address.digitMode =
   7350                 (V1_0::CdmaSmsDigitMode) rilMsg->sAddress.digit_mode;
   7351         msg.address.numberMode =
   7352                 (V1_0::CdmaSmsNumberMode) rilMsg->sAddress.number_mode;
   7353         msg.address.numberType =
   7354                 (V1_0::CdmaSmsNumberType) rilMsg->sAddress.number_type;
   7355         msg.address.numberPlan =
   7356                 (V1_0::CdmaSmsNumberPlan) rilMsg->sAddress.number_plan;
   7357 
   7358         int digitLimit = MIN((rilMsg->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
   7359         msg.address.digits.setToExternal(rilMsg->sAddress.digits, digitLimit);
   7360 
   7361         msg.subAddress.subaddressType = (V1_0::CdmaSmsSubaddressType)
   7362                 rilMsg->sSubAddress.subaddressType;
   7363         msg.subAddress.odd = rilMsg->sSubAddress.odd;
   7364 
   7365         digitLimit= MIN((rilMsg->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
   7366         msg.subAddress.digits.setToExternal(rilMsg->sSubAddress.digits, digitLimit);
   7367 
   7368         digitLimit = MIN((rilMsg->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
   7369         msg.bearerData.setToExternal(rilMsg->aBearerData, digitLimit);
   7370 
   7371 #if VDBG
   7372         RLOGD("cdmaNewSmsInd");
   7373 #endif
   7374         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaNewSms(
   7375                 convertIntToRadioIndicationType(indicationType), msg);
   7376         radioService[slotId]->checkReturnStatus(retStatus);
   7377     } else {
   7378         RLOGE("cdmaNewSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7379     }
   7380 
   7381     return 0;
   7382 }
   7383 
   7384 int radio::newBroadcastSmsInd(int slotId,
   7385                               int indicationType, int token, RIL_Errno e, void *response,
   7386                               size_t responseLen) {
   7387     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7388         if (response == NULL || responseLen == 0) {
   7389             RLOGE("newBroadcastSmsInd: invalid response");
   7390             return 0;
   7391         }
   7392 
   7393         hidl_vec<uint8_t> data;
   7394         data.setToExternal((uint8_t *) response, responseLen);
   7395 #if VDBG
   7396         RLOGD("newBroadcastSmsInd");
   7397 #endif
   7398         Return<void> retStatus = radioService[slotId]->mRadioIndication->newBroadcastSms(
   7399                 convertIntToRadioIndicationType(indicationType), data);
   7400         radioService[slotId]->checkReturnStatus(retStatus);
   7401     } else {
   7402         RLOGE("newBroadcastSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7403     }
   7404 
   7405     return 0;
   7406 }
   7407 
   7408 int radio::cdmaRuimSmsStorageFullInd(int slotId,
   7409                                      int indicationType, int token, RIL_Errno e, void *response,
   7410                                      size_t responseLen) {
   7411     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7412 #if VDBG
   7413         RLOGD("cdmaRuimSmsStorageFullInd");
   7414 #endif
   7415         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaRuimSmsStorageFull(
   7416                 convertIntToRadioIndicationType(indicationType));
   7417         radioService[slotId]->checkReturnStatus(retStatus);
   7418     } else {
   7419         RLOGE("cdmaRuimSmsStorageFullInd: radioService[%d]->mRadioIndication == NULL",
   7420                 slotId);
   7421     }
   7422 
   7423     return 0;
   7424 }
   7425 
   7426 int radio::restrictedStateChangedInd(int slotId,
   7427                                      int indicationType, int token, RIL_Errno e, void *response,
   7428                                      size_t responseLen) {
   7429     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7430         if (response == NULL || responseLen != sizeof(int)) {
   7431             RLOGE("restrictedStateChangedInd: invalid response");
   7432             return 0;
   7433         }
   7434         int32_t state = ((int32_t *) response)[0];
   7435 #if VDBG
   7436         RLOGD("restrictedStateChangedInd: state %d", state);
   7437 #endif
   7438         Return<void> retStatus = radioService[slotId]->mRadioIndication->restrictedStateChanged(
   7439                 convertIntToRadioIndicationType(indicationType), (PhoneRestrictedState) state);
   7440         radioService[slotId]->checkReturnStatus(retStatus);
   7441     } else {
   7442         RLOGE("restrictedStateChangedInd: radioService[%d]->mRadioIndication == NULL",
   7443                 slotId);
   7444     }
   7445 
   7446     return 0;
   7447 }
   7448 
   7449 int radio::enterEmergencyCallbackModeInd(int slotId,
   7450                                          int indicationType, int token, RIL_Errno e, void *response,
   7451                                          size_t responseLen) {
   7452     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7453 #if VDBG
   7454         RLOGD("enterEmergencyCallbackModeInd");
   7455 #endif
   7456         Return<void> retStatus = radioService[slotId]->mRadioIndication->enterEmergencyCallbackMode(
   7457                 convertIntToRadioIndicationType(indicationType));
   7458         radioService[slotId]->checkReturnStatus(retStatus);
   7459     } else {
   7460         RLOGE("enterEmergencyCallbackModeInd: radioService[%d]->mRadioIndication == NULL",
   7461                 slotId);
   7462     }
   7463 
   7464     return 0;
   7465 }
   7466 
   7467 int radio::cdmaCallWaitingInd(int slotId,
   7468                               int indicationType, int token, RIL_Errno e, void *response,
   7469                               size_t responseLen) {
   7470     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7471         if (response == NULL || responseLen != sizeof(RIL_CDMA_CallWaiting_v6)) {
   7472             RLOGE("cdmaCallWaitingInd: invalid response");
   7473             return 0;
   7474         }
   7475 
   7476         CdmaCallWaiting callWaitingRecord = {};
   7477         RIL_CDMA_CallWaiting_v6 *callWaitingRil = ((RIL_CDMA_CallWaiting_v6 *) response);
   7478         callWaitingRecord.number = convertCharPtrToHidlString(callWaitingRil->number);
   7479         callWaitingRecord.numberPresentation =
   7480                 (CdmaCallWaitingNumberPresentation) callWaitingRil->numberPresentation;
   7481         callWaitingRecord.name = convertCharPtrToHidlString(callWaitingRil->name);
   7482         convertRilCdmaSignalInfoRecordToHal(&callWaitingRil->signalInfoRecord,
   7483                 callWaitingRecord.signalInfoRecord);
   7484         callWaitingRecord.numberType = (CdmaCallWaitingNumberType) callWaitingRil->number_type;
   7485         callWaitingRecord.numberPlan = (CdmaCallWaitingNumberPlan) callWaitingRil->number_plan;
   7486 
   7487 #if VDBG
   7488         RLOGD("cdmaCallWaitingInd");
   7489 #endif
   7490         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaCallWaiting(
   7491                 convertIntToRadioIndicationType(indicationType), callWaitingRecord);
   7492         radioService[slotId]->checkReturnStatus(retStatus);
   7493     } else {
   7494         RLOGE("cdmaCallWaitingInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7495     }
   7496 
   7497     return 0;
   7498 }
   7499 
   7500 int radio::cdmaOtaProvisionStatusInd(int slotId,
   7501                                      int indicationType, int token, RIL_Errno e, void *response,
   7502                                      size_t responseLen) {
   7503     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7504         if (response == NULL || responseLen != sizeof(int)) {
   7505             RLOGE("cdmaOtaProvisionStatusInd: invalid response");
   7506             return 0;
   7507         }
   7508         int32_t status = ((int32_t *) response)[0];
   7509 #if VDBG
   7510         RLOGD("cdmaOtaProvisionStatusInd: status %d", status);
   7511 #endif
   7512         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaOtaProvisionStatus(
   7513                 convertIntToRadioIndicationType(indicationType), (CdmaOtaProvisionStatus) status);
   7514         radioService[slotId]->checkReturnStatus(retStatus);
   7515     } else {
   7516         RLOGE("cdmaOtaProvisionStatusInd: radioService[%d]->mRadioIndication == NULL",
   7517                 slotId);
   7518     }
   7519 
   7520     return 0;
   7521 }
   7522 
   7523 int radio::cdmaInfoRecInd(int slotId,
   7524                           int indicationType, int token, RIL_Errno e, void *response,
   7525                           size_t responseLen) {
   7526     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7527         if (response == NULL || responseLen != sizeof(RIL_CDMA_InformationRecords)) {
   7528             RLOGE("cdmaInfoRecInd: invalid response");
   7529             return 0;
   7530         }
   7531 
   7532         CdmaInformationRecords records = {};
   7533         RIL_CDMA_InformationRecords *recordsRil = (RIL_CDMA_InformationRecords *) response;
   7534 
   7535         char* string8 = NULL;
   7536         int num = MIN(recordsRil->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
   7537         if (recordsRil->numberOfInfoRecs > RIL_CDMA_MAX_NUMBER_OF_INFO_RECS) {
   7538             RLOGE("cdmaInfoRecInd: received %d recs which is more than %d, dropping "
   7539                     "additional ones", recordsRil->numberOfInfoRecs,
   7540                     RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
   7541         }
   7542         records.infoRec.resize(num);
   7543         for (int i = 0 ; i < num ; i++) {
   7544             CdmaInformationRecord *record = &records.infoRec[i];
   7545             RIL_CDMA_InformationRecord *infoRec = &recordsRil->infoRec[i];
   7546             record->name = (CdmaInfoRecName) infoRec->name;
   7547             // All vectors should be size 0 except one which will be size 1. Set everything to
   7548             // size 0 initially.
   7549             record->display.resize(0);
   7550             record->number.resize(0);
   7551             record->signal.resize(0);
   7552             record->redir.resize(0);
   7553             record->lineCtrl.resize(0);
   7554             record->clir.resize(0);
   7555             record->audioCtrl.resize(0);
   7556             switch (infoRec->name) {
   7557                 case RIL_CDMA_DISPLAY_INFO_REC:
   7558                 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC: {
   7559                     if (infoRec->rec.display.alpha_len > CDMA_ALPHA_INFO_BUFFER_LENGTH) {
   7560                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
   7561                                 "expected not more than %d", (int) infoRec->rec.display.alpha_len,
   7562                                 CDMA_ALPHA_INFO_BUFFER_LENGTH);
   7563                         return 0;
   7564                     }
   7565                     string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1) * sizeof(char));
   7566                     if (string8 == NULL) {
   7567                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
   7568                                 "responseCdmaInformationRecords");
   7569                         return 0;
   7570                     }
   7571                     memcpy(string8, infoRec->rec.display.alpha_buf, infoRec->rec.display.alpha_len);
   7572                     string8[(int)infoRec->rec.display.alpha_len] = '\0';
   7573 
   7574                     record->display.resize(1);
   7575                     record->display[0].alphaBuf = string8;
   7576                     free(string8);
   7577                     string8 = NULL;
   7578                     break;
   7579                 }
   7580 
   7581                 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
   7582                 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
   7583                 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC: {
   7584                     if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
   7585                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
   7586                                 "expected not more than %d", (int) infoRec->rec.number.len,
   7587                                 CDMA_NUMBER_INFO_BUFFER_LENGTH);
   7588                         return 0;
   7589                     }
   7590                     string8 = (char*) malloc((infoRec->rec.number.len + 1) * sizeof(char));
   7591                     if (string8 == NULL) {
   7592                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
   7593                                 "responseCdmaInformationRecords");
   7594                         return 0;
   7595                     }
   7596                     memcpy(string8, infoRec->rec.number.buf, infoRec->rec.number.len);
   7597                     string8[(int)infoRec->rec.number.len] = '\0';
   7598 
   7599                     record->number.resize(1);
   7600                     record->number[0].number = string8;
   7601                     free(string8);
   7602                     string8 = NULL;
   7603                     record->number[0].numberType = infoRec->rec.number.number_type;
   7604                     record->number[0].numberPlan = infoRec->rec.number.number_plan;
   7605                     record->number[0].pi = infoRec->rec.number.pi;
   7606                     record->number[0].si = infoRec->rec.number.si;
   7607                     break;
   7608                 }
   7609 
   7610                 case RIL_CDMA_SIGNAL_INFO_REC: {
   7611                     record->signal.resize(1);
   7612                     record->signal[0].isPresent = infoRec->rec.signal.isPresent;
   7613                     record->signal[0].signalType = infoRec->rec.signal.signalType;
   7614                     record->signal[0].alertPitch = infoRec->rec.signal.alertPitch;
   7615                     record->signal[0].signal = infoRec->rec.signal.signal;
   7616                     break;
   7617                 }
   7618 
   7619                 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC: {
   7620                     if (infoRec->rec.redir.redirectingNumber.len >
   7621                                                   CDMA_NUMBER_INFO_BUFFER_LENGTH) {
   7622                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
   7623                                 "expected not more than %d\n",
   7624                                 (int)infoRec->rec.redir.redirectingNumber.len,
   7625                                 CDMA_NUMBER_INFO_BUFFER_LENGTH);
   7626                         return 0;
   7627                     }
   7628                     string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber.len + 1) *
   7629                             sizeof(char));
   7630                     if (string8 == NULL) {
   7631                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
   7632                                 "responseCdmaInformationRecords");
   7633                         return 0;
   7634                     }
   7635                     memcpy(string8, infoRec->rec.redir.redirectingNumber.buf,
   7636                             infoRec->rec.redir.redirectingNumber.len);
   7637                     string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
   7638 
   7639                     record->redir.resize(1);
   7640                     record->redir[0].redirectingNumber.number = string8;
   7641                     free(string8);
   7642                     string8 = NULL;
   7643                     record->redir[0].redirectingNumber.numberType =
   7644                             infoRec->rec.redir.redirectingNumber.number_type;
   7645                     record->redir[0].redirectingNumber.numberPlan =
   7646                             infoRec->rec.redir.redirectingNumber.number_plan;
   7647                     record->redir[0].redirectingNumber.pi = infoRec->rec.redir.redirectingNumber.pi;
   7648                     record->redir[0].redirectingNumber.si = infoRec->rec.redir.redirectingNumber.si;
   7649                     record->redir[0].redirectingReason =
   7650                             (CdmaRedirectingReason) infoRec->rec.redir.redirectingReason;
   7651                     break;
   7652                 }
   7653 
   7654                 case RIL_CDMA_LINE_CONTROL_INFO_REC: {
   7655                     record->lineCtrl.resize(1);
   7656                     record->lineCtrl[0].lineCtrlPolarityIncluded =
   7657                             infoRec->rec.lineCtrl.lineCtrlPolarityIncluded;
   7658                     record->lineCtrl[0].lineCtrlToggle = infoRec->rec.lineCtrl.lineCtrlToggle;
   7659                     record->lineCtrl[0].lineCtrlReverse = infoRec->rec.lineCtrl.lineCtrlReverse;
   7660                     record->lineCtrl[0].lineCtrlPowerDenial =
   7661                             infoRec->rec.lineCtrl.lineCtrlPowerDenial;
   7662                     break;
   7663                 }
   7664 
   7665                 case RIL_CDMA_T53_CLIR_INFO_REC: {
   7666                     record->clir.resize(1);
   7667                     record->clir[0].cause = infoRec->rec.clir.cause;
   7668                     break;
   7669                 }
   7670 
   7671                 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC: {
   7672                     record->audioCtrl.resize(1);
   7673                     record->audioCtrl[0].upLink = infoRec->rec.audioCtrl.upLink;
   7674                     record->audioCtrl[0].downLink = infoRec->rec.audioCtrl.downLink;
   7675                     break;
   7676                 }
   7677 
   7678                 case RIL_CDMA_T53_RELEASE_INFO_REC:
   7679                     RLOGE("cdmaInfoRecInd: RIL_CDMA_T53_RELEASE_INFO_REC: INVALID");
   7680                     return 0;
   7681 
   7682                 default:
   7683                     RLOGE("cdmaInfoRecInd: Incorrect name value");
   7684                     return 0;
   7685             }
   7686         }
   7687 
   7688 #if VDBG
   7689         RLOGD("cdmaInfoRecInd");
   7690 #endif
   7691         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaInfoRec(
   7692                 convertIntToRadioIndicationType(indicationType), records);
   7693         radioService[slotId]->checkReturnStatus(retStatus);
   7694     } else {
   7695         RLOGE("cdmaInfoRecInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7696     }
   7697 
   7698     return 0;
   7699 }
   7700 
   7701 int radio::indicateRingbackToneInd(int slotId,
   7702                                    int indicationType, int token, RIL_Errno e, void *response,
   7703                                    size_t responseLen) {
   7704     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7705         if (response == NULL || responseLen != sizeof(int)) {
   7706             RLOGE("indicateRingbackToneInd: invalid response");
   7707             return 0;
   7708         }
   7709         bool start = ((int32_t *) response)[0];
   7710 #if VDBG
   7711         RLOGD("indicateRingbackToneInd: start %d", start);
   7712 #endif
   7713         Return<void> retStatus = radioService[slotId]->mRadioIndication->indicateRingbackTone(
   7714                 convertIntToRadioIndicationType(indicationType), start);
   7715         radioService[slotId]->checkReturnStatus(retStatus);
   7716     } else {
   7717         RLOGE("indicateRingbackToneInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7718     }
   7719 
   7720     return 0;
   7721 }
   7722 
   7723 int radio::resendIncallMuteInd(int slotId,
   7724                                int indicationType, int token, RIL_Errno e, void *response,
   7725                                size_t responseLen) {
   7726     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7727 #if VDBG
   7728         RLOGD("resendIncallMuteInd");
   7729 #endif
   7730         Return<void> retStatus = radioService[slotId]->mRadioIndication->resendIncallMute(
   7731                 convertIntToRadioIndicationType(indicationType));
   7732         radioService[slotId]->checkReturnStatus(retStatus);
   7733     } else {
   7734         RLOGE("resendIncallMuteInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7735     }
   7736 
   7737     return 0;
   7738 }
   7739 
   7740 int radio::cdmaSubscriptionSourceChangedInd(int slotId,
   7741                                             int indicationType, int token, RIL_Errno e,
   7742                                             void *response, size_t responseLen) {
   7743     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7744         if (response == NULL || responseLen != sizeof(int)) {
   7745             RLOGE("cdmaSubscriptionSourceChangedInd: invalid response");
   7746             return 0;
   7747         }
   7748         int32_t cdmaSource = ((int32_t *) response)[0];
   7749 #if VDBG
   7750         RLOGD("cdmaSubscriptionSourceChangedInd: cdmaSource %d", cdmaSource);
   7751 #endif
   7752         Return<void> retStatus = radioService[slotId]->mRadioIndication->
   7753                 cdmaSubscriptionSourceChanged(convertIntToRadioIndicationType(indicationType),
   7754                 (CdmaSubscriptionSource) cdmaSource);
   7755         radioService[slotId]->checkReturnStatus(retStatus);
   7756     } else {
   7757         RLOGE("cdmaSubscriptionSourceChangedInd: radioService[%d]->mRadioIndication == NULL",
   7758                 slotId);
   7759     }
   7760 
   7761     return 0;
   7762 }
   7763 
   7764 int radio::cdmaPrlChangedInd(int slotId,
   7765                              int indicationType, int token, RIL_Errno e, void *response,
   7766                              size_t responseLen) {
   7767     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7768         if (response == NULL || responseLen != sizeof(int)) {
   7769             RLOGE("cdmaPrlChangedInd: invalid response");
   7770             return 0;
   7771         }
   7772         int32_t version = ((int32_t *) response)[0];
   7773 #if VDBG
   7774         RLOGD("cdmaPrlChangedInd: version %d", version);
   7775 #endif
   7776         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaPrlChanged(
   7777                 convertIntToRadioIndicationType(indicationType), version);
   7778         radioService[slotId]->checkReturnStatus(retStatus);
   7779     } else {
   7780         RLOGE("cdmaPrlChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7781     }
   7782 
   7783     return 0;
   7784 }
   7785 
   7786 int radio::exitEmergencyCallbackModeInd(int slotId,
   7787                                         int indicationType, int token, RIL_Errno e, void *response,
   7788                                         size_t responseLen) {
   7789     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7790 #if VDBG
   7791         RLOGD("exitEmergencyCallbackModeInd");
   7792 #endif
   7793         Return<void> retStatus = radioService[slotId]->mRadioIndication->exitEmergencyCallbackMode(
   7794                 convertIntToRadioIndicationType(indicationType));
   7795         radioService[slotId]->checkReturnStatus(retStatus);
   7796     } else {
   7797         RLOGE("exitEmergencyCallbackModeInd: radioService[%d]->mRadioIndication == NULL",
   7798                 slotId);
   7799     }
   7800 
   7801     return 0;
   7802 }
   7803 
   7804 int radio::rilConnectedInd(int slotId,
   7805                            int indicationType, int token, RIL_Errno e, void *response,
   7806                            size_t responseLen) {
   7807     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7808         RLOGD("rilConnectedInd");
   7809         Return<void> retStatus = radioService[slotId]->mRadioIndication->rilConnected(
   7810                 convertIntToRadioIndicationType(indicationType));
   7811         radioService[slotId]->checkReturnStatus(retStatus);
   7812     } else {
   7813         RLOGE("rilConnectedInd: radioService[%d]->mRadioIndication == NULL", slotId);
   7814     }
   7815 
   7816     return 0;
   7817 }
   7818 
   7819 int radio::voiceRadioTechChangedInd(int slotId,
   7820                                     int indicationType, int token, RIL_Errno e, void *response,
   7821                                     size_t responseLen) {
   7822     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7823         if (response == NULL || responseLen != sizeof(int)) {
   7824             RLOGE("voiceRadioTechChangedInd: invalid response");
   7825             return 0;
   7826         }
   7827         int32_t rat = ((int32_t *) response)[0];
   7828 #if VDBG
   7829         RLOGD("voiceRadioTechChangedInd: rat %d", rat);
   7830 #endif
   7831         Return<void> retStatus = radioService[slotId]->mRadioIndication->voiceRadioTechChanged(
   7832                 convertIntToRadioIndicationType(indicationType), (RadioTechnology) rat);
   7833         radioService[slotId]->checkReturnStatus(retStatus);
   7834     } else {
   7835         RLOGE("voiceRadioTechChangedInd: radioService[%d]->mRadioIndication == NULL",
   7836                 slotId);
   7837     }
   7838 
   7839     return 0;
   7840 }
   7841 
   7842 void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<CellInfo>& records) {
   7843     int num = responseLen / sizeof(RIL_CellInfo_v12);
   7844     records.resize(num);
   7845 
   7846     RIL_CellInfo_v12 *rillCellInfo = (RIL_CellInfo_v12 *) response;
   7847     for (int i = 0; i < num; i++) {
   7848         records[i].cellInfoType = (CellInfoType) rillCellInfo->cellInfoType;
   7849         records[i].registered = rillCellInfo->registered;
   7850         records[i].timeStampType = (TimeStampType) rillCellInfo->timeStampType;
   7851         records[i].timeStamp = rillCellInfo->timeStamp;
   7852         // All vectors should be size 0 except one which will be size 1. Set everything to
   7853         // size 0 initially.
   7854         records[i].gsm.resize(0);
   7855         records[i].wcdma.resize(0);
   7856         records[i].cdma.resize(0);
   7857         records[i].lte.resize(0);
   7858         records[i].tdscdma.resize(0);
   7859         switch(rillCellInfo->cellInfoType) {
   7860             case RIL_CELL_INFO_TYPE_GSM: {
   7861                 records[i].gsm.resize(1);
   7862                 CellInfoGsm *cellInfoGsm = &records[i].gsm[0];
   7863                 cellInfoGsm->cellIdentityGsm.mcc =
   7864                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
   7865                 cellInfoGsm->cellIdentityGsm.mnc =
   7866                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
   7867                 cellInfoGsm->cellIdentityGsm.lac =
   7868                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
   7869                 cellInfoGsm->cellIdentityGsm.cid =
   7870                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
   7871                 cellInfoGsm->cellIdentityGsm.arfcn =
   7872                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
   7873                 cellInfoGsm->cellIdentityGsm.bsic =
   7874                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
   7875                 cellInfoGsm->signalStrengthGsm.signalStrength =
   7876                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
   7877                 cellInfoGsm->signalStrengthGsm.bitErrorRate =
   7878                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
   7879                 cellInfoGsm->signalStrengthGsm.timingAdvance =
   7880                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
   7881                 break;
   7882             }
   7883 
   7884             case RIL_CELL_INFO_TYPE_WCDMA: {
   7885                 records[i].wcdma.resize(1);
   7886                 CellInfoWcdma *cellInfoWcdma = &records[i].wcdma[0];
   7887                 cellInfoWcdma->cellIdentityWcdma.mcc =
   7888                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
   7889                 cellInfoWcdma->cellIdentityWcdma.mnc =
   7890                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
   7891                 cellInfoWcdma->cellIdentityWcdma.lac =
   7892                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
   7893                 cellInfoWcdma->cellIdentityWcdma.cid =
   7894                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
   7895                 cellInfoWcdma->cellIdentityWcdma.psc =
   7896                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
   7897                 cellInfoWcdma->cellIdentityWcdma.uarfcn =
   7898                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
   7899                 cellInfoWcdma->signalStrengthWcdma.signalStrength =
   7900                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
   7901                 cellInfoWcdma->signalStrengthWcdma.bitErrorRate =
   7902                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
   7903                 break;
   7904             }
   7905 
   7906             case RIL_CELL_INFO_TYPE_CDMA: {
   7907                 records[i].cdma.resize(1);
   7908                 CellInfoCdma *cellInfoCdma = &records[i].cdma[0];
   7909                 cellInfoCdma->cellIdentityCdma.networkId =
   7910                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
   7911                 cellInfoCdma->cellIdentityCdma.systemId =
   7912                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
   7913                 cellInfoCdma->cellIdentityCdma.baseStationId =
   7914                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
   7915                 cellInfoCdma->cellIdentityCdma.longitude =
   7916                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
   7917                 cellInfoCdma->cellIdentityCdma.latitude =
   7918                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
   7919                 cellInfoCdma->signalStrengthCdma.dbm =
   7920                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
   7921                 cellInfoCdma->signalStrengthCdma.ecio =
   7922                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
   7923                 cellInfoCdma->signalStrengthEvdo.dbm =
   7924                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
   7925                 cellInfoCdma->signalStrengthEvdo.ecio =
   7926                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
   7927                 cellInfoCdma->signalStrengthEvdo.signalNoiseRatio =
   7928                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
   7929                 break;
   7930             }
   7931 
   7932             case RIL_CELL_INFO_TYPE_LTE: {
   7933                 records[i].lte.resize(1);
   7934                 CellInfoLte *cellInfoLte = &records[i].lte[0];
   7935                 cellInfoLte->cellIdentityLte.mcc =
   7936                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
   7937                 cellInfoLte->cellIdentityLte.mnc =
   7938                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
   7939                 cellInfoLte->cellIdentityLte.ci =
   7940                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
   7941                 cellInfoLte->cellIdentityLte.pci =
   7942                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
   7943                 cellInfoLte->cellIdentityLte.tac =
   7944                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
   7945                 cellInfoLte->cellIdentityLte.earfcn =
   7946                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
   7947                 cellInfoLte->signalStrengthLte.signalStrength =
   7948                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
   7949                 cellInfoLte->signalStrengthLte.rsrp =
   7950                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
   7951                 cellInfoLte->signalStrengthLte.rsrq =
   7952                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
   7953                 cellInfoLte->signalStrengthLte.rssnr =
   7954                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
   7955                 cellInfoLte->signalStrengthLte.cqi =
   7956                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
   7957                 cellInfoLte->signalStrengthLte.timingAdvance =
   7958                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
   7959                 break;
   7960             }
   7961 
   7962             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
   7963                 records[i].tdscdma.resize(1);
   7964                 CellInfoTdscdma *cellInfoTdscdma = &records[i].tdscdma[0];
   7965                 cellInfoTdscdma->cellIdentityTdscdma.mcc =
   7966                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
   7967                 cellInfoTdscdma->cellIdentityTdscdma.mnc =
   7968                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
   7969                 cellInfoTdscdma->cellIdentityTdscdma.lac =
   7970                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
   7971                 cellInfoTdscdma->cellIdentityTdscdma.cid =
   7972                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
   7973                 cellInfoTdscdma->cellIdentityTdscdma.cpid =
   7974                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
   7975                 cellInfoTdscdma->signalStrengthTdscdma.rscp =
   7976                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
   7977                 break;
   7978             }
   7979             default: {
   7980                 break;
   7981             }
   7982         }
   7983         rillCellInfo += 1;
   7984     }
   7985 }
   7986 
   7987 int radio::cellInfoListInd(int slotId,
   7988                            int indicationType, int token, RIL_Errno e, void *response,
   7989                            size_t responseLen) {
   7990     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   7991         if ((response == NULL && responseLen != 0) || responseLen % sizeof(RIL_CellInfo_v12) != 0) {
   7992             RLOGE("cellInfoListInd: invalid response");
   7993             return 0;
   7994         }
   7995 
   7996         hidl_vec<CellInfo> records;
   7997         convertRilCellInfoListToHal(response, responseLen, records);
   7998 
   7999 #if VDBG
   8000         RLOGD("cellInfoListInd");
   8001 #endif
   8002         Return<void> retStatus = radioService[slotId]->mRadioIndication->cellInfoList(
   8003                 convertIntToRadioIndicationType(indicationType), records);
   8004         radioService[slotId]->checkReturnStatus(retStatus);
   8005     } else {
   8006         RLOGE("cellInfoListInd: radioService[%d]->mRadioIndication == NULL", slotId);
   8007     }
   8008 
   8009     return 0;
   8010 }
   8011 
   8012 int radio::imsNetworkStateChangedInd(int slotId,
   8013                                      int indicationType, int token, RIL_Errno e, void *response,
   8014                                      size_t responseLen) {
   8015     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8016 #if VDBG
   8017         RLOGD("imsNetworkStateChangedInd");
   8018 #endif
   8019         Return<void> retStatus = radioService[slotId]->mRadioIndication->imsNetworkStateChanged(
   8020                 convertIntToRadioIndicationType(indicationType));
   8021         radioService[slotId]->checkReturnStatus(retStatus);
   8022     } else {
   8023         RLOGE("imsNetworkStateChangedInd: radioService[%d]->mRadioIndication == NULL",
   8024                 slotId);
   8025     }
   8026 
   8027     return 0;
   8028 }
   8029 
   8030 int radio::subscriptionStatusChangedInd(int slotId,
   8031                                         int indicationType, int token, RIL_Errno e, void *response,
   8032                                         size_t responseLen) {
   8033     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8034         if (response == NULL || responseLen != sizeof(int)) {
   8035             RLOGE("subscriptionStatusChangedInd: invalid response");
   8036             return 0;
   8037         }
   8038         bool activate = ((int32_t *) response)[0];
   8039 #if VDBG
   8040         RLOGD("subscriptionStatusChangedInd: activate %d", activate);
   8041 #endif
   8042         Return<void> retStatus = radioService[slotId]->mRadioIndication->subscriptionStatusChanged(
   8043                 convertIntToRadioIndicationType(indicationType), activate);
   8044         radioService[slotId]->checkReturnStatus(retStatus);
   8045     } else {
   8046         RLOGE("subscriptionStatusChangedInd: radioService[%d]->mRadioIndication == NULL",
   8047                 slotId);
   8048     }
   8049 
   8050     return 0;
   8051 }
   8052 
   8053 int radio::srvccStateNotifyInd(int slotId,
   8054                                int indicationType, int token, RIL_Errno e, void *response,
   8055                                size_t responseLen) {
   8056     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8057         if (response == NULL || responseLen != sizeof(int)) {
   8058             RLOGE("srvccStateNotifyInd: invalid response");
   8059             return 0;
   8060         }
   8061         int32_t state = ((int32_t *) response)[0];
   8062 #if VDBG
   8063         RLOGD("srvccStateNotifyInd: rat %d", state);
   8064 #endif
   8065         Return<void> retStatus = radioService[slotId]->mRadioIndication->srvccStateNotify(
   8066                 convertIntToRadioIndicationType(indicationType), (SrvccState) state);
   8067         radioService[slotId]->checkReturnStatus(retStatus);
   8068     } else {
   8069         RLOGE("srvccStateNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
   8070     }
   8071 
   8072     return 0;
   8073 }
   8074 
   8075 void convertRilHardwareConfigListToHal(void *response, size_t responseLen,
   8076         hidl_vec<HardwareConfig>& records) {
   8077     int num = responseLen / sizeof(RIL_HardwareConfig);
   8078     records.resize(num);
   8079 
   8080     RIL_HardwareConfig *rilHardwareConfig = (RIL_HardwareConfig *) response;
   8081     for (int i = 0; i < num; i++) {
   8082         records[i].type = (HardwareConfigType) rilHardwareConfig[i].type;
   8083         records[i].uuid = convertCharPtrToHidlString(rilHardwareConfig[i].uuid);
   8084         records[i].state = (HardwareConfigState) rilHardwareConfig[i].state;
   8085         switch (rilHardwareConfig[i].type) {
   8086             case RIL_HARDWARE_CONFIG_MODEM: {
   8087                 records[i].modem.resize(1);
   8088                 records[i].sim.resize(0);
   8089                 HardwareConfigModem *hwConfigModem = &records[i].modem[0];
   8090                 hwConfigModem->rat = rilHardwareConfig[i].cfg.modem.rat;
   8091                 hwConfigModem->maxVoice = rilHardwareConfig[i].cfg.modem.maxVoice;
   8092                 hwConfigModem->maxData = rilHardwareConfig[i].cfg.modem.maxData;
   8093                 hwConfigModem->maxStandby = rilHardwareConfig[i].cfg.modem.maxStandby;
   8094                 break;
   8095             }
   8096 
   8097             case RIL_HARDWARE_CONFIG_SIM: {
   8098                 records[i].sim.resize(1);
   8099                 records[i].modem.resize(0);
   8100                 records[i].sim[0].modemUuid =
   8101                         convertCharPtrToHidlString(rilHardwareConfig[i].cfg.sim.modemUuid);
   8102                 break;
   8103             }
   8104         }
   8105     }
   8106 }
   8107 
   8108 int radio::hardwareConfigChangedInd(int slotId,
   8109                                     int indicationType, int token, RIL_Errno e, void *response,
   8110                                     size_t responseLen) {
   8111     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8112         if ((response == NULL && responseLen != 0)
   8113                 || responseLen % sizeof(RIL_HardwareConfig) != 0) {
   8114             RLOGE("hardwareConfigChangedInd: invalid response");
   8115             return 0;
   8116         }
   8117 
   8118         hidl_vec<HardwareConfig> configs;
   8119         convertRilHardwareConfigListToHal(response, responseLen, configs);
   8120 
   8121 #if VDBG
   8122         RLOGD("hardwareConfigChangedInd");
   8123 #endif
   8124         Return<void> retStatus = radioService[slotId]->mRadioIndication->hardwareConfigChanged(
   8125                 convertIntToRadioIndicationType(indicationType), configs);
   8126         radioService[slotId]->checkReturnStatus(retStatus);
   8127     } else {
   8128         RLOGE("hardwareConfigChangedInd: radioService[%d]->mRadioIndication == NULL",
   8129                 slotId);
   8130     }
   8131 
   8132     return 0;
   8133 }
   8134 
   8135 void convertRilRadioCapabilityToHal(void *response, size_t responseLen, RadioCapability& rc) {
   8136     RIL_RadioCapability *rilRadioCapability = (RIL_RadioCapability *) response;
   8137     rc.session = rilRadioCapability->session;
   8138     rc.phase = (V1_0::RadioCapabilityPhase) rilRadioCapability->phase;
   8139     rc.raf = rilRadioCapability->rat;
   8140     rc.logicalModemUuid = convertCharPtrToHidlString(rilRadioCapability->logicalModemUuid);
   8141     rc.status = (V1_0::RadioCapabilityStatus) rilRadioCapability->status;
   8142 }
   8143 
   8144 int radio::radioCapabilityIndicationInd(int slotId,
   8145                                         int indicationType, int token, RIL_Errno e, void *response,
   8146                                         size_t responseLen) {
   8147     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8148         if (response == NULL || responseLen != sizeof(RIL_RadioCapability)) {
   8149             RLOGE("radioCapabilityIndicationInd: invalid response");
   8150             return 0;
   8151         }
   8152 
   8153         RadioCapability rc = {};
   8154         convertRilRadioCapabilityToHal(response, responseLen, rc);
   8155 
   8156 #if VDBG
   8157         RLOGD("radioCapabilityIndicationInd");
   8158 #endif
   8159         Return<void> retStatus = radioService[slotId]->mRadioIndication->radioCapabilityIndication(
   8160                 convertIntToRadioIndicationType(indicationType), rc);
   8161         radioService[slotId]->checkReturnStatus(retStatus);
   8162     } else {
   8163         RLOGE("radioCapabilityIndicationInd: radioService[%d]->mRadioIndication == NULL",
   8164                 slotId);
   8165     }
   8166 
   8167     return 0;
   8168 }
   8169 
   8170 bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
   8171     if ((reqType == SS_INTERROGATION) &&
   8172         (serType == SS_CFU ||
   8173          serType == SS_CF_BUSY ||
   8174          serType == SS_CF_NO_REPLY ||
   8175          serType == SS_CF_NOT_REACHABLE ||
   8176          serType == SS_CF_ALL ||
   8177          serType == SS_CF_ALL_CONDITIONAL)) {
   8178         return true;
   8179     }
   8180     return false;
   8181 }
   8182 
   8183 int radio::onSupplementaryServiceIndicationInd(int slotId,
   8184                                                int indicationType, int token, RIL_Errno e,
   8185                                                void *response, size_t responseLen) {
   8186     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8187         if (response == NULL || responseLen != sizeof(RIL_StkCcUnsolSsResponse)) {
   8188             RLOGE("onSupplementaryServiceIndicationInd: invalid response");
   8189             return 0;
   8190         }
   8191 
   8192         RIL_StkCcUnsolSsResponse *rilSsResponse = (RIL_StkCcUnsolSsResponse *) response;
   8193         StkCcUnsolSsResult ss = {};
   8194         ss.serviceType = (SsServiceType) rilSsResponse->serviceType;
   8195         ss.requestType = (SsRequestType) rilSsResponse->requestType;
   8196         ss.teleserviceType = (SsTeleserviceType) rilSsResponse->teleserviceType;
   8197         ss.serviceClass = rilSsResponse->serviceClass;
   8198         ss.result = (RadioError) rilSsResponse->result;
   8199 
   8200         if (isServiceTypeCfQuery(rilSsResponse->serviceType, rilSsResponse->requestType)) {
   8201 #if VDBG
   8202             RLOGD("onSupplementaryServiceIndicationInd CF type, num of Cf elements %d",
   8203                     rilSsResponse->cfData.numValidIndexes);
   8204 #endif
   8205             if (rilSsResponse->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
   8206                 RLOGE("onSupplementaryServiceIndicationInd numValidIndexes is greater than "
   8207                         "max value %d, truncating it to max value", NUM_SERVICE_CLASSES);
   8208                 rilSsResponse->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
   8209             }
   8210 
   8211             ss.cfData.resize(1);
   8212             ss.ssInfo.resize(0);
   8213 
   8214             /* number of call info's */
   8215             ss.cfData[0].cfInfo.resize(rilSsResponse->cfData.numValidIndexes);
   8216 
   8217             for (int i = 0; i < rilSsResponse->cfData.numValidIndexes; i++) {
   8218                  RIL_CallForwardInfo cf = rilSsResponse->cfData.cfInfo[i];
   8219                  CallForwardInfo *cfInfo = &ss.cfData[0].cfInfo[i];
   8220 
   8221                  cfInfo->status = (CallForwardInfoStatus) cf.status;
   8222                  cfInfo->reason = cf.reason;
   8223                  cfInfo->serviceClass = cf.serviceClass;
   8224                  cfInfo->toa = cf.toa;
   8225                  cfInfo->number = convertCharPtrToHidlString(cf.number);
   8226                  cfInfo->timeSeconds = cf.timeSeconds;
   8227 #if VDBG
   8228                  RLOGD("onSupplementaryServiceIndicationInd: "
   8229                         "Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
   8230                         cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
   8231 #endif
   8232             }
   8233         } else {
   8234             ss.ssInfo.resize(1);
   8235             ss.cfData.resize(0);
   8236 
   8237             /* each int */
   8238             ss.ssInfo[0].ssInfo.resize(SS_INFO_MAX);
   8239             for (int i = 0; i < SS_INFO_MAX; i++) {
   8240 #if VDBG
   8241                  RLOGD("onSupplementaryServiceIndicationInd: Data: %d",
   8242                         rilSsResponse->ssInfo[i]);
   8243 #endif
   8244                  ss.ssInfo[0].ssInfo[i] = rilSsResponse->ssInfo[i];
   8245             }
   8246         }
   8247 
   8248 #if VDBG
   8249         RLOGD("onSupplementaryServiceIndicationInd");
   8250 #endif
   8251         Return<void> retStatus = radioService[slotId]->mRadioIndication->
   8252                 onSupplementaryServiceIndication(convertIntToRadioIndicationType(indicationType),
   8253                 ss);
   8254         radioService[slotId]->checkReturnStatus(retStatus);
   8255     } else {
   8256         RLOGE("onSupplementaryServiceIndicationInd: "
   8257                 "radioService[%d]->mRadioIndication == NULL", slotId);
   8258     }
   8259 
   8260     return 0;
   8261 }
   8262 
   8263 int radio::stkCallControlAlphaNotifyInd(int slotId,
   8264                                         int indicationType, int token, RIL_Errno e, void *response,
   8265                                         size_t responseLen) {
   8266     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8267         if (response == NULL || responseLen == 0) {
   8268             RLOGE("stkCallControlAlphaNotifyInd: invalid response");
   8269             return 0;
   8270         }
   8271 #if VDBG
   8272         RLOGD("stkCallControlAlphaNotifyInd");
   8273 #endif
   8274         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkCallControlAlphaNotify(
   8275                 convertIntToRadioIndicationType(indicationType),
   8276                 convertCharPtrToHidlString((char *) response));
   8277         radioService[slotId]->checkReturnStatus(retStatus);
   8278     } else {
   8279         RLOGE("stkCallControlAlphaNotifyInd: radioService[%d]->mRadioIndication == NULL",
   8280                 slotId);
   8281     }
   8282 
   8283     return 0;
   8284 }
   8285 
   8286 void convertRilLceDataInfoToHal(void *response, size_t responseLen, LceDataInfo& lce) {
   8287     RIL_LceDataInfo *rilLceDataInfo = (RIL_LceDataInfo *)response;
   8288     lce.lastHopCapacityKbps = rilLceDataInfo->last_hop_capacity_kbps;
   8289     lce.confidenceLevel = rilLceDataInfo->confidence_level;
   8290     lce.lceSuspended = rilLceDataInfo->lce_suspended;
   8291 }
   8292 
   8293 int radio::lceDataInd(int slotId,
   8294                       int indicationType, int token, RIL_Errno e, void *response,
   8295                       size_t responseLen) {
   8296     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8297         if (response == NULL || responseLen != sizeof(RIL_LceDataInfo)) {
   8298             RLOGE("lceDataInd: invalid response");
   8299             return 0;
   8300         }
   8301 
   8302         LceDataInfo lce = {};
   8303         convertRilLceDataInfoToHal(response, responseLen, lce);
   8304 #if VDBG
   8305         RLOGD("lceDataInd");
   8306 #endif
   8307         Return<void> retStatus = radioService[slotId]->mRadioIndication->lceData(
   8308                 convertIntToRadioIndicationType(indicationType), lce);
   8309         radioService[slotId]->checkReturnStatus(retStatus);
   8310     } else {
   8311         RLOGE("lceDataInd: radioService[%d]->mRadioIndication == NULL", slotId);
   8312     }
   8313 
   8314     return 0;
   8315 }
   8316 
   8317 int radio::pcoDataInd(int slotId,
   8318                       int indicationType, int token, RIL_Errno e, void *response,
   8319                       size_t responseLen) {
   8320     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8321         if (response == NULL || responseLen != sizeof(RIL_PCO_Data)) {
   8322             RLOGE("pcoDataInd: invalid response");
   8323             return 0;
   8324         }
   8325 
   8326         PcoDataInfo pco = {};
   8327         RIL_PCO_Data *rilPcoData = (RIL_PCO_Data *)response;
   8328         pco.cid = rilPcoData->cid;
   8329         pco.bearerProto = convertCharPtrToHidlString(rilPcoData->bearer_proto);
   8330         pco.pcoId = rilPcoData->pco_id;
   8331         pco.contents.setToExternal((uint8_t *) rilPcoData->contents, rilPcoData->contents_length);
   8332 
   8333 #if VDBG
   8334         RLOGD("pcoDataInd");
   8335 #endif
   8336         Return<void> retStatus = radioService[slotId]->mRadioIndication->pcoData(
   8337                 convertIntToRadioIndicationType(indicationType), pco);
   8338         radioService[slotId]->checkReturnStatus(retStatus);
   8339     } else {
   8340         RLOGE("pcoDataInd: radioService[%d]->mRadioIndication == NULL", slotId);
   8341     }
   8342 
   8343     return 0;
   8344 }
   8345 
   8346 int radio::modemResetInd(int slotId,
   8347                          int indicationType, int token, RIL_Errno e, void *response,
   8348                          size_t responseLen) {
   8349     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
   8350         if (response == NULL || responseLen == 0) {
   8351             RLOGE("modemResetInd: invalid response");
   8352             return 0;
   8353         }
   8354 #if VDBG
   8355         RLOGD("modemResetInd");
   8356 #endif
   8357         Return<void> retStatus = radioService[slotId]->mRadioIndication->modemReset(
   8358                 convertIntToRadioIndicationType(indicationType),
   8359                 convertCharPtrToHidlString((char *) response));
   8360         radioService[slotId]->checkReturnStatus(retStatus);
   8361     } else {
   8362         RLOGE("modemResetInd: radioService[%d]->mRadioIndication == NULL", slotId);
   8363     }
   8364 
   8365     return 0;
   8366 }
   8367 
   8368 int radio::networkScanResultInd(int slotId,
   8369                                 int indicationType, int token, RIL_Errno e, void *response,
   8370                                 size_t responseLen) {
   8371 #if VDBG
   8372     RLOGD("networkScanResultInd");
   8373 #endif
   8374     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndicationV1_1 != NULL) {
   8375         if (response == NULL || responseLen == 0) {
   8376             RLOGE("networkScanResultInd: invalid response");
   8377             return 0;
   8378         }
   8379         RLOGD("networkScanResultInd");
   8380 
   8381 #if VDBG
   8382         RLOGD("networkScanResultInd");
   8383 #endif
   8384 
   8385         RIL_NetworkScanResult *networkScanResult = (RIL_NetworkScanResult *) response;
   8386 
   8387         V1_1::NetworkScanResult result;
   8388         result.status = (V1_1::ScanStatus) networkScanResult->status;
   8389         result.error = (RadioError) networkScanResult->error;
   8390         convertRilCellInfoListToHal(
   8391                 networkScanResult->network_infos,
   8392                 networkScanResult->network_infos_length * sizeof(RIL_CellInfo_v12),
   8393                 result.networkInfos);
   8394 
   8395         Return<void> retStatus = radioService[slotId]->mRadioIndicationV1_1->networkScanResult(
   8396                 convertIntToRadioIndicationType(indicationType), result);
   8397         radioService[slotId]->checkReturnStatus(retStatus);
   8398     } else {
   8399         RLOGE("networkScanResultInd: radioService[%d]->mRadioIndicationV1_1 == NULL", slotId);
   8400     }
   8401     return 0;
   8402 }
   8403 
   8404 int radio::carrierInfoForImsiEncryption(int slotId,
   8405                                   int indicationType, int token, RIL_Errno e, void *response,
   8406                                   size_t responseLen) {
   8407     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndicationV1_1 != NULL) {
   8408         if (response == NULL || responseLen == 0) {
   8409             RLOGE("carrierInfoForImsiEncryption: invalid response");
   8410             return 0;
   8411         }
   8412         RLOGD("carrierInfoForImsiEncryption");
   8413         Return<void> retStatus = radioService[slotId]->mRadioIndicationV1_1->
   8414                 carrierInfoForImsiEncryption(convertIntToRadioIndicationType(indicationType));
   8415         radioService[slotId]->checkReturnStatus(retStatus);
   8416     } else {
   8417         RLOGE("carrierInfoForImsiEncryption: radioService[%d]->mRadioIndicationV1_1 == NULL",
   8418                 slotId);
   8419     }
   8420 
   8421     return 0;
   8422 }
   8423 
   8424 int radio::keepaliveStatusInd(int slotId,
   8425                          int indicationType, int token, RIL_Errno e, void *response,
   8426                          size_t responseLen) {
   8427 #if VDBG
   8428     RLOGD("%s(): token=%d", __FUNCTION__, token);
   8429 #endif
   8430     if (radioService[slotId] == NULL || radioService[slotId]->mRadioIndication == NULL) {
   8431         RLOGE("%s: radioService[%d]->mRadioIndication == NULL", __FUNCTION__, slotId);
   8432         return 0;
   8433     }
   8434 
   8435     auto ret = V1_1::IRadioIndication::castFrom(
   8436         radioService[slotId]->mRadioIndication);
   8437     if (!ret.isOk()) {
   8438         RLOGE("%s: ret.isOk() == false for radioService[%d]", __FUNCTION__, slotId);
   8439         return 0;
   8440     }
   8441     sp<V1_1::IRadioIndication> radioIndicationV1_1 = ret;
   8442 
   8443     if (response == NULL || responseLen != sizeof(V1_1::KeepaliveStatus)) {
   8444         RLOGE("%s: invalid response", __FUNCTION__);
   8445         return 0;
   8446     }
   8447 
   8448     V1_1::KeepaliveStatus ks;
   8449     convertRilKeepaliveStatusToHal(static_cast<RIL_KeepaliveStatus*>(response), ks);
   8450 
   8451     Return<void> retStatus = radioIndicationV1_1->keepaliveStatus(
   8452             convertIntToRadioIndicationType(indicationType), ks);
   8453     radioService[slotId]->checkReturnStatus(retStatus);
   8454     return 0;
   8455 }
   8456 
   8457 int radio::oemHookRawInd(int slotId,
   8458                          int indicationType, int token, RIL_Errno e, void *response,
   8459                          size_t responseLen) {
   8460     if (!kOemHookEnabled) return 0;
   8461 
   8462     if (oemHookService[slotId] != NULL && oemHookService[slotId]->mOemHookIndication != NULL) {
   8463         if (response == NULL || responseLen == 0) {
   8464             RLOGE("oemHookRawInd: invalid response");
   8465             return 0;
   8466         }
   8467 
   8468         hidl_vec<uint8_t> data;
   8469         data.setToExternal((uint8_t *) response, responseLen);
   8470 #if VDBG
   8471         RLOGD("oemHookRawInd");
   8472 #endif
   8473         Return<void> retStatus = oemHookService[slotId]->mOemHookIndication->oemHookRaw(
   8474                 convertIntToRadioIndicationType(indicationType), data);
   8475         checkReturnStatus(slotId, retStatus, false);
   8476     } else {
   8477         RLOGE("oemHookRawInd: oemHookService[%d]->mOemHookIndication == NULL", slotId);
   8478     }
   8479 
   8480     return 0;
   8481 }
   8482 
   8483 void radio::registerService(RIL_RadioFunctions *callbacks, CommandInfo *commands) {
   8484     using namespace android::hardware;
   8485     int simCount = 1;
   8486     const char *serviceNames[] = {
   8487             android::RIL_getServiceName()
   8488             #if (SIM_COUNT >= 2)
   8489             , RIL2_SERVICE_NAME
   8490             #if (SIM_COUNT >= 3)
   8491             , RIL3_SERVICE_NAME
   8492             #if (SIM_COUNT >= 4)
   8493             , RIL4_SERVICE_NAME
   8494             #endif
   8495             #endif
   8496             #endif
   8497             };
   8498 
   8499     #if (SIM_COUNT >= 2)
   8500     simCount = SIM_COUNT;
   8501     #endif
   8502 
   8503     s_vendorFunctions = callbacks;
   8504     s_commands = commands;
   8505 
   8506     configureRpcThreadpool(1, true /* callerWillJoin */);
   8507     for (int i = 0; i < simCount; i++) {
   8508         pthread_rwlock_t *radioServiceRwlockPtr = getRadioServiceRwlock(i);
   8509         int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
   8510         assert(ret == 0);
   8511 
   8512         radioService[i] = new RadioImpl;
   8513         radioService[i]->mSlotId = i;
   8514         RLOGD("registerService: starting android::hardware::radio::V1_1::IRadio %s",
   8515                 serviceNames[i]);
   8516         android::status_t status = radioService[i]->registerAsService(serviceNames[i]);
   8517 
   8518         if (kOemHookEnabled) {
   8519             oemHookService[i] = new OemHookImpl;
   8520             oemHookService[i]->mSlotId = i;
   8521             status = oemHookService[i]->registerAsService(serviceNames[i]);
   8522         }
   8523 
   8524         ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
   8525         assert(ret == 0);
   8526     }
   8527 }
   8528 
   8529 void rilc_thread_pool() {
   8530     joinRpcThreadpool();
   8531 }
   8532 
   8533 pthread_rwlock_t * radio::getRadioServiceRwlock(int slotId) {
   8534     pthread_rwlock_t *radioServiceRwlockPtr = &radioServiceRwlock;
   8535 
   8536     #if (SIM_COUNT >= 2)
   8537     if (slotId == 2) radioServiceRwlockPtr = &radioServiceRwlock2;
   8538     #if (SIM_COUNT >= 3)
   8539     if (slotId == 3) radioServiceRwlockPtr = &radioServiceRwlock3;
   8540     #if (SIM_COUNT >= 4)
   8541     if (slotId == 4) radioServiceRwlockPtr = &radioServiceRwlock4;
   8542     #endif
   8543     #endif
   8544     #endif
   8545 
   8546     return radioServiceRwlockPtr;
   8547 }
   8548 
   8549 // should acquire write lock for the corresponding service before calling this
   8550 void radio::setNitzTimeReceived(int slotId, long timeReceived) {
   8551     nitzTimeReceived[slotId] = timeReceived;
   8552 }
   8553