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