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