OSDN Git Service

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