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