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