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