OSDN Git Service

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