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