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 "RefImsMedia.h"
20 #include "RefRadioIms.h"
21 #include "RefRadioModem.h"
22 #include "RefRadioNetwork.h"
23 #include "RefRadioSim.h"
24 
25 #include <android-base/logging.h>
26 #include <android/binder_manager.h>
27 #include <android/binder_process.h>
28 #include <android/hardware/radio/1.6/IRadio.h>
29 #include <android/hardware/radio/1.6/IRadioIndication.h>
30 #include <android/hardware/radio/1.6/IRadioResponse.h>
31 #include <android/hardware/radio/1.6/types.h>
32 #include <libradiocompat/CallbackManager.h>
33 #include <libradiocompat/RadioData.h>
34 #include <libradiocompat/RadioIms.h>
35 #include <libradiocompat/RadioImsMedia.h>
36 #include <libradiocompat/RadioMessaging.h>
37 #include <libradiocompat/RadioModem.h>
38 #include <libradiocompat/RadioSim.h>
39 #include <libradiocompat/RadioVoice.h>
40 
41 #include <android/hardware/radio/deprecated/1.0/IOemHook.h>
42 
43 #include <hwbinder/IPCThreadState.h>
44 #include <hwbinder/ProcessState.h>
45 #include <guest/hals/ril/reference-libril/ril.h>
46 #include <telephony/ril_mnc.h>
47 #include <guest/hals/ril/reference-libril/ril_service.h>
48 #include <hidl/HidlTransportSupport.h>
49 #include <utils/SystemClock.h>
50 #include <inttypes.h>
51 
52 #define INVALID_HEX_CHAR 16
53 
54 using namespace android::hardware::radio;
55 using namespace android::hardware::radio::V1_0;
56 using namespace android::hardware::radio::deprecated::V1_0;
57 using namespace std::string_literals;
58 namespace compat = android::hardware::radio::compat;
59 using ::android::hardware::Return;
60 using ::android::hardware::hidl_bitfield;
61 using ::android::hardware::hidl_string;
62 using ::android::hardware::hidl_vec;
63 using ::android::hardware::hidl_array;
64 using ::android::hardware::Void;
65 using android::CommandInfo;
66 using android::RequestInfo;
67 using android::requestToString;
68 using android::sp;
69 
70 using RegStateResultV1_6 = android::hardware::radio::V1_6::RegStateResult;
71 using RegStateResultV1_5 = android::hardware::radio::V1_5::RegStateResult;
72 using PhysicalChannelConfigV1_4 =
73     android::hardware::radio::V1_4::PhysicalChannelConfig;
74 using RadioTechnologyV1_4 = android::hardware::radio::V1_4::RadioTechnology;
75 
76 namespace aidl_radio = ::aidl::android::hardware::radio;
77 
78 #define BOOL_TO_INT(x) (x ? 1 : 0)
79 #define ATOI_NULL_HANDLED(x) (x ? atoi(x) : -1)
80 #define ATOI_NULL_HANDLED_DEF(x, defaultVal) (x ? atoi(x) : defaultVal)
81 
82 #if defined(ANDROID_MULTI_SIM)
83 #define CALL_ONREQUEST(a, b, c, d, e) \
84         s_vendorFunctions->onRequest((a), (b), (c), (d), ((RIL_SOCKET_ID)(e)))
85 #define CALL_ONSTATEREQUEST(a) s_vendorFunctions->onStateRequest((RIL_SOCKET_ID)(a))
86 #else
87 #define CALL_ONREQUEST(a, b, c, d, e) s_vendorFunctions->onRequest((a), (b), (c), (d))
88 #define CALL_ONSTATEREQUEST(a) s_vendorFunctions->onStateRequest()
89 #endif
90 
91 #ifdef OEM_HOOK_DISABLED
92 constexpr bool kOemHookEnabled = false;
93 #else
94 constexpr bool kOemHookEnabled = true;
95 #endif
96 
97 RIL_RadioFunctions *s_vendorFunctions = NULL;
98 static CommandInfo *s_commands;
99 
100 struct RadioImpl_1_6;
101 struct OemHookImpl;
102 
103 #if (SIM_COUNT >= 2)
104 sp<RadioImpl_1_6> radioService[SIM_COUNT];
105 sp<OemHookImpl> oemHookService[SIM_COUNT];
106 int64_t nitzTimeReceived[SIM_COUNT];
107 // counter used for synchronization. It is incremented every time response callbacks are updated.
108 volatile int32_t mCounterRadio[SIM_COUNT];
109 volatile int32_t mCounterOemHook[SIM_COUNT];
110 #else
111 sp<RadioImpl_1_6> radioService[1];
112 sp<OemHookImpl> oemHookService[1];
113 int64_t nitzTimeReceived[1];
114 // counter used for synchronization. It is incremented every time response callbacks are updated.
115 volatile int32_t mCounterRadio[1];
116 volatile int32_t mCounterOemHook[1];
117 hidl_vec<uint8_t> osAppIdVec;
118 #endif
119 
120 static pthread_rwlock_t radioServiceRwlock = PTHREAD_RWLOCK_INITIALIZER;
121 
122 #if (SIM_COUNT >= 2)
123 static pthread_rwlock_t radioServiceRwlock2 = PTHREAD_RWLOCK_INITIALIZER;
124 #if (SIM_COUNT >= 3)
125 static pthread_rwlock_t radioServiceRwlock3 = PTHREAD_RWLOCK_INITIALIZER;
126 #if (SIM_COUNT >= 4)
127 static pthread_rwlock_t radioServiceRwlock4 = PTHREAD_RWLOCK_INITIALIZER;
128 #endif
129 #endif
130 #endif
131 
132 void convertRilHardwareConfigListToHal(void *response, size_t responseLen,
133         hidl_vec<HardwareConfig>& records);
134 
135 void convertRilRadioCapabilityToHal(void *response, size_t responseLen, RadioCapability& rc);
136 
137 void convertRilLceDataInfoToHal(void *response, size_t responseLen, LceDataInfo& lce);
138 
139 void convertRilSignalStrengthToHal(void *response, size_t responseLen,
140         SignalStrength& signalStrength);
141 
142 void convertRilSignalStrengthToHal_1_2(void* response, size_t responseLen,
143                                        V1_2::SignalStrength& signalStrength);
144 
145 void convertRilSignalStrengthToHal_1_4(void *response, size_t responseLen,
146         V1_4::SignalStrength& signalStrength);
147 
148 void convertRilSignalStrengthToHal_1_6(void* response, size_t responseLen,
149                                        V1_6::SignalStrength& signalStrength);
150 
151 void convertRilDataCallToHal(RIL_Data_Call_Response_v11* dcResponse, SetupDataCallResult& dcResult);
152 
153 void convertRilDataCallToHal(RIL_Data_Call_Response_v11* dcResponse,
154                              V1_4::SetupDataCallResult& dcResult);
155 
156 void convertRilDataCallToHal(RIL_Data_Call_Response_v11* dcResponse,
157                              V1_5::SetupDataCallResult& dcResult);
158 
159 void convertRilDataCallToHal(RIL_Data_Call_Response_v11* dcResponse,
160                              V1_6::SetupDataCallResult& dcResult);
161 
162 void convertRilDataCallListToHal(void *response, size_t responseLen,
163         hidl_vec<SetupDataCallResult>& dcResultList);
164 
165 void convertRilDataCallListToHal_1_4(void* response, size_t responseLen,
166                                      hidl_vec<V1_4::SetupDataCallResult>& dcResultList);
167 
168 void convertRilDataCallListToHal_1_5(void* response, size_t responseLen,
169                                      hidl_vec<V1_5::SetupDataCallResult>& dcResultList);
170 
171 void convertRilDataCallListToHal_1_6(void* response, size_t responseLen,
172                                      hidl_vec<V1_6::SetupDataCallResult>& dcResultList);
173 
174 void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<CellInfo>& records);
175 void convertRilCellInfoListToHal_1_2(void *response, size_t responseLen, hidl_vec<V1_2::CellInfo>& records);
176 void convertRilCellInfoListToHal_1_4(void* response, size_t responseLen,
177                                      hidl_vec<V1_4::CellInfo>& records);
178 void convertRilCellInfoListToHal_1_5(void* response, size_t responseLen,
179                                      hidl_vec<V1_5::CellInfo>& records);
180 void convertRilCellInfoListToHal_1_6(void* response, size_t responseLen,
181                                      hidl_vec<V1_6::CellInfo>& records);
182 
183 void populateResponseInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
184                          RIL_Errno e);
185 
186 void populateResponseInfo_1_6(
187     ::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo,
188     int serial, int responseType, RIL_Errno e);
189 
190 struct RadioImpl_1_6 : public V1_6::IRadio {
191     int32_t mSlotId;
192     V1_1::CardPowerState mSimCardPowerState;
193     sp<IRadioResponse> mRadioResponse;
194     sp<IRadioIndication> mRadioIndication;
195     sp<V1_1::IRadioResponse> mRadioResponseV1_1;
196     sp<V1_1::IRadioIndication> mRadioIndicationV1_1;
197     sp<V1_2::IRadioResponse> mRadioResponseV1_2;
198     sp<V1_2::IRadioIndication> mRadioIndicationV1_2;
199     sp<V1_3::IRadioResponse> mRadioResponseV1_3;
200     sp<V1_3::IRadioIndication> mRadioIndicationV1_3;
201     sp<V1_4::IRadioResponse> mRadioResponseV1_4;
202     sp<V1_4::IRadioIndication> mRadioIndicationV1_4;
203     sp<V1_5::IRadioResponse> mRadioResponseV1_5;
204     sp<V1_5::IRadioIndication> mRadioIndicationV1_5;
205     sp<V1_6::IRadioResponse> mRadioResponseV1_6;
206     sp<V1_6::IRadioIndication> mRadioIndicationV1_6;
207     std::shared_ptr<compat::CallbackManager> mCallbackManager;
208 
209     Return<void> setResponseFunctions(
210             const ::android::sp<IRadioResponse>& radioResponse,
211             const ::android::sp<IRadioIndication>& radioIndication);
212 
213     Return<void> getIccCardStatus(int32_t serial);
214 
215     Return<void> supplyIccPinForApp(int32_t serial, const hidl_string& pin,
216             const hidl_string& aid);
217 
218     Return<void> supplyIccPukForApp(int32_t serial, const hidl_string& puk,
219             const hidl_string& pin, const hidl_string& aid);
220 
221     Return<void> supplyIccPin2ForApp(int32_t serial,
222             const hidl_string& pin2,
223             const hidl_string& aid);
224 
225     Return<void> supplyIccPuk2ForApp(int32_t serial, const hidl_string& puk2,
226             const hidl_string& pin2, const hidl_string& aid);
227 
228     Return<void> changeIccPinForApp(int32_t serial, const hidl_string& oldPin,
229             const hidl_string& newPin, const hidl_string& aid);
230 
231     Return<void> changeIccPin2ForApp(int32_t serial, const hidl_string& oldPin2,
232             const hidl_string& newPin2, const hidl_string& aid);
233 
234     Return<void> supplyNetworkDepersonalization(int32_t serial, const hidl_string& netPin);
235 
236     Return<void> getCurrentCalls(int32_t serial);
237 
238     Return<void> getCurrentCalls_1_6(int32_t serial);
239 
240     Return<void> dial(int32_t serial, const Dial& dialInfo);
241 
242     Return<void> getImsiForApp(int32_t serial,
243             const ::android::hardware::hidl_string& aid);
244 
245     Return<void> hangup(int32_t serial, int32_t gsmIndex);
246 
247     Return<void> hangupWaitingOrBackground(int32_t serial);
248 
249     Return<void> hangupForegroundResumeBackground(int32_t serial);
250 
251     Return<void> switchWaitingOrHoldingAndActive(int32_t serial);
252 
253     Return<void> conference(int32_t serial);
254 
255     Return<void> rejectCall(int32_t serial);
256 
257     Return<void> getLastCallFailCause(int32_t serial);
258 
259     Return<void> getSignalStrength(int32_t serial);
260 
261     Return<void> getSignalStrength_1_6(int32_t serial);
262 
263     Return<void> getVoiceRegistrationState(int32_t serial);
264 
265     Return<void> getDataRegistrationState(int32_t serial);
266 
267     Return<void> getOperator(int32_t serial);
268 
269     Return<void> setRadioPower(int32_t serial, bool on);
270 
271     Return<void> sendDtmf(int32_t serial,
272             const ::android::hardware::hidl_string& s);
273 
274     Return<void> sendSms(int32_t serial, const GsmSmsMessage& message);
275 
276     Return<void> sendSMSExpectMore(int32_t serial, const GsmSmsMessage& message);
277 
278     Return<void> setupDataCall(int32_t serial,
279             RadioTechnology radioTechnology,
280             const DataProfileInfo& profileInfo,
281             bool modemCognitive,
282             bool roamingAllowed,
283             bool isRoaming);
284 
285     Return<void> iccIOForApp(int32_t serial,
286             const IccIo& iccIo);
287 
288     Return<void> sendUssd(int32_t serial,
289             const ::android::hardware::hidl_string& ussd);
290 
291     Return<void> cancelPendingUssd(int32_t serial);
292 
293     Return<void> getClir(int32_t serial);
294 
295     Return<void> setClir(int32_t serial, int32_t status);
296 
297     Return<void> getCallForwardStatus(int32_t serial,
298             const CallForwardInfo& callInfo);
299 
300     Return<void> setCallForward(int32_t serial,
301             const CallForwardInfo& callInfo);
302 
303     Return<void> getCallWaiting(int32_t serial, int32_t serviceClass);
304 
305     Return<void> setCallWaiting(int32_t serial, bool enable, int32_t serviceClass);
306 
307     Return<void> acknowledgeLastIncomingGsmSms(int32_t serial,
308             bool success, SmsAcknowledgeFailCause cause);
309 
310     Return<void> acceptCall(int32_t serial);
311 
312     Return<void> deactivateDataCall(int32_t serial,
313             int32_t cid, bool reasonRadioShutDown);
314 
315     Return<void> getFacilityLockForApp(int32_t serial,
316             const ::android::hardware::hidl_string& facility,
317             const ::android::hardware::hidl_string& password,
318             int32_t serviceClass,
319             const ::android::hardware::hidl_string& appId);
320 
321     Return<void> setFacilityLockForApp(int32_t serial,
322             const ::android::hardware::hidl_string& facility,
323             bool lockState,
324             const ::android::hardware::hidl_string& password,
325             int32_t serviceClass,
326             const ::android::hardware::hidl_string& appId);
327 
328     Return<void> setBarringPassword(int32_t serial,
329             const ::android::hardware::hidl_string& facility,
330             const ::android::hardware::hidl_string& oldPassword,
331             const ::android::hardware::hidl_string& newPassword);
332 
333     Return<void> getNetworkSelectionMode(int32_t serial);
334 
335     Return<void> setNetworkSelectionModeAutomatic(int32_t serial);
336 
337     Return<void> setNetworkSelectionModeManual(int32_t serial,
338             const ::android::hardware::hidl_string& operatorNumeric);
339 
340     Return<void> getAvailableNetworks(int32_t serial);
341 
342     Return<void> startNetworkScan(int32_t serial, const V1_1::NetworkScanRequest& request);
343 
344     Return<void> stopNetworkScan(int32_t serial);
345 
346     Return<void> startDtmf(int32_t serial,
347             const ::android::hardware::hidl_string& s);
348 
349     Return<void> stopDtmf(int32_t serial);
350 
351     Return<void> getBasebandVersion(int32_t serial);
352 
353     Return<void> separateConnection(int32_t serial, int32_t gsmIndex);
354 
355     Return<void> setMute(int32_t serial, bool enable);
356 
357     Return<void> getMute(int32_t serial);
358 
359     Return<void> getClip(int32_t serial);
360 
361     Return<void> getDataCallList(int32_t serial);
362 
363     Return<void> setSuppServiceNotifications(int32_t serial, bool enable);
364 
365     Return<void> writeSmsToSim(int32_t serial,
366             const SmsWriteArgs& smsWriteArgs);
367 
368     Return<void> deleteSmsOnSim(int32_t serial, int32_t index);
369 
370     Return<void> setBandMode(int32_t serial, RadioBandMode mode);
371 
372     Return<void> getAvailableBandModes(int32_t serial);
373 
374     Return<void> sendEnvelope(int32_t serial,
375             const ::android::hardware::hidl_string& command);
376 
377     Return<void> sendTerminalResponseToSim(int32_t serial,
378             const ::android::hardware::hidl_string& commandResponse);
379 
380     Return<void> handleStkCallSetupRequestFromSim(int32_t serial, bool accept);
381 
382     Return<void> explicitCallTransfer(int32_t serial);
383 
384     Return<void> setPreferredNetworkType(int32_t serial, PreferredNetworkType nwType);
385 
386     Return<void> getPreferredNetworkType(int32_t serial);
387 
388     Return<void> getNeighboringCids(int32_t serial);
389 
390     Return<void> setLocationUpdates(int32_t serial, bool enable);
391 
392     Return<void> setCdmaSubscriptionSource(int32_t serial,
393             CdmaSubscriptionSource cdmaSub);
394 
395     Return<void> setCdmaRoamingPreference(int32_t serial, CdmaRoamingType type);
396 
397     Return<void> getCdmaRoamingPreference(int32_t serial);
398 
399     Return<void> setTTYMode(int32_t serial, TtyMode mode);
400 
401     Return<void> getTTYMode(int32_t serial);
402 
403     Return<void> setPreferredVoicePrivacy(int32_t serial, bool enable);
404 
405     Return<void> getPreferredVoicePrivacy(int32_t serial);
406 
407     Return<void> sendCDMAFeatureCode(int32_t serial,
408             const ::android::hardware::hidl_string& featureCode);
409 
410     Return<void> sendBurstDtmf(int32_t serial,
411             const ::android::hardware::hidl_string& dtmf,
412             int32_t on,
413             int32_t off);
414 
415     Return<void> sendCdmaSms(int32_t serial, const CdmaSmsMessage& sms);
416 
417     Return<void> acknowledgeLastIncomingCdmaSms(int32_t serial,
418             const CdmaSmsAck& smsAck);
419 
420     Return<void> getGsmBroadcastConfig(int32_t serial);
421 
422     Return<void> setGsmBroadcastConfig(int32_t serial,
423             const hidl_vec<GsmBroadcastSmsConfigInfo>& configInfo);
424 
425     Return<void> setGsmBroadcastActivation(int32_t serial, bool activate);
426 
427     Return<void> getCdmaBroadcastConfig(int32_t serial);
428 
429     Return<void> setCdmaBroadcastConfig(int32_t serial,
430             const hidl_vec<CdmaBroadcastSmsConfigInfo>& configInfo);
431 
432     Return<void> setCdmaBroadcastActivation(int32_t serial, bool activate);
433 
434     Return<void> getCDMASubscription(int32_t serial);
435 
436     Return<void> writeSmsToRuim(int32_t serial, const CdmaSmsWriteArgs& cdmaSms);
437 
438     Return<void> deleteSmsOnRuim(int32_t serial, int32_t index);
439 
440     Return<void> getDeviceIdentity(int32_t serial);
441 
442     Return<void> exitEmergencyCallbackMode(int32_t serial);
443 
444     Return<void> getSmscAddress(int32_t serial);
445 
446     Return<void> setSmscAddress(int32_t serial,
447             const ::android::hardware::hidl_string& smsc);
448 
449     Return<void> reportSmsMemoryStatus(int32_t serial, bool available);
450 
451     Return<void> reportStkServiceIsRunning(int32_t serial);
452 
453     Return<void> getCdmaSubscriptionSource(int32_t serial);
454 
455     Return<void> requestIsimAuthentication(int32_t serial,
456             const ::android::hardware::hidl_string& challenge);
457 
458     Return<void> acknowledgeIncomingGsmSmsWithPdu(int32_t serial,
459             bool success,
460             const ::android::hardware::hidl_string& ackPdu);
461 
462     Return<void> sendEnvelopeWithStatus(int32_t serial,
463             const ::android::hardware::hidl_string& contents);
464 
465     Return<void> getVoiceRadioTechnology(int32_t serial);
466 
467     Return<void> getCellInfoList(int32_t serial);
468 
469     Return<void> getCellInfoList_1_6(int32_t serial);
470 
471     Return<void> setCellInfoListRate(int32_t serial, int32_t rate);
472 
473     Return<void> setInitialAttachApn(int32_t serial, const DataProfileInfo& dataProfileInfo,
474             bool modemCognitive, bool isRoaming);
475 
476     Return<void> getImsRegistrationState(int32_t serial);
477 
478     Return<void> sendImsSms(int32_t serial, const ImsSmsMessage& message);
479 
480     Return<void> iccTransmitApduBasicChannel(int32_t serial, const SimApdu& message);
481 
482     Return<void> iccOpenLogicalChannel(int32_t serial,
483             const ::android::hardware::hidl_string& aid, int32_t p2);
484 
485     Return<void> iccCloseLogicalChannel(int32_t serial, int32_t channelId);
486 
487     Return<void> iccTransmitApduLogicalChannel(int32_t serial, const SimApdu& message);
488 
489     Return<void> nvReadItem(int32_t serial, NvItem itemId);
490 
491     Return<void> nvWriteItem(int32_t serial, const NvWriteItem& item);
492 
493     Return<void> nvWriteCdmaPrl(int32_t serial,
494             const ::android::hardware::hidl_vec<uint8_t>& prl);
495 
496     Return<void> nvResetConfig(int32_t serial, ResetNvType resetType);
497 
498     Return<void> setUiccSubscription(int32_t serial, const SelectUiccSub& uiccSub);
499 
500     Return<void> setDataAllowed(int32_t serial, bool allow);
501 
502     Return<void> getHardwareConfig(int32_t serial);
503 
504     Return<void> requestIccSimAuthentication(int32_t serial,
505             int32_t authContext,
506             const ::android::hardware::hidl_string& authData,
507             const ::android::hardware::hidl_string& aid);
508 
509     Return<void> setDataProfile(int32_t serial,
510             const ::android::hardware::hidl_vec<DataProfileInfo>& profiles, bool isRoaming);
511 
512     Return<void> requestShutdown(int32_t serial);
513 
514     Return<void> getRadioCapability(int32_t serial);
515 
516     Return<void> setRadioCapability(int32_t serial, const RadioCapability& rc);
517 
518     Return<void> startLceService(int32_t serial, int32_t reportInterval, bool pullMode);
519 
520     Return<void> stopLceService(int32_t serial);
521 
522     Return<void> pullLceData(int32_t serial);
523 
524     Return<void> getModemActivityInfo(int32_t serial);
525 
526     Return<void> setAllowedCarriers(int32_t serial,
527             bool allAllowed,
528             const CarrierRestrictions& carriers);
529 
530     Return<void> getAllowedCarriers(int32_t serial);
531 
532     Return<void> sendDeviceState(int32_t serial, DeviceStateType deviceStateType, bool state);
533 
534     Return<void> setIndicationFilter(int32_t serial, int32_t indicationFilter);
535 
536     Return<void> startKeepalive(int32_t serial, const V1_1::KeepaliveRequest& keepalive);
537 
538     Return<void> stopKeepalive(int32_t serial, int32_t sessionHandle);
539 
540     Return<void> setSimCardPower(int32_t serial, bool powerUp);
541     Return<void> setSimCardPower_1_1(int32_t serial,
542             const V1_1::CardPowerState state);
543     Return<void> setSimCardPower_1_6(int32_t serial,
544             const V1_1::CardPowerState state);
545 
546     Return<void> responseAcknowledgement();
547 
548     Return<void> setCarrierInfoForImsiEncryption(int32_t serial,
549             const V1_1::ImsiEncryptionInfo& message);
550 
551     void checkReturnStatus(Return<void>& ret);
552 
553     // Methods from ::android::hardware::radio::V1_2::IRadio follow.
554     Return<void> startNetworkScan_1_2(int32_t serial,
555             const ::android::hardware::radio::V1_2::NetworkScanRequest& request);
556     Return<void> setIndicationFilter_1_2(int32_t serial,
557             hidl_bitfield<::android::hardware::radio::V1_2::IndicationFilter> indicationFilter);
558     Return<void> setSignalStrengthReportingCriteria(int32_t serial, int32_t hysteresisMs,
559             int32_t hysteresisDb, const hidl_vec<int32_t>& thresholdsDbm,
560             ::android::hardware::radio::V1_2::AccessNetwork accessNetwork);
561     Return<void> setLinkCapacityReportingCriteria(int32_t serial, int32_t hysteresisMs,
562             int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
563             const hidl_vec<int32_t>& thresholdsDownlinkKbps,
564             const hidl_vec<int32_t>& thresholdsUplinkKbps,
565             ::android::hardware::radio::V1_2::AccessNetwork accessNetwork);
566     Return<void> setupDataCall_1_2(int32_t serial,
567             ::android::hardware::radio::V1_2::AccessNetwork accessNetwork,
568             const ::android::hardware::radio::V1_0::DataProfileInfo& dataProfileInfo,
569             bool modemCognitive, bool roamingAllowed, bool isRoaming,
570             ::android::hardware::radio::V1_2::DataRequestReason reason,
571             const hidl_vec<hidl_string>& addresses, const hidl_vec<hidl_string>& dnses);
572     Return<void> deactivateDataCall_1_2(int32_t serial, int32_t cid,
573             ::android::hardware::radio::V1_2::DataRequestReason reason);
574 
575     // Methods from ::android::hardware::radio::V1_3::IRadio follow.
576     Return<void> setSystemSelectionChannels(int32_t serial, bool specifyChannels,
577             const hidl_vec<::android::hardware::radio::V1_1::RadioAccessSpecifier>& specifiers);
578     Return<void> enableModem(int32_t serial, bool on);
579     Return<void> getModemStackStatus(int32_t serial);
580 
581     // Methods from ::android::hardware::radio::V1_4::IRadio follow.
582     Return<void> setupDataCall_1_4(int32_t serial,
583             ::android::hardware::radio::V1_4::AccessNetwork accessNetwork,
584             const ::android::hardware::radio::V1_4::DataProfileInfo& dataProfileInfo,
585             bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason reason,
586             const hidl_vec<hidl_string>& addresses, const hidl_vec<hidl_string>& dnses);
587     Return<void> setInitialAttachApn_1_4(int32_t serial,
588             const ::android::hardware::radio::V1_4::DataProfileInfo& dataProfileInfo);
589     Return<void> setDataProfile_1_4(int32_t serial,
590             const hidl_vec<::android::hardware::radio::V1_4::DataProfileInfo>& profiles);
591     Return<void> emergencyDial(int32_t serial,
592             const ::android::hardware::radio::V1_0::Dial& dialInfo,
593             hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,
594             const hidl_vec<hidl_string>& urns,
595             ::android::hardware::radio::V1_4::EmergencyCallRouting routing,
596             bool fromEmergencyDialer, bool isTesting);
597     Return<void> emergencyDial_1_6(int32_t serial,
598             const ::android::hardware::radio::V1_0::Dial& dialInfo,
599             hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,
600             const hidl_vec<hidl_string>& urns,
601             ::android::hardware::radio::V1_4::EmergencyCallRouting routing,
602             bool fromEmergencyDialer, bool isTesting);
603     Return<void> startNetworkScan_1_4(int32_t serial,
604             const ::android::hardware::radio::V1_2::NetworkScanRequest& request);
605     Return<void> getPreferredNetworkTypeBitmap(int32_t serial);
606     Return<void> setPreferredNetworkTypeBitmap(
607             int32_t serial, hidl_bitfield<RadioAccessFamily> networkTypeBitmap);
608     Return<void> setAllowedCarriers_1_4(int32_t serial,
609             const ::android::hardware::radio::V1_4::CarrierRestrictionsWithPriority& carriers,
610             ::android::hardware::radio::V1_4::SimLockMultiSimPolicy multiSimPolicy);
611     Return<void> getAllowedCarriers_1_4(int32_t serial);
612     Return<void> getSignalStrength_1_4(int32_t serial);
613 
614     // Methods from ::android::hardware::radio::V1_5::IRadio follow.
615     Return<void> setSignalStrengthReportingCriteria_1_5(int32_t serial,
616             const ::android::hardware::radio::V1_5::SignalThresholdInfo& signalThresholdInfo,
617             const ::android::hardware::radio::V1_5::AccessNetwork accessNetwork);
618     Return<void> setLinkCapacityReportingCriteria_1_5(int32_t serial, int32_t hysteresisMs,
619             int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
620             const hidl_vec<int32_t>& thresholdsDownlinkKbps,
621             const hidl_vec<int32_t>& thresholdsUplinkKbps,
622             V1_5::AccessNetwork accessNetwork);
623     Return<void> enableUiccApplications(int32_t serial, bool detach);
624     Return<void> areUiccApplicationsEnabled(int32_t serial);
625     Return<void> setSystemSelectionChannels_1_5(int32_t serial, bool specifyChannels,
626             const hidl_vec<::android::hardware::radio::V1_5::RadioAccessSpecifier>& specifiers);
627     Return<void> startNetworkScan_1_5(int32_t serial,
628             const ::android::hardware::radio::V1_5::NetworkScanRequest& request);
629     Return<void> setupDataCall_1_5(int32_t serial,
630             ::android::hardware::radio::V1_5::AccessNetwork accessNetwork,
631             const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
632             bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason reason,
633             const hidl_vec<::android::hardware::radio::V1_5::LinkAddress>& addresses,
634             const hidl_vec<hidl_string>& dnses);
635     Return<void> setInitialAttachApn_1_5(int32_t serial,
636             const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo);
637     Return<void> setDataProfile_1_5(int32_t serial,
638             const hidl_vec<::android::hardware::radio::V1_5::DataProfileInfo>& profiles);
639     Return<void> setRadioPower_1_5(int32_t serial, bool powerOn, bool forEmergencyCall,
640             bool preferredForEmergencyCall);
641     Return<void> setIndicationFilter_1_5(int32_t serial,
642             hidl_bitfield<::android::hardware::radio::V1_5::IndicationFilter> indicationFilter);
643     Return<void> getBarringInfo(int32_t serial);
644     Return<void> getVoiceRegistrationState_1_5(int32_t serial);
645     Return<void> getDataRegistrationState_1_5(int32_t serial);
646     Return<void> setNetworkSelectionModeManual_1_5(int32_t serial,
647             const hidl_string& operatorNumeric, V1_5::RadioAccessNetworks ran);
648     Return<void> sendCdmaSmsExpectMore(int32_t serial, const CdmaSmsMessage& sms);
649     Return<void> supplySimDepersonalization(int32_t serial, V1_5::PersoSubstate persoType,
650                                             const hidl_string& controlKey);
651     Return<void> setNrDualConnectivityState(int32_t serial,
652             V1_6::NrDualConnectivityState nrDualConnectivityState);
653     Return<void> isNrDualConnectivityEnabled(int32_t serial);
654 
655     // Methods from ::android::hardware::radio::V1_6::IRadio follow.
656     Return<void> getDataCallList_1_6(int32_t serial);
657     Return<void> setupDataCall_1_6(int32_t serial,
658             ::android::hardware::radio::V1_5::AccessNetwork accessNetwork,
659             const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
660             bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason reason,
661             const hidl_vec<::android::hardware::radio::V1_5::LinkAddress>& addresses,
662             const hidl_vec<hidl_string>& dnses,
663             int32_t pduSessionId,
664             const ::android::hardware::radio::V1_6::OptionalSliceInfo& sliceInfo,
665             const ::android::hardware::radio::V1_6::OptionalTrafficDescriptor& trafficDescriptor,
666             bool matchAllRuleAllowed);
667     Return<void> sendSms_1_6(int32_t serial, const GsmSmsMessage& message);
668     Return<void> sendSmsExpectMore_1_6(int32_t serial, const GsmSmsMessage& message);
669     Return<void> sendCdmaSms_1_6(int32_t serial, const CdmaSmsMessage& sms);
670     Return<void> sendCdmaSmsExpectMore_1_6(int32_t serial, const CdmaSmsMessage& sms);
671     Return<void> setRadioPower_1_6(int32_t serial, bool powerOn, bool forEmergencyCall,
672             bool preferredForEmergencyCall);
673     Return<void> allocatePduSessionId(int32_t serial);
674     Return<void> releasePduSessionId(int32_t serial, int32_t id);
675     Return<void> startHandover(int32_t serial, int32_t callId);
676     Return<void> cancelHandover(int32_t serial, int32_t callId);
677     Return<void> setAllowedNetworkTypesBitmap(uint32_t serial,
678             hidl_bitfield<::android::hardware::radio::V1_4::RadioAccessFamily> networkTypeBitmap);
679     Return<void> setDataThrottling(int32_t serial,
680             V1_6::DataThrottlingAction dataThrottlingAction,
681             int64_t completionDurationMillis);
682     Return<void> getSystemSelectionChannels(int32_t serial);
683     Return<void> getVoiceRegistrationState_1_6(int32_t serial);
684     Return<void> getDataRegistrationState_1_6(int32_t serial);
685     Return<void> getAllowedNetworkTypesBitmap(int32_t serial);
686     Return<void> getSlicingConfig(int32_t serial);
687     Return<void> setCarrierInfoForImsiEncryption_1_6(
688             int32_t serial,
689             const ::android::hardware::radio::V1_6::ImsiEncryptionInfo& imsiEncryptionInfo);
690     Return<void> getSimPhonebookRecords(int32_t serial);
691     Return<void> getSimPhonebookCapacity(int32_t serial);
692     Return<void> updateSimPhonebookRecords(
693             int32_t serial,
694             const ::android::hardware::radio::V1_6::PhonebookRecordInfo& recordInfo);
695 };
696 
697 struct OemHookImpl : public IOemHook {
698     int32_t mSlotId;
699     sp<IOemHookResponse> mOemHookResponse;
700     sp<IOemHookIndication> mOemHookIndication;
701 
702     Return<void> setResponseFunctions(
703             const ::android::sp<IOemHookResponse>& oemHookResponse,
704             const ::android::sp<IOemHookIndication>& oemHookIndication);
705 
706     Return<void> sendRequestRaw(int32_t serial,
707             const ::android::hardware::hidl_vec<uint8_t>& data);
708 
709     Return<void> sendRequestStrings(int32_t serial,
710             const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& data);
711 };
712 
memsetAndFreeStrings(int numPointers,...)713 void memsetAndFreeStrings(int numPointers, ...) {
714     va_list ap;
715     va_start(ap, numPointers);
716     for (int i = 0; i < numPointers; i++) {
717         char *ptr = va_arg(ap, char *);
718         if (ptr) {
719 #ifdef MEMSET_FREED
720 #define MAX_STRING_LENGTH 4096
721             memset(ptr, 0, strnlen(ptr, MAX_STRING_LENGTH));
722 #endif
723             free(ptr);
724         }
725     }
726     va_end(ap);
727 }
728 
sendErrorResponse(RequestInfo * pRI,RIL_Errno err)729 void sendErrorResponse(RequestInfo *pRI, RIL_Errno err) {
730     pRI->pCI->responseFunction((int) pRI->socket_id,
731             (int) RadioResponseType::SOLICITED, pRI->token, err, NULL, 0);
732 }
733 
734 /**
735  * Copies over src to dest. If memory allocation fails, responseFunction() is called for the
736  * request with error RIL_E_NO_MEMORY. The size() method is used to determine the size of the
737  * destination buffer into which the HIDL string is copied. If there is a discrepancy between
738  * the string length reported by the size() method, and the length of the string returned by
739  * the c_str() method, the function will return false indicating a failure.
740  *
741  * Returns true on success, and false on failure.
742  */
copyHidlStringToRil(char ** dest,const hidl_string & src,RequestInfo * pRI,bool allowEmpty)743 bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI, bool allowEmpty) {
744     size_t len = src.size();
745     if (len == 0 && !allowEmpty) {
746         *dest = NULL;
747         return true;
748     }
749     *dest = (char *) calloc(len + 1, sizeof(char));
750     if (*dest == NULL) {
751         RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
752         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
753         return false;
754     }
755     if (strlcpy(*dest, src.c_str(), len + 1) >= (len + 1)) {
756         RLOGE("Copy of the HIDL string has been truncated, as "
757               "the string length reported by size() does not "
758               "match the length of string returned by c_str().");
759         free(*dest);
760         *dest = NULL;
761         sendErrorResponse(pRI, RIL_E_INTERNAL_ERR);
762         return false;
763     }
764     return true;
765 }
766 
copyHidlStringToRil(char ** dest,const hidl_string & src,RequestInfo * pRI)767 bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI) {
768     return copyHidlStringToRil(dest, src, pRI, false);
769 }
770 
convertCharPtrToHidlString(const char * ptr)771 hidl_string convertCharPtrToHidlString(const char *ptr) {
772     hidl_string ret;
773     if (ptr != NULL) {
774         // TODO: replace this with strnlen
775         ret.setToExternal(ptr, strlen(ptr));
776     }
777     return ret;
778 }
779 
dispatchVoid(int serial,int slotId,int request)780 bool dispatchVoid(int serial, int slotId, int request) {
781     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
782     if (pRI == NULL) {
783         return false;
784     }
785     CALL_ONREQUEST(request, NULL, 0, pRI, slotId);
786     return true;
787 }
788 
dispatchString(int serial,int slotId,int request,const char * str)789 bool dispatchString(int serial, int slotId, int request, const char * str) {
790     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
791     if (pRI == NULL) {
792         return false;
793     }
794 
795     char *pString;
796     if (!copyHidlStringToRil(&pString, str, pRI)) {
797         return false;
798     }
799 
800     CALL_ONREQUEST(request, pString, sizeof(char *), pRI, slotId);
801 
802     memsetAndFreeStrings(1, pString);
803     return true;
804 }
805 
dispatchStrings(int serial,int slotId,int request,bool allowEmpty,int countStrings,...)806 bool dispatchStrings(int serial, int slotId, int request, bool allowEmpty, int countStrings, ...) {
807     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
808     if (pRI == NULL) {
809         return false;
810     }
811 
812     char **pStrings;
813     pStrings = (char **)calloc(countStrings, sizeof(char *));
814     if (pStrings == NULL) {
815         RLOGE("Memory allocation failed for request %s", requestToString(request));
816         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
817         return false;
818     }
819     va_list ap;
820     va_start(ap, countStrings);
821     for (int i = 0; i < countStrings; i++) {
822         const char* str = va_arg(ap, const char *);
823         if (!copyHidlStringToRil(&pStrings[i], hidl_string(str), pRI, allowEmpty)) {
824             va_end(ap);
825             for (int j = 0; j < i; j++) {
826                 memsetAndFreeStrings(1, pStrings[j]);
827             }
828             free(pStrings);
829             return false;
830         }
831     }
832     va_end(ap);
833 
834     CALL_ONREQUEST(request, pStrings, countStrings * sizeof(char *), pRI, slotId);
835 
836     if (pStrings != NULL) {
837         for (int i = 0 ; i < countStrings ; i++) {
838             memsetAndFreeStrings(1, pStrings[i]);
839         }
840 
841 #ifdef MEMSET_FREED
842         memset(pStrings, 0, countStrings * sizeof(char *));
843 #endif
844         free(pStrings);
845     }
846     return true;
847 }
848 
dispatchStrings(int serial,int slotId,int request,const hidl_vec<hidl_string> & data)849 bool dispatchStrings(int serial, int slotId, int request, const hidl_vec<hidl_string>& data) {
850     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
851     if (pRI == NULL) {
852         return false;
853     }
854 
855     int countStrings = data.size();
856     char **pStrings;
857     pStrings = (char **)calloc(countStrings, sizeof(char *));
858     if (pStrings == NULL) {
859         RLOGE("Memory allocation failed for request %s", requestToString(request));
860         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
861         return false;
862     }
863 
864     for (int i = 0; i < countStrings; i++) {
865         if (!copyHidlStringToRil(&pStrings[i], data[i], pRI)) {
866             for (int j = 0; j < i; j++) {
867                 memsetAndFreeStrings(1, pStrings[j]);
868             }
869             free(pStrings);
870             return false;
871         }
872     }
873 
874     CALL_ONREQUEST(request, pStrings, countStrings * sizeof(char *), pRI, slotId);
875 
876     if (pStrings != NULL) {
877         for (int i = 0 ; i < countStrings ; i++) {
878             memsetAndFreeStrings(1, pStrings[i]);
879         }
880 
881 #ifdef MEMSET_FREED
882         memset(pStrings, 0, countStrings * sizeof(char *));
883 #endif
884         free(pStrings);
885     }
886     return true;
887 }
888 
dispatchInts(int serial,int slotId,int request,int countInts,...)889 bool dispatchInts(int serial, int slotId, int request, int countInts, ...) {
890     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
891     if (pRI == NULL) {
892         return false;
893     }
894 
895     int *pInts = (int *)calloc(countInts, sizeof(int));
896 
897     if (pInts == NULL) {
898         RLOGE("Memory allocation failed for request %s", requestToString(request));
899         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
900         return false;
901     }
902     va_list ap;
903     va_start(ap, countInts);
904     for (int i = 0; i < countInts; i++) {
905         pInts[i] = va_arg(ap, int);
906     }
907     va_end(ap);
908 
909     CALL_ONREQUEST(request, pInts, countInts * sizeof(int), pRI, slotId);
910 
911     if (pInts != NULL) {
912 #ifdef MEMSET_FREED
913         memset(pInts, 0, countInts * sizeof(int));
914 #endif
915         free(pInts);
916     }
917     return true;
918 }
919 
dispatchCallForwardStatus(int serial,int slotId,int request,const CallForwardInfo & callInfo)920 bool dispatchCallForwardStatus(int serial, int slotId, int request,
921                               const CallForwardInfo& callInfo) {
922     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
923     if (pRI == NULL) {
924         return false;
925     }
926 
927     RIL_CallForwardInfo cf;
928     cf.status = (int) callInfo.status;
929     cf.reason = callInfo.reason;
930     cf.serviceClass = callInfo.serviceClass;
931     cf.toa = callInfo.toa;
932     cf.timeSeconds = callInfo.timeSeconds;
933 
934     if (!copyHidlStringToRil(&cf.number, callInfo.number, pRI)) {
935         return false;
936     }
937 
938     CALL_ONREQUEST(request, &cf, sizeof(cf), pRI, slotId);
939 
940     memsetAndFreeStrings(1, cf.number);
941 
942     return true;
943 }
944 
dispatchRaw(int serial,int slotId,int request,const hidl_vec<uint8_t> & rawBytes)945 bool dispatchRaw(int serial, int slotId, int request, const hidl_vec<uint8_t>& rawBytes) {
946     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
947     if (pRI == NULL) {
948         return false;
949     }
950 
951     const uint8_t *uData = rawBytes.data();
952 
953     CALL_ONREQUEST(request, (void *) uData, rawBytes.size(), pRI, slotId);
954 
955     return true;
956 }
957 
dispatchIccApdu(int serial,int slotId,int request,const SimApdu & message)958 bool dispatchIccApdu(int serial, int slotId, int request, const SimApdu& message) {
959     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
960     if (pRI == NULL) {
961         return false;
962     }
963 
964     RIL_SIM_APDU apdu = {};
965 
966     apdu.sessionid = message.sessionId;
967     apdu.cla = message.cla;
968     apdu.instruction = message.instruction;
969     apdu.p1 = message.p1;
970     apdu.p2 = message.p2;
971     apdu.p3 = message.p3;
972 
973     if (!copyHidlStringToRil(&apdu.data, message.data, pRI)) {
974         return false;
975     }
976 
977     CALL_ONREQUEST(request, &apdu, sizeof(apdu), pRI, slotId);
978 
979     memsetAndFreeStrings(1, apdu.data);
980 
981     return true;
982 }
983 
checkReturnStatus(int32_t slotId,Return<void> & ret,bool isRadioService)984 void checkReturnStatus(int32_t slotId, Return<void>& ret, bool isRadioService) {
985     if (ret.isOk() == false) {
986         RLOGE("checkReturnStatus: unable to call response/indication callback");
987         // Remote process hosting the callbacks must be dead. Reset the callback objects;
988         // there's no other recovery to be done here. When the client process is back up, it will
989         // call setResponseFunctions()
990 
991         // Caller should already hold rdlock, release that first
992         // note the current counter to avoid overwriting updates made by another thread before
993         // write lock is acquired.
994         int counter = isRadioService ? mCounterRadio[slotId] : mCounterOemHook[slotId];
995         pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(slotId);
996         int ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
997         CHECK_EQ(ret, 0);
998 
999         // acquire wrlock
1000         ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
1001         CHECK_EQ(ret, 0);
1002 
1003         // make sure the counter value has not changed
1004         if (counter == (isRadioService ? mCounterRadio[slotId] : mCounterOemHook[slotId])) {
1005             if (isRadioService) {
1006                 radioService[slotId]->mRadioResponse = NULL;
1007                 radioService[slotId]->mRadioIndication = NULL;
1008                 radioService[slotId]->mRadioResponseV1_2 = NULL;
1009                 radioService[slotId]->mRadioIndicationV1_2 = NULL;
1010                 radioService[slotId]->mRadioResponseV1_3 = NULL;
1011                 radioService[slotId]->mRadioIndicationV1_3 = NULL;
1012                 radioService[slotId]->mRadioResponseV1_4 = NULL;
1013                 radioService[slotId]->mRadioIndicationV1_4 = NULL;
1014                 radioService[slotId]->mRadioResponseV1_5 = NULL;
1015                 radioService[slotId]->mRadioIndicationV1_5 = NULL;
1016                 radioService[slotId]->mRadioResponseV1_6 = NULL;
1017                 radioService[slotId]->mRadioIndicationV1_6 = NULL;
1018             } else {
1019                 oemHookService[slotId]->mOemHookResponse = NULL;
1020                 oemHookService[slotId]->mOemHookIndication = NULL;
1021             }
1022             isRadioService ? mCounterRadio[slotId]++ : mCounterOemHook[slotId]++;
1023         } else {
1024             RLOGE("checkReturnStatus: not resetting responseFunctions as they likely "
1025                     "got updated on another thread");
1026         }
1027 
1028         // release wrlock
1029         ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
1030         CHECK_EQ(ret, 0);
1031 
1032         // Reacquire rdlock
1033         ret = pthread_rwlock_rdlock(radioServiceRwlockPtr);
1034         CHECK_EQ(ret, 0);
1035     }
1036 }
1037 
checkReturnStatus(Return<void> & ret)1038 void RadioImpl_1_6::checkReturnStatus(Return<void>& ret) {
1039     ::checkReturnStatus(mSlotId, ret, true);
1040 }
1041 
setResponseFunctions(const::android::sp<IRadioResponse> & radioResponseParam,const::android::sp<IRadioIndication> & radioIndicationParam)1042 Return<void> RadioImpl_1_6::setResponseFunctions(
1043         const ::android::sp<IRadioResponse>& radioResponseParam,
1044         const ::android::sp<IRadioIndication>& radioIndicationParam) {
1045     RLOGD("setResponseFunctions");
1046 
1047     pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(mSlotId);
1048     int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
1049     CHECK_EQ(ret, 0);
1050 
1051     mRadioResponse = radioResponseParam;
1052     mRadioIndication = radioIndicationParam;
1053 
1054    mRadioResponseV1_6 = V1_6::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1055    mRadioIndicationV1_6 = V1_6::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1056    if (mRadioResponseV1_6 == nullptr || mRadioIndicationV1_6 == nullptr) {
1057        mRadioResponseV1_6 = nullptr;
1058        mRadioIndicationV1_6 = nullptr;
1059    }
1060 
1061    mRadioResponseV1_5 = V1_5::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1062    mRadioIndicationV1_5 = V1_5::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1063    if (mRadioResponseV1_5 == nullptr || mRadioIndicationV1_5 == nullptr) {
1064        mRadioResponseV1_5 = nullptr;
1065        mRadioIndicationV1_5 = nullptr;
1066    }
1067 
1068     mRadioResponseV1_4 = V1_4::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1069     mRadioIndicationV1_4 = V1_4::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1070     if (mRadioResponseV1_4 == nullptr || mRadioIndicationV1_4 == nullptr) {
1071         mRadioResponseV1_4 = nullptr;
1072         mRadioIndicationV1_4 = nullptr;
1073     }
1074 
1075     mRadioResponseV1_3 = V1_3::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1076     mRadioIndicationV1_3 = V1_3::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1077     if (mRadioResponseV1_3 == nullptr || mRadioIndicationV1_3 == nullptr) {
1078         mRadioResponseV1_3 = nullptr;
1079         mRadioIndicationV1_3 = nullptr;
1080     }
1081 
1082     mRadioResponseV1_2 = V1_2::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1083     mRadioIndicationV1_2 = V1_2::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1084     if (mRadioResponseV1_2 == nullptr || mRadioIndicationV1_2 == nullptr) {
1085         mRadioResponseV1_2 = nullptr;
1086         mRadioIndicationV1_2 = nullptr;
1087     }
1088 
1089     mRadioResponseV1_1 = V1_1::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1090     mRadioIndicationV1_1 = V1_1::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1091     if (mRadioResponseV1_1 == nullptr || mRadioIndicationV1_1 == nullptr) {
1092         mRadioResponseV1_1 = nullptr;
1093         mRadioIndicationV1_1 = nullptr;
1094     }
1095 
1096     mCounterRadio[mSlotId]++;
1097 
1098     ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
1099     CHECK_EQ(ret, 0);
1100 
1101     // client is connected. Send initial indications.
1102     android::onNewCommandConnect((RIL_SOCKET_ID) mSlotId);
1103 
1104     return Void();
1105 }
1106 
getIccCardStatus(int32_t serial)1107 Return<void> RadioImpl_1_6::getIccCardStatus(int32_t serial) {
1108 #if VDBG
1109     RLOGD("getIccCardStatus: serial %d", serial);
1110 #endif
1111     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SIM_STATUS);
1112     return Void();
1113 }
1114 
supplyIccPinForApp(int32_t serial,const hidl_string & pin,const hidl_string & aid)1115 Return<void> RadioImpl_1_6::supplyIccPinForApp(int32_t serial, const hidl_string& pin,
1116         const hidl_string& aid) {
1117 #if VDBG
1118     RLOGD("supplyIccPinForApp: serial %d", serial);
1119 #endif
1120     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN, true,
1121             2, pin.c_str(), aid.c_str());
1122     return Void();
1123 }
1124 
supplyIccPukForApp(int32_t serial,const hidl_string & puk,const hidl_string & pin,const hidl_string & aid)1125 Return<void> RadioImpl_1_6::supplyIccPukForApp(int32_t serial, const hidl_string& puk,
1126                                            const hidl_string& pin, const hidl_string& aid) {
1127 #if VDBG
1128     RLOGD("supplyIccPukForApp: serial %d", serial);
1129 #endif
1130     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK, true,
1131             3, puk.c_str(), pin.c_str(), aid.c_str());
1132     return Void();
1133 }
1134 
supplyIccPin2ForApp(int32_t serial,const hidl_string & pin2,const hidl_string & aid)1135 Return<void> RadioImpl_1_6::supplyIccPin2ForApp(int32_t serial, const hidl_string& pin2,
1136                                             const hidl_string& aid) {
1137 #if VDBG
1138     RLOGD("supplyIccPin2ForApp: serial %d", serial);
1139 #endif
1140     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN2, true,
1141             2, pin2.c_str(), aid.c_str());
1142     return Void();
1143 }
1144 
supplyIccPuk2ForApp(int32_t serial,const hidl_string & puk2,const hidl_string & pin2,const hidl_string & aid)1145 Return<void> RadioImpl_1_6::supplyIccPuk2ForApp(int32_t serial, const hidl_string& puk2,
1146                                             const hidl_string& pin2, const hidl_string& aid) {
1147 #if VDBG
1148     RLOGD("supplyIccPuk2ForApp: serial %d", serial);
1149 #endif
1150     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK2, true,
1151             3, puk2.c_str(), pin2.c_str(), aid.c_str());
1152     return Void();
1153 }
1154 
changeIccPinForApp(int32_t serial,const hidl_string & oldPin,const hidl_string & newPin,const hidl_string & aid)1155 Return<void> RadioImpl_1_6::changeIccPinForApp(int32_t serial, const hidl_string& oldPin,
1156                                            const hidl_string& newPin, const hidl_string& aid) {
1157 #if VDBG
1158     RLOGD("changeIccPinForApp: serial %d", serial);
1159 #endif
1160     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN, true,
1161             3, oldPin.c_str(), newPin.c_str(), aid.c_str());
1162     return Void();
1163 }
1164 
changeIccPin2ForApp(int32_t serial,const hidl_string & oldPin2,const hidl_string & newPin2,const hidl_string & aid)1165 Return<void> RadioImpl_1_6::changeIccPin2ForApp(int32_t serial, const hidl_string& oldPin2,
1166                                             const hidl_string& newPin2, const hidl_string& aid) {
1167 #if VDBG
1168     RLOGD("changeIccPin2ForApp: serial %d", serial);
1169 #endif
1170     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN2, true,
1171             3, oldPin2.c_str(), newPin2.c_str(), aid.c_str());
1172     return Void();
1173 }
1174 
supplyNetworkDepersonalization(int32_t serial,const hidl_string & netPin)1175 Return<void> RadioImpl_1_6::supplyNetworkDepersonalization(int32_t serial,
1176                                                        const hidl_string& netPin) {
1177 #if VDBG
1178     RLOGD("supplyNetworkDepersonalization: serial %d", serial);
1179 #endif
1180     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, true,
1181             1, netPin.c_str());
1182     return Void();
1183 }
1184 
getCurrentCalls(int32_t serial)1185 Return<void> RadioImpl_1_6::getCurrentCalls(int32_t serial) {
1186 #if VDBG
1187     RLOGD("getCurrentCalls: serial %d", serial);
1188 #endif
1189     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CURRENT_CALLS);
1190     return Void();
1191 }
1192 
getCurrentCalls_1_6(int32_t serial)1193 Return<void> RadioImpl_1_6::getCurrentCalls_1_6(int32_t serial) {
1194 #if VDBG
1195     RLOGD("getCurrentCalls_1_6: serial %d", serial);
1196 #endif
1197     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CURRENT_CALLS);
1198     return Void();
1199 }
1200 
dial(int32_t serial,const Dial & dialInfo)1201 Return<void> RadioImpl_1_6::dial(int32_t serial, const Dial& dialInfo) {
1202 #if VDBG
1203     RLOGD("dial: serial %d", serial);
1204 #endif
1205     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_DIAL);
1206     if (pRI == NULL) {
1207         return Void();
1208     }
1209     RIL_Dial dial = {};
1210     RIL_UUS_Info uusInfo = {};
1211     int32_t sizeOfDial = sizeof(dial);
1212 
1213     if (!copyHidlStringToRil(&dial.address, dialInfo.address, pRI)) {
1214         return Void();
1215     }
1216     dial.clir = (int) dialInfo.clir;
1217 
1218     if (dialInfo.uusInfo.size() != 0) {
1219         uusInfo.uusType = (RIL_UUS_Type) dialInfo.uusInfo[0].uusType;
1220         uusInfo.uusDcs = (RIL_UUS_DCS) dialInfo.uusInfo[0].uusDcs;
1221 
1222         if (dialInfo.uusInfo[0].uusData.size() == 0) {
1223             uusInfo.uusData = NULL;
1224             uusInfo.uusLength = 0;
1225         } else {
1226             if (!copyHidlStringToRil(&uusInfo.uusData, dialInfo.uusInfo[0].uusData, pRI)) {
1227                 memsetAndFreeStrings(1, dial.address);
1228                 return Void();
1229             }
1230             uusInfo.uusLength = dialInfo.uusInfo[0].uusData.size();
1231         }
1232 
1233         dial.uusInfo = &uusInfo;
1234     }
1235 
1236     CALL_ONREQUEST(RIL_REQUEST_DIAL, &dial, sizeOfDial, pRI, mSlotId);
1237 
1238     memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
1239 
1240     return Void();
1241 }
1242 
getImsiForApp(int32_t serial,const hidl_string & aid)1243 Return<void> RadioImpl_1_6::getImsiForApp(int32_t serial, const hidl_string& aid) {
1244 #if VDBG
1245     RLOGD("getImsiForApp: serial %d", serial);
1246 #endif
1247     dispatchStrings(serial, mSlotId, RIL_REQUEST_GET_IMSI, false,
1248             1, aid.c_str());
1249     return Void();
1250 }
1251 
hangup(int32_t serial,int32_t gsmIndex)1252 Return<void> RadioImpl_1_6::hangup(int32_t serial, int32_t gsmIndex) {
1253 #if VDBG
1254     RLOGD("hangup: serial %d", serial);
1255 #endif
1256     dispatchInts(serial, mSlotId, RIL_REQUEST_HANGUP, 1, gsmIndex);
1257     return Void();
1258 }
1259 
hangupWaitingOrBackground(int32_t serial)1260 Return<void> RadioImpl_1_6::hangupWaitingOrBackground(int32_t serial) {
1261 #if VDBG
1262     RLOGD("hangupWaitingOrBackground: serial %d", serial);
1263 #endif
1264     dispatchVoid(serial, mSlotId, RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND);
1265     return Void();
1266 }
1267 
hangupForegroundResumeBackground(int32_t serial)1268 Return<void> RadioImpl_1_6::hangupForegroundResumeBackground(int32_t serial) {
1269 #if VDBG
1270     RLOGD("hangupForegroundResumeBackground: serial %d", serial);
1271 #endif
1272     dispatchVoid(serial, mSlotId, RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND);
1273     return Void();
1274 }
1275 
switchWaitingOrHoldingAndActive(int32_t serial)1276 Return<void> RadioImpl_1_6::switchWaitingOrHoldingAndActive(int32_t serial) {
1277 #if VDBG
1278     RLOGD("switchWaitingOrHoldingAndActive: serial %d", serial);
1279 #endif
1280     dispatchVoid(serial, mSlotId, RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE);
1281     return Void();
1282 }
1283 
conference(int32_t serial)1284 Return<void> RadioImpl_1_6::conference(int32_t serial) {
1285 #if VDBG
1286     RLOGD("conference: serial %d", serial);
1287 #endif
1288     dispatchVoid(serial, mSlotId, RIL_REQUEST_CONFERENCE);
1289     return Void();
1290 }
1291 
rejectCall(int32_t serial)1292 Return<void> RadioImpl_1_6::rejectCall(int32_t serial) {
1293 #if VDBG
1294     RLOGD("rejectCall: serial %d", serial);
1295 #endif
1296     dispatchVoid(serial, mSlotId, RIL_REQUEST_UDUB);
1297     return Void();
1298 }
1299 
getLastCallFailCause(int32_t serial)1300 Return<void> RadioImpl_1_6::getLastCallFailCause(int32_t serial) {
1301 #if VDBG
1302     RLOGD("getLastCallFailCause: serial %d", serial);
1303 #endif
1304     dispatchVoid(serial, mSlotId, RIL_REQUEST_LAST_CALL_FAIL_CAUSE);
1305     return Void();
1306 }
1307 
getSignalStrength(int32_t serial)1308 Return<void> RadioImpl_1_6::getSignalStrength(int32_t serial) {
1309 #if VDBG
1310     RLOGD("getSignalStrength: serial %d", serial);
1311 #endif
1312     dispatchVoid(serial, mSlotId, RIL_REQUEST_SIGNAL_STRENGTH);
1313     return Void();
1314 }
1315 
getVoiceRegistrationState(int32_t serial)1316 Return<void> RadioImpl_1_6::getVoiceRegistrationState(int32_t serial) {
1317 #if VDBG
1318     RLOGD("getVoiceRegistrationState: serial %d", serial);
1319 #endif
1320     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_REGISTRATION_STATE);
1321     return Void();
1322 }
1323 
getDataRegistrationState(int32_t serial)1324 Return<void> RadioImpl_1_6::getDataRegistrationState(int32_t serial) {
1325 #if VDBG
1326     RLOGD("getDataRegistrationState: serial %d", serial);
1327 #endif
1328     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_REGISTRATION_STATE);
1329     return Void();
1330 }
1331 
getOperator(int32_t serial)1332 Return<void> RadioImpl_1_6::getOperator(int32_t serial) {
1333 #if VDBG
1334     RLOGD("getOperator: serial %d", serial);
1335 #endif
1336     dispatchVoid(serial, mSlotId, RIL_REQUEST_OPERATOR);
1337     return Void();
1338 }
1339 
setRadioPower(int32_t serial,bool on)1340 Return<void> RadioImpl_1_6::setRadioPower(int32_t serial, bool on) {
1341 #if VDBG
1342     RLOGD("setRadioPower: serial %d on %d", serial, on);
1343 #endif
1344     dispatchInts(serial, mSlotId, RIL_REQUEST_RADIO_POWER, 1, BOOL_TO_INT(on));
1345     return Void();
1346 }
1347 
sendDtmf(int32_t serial,const hidl_string & s)1348 Return<void> RadioImpl_1_6::sendDtmf(int32_t serial, const hidl_string& s) {
1349 #if VDBG
1350     RLOGD("sendDtmf: serial %d", serial);
1351 #endif
1352     dispatchString(serial, mSlotId, RIL_REQUEST_DTMF, s.c_str());
1353     return Void();
1354 }
1355 
sendSms(int32_t serial,const GsmSmsMessage & message)1356 Return<void> RadioImpl_1_6::sendSms(int32_t serial, const GsmSmsMessage& message) {
1357 #if VDBG
1358     RLOGD("sendSms: serial %d", serial);
1359 #endif
1360     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS, false,
1361             2, message.smscPdu.c_str(), message.pdu.c_str());
1362     return Void();
1363 }
1364 
sendSms_1_6(int32_t serial,const GsmSmsMessage & message)1365 Return<void> RadioImpl_1_6::sendSms_1_6(int32_t serial, const GsmSmsMessage& message) {
1366 #if VDBG
1367     RLOGD("sendSms: serial %d", serial);
1368 #endif
1369     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS, false,
1370             2, message.smscPdu.c_str(), message.pdu.c_str());
1371     return Void();
1372 }
1373 
sendSMSExpectMore(int32_t serial,const GsmSmsMessage & message)1374 Return<void> RadioImpl_1_6::sendSMSExpectMore(int32_t serial, const GsmSmsMessage& message) {
1375 #if VDBG
1376     RLOGD("sendSmsExpectMore: serial %d", serial);
1377 #endif
1378     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS_EXPECT_MORE, false,
1379             2, message.smscPdu.c_str(), message.pdu.c_str());
1380     return Void();
1381 }
1382 
sendSmsExpectMore_1_6(int32_t serial,const GsmSmsMessage & message)1383 Return<void> RadioImpl_1_6::sendSmsExpectMore_1_6(int32_t serial, const GsmSmsMessage& message) {
1384 #if VDBG
1385     RLOGD("sendSmsExpectMore: serial %d", serial);
1386 #endif
1387     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS_EXPECT_MORE, false,
1388             2, message.smscPdu.c_str(), message.pdu.c_str());
1389     return Void();
1390 }
1391 
convertMvnoTypeToString(MvnoType type,char * & str)1392 static bool convertMvnoTypeToString(MvnoType type, char *&str) {
1393     switch (type) {
1394         case MvnoType::IMSI:
1395             str = (char *)"imsi";
1396             return true;
1397         case MvnoType::GID:
1398             str = (char *)"gid";
1399             return true;
1400         case MvnoType::SPN:
1401             str = (char *)"spn";
1402             return true;
1403         case MvnoType::NONE:
1404             str = (char *)"";
1405             return true;
1406     }
1407     return false;
1408 }
1409 
setupDataCall(int32_t serial,RadioTechnology radioTechnology,const DataProfileInfo & dataProfileInfo,bool modemCognitive,bool roamingAllowed,bool isRoaming)1410 Return<void> RadioImpl_1_6::setupDataCall(int32_t serial, RadioTechnology radioTechnology,
1411                                       const DataProfileInfo& dataProfileInfo, bool modemCognitive,
1412                                       bool roamingAllowed, bool isRoaming) {
1413 
1414 #if VDBG
1415     RLOGD("setupDataCall: serial %d", serial);
1416 #endif
1417 
1418     if (s_vendorFunctions->version >= 4 && s_vendorFunctions->version <= 14) {
1419         const hidl_string &protocol =
1420                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
1421         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 7,
1422             std::to_string((int) radioTechnology + 2).c_str(),
1423             std::to_string((int) dataProfileInfo.profileId).c_str(),
1424             dataProfileInfo.apn.c_str(),
1425             dataProfileInfo.user.c_str(),
1426             dataProfileInfo.password.c_str(),
1427             std::to_string((int) dataProfileInfo.authType).c_str(),
1428             protocol.c_str());
1429     } else if (s_vendorFunctions->version == 15) {
1430         char *mvnoTypeStr = NULL;
1431         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) {
1432             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
1433                     RIL_REQUEST_SETUP_DATA_CALL);
1434             if (pRI != NULL) {
1435                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1436             }
1437             return Void();
1438         }
1439         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15,
1440             std::to_string((int) radioTechnology + 2).c_str(),
1441             std::to_string((int) dataProfileInfo.profileId).c_str(),
1442             dataProfileInfo.apn.c_str(),
1443             dataProfileInfo.user.c_str(),
1444             dataProfileInfo.password.c_str(),
1445             std::to_string((int) dataProfileInfo.authType).c_str(),
1446             dataProfileInfo.protocol.c_str(),
1447             dataProfileInfo.roamingProtocol.c_str(),
1448             std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
1449             std::to_string(dataProfileInfo.bearerBitmap).c_str(),
1450             modemCognitive ? "1" : "0",
1451             std::to_string(dataProfileInfo.mtu).c_str(),
1452             mvnoTypeStr,
1453             dataProfileInfo.mvnoMatchData.c_str(),
1454             roamingAllowed ? "1" : "0");
1455     } else if (s_vendorFunctions->version >= 16) {
1456         char *mvnoTypeStr = NULL;
1457         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) {
1458             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
1459                     RIL_REQUEST_SETUP_DATA_CALL);
1460             if (pRI != NULL) {
1461                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1462             }
1463             return Void();
1464         }
1465         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 16,
1466             std::to_string((int) radioTechnology + 2).c_str(),
1467             std::to_string((int) dataProfileInfo.profileId).c_str(),
1468             dataProfileInfo.apn.c_str(),
1469             dataProfileInfo.user.c_str(),
1470             dataProfileInfo.password.c_str(),
1471             std::to_string((int) dataProfileInfo.authType).c_str(),
1472             dataProfileInfo.protocol.c_str(),
1473             dataProfileInfo.roamingProtocol.c_str(),
1474             std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
1475             std::to_string(dataProfileInfo.bearerBitmap).c_str(),
1476             modemCognitive ? "1" : "0",
1477             std::to_string(dataProfileInfo.mtu).c_str(),
1478             mvnoTypeStr,
1479             dataProfileInfo.mvnoMatchData.c_str(),
1480             roamingAllowed ? "1" : "0",
1481             "-1",
1482             "");
1483     } else {
1484         RLOGE("Unsupported RIL version %d, min version expected 4", s_vendorFunctions->version);
1485         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
1486                 RIL_REQUEST_SETUP_DATA_CALL);
1487         if (pRI != NULL) {
1488             sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
1489         }
1490     }
1491     return Void();
1492 }
1493 
iccIOForApp(int32_t serial,const IccIo & iccIo)1494 Return<void> RadioImpl_1_6::iccIOForApp(int32_t serial, const IccIo& iccIo) {
1495 #if VDBG
1496     RLOGD("iccIOForApp: serial %d", serial);
1497 #endif
1498     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_IO);
1499     if (pRI == NULL) {
1500         return Void();
1501     }
1502 
1503     RIL_SIM_IO_v6 rilIccIo = {};
1504     rilIccIo.command = iccIo.command;
1505     rilIccIo.fileid = iccIo.fileId;
1506     if (!copyHidlStringToRil(&rilIccIo.path, iccIo.path, pRI)) {
1507         return Void();
1508     }
1509 
1510     rilIccIo.p1 = iccIo.p1;
1511     rilIccIo.p2 = iccIo.p2;
1512     rilIccIo.p3 = iccIo.p3;
1513 
1514     if (!copyHidlStringToRil(&rilIccIo.data, iccIo.data, pRI)) {
1515         memsetAndFreeStrings(1, rilIccIo.path);
1516         return Void();
1517     }
1518 
1519     if (!copyHidlStringToRil(&rilIccIo.pin2, iccIo.pin2, pRI)) {
1520         memsetAndFreeStrings(2, rilIccIo.path, rilIccIo.data);
1521         return Void();
1522     }
1523 
1524     if (!copyHidlStringToRil(&rilIccIo.aidPtr, iccIo.aid, pRI)) {
1525         memsetAndFreeStrings(3, rilIccIo.path, rilIccIo.data, rilIccIo.pin2);
1526         return Void();
1527     }
1528 
1529     CALL_ONREQUEST(RIL_REQUEST_SIM_IO, &rilIccIo, sizeof(rilIccIo), pRI, mSlotId);
1530 
1531     memsetAndFreeStrings(4, rilIccIo.path, rilIccIo.data, rilIccIo.pin2, rilIccIo.aidPtr);
1532 
1533     return Void();
1534 }
1535 
sendUssd(int32_t serial,const hidl_string & ussd)1536 Return<void> RadioImpl_1_6::sendUssd(int32_t serial, const hidl_string& ussd) {
1537 #if VDBG
1538     RLOGD("sendUssd: serial %d", serial);
1539 #endif
1540     dispatchString(serial, mSlotId, RIL_REQUEST_SEND_USSD, ussd.c_str());
1541     return Void();
1542 }
1543 
cancelPendingUssd(int32_t serial)1544 Return<void> RadioImpl_1_6::cancelPendingUssd(int32_t serial) {
1545 #if VDBG
1546     RLOGD("cancelPendingUssd: serial %d", serial);
1547 #endif
1548     dispatchVoid(serial, mSlotId, RIL_REQUEST_CANCEL_USSD);
1549     return Void();
1550 }
1551 
getClir(int32_t serial)1552 Return<void> RadioImpl_1_6::getClir(int32_t serial) {
1553 #if VDBG
1554     RLOGD("getClir: serial %d", serial);
1555 #endif
1556     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CLIR);
1557     return Void();
1558 }
1559 
setClir(int32_t serial,int32_t status)1560 Return<void> RadioImpl_1_6::setClir(int32_t serial, int32_t status) {
1561 #if VDBG
1562     RLOGD("setClir: serial %d", serial);
1563 #endif
1564     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_CLIR, 1, status);
1565     return Void();
1566 }
1567 
getCallForwardStatus(int32_t serial,const CallForwardInfo & callInfo)1568 Return<void> RadioImpl_1_6::getCallForwardStatus(int32_t serial, const CallForwardInfo& callInfo) {
1569 #if VDBG
1570     RLOGD("getCallForwardStatus: serial %d", serial);
1571 #endif
1572     dispatchCallForwardStatus(serial, mSlotId, RIL_REQUEST_QUERY_CALL_FORWARD_STATUS,
1573             callInfo);
1574     return Void();
1575 }
1576 
setCallForward(int32_t serial,const CallForwardInfo & callInfo)1577 Return<void> RadioImpl_1_6::setCallForward(int32_t serial, const CallForwardInfo& callInfo) {
1578 #if VDBG
1579     RLOGD("setCallForward: serial %d", serial);
1580 #endif
1581     dispatchCallForwardStatus(serial, mSlotId, RIL_REQUEST_SET_CALL_FORWARD,
1582             callInfo);
1583     return Void();
1584 }
1585 
getCallWaiting(int32_t serial,int32_t serviceClass)1586 Return<void> RadioImpl_1_6::getCallWaiting(int32_t serial, int32_t serviceClass) {
1587 #if VDBG
1588     RLOGD("getCallWaiting: serial %d", serial);
1589 #endif
1590     dispatchInts(serial, mSlotId, RIL_REQUEST_QUERY_CALL_WAITING, 1, serviceClass);
1591     return Void();
1592 }
1593 
setCallWaiting(int32_t serial,bool enable,int32_t serviceClass)1594 Return<void> RadioImpl_1_6::setCallWaiting(int32_t serial, bool enable, int32_t serviceClass) {
1595 #if VDBG
1596     RLOGD("setCallWaiting: serial %d", serial);
1597 #endif
1598     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_CALL_WAITING, 2, BOOL_TO_INT(enable),
1599             serviceClass);
1600     return Void();
1601 }
1602 
acknowledgeLastIncomingGsmSms(int32_t serial,bool success,SmsAcknowledgeFailCause cause)1603 Return<void> RadioImpl_1_6::acknowledgeLastIncomingGsmSms(int32_t serial,
1604                                                       bool success, SmsAcknowledgeFailCause cause) {
1605 #if VDBG
1606     RLOGD("acknowledgeLastIncomingGsmSms: serial %d", serial);
1607 #endif
1608     dispatchInts(serial, mSlotId, RIL_REQUEST_SMS_ACKNOWLEDGE, 2, BOOL_TO_INT(success),
1609             cause);
1610     return Void();
1611 }
1612 
acceptCall(int32_t serial)1613 Return<void> RadioImpl_1_6::acceptCall(int32_t serial) {
1614 #if VDBG
1615     RLOGD("acceptCall: serial %d", serial);
1616 #endif
1617     dispatchVoid(serial, mSlotId, RIL_REQUEST_ANSWER);
1618     return Void();
1619 }
1620 
deactivateDataCall(int32_t serial,int32_t cid,bool reasonRadioShutDown)1621 Return<void> RadioImpl_1_6::deactivateDataCall(int32_t serial,
1622                                            int32_t cid, bool reasonRadioShutDown) {
1623 #if VDBG
1624     RLOGD("deactivateDataCall: serial %d", serial);
1625 #endif
1626     dispatchStrings(serial, mSlotId, RIL_REQUEST_DEACTIVATE_DATA_CALL, false,
1627             2, (std::to_string(cid)).c_str(), reasonRadioShutDown ? "1" : "0");
1628     return Void();
1629 }
1630 
getFacilityLockForApp(int32_t serial,const hidl_string & facility,const hidl_string & password,int32_t serviceClass,const hidl_string & appId)1631 Return<void> RadioImpl_1_6::getFacilityLockForApp(int32_t serial, const hidl_string& facility,
1632                                               const hidl_string& password, int32_t serviceClass,
1633                                               const hidl_string& appId) {
1634 #if VDBG
1635     RLOGD("getFacilityLockForApp: serial %d", serial);
1636 #endif
1637     dispatchStrings(serial, mSlotId, RIL_REQUEST_QUERY_FACILITY_LOCK, true,
1638             4, facility.c_str(), password.c_str(),
1639             (std::to_string(serviceClass)).c_str(), appId.c_str());
1640     return Void();
1641 }
1642 
setFacilityLockForApp(int32_t serial,const hidl_string & facility,bool lockState,const hidl_string & password,int32_t serviceClass,const hidl_string & appId)1643 Return<void> RadioImpl_1_6::setFacilityLockForApp(int32_t serial, const hidl_string& facility,
1644                                               bool lockState, const hidl_string& password,
1645                                               int32_t serviceClass, const hidl_string& appId) {
1646 #if VDBG
1647     RLOGD("setFacilityLockForApp: serial %d", serial);
1648 #endif
1649     dispatchStrings(serial, mSlotId, RIL_REQUEST_SET_FACILITY_LOCK, true,
1650             5, facility.c_str(), lockState ? "1" : "0", password.c_str(),
1651             (std::to_string(serviceClass)).c_str(), appId.c_str() );
1652     return Void();
1653 }
1654 
setBarringPassword(int32_t serial,const hidl_string & facility,const hidl_string & oldPassword,const hidl_string & newPassword)1655 Return<void> RadioImpl_1_6::setBarringPassword(int32_t serial, const hidl_string& facility,
1656                                            const hidl_string& oldPassword,
1657                                            const hidl_string& newPassword) {
1658 #if VDBG
1659     RLOGD("setBarringPassword: serial %d", serial);
1660 #endif
1661     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_BARRING_PASSWORD, true,
1662             3, facility.c_str(), oldPassword.c_str(), newPassword.c_str());
1663     return Void();
1664 }
1665 
getNetworkSelectionMode(int32_t serial)1666 Return<void> RadioImpl_1_6::getNetworkSelectionMode(int32_t serial) {
1667 #if VDBG
1668     RLOGD("getNetworkSelectionMode: serial %d", serial);
1669 #endif
1670     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE);
1671     return Void();
1672 }
1673 
setNetworkSelectionModeAutomatic(int32_t serial)1674 Return<void> RadioImpl_1_6::setNetworkSelectionModeAutomatic(int32_t serial) {
1675 #if VDBG
1676     RLOGD("setNetworkSelectionModeAutomatic: serial %d", serial);
1677 #endif
1678     dispatchVoid(serial, mSlotId, RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC);
1679     return Void();
1680 }
1681 
setNetworkSelectionModeManual(int32_t serial,const hidl_string & operatorNumeric)1682 Return<void> RadioImpl_1_6::setNetworkSelectionModeManual(int32_t serial,
1683                                                       const hidl_string& operatorNumeric) {
1684 #if VDBG
1685     RLOGD("setNetworkSelectionModeManual: serial %d", serial);
1686 #endif
1687     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
1688         RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL);
1689     if (pRI == NULL) {
1690         return Void();
1691     }
1692 
1693     RIL_NetworkOperator networkOperator = {};
1694 
1695     networkOperator.act = UNKNOWN;
1696     if (!copyHidlStringToRil(&networkOperator.operatorNumeric, operatorNumeric, pRI)) {
1697         return Void();
1698     }
1699     CALL_ONREQUEST(pRI->pCI->requestNumber, &networkOperator,
1700         sizeof(networkOperator), pRI, mSlotId);
1701 
1702     return Void();
1703 }
1704 
getAvailableNetworks(int32_t serial)1705 Return<void> RadioImpl_1_6::getAvailableNetworks(int32_t serial) {
1706 #if VDBG
1707     RLOGD("getAvailableNetworks: serial %d", serial);
1708 #endif
1709     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_AVAILABLE_NETWORKS);
1710     return Void();
1711 }
1712 
startNetworkScan(int32_t serial,const V1_1::NetworkScanRequest & request)1713 Return<void> RadioImpl_1_6::startNetworkScan(int32_t serial, const V1_1::NetworkScanRequest& request) {
1714 #if VDBG
1715     RLOGD("startNetworkScan: serial %d", serial);
1716 #endif
1717 
1718     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
1719     if (pRI == NULL) {
1720         return Void();
1721     }
1722 
1723     if (request.specifiers.size() > MAX_RADIO_ACCESS_NETWORKS) {
1724         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1725         return Void();
1726     }
1727 
1728     RIL_NetworkScanRequest scan_request = {};
1729 
1730     scan_request.type = (RIL_ScanType) request.type;
1731     scan_request.interval = request.interval;
1732     scan_request.specifiers_length = request.specifiers.size();
1733     for (size_t i = 0; i < request.specifiers.size(); ++i) {
1734         if (request.specifiers[i].geranBands.size() > MAX_BANDS ||
1735             request.specifiers[i].utranBands.size() > MAX_BANDS ||
1736             request.specifiers[i].eutranBands.size() > MAX_BANDS ||
1737             request.specifiers[i].channels.size() > MAX_CHANNELS) {
1738             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1739             return Void();
1740         }
1741         const V1_1::RadioAccessSpecifier& ras_from =
1742                 request.specifiers[i];
1743         RIL_RadioAccessSpecifier& ras_to = scan_request.specifiers[i];
1744 
1745         ras_to.radio_access_network = (RIL_RadioAccessNetworks) ras_from.radioAccessNetwork;
1746         ras_to.channels_length = ras_from.channels.size();
1747 
1748         std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
1749         const std::vector<uint32_t> * bands = nullptr;
1750         switch (request.specifiers[i].radioAccessNetwork) {
1751             case V1_1::RadioAccessNetworks::GERAN:
1752                 ras_to.bands_length = ras_from.geranBands.size();
1753                 bands = (std::vector<uint32_t> *) &ras_from.geranBands;
1754                 break;
1755             case V1_1::RadioAccessNetworks::UTRAN:
1756                 ras_to.bands_length = ras_from.utranBands.size();
1757                 bands = (std::vector<uint32_t> *) &ras_from.utranBands;
1758                 break;
1759             case V1_1::RadioAccessNetworks::EUTRAN:
1760                 ras_to.bands_length = ras_from.eutranBands.size();
1761                 bands = (std::vector<uint32_t> *) &ras_from.eutranBands;
1762                 break;
1763             default:
1764                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1765                 return Void();
1766         }
1767         // safe to copy to geran_bands because it's a union member
1768         for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
1769             ras_to.bands.geran_bands[idx] = (RIL_GeranBands) (*bands)[idx];
1770         }
1771     }
1772 
1773     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
1774             mSlotId);
1775 
1776     return Void();
1777 }
1778 
stopNetworkScan(int32_t serial)1779 Return<void> RadioImpl_1_6::stopNetworkScan(int32_t serial) {
1780 #if VDBG
1781     RLOGD("stopNetworkScan: serial %d", serial);
1782 #endif
1783     dispatchVoid(serial, mSlotId, RIL_REQUEST_STOP_NETWORK_SCAN);
1784     return Void();
1785 }
1786 
startDtmf(int32_t serial,const hidl_string & s)1787 Return<void> RadioImpl_1_6::startDtmf(int32_t serial, const hidl_string& s) {
1788 #if VDBG
1789     RLOGD("startDtmf: serial %d", serial);
1790 #endif
1791     dispatchString(serial, mSlotId, RIL_REQUEST_DTMF_START,
1792             s.c_str());
1793     return Void();
1794 }
1795 
stopDtmf(int32_t serial)1796 Return<void> RadioImpl_1_6::stopDtmf(int32_t serial) {
1797 #if VDBG
1798     RLOGD("stopDtmf: serial %d", serial);
1799 #endif
1800     dispatchVoid(serial, mSlotId, RIL_REQUEST_DTMF_STOP);
1801     return Void();
1802 }
1803 
getBasebandVersion(int32_t serial)1804 Return<void> RadioImpl_1_6::getBasebandVersion(int32_t serial) {
1805 #if VDBG
1806     RLOGD("getBasebandVersion: serial %d", serial);
1807 #endif
1808     dispatchVoid(serial, mSlotId, RIL_REQUEST_BASEBAND_VERSION);
1809     return Void();
1810 }
1811 
separateConnection(int32_t serial,int32_t gsmIndex)1812 Return<void> RadioImpl_1_6::separateConnection(int32_t serial, int32_t gsmIndex) {
1813 #if VDBG
1814     RLOGD("separateConnection: serial %d", serial);
1815 #endif
1816     dispatchInts(serial, mSlotId, RIL_REQUEST_SEPARATE_CONNECTION, 1, gsmIndex);
1817     return Void();
1818 }
1819 
setMute(int32_t serial,bool enable)1820 Return<void> RadioImpl_1_6::setMute(int32_t serial, bool enable) {
1821 #if VDBG
1822     RLOGD("setMute: serial %d", serial);
1823 #endif
1824     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_MUTE, 1, BOOL_TO_INT(enable));
1825     return Void();
1826 }
1827 
getMute(int32_t serial)1828 Return<void> RadioImpl_1_6::getMute(int32_t serial) {
1829 #if VDBG
1830     RLOGD("getMute: serial %d", serial);
1831 #endif
1832     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_MUTE);
1833     return Void();
1834 }
1835 
getClip(int32_t serial)1836 Return<void> RadioImpl_1_6::getClip(int32_t serial) {
1837 #if VDBG
1838     RLOGD("getClip: serial %d", serial);
1839 #endif
1840     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_CLIP);
1841     return Void();
1842 }
1843 
getDataCallList(int32_t serial)1844 Return<void> RadioImpl_1_6::getDataCallList(int32_t serial) {
1845 #if VDBG
1846     RLOGD("getDataCallList: serial %d", serial);
1847 #endif
1848     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_CALL_LIST);
1849     return Void();
1850 }
1851 
getDataCallList_1_6(int32_t serial)1852 Return<void> RadioImpl_1_6::getDataCallList_1_6(int32_t serial) {
1853 #if VDBG
1854     RLOGD("getDataCallList_1_6: serial %d", serial);
1855 #endif
1856     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_CALL_LIST);
1857     return Void();
1858 }
1859 
emergencyDial_1_6(int32_t serial,const::android::hardware::radio::V1_0::Dial & dialInfo,hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,const hidl_vec<hidl_string> & urns,::android::hardware::radio::V1_4::EmergencyCallRouting routing,bool fromEmergencyDialer,bool)1860 Return<void> RadioImpl_1_6::emergencyDial_1_6(int32_t serial,
1861         const ::android::hardware::radio::V1_0::Dial& dialInfo,
1862         hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,
1863         const hidl_vec<hidl_string>&  urns ,
1864         ::android::hardware::radio::V1_4::EmergencyCallRouting routing,
1865         bool fromEmergencyDialer, bool /* isTesting */) {
1866 #if VDBG
1867     RLOGD("emergencyDial: serial %d", serial);
1868 #endif
1869 
1870     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_EMERGENCY_DIAL);
1871     if (pRI == NULL) {
1872         return Void();
1873     }
1874 
1875     RIL_EmergencyDial eccDial = {};
1876     RIL_Dial& dial = eccDial.dialInfo;
1877     RIL_UUS_Info uusInfo = {};
1878 
1879     if (!copyHidlStringToRil(&dial.address, dialInfo.address, pRI)) {
1880         return Void();
1881     }
1882     dial.clir = (int) dialInfo.clir;
1883 
1884     if (dialInfo.uusInfo.size() != 0) {
1885         uusInfo.uusType = (RIL_UUS_Type) dialInfo.uusInfo[0].uusType;
1886         uusInfo.uusDcs = (RIL_UUS_DCS) dialInfo.uusInfo[0].uusDcs;
1887 
1888         if (dialInfo.uusInfo[0].uusData.size() == 0) {
1889             uusInfo.uusData = NULL;
1890             uusInfo.uusLength = 0;
1891         } else {
1892             if (!copyHidlStringToRil(&uusInfo.uusData, dialInfo.uusInfo[0].uusData, pRI)) {
1893                 memsetAndFreeStrings(1, dial.address);
1894                 return Void();
1895             }
1896             uusInfo.uusLength = dialInfo.uusInfo[0].uusData.size();
1897         }
1898 
1899         dial.uusInfo = &uusInfo;
1900     }
1901 
1902     eccDial.urnsNumber = urns.size();
1903     if (eccDial.urnsNumber != 0) {
1904         char **ppUrns = (char **)calloc(eccDial.urnsNumber, sizeof(char *));
1905         if (ppUrns == NULL) {
1906             RLOGE("Memory allocation failed for request %s",
1907                     requestToString(pRI->pCI->requestNumber));
1908             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
1909             memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
1910             return Void();
1911         }
1912         for (uint32_t i = 0; i < eccDial.urnsNumber; i++) {
1913             if (!copyHidlStringToRil(&ppUrns[i], hidl_string(urns[i]), pRI)) {
1914                 for (uint32_t j = 0; j < i; j++) {
1915                     memsetAndFreeStrings(1, ppUrns[j]);
1916                 }
1917                 memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
1918                 free(ppUrns);
1919                 return Void();
1920             }
1921         }
1922         eccDial.urns = ppUrns;
1923     }
1924 
1925     eccDial.categories = (RIL_EmergencyServiceCategory)categories;
1926     eccDial.routing = (RIL_EmergencyCallRouting)routing;
1927     eccDial.fromEmergencyDialer = fromEmergencyDialer;
1928 
1929     CALL_ONREQUEST(RIL_REQUEST_EMERGENCY_DIAL, &eccDial, sizeof(RIL_EmergencyDial), pRI, mSlotId);
1930 
1931     memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
1932     if (eccDial.urns != NULL) {
1933         for (size_t i = 0; i < eccDial.urnsNumber; i++) {
1934             memsetAndFreeStrings(1, eccDial.urns[i]);
1935         }
1936         free(eccDial.urns);
1937     }
1938     return Void();
1939 }
1940 
setSuppServiceNotifications(int32_t serial,bool enable)1941 Return<void> RadioImpl_1_6::setSuppServiceNotifications(int32_t serial, bool enable) {
1942 #if VDBG
1943     RLOGD("setSuppServiceNotifications: serial %d", serial);
1944 #endif
1945     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, 1,
1946             BOOL_TO_INT(enable));
1947     return Void();
1948 }
1949 
writeSmsToSim(int32_t serial,const SmsWriteArgs & smsWriteArgs)1950 Return<void> RadioImpl_1_6::writeSmsToSim(int32_t serial, const SmsWriteArgs& smsWriteArgs) {
1951 #if VDBG
1952     RLOGD("writeSmsToSim: serial %d", serial);
1953 #endif
1954     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_WRITE_SMS_TO_SIM);
1955     if (pRI == NULL) {
1956         return Void();
1957     }
1958 
1959     RIL_SMS_WriteArgs args;
1960     args.status = (int) smsWriteArgs.status;
1961 
1962     if (!copyHidlStringToRil(&args.pdu, smsWriteArgs.pdu, pRI)) {
1963         return Void();
1964     }
1965 
1966     if (!copyHidlStringToRil(&args.smsc, smsWriteArgs.smsc, pRI)) {
1967         memsetAndFreeStrings(1, args.pdu);
1968         return Void();
1969     }
1970 
1971     CALL_ONREQUEST(RIL_REQUEST_WRITE_SMS_TO_SIM, &args, sizeof(args), pRI, mSlotId);
1972 
1973     memsetAndFreeStrings(2, args.smsc, args.pdu);
1974 
1975     return Void();
1976 }
1977 
deleteSmsOnSim(int32_t serial,int32_t index)1978 Return<void> RadioImpl_1_6::deleteSmsOnSim(int32_t serial, int32_t index) {
1979 #if VDBG
1980     RLOGD("deleteSmsOnSim: serial %d", serial);
1981 #endif
1982     dispatchInts(serial, mSlotId, RIL_REQUEST_DELETE_SMS_ON_SIM, 1, index);
1983     return Void();
1984 }
1985 
setBandMode(int32_t serial,RadioBandMode mode)1986 Return<void> RadioImpl_1_6::setBandMode(int32_t serial, RadioBandMode mode) {
1987 #if VDBG
1988     RLOGD("setBandMode: serial %d", serial);
1989 #endif
1990     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_BAND_MODE, 1, mode);
1991     return Void();
1992 }
1993 
getAvailableBandModes(int32_t serial)1994 Return<void> RadioImpl_1_6::getAvailableBandModes(int32_t serial) {
1995 #if VDBG
1996     RLOGD("getAvailableBandModes: serial %d", serial);
1997 #endif
1998     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE);
1999     return Void();
2000 }
2001 
sendEnvelope(int32_t serial,const hidl_string & command)2002 Return<void> RadioImpl_1_6::sendEnvelope(int32_t serial, const hidl_string& command) {
2003 #if VDBG
2004     RLOGD("sendEnvelope: serial %d", serial);
2005 #endif
2006     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND,
2007             command.c_str());
2008     return Void();
2009 }
2010 
sendTerminalResponseToSim(int32_t serial,const hidl_string & commandResponse)2011 Return<void> RadioImpl_1_6::sendTerminalResponseToSim(int32_t serial,
2012                                                   const hidl_string& commandResponse) {
2013 #if VDBG
2014     RLOGD("sendTerminalResponseToSim: serial %d", serial);
2015 #endif
2016     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE,
2017             commandResponse.c_str());
2018     return Void();
2019 }
2020 
handleStkCallSetupRequestFromSim(int32_t serial,bool accept)2021 Return<void> RadioImpl_1_6::handleStkCallSetupRequestFromSim(int32_t serial, bool accept) {
2022 #if VDBG
2023     RLOGD("handleStkCallSetupRequestFromSim: serial %d", serial);
2024 #endif
2025     dispatchInts(serial, mSlotId, RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,
2026             1, BOOL_TO_INT(accept));
2027     return Void();
2028 }
2029 
explicitCallTransfer(int32_t serial)2030 Return<void> RadioImpl_1_6::explicitCallTransfer(int32_t serial) {
2031 #if VDBG
2032     RLOGD("explicitCallTransfer: serial %d", serial);
2033 #endif
2034     dispatchVoid(serial, mSlotId, RIL_REQUEST_EXPLICIT_CALL_TRANSFER);
2035     return Void();
2036 }
2037 
setPreferredNetworkType(int32_t serial,PreferredNetworkType nwType)2038 Return<void> RadioImpl_1_6::setPreferredNetworkType(int32_t serial, PreferredNetworkType nwType) {
2039 #if VDBG
2040     RLOGD("setPreferredNetworkType: serial %d", serial);
2041 #endif
2042     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, 1, nwType);
2043     return Void();
2044 }
2045 
getPreferredNetworkType(int32_t serial)2046 Return<void> RadioImpl_1_6::getPreferredNetworkType(int32_t serial) {
2047 #if VDBG
2048     RLOGD("getPreferredNetworkType: serial %d", serial);
2049 #endif
2050     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE);
2051     return Void();
2052 }
2053 
getNeighboringCids(int32_t serial)2054 Return<void> RadioImpl_1_6::getNeighboringCids(int32_t serial) {
2055 #if VDBG
2056     RLOGD("getNeighboringCids: serial %d", serial);
2057 #endif
2058     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_NEIGHBORING_CELL_IDS);
2059     return Void();
2060 }
2061 
setLocationUpdates(int32_t serial,bool enable)2062 Return<void> RadioImpl_1_6::setLocationUpdates(int32_t serial, bool enable) {
2063 #if VDBG
2064     RLOGD("setLocationUpdates: serial %d", serial);
2065 #endif
2066     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_LOCATION_UPDATES, 1, BOOL_TO_INT(enable));
2067     return Void();
2068 }
2069 
setCdmaSubscriptionSource(int32_t serial,CdmaSubscriptionSource cdmaSub)2070 Return<void> RadioImpl_1_6::setCdmaSubscriptionSource(int32_t serial, CdmaSubscriptionSource cdmaSub) {
2071 #if VDBG
2072     RLOGD("setCdmaSubscriptionSource: serial %d", serial);
2073 #endif
2074     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, 1, cdmaSub);
2075     return Void();
2076 }
2077 
setCdmaRoamingPreference(int32_t serial,CdmaRoamingType type)2078 Return<void> RadioImpl_1_6::setCdmaRoamingPreference(int32_t serial, CdmaRoamingType type) {
2079 #if VDBG
2080     RLOGD("setCdmaRoamingPreference: serial %d", serial);
2081 #endif
2082     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, 1, type);
2083     return Void();
2084 }
2085 
getCdmaRoamingPreference(int32_t serial)2086 Return<void> RadioImpl_1_6::getCdmaRoamingPreference(int32_t serial) {
2087 #if VDBG
2088     RLOGD("getCdmaRoamingPreference: serial %d", serial);
2089 #endif
2090     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE);
2091     return Void();
2092 }
2093 
setTTYMode(int32_t serial,TtyMode mode)2094 Return<void> RadioImpl_1_6::setTTYMode(int32_t serial, TtyMode mode) {
2095 #if VDBG
2096     RLOGD("setTTYMode: serial %d", serial);
2097 #endif
2098     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_TTY_MODE, 1, mode);
2099     return Void();
2100 }
2101 
getTTYMode(int32_t serial)2102 Return<void> RadioImpl_1_6::getTTYMode(int32_t serial) {
2103 #if VDBG
2104     RLOGD("getTTYMode: serial %d", serial);
2105 #endif
2106     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_TTY_MODE);
2107     return Void();
2108 }
2109 
setPreferredVoicePrivacy(int32_t serial,bool enable)2110 Return<void> RadioImpl_1_6::setPreferredVoicePrivacy(int32_t serial, bool enable) {
2111 #if VDBG
2112     RLOGD("setPreferredVoicePrivacy: serial %d", serial);
2113 #endif
2114     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE,
2115             1, BOOL_TO_INT(enable));
2116     return Void();
2117 }
2118 
getPreferredVoicePrivacy(int32_t serial)2119 Return<void> RadioImpl_1_6::getPreferredVoicePrivacy(int32_t serial) {
2120 #if VDBG
2121     RLOGD("getPreferredVoicePrivacy: serial %d", serial);
2122 #endif
2123     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE);
2124     return Void();
2125 }
2126 
sendCDMAFeatureCode(int32_t serial,const hidl_string & featureCode)2127 Return<void> RadioImpl_1_6::sendCDMAFeatureCode(int32_t serial, const hidl_string& featureCode) {
2128 #if VDBG
2129     RLOGD("sendCDMAFeatureCode: serial %d", serial);
2130 #endif
2131     dispatchString(serial, mSlotId, RIL_REQUEST_CDMA_FLASH,
2132             featureCode.c_str());
2133     return Void();
2134 }
2135 
sendBurstDtmf(int32_t serial,const hidl_string & dtmf,int32_t on,int32_t off)2136 Return<void> RadioImpl_1_6::sendBurstDtmf(int32_t serial, const hidl_string& dtmf, int32_t on,
2137                                       int32_t off) {
2138 #if VDBG
2139     RLOGD("sendBurstDtmf: serial %d", serial);
2140 #endif
2141     dispatchStrings(serial, mSlotId, RIL_REQUEST_CDMA_BURST_DTMF, false,
2142             3, dtmf.c_str(), (std::to_string(on)).c_str(),
2143             (std::to_string(off)).c_str());
2144     return Void();
2145 }
2146 
constructCdmaSms(RIL_CDMA_SMS_Message & rcsm,const CdmaSmsMessage & sms)2147 void constructCdmaSms(RIL_CDMA_SMS_Message &rcsm, const CdmaSmsMessage& sms) {
2148     rcsm.uTeleserviceID = sms.teleserviceId;
2149     rcsm.bIsServicePresent = BOOL_TO_INT(sms.isServicePresent);
2150     rcsm.uServicecategory = sms.serviceCategory;
2151     rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) sms.address.digitMode;
2152     rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) sms.address.numberMode;
2153     rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) sms.address.numberType;
2154     rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) sms.address.numberPlan;
2155 
2156     rcsm.sAddress.number_of_digits = sms.address.digits.size();
2157     int digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2158     for (int i = 0; i < digitLimit; i++) {
2159         rcsm.sAddress.digits[i] = sms.address.digits[i];
2160     }
2161 
2162     rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) sms.subAddress.subaddressType;
2163     rcsm.sSubAddress.odd = BOOL_TO_INT(sms.subAddress.odd);
2164 
2165     rcsm.sSubAddress.number_of_digits = sms.subAddress.digits.size();
2166     digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2167     for (int i = 0; i < digitLimit; i++) {
2168         rcsm.sSubAddress.digits[i] = sms.subAddress.digits[i];
2169     }
2170 
2171     rcsm.uBearerDataLen = sms.bearerData.size();
2172     digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2173     for (int i = 0; i < digitLimit; i++) {
2174         rcsm.aBearerData[i] = sms.bearerData[i];
2175     }
2176 }
2177 
sendCdmaSms(int32_t serial,const CdmaSmsMessage & sms)2178 Return<void> RadioImpl_1_6::sendCdmaSms(int32_t serial, const CdmaSmsMessage& sms) {
2179 #if VDBG
2180     RLOGD("sendCdmaSms: serial %d", serial);
2181 #endif
2182     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SEND_SMS);
2183     if (pRI == NULL) {
2184         return Void();
2185     }
2186 
2187     RIL_CDMA_SMS_Message rcsm = {};
2188     constructCdmaSms(rcsm, sms);
2189 
2190     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
2191     return Void();
2192 }
2193 
sendCdmaSms_1_6(int32_t serial,const CdmaSmsMessage & sms)2194 Return<void> RadioImpl_1_6::sendCdmaSms_1_6(int32_t serial, const CdmaSmsMessage& sms) {
2195 #if VDBG
2196     RLOGD("sendCdmaSms: serial %d", serial);
2197 #endif
2198     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SEND_SMS);
2199     if (pRI == NULL) {
2200         return Void();
2201     }
2202 
2203     RIL_CDMA_SMS_Message rcsm = {};
2204     constructCdmaSms(rcsm, sms);
2205 
2206     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
2207     return Void();
2208 }
2209 
acknowledgeLastIncomingCdmaSms(int32_t serial,const CdmaSmsAck & smsAck)2210 Return<void> RadioImpl_1_6::acknowledgeLastIncomingCdmaSms(int32_t serial, const CdmaSmsAck& smsAck) {
2211 #if VDBG
2212     RLOGD("acknowledgeLastIncomingCdmaSms: serial %d", serial);
2213 #endif
2214     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE);
2215     if (pRI == NULL) {
2216         return Void();
2217     }
2218 
2219     RIL_CDMA_SMS_Ack rcsa = {};
2220 
2221     rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) smsAck.errorClass;
2222     rcsa.uSMSCauseCode = smsAck.smsCauseCode;
2223 
2224     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa), pRI, mSlotId);
2225     return Void();
2226 }
2227 
getGsmBroadcastConfig(int32_t serial)2228 Return<void> RadioImpl_1_6::getGsmBroadcastConfig(int32_t serial) {
2229 #if VDBG
2230     RLOGD("getGsmBroadcastConfig: serial %d", serial);
2231 #endif
2232     dispatchVoid(serial, mSlotId, RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG);
2233     return Void();
2234 }
2235 
setGsmBroadcastConfig(int32_t serial,const hidl_vec<GsmBroadcastSmsConfigInfo> & configInfo)2236 Return<void> RadioImpl_1_6::setGsmBroadcastConfig(int32_t serial,
2237                                               const hidl_vec<GsmBroadcastSmsConfigInfo>&
2238                                               configInfo) {
2239 #if VDBG
2240     RLOGD("setGsmBroadcastConfig: serial %d", serial);
2241 #endif
2242     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2243             RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG);
2244     if (pRI == NULL) {
2245         return Void();
2246     }
2247 
2248     int num = configInfo.size();
2249     if (num > MAX_BROADCAST_SMS_CONFIG_INFO) {
2250         RLOGE("setGsmBroadcastConfig: Invalid configInfo length %s",
2251                 requestToString(pRI->pCI->requestNumber));
2252         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2253         return Void();
2254     }
2255     RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
2256     RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
2257 
2258     for (int i = 0 ; i < num ; i++ ) {
2259         gsmBciPtrs[i] = &gsmBci[i];
2260         gsmBci[i].fromServiceId = configInfo[i].fromServiceId;
2261         gsmBci[i].toServiceId = configInfo[i].toServiceId;
2262         gsmBci[i].fromCodeScheme = configInfo[i].fromCodeScheme;
2263         gsmBci[i].toCodeScheme = configInfo[i].toCodeScheme;
2264         gsmBci[i].selected = BOOL_TO_INT(configInfo[i].selected);
2265     }
2266 
2267     CALL_ONREQUEST(pRI->pCI->requestNumber, gsmBciPtrs,
2268             num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *), pRI, mSlotId);
2269     return Void();
2270 }
2271 
setGsmBroadcastActivation(int32_t serial,bool activate)2272 Return<void> RadioImpl_1_6::setGsmBroadcastActivation(int32_t serial, bool activate) {
2273 #if VDBG
2274     RLOGD("setGsmBroadcastActivation: serial %d", serial);
2275 #endif
2276     dispatchInts(serial, mSlotId, RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION,
2277             1, BOOL_TO_INT(!activate));
2278     return Void();
2279 }
2280 
getCdmaBroadcastConfig(int32_t serial)2281 Return<void> RadioImpl_1_6::getCdmaBroadcastConfig(int32_t serial) {
2282 #if VDBG
2283     RLOGD("getCdmaBroadcastConfig: serial %d", serial);
2284 #endif
2285     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG);
2286     return Void();
2287 }
2288 
setCdmaBroadcastConfig(int32_t serial,const hidl_vec<CdmaBroadcastSmsConfigInfo> & configInfo)2289 Return<void> RadioImpl_1_6::setCdmaBroadcastConfig(int32_t serial,
2290                                                const hidl_vec<CdmaBroadcastSmsConfigInfo>&
2291                                                configInfo) {
2292 #if VDBG
2293     RLOGD("setCdmaBroadcastConfig: serial %d", serial);
2294 #endif
2295     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2296             RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG);
2297     if (pRI == NULL) {
2298         return Void();
2299     }
2300 
2301     int num = configInfo.size();
2302     if (num > MAX_BROADCAST_SMS_CONFIG_INFO) {
2303         RLOGE("setCdmaBroadcastConfig: Invalid configInfo length %s",
2304                 requestToString(pRI->pCI->requestNumber));
2305         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2306         return Void();
2307     }
2308     RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
2309     RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
2310 
2311     for (int i = 0 ; i < num ; i++ ) {
2312         cdmaBciPtrs[i] = &cdmaBci[i];
2313         cdmaBci[i].service_category = configInfo[i].serviceCategory;
2314         cdmaBci[i].language = configInfo[i].language;
2315         cdmaBci[i].selected = BOOL_TO_INT(configInfo[i].selected);
2316     }
2317 
2318     CALL_ONREQUEST(pRI->pCI->requestNumber, cdmaBciPtrs,
2319             num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *), pRI, mSlotId);
2320     return Void();
2321 }
2322 
setCdmaBroadcastActivation(int32_t serial,bool activate)2323 Return<void> RadioImpl_1_6::setCdmaBroadcastActivation(int32_t serial, bool activate) {
2324 #if VDBG
2325     RLOGD("setCdmaBroadcastActivation: serial %d", serial);
2326 #endif
2327     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION,
2328             1, BOOL_TO_INT(!activate));
2329     return Void();
2330 }
2331 
getCDMASubscription(int32_t serial)2332 Return<void> RadioImpl_1_6::getCDMASubscription(int32_t serial) {
2333 #if VDBG
2334     RLOGD("getCDMASubscription: serial %d", serial);
2335 #endif
2336     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_SUBSCRIPTION);
2337     return Void();
2338 }
2339 
writeSmsToRuim(int32_t serial,const CdmaSmsWriteArgs & cdmaSms)2340 Return<void> RadioImpl_1_6::writeSmsToRuim(int32_t serial, const CdmaSmsWriteArgs& cdmaSms) {
2341 #if VDBG
2342     RLOGD("writeSmsToRuim: serial %d", serial);
2343 #endif
2344     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2345             RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM);
2346     if (pRI == NULL) {
2347         return Void();
2348     }
2349 
2350     RIL_CDMA_SMS_WriteArgs rcsw = {};
2351     rcsw.status = (int) cdmaSms.status;
2352     constructCdmaSms(rcsw.message, cdmaSms.message);
2353 
2354     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw), pRI, mSlotId);
2355     return Void();
2356 }
2357 
deleteSmsOnRuim(int32_t serial,int32_t index)2358 Return<void> RadioImpl_1_6::deleteSmsOnRuim(int32_t serial, int32_t index) {
2359 #if VDBG
2360     RLOGD("deleteSmsOnRuim: serial %d", serial);
2361 #endif
2362     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, 1, index);
2363     return Void();
2364 }
2365 
getDeviceIdentity(int32_t serial)2366 Return<void> RadioImpl_1_6::getDeviceIdentity(int32_t serial) {
2367 #if VDBG
2368     RLOGD("getDeviceIdentity: serial %d", serial);
2369 #endif
2370     dispatchVoid(serial, mSlotId, RIL_REQUEST_DEVICE_IDENTITY);
2371     return Void();
2372 }
2373 
exitEmergencyCallbackMode(int32_t serial)2374 Return<void> RadioImpl_1_6::exitEmergencyCallbackMode(int32_t serial) {
2375 #if VDBG
2376     RLOGD("exitEmergencyCallbackMode: serial %d", serial);
2377 #endif
2378     dispatchVoid(serial, mSlotId, RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE);
2379     return Void();
2380 }
2381 
getSmscAddress(int32_t serial)2382 Return<void> RadioImpl_1_6::getSmscAddress(int32_t serial) {
2383 #if VDBG
2384     RLOGD("getSmscAddress: serial %d", serial);
2385 #endif
2386     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SMSC_ADDRESS);
2387     return Void();
2388 }
2389 
setSmscAddress(int32_t serial,const hidl_string & smsc)2390 Return<void> RadioImpl_1_6::setSmscAddress(int32_t serial, const hidl_string& smsc) {
2391 #if VDBG
2392     RLOGD("setSmscAddress: serial %d", serial);
2393 #endif
2394     dispatchString(serial, mSlotId, RIL_REQUEST_SET_SMSC_ADDRESS,
2395             smsc.c_str());
2396     return Void();
2397 }
2398 
reportSmsMemoryStatus(int32_t serial,bool available)2399 Return<void> RadioImpl_1_6::reportSmsMemoryStatus(int32_t serial, bool available) {
2400 #if VDBG
2401     RLOGD("reportSmsMemoryStatus: serial %d", serial);
2402 #endif
2403     dispatchInts(serial, mSlotId, RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, 1,
2404             BOOL_TO_INT(available));
2405     return Void();
2406 }
2407 
reportStkServiceIsRunning(int32_t serial)2408 Return<void> RadioImpl_1_6::reportStkServiceIsRunning(int32_t serial) {
2409 #if VDBG
2410     RLOGD("reportStkServiceIsRunning: serial %d", serial);
2411 #endif
2412     dispatchVoid(serial, mSlotId, RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING);
2413     return Void();
2414 }
2415 
getCdmaSubscriptionSource(int32_t serial)2416 Return<void> RadioImpl_1_6::getCdmaSubscriptionSource(int32_t serial) {
2417 #if VDBG
2418     RLOGD("getCdmaSubscriptionSource: serial %d", serial);
2419 #endif
2420     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE);
2421     return Void();
2422 }
2423 
requestIsimAuthentication(int32_t serial,const hidl_string & challenge)2424 Return<void> RadioImpl_1_6::requestIsimAuthentication(int32_t serial, const hidl_string& challenge) {
2425 #if VDBG
2426     RLOGD("requestIsimAuthentication: serial %d", serial);
2427 #endif
2428     dispatchString(serial, mSlotId, RIL_REQUEST_ISIM_AUTHENTICATION,
2429             challenge.c_str());
2430     return Void();
2431 }
2432 
acknowledgeIncomingGsmSmsWithPdu(int32_t serial,bool success,const hidl_string & ackPdu)2433 Return<void> RadioImpl_1_6::acknowledgeIncomingGsmSmsWithPdu(int32_t serial, bool success,
2434                                                          const hidl_string& ackPdu) {
2435 #if VDBG
2436     RLOGD("acknowledgeIncomingGsmSmsWithPdu: serial %d", serial);
2437 #endif
2438     dispatchStrings(serial, mSlotId, RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, false,
2439             2, success ? "1" : "0", ackPdu.c_str());
2440     return Void();
2441 }
2442 
sendEnvelopeWithStatus(int32_t serial,const hidl_string & contents)2443 Return<void> RadioImpl_1_6::sendEnvelopeWithStatus(int32_t serial, const hidl_string& contents) {
2444 #if VDBG
2445     RLOGD("sendEnvelopeWithStatus: serial %d", serial);
2446 #endif
2447     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS,
2448             contents.c_str());
2449     return Void();
2450 }
2451 
getVoiceRadioTechnology(int32_t serial)2452 Return<void> RadioImpl_1_6::getVoiceRadioTechnology(int32_t serial) {
2453 #if VDBG
2454     RLOGD("getVoiceRadioTechnology: serial %d", serial);
2455 #endif
2456     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_RADIO_TECH);
2457     return Void();
2458 }
2459 
getCellInfoList(int32_t serial)2460 Return<void> RadioImpl_1_6::getCellInfoList(int32_t serial) {
2461 #if VDBG
2462     RLOGD("getCellInfoList: serial %d", serial);
2463 #endif
2464     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CELL_INFO_LIST);
2465     return Void();
2466 }
2467 
getCellInfoList_1_6(int32_t serial)2468 Return<void> RadioImpl_1_6::getCellInfoList_1_6(int32_t serial) {
2469 #if VDBG
2470     RLOGD("getCellInfoList_1_6: serial %d", serial);
2471 #endif
2472     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CELL_INFO_LIST_1_6);
2473     return Void();
2474 }
2475 
setCellInfoListRate(int32_t serial,int32_t rate)2476 Return<void> RadioImpl_1_6::setCellInfoListRate(int32_t serial, int32_t rate) {
2477 #if VDBG
2478     RLOGD("setCellInfoListRate: serial %d", serial);
2479 #endif
2480     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, 1, rate);
2481     return Void();
2482 }
2483 
setInitialAttachApn(int32_t serial,const DataProfileInfo & dataProfileInfo,bool modemCognitive,bool isRoaming)2484 Return<void> RadioImpl_1_6::setInitialAttachApn(int32_t serial, const DataProfileInfo& dataProfileInfo,
2485                                             bool modemCognitive, bool isRoaming) {
2486 #if VDBG
2487     RLOGD("setInitialAttachApn: serial %d", serial);
2488 #endif
2489     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2490             RIL_REQUEST_SET_INITIAL_ATTACH_APN);
2491     if (pRI == NULL) {
2492         return Void();
2493     }
2494 
2495     if (s_vendorFunctions->version <= 14) {
2496         RIL_InitialAttachApn iaa = {};
2497 
2498         if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) {
2499             return Void();
2500         }
2501 
2502         const hidl_string &protocol =
2503                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
2504 
2505         if (!copyHidlStringToRil(&iaa.protocol, protocol, pRI)) {
2506             memsetAndFreeStrings(1, iaa.apn);
2507             return Void();
2508         }
2509         iaa.authtype = (int) dataProfileInfo.authType;
2510         if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) {
2511             memsetAndFreeStrings(2, iaa.apn, iaa.protocol);
2512             return Void();
2513         }
2514         if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) {
2515             memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.username);
2516             return Void();
2517         }
2518 
2519         CALL_ONREQUEST(RIL_REQUEST_SET_INITIAL_ATTACH_APN, &iaa, sizeof(iaa), pRI, mSlotId);
2520 
2521         memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.username, iaa.password);
2522     } else {
2523         RIL_InitialAttachApn_v15 iaa = {};
2524 
2525         if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) {
2526             return Void();
2527         }
2528 
2529         if (!copyHidlStringToRil(&iaa.protocol, dataProfileInfo.protocol, pRI)) {
2530             memsetAndFreeStrings(1, iaa.apn);
2531             return Void();
2532         }
2533         if (!copyHidlStringToRil(&iaa.roamingProtocol, dataProfileInfo.roamingProtocol, pRI)) {
2534             memsetAndFreeStrings(2, iaa.apn, iaa.protocol);
2535             return Void();
2536         }
2537         iaa.authtype = (int) dataProfileInfo.authType;
2538         if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) {
2539             memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.roamingProtocol);
2540             return Void();
2541         }
2542         if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) {
2543             memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username);
2544             return Void();
2545         }
2546         iaa.supportedTypesBitmask = dataProfileInfo.supportedApnTypesBitmap;
2547         iaa.bearerBitmask = dataProfileInfo.bearerBitmap;
2548         iaa.modemCognitive = BOOL_TO_INT(modemCognitive);
2549         iaa.mtu = dataProfileInfo.mtu;
2550 
2551         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, iaa.mvnoType)) {
2552             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2553             memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
2554                     iaa.password);
2555             return Void();
2556         }
2557 
2558         if (!copyHidlStringToRil(&iaa.mvnoMatchData, dataProfileInfo.mvnoMatchData, pRI)) {
2559             memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
2560                     iaa.password);
2561             return Void();
2562         }
2563 
2564         CALL_ONREQUEST(RIL_REQUEST_SET_INITIAL_ATTACH_APN, &iaa, sizeof(iaa), pRI, mSlotId);
2565 
2566         memsetAndFreeStrings(6, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
2567                 iaa.password, iaa.mvnoMatchData);
2568     }
2569 
2570     return Void();
2571 }
2572 
getImsRegistrationState(int32_t serial)2573 Return<void> RadioImpl_1_6::getImsRegistrationState(int32_t serial) {
2574 #if VDBG
2575     RLOGD("getImsRegistrationState: serial %d", serial);
2576 #endif
2577     dispatchVoid(serial, mSlotId, RIL_REQUEST_IMS_REGISTRATION_STATE);
2578     return Void();
2579 }
2580 
dispatchImsGsmSms(const ImsSmsMessage & message,RequestInfo * pRI)2581 bool dispatchImsGsmSms(const ImsSmsMessage& message, RequestInfo *pRI) {
2582     RIL_IMS_SMS_Message rism = {};
2583     char **pStrings;
2584     int countStrings = 2;
2585     int dataLen = sizeof(char *) * countStrings;
2586 
2587     rism.tech = RADIO_TECH_3GPP;
2588     rism.retry = BOOL_TO_INT(message.retry);
2589     rism.messageRef = message.messageRef;
2590 
2591     if (message.gsmMessage.size() != 1) {
2592         RLOGE("dispatchImsGsmSms: Invalid len %s", requestToString(pRI->pCI->requestNumber));
2593         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2594         return false;
2595     }
2596 
2597     pStrings = (char **)calloc(countStrings, sizeof(char *));
2598     if (pStrings == NULL) {
2599         RLOGE("dispatchImsGsmSms: Memory allocation failed for request %s",
2600                 requestToString(pRI->pCI->requestNumber));
2601         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
2602         return false;
2603     }
2604 
2605     if (!copyHidlStringToRil(&pStrings[0], message.gsmMessage[0].smscPdu, pRI)) {
2606 #ifdef MEMSET_FREED
2607         memset(pStrings, 0, dataLen);
2608 #endif
2609         free(pStrings);
2610         return false;
2611     }
2612 
2613     if (!copyHidlStringToRil(&pStrings[1], message.gsmMessage[0].pdu, pRI)) {
2614         memsetAndFreeStrings(1, pStrings[0]);
2615 #ifdef MEMSET_FREED
2616         memset(pStrings, 0, dataLen);
2617 #endif
2618         free(pStrings);
2619         return false;
2620     }
2621 
2622     rism.message.gsmMessage = pStrings;
2623     CALL_ONREQUEST(pRI->pCI->requestNumber, &rism, sizeof(RIL_RadioTechnologyFamily) +
2624             sizeof(uint8_t) + sizeof(int32_t) + dataLen, pRI, pRI->socket_id);
2625 
2626     for (int i = 0 ; i < countStrings ; i++) {
2627         memsetAndFreeStrings(1, pStrings[i]);
2628     }
2629 
2630 #ifdef MEMSET_FREED
2631     memset(pStrings, 0, dataLen);
2632 #endif
2633     free(pStrings);
2634 
2635     return true;
2636 }
2637 
2638 struct ImsCdmaSms {
2639     RIL_IMS_SMS_Message imsSms;
2640     RIL_CDMA_SMS_Message cdmaSms;
2641 };
2642 
dispatchImsCdmaSms(const ImsSmsMessage & message,RequestInfo * pRI)2643 bool dispatchImsCdmaSms(const ImsSmsMessage& message, RequestInfo *pRI) {
2644     ImsCdmaSms temp = {};
2645 
2646     if (message.cdmaMessage.size() != 1) {
2647         RLOGE("dispatchImsCdmaSms: Invalid len %s", requestToString(pRI->pCI->requestNumber));
2648         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2649         return false;
2650     }
2651 
2652     temp.imsSms.tech = RADIO_TECH_3GPP2;
2653     temp.imsSms.retry = BOOL_TO_INT(message.retry);
2654     temp.imsSms.messageRef = message.messageRef;
2655     temp.imsSms.message.cdmaMessage = &temp.cdmaSms;
2656 
2657     constructCdmaSms(temp.cdmaSms, message.cdmaMessage[0]);
2658 
2659     // Vendor code expects payload length to include actual msg payload
2660     // (sizeof(RIL_CDMA_SMS_Message)) instead of (RIL_CDMA_SMS_Message *) + size of other fields in
2661     // RIL_IMS_SMS_Message
2662     int payloadLen = sizeof(RIL_RadioTechnologyFamily) + sizeof(uint8_t) + sizeof(int32_t)
2663             + sizeof(RIL_CDMA_SMS_Message);
2664 
2665     CALL_ONREQUEST(pRI->pCI->requestNumber, &temp.imsSms, payloadLen, pRI, pRI->socket_id);
2666 
2667     return true;
2668 }
2669 
sendImsSms(int32_t serial,const ImsSmsMessage & message)2670 Return<void> RadioImpl_1_6::sendImsSms(int32_t serial, const ImsSmsMessage& message) {
2671 #if VDBG
2672     RLOGD("sendImsSms: serial %d", serial);
2673 #endif
2674     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_IMS_SEND_SMS);
2675     if (pRI == NULL) {
2676         return Void();
2677     }
2678 
2679     RIL_RadioTechnologyFamily format = (RIL_RadioTechnologyFamily) message.tech;
2680 
2681     if (RADIO_TECH_3GPP == format) {
2682         dispatchImsGsmSms(message, pRI);
2683     } else if (RADIO_TECH_3GPP2 == format) {
2684         dispatchImsCdmaSms(message, pRI);
2685     } else {
2686         RLOGE("sendImsSms: Invalid radio tech %s",
2687                 requestToString(pRI->pCI->requestNumber));
2688         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2689     }
2690     return Void();
2691 }
2692 
iccTransmitApduBasicChannel(int32_t serial,const SimApdu & message)2693 Return<void> RadioImpl_1_6::iccTransmitApduBasicChannel(int32_t serial, const SimApdu& message) {
2694 #if VDBG
2695     RLOGD("iccTransmitApduBasicChannel: serial %d", serial);
2696 #endif
2697     dispatchIccApdu(serial, mSlotId, RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, message);
2698     return Void();
2699 }
2700 
iccOpenLogicalChannel(int32_t serial,const hidl_string & aid,int32_t p2)2701 Return<void> RadioImpl_1_6::iccOpenLogicalChannel(int32_t serial, const hidl_string& aid, int32_t p2) {
2702 #if VDBG
2703     RLOGD("iccOpenLogicalChannel: serial %d", serial);
2704 #endif
2705     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_OPEN_CHANNEL);
2706     if (pRI == NULL) {
2707         return Void();
2708     }
2709 
2710     RIL_OpenChannelParams params = {};
2711 
2712     params.p2 = p2;
2713 
2714     if (!copyHidlStringToRil(&params.aidPtr, aid, pRI)) {
2715         return Void();
2716     }
2717 
2718     CALL_ONREQUEST(pRI->pCI->requestNumber, &params, sizeof(params), pRI, mSlotId);
2719 
2720     memsetAndFreeStrings(1, params.aidPtr);
2721     return Void();
2722 }
2723 
iccCloseLogicalChannel(int32_t serial,int32_t channelId)2724 Return<void> RadioImpl_1_6::iccCloseLogicalChannel(int32_t serial, int32_t channelId) {
2725 #if VDBG
2726     RLOGD("iccCloseLogicalChannel: serial %d", serial);
2727 #endif
2728     dispatchInts(serial, mSlotId, RIL_REQUEST_SIM_CLOSE_CHANNEL, 1, channelId);
2729     return Void();
2730 }
2731 
iccTransmitApduLogicalChannel(int32_t serial,const SimApdu & message)2732 Return<void> RadioImpl_1_6::iccTransmitApduLogicalChannel(int32_t serial, const SimApdu& message) {
2733 #if VDBG
2734     RLOGD("iccTransmitApduLogicalChannel: serial %d", serial);
2735 #endif
2736     dispatchIccApdu(serial, mSlotId, RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, message);
2737     return Void();
2738 }
2739 
nvReadItem(int32_t serial,NvItem itemId)2740 Return<void> RadioImpl_1_6::nvReadItem(int32_t serial, NvItem itemId) {
2741 #if VDBG
2742     RLOGD("nvReadItem: serial %d", serial);
2743 #endif
2744     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_NV_READ_ITEM);
2745     if (pRI == NULL) {
2746         return Void();
2747     }
2748 
2749     RIL_NV_ReadItem nvri = {};
2750     nvri.itemID = (RIL_NV_Item) itemId;
2751 
2752     CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, mSlotId);
2753     return Void();
2754 }
2755 
nvWriteItem(int32_t serial,const NvWriteItem & item)2756 Return<void> RadioImpl_1_6::nvWriteItem(int32_t serial, const NvWriteItem& item) {
2757 #if VDBG
2758     RLOGD("nvWriteItem: serial %d", serial);
2759 #endif
2760     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_NV_WRITE_ITEM);
2761     if (pRI == NULL) {
2762         return Void();
2763     }
2764 
2765     RIL_NV_WriteItem nvwi = {};
2766 
2767     nvwi.itemID = (RIL_NV_Item) item.itemId;
2768 
2769     if (!copyHidlStringToRil(&nvwi.value, item.value, pRI)) {
2770         return Void();
2771     }
2772 
2773     CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, mSlotId);
2774 
2775     memsetAndFreeStrings(1, nvwi.value);
2776     return Void();
2777 }
2778 
nvWriteCdmaPrl(int32_t serial,const hidl_vec<uint8_t> & prl)2779 Return<void> RadioImpl_1_6::nvWriteCdmaPrl(int32_t serial, const hidl_vec<uint8_t>& prl) {
2780 #if VDBG
2781     RLOGD("nvWriteCdmaPrl: serial %d", serial);
2782 #endif
2783     dispatchRaw(serial, mSlotId, RIL_REQUEST_NV_WRITE_CDMA_PRL, prl);
2784     return Void();
2785 }
2786 
nvResetConfig(int32_t serial,ResetNvType resetType)2787 Return<void> RadioImpl_1_6::nvResetConfig(int32_t serial, ResetNvType resetType) {
2788     int rilResetType = -1;
2789 #if VDBG
2790     RLOGD("nvResetConfig: serial %d", serial);
2791 #endif
2792     /* Convert ResetNvType to RIL.h values
2793      * RIL_REQUEST_NV_RESET_CONFIG
2794      * 1 - reload all NV items
2795      * 2 - erase NV reset (SCRTN)
2796      * 3 - factory reset (RTN)
2797      */
2798     switch(resetType) {
2799       case ResetNvType::RELOAD:
2800         rilResetType = 1;
2801         break;
2802       case ResetNvType::ERASE:
2803         rilResetType = 2;
2804         break;
2805       case ResetNvType::FACTORY_RESET:
2806         rilResetType = 3;
2807         break;
2808     }
2809     dispatchInts(serial, mSlotId, RIL_REQUEST_NV_RESET_CONFIG, 1, rilResetType);
2810     return Void();
2811 }
2812 
setUiccSubscription(int32_t serial,const SelectUiccSub & uiccSub)2813 Return<void> RadioImpl_1_6::setUiccSubscription(int32_t serial, const SelectUiccSub& uiccSub) {
2814 #if VDBG
2815     RLOGD("setUiccSubscription: serial %d", serial);
2816 #endif
2817     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2818             RIL_REQUEST_SET_UICC_SUBSCRIPTION);
2819     if (pRI == NULL) {
2820         return Void();
2821     }
2822 
2823     RIL_SelectUiccSub rilUiccSub = {};
2824 
2825     rilUiccSub.slot = uiccSub.slot;
2826     rilUiccSub.app_index = uiccSub.appIndex;
2827     rilUiccSub.sub_type = (RIL_SubscriptionType) uiccSub.subType;
2828     rilUiccSub.act_status = (RIL_UiccSubActStatus) uiccSub.actStatus;
2829 
2830     CALL_ONREQUEST(pRI->pCI->requestNumber, &rilUiccSub, sizeof(rilUiccSub), pRI, mSlotId);
2831     return Void();
2832 }
2833 
setDataAllowed(int32_t serial,bool allow)2834 Return<void> RadioImpl_1_6::setDataAllowed(int32_t serial, bool allow) {
2835 #if VDBG
2836     RLOGD("setDataAllowed: serial %d", serial);
2837 #endif
2838     dispatchInts(serial, mSlotId, RIL_REQUEST_ALLOW_DATA, 1, BOOL_TO_INT(allow));
2839     return Void();
2840 }
2841 
getHardwareConfig(int32_t serial)2842 Return<void> RadioImpl_1_6::getHardwareConfig(int32_t serial) {
2843 #if VDBG
2844     RLOGD("getHardwareConfig: serial %d", serial);
2845 #endif
2846     RLOGD("getHardwareConfig: serial %d, mSlotId = %d", serial, mSlotId);
2847     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_HARDWARE_CONFIG);
2848     return Void();
2849 }
2850 
requestIccSimAuthentication(int32_t serial,int32_t authContext,const hidl_string & authData,const hidl_string & aid)2851 Return<void> RadioImpl_1_6::requestIccSimAuthentication(int32_t serial, int32_t authContext,
2852         const hidl_string& authData, const hidl_string& aid) {
2853 #if VDBG
2854     RLOGD("requestIccSimAuthentication: serial %d", serial);
2855 #endif
2856     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_AUTHENTICATION);
2857     if (pRI == NULL) {
2858         return Void();
2859     }
2860 
2861     RIL_SimAuthentication pf = {};
2862 
2863     pf.authContext = authContext;
2864 
2865     if (!copyHidlStringToRil(&pf.authData, authData, pRI)) {
2866         return Void();
2867     }
2868 
2869     if (!copyHidlStringToRil(&pf.aid, aid, pRI)) {
2870         memsetAndFreeStrings(1, pf.authData);
2871         return Void();
2872     }
2873 
2874     CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, mSlotId);
2875 
2876     memsetAndFreeStrings(2, pf.authData, pf.aid);
2877     return Void();
2878 }
2879 
2880 /**
2881  * @param numProfiles number of data profile
2882  * @param dataProfiles the pointer to the actual data profiles. The acceptable type is
2883           RIL_DataProfileInfo or RIL_DataProfileInfo_v15.
2884  * @param dataProfilePtrs the pointer to the pointers that point to each data profile structure
2885  * @param numfields number of string-type member in the data profile structure
2886  * @param ... the variadic parameters are pointers to each string-type member
2887  **/
2888 template <typename T>
freeSetDataProfileData(int numProfiles,T * dataProfiles,T ** dataProfilePtrs,int numfields,...)2889 void freeSetDataProfileData(int numProfiles, T *dataProfiles, T **dataProfilePtrs,
2890                             int numfields, ...) {
2891     va_list args;
2892     va_start(args, numfields);
2893 
2894     // Iterate through each string-type field that need to be free.
2895     for (int i = 0; i < numfields; i++) {
2896         // Iterate through each data profile and free that specific string-type field.
2897         // The type 'char *T::*' is a type of pointer to a 'char *' member inside T structure.
2898         char *T::*ptr = va_arg(args, char *T::*);
2899         for (int j = 0; j < numProfiles; j++) {
2900             memsetAndFreeStrings(1, dataProfiles[j].*ptr);
2901         }
2902     }
2903 
2904     va_end(args);
2905 
2906 #ifdef MEMSET_FREED
2907     memset(dataProfiles, 0, numProfiles * sizeof(T));
2908     memset(dataProfilePtrs, 0, numProfiles * sizeof(T *));
2909 #endif
2910     free(dataProfiles);
2911     free(dataProfilePtrs);
2912 }
2913 
setDataProfile(int32_t serial,const hidl_vec<DataProfileInfo> & profiles,bool isRoaming)2914 Return<void> RadioImpl_1_6::setDataProfile(int32_t serial, const hidl_vec<DataProfileInfo>& profiles,
2915                                        bool isRoaming) {
2916 #if VDBG
2917     RLOGD("setDataProfile: serial %d", serial);
2918 #endif
2919     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SET_DATA_PROFILE);
2920     if (pRI == NULL) {
2921         return Void();
2922     }
2923 
2924     size_t num = profiles.size();
2925     bool success = false;
2926 
2927     if (s_vendorFunctions->version <= 14) {
2928 
2929         RIL_DataProfileInfo *dataProfiles =
2930             (RIL_DataProfileInfo *) calloc(num, sizeof(RIL_DataProfileInfo));
2931 
2932         if (dataProfiles == NULL) {
2933             RLOGE("Memory allocation failed for request %s",
2934                     requestToString(pRI->pCI->requestNumber));
2935             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
2936             return Void();
2937         }
2938 
2939         RIL_DataProfileInfo **dataProfilePtrs =
2940             (RIL_DataProfileInfo **) calloc(num, sizeof(RIL_DataProfileInfo *));
2941         if (dataProfilePtrs == NULL) {
2942             RLOGE("Memory allocation failed for request %s",
2943                     requestToString(pRI->pCI->requestNumber));
2944             free(dataProfiles);
2945             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
2946             return Void();
2947         }
2948 
2949         for (size_t i = 0; i < num; i++) {
2950             dataProfilePtrs[i] = &dataProfiles[i];
2951 
2952             success = copyHidlStringToRil(&dataProfiles[i].apn, profiles[i].apn, pRI, true);
2953 
2954             const hidl_string &protocol =
2955                     (isRoaming ? profiles[i].roamingProtocol : profiles[i].protocol);
2956 
2957             if (success && !copyHidlStringToRil(&dataProfiles[i].protocol, protocol, pRI, true)) {
2958                 success = false;
2959             }
2960 
2961             if (success && !copyHidlStringToRil(&dataProfiles[i].user, profiles[i].user, pRI,
2962                     true)) {
2963                 success = false;
2964             }
2965             if (success && !copyHidlStringToRil(&dataProfiles[i].password, profiles[i].password,
2966                     pRI, true)) {
2967                 success = false;
2968             }
2969 
2970             if (!success) {
2971                 freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 4,
2972                     &RIL_DataProfileInfo::apn, &RIL_DataProfileInfo::protocol,
2973                     &RIL_DataProfileInfo::user, &RIL_DataProfileInfo::password);
2974                 return Void();
2975             }
2976 
2977             dataProfiles[i].profileId = (RIL_DataProfile) profiles[i].profileId;
2978             dataProfiles[i].authType = (int) profiles[i].authType;
2979             dataProfiles[i].type = (int) profiles[i].type;
2980             dataProfiles[i].maxConnsTime = profiles[i].maxConnsTime;
2981             dataProfiles[i].maxConns = profiles[i].maxConns;
2982             dataProfiles[i].waitTime = profiles[i].waitTime;
2983             dataProfiles[i].enabled = BOOL_TO_INT(profiles[i].enabled);
2984         }
2985 
2986         CALL_ONREQUEST(RIL_REQUEST_SET_DATA_PROFILE, dataProfilePtrs,
2987                 num * sizeof(RIL_DataProfileInfo *), pRI, mSlotId);
2988 
2989         freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 4,
2990                 &RIL_DataProfileInfo::apn, &RIL_DataProfileInfo::protocol,
2991                 &RIL_DataProfileInfo::user, &RIL_DataProfileInfo::password);
2992     } else {
2993         RIL_DataProfileInfo_v15 *dataProfiles =
2994             (RIL_DataProfileInfo_v15 *) calloc(num, sizeof(RIL_DataProfileInfo_v15));
2995 
2996         if (dataProfiles == NULL) {
2997             RLOGE("Memory allocation failed for request %s",
2998                     requestToString(pRI->pCI->requestNumber));
2999             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3000             return Void();
3001         }
3002 
3003         RIL_DataProfileInfo_v15 **dataProfilePtrs =
3004             (RIL_DataProfileInfo_v15 **) calloc(num, sizeof(RIL_DataProfileInfo_v15 *));
3005         if (dataProfilePtrs == NULL) {
3006             RLOGE("Memory allocation failed for request %s",
3007                     requestToString(pRI->pCI->requestNumber));
3008             free(dataProfiles);
3009             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3010             return Void();
3011         }
3012 
3013         for (size_t i = 0; i < num; i++) {
3014             dataProfilePtrs[i] = &dataProfiles[i];
3015 
3016             success = copyHidlStringToRil(&dataProfiles[i].apn, profiles[i].apn, pRI, true);
3017             if (success && !copyHidlStringToRil(&dataProfiles[i].protocol, profiles[i].protocol,
3018                     pRI)) {
3019                 success = false;
3020             }
3021             if (success && !copyHidlStringToRil(&dataProfiles[i].roamingProtocol,
3022                     profiles[i].roamingProtocol, pRI, true)) {
3023                 success = false;
3024             }
3025             if (success && !copyHidlStringToRil(&dataProfiles[i].user, profiles[i].user, pRI,
3026                     true)) {
3027                 success = false;
3028             }
3029             if (success && !copyHidlStringToRil(&dataProfiles[i].password, profiles[i].password,
3030                     pRI, true)) {
3031                 success = false;
3032             }
3033             if (success && !copyHidlStringToRil(&dataProfiles[i].mvnoMatchData,
3034                     profiles[i].mvnoMatchData, pRI, true)) {
3035                 success = false;
3036             }
3037 
3038             if (success && !convertMvnoTypeToString(profiles[i].mvnoType,
3039                     dataProfiles[i].mvnoType)) {
3040                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3041                 success = false;
3042             }
3043 
3044             if (!success) {
3045                 freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 6,
3046                     &RIL_DataProfileInfo_v15::apn, &RIL_DataProfileInfo_v15::protocol,
3047                     &RIL_DataProfileInfo_v15::roamingProtocol, &RIL_DataProfileInfo_v15::user,
3048                     &RIL_DataProfileInfo_v15::password, &RIL_DataProfileInfo_v15::mvnoMatchData);
3049                 return Void();
3050             }
3051 
3052             dataProfiles[i].profileId = (RIL_DataProfile) profiles[i].profileId;
3053             dataProfiles[i].authType = (int) profiles[i].authType;
3054             dataProfiles[i].type = (int) profiles[i].type;
3055             dataProfiles[i].maxConnsTime = profiles[i].maxConnsTime;
3056             dataProfiles[i].maxConns = profiles[i].maxConns;
3057             dataProfiles[i].waitTime = profiles[i].waitTime;
3058             dataProfiles[i].enabled = BOOL_TO_INT(profiles[i].enabled);
3059             dataProfiles[i].supportedTypesBitmask = profiles[i].supportedApnTypesBitmap;
3060             dataProfiles[i].bearerBitmask = profiles[i].bearerBitmap;
3061             dataProfiles[i].mtu = profiles[i].mtu;
3062         }
3063 
3064         CALL_ONREQUEST(RIL_REQUEST_SET_DATA_PROFILE, dataProfilePtrs,
3065                 num * sizeof(RIL_DataProfileInfo_v15 *), pRI, mSlotId);
3066 
3067         freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 6,
3068                 &RIL_DataProfileInfo_v15::apn, &RIL_DataProfileInfo_v15::protocol,
3069                 &RIL_DataProfileInfo_v15::roamingProtocol, &RIL_DataProfileInfo_v15::user,
3070                 &RIL_DataProfileInfo_v15::password, &RIL_DataProfileInfo_v15::mvnoMatchData);
3071     }
3072 
3073     return Void();
3074 }
3075 
requestShutdown(int32_t serial)3076 Return<void> RadioImpl_1_6::requestShutdown(int32_t serial) {
3077 #if VDBG
3078     RLOGD("requestShutdown: serial %d", serial);
3079 #endif
3080     dispatchVoid(serial, mSlotId, RIL_REQUEST_SHUTDOWN);
3081     return Void();
3082 }
3083 
getRadioCapability(int32_t serial)3084 Return<void> RadioImpl_1_6::getRadioCapability(int32_t serial) {
3085 #if VDBG
3086     RLOGD("getRadioCapability: serial %d", serial);
3087 #endif
3088     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_RADIO_CAPABILITY);
3089     return Void();
3090 }
3091 
setRadioCapability(int32_t serial,const RadioCapability & rc)3092 Return<void> RadioImpl_1_6::setRadioCapability(int32_t serial, const RadioCapability& rc) {
3093 #if VDBG
3094     RLOGD("setRadioCapability: serial %d", serial);
3095 #endif
3096     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SET_RADIO_CAPABILITY);
3097     if (pRI == NULL) {
3098         return Void();
3099     }
3100 
3101     RIL_RadioCapability rilRc = {};
3102 
3103     // TODO : set rilRc.version using HIDL version ?
3104     rilRc.session = rc.session;
3105     rilRc.phase = (int) rc.phase;
3106     rilRc.rat = (int) rc.raf;
3107     rilRc.status = (int) rc.status;
3108     strlcpy(rilRc.logicalModemUuid, rc.logicalModemUuid.c_str(), sizeof(rilRc.logicalModemUuid));
3109 
3110     CALL_ONREQUEST(pRI->pCI->requestNumber, &rilRc, sizeof(rilRc), pRI, mSlotId);
3111 
3112     return Void();
3113 }
3114 
startLceService(int32_t serial,int32_t reportInterval,bool pullMode)3115 Return<void> RadioImpl_1_6::startLceService(int32_t serial, int32_t reportInterval, bool pullMode) {
3116 #if VDBG
3117     RLOGD("startLceService: serial %d", serial);
3118 #endif
3119     dispatchInts(serial, mSlotId, RIL_REQUEST_START_LCE, 2, reportInterval,
3120             BOOL_TO_INT(pullMode));
3121     return Void();
3122 }
3123 
stopLceService(int32_t serial)3124 Return<void> RadioImpl_1_6::stopLceService(int32_t serial) {
3125 #if VDBG
3126     RLOGD("stopLceService: serial %d", serial);
3127 #endif
3128     dispatchVoid(serial, mSlotId, RIL_REQUEST_STOP_LCE);
3129     return Void();
3130 }
3131 
pullLceData(int32_t serial)3132 Return<void> RadioImpl_1_6::pullLceData(int32_t serial) {
3133 #if VDBG
3134     RLOGD("pullLceData: serial %d", serial);
3135 #endif
3136     dispatchVoid(serial, mSlotId, RIL_REQUEST_PULL_LCEDATA);
3137     return Void();
3138 }
3139 
getModemActivityInfo(int32_t serial)3140 Return<void> RadioImpl_1_6::getModemActivityInfo(int32_t serial) {
3141 #if VDBG
3142     RLOGD("getModemActivityInfo: serial %d", serial);
3143 #endif
3144     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_ACTIVITY_INFO);
3145     return Void();
3146 }
3147 
prepareCarrierRestrictions(RIL_CarrierRestrictions & request,bool allAllowed,const hidl_vec<Carrier> & allowedList,const hidl_vec<Carrier> & excludedList,RequestInfo * pRI)3148 int prepareCarrierRestrictions(RIL_CarrierRestrictions &request, bool allAllowed,
3149                                const hidl_vec<Carrier>& allowedList,
3150                                const hidl_vec<Carrier>& excludedList,
3151                                RequestInfo *pRI) {
3152     RIL_Carrier *allowedCarriers = NULL;
3153     RIL_Carrier *excludedCarriers = NULL;
3154 
3155     request.len_allowed_carriers = allowedList.size();
3156     allowedCarriers = (RIL_Carrier *)calloc(request.len_allowed_carriers, sizeof(RIL_Carrier));
3157     if (allowedCarriers == NULL) {
3158         RLOGE("prepareCarrierRestrictions: Memory allocation failed for request %s",
3159                 requestToString(pRI->pCI->requestNumber));
3160         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3161         return -1;
3162     }
3163     request.allowed_carriers = allowedCarriers;
3164 
3165     request.len_excluded_carriers = excludedList.size();
3166     excludedCarriers = (RIL_Carrier *)calloc(request.len_excluded_carriers, sizeof(RIL_Carrier));
3167     if (excludedCarriers == NULL) {
3168         RLOGE("prepareCarrierRestrictions: Memory allocation failed for request %s",
3169                 requestToString(pRI->pCI->requestNumber));
3170         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3171 #ifdef MEMSET_FREED
3172         memset(allowedCarriers, 0, request.len_allowed_carriers * sizeof(RIL_Carrier));
3173 #endif
3174         free(allowedCarriers);
3175         return -1;
3176     }
3177     request.excluded_carriers = excludedCarriers;
3178 
3179     for (int i = 0; i < request.len_allowed_carriers; i++) {
3180         allowedCarriers[i].mcc = allowedList[i].mcc.c_str();
3181         allowedCarriers[i].mnc = allowedList[i].mnc.c_str();
3182         allowedCarriers[i].match_type = (RIL_CarrierMatchType) allowedList[i].matchType;
3183         allowedCarriers[i].match_data = allowedList[i].matchData.c_str();
3184     }
3185 
3186     for (int i = 0; i < request.len_excluded_carriers; i++) {
3187         excludedCarriers[i].mcc = excludedList[i].mcc.c_str();
3188         excludedCarriers[i].mnc = excludedList[i].mnc.c_str();
3189         excludedCarriers[i].match_type =
3190                 (RIL_CarrierMatchType) excludedList[i].matchType;
3191         excludedCarriers[i].match_data = excludedList[i].matchData.c_str();
3192     }
3193 
3194     return 0;
3195 }
3196 
freeCarrierRestrictions(RIL_CarrierRestrictions & request)3197 void freeCarrierRestrictions(RIL_CarrierRestrictions &request) {
3198     if (request.allowed_carriers != NULL) {
3199 #ifdef MEMSET_FREED
3200         memset(request.allowed_carriers, 0, request.len_allowed_carriers * sizeof(RIL_Carrier));
3201 #endif
3202         free(request.allowed_carriers);
3203     }
3204     if (request.excluded_carriers != NULL) {
3205 #ifdef MEMSET_FREED
3206         memset(request.excluded_carriers, 0, request.len_excluded_carriers * sizeof(RIL_Carrier));
3207 #endif
3208         free(request.excluded_carriers);
3209     }
3210 }
3211 
setAllowedCarriers(int32_t serial,bool allAllowed,const CarrierRestrictions & carriers)3212 Return<void> RadioImpl_1_6::setAllowedCarriers(int32_t serial, bool allAllowed,
3213                                            const CarrierRestrictions& carriers) {
3214 #if VDBG
3215     RLOGD("setAllowedCarriers: serial %d", serial);
3216 #endif
3217     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3218             RIL_REQUEST_SET_CARRIER_RESTRICTIONS);
3219     if (pRI == NULL) {
3220         return Void();
3221     }
3222 
3223     RIL_CarrierRestrictions cr = {};
3224     if (prepareCarrierRestrictions(cr, allAllowed, carriers.allowedCarriers,
3225             carriers.excludedCarriers, pRI) < 0) {
3226         return Void();
3227     }
3228 
3229     CALL_ONREQUEST(pRI->pCI->requestNumber, &cr, sizeof(RIL_CarrierRestrictions), pRI, mSlotId);
3230 
3231     freeCarrierRestrictions(cr);
3232 
3233     return Void();
3234 }
3235 
getAllowedCarriers(int32_t serial)3236 Return<void> RadioImpl_1_6::getAllowedCarriers(int32_t serial) {
3237 #if VDBG
3238     RLOGD("getAllowedCarriers: serial %d", serial);
3239 #endif
3240     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CARRIER_RESTRICTIONS);
3241     return Void();
3242 }
3243 
sendDeviceState(int32_t serial,DeviceStateType deviceStateType,bool state)3244 Return<void> RadioImpl_1_6::sendDeviceState(int32_t serial, DeviceStateType deviceStateType,
3245                                         bool state) {
3246 #if VDBG
3247     RLOGD("sendDeviceState: serial %d", serial);
3248 #endif
3249     if (s_vendorFunctions->version < 15) {
3250         if (deviceStateType ==  DeviceStateType::LOW_DATA_EXPECTED) {
3251             RLOGD("sendDeviceState: calling screen state %d", BOOL_TO_INT(!state));
3252             dispatchInts(serial, mSlotId, RIL_REQUEST_SCREEN_STATE, 1, BOOL_TO_INT(!state));
3253         } else {
3254             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3255                     RIL_REQUEST_SEND_DEVICE_STATE);
3256             sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
3257         }
3258         return Void();
3259     }
3260     dispatchInts(serial, mSlotId, RIL_REQUEST_SEND_DEVICE_STATE, 2, (int) deviceStateType,
3261             BOOL_TO_INT(state));
3262     return Void();
3263 }
3264 
setIndicationFilter(int32_t serial,int32_t indicationFilter)3265 Return<void> RadioImpl_1_6::setIndicationFilter(int32_t serial, int32_t indicationFilter) {
3266 #if VDBG
3267     RLOGD("setIndicationFilter: serial %d", serial);
3268 #endif
3269     if (s_vendorFunctions->version < 15) {
3270         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3271                 RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER);
3272         sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
3273         return Void();
3274     }
3275     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, 1, indicationFilter);
3276     return Void();
3277 }
3278 
setSimCardPower(int32_t serial,bool powerUp)3279 Return<void> RadioImpl_1_6::setSimCardPower(int32_t serial, bool powerUp) {
3280 #if VDBG
3281     RLOGD("setSimCardPower: serial %d", serial);
3282 #endif
3283     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, BOOL_TO_INT(powerUp));
3284     return Void();
3285 }
3286 
setSimCardPower_1_1(int32_t serial,const V1_1::CardPowerState state)3287 Return<void> RadioImpl_1_6::setSimCardPower_1_1(int32_t serial, const V1_1::CardPowerState state) {
3288 #if VDBG
3289     RLOGD("setSimCardPower_1_1: serial %d state %d", serial, state);
3290 #endif
3291     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, state);
3292     return Void();
3293 }
3294 
setSimCardPower_1_6(int32_t serial,const V1_1::CardPowerState state)3295 Return<void> RadioImpl_1_6::setSimCardPower_1_6(int32_t serial, const V1_1::CardPowerState state) {
3296 #if VDBG
3297     RLOGD("setSimCardPower_1_6: serial %d state %d", serial, state);
3298 #endif
3299     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, state);
3300     mSimCardPowerState = state;
3301     return Void();
3302 }
3303 
setCarrierInfoForImsiEncryption(int32_t serial,const V1_1::ImsiEncryptionInfo & data)3304 Return<void> RadioImpl_1_6::setCarrierInfoForImsiEncryption(int32_t serial,
3305         const V1_1::ImsiEncryptionInfo& data) {
3306 #if VDBG
3307     RLOGD("setCarrierInfoForImsiEncryption: serial %d", serial);
3308 #endif
3309     RequestInfo *pRI = android::addRequestToList(
3310             serial, mSlotId, RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION);
3311     if (pRI == NULL) {
3312         return Void();
3313     }
3314 
3315     RIL_CarrierInfoForImsiEncryption imsiEncryption = {};
3316 
3317     if (!copyHidlStringToRil(&imsiEncryption.mnc, data.mnc, pRI)) {
3318         return Void();
3319     }
3320     if (!copyHidlStringToRil(&imsiEncryption.mcc, data.mcc, pRI)) {
3321         memsetAndFreeStrings(1, imsiEncryption.mnc);
3322         return Void();
3323     }
3324     if (!copyHidlStringToRil(&imsiEncryption.keyIdentifier, data.keyIdentifier, pRI)) {
3325         memsetAndFreeStrings(2, imsiEncryption.mnc, imsiEncryption.mcc);
3326         return Void();
3327     }
3328     imsiEncryption.carrierKeyLength = data.carrierKey.size();
3329     imsiEncryption.carrierKey = new uint8_t[imsiEncryption.carrierKeyLength];
3330     memcpy(imsiEncryption.carrierKey, data.carrierKey.data(), imsiEncryption.carrierKeyLength);
3331     imsiEncryption.expirationTime = data.expirationTime;
3332     CALL_ONREQUEST(pRI->pCI->requestNumber, &imsiEncryption,
3333             sizeof(RIL_CarrierInfoForImsiEncryption), pRI, mSlotId);
3334     delete(imsiEncryption.carrierKey);
3335     return Void();
3336 }
3337 
startKeepalive(int32_t serial,const V1_1::KeepaliveRequest & keepalive)3338 Return<void> RadioImpl_1_6::startKeepalive(int32_t serial, const V1_1::KeepaliveRequest& keepalive) {
3339 #if VDBG
3340     RLOGD("%s(): %d", __FUNCTION__, serial);
3341 #endif
3342     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_KEEPALIVE);
3343     if (pRI == NULL) {
3344         return Void();
3345     }
3346 
3347     RIL_KeepaliveRequest kaReq = {};
3348 
3349     kaReq.type = static_cast<RIL_KeepaliveType>(keepalive.type);
3350     switch(kaReq.type) {
3351         case NATT_IPV4:
3352             if (keepalive.sourceAddress.size() != 4 ||
3353                     keepalive.destinationAddress.size() != 4) {
3354                 RLOGE("Invalid address for keepalive!");
3355                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3356                 return Void();
3357             }
3358             break;
3359         case NATT_IPV6:
3360             if (keepalive.sourceAddress.size() != 16 ||
3361                     keepalive.destinationAddress.size() != 16) {
3362                 RLOGE("Invalid address for keepalive!");
3363                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3364                 return Void();
3365             }
3366             break;
3367         default:
3368             RLOGE("Unknown packet keepalive type!");
3369             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3370             return Void();
3371     }
3372 
3373     ::memcpy(kaReq.sourceAddress, keepalive.sourceAddress.data(), keepalive.sourceAddress.size());
3374     kaReq.sourcePort = keepalive.sourcePort;
3375 
3376     ::memcpy(kaReq.destinationAddress,
3377             keepalive.destinationAddress.data(), keepalive.destinationAddress.size());
3378     kaReq.destinationPort = keepalive.destinationPort;
3379 
3380     kaReq.maxKeepaliveIntervalMillis = keepalive.maxKeepaliveIntervalMillis;
3381     kaReq.cid = keepalive.cid; // This is the context ID of the data call
3382 
3383     CALL_ONREQUEST(pRI->pCI->requestNumber, &kaReq, sizeof(RIL_KeepaliveRequest), pRI, mSlotId);
3384     return Void();
3385 }
3386 
stopKeepalive(int32_t serial,int32_t sessionHandle)3387 Return<void> RadioImpl_1_6::stopKeepalive(int32_t serial, int32_t sessionHandle) {
3388 #if VDBG
3389     RLOGD("%s(): %d", __FUNCTION__, serial);
3390 #endif
3391     dispatchInts(serial, mSlotId, RIL_REQUEST_STOP_KEEPALIVE, 1, sessionHandle);
3392     return Void();
3393 }
3394 
responseAcknowledgement()3395 Return<void> RadioImpl_1_6::responseAcknowledgement() {
3396     android::releaseWakeLock();
3397     return Void();
3398 }
3399 
3400 // Methods from ::android::hardware::radio::V1_2::IRadio follow.
prepareNetworkScanRequest_1_2(RIL_NetworkScanRequest & scan_request,const::android::hardware::radio::V1_2::NetworkScanRequest & request,RequestInfo * pRI)3401 int prepareNetworkScanRequest_1_2(RIL_NetworkScanRequest &scan_request,
3402     const ::android::hardware::radio::V1_2::NetworkScanRequest& request,
3403     RequestInfo *pRI) {
3404 
3405     scan_request.type = (RIL_ScanType) request.type;
3406     scan_request.interval = request.interval;
3407     scan_request.specifiers_length = request.specifiers.size();
3408 
3409     int intervalLow = static_cast<int>(::android::hardware::radio::V1_2::ScanIntervalRange::MIN);
3410     int intervalHigh = static_cast<int>(::android::hardware::radio::V1_2::ScanIntervalRange::MAX);
3411     int maxSearchTimeLow =
3412         static_cast<int>(::android::hardware::radio::V1_2::MaxSearchTimeRange::MIN);
3413     int maxSearchTimeHigh =
3414         static_cast<int>(::android::hardware::radio::V1_2::MaxSearchTimeRange::MAX);
3415     int incrementalResultsPeriodicityRangeLow =
3416         static_cast<int>(::android::hardware::radio::V1_2::IncrementalResultsPeriodicityRange::MIN);
3417     int incrementalResultsPeriodicityRangeHigh =
3418         static_cast<int>(::android::hardware::radio::V1_2::IncrementalResultsPeriodicityRange::MAX);
3419     uint maxSpecifierSize =
3420         static_cast<uint>(::android::hardware::radio::V1_2::RadioConst
3421             ::RADIO_ACCESS_SPECIFIER_MAX_SIZE);
3422 
3423     if (request.interval < intervalLow || request.interval > intervalHigh) {
3424         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3425         return -1;
3426     }
3427     // If defined, must fall in correct range.
3428     if (request.maxSearchTime != 0
3429         && (request.maxSearchTime < maxSearchTimeLow
3430             || request.maxSearchTime > maxSearchTimeHigh)) {
3431         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3432         return -1;
3433     }
3434     if (request.maxSearchTime != 0
3435         && (request.incrementalResultsPeriodicity < incrementalResultsPeriodicityRangeLow
3436             || request.incrementalResultsPeriodicity > incrementalResultsPeriodicityRangeHigh
3437             || request.incrementalResultsPeriodicity > request.maxSearchTime)) {
3438         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3439         return -1;
3440     }
3441     if (request.specifiers.size() == 0 || request.specifiers.size() > maxSpecifierSize) {
3442         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3443         return -1;
3444     }
3445 
3446     for (size_t i = 0; i < request.specifiers.size(); ++i) {
3447         if (request.specifiers[i].geranBands.size() > MAX_BANDS ||
3448             request.specifiers[i].utranBands.size() > MAX_BANDS ||
3449             request.specifiers[i].eutranBands.size() > MAX_BANDS ||
3450             request.specifiers[i].channels.size() > MAX_CHANNELS) {
3451             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3452             return -1;
3453         }
3454         const V1_1::RadioAccessSpecifier& ras_from =
3455                 request.specifiers[i];
3456         RIL_RadioAccessSpecifier& ras_to = scan_request.specifiers[i];
3457 
3458         ras_to.radio_access_network = (RIL_RadioAccessNetworks) ras_from.radioAccessNetwork;
3459         ras_to.channels_length = ras_from.channels.size();
3460 
3461         std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
3462         const std::vector<uint32_t> * bands = nullptr;
3463         switch (request.specifiers[i].radioAccessNetwork) {
3464             case V1_1::RadioAccessNetworks::GERAN:
3465                 ras_to.bands_length = ras_from.geranBands.size();
3466                 bands = (std::vector<uint32_t> *) &ras_from.geranBands;
3467                 break;
3468             case V1_1::RadioAccessNetworks::UTRAN:
3469                 ras_to.bands_length = ras_from.utranBands.size();
3470                 bands = (std::vector<uint32_t> *) &ras_from.utranBands;
3471                 break;
3472             case V1_1::RadioAccessNetworks::EUTRAN:
3473                 ras_to.bands_length = ras_from.eutranBands.size();
3474                 bands = (std::vector<uint32_t> *) &ras_from.eutranBands;
3475                 break;
3476             default:
3477                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3478                 return -1;
3479         }
3480         // safe to copy to geran_bands because it's a union member
3481         for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
3482             ras_to.bands.geran_bands[idx] = (RIL_GeranBands) (*bands)[idx];
3483         }
3484     }
3485 
3486     return 0;
3487 }
3488 
startNetworkScan_1_2(int32_t serial,const::android::hardware::radio::V1_2::NetworkScanRequest & request)3489 Return<void> RadioImpl_1_6::startNetworkScan_1_2(int32_t serial,
3490         const ::android::hardware::radio::V1_2::NetworkScanRequest& request) {
3491 #if VDBG
3492     RLOGD("startNetworkScan_1_2: serial %d", serial);
3493 #endif
3494 
3495     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
3496     if (pRI == NULL) {
3497         return Void();
3498     }
3499 
3500     RIL_NetworkScanRequest scan_request = {};
3501 
3502     if (prepareNetworkScanRequest_1_2(scan_request, request, pRI) < 0) {
3503         return Void();
3504     }
3505 
3506     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
3507             mSlotId);
3508 
3509     return Void();
3510 }
3511 
setIndicationFilter_1_2(int32_t serial,::android::hardware::hidl_bitfield<V1_2::IndicationFilter> indicationFilter)3512 Return<void> RadioImpl_1_6::setIndicationFilter_1_2(int32_t serial,
3513         ::android::hardware::hidl_bitfield<V1_2::IndicationFilter> indicationFilter) {
3514 #if VDBG
3515     RLOGD("setIndicationFilter_1_2: serial %d", serial);
3516 #endif
3517 
3518     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3519             RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER);
3520     sendErrorResponse(pRI, RIL_E_SUCCESS);  // TODO: for vts
3521     return Void();
3522 }
3523 
setSignalStrengthReportingCriteria(int32_t serial,int32_t hysteresisMs,int32_t hysteresisDb,const hidl_vec<int32_t> & thresholdsDbm,::android::hardware::radio::V1_2::AccessNetwork accessNetwork)3524 Return<void> RadioImpl_1_6::setSignalStrengthReportingCriteria(int32_t serial,
3525         int32_t hysteresisMs, int32_t hysteresisDb,
3526         const hidl_vec<int32_t>& thresholdsDbm,
3527         ::android::hardware::radio::V1_2::AccessNetwork  accessNetwork) {
3528 #if VDBG
3529     RLOGD("setSignalStrengthReportingCriteria: %d", serial);
3530 #endif
3531     RIL_Errno e;
3532     if (radioService[mSlotId]->mRadioResponseV1_2 != NULL) {
3533          RadioResponseInfo responseInfo = {};
3534          if (hysteresisDb >= 10) {
3535              e = RIL_E_INVALID_ARGUMENTS;
3536          } else {
3537              e = RIL_E_SUCCESS;
3538          }
3539          populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, e);
3540          Return<void> retStatus =
3541                  radioService[mSlotId]
3542                          ->mRadioResponseV1_2->setSignalStrengthReportingCriteriaResponse(
3543                                  responseInfo);
3544          radioService[mSlotId]->checkReturnStatus(retStatus);
3545     } else {
3546         RLOGE("setSignalStrengthReportingCriteria: radioService[%d]->mRadioResponse == NULL",
3547               mSlotId);
3548     }
3549     return Void();
3550 }
3551 
setLinkCapacityReportingCriteria(int32_t serial,int32_t hysteresisMs,int32_t hysteresisDlKbps,int32_t hysteresisUlKbps,const hidl_vec<int32_t> & thresholdsDownlinkKbps,const hidl_vec<int32_t> & thresholdsUplinkKbps,V1_2::AccessNetwork accessNetwork)3552 Return<void> RadioImpl_1_6::setLinkCapacityReportingCriteria(int32_t serial,
3553        int32_t hysteresisMs, int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
3554        const hidl_vec<int32_t>& thresholdsDownlinkKbps,
3555         const hidl_vec<int32_t>& thresholdsUplinkKbps,
3556         V1_2::AccessNetwork accessNetwork) {
3557 #if VDBG
3558     RLOGE("[%04d]< %s", serial, "Method is not implemented");
3559     RLOGD("setLinkCapacityReportingCriteria: %d", serial);
3560 #endif
3561 
3562     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3563             RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA);
3564     if (pRI == NULL) {
3565         return Void();
3566     }
3567     // TODO: for vts. hysteresisDlKbps and hysteresisUlKbps range not confirmed
3568     if (hysteresisDlKbps >= 5000 || hysteresisUlKbps >= 1000) {
3569         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3570         return Void();
3571     } else {
3572         sendErrorResponse(pRI, RIL_E_SUCCESS);
3573     }
3574     return Void();
3575 }
3576 
setupDataCall_1_2(int32_t serial,V1_2::AccessNetwork accessNetwork,const V1_0::DataProfileInfo & dataProfileInfo,bool modemCognitive,bool roamingAllowed,bool isRoaming,V1_2::DataRequestReason reason,const hidl_vec<hidl_string> & addresses,const hidl_vec<hidl_string> & dnses)3577 Return<void> RadioImpl_1_6::setupDataCall_1_2(int32_t serial, V1_2::AccessNetwork accessNetwork,
3578         const V1_0::DataProfileInfo& dataProfileInfo, bool modemCognitive,
3579         bool roamingAllowed, bool isRoaming, V1_2::DataRequestReason reason,
3580         const hidl_vec<hidl_string>& addresses, const hidl_vec<hidl_string>& dnses) {
3581 #if VDBG
3582     RLOGE("[%04d]< %s", serial, "Method is not implemented");
3583     RLOGD("setupDataCall_1_2: serial %d", serial);
3584 #endif
3585 
3586     if (s_vendorFunctions->version >= 4 && s_vendorFunctions->version <= 14) {
3587         const hidl_string &protocol =
3588                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
3589         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 7,
3590             std::to_string((int)accessNetwork).c_str(),
3591             std::to_string((int)dataProfileInfo.profileId).c_str(),
3592             dataProfileInfo.apn.c_str(),
3593             dataProfileInfo.user.c_str(),
3594             dataProfileInfo.password.c_str(),
3595             std::to_string((int)dataProfileInfo.authType).c_str(),
3596             protocol.c_str());
3597     } else if (s_vendorFunctions->version >= 15) {
3598         char *mvnoTypeStr = NULL;
3599         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) {
3600             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3601                     RIL_REQUEST_SETUP_DATA_CALL);
3602             if (pRI != NULL) {
3603                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3604             }
3605             return Void();
3606         }
3607         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15,
3608             std::to_string((int)accessNetwork).c_str(),
3609             std::to_string((int)dataProfileInfo.profileId).c_str(),
3610             dataProfileInfo.apn.c_str(),
3611             dataProfileInfo.user.c_str(),
3612             dataProfileInfo.password.c_str(),
3613             std::to_string((int) dataProfileInfo.authType).c_str(),
3614             dataProfileInfo.protocol.c_str(),
3615             dataProfileInfo.roamingProtocol.c_str(),
3616             std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
3617             std::to_string(dataProfileInfo.bearerBitmap).c_str(),
3618             modemCognitive ? "1" : "0",
3619             std::to_string(dataProfileInfo.mtu).c_str(),
3620             mvnoTypeStr,
3621             dataProfileInfo.mvnoMatchData.c_str(),
3622             roamingAllowed ? "1" : "0");
3623     } else {
3624         RLOGE("Unsupported RIL version %d, min version expected 4", s_vendorFunctions->version);
3625         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3626                 RIL_REQUEST_SETUP_DATA_CALL);
3627         if (pRI != NULL) {
3628             sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
3629         }
3630     }
3631     return Void();
3632 }
3633 
deactivateDataCall_1_2(int32_t serial,int32_t cid,::android::hardware::radio::V1_2::DataRequestReason reason)3634 Return<void> RadioImpl_1_6::deactivateDataCall_1_2(int32_t serial, int32_t cid,
3635         ::android::hardware::radio::V1_2::DataRequestReason reason) {
3636 #if VDBG
3637     RLOGD("deactivateDataCall_1_2: serial %d", serial);
3638 #endif
3639 
3640     RIL_DataRequestReason dataRequestReason = (RIL_DataRequestReason)reason;
3641     const char *reasonStr = NULL;
3642     switch (dataRequestReason) {
3643         case DATA_REQ_REASOPN_NORMAL:
3644             reasonStr = "normal";
3645             break;
3646         case DATA_REQ_REASOPN_SHUTDOWN:
3647             reasonStr = "shutdown";
3648             break;
3649         case DATA_REQ_REASOPN_HANDOVER:
3650             reasonStr = "handover";
3651             break;
3652         default:
3653             reasonStr = "unknown";
3654             break;
3655     }
3656 
3657     dispatchStrings(serial, mSlotId, RIL_REQUEST_DEACTIVATE_DATA_CALL, false,
3658             2, (std::to_string(cid)).c_str(), reasonStr);
3659     return Void();
3660 }
3661 
3662 // Methods from ::android::hardware::radio::V1_3::IRadio follow.
setSystemSelectionChannels(int32_t serial,bool,const hidl_vec<::android::hardware::radio::V1_1::RadioAccessSpecifier> &)3663 Return<void> RadioImpl_1_6::setSystemSelectionChannels(int32_t serial, bool /* specifyChannels */,
3664         const hidl_vec<::android::hardware::radio::V1_1::RadioAccessSpecifier>& /* specifiers */) {
3665 #if VDBG
3666     RLOGD("setSystemSelectionChannels: serial %d", serial);
3667 #endif
3668     dispatchVoid(serial, mSlotId, RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS);
3669     return Void();
3670 }
3671 
enableModem(int32_t serial,bool)3672 Return<void> RadioImpl_1_6::enableModem(int32_t serial, bool /* on */) {
3673 #if VDBG
3674     RLOGE("enableModem: serial = %d", serial);
3675 #endif
3676     dispatchVoid(serial, mSlotId, RIL_REQUEST_ENABLE_MODEM);
3677     return Void();
3678 }
3679 
getModemStackStatus(int32_t serial)3680 Return<void> RadioImpl_1_6::getModemStackStatus(int32_t serial) {
3681 #if VDBG
3682     RLOGD("getModemStackStatus: serial %d", serial);
3683 #endif
3684     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_MODEM_STACK_STATUS);
3685     return Void();
3686 }
3687 
getProtocolString(const::android::hardware::radio::V1_4::PdpProtocolType protocolVal)3688 const char * getProtocolString(const ::android::hardware::radio::V1_4::PdpProtocolType protocolVal) {
3689     switch(protocolVal) {
3690         case ::android::hardware::radio::V1_4::PdpProtocolType::IP:
3691             return "IP";
3692         case ::android::hardware::radio::V1_4::PdpProtocolType::IPV6:
3693             return "IPV6";
3694         case ::android::hardware::radio::V1_4::PdpProtocolType::IPV4V6:
3695             return "IPV4V6";
3696         case ::android::hardware::radio::V1_4::PdpProtocolType::PPP:
3697             return "PPP";
3698         case ::android::hardware::radio::V1_4::PdpProtocolType::NON_IP:
3699             return "NON_IP";
3700         case ::android::hardware::radio::V1_4::PdpProtocolType::UNSTRUCTURED:
3701             return "UNSTRUCTURED";
3702         default:
3703             return "UNKNOWN";
3704     }
3705 }
3706 
3707 // Methods from ::android::hardware::radio::V1_4::IRadio follow.
setAllowedCarriers_1_4(int32_t serial,const V1_4::CarrierRestrictionsWithPriority & carriers,V1_4::SimLockMultiSimPolicy multiSimPolicy)3708 Return<void> RadioImpl_1_6::setAllowedCarriers_1_4(int32_t  serial,
3709         const V1_4::CarrierRestrictionsWithPriority& carriers,
3710         V1_4::SimLockMultiSimPolicy multiSimPolicy) {
3711 #if VDBG
3712     RLOGD("setAllowedCarriers_1_4: serial %d", serial);
3713 #endif
3714 
3715     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3716             RIL_REQUEST_SET_CARRIER_RESTRICTIONS);
3717     if (pRI == NULL) {
3718         return Void();
3719     }
3720 
3721     // Prepare legacy structure (defined in IRadio 1.0) to reuse existing code.
3722     RIL_CarrierRestrictions cr = {};
3723     if (prepareCarrierRestrictions(cr, false, carriers.allowedCarriers, carriers.excludedCarriers,
3724             pRI) < 0) {
3725         return Void();
3726     }
3727     // Copy the legacy structure into the new structure (defined in IRadio 1.4)
3728     RIL_CarrierRestrictionsWithPriority crExt = {};
3729     crExt.len_allowed_carriers = cr.len_allowed_carriers;
3730     crExt.allowed_carriers = cr.allowed_carriers;
3731     crExt.len_excluded_carriers = cr.len_excluded_carriers;
3732     crExt.excluded_carriers = cr.excluded_carriers;
3733     crExt.allowedCarriersPrioritized = BOOL_TO_INT(carriers.allowedCarriersPrioritized);
3734     crExt.multiSimPolicy = (RIL_SimLockMultiSimPolicy)multiSimPolicy;
3735 
3736     CALL_ONREQUEST(pRI->pCI->requestNumber, &crExt, sizeof(RIL_CarrierRestrictionsWithPriority),
3737             pRI, mSlotId);
3738 
3739     freeCarrierRestrictions(cr);
3740 
3741     return Void();
3742 }
3743 
getAllowedCarriers_1_4(int32_t serial)3744 Return<void> RadioImpl_1_6::getAllowedCarriers_1_4(int32_t serial) {
3745 #if VDBG
3746     RLOGD("getAllowedCarriers_1_4: serial %d", serial);
3747 #endif
3748     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CARRIER_RESTRICTIONS);
3749     return Void();
3750 }
3751 
setupDataCall_1_4(int32_t serial,::android::hardware::radio::V1_4::AccessNetwork,const::android::hardware::radio::V1_4::DataProfileInfo & dataProfileInfo,bool roamingAllowed,::android::hardware::radio::V1_2::DataRequestReason,const hidl_vec<hidl_string> &,const hidl_vec<hidl_string> &)3752 Return<void> RadioImpl_1_6::setupDataCall_1_4(int32_t serial ,
3753         ::android::hardware::radio::V1_4::AccessNetwork /* accessNetwork */,
3754         const ::android::hardware::radio::V1_4::DataProfileInfo& dataProfileInfo,
3755         bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason /* reason */,
3756         const hidl_vec<hidl_string>& /* addresses */, const hidl_vec<hidl_string>& /* dnses */) {
3757 
3758 #if VDBG
3759     RLOGD("setupDataCall_1_4: serial %d", serial);
3760 #endif
3761 
3762     char *mvnoTypeStr = NULL;
3763     if (!convertMvnoTypeToString(MvnoType::IMSI, mvnoTypeStr)) {
3764         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3765                 RIL_REQUEST_SETUP_DATA_CALL);
3766         if (pRI != NULL) {
3767             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3768         }
3769         return Void();
3770     }
3771     dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 16,
3772         std::to_string((int) RadioTechnology::UNKNOWN + 2).c_str(),
3773         std::to_string((int) dataProfileInfo.profileId).c_str(),
3774         dataProfileInfo.apn.c_str(),
3775         dataProfileInfo.user.c_str(),
3776         dataProfileInfo.password.c_str(),
3777         std::to_string((int) dataProfileInfo.authType).c_str(),
3778         getProtocolString(dataProfileInfo.protocol),
3779         getProtocolString(dataProfileInfo.roamingProtocol),
3780         std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
3781         std::to_string(dataProfileInfo.bearerBitmap).c_str(),
3782         dataProfileInfo.persistent ? "1" : "0",
3783         std::to_string(dataProfileInfo.mtu).c_str(),
3784         mvnoTypeStr,
3785         "302720x94",
3786         roamingAllowed ? "1" : "0",
3787         "-1");
3788     return Void();
3789 }
3790 
setInitialAttachApn_1_4(int32_t serial,const::android::hardware::radio::V1_4::DataProfileInfo & dataProfileInfo)3791 Return<void> RadioImpl_1_6::setInitialAttachApn_1_4(int32_t  serial ,
3792         const ::android::hardware::radio::V1_4::DataProfileInfo& dataProfileInfo) {
3793     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3794             RIL_REQUEST_SET_INITIAL_ATTACH_APN);
3795     if (pRI == NULL) {
3796         return Void();
3797     }
3798 
3799     RadioResponseInfo responseInfo = {};
3800     populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
3801 
3802     if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
3803         Return<void> retStatus
3804                 = radioService[mSlotId]->mRadioResponseV1_4->setInitialAttachApnResponse(responseInfo);
3805         radioService[mSlotId]->checkReturnStatus(retStatus);
3806     } else if (radioService[mSlotId]->mRadioResponse != NULL) {
3807         Return<void> retStatus
3808                 = radioService[mSlotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo);
3809         radioService[mSlotId]->checkReturnStatus(retStatus);
3810     } else {
3811         RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
3812     }
3813 
3814     return Void();
3815 }
3816 
setDataProfile_1_4(int32_t serial,const hidl_vec<::android::hardware::radio::V1_4::DataProfileInfo> &)3817 Return<void> RadioImpl_1_6::setDataProfile_1_4(int32_t  serial ,
3818         const hidl_vec<::android::hardware::radio::V1_4::DataProfileInfo>& /* profiles */) {
3819     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3820             RIL_REQUEST_SET_DATA_PROFILE);
3821     if (pRI == NULL) {
3822         return Void();
3823     }
3824 
3825     RadioResponseInfo responseInfo = {};
3826     populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
3827 
3828     if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
3829         Return<void> retStatus
3830                 = radioService[mSlotId]->mRadioResponseV1_4->setDataProfileResponse(responseInfo);
3831         radioService[mSlotId]->checkReturnStatus(retStatus);
3832     } else if (radioService[mSlotId]->mRadioResponse != NULL) {
3833         Return<void> retStatus
3834                 = radioService[mSlotId]->mRadioResponse->setDataProfileResponse(responseInfo);
3835         radioService[mSlotId]->checkReturnStatus(retStatus);
3836     } else {
3837         RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
3838     }
3839 
3840     return Void();
3841 }
3842 
emergencyDial(int32_t serial,const::android::hardware::radio::V1_0::Dial & dialInfo,hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,const hidl_vec<hidl_string> & urns,::android::hardware::radio::V1_4::EmergencyCallRouting routing,bool fromEmergencyDialer,bool)3843 Return<void> RadioImpl_1_6::emergencyDial(int32_t serial,
3844         const ::android::hardware::radio::V1_0::Dial& dialInfo,
3845         hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,
3846         const hidl_vec<hidl_string>&  urns ,
3847         ::android::hardware::radio::V1_4::EmergencyCallRouting routing,
3848         bool fromEmergencyDialer, bool /* isTesting */) {
3849 #if VDBG
3850     RLOGD("emergencyDial: serial %d", serial);
3851 #endif
3852 
3853     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_EMERGENCY_DIAL);
3854     if (pRI == NULL) {
3855         return Void();
3856     }
3857 
3858     RIL_EmergencyDial eccDial = {};
3859     RIL_Dial& dial = eccDial.dialInfo;
3860     RIL_UUS_Info uusInfo = {};
3861 
3862     if (!copyHidlStringToRil(&dial.address, dialInfo.address, pRI)) {
3863         return Void();
3864     }
3865     dial.clir = (int) dialInfo.clir;
3866 
3867     if (dialInfo.uusInfo.size() != 0) {
3868         uusInfo.uusType = (RIL_UUS_Type) dialInfo.uusInfo[0].uusType;
3869         uusInfo.uusDcs = (RIL_UUS_DCS) dialInfo.uusInfo[0].uusDcs;
3870 
3871         if (dialInfo.uusInfo[0].uusData.size() == 0) {
3872             uusInfo.uusData = NULL;
3873             uusInfo.uusLength = 0;
3874         } else {
3875             if (!copyHidlStringToRil(&uusInfo.uusData, dialInfo.uusInfo[0].uusData, pRI)) {
3876                 memsetAndFreeStrings(1, dial.address);
3877                 return Void();
3878             }
3879             uusInfo.uusLength = dialInfo.uusInfo[0].uusData.size();
3880         }
3881 
3882         dial.uusInfo = &uusInfo;
3883     }
3884 
3885     eccDial.urnsNumber = urns.size();
3886     if (eccDial.urnsNumber != 0) {
3887         char **ppUrns = (char **)calloc(eccDial.urnsNumber, sizeof(char *));
3888         if (ppUrns == NULL) {
3889             RLOGE("Memory allocation failed for request %s",
3890                     requestToString(pRI->pCI->requestNumber));
3891             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3892             memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
3893             return Void();
3894         }
3895         for (uint32_t i = 0; i < eccDial.urnsNumber; i++) {
3896             if (!copyHidlStringToRil(&ppUrns[i], hidl_string(urns[i]), pRI)) {
3897                 for (uint32_t j = 0; j < i; j++) {
3898                     memsetAndFreeStrings(1, ppUrns[j]);
3899                 }
3900                 memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
3901                 free(ppUrns);
3902                 return Void();
3903             }
3904         }
3905         eccDial.urns = ppUrns;
3906     }
3907 
3908     eccDial.categories = (RIL_EmergencyServiceCategory)categories;
3909     eccDial.routing = (RIL_EmergencyCallRouting)routing;
3910     eccDial.fromEmergencyDialer = fromEmergencyDialer;
3911 
3912     CALL_ONREQUEST(RIL_REQUEST_EMERGENCY_DIAL, &eccDial, sizeof(RIL_EmergencyDial), pRI, mSlotId);
3913 
3914     memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
3915     if (eccDial.urns != NULL) {
3916         for (size_t i = 0; i < eccDial.urnsNumber; i++) {
3917             memsetAndFreeStrings(1, eccDial.urns[i]);
3918         }
3919         free(eccDial.urns);
3920     }
3921     return Void();
3922 }
3923 
startNetworkScan_1_4(int32_t serial,const::android::hardware::radio::V1_2::NetworkScanRequest & request)3924 Return<void> RadioImpl_1_6::startNetworkScan_1_4(int32_t serial,
3925         const ::android::hardware::radio::V1_2::NetworkScanRequest& request) {
3926 #if VDBG
3927     RLOGD("startNetworkScan_1_4: serial %d", serial);
3928 #endif
3929 
3930     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
3931     if (pRI == NULL) {
3932         return Void();
3933     }
3934 
3935     RIL_NetworkScanRequest scan_request = {};
3936 
3937     if (prepareNetworkScanRequest_1_2(scan_request, request, pRI) < 0) {
3938         return Void();
3939     }
3940 
3941     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
3942             mSlotId);
3943 
3944     return Void();
3945 }
3946 
getPreferredNetworkTypeBitmap(int32_t serial)3947 Return<void> RadioImpl_1_6::getPreferredNetworkTypeBitmap(int32_t serial ) {
3948 #if VDBG
3949     RLOGD("getPreferredNetworkTypeBitmap: serial %d", serial);
3950 #endif
3951     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE_BITMAP);
3952     return Void();
3953 }
3954 
setPreferredNetworkTypeBitmap(int32_t serial,hidl_bitfield<RadioAccessFamily> networkTypeBitmap)3955 Return<void> RadioImpl_1_6::setPreferredNetworkTypeBitmap(
3956         int32_t serial, hidl_bitfield<RadioAccessFamily> networkTypeBitmap) {
3957 #if VDBG
3958     RLOGD("setPreferredNetworkTypeBitmap: serial %d", serial);
3959 #endif
3960     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE_BITMAP, 1, networkTypeBitmap);
3961     return Void();
3962 }
3963 
setAllowedNetworkTypesBitmap(uint32_t serial,hidl_bitfield<RadioAccessFamily> networkTypeBitmap)3964 Return<void> RadioImpl_1_6::setAllowedNetworkTypesBitmap(
3965         uint32_t serial, hidl_bitfield<RadioAccessFamily> networkTypeBitmap) {
3966 #if VDBG
3967     RLOGD("setAllowedNetworkTypesBitmap: serial %d", serial);
3968 #endif
3969     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP, 1, networkTypeBitmap);
3970     return Void();
3971 }
3972 
getAllowedNetworkTypesBitmap(int32_t serial)3973 Return<void> RadioImpl_1_6::getAllowedNetworkTypesBitmap(int32_t serial) {
3974 #if VDBG
3975     RLOGD("getAllowedNetworkTypesBitmap: serial %d", serial);
3976 #endif
3977     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP);
3978     return Void();
3979 }
3980 
getSignalStrength_1_4(int32_t serial)3981 Return<void> RadioImpl_1_6::getSignalStrength_1_4(int32_t serial) {
3982 #if VDBG
3983     RLOGD("getSignalStrength_1_4: serial %d", serial);
3984 #endif
3985     dispatchVoid(serial, mSlotId, RIL_REQUEST_SIGNAL_STRENGTH);
3986     return Void();
3987 }
3988 
getSignalStrength_1_6(int32_t serial)3989 Return<void> RadioImpl_1_6::getSignalStrength_1_6(int32_t serial) {
3990 #if VDBG
3991     RLOGD("getSignalStrength_1_6: serial %d", serial);
3992 #endif
3993     dispatchVoid(serial, mSlotId, RIL_REQUEST_SIGNAL_STRENGTH);
3994     return Void();
3995 }
3996 
3997 // Methods from ::android::hardware::radio::V1_5::IRadio follow.
setSignalStrengthReportingCriteria_1_5(int32_t serial,const V1_5::SignalThresholdInfo & signalThresholdInfo,V1_5::AccessNetwork accessNetwork)3998 Return<void> RadioImpl_1_6::setSignalStrengthReportingCriteria_1_5(int32_t serial,
3999         const V1_5::SignalThresholdInfo& signalThresholdInfo,
4000         V1_5::AccessNetwork accessNetwork) {
4001 #if VDBG
4002     RLOGD("setSignalStrengthReportingCriteria_1_5: %d", serial);
4003 #endif
4004 
4005     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4006             RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA);
4007     if (pRI == NULL) {
4008         return Void();
4009     }
4010 
4011     if (signalThresholdInfo.hysteresisDb >= 10) {  // TODO: for vts. hysteresisDb range not checked
4012         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4013         return Void();
4014     }
4015 
4016     RIL_SignalStrengthReportingCriteria_v1_5 *criteria = (RIL_SignalStrengthReportingCriteria_v1_5 *)
4017             calloc(1, sizeof(RIL_SignalStrengthReportingCriteria_v1_5));
4018     if (criteria == NULL) {
4019         RLOGE("Memory allocation failed for request %s",
4020                 requestToString(pRI->pCI->requestNumber));
4021         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
4022         return Void();
4023     }
4024 
4025     criteria->signalMeasurement = (SignalMeasurementType)signalThresholdInfo.signalMeasurement;
4026     criteria->isEnabled = signalThresholdInfo.isEnabled;
4027     criteria->hysteresisMs = signalThresholdInfo.hysteresisMs;
4028     criteria->hysteresisDb = signalThresholdInfo.hysteresisDb;
4029     criteria->thresholdsDbmNumber = signalThresholdInfo.thresholds.size();
4030     criteria->thresholdsDbm = new int32_t[criteria->thresholdsDbmNumber];
4031     memcpy(criteria->thresholdsDbm, signalThresholdInfo.thresholds.data(),
4032             criteria->thresholdsDbmNumber * sizeof(int32_t));
4033     criteria->accessNetwork = (RIL_RadioAccessNetworks_v1_5)accessNetwork;
4034 
4035     CALL_ONREQUEST(pRI->pCI->requestNumber, criteria,
4036             sizeof(RIL_SignalStrengthReportingCriteria_v1_5), pRI, mSlotId);
4037 
4038     return Void();
4039 }
4040 
setLinkCapacityReportingCriteria_1_5(int32_t serial,int32_t hysteresisMs,int32_t hysteresisDlKbps,int32_t hysteresisUlKbps,const hidl_vec<int32_t> & thresholdsDownlinkKbps,const hidl_vec<int32_t> & thresholdsUplinkKbps,V1_5::AccessNetwork accessNetwork)4041 Return<void> RadioImpl_1_6::setLinkCapacityReportingCriteria_1_5(int32_t serial,
4042     int32_t hysteresisMs, int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
4043      const hidl_vec<int32_t>& thresholdsDownlinkKbps,
4044      const hidl_vec<int32_t>& thresholdsUplinkKbps,
4045      V1_5::AccessNetwork accessNetwork) {
4046 #if VDBG
4047  RLOGD("setLinkCapacityReportingCriteria_1_5: %d", serial);
4048 #endif
4049 
4050      RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4051              RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA);
4052      if (pRI == NULL) {
4053          return Void();
4054      }
4055      // TODO: for vts. hysteresisDlKbps and hysteresisUlKbps range not confirmed
4056      if (hysteresisDlKbps >= 5000 || hysteresisUlKbps >= 1000) {
4057          sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4058          return Void();
4059      }
4060 
4061      RIL_LinkCapacityReportingCriteria *criteria = (RIL_LinkCapacityReportingCriteria *)
4062              calloc(1, sizeof(RIL_LinkCapacityReportingCriteria));
4063      if (criteria == NULL) {
4064          RLOGE("Memory allocation failed for request %s",
4065                  requestToString(pRI->pCI->requestNumber));
4066          sendErrorResponse(pRI, RIL_E_NO_MEMORY);
4067          return Void();
4068      }
4069 
4070      criteria->hysteresisMs = hysteresisMs;
4071      criteria->hysteresisDlKbps = hysteresisDlKbps;
4072      criteria->hysteresisUlKbps = hysteresisUlKbps;
4073      criteria->thresholdsDownlinkKbpsLength = thresholdsDownlinkKbps.size();
4074      criteria->thresholdsUplinkKbpsLength = thresholdsUplinkKbps.size();
4075      criteria->thresholdsDownlinkKbps = new int32_t[criteria->thresholdsDownlinkKbpsLength];
4076      criteria->thresholdsUplinkKbps = new int32_t[criteria->thresholdsUplinkKbpsLength];
4077      memcpy(criteria->thresholdsDownlinkKbps, thresholdsDownlinkKbps.data(),
4078              criteria->thresholdsDownlinkKbpsLength * sizeof(int32_t));
4079      memcpy(criteria->thresholdsUplinkKbps, thresholdsUplinkKbps.data(),
4080              criteria->thresholdsUplinkKbpsLength * sizeof(int32_t));
4081      criteria->accessNetwork = (RIL_RadioAccessNetworks_v1_5)accessNetwork;
4082 
4083      CALL_ONREQUEST(pRI->pCI->requestNumber, criteria,
4084              sizeof(RIL_LinkCapacityReportingCriteria), pRI, pRI->socket_id);
4085 
4086      return Void();
4087 }
4088 
enableUiccApplications(int32_t serial,bool enable)4089 Return<void> RadioImpl_1_6::enableUiccApplications(int32_t serial, bool enable) {
4090 #if VDBG
4091     RLOGD("enableUiccApplications: serial %d enable %d", serial, enable);
4092 #endif
4093     dispatchInts(serial, mSlotId, RIL_REQUEST_ENABLE_UICC_APPLICATIONS, 1, BOOL_TO_INT(enable));
4094     return Void();
4095 }
4096 
setRadioPower_1_5(int32_t serial,bool powerOn,bool forEmergencyCall,bool preferredForEmergencyCall)4097 Return<void> RadioImpl_1_6::setRadioPower_1_5(int32_t serial, bool powerOn, bool forEmergencyCall,
4098                                           bool preferredForEmergencyCall) {
4099 #if VDBG
4100     RLOGD("setRadioPower_1_6: serial %d powerOn %d forEmergency %d preferredForEmergencyCall %d",
4101         serial, powerOn, forEmergencyCall, preferredForEmergencyCall);
4102 #endif
4103     dispatchInts(serial, mSlotId, RIL_REQUEST_RADIO_POWER, 1, BOOL_TO_INT(powerOn));
4104     return Void();
4105 }
4106 
setRadioPower_1_6(int32_t serial,bool powerOn,bool forEmergencyCall,bool preferredForEmergencyCall)4107 Return<void> RadioImpl_1_6::setRadioPower_1_6(int32_t serial, bool powerOn, bool forEmergencyCall,
4108                                           bool preferredForEmergencyCall) {
4109 #if VDBG
4110     RLOGD("setRadioPower_1_6: serial %d powerOn %d forEmergency %d preferredForEmergencyCall %d",
4111         serial, powerOn, forEmergencyCall, preferredForEmergencyCall);
4112 #endif
4113     dispatchInts(serial, mSlotId, RIL_REQUEST_RADIO_POWER, 1, BOOL_TO_INT(powerOn));
4114     return Void();
4115 }
4116 
areUiccApplicationsEnabled(int32_t serial)4117 Return<void> RadioImpl_1_6::areUiccApplicationsEnabled(int32_t serial) {
4118 #if VDBG
4119     RLOGD("areUiccApplicationsEnabled: serial %d", serial);
4120 #endif
4121     dispatchVoid(serial, mSlotId, RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED);
4122     return Void();
4123 }
4124 
getVoiceRegistrationState_1_5(int32_t serial)4125 Return<void> RadioImpl_1_6::getVoiceRegistrationState_1_5(int32_t serial) {
4126 #if VDBG
4127     RLOGD("getVoiceRegistrationState_1_5: serial %d", serial);
4128 #endif
4129     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_REGISTRATION_STATE);
4130     return Void();
4131 }
4132 
getDataRegistrationState_1_5(int32_t serial)4133 Return<void> RadioImpl_1_6::getDataRegistrationState_1_5(int32_t serial) {
4134 #if VDBG
4135     RLOGD("getDataRegistrationState_1_5: serial %d", serial);
4136 #endif
4137     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_REGISTRATION_STATE);
4138     return Void();
4139 }
4140 
getVoiceRegistrationState_1_6(int32_t serial)4141 Return<void> RadioImpl_1_6::getVoiceRegistrationState_1_6(int32_t serial) {
4142 #if VDBG
4143     RLOGD("getVoiceRegistrationState_1_6: serial %d", serial);
4144 #endif
4145     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_REGISTRATION_STATE);
4146     return Void();
4147 }
4148 
getDataRegistrationState_1_6(int32_t serial)4149 Return<void> RadioImpl_1_6::getDataRegistrationState_1_6(int32_t serial) {
4150 #if VDBG
4151     RLOGD("getDataRegistrationState_1_6: serial %d", serial);
4152 #endif
4153     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_REGISTRATION_STATE);
4154     return Void();
4155 }
4156 
setSystemSelectionChannels_1_5(int32_t serial,bool specifyChannels,const hidl_vec<V1_5::RadioAccessSpecifier> & specifiers)4157 Return<void> RadioImpl_1_6::setSystemSelectionChannels_1_5(int32_t serial,
4158         bool specifyChannels, const hidl_vec<V1_5::RadioAccessSpecifier>& specifiers) {
4159 
4160 #if VDBG
4161 RLOGD("setSystemSelectionChannels_1_5: %d", serial);
4162 #endif
4163 
4164     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4165                   RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS);
4166     if (pRI == NULL) {
4167       return Void();
4168     }
4169 
4170     if (specifiers.size() > RIL_RADIO_ACCESS_SPECIFIER_MAX_SIZE) {
4171       sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4172       return Void();
4173     }
4174 
4175     RIL_SystemSelectionChannels_v1_5 *sysSelectionChannels =
4176           (RIL_SystemSelectionChannels_v1_5 *)calloc(1, sizeof(RIL_SystemSelectionChannels_v1_5));
4177     if (sysSelectionChannels == NULL) {
4178       RLOGE("Memory allocation failed for request %s",
4179               requestToString(pRI->pCI->requestNumber));
4180       sendErrorResponse(pRI, RIL_E_NO_MEMORY);
4181       return Void();
4182     }
4183     sysSelectionChannels->specifyChannels = specifyChannels;
4184     sysSelectionChannels->specifiers_length = specifiers.size();
4185     for (size_t i = 0; i < specifiers.size(); ++i) {
4186       const V1_5::RadioAccessSpecifier& ras_from = specifiers[i];
4187       RIL_RadioAccessSpecifier_v1_5 &ras_to = sysSelectionChannels->specifiers[i];
4188 
4189       ras_to.radio_access_network = (RIL_RadioAccessNetworks_v1_5)ras_from.radioAccessNetwork;
4190       ras_to.channels_length = ras_from.channels.size();
4191 
4192       std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
4193       const std::vector<uint32_t> * bands = nullptr;
4194       switch (specifiers[i].radioAccessNetwork) {
4195           case V1_5::RadioAccessNetworks::GERAN:
4196               ras_to.bands_length = ras_from.bands.geranBands().size();
4197               bands = (std::vector<uint32_t> *) &ras_from.bands.geranBands();
4198               break;
4199           case V1_5::RadioAccessNetworks::UTRAN:
4200               ras_to.bands_length = ras_from.bands.utranBands().size();
4201               bands = (std::vector<uint32_t> *) &ras_from.bands.utranBands();
4202               break;
4203           case V1_5::RadioAccessNetworks::EUTRAN:
4204               ras_to.bands_length = ras_from.bands.eutranBands().size();
4205               bands = (std::vector<uint32_t> *) &ras_from.bands.eutranBands();
4206               break;
4207           case V1_5::RadioAccessNetworks::NGRAN:
4208               ras_to.bands_length = ras_from.bands.ngranBands().size();
4209               bands = (std::vector<uint32_t> *) &ras_from.bands.ngranBands();
4210               break;
4211           default: {
4212               sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4213               free(sysSelectionChannels);
4214               return Void();
4215           }
4216       }
4217       // safe to copy to geran_bands because it's a union member
4218       for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4219           ras_to.bands.geran_bands[idx] = (RIL_GeranBands)(*bands)[idx];
4220       }
4221     }
4222 
4223     CALL_ONREQUEST(RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS, sysSelectionChannels,
4224           sizeof(RIL_SystemSelectionChannels_v1_5), pRI, mSlotId);
4225 
4226     return Void();
4227 }
4228 
prepareNetworkScanRequest_1_5(RIL_NetworkScanRequest_v1_5 & scan_request,const V1_5::NetworkScanRequest & request,RequestInfo * pRI)4229 int prepareNetworkScanRequest_1_5(RIL_NetworkScanRequest_v1_5 &scan_request,
4230         const V1_5::NetworkScanRequest& request, RequestInfo *pRI) {
4231     scan_request.type = (RIL_ScanType) request.type;
4232     scan_request.interval = request.interval;
4233     scan_request.specifiers_length = request.specifiers.size();
4234     scan_request.maxSearchTime = request.maxSearchTime;
4235     scan_request.incrementalResults = request.incrementalResults;
4236     scan_request.incrementalResultsPeriodicity = request.incrementalResultsPeriodicity;
4237     scan_request.mccMncsNumbers = request.mccMncs.size();
4238 
4239     int intervalLow = static_cast<int>(V1_2::ScanIntervalRange::MIN);
4240     int intervalHigh = static_cast<int>(V1_2::ScanIntervalRange::MAX);
4241     int maxSearchTimeLow = static_cast<int>(V1_2::MaxSearchTimeRange::MIN);
4242     int maxSearchTimeHigh = static_cast<int>(V1_2::MaxSearchTimeRange::MAX);
4243     int incrementalResultsPeriodicityRangeLow =
4244             static_cast<int>(V1_2::IncrementalResultsPeriodicityRange::MIN);
4245     int incrementalResultsPeriodicityRangeHigh =
4246             static_cast<int>(V1_2::IncrementalResultsPeriodicityRange::MAX);
4247     uint maxSpecifierSize = static_cast<uint>(V1_2::RadioConst::RADIO_ACCESS_SPECIFIER_MAX_SIZE);
4248 
4249     if (request.interval < intervalLow || request.interval > intervalHigh) {
4250         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4251         return -1;
4252     }
4253     // If defined, must fall in correct range.
4254     if (request.maxSearchTime != 0 && (request.maxSearchTime < maxSearchTimeLow
4255             || request.maxSearchTime > maxSearchTimeHigh)) {
4256         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4257         return -1;
4258     }
4259     if (request.maxSearchTime != 0
4260             && (request.incrementalResultsPeriodicity < incrementalResultsPeriodicityRangeLow
4261             || request.incrementalResultsPeriodicity > incrementalResultsPeriodicityRangeHigh
4262             || request.incrementalResultsPeriodicity > request.maxSearchTime)) {
4263         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4264         return -1;
4265     }
4266     if (request.specifiers.size() == 0 || request.specifiers.size() > maxSpecifierSize) {
4267         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4268         return -1;
4269     }
4270 
4271     for (size_t i = 0; i < request.specifiers.size(); ++i) {
4272         if (request.specifiers[i].channels.size() > MAX_CHANNELS) {
4273             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4274             return -1;
4275         }
4276         switch (request.specifiers[i].bands.getDiscriminator()) {
4277             case V1_5::RadioAccessSpecifier::Bands::hidl_discriminator::geranBands:
4278                 if (request.specifiers[i].bands.geranBands().size() > MAX_BANDS) {
4279                   sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4280                   return -1;
4281                 }
4282                 break;
4283             case V1_5::RadioAccessSpecifier::Bands::hidl_discriminator::utranBands:
4284                 if (request.specifiers[i].bands.utranBands().size() > MAX_BANDS) {
4285                   sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4286                   return -1;
4287                 }
4288                 break;
4289             case V1_5::RadioAccessSpecifier::Bands::hidl_discriminator::eutranBands:
4290                 if (request.specifiers[i].bands.eutranBands().size() > MAX_BANDS) {
4291                   sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4292                   return -1;
4293                 }
4294                 break;
4295             case V1_5::RadioAccessSpecifier::Bands::hidl_discriminator::ngranBands:
4296                 if (request.specifiers[i].bands.ngranBands().size() > MAX_BANDS) {
4297                   sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4298                   return -1;
4299                 }
4300                 break;
4301             default:
4302               sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4303               return -1;
4304         }
4305 
4306         if (request.specifiers[i].channels.size() > MAX_CHANNELS) {
4307             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4308             return -1;
4309         }
4310 
4311         const V1_5::RadioAccessSpecifier& ras_from = request.specifiers[i];
4312         RIL_RadioAccessSpecifier_v1_5& ras_to = scan_request.specifiers[i];
4313 
4314         ras_to.radio_access_network = (RIL_RadioAccessNetworks_v1_5) ras_from.radioAccessNetwork;
4315         ras_to.channels_length = ras_from.channels.size();
4316 
4317         std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
4318         switch (request.specifiers[i].radioAccessNetwork) {
4319             case V1_5::RadioAccessNetworks::GERAN: {
4320                 hidl_vec<V1_1::GeranBands> geranBands = ras_from.bands.geranBands();
4321                 ras_to.bands_length = MIN(geranBands.size(), MAX_BANDS);
4322                 // safe to copy to geran_bands because it's a union member
4323                 for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4324                     ras_to.bands.geran_bands[idx] =
4325                             static_cast<RIL_GeranBands>(geranBands[idx]);
4326                 }
4327                 break;
4328             }
4329             case V1_5::RadioAccessNetworks::UTRAN: {
4330                 hidl_vec<V1_5::UtranBands> utranBands = ras_from.bands.utranBands();
4331                 ras_to.bands_length = MIN(utranBands.size(), MAX_BANDS);
4332                 // safe to copy to utran_bands because it's a union member
4333                 for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4334                     ras_to.bands.utran_bands[idx] =
4335                             static_cast<RIL_UtranBands>(utranBands[idx]);
4336                 }
4337                 break;
4338             }
4339             case V1_5::RadioAccessNetworks::EUTRAN: {
4340                 hidl_vec<V1_5::EutranBands> eutranBands = ras_from.bands.eutranBands();
4341                 ras_to.bands_length = MIN(eutranBands.size(), MAX_BANDS);
4342                 // safe to copy to eutran_bands because it's a union member
4343                 for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4344                     ras_to.bands.eutran_bands[idx] =
4345                             static_cast<RIL_EutranBands>(eutranBands[idx]);
4346                 }
4347                 break;
4348             }
4349             case V1_5::RadioAccessNetworks::NGRAN: {
4350                 hidl_vec<V1_5::NgranBands> ngranBands = ras_from.bands.ngranBands();
4351                 ras_to.bands_length = MIN(ngranBands.size(), MAX_BANDS);
4352                 // safe to copy to ngran_bands because it's a union member
4353                 for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4354                     ras_to.bands.ngran_bands[idx] =
4355                             static_cast<RIL_NgranBands>(ngranBands[idx]);
4356                 }
4357                 break;
4358             }
4359             default:
4360                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4361                 return -1;
4362         }
4363     }
4364     if (scan_request.mccMncsNumbers != 0) {
4365         char **pStrings = (char **)calloc(scan_request.mccMncsNumbers, sizeof(char *));
4366         if (pStrings == NULL) {
4367             RLOGE("Memory allocation failed for request %s",
4368                     requestToString(pRI->pCI->requestNumber));
4369             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
4370             return -1;
4371         }
4372         for (size_t i = 0; i < request.mccMncs.size(); ++i) {
4373             if (!copyHidlStringToRil(&pStrings[i], hidl_string(request.mccMncs[i]), pRI)) {
4374                 for (size_t j = 0; j < i; j++) {
4375                     memsetAndFreeStrings(1, pStrings[j]);
4376                 }
4377                 free(pStrings);
4378                 return -1;
4379             }
4380         }
4381         scan_request.mccMncs = pStrings;
4382     }
4383     return 0;
4384 }
4385 
startNetworkScan_1_5(int32_t serial,const::android::hardware::radio::V1_5::NetworkScanRequest & request)4386 Return<void> RadioImpl_1_6::startNetworkScan_1_5(int32_t serial,
4387         const ::android::hardware::radio::V1_5::NetworkScanRequest& request) {
4388 #if VDBG
4389     RLOGD("startNetworkScan_1_6: serial %d", serial);
4390 #endif
4391 
4392     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
4393     if (pRI == NULL) {
4394         return Void();
4395     }
4396 
4397     RIL_NetworkScanRequest_v1_5 scan_request = {};
4398 
4399     if (prepareNetworkScanRequest_1_5(scan_request, request, pRI) < 0) {
4400         return Void();
4401     }
4402 
4403     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
4404             mSlotId);
4405 
4406     return Void();
4407 }
4408 
setupDataCall_1_5(int32_t serial,::android::hardware::radio::V1_5::AccessNetwork,const::android::hardware::radio::V1_5::DataProfileInfo & dataProfileInfo,bool roamingAllowed,::android::hardware::radio::V1_2::DataRequestReason,const hidl_vec<::android::hardware::radio::V1_5::LinkAddress> &,const hidl_vec<hidl_string> &)4409 Return<void> RadioImpl_1_6::setupDataCall_1_5(int32_t serial ,
4410         ::android::hardware::radio::V1_5::AccessNetwork /* accessNetwork */,
4411         const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
4412         bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason /* reason */,
4413         const hidl_vec<::android::hardware::radio::V1_5::LinkAddress>& /* addresses */,
4414         const hidl_vec<hidl_string>& /* dnses */) {
4415 
4416 #if VDBG
4417     RLOGD("setupDataCall_1_5: serial %d", serial);
4418 #endif
4419 
4420     char *mvnoTypeStr = NULL;
4421     if (!convertMvnoTypeToString(MvnoType::IMSI, mvnoTypeStr)) {
4422         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4423                 RIL_REQUEST_SETUP_DATA_CALL);
4424         if (pRI != NULL) {
4425             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4426         }
4427         return Void();
4428     }
4429     dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15,
4430         std::to_string((int) RadioTechnology::UNKNOWN + 2).c_str(),
4431         std::to_string((int) dataProfileInfo.profileId).c_str(),
4432         dataProfileInfo.apn.c_str(),
4433         dataProfileInfo.user.c_str(),
4434         dataProfileInfo.password.c_str(),
4435         std::to_string((int) dataProfileInfo.authType).c_str(),
4436         getProtocolString(dataProfileInfo.protocol),
4437         getProtocolString(dataProfileInfo.roamingProtocol),
4438         std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
4439         std::to_string(dataProfileInfo.bearerBitmap).c_str(),
4440         dataProfileInfo.persistent ? "1" : "0",
4441         std::to_string(dataProfileInfo.mtuV4).c_str(),
4442         std::to_string(dataProfileInfo.mtuV6).c_str(),
4443         mvnoTypeStr,
4444         "302720x94",
4445         roamingAllowed ? "1" : "0");
4446     return Void();
4447 }
4448 
setupDataCall_1_6(int32_t serial,::android::hardware::radio::V1_5::AccessNetwork,const::android::hardware::radio::V1_5::DataProfileInfo & dataProfileInfo,bool roamingAllowed,::android::hardware::radio::V1_2::DataRequestReason,const hidl_vec<::android::hardware::radio::V1_5::LinkAddress> &,const hidl_vec<hidl_string> &,int32_t,const::android::hardware::radio::V1_6::OptionalSliceInfo &,const::android::hardware::radio::V1_6::OptionalTrafficDescriptor & trafficDescriptor,bool matchAllRuleAllowed)4449 Return<void> RadioImpl_1_6::setupDataCall_1_6(
4450         int32_t serial, ::android::hardware::radio::V1_5::AccessNetwork /* accessNetwork */,
4451         const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
4452         bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason /* reason */,
4453         const hidl_vec<::android::hardware::radio::V1_5::LinkAddress>& /* addresses */,
4454         const hidl_vec<hidl_string>& /* dnses */, int32_t /* pduSessionId */,
4455         const ::android::hardware::radio::V1_6::OptionalSliceInfo& /* sliceInfo */,
4456         const ::android::hardware::radio::V1_6::OptionalTrafficDescriptor& trafficDescriptor,
4457         bool matchAllRuleAllowed) {
4458 #if VDBG
4459     RLOGD("setupDataCall_1_6: serial %d", serial);
4460 #endif
4461 
4462     char *mvnoTypeStr = NULL;
4463     if (!convertMvnoTypeToString(MvnoType::IMSI, mvnoTypeStr)) {
4464         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4465                 RIL_REQUEST_SETUP_DATA_CALL);
4466         if (pRI != NULL) {
4467             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4468         }
4469         return Void();
4470     }
4471 
4472     if (trafficDescriptor.getDiscriminator() ==
4473                 V1_6::OptionalTrafficDescriptor::hidl_discriminator::value &&
4474         trafficDescriptor.value().osAppId.getDiscriminator() ==
4475                 V1_6::OptionalOsAppId::hidl_discriminator::value) {
4476         osAppIdVec = trafficDescriptor.value().osAppId.value().osAppId;
4477     } else {
4478         osAppIdVec = {};
4479     }
4480 
4481     dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 16,
4482         std::to_string((int) RadioTechnology::UNKNOWN + 2).c_str(),
4483         std::to_string((int) dataProfileInfo.profileId).c_str(),
4484         dataProfileInfo.apn.c_str(),
4485         dataProfileInfo.user.c_str(),
4486         dataProfileInfo.password.c_str(),
4487         std::to_string((int) dataProfileInfo.authType).c_str(),
4488         getProtocolString(dataProfileInfo.protocol),
4489         getProtocolString(dataProfileInfo.roamingProtocol),
4490         std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
4491         std::to_string(dataProfileInfo.bearerBitmap).c_str(),
4492         dataProfileInfo.persistent ? "1" : "0",
4493         std::to_string(dataProfileInfo.mtuV4).c_str(),
4494         std::to_string(dataProfileInfo.mtuV6).c_str(),
4495         mvnoTypeStr,
4496         "302720x94",
4497         roamingAllowed ? "1" : "0");
4498     return Void();
4499 }
4500 
setInitialAttachApn_1_5(int32_t serial,const::android::hardware::radio::V1_5::DataProfileInfo & dataProfileInfo)4501 Return<void> RadioImpl_1_6::setInitialAttachApn_1_5(int32_t  serial ,
4502         const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo) {
4503     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4504             RIL_REQUEST_SET_INITIAL_ATTACH_APN);
4505     if (pRI == NULL) {
4506         return Void();
4507     }
4508 
4509     RadioResponseInfo responseInfo = {};
4510     populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
4511 
4512     if (radioService[mSlotId]->mRadioResponseV1_5 != NULL) {
4513         Return<void> retStatus =
4514                 radioService[mSlotId]->mRadioResponseV1_5->setInitialAttachApnResponse_1_5(
4515                         responseInfo);
4516     } else if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
4517         Return<void> retStatus
4518                 = radioService[mSlotId]->mRadioResponseV1_4->setInitialAttachApnResponse(responseInfo);
4519         radioService[mSlotId]->checkReturnStatus(retStatus);
4520     } else if (radioService[mSlotId]->mRadioResponse != NULL) {
4521         Return<void> retStatus
4522                 = radioService[mSlotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo);
4523         radioService[mSlotId]->checkReturnStatus(retStatus);
4524     } else {
4525         RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
4526     }
4527 
4528     return Void();
4529 }
4530 
setDataProfile_1_5(int32_t serial,const hidl_vec<::android::hardware::radio::V1_5::DataProfileInfo> &)4531 Return<void> RadioImpl_1_6::setDataProfile_1_5(int32_t  serial ,
4532         const hidl_vec<::android::hardware::radio::V1_5::DataProfileInfo>& /* profiles */) {
4533     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4534             RIL_REQUEST_SET_DATA_PROFILE);
4535     if (pRI == NULL) {
4536         return Void();
4537     }
4538 
4539     RadioResponseInfo responseInfo = {};
4540     populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
4541 
4542     if (radioService[mSlotId]->mRadioResponseV1_5 != NULL) {
4543         Return<void> retStatus =
4544                 radioService[mSlotId]->mRadioResponseV1_5->setDataProfileResponse_1_5(responseInfo);
4545     } else if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
4546         Return<void> retStatus
4547                 = radioService[mSlotId]->mRadioResponseV1_4->setDataProfileResponse(responseInfo);
4548         radioService[mSlotId]->checkReturnStatus(retStatus);
4549     } else if (radioService[mSlotId]->mRadioResponse != NULL) {
4550         Return<void> retStatus
4551                 = radioService[mSlotId]->mRadioResponse->setDataProfileResponse(responseInfo);
4552         radioService[mSlotId]->checkReturnStatus(retStatus);
4553     } else {
4554         RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
4555     }
4556 
4557     return Void();
4558 }
4559 
setIndicationFilter_1_5(int32_t serial,hidl_bitfield<::android::hardware::radio::V1_5::IndicationFilter> indicationFilter)4560 Return<void> RadioImpl_1_6::setIndicationFilter_1_5(
4561         int32_t serial,
4562         hidl_bitfield<::android::hardware::radio::V1_5::IndicationFilter> indicationFilter) {
4563 #if VDBG
4564     RLOGE("setIndicationFilter_1_5: serial %d", serial);
4565 #endif
4566     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, 1, indicationFilter);
4567     return Void();
4568 }
4569 
getBarringInfo(int32_t serial)4570 Return<void> RadioImpl_1_6::getBarringInfo(int32_t serial) {
4571 #if VDBG
4572     RLOGD("getBarringInfo: serial %d", serial);
4573 #endif
4574     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_BARRING_INFO);
4575     return Void();
4576 }
4577 
setNetworkSelectionModeManual_1_5(int32_t serial,const hidl_string & operatorNumeric,V1_5::RadioAccessNetworks ran)4578 Return<void> RadioImpl_1_6::setNetworkSelectionModeManual_1_5(int32_t serial,
4579         const hidl_string& operatorNumeric, V1_5::RadioAccessNetworks ran) {
4580 #if VDBG
4581     RLOGD("setNetworkSelectionModeManual_1_6: serial %d", serial);
4582 #endif
4583     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4584         RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL);
4585     if (pRI == NULL) {
4586         return Void();
4587     }
4588 
4589     RIL_NetworkOperator networkOperator = {};
4590 
4591     networkOperator.act = (RIL_RadioAccessNetworks)ran;
4592     if (!copyHidlStringToRil(&networkOperator.operatorNumeric, operatorNumeric, pRI)) {
4593         return Void();
4594     }
4595     CALL_ONREQUEST(pRI->pCI->requestNumber, &networkOperator,
4596         sizeof(networkOperator), pRI, mSlotId);
4597 
4598     return Void();
4599 }
4600 
sendCdmaSmsExpectMore(int32_t serial,const CdmaSmsMessage & sms)4601 Return<void> RadioImpl_1_6::sendCdmaSmsExpectMore(int32_t serial, const CdmaSmsMessage& sms) {
4602 #if VDBG
4603     RLOGD("sendCdmaSmsExpectMore: serial %d", serial);
4604 #endif
4605     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4606             RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE);
4607     if (pRI == NULL) {
4608         return Void();
4609     }
4610 
4611     RIL_CDMA_SMS_Message rcsm = {};
4612     constructCdmaSms(rcsm, sms);
4613 
4614     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
4615     return Void();
4616 }
4617 
4618 // Methods from ::android::hardware::radio::V1_6::IRadio follow.
sendCdmaSmsExpectMore_1_6(int32_t serial,const CdmaSmsMessage & sms)4619 Return<void> RadioImpl_1_6::sendCdmaSmsExpectMore_1_6(int32_t serial, const CdmaSmsMessage& sms) {
4620 #if VDBG
4621     RLOGD("sendCdmaSmsExpectMore: serial %d", serial);
4622 #endif
4623     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4624             RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE);
4625     if (pRI == NULL) {
4626         return Void();
4627     }
4628 
4629     RIL_CDMA_SMS_Message rcsm = {};
4630     constructCdmaSms(rcsm, sms);
4631 
4632     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
4633     return Void();
4634 }
4635 
supplySimDepersonalization(int32_t serial,V1_5::PersoSubstate persoType,const hidl_string & controlKey)4636 Return<void> RadioImpl_1_6::supplySimDepersonalization(int32_t serial,
4637         V1_5::PersoSubstate persoType, const hidl_string& controlKey) {
4638 #if VDBG
4639     RLOGD("supplySimDepersonalization: serial %d", serial);
4640 #endif
4641     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION, true, 1,
4642             controlKey.c_str());
4643     return Void();
4644 }
4645 
setNrDualConnectivityState(int32_t serial,V1_6::NrDualConnectivityState nrDualConnectivityState)4646 Return<void> RadioImpl_1_6::setNrDualConnectivityState(int32_t serial,
4647         V1_6::NrDualConnectivityState nrDualConnectivityState) {
4648 #if VDBG
4649     RLOGD("setNrDualConnectivityState: serial %d", serial);
4650 #endif
4651     dispatchInts(serial, mSlotId, RIL_REQUEST_ENABLE_NR_DUAL_CONNECTIVITY, 1,
4652             nrDualConnectivityState);
4653     return Void();
4654 }
4655 
isNrDualConnectivityEnabled(int32_t serial)4656 Return<void> RadioImpl_1_6::isNrDualConnectivityEnabled(int32_t serial) {
4657 #if VDBG
4658     RLOGD("isNrDualConnectivityEnabled: serial %d", serial);
4659 #endif
4660     dispatchVoid(serial, mSlotId, RIL_REQUEST_IS_NR_DUAL_CONNECTIVITY_ENABLED);
4661     return Void();
4662 }
4663 
allocatePduSessionId(int32_t serial)4664 Return<void> RadioImpl_1_6::allocatePduSessionId(int32_t serial) {
4665 #if VDBG
4666     RLOGD("allocatePduSessionId: serial %d", serial);
4667 #endif
4668     dispatchVoid(serial, mSlotId, RIL_REQUEST_ALLOCATE_PDU_SESSION_ID);
4669     return Void();
4670 }
4671 
releasePduSessionId(int32_t serial,int32_t id)4672 Return<void> RadioImpl_1_6::releasePduSessionId(int32_t serial, int32_t id) {
4673 #if VDBG
4674     RLOGD("releasePduSessionId: serial %d, pduSessionId: %d", serial, id);
4675 #endif
4676     dispatchVoid(serial, mSlotId, RIL_REQUEST_RELEASE_PDU_SESSION_ID);
4677     return Void();
4678 }
4679 
startHandover(int32_t serial,int32_t callId)4680 Return<void> RadioImpl_1_6::startHandover(int32_t serial, int32_t callId) {
4681 #if VDBG
4682     RLOGD("startHandover: serial %d, callId: %d", serial, callId);
4683 #endif
4684     dispatchVoid(serial, mSlotId, RIL_REQUEST_START_HANDOVER);
4685     return Void();
4686 }
4687 
cancelHandover(int32_t serial,int32_t callId)4688 Return<void> RadioImpl_1_6::cancelHandover(int32_t serial, int32_t callId) {
4689 #if VDBG
4690     RLOGD("cancelHandover: serial %d, callId: %d", serial, callId);
4691 #endif
4692     dispatchVoid(serial, mSlotId, RIL_REQUEST_CANCEL_HANDOVER);
4693     return Void();
4694 }
4695 
4696 
setDataThrottling(int32_t serial,V1_6::DataThrottlingAction dataThrottlingAction,int64_t completionDurationMillis)4697 Return<void> RadioImpl_1_6::setDataThrottling(int32_t serial, V1_6::DataThrottlingAction dataThrottlingAction, int64_t completionDurationMillis) {
4698    #if VDBG
4699        RLOGD("OemHookImpl::sendRequestRaw: serial %d", serial);
4700    #endif
4701        dispatchInts(serial, mSlotId, RIL_REQUEST_SET_DATA_THROTTLING, 2,
4702           dataThrottlingAction, completionDurationMillis);
4703        return Void();
4704 }
4705 
getSystemSelectionChannels(int32_t serial)4706 Return<void> RadioImpl_1_6::getSystemSelectionChannels(int32_t serial) {
4707 #if VDBG
4708     RLOGD("getSystemSelectionChannels: serial %d", serial);
4709 #endif
4710     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS);
4711     return Void();
4712 }
4713 
getSlicingConfig(int32_t serial)4714 Return<void> RadioImpl_1_6::getSlicingConfig(int32_t serial) {
4715 #if VDBG
4716     RLOGD("getSlicingConfig: serial %d", serial);
4717 #endif
4718     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SLICING_CONFIG);
4719     return Void();
4720 }
4721 
setCarrierInfoForImsiEncryption_1_6(int32_t serial,const V1_6::ImsiEncryptionInfo & data)4722 Return<void> RadioImpl_1_6::setCarrierInfoForImsiEncryption_1_6(
4723         int32_t serial, const V1_6::ImsiEncryptionInfo& data) {
4724 #if VDBG
4725     RLOGD("setCarrierInfoForImsiEncryption_1_6: serial %d", serial);
4726 #endif
4727     RequestInfo* pRI = android::addRequestToList(serial, mSlotId,
4728                                                  RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION);
4729     if (pRI == NULL) {
4730         return Void();
4731     }
4732 
4733     RIL_CarrierInfoForImsiEncryption_v16 imsiEncryption = {};
4734 
4735     if (!copyHidlStringToRil(&imsiEncryption.mnc, data.base.mnc, pRI)) {
4736         return Void();
4737     }
4738     if (!copyHidlStringToRil(&imsiEncryption.mcc, data.base.mcc, pRI)) {
4739         memsetAndFreeStrings(1, imsiEncryption.mnc);
4740         return Void();
4741     }
4742     if (!copyHidlStringToRil(&imsiEncryption.keyIdentifier, data.base.keyIdentifier, pRI)) {
4743         memsetAndFreeStrings(2, imsiEncryption.mnc, imsiEncryption.mcc);
4744         return Void();
4745     }
4746     imsiEncryption.carrierKeyLength = data.base.carrierKey.size();
4747     imsiEncryption.carrierKey = new uint8_t[imsiEncryption.carrierKeyLength];
4748     memcpy(imsiEncryption.carrierKey, data.base.carrierKey.data(), imsiEncryption.carrierKeyLength);
4749     imsiEncryption.expirationTime = data.base.expirationTime;
4750     imsiEncryption.keyType = (RIL_PublicKeyType)data.keyType;
4751 
4752     CALL_ONREQUEST(pRI->pCI->requestNumber, &imsiEncryption,
4753                    sizeof(RIL_CarrierInfoForImsiEncryption_v16), pRI, mSlotId);
4754     delete (imsiEncryption.carrierKey);
4755     return Void();
4756 }
4757 
4758 
getSimPhonebookRecords(int32_t serial)4759 Return<void> RadioImpl_1_6::getSimPhonebookRecords(int32_t serial) {
4760 #if VDBG
4761     RLOGD("getSimPhonebookRecords: serial %d", serial);
4762 #endif
4763     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS);
4764     return Void();
4765 }
4766 
getSimPhonebookCapacity(int32_t serial)4767 Return<void> RadioImpl_1_6::getSimPhonebookCapacity(int32_t serial) {
4768 #if VDBG
4769     RLOGD("getSimPhonebookCapacity: serial %d", serial);
4770 #endif
4771     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY);
4772     return Void();
4773 }
4774 
updateSimPhonebookRecords(int32_t serial,const::android::hardware::radio::V1_6::PhonebookRecordInfo & recordInfo)4775 Return<void> RadioImpl_1_6::updateSimPhonebookRecords(
4776     int32_t serial,
4777     const ::android::hardware::radio::V1_6::PhonebookRecordInfo& recordInfo) {
4778 #if VDBG
4779     RLOGD("updateSimPhonebookRecords: serial %d", serial);
4780 #endif
4781     dispatchVoid(serial, mSlotId, RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORDS);
4782     return Void();
4783 }
4784 
4785 
4786 // OEM hook methods:
setResponseFunctions(const::android::sp<IOemHookResponse> & oemHookResponseParam,const::android::sp<IOemHookIndication> & oemHookIndicationParam)4787 Return<void> OemHookImpl::setResponseFunctions(
4788         const ::android::sp<IOemHookResponse>& oemHookResponseParam,
4789         const ::android::sp<IOemHookIndication>& oemHookIndicationParam) {
4790 #if VDBG
4791     RLOGD("OemHookImpl::setResponseFunctions");
4792 #endif
4793 
4794     pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(mSlotId);
4795     int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
4796     CHECK_EQ(ret, 0);
4797 
4798     mOemHookResponse = oemHookResponseParam;
4799     mOemHookIndication = oemHookIndicationParam;
4800     mCounterOemHook[mSlotId]++;
4801 
4802     ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
4803     CHECK_EQ(ret, 0);
4804 
4805     return Void();
4806 }
4807 
sendRequestRaw(int32_t serial,const hidl_vec<uint8_t> & data)4808 Return<void> OemHookImpl::sendRequestRaw(int32_t serial, const hidl_vec<uint8_t>& data) {
4809 #if VDBG
4810     RLOGD("OemHookImpl::sendRequestRaw: serial %d", serial);
4811 #endif
4812     dispatchRaw(serial, mSlotId, RIL_REQUEST_OEM_HOOK_RAW, data);
4813     return Void();
4814 }
4815 
sendRequestStrings(int32_t serial,const hidl_vec<hidl_string> & data)4816 Return<void> OemHookImpl::sendRequestStrings(int32_t serial,
4817         const hidl_vec<hidl_string>& data) {
4818 #if VDBG
4819     RLOGD("OemHookImpl::sendRequestStrings: serial %d", serial);
4820 #endif
4821     dispatchStrings(serial, mSlotId, RIL_REQUEST_OEM_HOOK_STRINGS, data);
4822     return Void();
4823 }
4824 
4825 /***************************************************************************************************
4826  * RESPONSE FUNCTIONS
4827  * Functions above are used for requests going from framework to vendor code. The ones below are
4828  * responses for those requests coming back from the vendor code.
4829  **************************************************************************************************/
4830 
acknowledgeRequest(int slotId,int serial)4831 void radio_1_6::acknowledgeRequest(int slotId, int serial) {
4832     if (radioService[slotId]->mRadioResponse != NULL) {
4833         Return<void> retStatus = radioService[slotId]->mRadioResponse->acknowledgeRequest(serial);
4834         radioService[slotId]->checkReturnStatus(retStatus);
4835     } else {
4836         RLOGE("acknowledgeRequest: radioService[%d]->mRadioResponse == NULL", slotId);
4837     }
4838 }
4839 
populateResponseInfo(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e)4840 void populateResponseInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
4841                          RIL_Errno e) {
4842     responseInfo.serial = serial;
4843     switch (responseType) {
4844         case RESPONSE_SOLICITED:
4845             responseInfo.type = RadioResponseType::SOLICITED;
4846             break;
4847         case RESPONSE_SOLICITED_ACK_EXP:
4848             responseInfo.type = RadioResponseType::SOLICITED_ACK_EXP;
4849             break;
4850     }
4851     responseInfo.error = (RadioError) e;
4852 }
4853 
populateResponseInfo_1_6(::android::hardware::radio::V1_6::RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e)4854 void populateResponseInfo_1_6(
4855     ::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo,
4856     int serial, int responseType, RIL_Errno e) {
4857   responseInfo.serial = serial;
4858   switch (responseType) {
4859     case RESPONSE_SOLICITED:
4860       responseInfo.type = RadioResponseType::SOLICITED;
4861       break;
4862     case RESPONSE_SOLICITED_ACK_EXP:
4863       responseInfo.type = RadioResponseType::SOLICITED_ACK_EXP;
4864       break;
4865   }
4866   responseInfo.error = (::android::hardware::radio::V1_6::RadioError)e;
4867 }
4868 
responseIntOrEmpty(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)4869 int responseIntOrEmpty(RadioResponseInfo& responseInfo, int serial, int responseType, RIL_Errno e,
4870                void *response, size_t responseLen) {
4871     populateResponseInfo(responseInfo, serial, responseType, e);
4872     int ret = -1;
4873 
4874     if (response == NULL && responseLen == 0) {
4875         // Earlier RILs did not send a response for some cases although the interface
4876         // expected an integer as response. Do not return error if response is empty. Instead
4877         // Return -1 in those cases to maintain backward compatibility.
4878     } else if (response == NULL || responseLen != sizeof(int)) {
4879         RLOGE("responseIntOrEmpty: Invalid response");
4880         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
4881     } else {
4882         int *p_int = (int *) response;
4883         ret = p_int[0];
4884     }
4885     return ret;
4886 }
4887 
responseInt(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)4888 int responseInt(RadioResponseInfo& responseInfo, int serial, int responseType, RIL_Errno e,
4889                void *response, size_t responseLen) {
4890     populateResponseInfo(responseInfo, serial, responseType, e);
4891     int ret = -1;
4892 
4893     if (response == NULL || responseLen != sizeof(int)) {
4894         RLOGE("responseInt: Invalid response");
4895         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
4896     } else {
4897         int *p_int = (int *) response;
4898         ret = p_int[0];
4899     }
4900     return ret;
4901 }
4902 
responseInt_1_6(::android::hardware::radio::V1_6::RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)4903 int responseInt_1_6(::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo, int serial, int responseType, RIL_Errno e,
4904                void *response, size_t responseLen) {
4905     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
4906     int ret = -1;
4907 
4908     if (response == NULL || responseLen != sizeof(int)) {
4909         RLOGE("responseInt_1_6: Invalid response");
4910         if (e == RIL_E_SUCCESS) responseInfo.error = ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
4911     } else {
4912         int *p_int = (int *) response;
4913         ret = p_int[0];
4914     }
4915     return ret;
4916 }
4917 
getIccCardStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)4918 int radio_1_6::getIccCardStatusResponse(int slotId,
4919                                    int responseType, int serial, RIL_Errno e,
4920                                    void *response, size_t responseLen) {
4921 #if VDBG
4922     RLOGD("getIccCardStatusResponse: serial %d", serial);
4923 #endif
4924     if (radioService[slotId]->mRadioResponseV1_5 != NULL
4925         || radioService[slotId]->mRadioResponseV1_4 != NULL
4926         || radioService[slotId]->mRadioResponseV1_2 != NULL
4927         || radioService[slotId]->mRadioResponse != NULL) {
4928         RadioResponseInfo responseInfo = {};
4929         populateResponseInfo(responseInfo, serial, responseType, e);
4930         CardStatus cardStatus = {CardState::ABSENT, PinState::UNKNOWN, -1, -1, -1, {}};
4931         RIL_AppStatus *rilAppStatus = NULL;
4932         RIL_CardStatus_v1_5 *p_cur = ((RIL_CardStatus_v1_5 *) response);
4933         if (response == NULL || responseLen != sizeof(RIL_CardStatus_v1_5)
4934                 || p_cur->base.base.base.gsm_umts_subscription_app_index >= p_cur->base.base.base.num_applications
4935                 || p_cur->base.base.base.cdma_subscription_app_index >= p_cur->base.base.base.num_applications
4936                 || p_cur->base.base.base.ims_subscription_app_index >= p_cur->base.base.base.num_applications) {
4937             RLOGE("getIccCardStatusResponse: Invalid response");
4938             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
4939         } else {
4940             cardStatus.cardState = (CardState) p_cur->base.base.base.card_state;
4941             cardStatus.universalPinState = (PinState) p_cur->base.base.base.universal_pin_state;
4942             cardStatus.gsmUmtsSubscriptionAppIndex = p_cur->base.base.base.gsm_umts_subscription_app_index;
4943             cardStatus.cdmaSubscriptionAppIndex = p_cur->base.base.base.cdma_subscription_app_index;
4944             cardStatus.imsSubscriptionAppIndex = p_cur->base.base.base.ims_subscription_app_index;
4945             rilAppStatus = p_cur->base.base.base.applications;
4946             cardStatus.applications.resize(p_cur->base.base.base.num_applications);
4947             AppStatus *appStatus = cardStatus.applications.data();
4948 #if VDBG
4949             RLOGD("getIccCardStatusResponse: num_applications %d", p_cur->base.base.base.num_applications);
4950 #endif
4951             for (int i = 0; i < p_cur->base.base.base.num_applications; i++) {
4952                 appStatus[i].appType = (AppType) rilAppStatus[i].app_type;
4953                 appStatus[i].appState = (AppState) rilAppStatus[i].app_state;
4954                 appStatus[i].persoSubstate = (PersoSubstate) rilAppStatus[i].perso_substate;
4955                 appStatus[i].aidPtr = convertCharPtrToHidlString(rilAppStatus[i].aid_ptr);
4956                 appStatus[i].appLabelPtr = convertCharPtrToHidlString(
4957                         rilAppStatus[i].app_label_ptr);
4958                 appStatus[i].pin1Replaced = rilAppStatus[i].pin1_replaced;
4959                 appStatus[i].pin1 = (PinState) rilAppStatus[i].pin1;
4960                 appStatus[i].pin2 = (PinState) rilAppStatus[i].pin2;
4961             }
4962         }
4963         if (p_cur && radioService[slotId]->mRadioResponseV1_5 != NULL) {
4964             ::android::hardware::radio::V1_2::CardStatus cardStatusV1_2;
4965             ::android::hardware::radio::V1_4::CardStatus cardStatusV1_4;
4966             ::android::hardware::radio::V1_5::CardStatus cardStatusV1_5;
4967             cardStatusV1_2.base = cardStatus;
4968             cardStatusV1_2.physicalSlotId = -1;
4969             cardStatusV1_2.iccid = convertCharPtrToHidlString(p_cur->base.base.iccid);
4970             cardStatusV1_4.base = cardStatusV1_2;
4971             cardStatusV1_5.base = cardStatusV1_4;
4972             cardStatusV1_5.applications.resize(p_cur->base.base.base.num_applications);
4973             for (int i = 0; i < p_cur->base.base.base.num_applications; i++) {
4974                 cardStatusV1_5.applications[i].base.appType = (AppType) rilAppStatus[i].app_type;
4975                 cardStatusV1_5.applications[i].base.appState = (AppState) rilAppStatus[i].app_state;
4976                 cardStatusV1_5.applications[i].base.persoSubstate = (PersoSubstate) rilAppStatus[i].perso_substate;
4977                 cardStatusV1_5.applications[i].base.aidPtr = convertCharPtrToHidlString(rilAppStatus[i].aid_ptr);
4978                 cardStatusV1_5.applications[i].base.appLabelPtr = convertCharPtrToHidlString(
4979                         rilAppStatus[i].app_label_ptr);
4980                 cardStatusV1_5.applications[i].base.pin1Replaced = rilAppStatus[i].pin1_replaced;
4981                 cardStatusV1_5.applications[i].base.pin1 = (PinState) rilAppStatus[i].pin1;
4982                 cardStatusV1_5.applications[i].base.pin2 = (PinState) rilAppStatus[i].pin2;
4983                 cardStatusV1_5.applications[i].persoSubstate = (V1_5::PersoSubstate)rilAppStatus[i].perso_substate;
4984             }
4985 
4986             // If POWER_DOWN then set applications to empty
4987             if (radioService[slotId]->mSimCardPowerState == V1_1::CardPowerState::POWER_DOWN) {
4988                 RLOGD("getIccCardStatusResponse: state is POWER_DOWN so clearing apps");
4989                 cardStatusV1_5.applications = {};
4990             }
4991             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5->
4992                     getIccCardStatusResponse_1_5(responseInfo, cardStatusV1_5);
4993             radioService[slotId]->checkReturnStatus(retStatus);
4994         } else if (p_cur && radioService[slotId]->mRadioResponseV1_4 != NULL) {
4995             ::android::hardware::radio::V1_2::CardStatus cardStatusV1_2;
4996             ::android::hardware::radio::V1_4::CardStatus cardStatusV1_4;
4997             cardStatusV1_2.base = cardStatus;
4998             cardStatusV1_2.physicalSlotId = -1;
4999             cardStatusV1_2.iccid = convertCharPtrToHidlString(p_cur->base.base.iccid);
5000             cardStatusV1_4.base = cardStatusV1_2;
5001             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4->
5002                     getIccCardStatusResponse_1_4(responseInfo, cardStatusV1_4);
5003             radioService[slotId]->checkReturnStatus(retStatus);
5004         } else if (p_cur && radioService[slotId]->mRadioResponseV1_3 != NULL) {
5005             ::android::hardware::radio::V1_2::CardStatus cardStatusV1_2;
5006             cardStatusV1_2.base = cardStatus;
5007             cardStatusV1_2.physicalSlotId = -1;
5008             cardStatusV1_2.iccid = convertCharPtrToHidlString(p_cur->base.base.iccid);
5009             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_3->
5010                     getIccCardStatusResponse_1_2(responseInfo, cardStatusV1_2);
5011             radioService[slotId]->checkReturnStatus(retStatus);
5012         } else if (p_cur && radioService[slotId]->mRadioResponseV1_2 != NULL) {
5013             ::android::hardware::radio::V1_2::CardStatus cardStatusV1_2;
5014             cardStatusV1_2.base = cardStatus;
5015             cardStatusV1_2.physicalSlotId = -1;
5016             cardStatusV1_2.iccid = convertCharPtrToHidlString(p_cur->base.base.iccid);
5017             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2->
5018                     getIccCardStatusResponse_1_2(responseInfo, cardStatusV1_2);
5019             radioService[slotId]->checkReturnStatus(retStatus);
5020             // TODO: add 1.1 if needed.
5021         } else {
5022             Return<void> retStatus = radioService[slotId]->mRadioResponse->
5023                     getIccCardStatusResponse(responseInfo, cardStatus);
5024             radioService[slotId]->checkReturnStatus(retStatus);
5025         }
5026     } else {
5027         RLOGE("getIccCardStatusResponse: radioService[%d]->mRadioResponse == NULL", slotId);
5028     }
5029     return 0;
5030 }
5031 
supplyIccPinForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5032 int radio_1_6::supplyIccPinForAppResponse(int slotId,
5033                                      int responseType, int serial, RIL_Errno e,
5034                                      void *response, size_t responseLen) {
5035 #if VDBG
5036     RLOGD("supplyIccPinForAppResponse: serial %d", serial);
5037 #endif
5038 
5039     if (radioService[slotId]->mRadioResponse != NULL) {
5040         RadioResponseInfo responseInfo = {};
5041         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5042         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5043                 supplyIccPinForAppResponse(responseInfo, ret);
5044         RLOGE("supplyIccPinForAppResponse: amit ret %d", ret);
5045         radioService[slotId]->checkReturnStatus(retStatus);
5046     } else {
5047         RLOGE("supplyIccPinForAppResponse: radioService[%d]->mRadioResponse == NULL",
5048                 slotId);
5049     }
5050 
5051     return 0;
5052 }
5053 
supplyIccPukForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5054 int radio_1_6::supplyIccPukForAppResponse(int slotId,
5055                                      int responseType, int serial, RIL_Errno e,
5056                                      void *response, size_t responseLen) {
5057 #if VDBG
5058     RLOGD("supplyIccPukForAppResponse: serial %d", serial);
5059 #endif
5060 
5061     if (radioService[slotId]->mRadioResponse != NULL) {
5062         RadioResponseInfo responseInfo = {};
5063         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5064         Return<void> retStatus = radioService[slotId]->mRadioResponse->supplyIccPukForAppResponse(
5065                 responseInfo, ret);
5066         radioService[slotId]->checkReturnStatus(retStatus);
5067     } else {
5068         RLOGE("supplyIccPukForAppResponse: radioService[%d]->mRadioResponse == NULL",
5069                 slotId);
5070     }
5071 
5072     return 0;
5073 }
5074 
supplyIccPin2ForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5075 int radio_1_6::supplyIccPin2ForAppResponse(int slotId,
5076                                       int responseType, int serial, RIL_Errno e,
5077                                       void *response, size_t responseLen) {
5078 #if VDBG
5079     RLOGD("supplyIccPin2ForAppResponse: serial %d", serial);
5080 #endif
5081 
5082     if (radioService[slotId]->mRadioResponse != NULL) {
5083         RadioResponseInfo responseInfo = {};
5084         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5085         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5086                 supplyIccPin2ForAppResponse(responseInfo, ret);
5087         radioService[slotId]->checkReturnStatus(retStatus);
5088     } else {
5089         RLOGE("supplyIccPin2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
5090                 slotId);
5091     }
5092 
5093     return 0;
5094 }
5095 
supplyIccPuk2ForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5096 int radio_1_6::supplyIccPuk2ForAppResponse(int slotId,
5097                                       int responseType, int serial, RIL_Errno e,
5098                                       void *response, size_t responseLen) {
5099 #if VDBG
5100     RLOGD("supplyIccPuk2ForAppResponse: serial %d", serial);
5101 #endif
5102 
5103     if (radioService[slotId]->mRadioResponse != NULL) {
5104         RadioResponseInfo responseInfo = {};
5105         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5106         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5107                 supplyIccPuk2ForAppResponse(responseInfo, ret);
5108         radioService[slotId]->checkReturnStatus(retStatus);
5109     } else {
5110         RLOGE("supplyIccPuk2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
5111                 slotId);
5112     }
5113 
5114     return 0;
5115 }
5116 
changeIccPinForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5117 int radio_1_6::changeIccPinForAppResponse(int slotId,
5118                                      int responseType, int serial, RIL_Errno e,
5119                                      void *response, size_t responseLen) {
5120 #if VDBG
5121     RLOGD("changeIccPinForAppResponse: serial %d", serial);
5122 #endif
5123 
5124     if (radioService[slotId]->mRadioResponse != NULL) {
5125         RadioResponseInfo responseInfo = {};
5126         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5127         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5128                 changeIccPinForAppResponse(responseInfo, ret);
5129         radioService[slotId]->checkReturnStatus(retStatus);
5130     } else {
5131         RLOGE("changeIccPinForAppResponse: radioService[%d]->mRadioResponse == NULL",
5132                 slotId);
5133     }
5134 
5135     return 0;
5136 }
5137 
changeIccPin2ForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5138 int radio_1_6::changeIccPin2ForAppResponse(int slotId,
5139                                       int responseType, int serial, RIL_Errno e,
5140                                       void *response, size_t responseLen) {
5141 #if VDBG
5142     RLOGD("changeIccPin2ForAppResponse: serial %d", serial);
5143 #endif
5144 
5145     if (radioService[slotId]->mRadioResponse != NULL) {
5146         RadioResponseInfo responseInfo = {};
5147         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5148         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5149                 changeIccPin2ForAppResponse(responseInfo, ret);
5150         radioService[slotId]->checkReturnStatus(retStatus);
5151     } else {
5152         RLOGE("changeIccPin2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
5153                 slotId);
5154     }
5155 
5156     return 0;
5157 }
5158 
supplyNetworkDepersonalizationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5159 int radio_1_6::supplyNetworkDepersonalizationResponse(int slotId,
5160                                                  int responseType, int serial, RIL_Errno e,
5161                                                  void *response, size_t responseLen) {
5162 #if VDBG
5163     RLOGD("supplyNetworkDepersonalizationResponse: serial %d", serial);
5164 #endif
5165 
5166     if (radioService[slotId]->mRadioResponse != NULL) {
5167         RadioResponseInfo responseInfo = {};
5168         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5169         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5170                 supplyNetworkDepersonalizationResponse(responseInfo, ret);
5171         radioService[slotId]->checkReturnStatus(retStatus);
5172     } else {
5173         RLOGE("supplyNetworkDepersonalizationResponse: radioService[%d]->mRadioResponse == "
5174                 "NULL", slotId);
5175     }
5176 
5177     return 0;
5178 }
5179 
getCurrentCallsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5180 int radio_1_6::getCurrentCallsResponse(int slotId, int responseType, int serial, RIL_Errno e,
5181                                        void* response, size_t responseLen) {
5182 #if VDBG
5183     RLOGD("getCurrentCallsResponse: serial %d", serial);
5184 #endif
5185 
5186     if (radioService[slotId]->mRadioResponseV1_6 != NULL ||
5187         radioService[slotId]->mRadioResponseV1_2 != NULL ||
5188         radioService[slotId]->mRadioResponse != NULL) {
5189         V1_6::RadioResponseInfo responseInfo16 = {};
5190         RadioResponseInfo responseInfo = {};
5191         if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
5192             populateResponseInfo_1_6(responseInfo16, serial, responseType, e);
5193         } else {
5194             populateResponseInfo(responseInfo, serial, responseType, e);
5195         }
5196         if ((response == NULL && responseLen != 0) || (responseLen % sizeof(RIL_Call*)) != 0) {
5197             RLOGE("getCurrentCallsResponse: Invalid response");
5198             if (e == RIL_E_SUCCESS) {
5199                 responseInfo16.error = V1_6::RadioError::INVALID_RESPONSE;
5200                 responseInfo.error = RadioError::INVALID_RESPONSE;
5201             }
5202             return 0;
5203         } else {
5204             Return<void> retStatus;
5205             if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
5206                 hidl_vec<V1_6::Call> calls;
5207                 int num = responseLen / sizeof(RIL_Call*);
5208                 calls.resize(num);
5209 
5210                 for (int i = 0; i < num; i++) {
5211                     RIL_Call* p_cur = ((RIL_Call**)response)[i];
5212                     /* each call info */
5213                     calls[i].base.base.state = (CallState)p_cur->state;
5214                     calls[i].base.base.index = p_cur->index;
5215                     calls[i].base.base.toa = p_cur->toa;
5216                     calls[i].base.base.isMpty = p_cur->isMpty;
5217                     calls[i].base.base.isMT = p_cur->isMT;
5218                     calls[i].base.base.als = p_cur->als;
5219                     calls[i].base.base.isVoice = p_cur->isVoice;
5220                     calls[i].base.base.isVoicePrivacy = p_cur->isVoicePrivacy;
5221                     calls[i].base.base.number = convertCharPtrToHidlString(p_cur->number);
5222                     calls[i].base.base.numberPresentation =
5223                             (CallPresentation)p_cur->numberPresentation;
5224                     calls[i].base.base.name = convertCharPtrToHidlString(p_cur->name);
5225                     calls[i].base.base.namePresentation = (CallPresentation)p_cur->namePresentation;
5226                     if (p_cur->uusInfo != NULL && p_cur->uusInfo->uusData != NULL) {
5227                         RIL_UUS_Info* uusInfo = p_cur->uusInfo;
5228                         calls[i].base.base.uusInfo.resize(1);
5229                         calls[i].base.base.uusInfo[0].uusType = (UusType)uusInfo->uusType;
5230                         calls[i].base.base.uusInfo[0].uusDcs = (UusDcs)uusInfo->uusDcs;
5231                         // convert uusInfo->uusData to a null-terminated string
5232                         char* nullTermStr = strndup(uusInfo->uusData, uusInfo->uusLength);
5233                         calls[i].base.base.uusInfo[0].uusData = nullTermStr;
5234                         free(nullTermStr);
5235                     }
5236                 }
5237                 retStatus = radioService[slotId]->mRadioResponseV1_6->getCurrentCallsResponse_1_6(
5238                         responseInfo16, calls);
5239             } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
5240                 hidl_vec<V1_2::Call> calls;
5241                 int num = responseLen / sizeof(RIL_Call*);
5242                 calls.resize(num);
5243 
5244                 for (int i = 0; i < num; i++) {
5245                     RIL_Call* p_cur = ((RIL_Call**)response)[i];
5246                     /* each call info */
5247                     calls[i].base.state = (CallState)p_cur->state;
5248                     calls[i].base.index = p_cur->index;
5249                     calls[i].base.toa = p_cur->toa;
5250                     calls[i].base.isMpty = p_cur->isMpty;
5251                     calls[i].base.isMT = p_cur->isMT;
5252                     calls[i].base.als = p_cur->als;
5253                     calls[i].base.isVoice = p_cur->isVoice;
5254                     calls[i].base.isVoicePrivacy = p_cur->isVoicePrivacy;
5255                     calls[i].base.number = convertCharPtrToHidlString(p_cur->number);
5256                     calls[i].base.numberPresentation = (CallPresentation)p_cur->numberPresentation;
5257                     calls[i].base.name = convertCharPtrToHidlString(p_cur->name);
5258                     calls[i].base.namePresentation = (CallPresentation)p_cur->namePresentation;
5259                     if (p_cur->uusInfo != NULL && p_cur->uusInfo->uusData != NULL) {
5260                         RIL_UUS_Info* uusInfo = p_cur->uusInfo;
5261                         calls[i].base.uusInfo.resize(1);
5262                         calls[i].base.uusInfo[0].uusType = (UusType)uusInfo->uusType;
5263                         calls[i].base.uusInfo[0].uusDcs = (UusDcs)uusInfo->uusDcs;
5264                         // convert uusInfo->uusData to a null-terminated string
5265                         char* nullTermStr = strndup(uusInfo->uusData, uusInfo->uusLength);
5266                         calls[i].base.uusInfo[0].uusData = nullTermStr;
5267                         free(nullTermStr);
5268                     }
5269                 }
5270                 retStatus = radioService[slotId]->mRadioResponseV1_2->getCurrentCallsResponse_1_2(
5271                         responseInfo, calls);
5272             } else {
5273                 hidl_vec<Call> calls;
5274                 int num = responseLen / sizeof(RIL_Call*);
5275                 calls.resize(num);
5276 
5277                 for (int i = 0; i < num; i++) {
5278                     RIL_Call* p_cur = ((RIL_Call**)response)[i];
5279                     /* each call info */
5280                     calls[i].state = (CallState)p_cur->state;
5281                     calls[i].index = p_cur->index;
5282                     calls[i].toa = p_cur->toa;
5283                     calls[i].isMpty = p_cur->isMpty;
5284                     calls[i].isMT = p_cur->isMT;
5285                     calls[i].als = p_cur->als;
5286                     calls[i].isVoice = p_cur->isVoice;
5287                     calls[i].isVoicePrivacy = p_cur->isVoicePrivacy;
5288                     calls[i].number = convertCharPtrToHidlString(p_cur->number);
5289                     calls[i].numberPresentation = (CallPresentation)p_cur->numberPresentation;
5290                     calls[i].name = convertCharPtrToHidlString(p_cur->name);
5291                     calls[i].namePresentation = (CallPresentation)p_cur->namePresentation;
5292                     if (p_cur->uusInfo != NULL && p_cur->uusInfo->uusData != NULL) {
5293                         RIL_UUS_Info* uusInfo = p_cur->uusInfo;
5294                         calls[i].uusInfo.resize(1);
5295                         calls[i].uusInfo[0].uusType = (UusType)uusInfo->uusType;
5296                         calls[i].uusInfo[0].uusDcs = (UusDcs)uusInfo->uusDcs;
5297                         // convert uusInfo->uusData to a null-terminated string
5298                         char* nullTermStr = strndup(uusInfo->uusData, uusInfo->uusLength);
5299                         calls[i].uusInfo[0].uusData = nullTermStr;
5300                         free(nullTermStr);
5301                     }
5302                 }
5303                 retStatus = radioService[slotId]->mRadioResponse->getCurrentCallsResponse(
5304                         responseInfo, calls);
5305             }
5306             radioService[slotId]->checkReturnStatus(retStatus);
5307         }
5308     } else {
5309         RLOGE("getCurrentCallsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
5310     }
5311 
5312     return 0;
5313 }
5314 
dialResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5315 int radio_1_6::dialResponse(int slotId,
5316                        int responseType, int serial, RIL_Errno e, void *response,
5317                        size_t responseLen) {
5318 #if VDBG
5319     RLOGD("dialResponse: serial %d", serial);
5320 #endif
5321 
5322     if (radioService[slotId]->mRadioResponse != NULL) {
5323         RadioResponseInfo responseInfo = {};
5324         populateResponseInfo(responseInfo, serial, responseType, e);
5325         Return<void> retStatus = radioService[slotId]->mRadioResponse->dialResponse(responseInfo);
5326         radioService[slotId]->checkReturnStatus(retStatus);
5327     } else {
5328         RLOGE("dialResponse: radioService[%d]->mRadioResponse == NULL", slotId);
5329     }
5330 
5331     return 0;
5332 }
5333 
getIMSIForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5334 int radio_1_6::getIMSIForAppResponse(int slotId,
5335                                 int responseType, int serial, RIL_Errno e, void *response,
5336                                 size_t responseLen) {
5337 #if VDBG
5338     RLOGD("getIMSIForAppResponse: serial %d", serial);
5339 #endif
5340 
5341     if (radioService[slotId]->mRadioResponse != NULL) {
5342         RadioResponseInfo responseInfo = {};
5343         populateResponseInfo(responseInfo, serial, responseType, e);
5344         Return<void> retStatus = radioService[slotId]->mRadioResponse->getIMSIForAppResponse(
5345                 responseInfo, convertCharPtrToHidlString((char *) response));
5346         radioService[slotId]->checkReturnStatus(retStatus);
5347     } else {
5348         RLOGE("getIMSIForAppResponse: radioService[%d]->mRadioResponse == NULL",
5349                 slotId);
5350     }
5351 
5352     return 0;
5353 }
5354 
hangupConnectionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5355 int radio_1_6::hangupConnectionResponse(int slotId,
5356                                    int responseType, int serial, RIL_Errno e,
5357                                    void *response, size_t responseLen) {
5358 #if VDBG
5359     RLOGD("hangupConnectionResponse: serial %d", serial);
5360 #endif
5361 
5362     if (radioService[slotId]->mRadioResponse != NULL) {
5363         RadioResponseInfo responseInfo = {};
5364         populateResponseInfo(responseInfo, serial, responseType, e);
5365         Return<void> retStatus = radioService[slotId]->mRadioResponse->hangupConnectionResponse(
5366                 responseInfo);
5367         radioService[slotId]->checkReturnStatus(retStatus);
5368     } else {
5369         RLOGE("hangupConnectionResponse: radioService[%d]->mRadioResponse == NULL",
5370                 slotId);
5371     }
5372 
5373     return 0;
5374 }
5375 
hangupWaitingOrBackgroundResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5376 int radio_1_6::hangupWaitingOrBackgroundResponse(int slotId,
5377                                             int responseType, int serial, RIL_Errno e,
5378                                             void *response, size_t responseLen) {
5379 #if VDBG
5380     RLOGD("hangupWaitingOrBackgroundResponse: serial %d", serial);
5381 #endif
5382 
5383     if (radioService[slotId]->mRadioResponse != NULL) {
5384         RadioResponseInfo responseInfo = {};
5385         populateResponseInfo(responseInfo, serial, responseType, e);
5386         Return<void> retStatus =
5387                 radioService[slotId]->mRadioResponse->hangupWaitingOrBackgroundResponse(
5388                 responseInfo);
5389         radioService[slotId]->checkReturnStatus(retStatus);
5390     } else {
5391         RLOGE("hangupWaitingOrBackgroundResponse: radioService[%d]->mRadioResponse == NULL",
5392                 slotId);
5393     }
5394 
5395     return 0;
5396 }
5397 
hangupForegroundResumeBackgroundResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5398 int radio_1_6::hangupForegroundResumeBackgroundResponse(int slotId, int responseType, int serial,
5399                                                     RIL_Errno e, void *response,
5400                                                     size_t responseLen) {
5401 #if VDBG
5402     RLOGD("hangupForegroundResumeBackgroundResponse: serial %d", serial);
5403 #endif
5404 
5405     if (radioService[slotId]->mRadioResponse != NULL) {
5406         RadioResponseInfo responseInfo = {};
5407         populateResponseInfo(responseInfo, serial, responseType, e);
5408         Return<void> retStatus =
5409                 radioService[slotId]->mRadioResponse->hangupForegroundResumeBackgroundResponse(
5410                         responseInfo);
5411         radioService[slotId]->checkReturnStatus(retStatus);
5412     } else {
5413         RLOGE("hangupForegroundResumeBackgroundResponse: radioService[%d]->mRadioResponse == NULL",
5414               slotId);
5415     }
5416 
5417     return 0;
5418 }
5419 
switchWaitingOrHoldingAndActiveResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5420 int radio_1_6::switchWaitingOrHoldingAndActiveResponse(int slotId, int responseType, int serial,
5421                                                    RIL_Errno e, void *response,
5422                                                    size_t responseLen) {
5423 #if VDBG
5424     RLOGD("switchWaitingOrHoldingAndActiveResponse: serial %d", serial);
5425 #endif
5426 
5427     if (radioService[slotId]->mRadioResponse != NULL) {
5428         RadioResponseInfo responseInfo = {};
5429         populateResponseInfo(responseInfo, serial, responseType, e);
5430         Return<void> retStatus =
5431                 radioService[slotId]->mRadioResponse->switchWaitingOrHoldingAndActiveResponse(
5432                 responseInfo);
5433         radioService[slotId]->checkReturnStatus(retStatus);
5434     } else {
5435         RLOGE("switchWaitingOrHoldingAndActiveResponse: radioService[%d]->mRadioResponse "
5436                 "== NULL", slotId);
5437     }
5438 
5439     return 0;
5440 }
5441 
conferenceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5442 int radio_1_6::conferenceResponse(int slotId, int responseType,
5443                              int serial, RIL_Errno e, void *response, size_t responseLen) {
5444 #if VDBG
5445     RLOGD("conferenceResponse: serial %d", serial);
5446 #endif
5447 
5448     if (radioService[slotId]->mRadioResponse != NULL) {
5449         RadioResponseInfo responseInfo = {};
5450         populateResponseInfo(responseInfo, serial, responseType, e);
5451         Return<void> retStatus = radioService[slotId]->mRadioResponse->conferenceResponse(
5452                 responseInfo);
5453         radioService[slotId]->checkReturnStatus(retStatus);
5454     } else {
5455         RLOGE("conferenceResponse: radioService[%d]->mRadioResponse == NULL",
5456                 slotId);
5457     }
5458 
5459     return 0;
5460 }
5461 
rejectCallResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5462 int radio_1_6::rejectCallResponse(int slotId, int responseType,
5463                              int serial, RIL_Errno e, void *response, size_t responseLen) {
5464 #if VDBG
5465     RLOGD("rejectCallResponse: serial %d", serial);
5466 #endif
5467 
5468     if (radioService[slotId]->mRadioResponse != NULL) {
5469         RadioResponseInfo responseInfo = {};
5470         populateResponseInfo(responseInfo, serial, responseType, e);
5471         Return<void> retStatus = radioService[slotId]->mRadioResponse->rejectCallResponse(
5472                 responseInfo);
5473         radioService[slotId]->checkReturnStatus(retStatus);
5474     } else {
5475         RLOGE("rejectCallResponse: radioService[%d]->mRadioResponse == NULL",
5476                 slotId);
5477     }
5478 
5479     return 0;
5480 }
5481 
getLastCallFailCauseResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5482 int radio_1_6::getLastCallFailCauseResponse(int slotId,
5483                                        int responseType, int serial, RIL_Errno e, void *response,
5484                                        size_t responseLen) {
5485 #if VDBG
5486     RLOGD("getLastCallFailCauseResponse: serial %d", serial);
5487 #endif
5488 
5489     if (radioService[slotId]->mRadioResponse != NULL) {
5490         RadioResponseInfo responseInfo = {};
5491         populateResponseInfo(responseInfo, serial, responseType, e);
5492 
5493         LastCallFailCauseInfo info = {};
5494         info.vendorCause = hidl_string();
5495         if (response == NULL) {
5496             RLOGE("getLastCallFailCauseResponse Invalid response: NULL");
5497             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
5498         } else if (responseLen == sizeof(int)) {
5499             int *pInt = (int *) response;
5500             info.causeCode = (LastCallFailCause) pInt[0];
5501         } else if (responseLen == sizeof(RIL_LastCallFailCauseInfo))  {
5502             RIL_LastCallFailCauseInfo *pFailCauseInfo = (RIL_LastCallFailCauseInfo *) response;
5503             info.causeCode = (LastCallFailCause) pFailCauseInfo->cause_code;
5504             info.vendorCause = convertCharPtrToHidlString(pFailCauseInfo->vendor_cause);
5505         } else {
5506             RLOGE("getLastCallFailCauseResponse Invalid response: NULL");
5507             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
5508         }
5509 
5510         Return<void> retStatus = radioService[slotId]->mRadioResponse->getLastCallFailCauseResponse(
5511                 responseInfo, info);
5512         radioService[slotId]->checkReturnStatus(retStatus);
5513     } else {
5514         RLOGE("getLastCallFailCauseResponse: radioService[%d]->mRadioResponse == NULL",
5515                 slotId);
5516     }
5517 
5518     return 0;
5519 }
5520 
getSignalStrengthResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5521 int radio_1_6::getSignalStrengthResponse(int slotId, int responseType, int serial, RIL_Errno e,
5522                                          void* response, size_t responseLen) {
5523 #if VDBG
5524     RLOGD("getSignalStrengthResponse: serial %d", serial);
5525 #endif
5526 
5527     V1_6::RadioResponseInfo responseInfo16 = {};
5528     RadioResponseInfo responseInfo = {};
5529     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
5530         populateResponseInfo_1_6(responseInfo16, serial, responseType, e);
5531     } else {
5532         populateResponseInfo(responseInfo, serial, responseType, e);
5533     }
5534 
5535     if (response == NULL || responseLen != sizeof(RIL_SignalStrength_v12)) {
5536         RLOGE("getSignalStrengthResponse: Invalid response");
5537         if (e == RIL_E_SUCCESS) {
5538             responseInfo16.error = V1_6::RadioError::INVALID_RESPONSE;
5539             responseInfo.error = RadioError::INVALID_RESPONSE;
5540         }
5541     } else {
5542         if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
5543             V1_6::SignalStrength signalStrength_1_6 = {};
5544             convertRilSignalStrengthToHal_1_6(response, responseLen, signalStrength_1_6);
5545             Return<void> retStatus =
5546                     radioService[slotId]->mRadioResponseV1_6->getSignalStrengthResponse_1_6(
5547                             responseInfo16, signalStrength_1_6);
5548             radioService[slotId]->checkReturnStatus(retStatus);
5549         } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
5550             V1_4::SignalStrength signalStrength_1_4 = {};
5551             convertRilSignalStrengthToHal_1_4(response, responseLen, signalStrength_1_4);
5552             // TODO: future implementation needs to fill tdScdma, wcdma and nr signal strength.
5553             Return<void> retStatus =
5554                     radioService[slotId]->mRadioResponseV1_4->getSignalStrengthResponse_1_4(
5555                             responseInfo, signalStrength_1_4);
5556             radioService[slotId]->checkReturnStatus(retStatus);
5557         } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
5558             V1_2::SignalStrength signalStrength_1_2 = {};
5559             convertRilSignalStrengthToHal_1_2(response, responseLen, signalStrength_1_2);
5560             Return<void> retStatus =
5561                     radioService[slotId]->mRadioResponseV1_2->getSignalStrengthResponse_1_2(
5562                             responseInfo, signalStrength_1_2);
5563             radioService[slotId]->checkReturnStatus(retStatus);
5564         } else if (radioService[slotId]->mRadioResponse != NULL) {
5565             SignalStrength signalStrength = {};
5566             convertRilSignalStrengthToHal(response, responseLen, signalStrength);
5567             Return<void> retStatus =
5568                     radioService[slotId]->mRadioResponse->getSignalStrengthResponse(responseInfo,
5569                                                                                     signalStrength);
5570             radioService[slotId]->checkReturnStatus(retStatus);
5571         } else {
5572             RLOGE("getSignalStrengthResponse: radioService[%d]->mRadioResponse == NULL", slotId);
5573         }
5574     }
5575 
5576     return 0;
5577 }
5578 
getCellInfoTypeRadioTechnology(char * rat)5579 RIL_CellInfoType getCellInfoTypeRadioTechnology(char *rat) {
5580     if (rat == NULL) {
5581         return RIL_CELL_INFO_TYPE_NONE;
5582     }
5583 
5584     int radioTech = atoi(rat);
5585 
5586     switch(radioTech) {
5587 
5588         case RADIO_TECH_GPRS:
5589         case RADIO_TECH_EDGE:
5590         case RADIO_TECH_GSM: {
5591             return RIL_CELL_INFO_TYPE_GSM;
5592         }
5593 
5594         case RADIO_TECH_UMTS:
5595         case RADIO_TECH_HSDPA:
5596         case RADIO_TECH_HSUPA:
5597         case RADIO_TECH_HSPA:
5598         case RADIO_TECH_HSPAP: {
5599             return RIL_CELL_INFO_TYPE_WCDMA;
5600         }
5601 
5602         case RADIO_TECH_IS95A:
5603         case RADIO_TECH_IS95B:
5604         case RADIO_TECH_1xRTT:
5605         case RADIO_TECH_EVDO_0:
5606         case RADIO_TECH_EVDO_A:
5607         case RADIO_TECH_EVDO_B:
5608         case RADIO_TECH_EHRPD: {
5609             return RIL_CELL_INFO_TYPE_CDMA;
5610         }
5611 
5612         case RADIO_TECH_LTE:
5613         case RADIO_TECH_LTE_CA: {
5614             return RIL_CELL_INFO_TYPE_LTE;
5615         }
5616 
5617         case RADIO_TECH_TD_SCDMA: {
5618             return RIL_CELL_INFO_TYPE_TD_SCDMA;
5619         }
5620 
5621         default: {
5622             break;
5623         }
5624     }
5625 
5626     return RIL_CELL_INFO_TYPE_NONE;
5627 
5628 }
5629 
fillCellIdentityResponse(CellIdentity & cellIdentity,RIL_CellIdentity_v16 & rilCellIdentity)5630 void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 &rilCellIdentity) {
5631 
5632     cellIdentity.cellIdentityGsm.resize(0);
5633     cellIdentity.cellIdentityWcdma.resize(0);
5634     cellIdentity.cellIdentityCdma.resize(0);
5635     cellIdentity.cellIdentityTdscdma.resize(0);
5636     cellIdentity.cellIdentityLte.resize(0);
5637     cellIdentity.cellInfoType = (CellInfoType)rilCellIdentity.cellInfoType;
5638     switch(rilCellIdentity.cellInfoType) {
5639 
5640         case RIL_CELL_INFO_TYPE_GSM: {
5641             cellIdentity.cellIdentityGsm.resize(1);
5642             cellIdentity.cellIdentityGsm[0].mcc =
5643                     std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5644             cellIdentity.cellIdentityGsm[0].mnc =
5645                     ril::util::mnc::decode(rilCellIdentity.cellIdentityGsm.mnc);
5646             cellIdentity.cellIdentityGsm[0].lac = rilCellIdentity.cellIdentityGsm.lac;
5647             cellIdentity.cellIdentityGsm[0].cid = rilCellIdentity.cellIdentityGsm.cid;
5648             cellIdentity.cellIdentityGsm[0].arfcn = rilCellIdentity.cellIdentityGsm.arfcn;
5649             cellIdentity.cellIdentityGsm[0].bsic = rilCellIdentity.cellIdentityGsm.bsic;
5650             break;
5651         }
5652 
5653         case RIL_CELL_INFO_TYPE_WCDMA: {
5654             cellIdentity.cellIdentityWcdma.resize(1);
5655             cellIdentity.cellIdentityWcdma[0].mcc =
5656                     std::to_string(rilCellIdentity.cellIdentityWcdma.mcc);
5657             cellIdentity.cellIdentityWcdma[0].mnc =
5658                     ril::util::mnc::decode(rilCellIdentity.cellIdentityWcdma.mnc);
5659             cellIdentity.cellIdentityWcdma[0].lac = rilCellIdentity.cellIdentityWcdma.lac;
5660             cellIdentity.cellIdentityWcdma[0].cid = rilCellIdentity.cellIdentityWcdma.cid;
5661             cellIdentity.cellIdentityWcdma[0].psc = rilCellIdentity.cellIdentityWcdma.psc;
5662             cellIdentity.cellIdentityWcdma[0].uarfcn = rilCellIdentity.cellIdentityWcdma.uarfcn;
5663             break;
5664         }
5665 
5666         case RIL_CELL_INFO_TYPE_CDMA: {
5667             cellIdentity.cellIdentityCdma.resize(1);
5668             cellIdentity.cellIdentityCdma[0].networkId = rilCellIdentity.cellIdentityCdma.networkId;
5669             cellIdentity.cellIdentityCdma[0].systemId = rilCellIdentity.cellIdentityCdma.systemId;
5670             cellIdentity.cellIdentityCdma[0].baseStationId =
5671                     rilCellIdentity.cellIdentityCdma.basestationId;
5672             cellIdentity.cellIdentityCdma[0].longitude = rilCellIdentity.cellIdentityCdma.longitude;
5673             cellIdentity.cellIdentityCdma[0].latitude = rilCellIdentity.cellIdentityCdma.latitude;
5674             break;
5675         }
5676 
5677         case RIL_CELL_INFO_TYPE_LTE: {
5678             cellIdentity.cellIdentityLte.resize(1);
5679             cellIdentity.cellIdentityLte[0].mcc =
5680                     std::to_string(rilCellIdentity.cellIdentityLte.mcc);
5681             cellIdentity.cellIdentityLte[0].mnc =
5682                     ril::util::mnc::decode(rilCellIdentity.cellIdentityLte.mnc);
5683             cellIdentity.cellIdentityLte[0].ci = rilCellIdentity.cellIdentityLte.ci;
5684             cellIdentity.cellIdentityLte[0].pci = rilCellIdentity.cellIdentityLte.pci;
5685             cellIdentity.cellIdentityLte[0].tac = rilCellIdentity.cellIdentityLte.tac;
5686             cellIdentity.cellIdentityLte[0].earfcn = rilCellIdentity.cellIdentityLte.earfcn;
5687             break;
5688         }
5689 
5690         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
5691             cellIdentity.cellIdentityTdscdma.resize(1);
5692             cellIdentity.cellIdentityTdscdma[0].mcc =
5693                     std::to_string(rilCellIdentity.cellIdentityTdscdma.mcc);
5694             cellIdentity.cellIdentityTdscdma[0].mnc =
5695                     ril::util::mnc::decode(rilCellIdentity.cellIdentityTdscdma.mnc);
5696             cellIdentity.cellIdentityTdscdma[0].lac = rilCellIdentity.cellIdentityTdscdma.lac;
5697             cellIdentity.cellIdentityTdscdma[0].cid = rilCellIdentity.cellIdentityTdscdma.cid;
5698             cellIdentity.cellIdentityTdscdma[0].cpid = rilCellIdentity.cellIdentityTdscdma.cpid;
5699             break;
5700         }
5701 
5702         default: {
5703             break;
5704         }
5705     }
5706 }
5707 
fillCellIdentityResponse_1_5(V1_5::CellIdentity & cellIdentity,RIL_CellIdentity_v16 & rilCellIdentity)5708 void fillCellIdentityResponse_1_5(V1_5::CellIdentity &cellIdentity,
5709                                   RIL_CellIdentity_v16 &rilCellIdentity) {
5710 
5711     switch (rilCellIdentity.cellInfoType) {
5712         case RIL_CELL_INFO_TYPE_GSM: {
5713             V1_5::CellIdentityGsm gsm;
5714             gsm.base.base.mcc = std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5715             gsm.base.base.mnc = ril::util::mnc::decode(rilCellIdentity.cellIdentityGsm.mnc);
5716             if (gsm.base.base.mcc == "-1") {
5717                 gsm.base.base.mcc = "";
5718             }
5719             gsm.base.base.lac = rilCellIdentity.cellIdentityGsm.lac;
5720             gsm.base.base.cid = rilCellIdentity.cellIdentityGsm.cid;
5721             gsm.base.base.arfcn = rilCellIdentity.cellIdentityGsm.arfcn;
5722             gsm.base.base.bsic = rilCellIdentity.cellIdentityGsm.bsic;
5723             cellIdentity.gsm(gsm);
5724             break;
5725         }
5726 
5727         case RIL_CELL_INFO_TYPE_WCDMA: {
5728             V1_5::CellIdentityWcdma wcdma;
5729             wcdma.base.base.mcc = std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5730             wcdma.base.base.mnc = ril::util::mnc::decode(rilCellIdentity.cellIdentityWcdma.mnc);
5731             if (wcdma.base.base.mcc == "-1") {
5732                 wcdma.base.base.mcc = "";
5733             }
5734             wcdma.base.base.lac = rilCellIdentity.cellIdentityWcdma.lac;
5735             wcdma.base.base.cid = rilCellIdentity.cellIdentityWcdma.cid;
5736             wcdma.base.base.psc = rilCellIdentity.cellIdentityWcdma.psc;
5737             wcdma.base.base.uarfcn = rilCellIdentity.cellIdentityWcdma.uarfcn;
5738             cellIdentity.wcdma(wcdma);
5739             break;
5740         }
5741 
5742         case RIL_CELL_INFO_TYPE_CDMA: {
5743             V1_2::CellIdentityCdma cdma;
5744             cdma.base.networkId = rilCellIdentity.cellIdentityCdma.networkId;
5745             cdma.base.systemId = rilCellIdentity.cellIdentityCdma.systemId;
5746             cdma.base.baseStationId =
5747                     rilCellIdentity.cellIdentityCdma.basestationId;
5748             cdma.base.longitude = rilCellIdentity.cellIdentityCdma.longitude;
5749             cdma.base.latitude = rilCellIdentity.cellIdentityCdma.latitude;
5750             cellIdentity.cdma(cdma);
5751             break;
5752         }
5753 
5754         case RIL_CELL_INFO_TYPE_LTE: {
5755             V1_5::CellIdentityLte lte;
5756             lte.base.base.mcc = std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5757             lte.base.base.mnc = ril::util::mnc::decode(rilCellIdentity.cellIdentityLte.mnc);
5758             if (lte.base.base.mcc == "-1") {
5759                 lte.base.base.mcc = "";
5760             }
5761             lte.base.base.ci = rilCellIdentity.cellIdentityLte.ci;
5762             lte.base.base.pci = rilCellIdentity.cellIdentityLte.pci;
5763             lte.base.base.tac = rilCellIdentity.cellIdentityLte.tac;
5764             lte.base.base.earfcn = rilCellIdentity.cellIdentityLte.earfcn;
5765             cellIdentity.lte(lte);
5766             break;
5767         }
5768 
5769         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
5770             V1_5::CellIdentityTdscdma tdscdma;
5771             tdscdma.base.base.mcc = std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5772             tdscdma.base.base.mnc = ril::util::mnc::decode(rilCellIdentity.cellIdentityTdscdma.mnc);
5773             if (tdscdma.base.base.mcc == "-1") {
5774                 tdscdma.base.base.mcc = "";
5775             }
5776             tdscdma.base.base.lac = rilCellIdentity.cellIdentityTdscdma.lac;
5777             tdscdma.base.base.cid = rilCellIdentity.cellIdentityTdscdma.cid;
5778             tdscdma.base.base.cpid = rilCellIdentity.cellIdentityTdscdma.cpid;
5779             cellIdentity.tdscdma(tdscdma);
5780             break;
5781         }
5782 
5783         default: {
5784             break;
5785         }
5786     }
5787 }
5788 
fillCellIdentityResponse_1_2(V1_2::CellIdentity & cellIdentity,RIL_CellIdentity_v1_2 & rilCellIdentity)5789 void fillCellIdentityResponse_1_2(V1_2::CellIdentity &cellIdentity,
5790                                   RIL_CellIdentity_v1_2 &rilCellIdentity) {
5791     cellIdentity.cellIdentityGsm.resize(0);
5792     cellIdentity.cellIdentityWcdma.resize(0);
5793     cellIdentity.cellIdentityCdma.resize(0);
5794     cellIdentity.cellIdentityTdscdma.resize(0);
5795     cellIdentity.cellIdentityLte.resize(0);
5796     cellIdentity.cellInfoType = (CellInfoType)rilCellIdentity.cellInfoType;
5797     switch(rilCellIdentity.cellInfoType) {
5798 
5799         case RIL_CELL_INFO_TYPE_GSM: {
5800             cellIdentity.cellIdentityGsm.resize(1);
5801             cellIdentity.cellIdentityGsm[0].base.mcc =
5802                 std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5803             cellIdentity.cellIdentityGsm[0].base.mnc =
5804                     ril::util::mnc::decode(rilCellIdentity.cellIdentityGsm.mnc);
5805 
5806             if (cellIdentity.cellIdentityGsm[0].base.mcc == "-1") {
5807                 cellIdentity.cellIdentityGsm[0].base.mcc = "";
5808             }
5809 
5810             cellIdentity.cellIdentityGsm[0].base.lac = rilCellIdentity.cellIdentityGsm.lac;
5811             cellIdentity.cellIdentityGsm[0].base.cid = rilCellIdentity.cellIdentityGsm.cid;
5812             cellIdentity.cellIdentityGsm[0].base.arfcn = rilCellIdentity.cellIdentityGsm.arfcn;
5813             cellIdentity.cellIdentityGsm[0].base.bsic = rilCellIdentity.cellIdentityGsm.bsic;
5814             break;
5815         }
5816 
5817         case RIL_CELL_INFO_TYPE_WCDMA: {
5818             cellIdentity.cellIdentityWcdma.resize(1);
5819             cellIdentity.cellIdentityWcdma[0].base.mcc =
5820                 std::to_string(rilCellIdentity.cellIdentityWcdma.mcc);
5821             cellIdentity.cellIdentityWcdma[0].base.mnc =
5822                     ril::util::mnc::decode(rilCellIdentity.cellIdentityWcdma.mnc);
5823 
5824             if (cellIdentity.cellIdentityWcdma[0].base.mcc == "-1") {
5825                 cellIdentity.cellIdentityWcdma[0].base.mcc = "";
5826             }
5827 
5828             cellIdentity.cellIdentityWcdma[0].base.lac = rilCellIdentity.cellIdentityWcdma.lac;
5829             cellIdentity.cellIdentityWcdma[0].base.cid = rilCellIdentity.cellIdentityWcdma.cid;
5830             cellIdentity.cellIdentityWcdma[0].base.psc = rilCellIdentity.cellIdentityWcdma.psc;
5831             cellIdentity.cellIdentityWcdma[0].base.uarfcn = rilCellIdentity.cellIdentityWcdma.uarfcn;
5832             break;
5833         }
5834 
5835         case RIL_CELL_INFO_TYPE_CDMA: {
5836             cellIdentity.cellIdentityCdma.resize(1);
5837             cellIdentity.cellIdentityCdma[0].base.networkId = rilCellIdentity.cellIdentityCdma.networkId;
5838             cellIdentity.cellIdentityCdma[0].base.systemId = rilCellIdentity.cellIdentityCdma.systemId;
5839             cellIdentity.cellIdentityCdma[0].base.baseStationId =
5840                     rilCellIdentity.cellIdentityCdma.basestationId;
5841             cellIdentity.cellIdentityCdma[0].base.longitude = rilCellIdentity.cellIdentityCdma.longitude;
5842             cellIdentity.cellIdentityCdma[0].base.latitude = rilCellIdentity.cellIdentityCdma.latitude;
5843             break;
5844         }
5845 
5846         case RIL_CELL_INFO_TYPE_LTE: {
5847             cellIdentity.cellIdentityLte.resize(1);
5848             cellIdentity.cellIdentityLte[0].base.mcc =
5849                 std::to_string(rilCellIdentity.cellIdentityLte.mcc);
5850             cellIdentity.cellIdentityLte[0].base.mnc =
5851                     ril::util::mnc::decode(rilCellIdentity.cellIdentityLte.mnc);
5852 
5853             if (cellIdentity.cellIdentityLte[0].base.mcc == "-1") {
5854                 cellIdentity.cellIdentityLte[0].base.mcc = "";
5855             }
5856 
5857             cellIdentity.cellIdentityLte[0].base.ci = rilCellIdentity.cellIdentityLte.ci;
5858             cellIdentity.cellIdentityLte[0].base.pci = rilCellIdentity.cellIdentityLte.pci;
5859             cellIdentity.cellIdentityLte[0].base.tac = rilCellIdentity.cellIdentityLte.tac;
5860             cellIdentity.cellIdentityLte[0].base.earfcn = rilCellIdentity.cellIdentityLte.earfcn;
5861             cellIdentity.cellIdentityLte[0].bandwidth = rilCellIdentity.cellIdentityLte.bandwidth;
5862             break;
5863         }
5864 
5865         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
5866             cellIdentity.cellIdentityTdscdma.resize(1);
5867             cellIdentity.cellIdentityTdscdma[0].base.mcc =
5868                 std::to_string(rilCellIdentity.cellIdentityTdscdma.mcc);
5869             cellIdentity.cellIdentityTdscdma[0].base.mnc =
5870                     ril::util::mnc::decode(rilCellIdentity.cellIdentityTdscdma.mnc);
5871 
5872             if (cellIdentity.cellIdentityTdscdma[0].base.mcc == "-1") {
5873                 cellIdentity.cellIdentityTdscdma[0].base.mcc = "";
5874             }
5875 
5876             cellIdentity.cellIdentityTdscdma[0].base.lac = rilCellIdentity.cellIdentityTdscdma.lac;
5877             cellIdentity.cellIdentityTdscdma[0].base.cid = rilCellIdentity.cellIdentityTdscdma.cid;
5878             cellIdentity.cellIdentityTdscdma[0].base.cpid = rilCellIdentity.cellIdentityTdscdma.cpid;
5879             cellIdentity.cellIdentityTdscdma[0].uarfcn = rilCellIdentity.cellIdentityTdscdma.uarfcn;
5880             break;
5881         }
5882 
5883         default: {
5884             break;
5885         }
5886     }
5887 }
5888 
convertResponseStringEntryToInt(char ** response,int index,int numStrings)5889 int convertResponseStringEntryToInt(char **response, int index, int numStrings) {
5890     if ((response != NULL) &&  (numStrings > index) && (response[index] != NULL)) {
5891         return atoi(response[index]);
5892     }
5893 
5894     return -1;
5895 }
5896 
convertResponseHexStringEntryToInt(char ** response,int index,int numStrings)5897 int convertResponseHexStringEntryToInt(char **response, int index, int numStrings) {
5898     const int hexBase = 16;
5899     if ((response != NULL) &&  (numStrings > index) && (response[index] != NULL)) {
5900         return strtol(response[index], NULL, hexBase);
5901     }
5902 
5903     return -1;
5904 }
5905 
5906 /* Fill Cell Identity info from Voice Registration State Response.
5907  * This function is applicable only for RIL Version < 15.
5908  * Response is a  "char **".
5909  * First and Second entries are in hex string format
5910  * and rest are integers represented in ascii format. */
fillCellIdentityFromVoiceRegStateResponseString(V1_5::CellIdentity & cellIdentity,int numStrings,char ** response)5911 void fillCellIdentityFromVoiceRegStateResponseString(V1_5::CellIdentity &cellIdentity,
5912         int numStrings, char** response) {
5913 
5914     RIL_CellIdentity_v16 rilCellIdentity;
5915     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
5916 
5917     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
5918     switch(rilCellIdentity.cellInfoType) {
5919 
5920         case RIL_CELL_INFO_TYPE_GSM: {
5921             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5922             rilCellIdentity.cellIdentityGsm.lac =
5923                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5924 
5925             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5926             rilCellIdentity.cellIdentityGsm.cid =
5927                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5928 
5929             if (numStrings > 15) {
5930                 rilCellIdentity.cellIdentityGsm.mcc =
5931                         convertResponseStringEntryToInt(response, 15, numStrings);
5932 
5933                 rilCellIdentity.cellIdentityGsm.mnc =
5934                         convertResponseStringEntryToInt(response, 16, numStrings);
5935             }
5936             break;
5937         }
5938 
5939         case RIL_CELL_INFO_TYPE_WCDMA: {
5940             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5941             rilCellIdentity.cellIdentityWcdma.lac =
5942                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5943 
5944             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5945             rilCellIdentity.cellIdentityWcdma.cid =
5946                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5947             rilCellIdentity.cellIdentityWcdma.psc =
5948                     convertResponseStringEntryToInt(response, 14, numStrings);
5949 
5950             if (numStrings > 15) {
5951                 rilCellIdentity.cellIdentityGsm.mcc =
5952                         convertResponseStringEntryToInt(response, 15, numStrings);
5953 
5954                 rilCellIdentity.cellIdentityGsm.mnc =
5955                         convertResponseStringEntryToInt(response, 16, numStrings);
5956             }
5957             break;
5958         }
5959 
5960         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
5961             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5962             rilCellIdentity.cellIdentityTdscdma.lac =
5963                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5964 
5965             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5966             rilCellIdentity.cellIdentityTdscdma.cid =
5967                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5968 
5969             if (numStrings > 15) {
5970                 rilCellIdentity.cellIdentityGsm.mcc =
5971                         convertResponseStringEntryToInt(response, 15, numStrings);
5972 
5973                 rilCellIdentity.cellIdentityGsm.mnc =
5974                         convertResponseStringEntryToInt(response, 16, numStrings);
5975             }
5976             break;
5977         }
5978 
5979         case RIL_CELL_INFO_TYPE_CDMA:{
5980             rilCellIdentity.cellIdentityCdma.basestationId =
5981                     convertResponseStringEntryToInt(response, 4, numStrings);
5982             /* Order of Lat. and Long. swapped between RIL and HIDL interface versions. */
5983             rilCellIdentity.cellIdentityCdma.latitude =
5984                     convertResponseStringEntryToInt(response, 5, numStrings);
5985             rilCellIdentity.cellIdentityCdma.longitude =
5986                     convertResponseStringEntryToInt(response, 6, numStrings);
5987             rilCellIdentity.cellIdentityCdma.systemId =
5988                     convertResponseStringEntryToInt(response, 8, numStrings);
5989             rilCellIdentity.cellIdentityCdma.networkId =
5990                     convertResponseStringEntryToInt(response, 9, numStrings);
5991             break;
5992         }
5993 
5994         case RIL_CELL_INFO_TYPE_LTE:{
5995             /* valid TAC are hexstrings in the range 0x0000 - 0xffff */
5996             rilCellIdentity.cellIdentityLte.tac =
5997                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5998 
5999             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6000             rilCellIdentity.cellIdentityLte.ci =
6001                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6002 
6003             if (numStrings > 15) {
6004                 rilCellIdentity.cellIdentityGsm.mcc =
6005                         convertResponseStringEntryToInt(response, 15, numStrings);
6006 
6007                 rilCellIdentity.cellIdentityGsm.mnc =
6008                         convertResponseStringEntryToInt(response, 16, numStrings);
6009             }
6010             break;
6011         }
6012 
6013         default: {
6014             break;
6015         }
6016     }
6017 
6018     fillCellIdentityResponse_1_5(cellIdentity, rilCellIdentity);
6019 }
6020 
fillCellIdentityFromVoiceRegStateResponseString_1_2(V1_2::CellIdentity & cellIdentity,int numStrings,char ** response)6021 void fillCellIdentityFromVoiceRegStateResponseString_1_2(V1_2::CellIdentity &cellIdentity,
6022         int numStrings, char** response) {
6023     RIL_CellIdentity_v1_2 rilCellIdentity;
6024     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v1_2));
6025 
6026     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
6027 
6028     switch(rilCellIdentity.cellInfoType) {
6029         case RIL_CELL_INFO_TYPE_GSM: {
6030             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6031             rilCellIdentity.cellIdentityGsm.lac =
6032                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6033 
6034             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6035             rilCellIdentity.cellIdentityGsm.cid =
6036                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6037 
6038             if (numStrings > 15) {
6039                 rilCellIdentity.cellIdentityGsm.mcc =
6040                         convertResponseStringEntryToInt(response, 15, numStrings);
6041 
6042                 rilCellIdentity.cellIdentityGsm.mnc =
6043                         convertResponseStringEntryToInt(response, 16, numStrings);
6044             }
6045             break;
6046         }
6047 
6048         case RIL_CELL_INFO_TYPE_WCDMA: {
6049             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6050             rilCellIdentity.cellIdentityWcdma.lac =
6051                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6052 
6053             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6054             rilCellIdentity.cellIdentityWcdma.cid =
6055                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6056             rilCellIdentity.cellIdentityWcdma.psc =
6057                     convertResponseStringEntryToInt(response, 14, numStrings);
6058 
6059             if (numStrings > 15) {
6060                 rilCellIdentity.cellIdentityWcdma.mcc =
6061                         convertResponseStringEntryToInt(response, 15, numStrings);
6062 
6063                 rilCellIdentity.cellIdentityWcdma.mnc =
6064                         convertResponseStringEntryToInt(response, 16, numStrings);
6065             }
6066             break;
6067         }
6068 
6069         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
6070             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6071             rilCellIdentity.cellIdentityTdscdma.lac =
6072                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6073 
6074             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6075             rilCellIdentity.cellIdentityTdscdma.cid =
6076                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6077 
6078             if (numStrings > 15) {
6079                 rilCellIdentity.cellIdentityTdscdma.mcc =
6080                         convertResponseStringEntryToInt(response, 15, numStrings);
6081 
6082                 rilCellIdentity.cellIdentityTdscdma.mnc =
6083                         convertResponseStringEntryToInt(response, 16, numStrings);
6084             }
6085             break;
6086         }
6087 
6088         case RIL_CELL_INFO_TYPE_CDMA:{
6089             rilCellIdentity.cellIdentityCdma.basestationId =
6090                     convertResponseStringEntryToInt(response, 4, numStrings);
6091             /* Order of Lat. and Long. swapped between RIL and HIDL interface versions. */
6092             rilCellIdentity.cellIdentityCdma.latitude =
6093                     convertResponseStringEntryToInt(response, 5, numStrings);
6094             rilCellIdentity.cellIdentityCdma.longitude =
6095                     convertResponseStringEntryToInt(response, 6, numStrings);
6096             rilCellIdentity.cellIdentityCdma.systemId =
6097                     convertResponseStringEntryToInt(response, 8, numStrings);
6098             rilCellIdentity.cellIdentityCdma.networkId =
6099                     convertResponseStringEntryToInt(response, 9, numStrings);
6100             break;
6101         }
6102 
6103         case RIL_CELL_INFO_TYPE_LTE:{
6104             /* valid TAC are hexstrings in the range 0x0000 - 0xffff */
6105             rilCellIdentity.cellIdentityLte.tac =
6106                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6107 
6108             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6109             rilCellIdentity.cellIdentityLte.ci =
6110                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6111 
6112             if (numStrings > 15) {
6113                 rilCellIdentity.cellIdentityLte.mcc =
6114                         convertResponseStringEntryToInt(response, 15, numStrings);
6115 
6116                 rilCellIdentity.cellIdentityLte.mnc =
6117                         convertResponseStringEntryToInt(response, 16, numStrings);
6118             }
6119             rilCellIdentity.cellIdentityLte.bandwidth = INT_MAX;
6120             break;
6121         }
6122 
6123         default: {
6124             break;
6125         }
6126     }
6127 
6128     fillCellIdentityResponse_1_2(cellIdentity, rilCellIdentity);
6129 }
6130 
6131 /* Fill Cell Identity info from Data Registration State Response.
6132  * This function is applicable only for RIL Version < 15.
6133  * Response is a  "char **".
6134  * First and Second entries are in hex string format
6135  * and rest are integers represented in ascii format. */
fillCellIdentityFromDataRegStateResponseString_1_5(V1_5::CellIdentity & cellIdentity,int numStrings,char ** response)6136 void fillCellIdentityFromDataRegStateResponseString_1_5(V1_5::CellIdentity &cellIdentity,
6137         int numStrings, char** response) {
6138 
6139     RIL_CellIdentity_v16 rilCellIdentity;
6140     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
6141 
6142     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
6143     switch(rilCellIdentity.cellInfoType) {
6144         case RIL_CELL_INFO_TYPE_GSM: {
6145             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6146             rilCellIdentity.cellIdentityGsm.lac =
6147                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6148 
6149             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6150             rilCellIdentity.cellIdentityGsm.cid =
6151                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6152 
6153             if (numStrings >= 13) {
6154                 rilCellIdentity.cellIdentityGsm.mcc =
6155                         convertResponseStringEntryToInt(response, 11, numStrings);
6156 
6157                 rilCellIdentity.cellIdentityGsm.mnc =
6158                         convertResponseStringEntryToInt(response, 12, numStrings);
6159             } else {
6160                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6161                 rilCellIdentity.cellIdentityGsm.mnc = 0;
6162                 rilCellIdentity.cellIdentityGsm.mcc = 0;
6163             }
6164             break;
6165         }
6166         case RIL_CELL_INFO_TYPE_WCDMA: {
6167             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6168             rilCellIdentity.cellIdentityWcdma.lac =
6169                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6170 
6171             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6172             rilCellIdentity.cellIdentityWcdma.cid =
6173                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6174 
6175             if (numStrings >= 13) {
6176                 rilCellIdentity.cellIdentityWcdma.mcc =
6177                         convertResponseStringEntryToInt(response, 11, numStrings);
6178 
6179                 rilCellIdentity.cellIdentityWcdma.mnc =
6180                         convertResponseStringEntryToInt(response, 12, numStrings);
6181             } else {
6182                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6183                 rilCellIdentity.cellIdentityWcdma.mnc = 0;
6184                 rilCellIdentity.cellIdentityWcdma.mcc = 0;
6185             }
6186             break;
6187         }
6188         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
6189             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6190             rilCellIdentity.cellIdentityTdscdma.lac =
6191                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6192 
6193             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6194             rilCellIdentity.cellIdentityTdscdma.cid =
6195                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6196 
6197             if (numStrings >= 13) {
6198                 rilCellIdentity.cellIdentityTdscdma.mcc =
6199                         convertResponseStringEntryToInt(response, 11, numStrings);
6200 
6201                 rilCellIdentity.cellIdentityTdscdma.mnc =
6202                         convertResponseStringEntryToInt(response, 12, numStrings);
6203             } else {
6204                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6205                 rilCellIdentity.cellIdentityTdscdma.mnc = 0;
6206                 rilCellIdentity.cellIdentityTdscdma.mcc = 0;
6207             }
6208             break;
6209         }
6210         case RIL_CELL_INFO_TYPE_LTE: {
6211             rilCellIdentity.cellIdentityLte.tac =
6212                     convertResponseStringEntryToInt(response, 6, numStrings);
6213             rilCellIdentity.cellIdentityLte.pci =
6214                     convertResponseStringEntryToInt(response, 7, numStrings);
6215             rilCellIdentity.cellIdentityLte.ci =
6216                     convertResponseStringEntryToInt(response, 8, numStrings);
6217 
6218             if (numStrings >= 13) {
6219                 rilCellIdentity.cellIdentityLte.mcc =
6220                         convertResponseStringEntryToInt(response, 11, numStrings);
6221 
6222                 rilCellIdentity.cellIdentityLte.mnc =
6223                         convertResponseStringEntryToInt(response, 12, numStrings);
6224             } else {
6225                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6226                 rilCellIdentity.cellIdentityLte.mnc = 0;
6227                 rilCellIdentity.cellIdentityLte.mcc = 0;
6228             }
6229             break;
6230         }
6231         default: {
6232             break;
6233         }
6234     }
6235 
6236     fillCellIdentityResponse_1_5(cellIdentity, rilCellIdentity);
6237 }
6238 
fillCellIdentityFromDataRegStateResponseString_1_2(V1_2::CellIdentity & cellIdentity,int numStrings,char ** response)6239 void fillCellIdentityFromDataRegStateResponseString_1_2(V1_2::CellIdentity &cellIdentity,
6240         int numStrings, char** response) {
6241 
6242     RIL_CellIdentity_v1_2 rilCellIdentity;
6243     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v1_2));
6244 
6245     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
6246     switch(rilCellIdentity.cellInfoType) {
6247         case RIL_CELL_INFO_TYPE_GSM: {
6248             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6249             rilCellIdentity.cellIdentityGsm.lac =
6250                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6251 
6252             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6253             rilCellIdentity.cellIdentityGsm.cid =
6254                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6255 
6256             if (numStrings >= 13) {
6257                 rilCellIdentity.cellIdentityGsm.mcc =
6258                         convertResponseStringEntryToInt(response, 11, numStrings);
6259 
6260                 rilCellIdentity.cellIdentityGsm.mnc =
6261                         convertResponseStringEntryToInt(response, 12, numStrings);
6262             } else {
6263                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6264                 rilCellIdentity.cellIdentityGsm.mnc = 0;
6265                 rilCellIdentity.cellIdentityGsm.mcc = 0;
6266             }
6267             break;
6268         }
6269         case RIL_CELL_INFO_TYPE_WCDMA: {
6270             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6271             rilCellIdentity.cellIdentityWcdma.lac =
6272                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6273 
6274             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6275             rilCellIdentity.cellIdentityWcdma.cid =
6276                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6277 
6278             if (numStrings >= 13) {
6279                 rilCellIdentity.cellIdentityWcdma.mcc =
6280                         convertResponseStringEntryToInt(response, 11, numStrings);
6281 
6282                 rilCellIdentity.cellIdentityWcdma.mnc =
6283                         convertResponseStringEntryToInt(response, 12, numStrings);
6284             } else {
6285                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6286                 rilCellIdentity.cellIdentityWcdma.mnc = 0;
6287                 rilCellIdentity.cellIdentityWcdma.mcc = 0;
6288             }
6289             break;
6290         }
6291         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
6292             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6293             rilCellIdentity.cellIdentityTdscdma.lac =
6294                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6295 
6296             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6297             rilCellIdentity.cellIdentityTdscdma.cid =
6298                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6299 
6300             if (numStrings >= 13) {
6301                 rilCellIdentity.cellIdentityTdscdma.mcc =
6302                         convertResponseStringEntryToInt(response, 11, numStrings);
6303 
6304                 rilCellIdentity.cellIdentityTdscdma.mnc =
6305                         convertResponseStringEntryToInt(response, 12, numStrings);
6306             } else {
6307                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6308                 rilCellIdentity.cellIdentityTdscdma.mnc = 0;
6309                 rilCellIdentity.cellIdentityTdscdma.mcc = 0;
6310             }
6311             break;
6312         }
6313         case RIL_CELL_INFO_TYPE_LTE: {
6314             rilCellIdentity.cellIdentityLte.tac =
6315                     convertResponseStringEntryToInt(response, 6, numStrings);
6316             rilCellIdentity.cellIdentityLte.pci =
6317                     convertResponseStringEntryToInt(response, 7, numStrings);
6318             rilCellIdentity.cellIdentityLte.ci =
6319                     convertResponseStringEntryToInt(response, 8, numStrings);
6320 
6321             if (numStrings >= 13) {
6322                 rilCellIdentity.cellIdentityLte.mcc =
6323                         convertResponseStringEntryToInt(response, 11, numStrings);
6324 
6325                 rilCellIdentity.cellIdentityLte.mnc =
6326                         convertResponseStringEntryToInt(response, 12, numStrings);
6327             } else {
6328                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6329                 rilCellIdentity.cellIdentityLte.mnc = 0;
6330                 rilCellIdentity.cellIdentityLte.mcc = 0;
6331             }
6332             break;
6333         }
6334         case RIL_CELL_INFO_TYPE_CDMA: {
6335             break;
6336         }
6337         default: {
6338             break;
6339         }
6340     }
6341 
6342     fillCellIdentityResponse_1_2(cellIdentity, rilCellIdentity);
6343 }
6344 
fillCellIdentityFromDataRegStateResponseString(CellIdentity & cellIdentity,int numStrings,char ** response)6345 void fillCellIdentityFromDataRegStateResponseString(CellIdentity &cellIdentity,
6346         int numStrings, char** response) {
6347 
6348     RIL_CellIdentity_v16 rilCellIdentity;
6349     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
6350 
6351     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
6352     switch(rilCellIdentity.cellInfoType) {
6353         case RIL_CELL_INFO_TYPE_GSM: {
6354             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6355             rilCellIdentity.cellIdentityGsm.lac =
6356                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6357 
6358             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6359             rilCellIdentity.cellIdentityGsm.cid =
6360                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6361 
6362             if (numStrings >= 13) {
6363                 rilCellIdentity.cellIdentityGsm.mcc =
6364                         convertResponseStringEntryToInt(response, 11, numStrings);
6365 
6366                 rilCellIdentity.cellIdentityGsm.mnc =
6367                         convertResponseStringEntryToInt(response, 12, numStrings);
6368             } else {
6369                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6370                 rilCellIdentity.cellIdentityGsm.mnc = 0;
6371                 rilCellIdentity.cellIdentityGsm.mcc = 0;
6372             }
6373             break;
6374         }
6375         case RIL_CELL_INFO_TYPE_WCDMA: {
6376             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6377             rilCellIdentity.cellIdentityWcdma.lac =
6378                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6379 
6380             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6381             rilCellIdentity.cellIdentityWcdma.cid =
6382                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6383 
6384             if (numStrings >= 13) {
6385                 rilCellIdentity.cellIdentityWcdma.mcc =
6386                         convertResponseStringEntryToInt(response, 11, numStrings);
6387 
6388                 rilCellIdentity.cellIdentityWcdma.mnc =
6389                         convertResponseStringEntryToInt(response, 12, numStrings);
6390             } else {
6391                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6392                 rilCellIdentity.cellIdentityWcdma.mnc = 0;
6393                 rilCellIdentity.cellIdentityWcdma.mcc = 0;
6394             }
6395 
6396             break;
6397         }
6398         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
6399             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6400             rilCellIdentity.cellIdentityTdscdma.lac =
6401                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6402 
6403             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6404             rilCellIdentity.cellIdentityTdscdma.cid =
6405                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6406 
6407             if (numStrings >= 13) {
6408                 rilCellIdentity.cellIdentityTdscdma.mcc =
6409                         convertResponseStringEntryToInt(response, 11, numStrings);
6410 
6411                 rilCellIdentity.cellIdentityTdscdma.mnc =
6412                         convertResponseStringEntryToInt(response, 12, numStrings);
6413             } else {
6414                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6415                 rilCellIdentity.cellIdentityTdscdma.mnc = 0;
6416                 rilCellIdentity.cellIdentityTdscdma.mcc = 0;
6417             }
6418             break;
6419         }
6420         case RIL_CELL_INFO_TYPE_LTE: {
6421             rilCellIdentity.cellIdentityLte.tac =
6422                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6423             rilCellIdentity.cellIdentityLte.ci =
6424                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6425 
6426             if (numStrings >= 13) {
6427                 rilCellIdentity.cellIdentityLte.mcc =
6428                         convertResponseStringEntryToInt(response, 11, numStrings);
6429 
6430                 rilCellIdentity.cellIdentityLte.mnc =
6431                         convertResponseStringEntryToInt(response, 12, numStrings);
6432             } else {
6433                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6434                 rilCellIdentity.cellIdentityLte.mnc = 0;
6435                 rilCellIdentity.cellIdentityLte.mcc = 0;
6436             }
6437             break;
6438         }
6439         // TODO add CDMA
6440         default: {
6441             break;
6442         }
6443     }
6444 
6445     fillCellIdentityResponse(cellIdentity, rilCellIdentity);
6446 }
6447 
getVoiceRegistrationStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6448 int radio_1_6::getVoiceRegistrationStateResponse(int slotId,
6449                                             int responseType, int serial, RIL_Errno e,
6450                                             void *response, size_t responseLen) {
6451 #if VDBG
6452     RLOGD("getVoiceRegistrationStateResponse: serial %d", serial);
6453 #endif
6454 
6455     if (radioService[slotId]->mRadioResponse != NULL ||
6456         radioService[slotId]->mRadioResponseV1_2 != NULL ||
6457         radioService[slotId]->mRadioResponseV1_5 != NULL ||
6458         radioService[slotId]->mRadioResponseV1_6 != NULL) {
6459         RadioResponseInfo responseInfo = {};
6460         populateResponseInfo(responseInfo, serial, responseType, e);
6461 
6462         VoiceRegStateResult voiceRegResponse = {};
6463         int numStrings = responseLen / sizeof(char *);
6464         if (response == NULL) {
6465                RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
6466                if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6467         } else if (s_vendorFunctions->version >= 15 &&
6468                    radioService[slotId]->mRadioResponseV1_6 != NULL) {
6469             ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6470             populateResponseInfo_1_6(responseInfo_1_6, serial, responseType, e);
6471             RegStateResultV1_6 regResponse = {};
6472             if (numStrings != 18) {
6473                 RLOGE("getVoiceRegistrationStateResponse_1_6 Invalid response: NULL");
6474                 if (e == RIL_E_SUCCESS) responseInfo_1_6.error =
6475                         ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
6476             } else {
6477                 char **resp = (char **) response;
6478                 regResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6479                 int rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6480                 regResponse.rat = (V1_4::RadioTechnology)rat;
6481                 if (rat == RADIO_TECH_EVDO_0 || rat == RADIO_TECH_EVDO_A ||
6482                     rat == RADIO_TECH_EVDO_B || rat == RADIO_TECH_1xRTT ||
6483                     rat == RADIO_TECH_IS95A || rat == RADIO_TECH_IS95B ||
6484                     rat == RADIO_TECH_EHRPD) {
6485                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6486                             Cdma2000RegistrationInfo cdmaInfo;
6487                     cdmaInfo.cssSupported = ATOI_NULL_HANDLED_DEF(resp[7], 0);
6488                     cdmaInfo.roamingIndicator = ATOI_NULL_HANDLED(resp[10]);
6489                     cdmaInfo.systemIsInPrl = (V1_5::PrlIndicator)ATOI_NULL_HANDLED_DEF(resp[11], 0);
6490                     cdmaInfo.defaultRoamingIndicator= ATOI_NULL_HANDLED_DEF(resp[12], 0);
6491                     regResponse.accessTechnologySpecificInfo.cdmaInfo(cdmaInfo);
6492                 } else if (rat == RADIO_TECH_NR) {
6493                     // rat is NR only for NR SA
6494                     V1_6::NrVopsInfo nrVopsInfo;
6495                     nrVopsInfo.vopsSupported =
6496                             ::android::hardware::radio::V1_6::VopsIndicator::VOPS_NOT_SUPPORTED;
6497                     nrVopsInfo.emcSupported =
6498                             ::android::hardware::radio::V1_6::EmcIndicator::EMC_NOT_SUPPORTED;
6499                     nrVopsInfo.emfSupported =
6500                             ::android::hardware::radio::V1_6::EmfIndicator::EMF_NOT_SUPPORTED;
6501                     regResponse.accessTechnologySpecificInfo.ngranNrVopsInfo(nrVopsInfo);
6502 
6503                 } else {
6504                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6505                         EutranRegistrationInfo eutranInfo;
6506                     if (rat == RADIO_TECH_LTE || rat == RADIO_TECH_LTE_CA) {
6507                         eutranInfo.lteVopsInfo.isVopsSupported = false;
6508                         eutranInfo.lteVopsInfo.isEmcBearerSupported = false;
6509                     }
6510                     eutranInfo.nrIndicators.isEndcAvailable = false;
6511                     eutranInfo.nrIndicators.isDcNrRestricted = false;
6512                     eutranInfo.nrIndicators.isEndcAvailable = false;
6513                     regResponse.accessTechnologySpecificInfo.eutranInfo(eutranInfo);
6514                 }
6515                 regResponse.reasonForDenial = (V1_5::RegistrationFailCause)
6516                         ATOI_NULL_HANDLED_DEF(resp[13], 0);
6517                 regResponse.registeredPlmn = convertCharPtrToHidlString(resp[17]);
6518 
6519                 fillCellIdentityFromVoiceRegStateResponseString(regResponse.cellIdentity,
6520                         numStrings, resp);
6521 
6522                 Return<void> retStatus =
6523                     radioService[slotId]
6524                         ->mRadioResponseV1_6
6525                         ->getVoiceRegistrationStateResponse_1_6(
6526                             responseInfo_1_6, regResponse);
6527                 radioService[slotId]->checkReturnStatus(retStatus);
6528             }
6529         } else if (s_vendorFunctions->version <= 14 &&
6530                    radioService[slotId]->mRadioResponseV1_5 != NULL) {
6531             RegStateResultV1_5 regResponse = {};
6532             if (numStrings != 18) {
6533                 RLOGE("getVoiceRegistrationStateResponse_1_5 Invalid response: NULL");
6534                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6535             } else {
6536                 char **resp = (char **) response;
6537                 regResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6538                 int rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6539                 regResponse.rat = (V1_4::RadioTechnology)rat;
6540                 if (rat == RADIO_TECH_EVDO_0 || rat == RADIO_TECH_EVDO_A ||
6541                     rat == RADIO_TECH_EVDO_B || rat == RADIO_TECH_1xRTT ||
6542                     rat == RADIO_TECH_IS95A || rat == RADIO_TECH_IS95B ||
6543                     rat == RADIO_TECH_EHRPD) {
6544                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6545                             Cdma2000RegistrationInfo cdmaInfo;
6546                     cdmaInfo.cssSupported = ATOI_NULL_HANDLED_DEF(resp[7], 0);
6547                     cdmaInfo.roamingIndicator = ATOI_NULL_HANDLED(resp[10]);
6548                     cdmaInfo.systemIsInPrl = (V1_5::PrlIndicator)ATOI_NULL_HANDLED_DEF(resp[11], 0);
6549                     cdmaInfo.defaultRoamingIndicator= ATOI_NULL_HANDLED_DEF(resp[12], 0);
6550                     regResponse.accessTechnologySpecificInfo.cdmaInfo(cdmaInfo);
6551                 } else {
6552                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6553                         EutranRegistrationInfo eutranInfo;
6554                     if (rat == RADIO_TECH_LTE || rat == RADIO_TECH_LTE_CA ||
6555                         rat == RADIO_TECH_NR) {
6556                         eutranInfo.lteVopsInfo.isVopsSupported = false;
6557                         eutranInfo.lteVopsInfo.isEmcBearerSupported = false;
6558                     }
6559                     eutranInfo.nrIndicators.isEndcAvailable = false;
6560                     eutranInfo.nrIndicators.isDcNrRestricted = false;
6561                     eutranInfo.nrIndicators.isEndcAvailable = false;
6562                     regResponse.accessTechnologySpecificInfo.eutranInfo(eutranInfo);
6563                 }
6564                 regResponse.reasonForDenial = (V1_5::RegistrationFailCause)
6565                         ATOI_NULL_HANDLED_DEF(resp[13], 0);
6566                 regResponse.registeredPlmn = convertCharPtrToHidlString(resp[17]);
6567 
6568                 fillCellIdentityFromVoiceRegStateResponseString(regResponse.cellIdentity,
6569                         numStrings, resp);
6570 
6571                 Return<void> retStatus =
6572                     radioService[slotId]
6573                         ->mRadioResponseV1_5
6574                         ->getVoiceRegistrationStateResponse_1_5(
6575                             responseInfo, regResponse);
6576                 radioService[slotId]->checkReturnStatus(retStatus);
6577             }
6578         } else if (s_vendorFunctions->version <= 14 &&
6579                       radioService[slotId]->mRadioResponseV1_2 != NULL) {
6580             V1_2::VoiceRegStateResult voiceRegResponse = {};
6581             int numStrings = responseLen / sizeof(char *);
6582             if (numStrings != 18) {
6583                 RLOGE("getVoiceRegistrationStateResponse_1_21 Invalid response: NULL");
6584                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6585             } else {
6586                 char **resp = (char **) response;
6587                 voiceRegResponse.regState = (RegState) ATOI_NULL_HANDLED_DEF(resp[0], 4);
6588                 voiceRegResponse.rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6589                 voiceRegResponse.cssSupported = ATOI_NULL_HANDLED_DEF(resp[7], 0);
6590                 voiceRegResponse.roamingIndicator = ATOI_NULL_HANDLED(resp[10]);
6591                 voiceRegResponse.systemIsInPrl = ATOI_NULL_HANDLED_DEF(resp[11], 0);
6592                 voiceRegResponse.defaultRoamingIndicator = ATOI_NULL_HANDLED_DEF(resp[12], 0);
6593                 voiceRegResponse.reasonForDenial = ATOI_NULL_HANDLED_DEF(resp[13], 0);
6594                 fillCellIdentityFromVoiceRegStateResponseString_1_2(
6595                         voiceRegResponse.cellIdentity, numStrings, resp);
6596               }
6597             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2->
6598                     getVoiceRegistrationStateResponse_1_2(responseInfo, voiceRegResponse);
6599             radioService[slotId]->checkReturnStatus(retStatus);
6600         } else {
6601               RIL_VoiceRegistrationStateResponse *voiceRegState =
6602                     (RIL_VoiceRegistrationStateResponse *)response;
6603               if (responseLen != sizeof(RIL_VoiceRegistrationStateResponse)) {
6604                   RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
6605                   if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6606               } else {
6607                   voiceRegResponse.regState = (RegState) voiceRegState->regState;
6608                   voiceRegResponse.rat = voiceRegState->rat;;
6609                   voiceRegResponse.cssSupported = voiceRegState->cssSupported;
6610                   voiceRegResponse.roamingIndicator = voiceRegState->roamingIndicator;
6611                   voiceRegResponse.systemIsInPrl = voiceRegState->systemIsInPrl;
6612                   voiceRegResponse.defaultRoamingIndicator = voiceRegState->defaultRoamingIndicator;
6613                   voiceRegResponse.reasonForDenial = voiceRegState->reasonForDenial;
6614                   fillCellIdentityResponse(voiceRegResponse.cellIdentity,
6615                           voiceRegState->cellIdentity);
6616               }
6617               Return<void> retStatus =
6618                       radioService[slotId]->mRadioResponse->getVoiceRegistrationStateResponse(
6619                       responseInfo, voiceRegResponse);
6620               radioService[slotId]->checkReturnStatus(retStatus);
6621         }
6622 
6623     } else {
6624         RLOGE("getVoiceRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
6625                 slotId);
6626     }
6627     return 0;
6628 }
6629 
getDataRegistrationStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6630 int radio_1_6::getDataRegistrationStateResponse(int slotId, int responseType, int serial,
6631                                                 RIL_Errno e, void* response, size_t responseLen) {
6632 #if VDBG
6633     RLOGD("getDataRegistrationStateResponse: serial %d", serial);
6634 #endif
6635     if (radioService[slotId]->mRadioResponse != NULL ||
6636         radioService[slotId]->mRadioResponseV1_2 != NULL ||
6637         radioService[slotId]->mRadioResponseV1_5 != NULL ||
6638         radioService[slotId]->mRadioResponseV1_6 != NULL) {
6639         RadioResponseInfo responseInfo = {};
6640         DataRegStateResult dataRegResponse = {};
6641         populateResponseInfo(responseInfo, serial, responseType, e);
6642         if (response == NULL) {
6643             RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6644             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6645         } else if (s_vendorFunctions->version >= 15 &&
6646                    radioService[slotId]->mRadioResponseV1_6 != NULL) {
6647             ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6648             populateResponseInfo_1_6(responseInfo_1_6, serial, responseType, e);
6649             RegStateResultV1_6 regResponse = {};
6650             int numStrings = responseLen / sizeof(char *);
6651             if ((numStrings != 6) && (numStrings != 11) && (numStrings != 14)) {
6652                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6653                 if (e == RIL_E_SUCCESS) responseInfo_1_6.error =
6654                         ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
6655             } else {
6656                 char **resp = (char **) response;
6657                 int rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6658                 regResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6659                 regResponse.rat = (V1_4::RadioTechnology)rat;
6660                 regResponse.reasonForDenial =
6661                         (V1_5::RegistrationFailCause)ATOI_NULL_HANDLED(resp[4]);
6662                 if (numStrings > 13) {
6663                     regResponse.registeredPlmn = convertCharPtrToHidlString(resp[13]);
6664                 }
6665 
6666                 fillCellIdentityFromDataRegStateResponseString_1_5(regResponse.cellIdentity,
6667                         numStrings, resp);
6668                 if (rat == RADIO_TECH_NR) {
6669                     // rat is NR only for NR SA
6670                     V1_6::NrVopsInfo nrVopsInfo;
6671                     nrVopsInfo.vopsSupported =
6672                             ::android::hardware::radio::V1_6::VopsIndicator::VOPS_NOT_SUPPORTED;
6673                     nrVopsInfo.emcSupported =
6674                             ::android::hardware::radio::V1_6::EmcIndicator::EMC_NOT_SUPPORTED;
6675                     nrVopsInfo.emfSupported =
6676                             ::android::hardware::radio::V1_6::EmfIndicator::EMF_NOT_SUPPORTED;
6677                     regResponse.accessTechnologySpecificInfo.ngranNrVopsInfo(nrVopsInfo);
6678 
6679                 } else {
6680                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6681                             EutranRegistrationInfo eutranInfo;
6682                     if (rat == RADIO_TECH_LTE || rat == RADIO_TECH_LTE_CA) {
6683                         eutranInfo.lteVopsInfo.isVopsSupported = false;
6684                         eutranInfo.lteVopsInfo.isEmcBearerSupported = false;
6685                     }
6686                     eutranInfo.nrIndicators.isEndcAvailable = false;
6687                     eutranInfo.nrIndicators.isDcNrRestricted = false;
6688                     eutranInfo.nrIndicators.isEndcAvailable = false;
6689                     regResponse.accessTechnologySpecificInfo.eutranInfo(eutranInfo);
6690                 }
6691 
6692                 Return<void> retStatus =
6693                         radioService[slotId]
6694                                 ->mRadioResponseV1_6->getDataRegistrationStateResponse_1_6(
6695                                         responseInfo_1_6, regResponse);
6696                 radioService[slotId]->checkReturnStatus(retStatus);
6697                 return 0;
6698             }
6699         } else if (s_vendorFunctions->version <= 14 &&
6700                    radioService[slotId]->mRadioResponseV1_5 != NULL) {
6701             RegStateResultV1_5 regResponse = {};
6702             int numStrings = responseLen / sizeof(char *);
6703             if ((numStrings != 6) && (numStrings != 11) && (numStrings != 14)) {
6704                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6705                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6706             } else {
6707                 char **resp = (char **) response;
6708                 int rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6709                 regResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6710                 regResponse.rat = (V1_4::RadioTechnology)rat;
6711                 regResponse.reasonForDenial =
6712                         (V1_5::RegistrationFailCause)ATOI_NULL_HANDLED(resp[4]);
6713                 if (numStrings > 13) {
6714                     regResponse.registeredPlmn = convertCharPtrToHidlString(resp[13]);
6715                 }
6716 
6717                 V1_5::RegStateResult::AccessTechnologySpecificInfo::
6718                         EutranRegistrationInfo eutranInfo;
6719                 if (rat == RADIO_TECH_LTE || rat == RADIO_TECH_LTE_CA ||
6720                     rat == RADIO_TECH_NR) {
6721                     eutranInfo.lteVopsInfo.isVopsSupported = false;
6722                     eutranInfo.lteVopsInfo.isEmcBearerSupported = false;
6723                 }
6724                 eutranInfo.nrIndicators.isEndcAvailable = false;
6725                 eutranInfo.nrIndicators.isDcNrRestricted = false;
6726                 eutranInfo.nrIndicators.isEndcAvailable = false;
6727                 regResponse.accessTechnologySpecificInfo.eutranInfo(eutranInfo);
6728 
6729                 fillCellIdentityFromDataRegStateResponseString_1_5(regResponse.cellIdentity,
6730                         numStrings, resp);
6731 
6732                 Return<void> retStatus =
6733                         radioService[slotId]
6734                                 ->mRadioResponseV1_5->getDataRegistrationStateResponse_1_5(
6735                                         responseInfo, regResponse);
6736                 radioService[slotId]->checkReturnStatus(retStatus);
6737                 return 0;
6738             }
6739         } else if (s_vendorFunctions->version <= 14 &&
6740                     radioService[slotId]->mRadioResponseV1_2 != NULL) {
6741             V1_2::DataRegStateResult dataRegResponse = {};
6742             int numStrings = responseLen / sizeof(char *);
6743             if ((numStrings != 11) && (numStrings != 13) && (numStrings != 14)) {
6744                 RLOGE("getDataRegistrationStateResponse_1_2 Invalid response: NULL");
6745                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6746             } else {
6747                 char **resp = (char **)response;
6748                 dataRegResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6749                 dataRegResponse.rat =  ATOI_NULL_HANDLED_DEF(resp[3], 0);
6750                 dataRegResponse.reasonDataDenied =  ATOI_NULL_HANDLED(resp[4]);
6751                 dataRegResponse.maxDataCalls =  ATOI_NULL_HANDLED_DEF(resp[5], 1);
6752                 fillCellIdentityFromDataRegStateResponseString_1_2(dataRegResponse.cellIdentity,
6753                         numStrings, resp);
6754                 Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2->
6755                         getDataRegistrationStateResponse_1_2(responseInfo, dataRegResponse);
6756                 radioService[slotId]->checkReturnStatus(retStatus);
6757                 return 0;
6758             }
6759       } else if (s_vendorFunctions->version <= 14) {
6760             int numStrings = responseLen / sizeof(char *);
6761             if ((numStrings != 11) && (numStrings != 13) && (numStrings != 14)) {
6762                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6763                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6764             } else {
6765                 char **resp = (char **) response;
6766                 dataRegResponse.regState = (RegState) ATOI_NULL_HANDLED_DEF(resp[0], 4);
6767                 dataRegResponse.rat =  ATOI_NULL_HANDLED_DEF(resp[3], 0);
6768                 dataRegResponse.reasonDataDenied =  ATOI_NULL_HANDLED(resp[4]);
6769                 dataRegResponse.maxDataCalls =  ATOI_NULL_HANDLED_DEF(resp[5], 1);
6770                 fillCellIdentityFromDataRegStateResponseString(dataRegResponse.cellIdentity,
6771                         numStrings, resp);
6772             }
6773         } else {
6774             RIL_DataRegistrationStateResponse *dataRegState =
6775                     (RIL_DataRegistrationStateResponse *)response;
6776 
6777             if (responseLen != sizeof(RIL_DataRegistrationStateResponse)) {
6778                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6779                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6780             } else {
6781                 dataRegResponse.regState = (RegState) dataRegState->regState;
6782                 dataRegResponse.rat = dataRegState->rat;
6783                 dataRegResponse.reasonDataDenied = dataRegState->reasonDataDenied;
6784                 dataRegResponse.maxDataCalls = dataRegState->maxDataCalls;
6785                 fillCellIdentityResponse(dataRegResponse.cellIdentity, dataRegState->cellIdentity);
6786             }
6787         }
6788 
6789         Return<void> retStatus =
6790                 radioService[slotId]->mRadioResponse->getDataRegistrationStateResponse(
6791                         responseInfo, dataRegResponse);
6792         radioService[slotId]->checkReturnStatus(retStatus);
6793     } else {
6794         RLOGE("getDataRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
6795                 slotId);
6796     }
6797 
6798     return 0;
6799 }
6800 
getOperatorResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6801 int radio_1_6::getOperatorResponse(int slotId,
6802                               int responseType, int serial, RIL_Errno e, void *response,
6803                               size_t responseLen) {
6804 #if VDBG
6805     RLOGD("getOperatorResponse: serial %d", serial);
6806 #endif
6807 
6808     if (radioService[slotId]->mRadioResponse != NULL) {
6809         RadioResponseInfo responseInfo = {};
6810         populateResponseInfo(responseInfo, serial, responseType, e);
6811         hidl_string longName;
6812         hidl_string shortName;
6813         hidl_string numeric;
6814         int numStrings = responseLen / sizeof(char *);
6815         if (response == NULL || numStrings != 3) {
6816             RLOGE("getOperatorResponse Invalid response: NULL");
6817             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6818 
6819         } else {
6820             char **resp = (char **) response;
6821             longName = convertCharPtrToHidlString(resp[0]);
6822             shortName = convertCharPtrToHidlString(resp[1]);
6823             numeric = convertCharPtrToHidlString(resp[2]);
6824         }
6825         Return<void> retStatus = radioService[slotId]->mRadioResponse->getOperatorResponse(
6826                 responseInfo, longName, shortName, numeric);
6827         radioService[slotId]->checkReturnStatus(retStatus);
6828     } else {
6829         RLOGE("getOperatorResponse: radioService[%d]->mRadioResponse == NULL",
6830                 slotId);
6831     }
6832 
6833     return 0;
6834 }
6835 
setRadioPowerResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6836 int radio_1_6::setRadioPowerResponse(int slotId,
6837                                 int responseType, int serial, RIL_Errno e, void *response,
6838                                 size_t responseLen) {
6839 #if VDBG
6840     RLOGD("setRadioPowerResponse: serial %d", serial);
6841 #endif
6842     RadioResponseInfo responseInfo = {};
6843     ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6844     populateResponseInfo(responseInfo, serial, responseType, e);
6845     populateResponseInfo_1_6(responseInfo_1_6, serial, responseType, e);
6846 
6847     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
6848         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
6849                 ->setRadioPowerResponse_1_6(responseInfo_1_6);
6850         radioService[slotId]->checkReturnStatus(retStatus);
6851     } else if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
6852         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
6853                 ->setRadioPowerResponse_1_5(responseInfo);
6854         radioService[slotId]->checkReturnStatus(retStatus);
6855     } else if (radioService[slotId]->mRadioResponse != NULL) {
6856         Return<void> retStatus = radioService[slotId]->mRadioResponse
6857                 ->setRadioPowerResponse(responseInfo);
6858         radioService[slotId]->checkReturnStatus(retStatus);
6859     } else {
6860         RLOGE("setRadioPowerResponse: radioService[%d]->mRadioResponse == NULL", slotId);
6861     }
6862 
6863     return 0;
6864 }
6865 
sendDtmfResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6866 int radio_1_6::sendDtmfResponse(int slotId,
6867                            int responseType, int serial, RIL_Errno e, void *response,
6868                            size_t responseLen) {
6869 #if VDBG
6870     RLOGD("sendDtmfResponse: serial %d", serial);
6871 #endif
6872 
6873     if (radioService[slotId]->mRadioResponse != NULL) {
6874         RadioResponseInfo responseInfo = {};
6875         populateResponseInfo(responseInfo, serial, responseType, e);
6876         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendDtmfResponse(
6877                 responseInfo);
6878         radioService[slotId]->checkReturnStatus(retStatus);
6879     } else {
6880         RLOGE("sendDtmfResponse: radioService[%d]->mRadioResponse == NULL",
6881                 slotId);
6882     }
6883 
6884     return 0;
6885 }
6886 
makeSendSmsResult(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)6887 SendSmsResult makeSendSmsResult(RadioResponseInfo& responseInfo, int serial, int responseType,
6888                                 RIL_Errno e, void *response, size_t responseLen) {
6889     populateResponseInfo(responseInfo, serial, responseType, e);
6890     SendSmsResult result = {};
6891 
6892     if (response == NULL || responseLen != sizeof(RIL_SMS_Response)) {
6893         RLOGE("Invalid response: NULL");
6894         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6895         result.ackPDU = hidl_string();
6896     } else {
6897         RIL_SMS_Response *resp = (RIL_SMS_Response *) response;
6898         result.messageRef = resp->messageRef;
6899         result.ackPDU = convertCharPtrToHidlString(resp->ackPDU);
6900         result.errorCode = resp->errorCode;
6901     }
6902     return result;
6903 }
6904 
makeSendSmsResult_1_6(::android::hardware::radio::V1_6::RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)6905 SendSmsResult makeSendSmsResult_1_6(
6906         ::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo, int serial,
6907         int responseType, RIL_Errno e, void *response, size_t responseLen) {
6908     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
6909     SendSmsResult result = {};
6910 
6911     if (response == NULL || responseLen != sizeof(RIL_SMS_Response)) {
6912         RLOGE("Invalid response: NULL");
6913         if (e == RIL_E_SUCCESS) {
6914             responseInfo.error = ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
6915         }
6916         result.ackPDU = hidl_string();
6917     } else {
6918         RIL_SMS_Response *resp = (RIL_SMS_Response *) response;
6919         result.messageRef = resp->messageRef;
6920         result.ackPDU = convertCharPtrToHidlString(resp->ackPDU);
6921         result.errorCode = resp->errorCode;
6922     }
6923     return result;
6924 }
6925 
sendSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6926 int radio_1_6::sendSmsResponse(int slotId,
6927                           int responseType, int serial, RIL_Errno e, void *response,
6928                           size_t responseLen) {
6929 #if VDBG
6930     RLOGD("sendSmsResponse: serial %d", serial);
6931 #endif
6932 
6933     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
6934         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6935         SendSmsResult result = makeSendSmsResult_1_6(responseInfo_1_6, serial, responseType, e, response,
6936                 responseLen);
6937 
6938         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
6939                 ->sendSmsResponse_1_6(responseInfo_1_6, result);
6940         radioService[slotId]->checkReturnStatus(retStatus);
6941     } else if (radioService[slotId]->mRadioResponse != NULL) {
6942         RadioResponseInfo responseInfo = {};
6943         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
6944                 responseLen);
6945 
6946         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendSmsResponse(responseInfo,
6947                 result);
6948         radioService[slotId]->checkReturnStatus(retStatus);
6949     } else {
6950         RLOGE("sendSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
6951     }
6952 
6953     return 0;
6954 }
6955 
sendSmsExpectMoreResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6956 int radio_1_6::sendSmsExpectMoreResponse(int slotId,
6957                                     int responseType, int serial, RIL_Errno e, void *response,
6958                                     size_t responseLen) {
6959 #if VDBG
6960     RLOGD("sendSmsExpectMoreResponse: serial %d", serial);
6961 #endif
6962 
6963     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
6964         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6965         SendSmsResult result = makeSendSmsResult_1_6(responseInfo_1_6, serial, responseType, e, response,
6966                 responseLen);
6967 
6968         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
6969                 ->sendSmsExpectMoreResponse_1_6(responseInfo_1_6, result);
6970         radioService[slotId]->checkReturnStatus(retStatus);
6971     } else if (radioService[slotId]->mRadioResponse != NULL) {
6972         RadioResponseInfo responseInfo = {};
6973         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
6974                 responseLen);
6975 
6976         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendSMSExpectMoreResponse(
6977                 responseInfo, result);
6978         radioService[slotId]->checkReturnStatus(retStatus);
6979     } else {
6980         RLOGE("sendSMSExpectMoreResponse: radioService[%d]->mRadioResponse == NULL", slotId);
6981     }
6982 
6983     return 0;
6984 }
6985 
setupDataCallResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6986 int radio_1_6::setupDataCallResponse(int slotId,
6987                                  int responseType, int serial, RIL_Errno e, void *response,
6988                                  size_t responseLen) {
6989 #if VDBG
6990     RLOGD("setupDataCallResponse: serial %d", serial);
6991 #endif
6992     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
6993         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6994         populateResponseInfo_1_6(responseInfo_1_6, serial, responseType, e);
6995         ::android::hardware::radio::V1_6::SetupDataCallResult result;
6996         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
6997             if (response != NULL) {
6998                 RLOGE("setupDataCallResponse_1_6: Invalid response");
6999                 if (e == RIL_E_SUCCESS) responseInfo_1_6.error =
7000                         ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
7001             }
7002             result.cause = ::android::hardware::radio::V1_6::DataCallFailCause::ERROR_UNSPECIFIED;
7003             result.type = ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
7004             result.ifname = hidl_string();
7005             result.addresses = hidl_vec<::android::hardware::radio::V1_5::LinkAddress>();
7006             result.dnses = hidl_vec<hidl_string>();
7007             result.gateways = hidl_vec<hidl_string>();
7008             result.pcscf = hidl_vec<hidl_string>();
7009             result.trafficDescriptors =
7010                     hidl_vec<::android::hardware::radio::V1_6::TrafficDescriptor>();
7011         } else {
7012             convertRilDataCallToHal((RIL_Data_Call_Response_v11*)response, result);
7013         }
7014 
7015         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6->setupDataCallResponse_1_6(
7016                 responseInfo_1_6, result);
7017         radioService[slotId]->checkReturnStatus(retStatus);
7018     } else if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
7019         RadioResponseInfo responseInfo = {};
7020         populateResponseInfo(responseInfo, serial, responseType, e);
7021         ::android::hardware::radio::V1_5::SetupDataCallResult result;
7022         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
7023             if (response != NULL) {
7024                 RLOGE("setupDataCallResponse_1_5: Invalid response");
7025                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7026             }
7027             result.cause = ::android::hardware::radio::V1_4::DataCallFailCause::ERROR_UNSPECIFIED;
7028             result.type = ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
7029             result.ifname = hidl_string();
7030             result.addresses = hidl_vec<::android::hardware::radio::V1_5::LinkAddress>();
7031             result.dnses = hidl_vec<hidl_string>();
7032             result.gateways = hidl_vec<hidl_string>();
7033             result.pcscf = hidl_vec<hidl_string>();
7034         } else {
7035             convertRilDataCallToHal((RIL_Data_Call_Response_v11*)response, result);
7036         }
7037 
7038         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5->setupDataCallResponse_1_5(
7039                 responseInfo, result);
7040         radioService[slotId]->checkReturnStatus(retStatus);
7041     } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
7042         RadioResponseInfo responseInfo = {};
7043         populateResponseInfo(responseInfo, serial, responseType, e);
7044         ::android::hardware::radio::V1_4::SetupDataCallResult result;
7045         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
7046             if (response != NULL) {
7047                 RLOGE("setupDataCallResponse_1_4: Invalid response");
7048                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7049             }
7050             result.cause = ::android::hardware::radio::V1_4::DataCallFailCause::ERROR_UNSPECIFIED;
7051             result.type = ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
7052             result.ifname = hidl_string();
7053             result.addresses = hidl_vec<hidl_string>();
7054             result.dnses = hidl_vec<hidl_string>();
7055             result.gateways = hidl_vec<hidl_string>();
7056             result.pcscf = hidl_vec<hidl_string>();
7057         } else {
7058             convertRilDataCallToHal((RIL_Data_Call_Response_v11 *) response, result);
7059         }
7060 
7061         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4->setupDataCallResponse_1_4(
7062                 responseInfo, result);
7063         radioService[slotId]->checkReturnStatus(retStatus);
7064     } else if (radioService[slotId]->mRadioResponse != NULL) {
7065         RadioResponseInfo responseInfo = {};
7066         populateResponseInfo(responseInfo, serial, responseType, e);
7067 
7068         SetupDataCallResult result = {};
7069         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
7070            if (response != NULL) {
7071                RLOGE("setupDataCallResponse: Invalid response");
7072                if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7073            }
7074            result.status = DataCallFailCause::ERROR_UNSPECIFIED;
7075            result.type = hidl_string();
7076            result.ifname = hidl_string();
7077            result.addresses = hidl_string();
7078            result.dnses = hidl_string();
7079            result.gateways = hidl_string();
7080            result.pcscf = hidl_string();
7081         } else {
7082            convertRilDataCallToHal((RIL_Data_Call_Response_v11 *) response, result);
7083         }
7084 
7085         Return<void> retStatus = radioService[slotId]->mRadioResponse->setupDataCallResponse(
7086                responseInfo, result);
7087         radioService[slotId]->checkReturnStatus(retStatus);
7088     } else {
7089         RLOGE("setupDataCallResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7090     }
7091 
7092     return 0;
7093 }
7094 
responseIccIo(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)7095 IccIoResult responseIccIo(RadioResponseInfo& responseInfo, int serial, int responseType,
7096                            RIL_Errno e, void *response, size_t responseLen) {
7097     populateResponseInfo(responseInfo, serial, responseType, e);
7098     IccIoResult result = {};
7099 
7100     if (response == NULL || responseLen != sizeof(RIL_SIM_IO_Response)) {
7101         RLOGE("Invalid response: NULL");
7102         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7103         result.simResponse = hidl_string();
7104     } else {
7105         RIL_SIM_IO_Response *resp = (RIL_SIM_IO_Response *) response;
7106         result.sw1 = resp->sw1;
7107         result.sw2 = resp->sw2;
7108         result.simResponse = convertCharPtrToHidlString(resp->simResponse);
7109     }
7110     return result;
7111 }
7112 
iccIOForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7113 int radio_1_6::iccIOForAppResponse(int slotId,
7114                       int responseType, int serial, RIL_Errno e, void *response,
7115                       size_t responseLen) {
7116 #if VDBG
7117     RLOGD("iccIOForAppResponse: serial %d", serial);
7118 #endif
7119 
7120     if (radioService[slotId]->mRadioResponse != NULL) {
7121         RadioResponseInfo responseInfo = {};
7122         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
7123                 responseLen);
7124 
7125         Return<void> retStatus = radioService[slotId]->mRadioResponse->iccIOForAppResponse(
7126                 responseInfo, result);
7127         radioService[slotId]->checkReturnStatus(retStatus);
7128     } else {
7129         RLOGE("iccIOForAppResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7130     }
7131 
7132     return 0;
7133 }
7134 
sendUssdResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7135 int radio_1_6::sendUssdResponse(int slotId,
7136                            int responseType, int serial, RIL_Errno e, void *response,
7137                            size_t responseLen) {
7138 #if VDBG
7139     RLOGD("sendUssdResponse: serial %d", serial);
7140 #endif
7141 
7142     if (radioService[slotId]->mRadioResponse != NULL) {
7143         RadioResponseInfo responseInfo = {};
7144         populateResponseInfo(responseInfo, serial, responseType, e);
7145         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendUssdResponse(
7146                 responseInfo);
7147         radioService[slotId]->checkReturnStatus(retStatus);
7148     } else {
7149         RLOGE("sendUssdResponse: radioService[%d]->mRadioResponse == NULL",
7150                 slotId);
7151     }
7152 
7153     return 0;
7154 }
7155 
cancelPendingUssdResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7156 int radio_1_6::cancelPendingUssdResponse(int slotId,
7157                                     int responseType, int serial, RIL_Errno e, void *response,
7158                                     size_t responseLen) {
7159 #if VDBG
7160     RLOGD("cancelPendingUssdResponse: serial %d", serial);
7161 #endif
7162 
7163     if (radioService[slotId]->mRadioResponse != NULL) {
7164         RadioResponseInfo responseInfo = {};
7165         populateResponseInfo(responseInfo, serial, responseType, e);
7166         Return<void> retStatus = radioService[slotId]->mRadioResponse->cancelPendingUssdResponse(
7167                 responseInfo);
7168         radioService[slotId]->checkReturnStatus(retStatus);
7169     } else {
7170         RLOGE("cancelPendingUssdResponse: radioService[%d]->mRadioResponse == NULL",
7171                 slotId);
7172     }
7173 
7174     return 0;
7175 }
7176 
getClirResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7177 int radio_1_6::getClirResponse(int slotId,
7178                               int responseType, int serial, RIL_Errno e, void *response,
7179                               size_t responseLen) {
7180 #if VDBG
7181     RLOGD("getClirResponse: serial %d", serial);
7182 #endif
7183 
7184     if (radioService[slotId]->mRadioResponse != NULL) {
7185         RadioResponseInfo responseInfo = {};
7186         populateResponseInfo(responseInfo, serial, responseType, e);
7187         int n = -1, m = -1;
7188         int numInts = responseLen / sizeof(int);
7189         if (response == NULL || numInts != 2) {
7190             RLOGE("getClirResponse Invalid response: NULL");
7191             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7192         } else {
7193             int *pInt = (int *) response;
7194             n = pInt[0];
7195             m = pInt[1];
7196         }
7197         Return<void> retStatus = radioService[slotId]->mRadioResponse->getClirResponse(responseInfo,
7198                 n, m);
7199         radioService[slotId]->checkReturnStatus(retStatus);
7200     } else {
7201         RLOGE("getClirResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7202     }
7203 
7204     return 0;
7205 }
7206 
setClirResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7207 int radio_1_6::setClirResponse(int slotId,
7208                           int responseType, int serial, RIL_Errno e, void *response,
7209                           size_t responseLen) {
7210 #if VDBG
7211     RLOGD("setClirResponse: serial %d", serial);
7212 #endif
7213 
7214     if (radioService[slotId]->mRadioResponse != NULL) {
7215         RadioResponseInfo responseInfo = {};
7216         populateResponseInfo(responseInfo, serial, responseType, e);
7217         Return<void> retStatus = radioService[slotId]->mRadioResponse->setClirResponse(
7218                 responseInfo);
7219         radioService[slotId]->checkReturnStatus(retStatus);
7220     } else {
7221         RLOGE("setClirResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7222     }
7223 
7224     return 0;
7225 }
7226 
getCallForwardStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7227 int radio_1_6::getCallForwardStatusResponse(int slotId,
7228                                        int responseType, int serial, RIL_Errno e,
7229                                        void *response, size_t responseLen) {
7230 #if VDBG
7231     RLOGD("getCallForwardStatusResponse: serial %d", serial);
7232 #endif
7233 
7234     if (radioService[slotId]->mRadioResponse != NULL) {
7235         RadioResponseInfo responseInfo = {};
7236         populateResponseInfo(responseInfo, serial, responseType, e);
7237         hidl_vec<CallForwardInfo> callForwardInfos;
7238 
7239         if ((response == NULL && responseLen != 0)
7240                 || responseLen % sizeof(RIL_CallForwardInfo *) != 0) {
7241             RLOGE("getCallForwardStatusResponse Invalid response: NULL");
7242             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7243         } else {
7244             int num = responseLen / sizeof(RIL_CallForwardInfo *);
7245             callForwardInfos.resize(num);
7246             for (int i = 0 ; i < num; i++) {
7247                 RIL_CallForwardInfo *resp = ((RIL_CallForwardInfo **) response)[i];
7248                 callForwardInfos[i].status = (CallForwardInfoStatus) resp->status;
7249                 callForwardInfos[i].reason = resp->reason;
7250                 callForwardInfos[i].serviceClass = resp->serviceClass;
7251                 callForwardInfos[i].toa = resp->toa;
7252                 callForwardInfos[i].number = convertCharPtrToHidlString(resp->number);
7253                 callForwardInfos[i].timeSeconds = resp->timeSeconds;
7254             }
7255         }
7256 
7257         Return<void> retStatus = radioService[slotId]->mRadioResponse->getCallForwardStatusResponse(
7258                 responseInfo, callForwardInfos);
7259         radioService[slotId]->checkReturnStatus(retStatus);
7260     } else {
7261         RLOGE("getCallForwardStatusResponse: radioService[%d]->mRadioResponse == NULL",
7262                 slotId);
7263     }
7264 
7265     return 0;
7266 }
7267 
setCallForwardResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7268 int radio_1_6::setCallForwardResponse(int slotId,
7269                                  int responseType, int serial, RIL_Errno e, void *response,
7270                                  size_t responseLen) {
7271 #if VDBG
7272     RLOGD("setCallForwardResponse: serial %d", serial);
7273 #endif
7274 
7275     if (radioService[slotId]->mRadioResponse != NULL) {
7276         RadioResponseInfo responseInfo = {};
7277         populateResponseInfo(responseInfo, serial, responseType, e);
7278         Return<void> retStatus = radioService[slotId]->mRadioResponse->setCallForwardResponse(
7279                 responseInfo);
7280         radioService[slotId]->checkReturnStatus(retStatus);
7281     } else {
7282         RLOGE("setCallForwardResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7283     }
7284 
7285     return 0;
7286 }
7287 
getCallWaitingResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7288 int radio_1_6::getCallWaitingResponse(int slotId,
7289                                  int responseType, int serial, RIL_Errno e, void *response,
7290                                  size_t responseLen) {
7291 #if VDBG
7292     RLOGD("getCallWaitingResponse: serial %d", serial);
7293 #endif
7294 
7295     if (radioService[slotId]->mRadioResponse != NULL) {
7296         RadioResponseInfo responseInfo = {};
7297         populateResponseInfo(responseInfo, serial, responseType, e);
7298         bool enable = false;
7299         int serviceClass = -1;
7300         int numInts = responseLen / sizeof(int);
7301         if (response == NULL || numInts != 2) {
7302             RLOGE("getCallWaitingResponse Invalid response: NULL");
7303             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7304         } else {
7305             int *pInt = (int *) response;
7306             enable = pInt[0] == 1 ? true : false;
7307             serviceClass = pInt[1];
7308         }
7309         Return<void> retStatus = radioService[slotId]->mRadioResponse->getCallWaitingResponse(
7310                 responseInfo, enable, serviceClass);
7311         radioService[slotId]->checkReturnStatus(retStatus);
7312     } else {
7313         RLOGE("getCallWaitingResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7314     }
7315 
7316     return 0;
7317 }
7318 
setCallWaitingResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7319 int radio_1_6::setCallWaitingResponse(int slotId,
7320                                  int responseType, int serial, RIL_Errno e, void *response,
7321                                  size_t responseLen) {
7322 #if VDBG
7323     RLOGD("setCallWaitingResponse: serial %d", serial);
7324 #endif
7325 
7326     if (radioService[slotId]->mRadioResponse != NULL) {
7327         RadioResponseInfo responseInfo = {};
7328         populateResponseInfo(responseInfo, serial, responseType, e);
7329         Return<void> retStatus = radioService[slotId]->mRadioResponse->setCallWaitingResponse(
7330                 responseInfo);
7331         radioService[slotId]->checkReturnStatus(retStatus);
7332     } else {
7333         RLOGE("setCallWaitingResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7334     }
7335 
7336     return 0;
7337 }
7338 
acknowledgeLastIncomingGsmSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7339 int radio_1_6::acknowledgeLastIncomingGsmSmsResponse(int slotId,
7340                                                 int responseType, int serial, RIL_Errno e,
7341                                                 void *response, size_t responseLen) {
7342 #if VDBG
7343     RLOGD("acknowledgeLastIncomingGsmSmsResponse: serial %d", serial);
7344 #endif
7345 
7346     if (radioService[slotId]->mRadioResponse != NULL) {
7347         RadioResponseInfo responseInfo = {};
7348         populateResponseInfo(responseInfo, serial, responseType, e);
7349         Return<void> retStatus =
7350                 radioService[slotId]->mRadioResponse->acknowledgeLastIncomingGsmSmsResponse(
7351                 responseInfo);
7352         radioService[slotId]->checkReturnStatus(retStatus);
7353     } else {
7354         RLOGE("acknowledgeLastIncomingGsmSmsResponse: radioService[%d]->mRadioResponse "
7355                 "== NULL", slotId);
7356     }
7357 
7358     return 0;
7359 }
7360 
acceptCallResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7361 int radio_1_6::acceptCallResponse(int slotId,
7362                              int responseType, int serial, RIL_Errno e,
7363                              void *response, size_t responseLen) {
7364 #if VDBG
7365     RLOGD("acceptCallResponse: serial %d", serial);
7366 #endif
7367 
7368     if (radioService[slotId]->mRadioResponse != NULL) {
7369         RadioResponseInfo responseInfo = {};
7370         populateResponseInfo(responseInfo, serial, responseType, e);
7371         Return<void> retStatus = radioService[slotId]->mRadioResponse->acceptCallResponse(
7372                 responseInfo);
7373         radioService[slotId]->checkReturnStatus(retStatus);
7374     } else {
7375         RLOGE("acceptCallResponse: radioService[%d]->mRadioResponse == NULL",
7376                 slotId);
7377     }
7378 
7379     return 0;
7380 }
7381 
deactivateDataCallResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7382 int radio_1_6::deactivateDataCallResponse(int slotId,
7383                                                 int responseType, int serial, RIL_Errno e,
7384                                                 void *response, size_t responseLen) {
7385 #if VDBG
7386     RLOGD("deactivateDataCallResponse: serial %d", serial);
7387 #endif
7388 
7389     if (radioService[slotId]->mRadioResponse != NULL) {
7390         RadioResponseInfo responseInfo = {};
7391         populateResponseInfo(responseInfo, serial, responseType, e);
7392         Return<void> retStatus = radioService[slotId]->mRadioResponse->deactivateDataCallResponse(
7393                 responseInfo);
7394         radioService[slotId]->checkReturnStatus(retStatus);
7395     } else {
7396         RLOGE("deactivateDataCallResponse: radioService[%d]->mRadioResponse == NULL",
7397                 slotId);
7398     }
7399 
7400     return 0;
7401 }
7402 
getFacilityLockForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7403 int radio_1_6::getFacilityLockForAppResponse(int slotId,
7404                                         int responseType, int serial, RIL_Errno e,
7405                                         void *response, size_t responseLen) {
7406 #if VDBG
7407     RLOGD("getFacilityLockForAppResponse: serial %d", serial);
7408 #endif
7409 
7410     if (radioService[slotId]->mRadioResponse != NULL) {
7411         RadioResponseInfo responseInfo = {};
7412         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
7413         Return<void> retStatus = radioService[slotId]->mRadioResponse->
7414                 getFacilityLockForAppResponse(responseInfo, ret);
7415         radioService[slotId]->checkReturnStatus(retStatus);
7416     } else {
7417         RLOGE("getFacilityLockForAppResponse: radioService[%d]->mRadioResponse == NULL",
7418                 slotId);
7419     }
7420 
7421     return 0;
7422 }
7423 
setFacilityLockForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7424 int radio_1_6::setFacilityLockForAppResponse(int slotId,
7425                                       int responseType, int serial, RIL_Errno e,
7426                                       void *response, size_t responseLen) {
7427 #if VDBG
7428     RLOGD("setFacilityLockForAppResponse: serial %d", serial);
7429 #endif
7430 
7431     if (radioService[slotId]->mRadioResponse != NULL) {
7432         RadioResponseInfo responseInfo = {};
7433         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
7434         Return<void> retStatus
7435                 = radioService[slotId]->mRadioResponse->setFacilityLockForAppResponse(responseInfo,
7436                 ret);
7437         radioService[slotId]->checkReturnStatus(retStatus);
7438     } else {
7439         RLOGE("setFacilityLockForAppResponse: radioService[%d]->mRadioResponse == NULL",
7440                 slotId);
7441     }
7442 
7443     return 0;
7444 }
7445 
setBarringPasswordResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7446 int radio_1_6::setBarringPasswordResponse(int slotId,
7447                              int responseType, int serial, RIL_Errno e,
7448                              void *response, size_t responseLen) {
7449 #if VDBG
7450     RLOGD("acceptCallResponse: serial %d", serial);
7451 #endif
7452 
7453     if (radioService[slotId]->mRadioResponse != NULL) {
7454         RadioResponseInfo responseInfo = {};
7455         populateResponseInfo(responseInfo, serial, responseType, e);
7456         Return<void> retStatus
7457                 = radioService[slotId]->mRadioResponse->setBarringPasswordResponse(responseInfo);
7458         radioService[slotId]->checkReturnStatus(retStatus);
7459     } else {
7460         RLOGE("setBarringPasswordResponse: radioService[%d]->mRadioResponse == NULL",
7461                 slotId);
7462     }
7463 
7464     return 0;
7465 }
7466 
getNetworkSelectionModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7467 int radio_1_6::getNetworkSelectionModeResponse(int slotId,
7468                                           int responseType, int serial, RIL_Errno e, void *response,
7469                                           size_t responseLen) {
7470 #if VDBG
7471     RLOGD("getNetworkSelectionModeResponse: serial %d", serial);
7472 #endif
7473 
7474     if (radioService[slotId]->mRadioResponse != NULL) {
7475         RadioResponseInfo responseInfo = {};
7476         populateResponseInfo(responseInfo, serial, responseType, e);
7477         bool manual = false;
7478         if (response == NULL || responseLen != sizeof(int)) {
7479             RLOGE("getNetworkSelectionModeResponse Invalid response: NULL");
7480             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7481         } else {
7482             int *pInt = (int *) response;
7483             manual = pInt[0] == 1 ? true : false;
7484         }
7485         Return<void> retStatus
7486                 = radioService[slotId]->mRadioResponse->getNetworkSelectionModeResponse(
7487                 responseInfo,
7488                 manual);
7489         radioService[slotId]->checkReturnStatus(retStatus);
7490     } else {
7491         RLOGE("getNetworkSelectionModeResponse: radioService[%d]->mRadioResponse == NULL",
7492                 slotId);
7493     }
7494 
7495     return 0;
7496 }
7497 
setNetworkSelectionModeAutomaticResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7498 int radio_1_6::setNetworkSelectionModeAutomaticResponse(int slotId, int responseType, int serial,
7499                                                     RIL_Errno e, void *response,
7500                                                     size_t responseLen) {
7501 #if VDBG
7502     RLOGD("setNetworkSelectionModeAutomaticResponse: serial %d", serial);
7503 #endif
7504 
7505     if (radioService[slotId]->mRadioResponse != NULL) {
7506         RadioResponseInfo responseInfo = {};
7507         populateResponseInfo(responseInfo, serial, responseType, e);
7508         Return<void> retStatus
7509                 = radioService[slotId]->mRadioResponse->setNetworkSelectionModeAutomaticResponse(
7510                 responseInfo);
7511         radioService[slotId]->checkReturnStatus(retStatus);
7512     } else {
7513         RLOGE("setNetworkSelectionModeAutomaticResponse: radioService[%d]->mRadioResponse "
7514                 "== NULL", slotId);
7515     }
7516 
7517     return 0;
7518 }
7519 
setNetworkSelectionModeManualResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7520 int radio_1_6::setNetworkSelectionModeManualResponse(int slotId,
7521                              int responseType, int serial, RIL_Errno e,
7522                              void *response, size_t responseLen) {
7523 #if VDBG
7524     RLOGD("setNetworkSelectionModeManualResponse: serial %d", serial);
7525 #endif
7526     RadioResponseInfo responseInfo = {};
7527     populateResponseInfo(responseInfo, serial, responseType, e);
7528 
7529     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
7530         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
7531                 ->setNetworkSelectionModeManualResponse_1_5(responseInfo);
7532         radioService[slotId]->checkReturnStatus(retStatus);
7533     } else if (radioService[slotId]->mRadioResponse != NULL) {
7534         Return<void> retStatus = radioService[slotId]->mRadioResponse
7535                 ->setNetworkSelectionModeManualResponse(responseInfo);
7536         radioService[slotId]->checkReturnStatus(retStatus);
7537     } else {
7538         RLOGE("acceptCallResponse: radioService[%d]->setNetworkSelectionModeManualResponse "
7539                 "== NULL", slotId);
7540     }
7541 
7542     return 0;
7543 }
7544 
convertOperatorStatusToInt(const char * str)7545 int convertOperatorStatusToInt(const char *str) {
7546     if (strncmp("unknown", str, 9) == 0) {
7547         return (int) OperatorStatus::UNKNOWN;
7548     } else if (strncmp("available", str, 9) == 0) {
7549         return (int) OperatorStatus::AVAILABLE;
7550     } else if (strncmp("current", str, 9) == 0) {
7551         return (int) OperatorStatus::CURRENT;
7552     } else if (strncmp("forbidden", str, 9) == 0) {
7553         return (int) OperatorStatus::FORBIDDEN;
7554     } else {
7555         return -1;
7556     }
7557 }
7558 
getAvailableNetworksResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7559 int radio_1_6::getAvailableNetworksResponse(int slotId,
7560                               int responseType, int serial, RIL_Errno e, void *response,
7561                               size_t responseLen) {
7562 #if VDBG
7563     RLOGD("getAvailableNetworksResponse: serial %d", serial);
7564 #endif
7565 
7566     if (radioService[slotId]->mRadioResponse != NULL) {
7567         RadioResponseInfo responseInfo = {};
7568         populateResponseInfo(responseInfo, serial, responseType, e);
7569         hidl_vec<OperatorInfo> networks;
7570         if ((response == NULL && responseLen != 0)
7571                 || responseLen % (4 * sizeof(char *))!= 0) {
7572             RLOGE("getAvailableNetworksResponse Invalid response: NULL");
7573             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7574         } else {
7575             char **resp = (char **) response;
7576             int numStrings = responseLen / sizeof(char *);
7577             networks.resize(numStrings/4);
7578             for (int i = 0, j = 0; i < numStrings; i = i + 4, j++) {
7579                 networks[j].alphaLong = convertCharPtrToHidlString(resp[i]);
7580                 networks[j].alphaShort = convertCharPtrToHidlString(resp[i + 1]);
7581                 networks[j].operatorNumeric = convertCharPtrToHidlString(resp[i + 2]);
7582                 int status = convertOperatorStatusToInt(resp[i + 3]);
7583                 if (status == -1) {
7584                     if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7585                 } else {
7586                     networks[j].status = (OperatorStatus) status;
7587                 }
7588             }
7589         }
7590         Return<void> retStatus
7591                 = radioService[slotId]->mRadioResponse->getAvailableNetworksResponse(responseInfo,
7592                 networks);
7593         radioService[slotId]->checkReturnStatus(retStatus);
7594     } else {
7595         RLOGE("getAvailableNetworksResponse: radioService[%d]->mRadioResponse == NULL",
7596                 slotId);
7597     }
7598 
7599     return 0;
7600 }
7601 
startDtmfResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7602 int radio_1_6::startDtmfResponse(int slotId,
7603                             int responseType, int serial, RIL_Errno e,
7604                             void *response, size_t responseLen) {
7605 #if VDBG
7606     RLOGD("startDtmfResponse: serial %d", serial);
7607 #endif
7608 
7609     if (radioService[slotId]->mRadioResponse != NULL) {
7610         RadioResponseInfo responseInfo = {};
7611         populateResponseInfo(responseInfo, serial, responseType, e);
7612         Return<void> retStatus
7613                 = radioService[slotId]->mRadioResponse->startDtmfResponse(responseInfo);
7614         radioService[slotId]->checkReturnStatus(retStatus);
7615     } else {
7616         RLOGE("startDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7617     }
7618 
7619     return 0;
7620 }
7621 
stopDtmfResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7622 int radio_1_6::stopDtmfResponse(int slotId,
7623                            int responseType, int serial, RIL_Errno e,
7624                            void *response, size_t responseLen) {
7625 #if VDBG
7626     RLOGD("stopDtmfResponse: serial %d", serial);
7627 #endif
7628 
7629     if (radioService[slotId]->mRadioResponse != NULL) {
7630         RadioResponseInfo responseInfo = {};
7631         populateResponseInfo(responseInfo, serial, responseType, e);
7632         Return<void> retStatus
7633                 = radioService[slotId]->mRadioResponse->stopDtmfResponse(responseInfo);
7634         radioService[slotId]->checkReturnStatus(retStatus);
7635     } else {
7636         RLOGE("stopDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7637     }
7638 
7639     return 0;
7640 }
7641 
getBasebandVersionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7642 int radio_1_6::getBasebandVersionResponse(int slotId,
7643                                      int responseType, int serial, RIL_Errno e,
7644                                      void *response, size_t responseLen) {
7645 #if VDBG
7646     RLOGD("getBasebandVersionResponse: serial %d", serial);
7647 #endif
7648 
7649     if (radioService[slotId]->mRadioResponse != NULL) {
7650         RadioResponseInfo responseInfo = {};
7651         populateResponseInfo(responseInfo, serial, responseType, e);
7652         Return<void> retStatus
7653                 = radioService[slotId]->mRadioResponse->getBasebandVersionResponse(responseInfo,
7654                 convertCharPtrToHidlString((char *) response));
7655         radioService[slotId]->checkReturnStatus(retStatus);
7656     } else {
7657         RLOGE("getBasebandVersionResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7658     }
7659 
7660     return 0;
7661 }
7662 
separateConnectionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7663 int radio_1_6::separateConnectionResponse(int slotId,
7664                                      int responseType, int serial, RIL_Errno e,
7665                                      void *response, size_t responseLen) {
7666 #if VDBG
7667     RLOGD("separateConnectionResponse: serial %d", serial);
7668 #endif
7669 
7670     if (radioService[slotId]->mRadioResponse != NULL) {
7671         RadioResponseInfo responseInfo = {};
7672         populateResponseInfo(responseInfo, serial, responseType, e);
7673         Return<void> retStatus
7674                 = radioService[slotId]->mRadioResponse->separateConnectionResponse(responseInfo);
7675         radioService[slotId]->checkReturnStatus(retStatus);
7676     } else {
7677         RLOGE("separateConnectionResponse: radioService[%d]->mRadioResponse == NULL",
7678                 slotId);
7679     }
7680 
7681     return 0;
7682 }
7683 
setMuteResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7684 int radio_1_6::setMuteResponse(int slotId,
7685                           int responseType, int serial, RIL_Errno e,
7686                           void *response, size_t responseLen) {
7687 #if VDBG
7688     RLOGD("setMuteResponse: serial %d", serial);
7689 #endif
7690 
7691     if (radioService[slotId]->mRadioResponse != NULL) {
7692         RadioResponseInfo responseInfo = {};
7693         populateResponseInfo(responseInfo, serial, responseType, e);
7694         Return<void> retStatus
7695                 = radioService[slotId]->mRadioResponse->setMuteResponse(responseInfo);
7696         radioService[slotId]->checkReturnStatus(retStatus);
7697     } else {
7698         RLOGE("setMuteResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7699     }
7700 
7701     return 0;
7702 }
7703 
getMuteResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7704 int radio_1_6::getMuteResponse(int slotId,
7705                           int responseType, int serial, RIL_Errno e, void *response,
7706                           size_t responseLen) {
7707 #if VDBG
7708     RLOGD("getMuteResponse: serial %d", serial);
7709 #endif
7710 
7711     if (radioService[slotId]->mRadioResponse != NULL) {
7712         RadioResponseInfo responseInfo = {};
7713         populateResponseInfo(responseInfo, serial, responseType, e);
7714         bool enable = false;
7715         if (response == NULL || responseLen != sizeof(int)) {
7716             RLOGE("getMuteResponse Invalid response: NULL");
7717             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7718         } else {
7719             int *pInt = (int *) response;
7720             enable = pInt[0] == 1 ? true : false;
7721         }
7722         Return<void> retStatus = radioService[slotId]->mRadioResponse->getMuteResponse(responseInfo,
7723                 enable);
7724         radioService[slotId]->checkReturnStatus(retStatus);
7725     } else {
7726         RLOGE("getMuteResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7727     }
7728 
7729     return 0;
7730 }
7731 
getClipResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7732 int radio_1_6::getClipResponse(int slotId,
7733                           int responseType, int serial, RIL_Errno e,
7734                           void *response, size_t responseLen) {
7735 #if VDBG
7736     RLOGD("getClipResponse: serial %d", serial);
7737 #endif
7738 
7739     if (radioService[slotId]->mRadioResponse != NULL) {
7740         RadioResponseInfo responseInfo = {};
7741         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
7742         Return<void> retStatus = radioService[slotId]->mRadioResponse->getClipResponse(responseInfo,
7743                 (ClipStatus) ret);
7744         radioService[slotId]->checkReturnStatus(retStatus);
7745     } else {
7746         RLOGE("getClipResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7747     }
7748 
7749     return 0;
7750 }
7751 
getDataCallListResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7752 int radio_1_6::getDataCallListResponse(int slotId, int responseType, int serial, RIL_Errno e,
7753                                        void* response, size_t responseLen) {
7754 #if VDBG
7755     RLOGD("getDataCallListResponse: serial %d", serial);
7756 #endif
7757 
7758     if (radioService[slotId]->mRadioResponse != NULL ||
7759         radioService[slotId]->mRadioResponseV1_4 != NULL ||
7760         radioService[slotId]->mRadioResponseV1_5 != NULL ||
7761         radioService[slotId]->mRadioResponseV1_6 != NULL) {
7762         V1_6::RadioResponseInfo responseInfo16 = {};
7763         RadioResponseInfo responseInfo = {};
7764         if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
7765             populateResponseInfo_1_6(responseInfo16, serial, responseType, e);
7766         } else {
7767             populateResponseInfo(responseInfo, serial, responseType, e);
7768         }
7769 
7770         if ((response == NULL && responseLen != 0)
7771                 || responseLen % sizeof(RIL_Data_Call_Response_v11) != 0) {
7772             RLOGE("getDataCallListResponse: invalid response");
7773             if (e == RIL_E_SUCCESS) {
7774                 responseInfo16.error = V1_6::RadioError::INVALID_RESPONSE;
7775                 responseInfo.error = RadioError::INVALID_RESPONSE;
7776             }
7777         } else {
7778             Return<void> retStatus;
7779             if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
7780                 hidl_vec<V1_6::SetupDataCallResult> ret;
7781                 convertRilDataCallListToHal_1_6(response, responseLen, ret);
7782                 retStatus = radioService[slotId]->mRadioResponseV1_6->getDataCallListResponse_1_6(
7783                         responseInfo16, ret);
7784             } else if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
7785                 hidl_vec<V1_5::SetupDataCallResult> ret;
7786                 convertRilDataCallListToHal_1_5(response, responseLen, ret);
7787                 retStatus = radioService[slotId]->mRadioResponseV1_5->getDataCallListResponse_1_5(
7788                         responseInfo, ret);
7789             } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
7790                 hidl_vec<V1_4::SetupDataCallResult> ret;
7791                 convertRilDataCallListToHal_1_4(response, responseLen, ret);
7792                 retStatus = radioService[slotId]->mRadioResponseV1_4->getDataCallListResponse_1_4(
7793                         responseInfo, ret);
7794             } else {
7795                 hidl_vec<SetupDataCallResult> ret;
7796                 convertRilDataCallListToHal(response, responseLen, ret);
7797                 retStatus = radioService[slotId]->mRadioResponse->getDataCallListResponse(
7798                         responseInfo, ret);
7799             }
7800             radioService[slotId]->checkReturnStatus(retStatus);
7801         }
7802     } else {
7803         RLOGE("getDataCallListResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7804     }
7805 
7806     return 0;
7807 }
7808 
setSuppServiceNotificationsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7809 int radio_1_6::setSuppServiceNotificationsResponse(int slotId,
7810                                               int responseType, int serial, RIL_Errno e,
7811                                               void *response, size_t responseLen) {
7812 #if VDBG
7813     RLOGD("setSuppServiceNotificationsResponse: serial %d", serial);
7814 #endif
7815 
7816     if (radioService[slotId]->mRadioResponse != NULL) {
7817         RadioResponseInfo responseInfo = {};
7818         populateResponseInfo(responseInfo, serial, responseType, e);
7819         Return<void> retStatus
7820                 = radioService[slotId]->mRadioResponse->setSuppServiceNotificationsResponse(
7821                 responseInfo);
7822         radioService[slotId]->checkReturnStatus(retStatus);
7823     } else {
7824         RLOGE("setSuppServiceNotificationsResponse: radioService[%d]->mRadioResponse "
7825                 "== NULL", slotId);
7826     }
7827 
7828     return 0;
7829 }
7830 
deleteSmsOnSimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7831 int radio_1_6::deleteSmsOnSimResponse(int slotId,
7832                                  int responseType, int serial, RIL_Errno e,
7833                                  void *response, size_t responseLen) {
7834 #if VDBG
7835     RLOGD("deleteSmsOnSimResponse: serial %d", serial);
7836 #endif
7837 
7838     if (radioService[slotId]->mRadioResponse != NULL) {
7839         RadioResponseInfo responseInfo = {};
7840         populateResponseInfo(responseInfo, serial, responseType, e);
7841         Return<void> retStatus
7842                 = radioService[slotId]->mRadioResponse->deleteSmsOnSimResponse(responseInfo);
7843         radioService[slotId]->checkReturnStatus(retStatus);
7844     } else {
7845         RLOGE("deleteSmsOnSimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7846     }
7847 
7848     return 0;
7849 }
7850 
setBandModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7851 int radio_1_6::setBandModeResponse(int slotId,
7852                               int responseType, int serial, RIL_Errno e,
7853                               void *response, size_t responseLen) {
7854 #if VDBG
7855     RLOGD("setBandModeResponse: serial %d", serial);
7856 #endif
7857 
7858     if (radioService[slotId]->mRadioResponse != NULL) {
7859         RadioResponseInfo responseInfo = {};
7860         populateResponseInfo(responseInfo, serial, responseType, e);
7861         Return<void> retStatus
7862                 = radioService[slotId]->mRadioResponse->setBandModeResponse(responseInfo);
7863         radioService[slotId]->checkReturnStatus(retStatus);
7864     } else {
7865         RLOGE("setBandModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7866     }
7867 
7868     return 0;
7869 }
7870 
writeSmsToSimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7871 int radio_1_6::writeSmsToSimResponse(int slotId,
7872                                 int responseType, int serial, RIL_Errno e,
7873                                 void *response, size_t responseLen) {
7874 #if VDBG
7875     RLOGD("writeSmsToSimResponse: serial %d", serial);
7876 #endif
7877 
7878     if (radioService[slotId]->mRadioResponse != NULL) {
7879         RadioResponseInfo responseInfo = {};
7880         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
7881         Return<void> retStatus
7882                 = radioService[slotId]->mRadioResponse->writeSmsToSimResponse(responseInfo, ret);
7883         radioService[slotId]->checkReturnStatus(retStatus);
7884     } else {
7885         RLOGE("writeSmsToSimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7886     }
7887 
7888     return 0;
7889 }
7890 
getAvailableBandModesResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7891 int radio_1_6::getAvailableBandModesResponse(int slotId,
7892                                         int responseType, int serial, RIL_Errno e, void *response,
7893                                         size_t responseLen) {
7894 #if VDBG
7895     RLOGD("getAvailableBandModesResponse: serial %d", serial);
7896 #endif
7897 
7898     if (radioService[slotId]->mRadioResponse != NULL) {
7899         RadioResponseInfo responseInfo = {};
7900         populateResponseInfo(responseInfo, serial, responseType, e);
7901         hidl_vec<RadioBandMode> modes;
7902         if ((response == NULL && responseLen != 0)|| responseLen % sizeof(int) != 0) {
7903             RLOGE("getAvailableBandModesResponse Invalid response: NULL");
7904             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7905         } else {
7906             int *pInt = (int *) response;
7907             int numInts = responseLen / sizeof(int);
7908             modes.resize(numInts);
7909             for (int i = 0; i < numInts; i++) {
7910                 modes[i] = (RadioBandMode) pInt[i];
7911             }
7912         }
7913         Return<void> retStatus
7914                 = radioService[slotId]->mRadioResponse->getAvailableBandModesResponse(responseInfo,
7915                 modes);
7916         radioService[slotId]->checkReturnStatus(retStatus);
7917     } else {
7918         RLOGE("getAvailableBandModesResponse: radioService[%d]->mRadioResponse == NULL",
7919                 slotId);
7920     }
7921 
7922     return 0;
7923 }
7924 
sendEnvelopeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7925 int radio_1_6::sendEnvelopeResponse(int slotId,
7926                                int responseType, int serial, RIL_Errno e,
7927                                void *response, size_t responseLen) {
7928 #if VDBG
7929     RLOGD("sendEnvelopeResponse: serial %d", serial);
7930 #endif
7931 
7932     if (radioService[slotId]->mRadioResponse != NULL) {
7933         RadioResponseInfo responseInfo = {};
7934         populateResponseInfo(responseInfo, serial, responseType, e);
7935         Return<void> retStatus
7936                 = radioService[slotId]->mRadioResponse->sendEnvelopeResponse(responseInfo,
7937                 convertCharPtrToHidlString((char *) response));
7938         radioService[slotId]->checkReturnStatus(retStatus);
7939     } else {
7940         RLOGE("sendEnvelopeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7941     }
7942 
7943     return 0;
7944 }
7945 
sendTerminalResponseToSimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7946 int radio_1_6::sendTerminalResponseToSimResponse(int slotId,
7947                                             int responseType, int serial, RIL_Errno e,
7948                                             void *response, size_t responseLen) {
7949 #if VDBG
7950     RLOGD("sendTerminalResponseToSimResponse: serial %d", serial);
7951 #endif
7952 
7953     if (radioService[slotId]->mRadioResponse != NULL) {
7954         RadioResponseInfo responseInfo = {};
7955         populateResponseInfo(responseInfo, serial, responseType, e);
7956         Return<void> retStatus
7957                 = radioService[slotId]->mRadioResponse->sendTerminalResponseToSimResponse(
7958                 responseInfo);
7959         radioService[slotId]->checkReturnStatus(retStatus);
7960     } else {
7961         RLOGE("sendTerminalResponseToSimResponse: radioService[%d]->mRadioResponse == NULL",
7962                 slotId);
7963     }
7964 
7965     return 0;
7966 }
7967 
handleStkCallSetupRequestFromSimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7968 int radio_1_6::handleStkCallSetupRequestFromSimResponse(int slotId,
7969                                                    int responseType, int serial,
7970                                                    RIL_Errno e, void *response,
7971                                                    size_t responseLen) {
7972 #if VDBG
7973     RLOGD("handleStkCallSetupRequestFromSimResponse: serial %d", serial);
7974 #endif
7975 
7976     if (radioService[slotId]->mRadioResponse != NULL) {
7977         RadioResponseInfo responseInfo = {};
7978         populateResponseInfo(responseInfo, serial, responseType, e);
7979         Return<void> retStatus
7980                 = radioService[slotId]->mRadioResponse->handleStkCallSetupRequestFromSimResponse(
7981                 responseInfo);
7982         radioService[slotId]->checkReturnStatus(retStatus);
7983     } else {
7984         RLOGE("handleStkCallSetupRequestFromSimResponse: radioService[%d]->mRadioResponse "
7985                 "== NULL", slotId);
7986     }
7987 
7988     return 0;
7989 }
7990 
explicitCallTransferResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7991 int radio_1_6::explicitCallTransferResponse(int slotId,
7992                                        int responseType, int serial, RIL_Errno e,
7993                                        void *response, size_t responseLen) {
7994 #if VDBG
7995     RLOGD("explicitCallTransferResponse: serial %d", serial);
7996 #endif
7997 
7998     if (radioService[slotId]->mRadioResponse != NULL) {
7999         RadioResponseInfo responseInfo = {};
8000         populateResponseInfo(responseInfo, serial, responseType, e);
8001         Return<void> retStatus
8002                 = radioService[slotId]->mRadioResponse->explicitCallTransferResponse(responseInfo);
8003         radioService[slotId]->checkReturnStatus(retStatus);
8004     } else {
8005         RLOGE("explicitCallTransferResponse: radioService[%d]->mRadioResponse == NULL",
8006                 slotId);
8007     }
8008 
8009     return 0;
8010 }
8011 
setPreferredNetworkTypeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8012 int radio_1_6::setPreferredNetworkTypeResponse(int slotId,
8013                                  int responseType, int serial, RIL_Errno e,
8014                                  void *response, size_t responseLen) {
8015 #if VDBG
8016     RLOGD("setPreferredNetworkTypeResponse: serial %d", serial);
8017 #endif
8018 
8019     if (radioService[slotId]->mRadioResponse != NULL) {
8020         RadioResponseInfo responseInfo = {};
8021         populateResponseInfo(responseInfo, serial, responseType, e);
8022         Return<void> retStatus
8023                 = radioService[slotId]->mRadioResponse->setPreferredNetworkTypeResponse(
8024                 responseInfo);
8025         radioService[slotId]->checkReturnStatus(retStatus);
8026     } else {
8027         RLOGE("setPreferredNetworkTypeResponse: radioService[%d]->mRadioResponse == NULL",
8028                 slotId);
8029     }
8030 
8031     return 0;
8032 }
8033 
setAllowedNetworkTypesBitmapResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8034 int radio_1_6::setAllowedNetworkTypesBitmapResponse(int slotId,
8035                                  int responseType, int serial, RIL_Errno e,
8036                                  void *response, size_t responseLen) {
8037 #if VDBG
8038     RLOGD("setAllowedNetworkTypesBitmapResponse: serial %d", serial);
8039 #endif
8040 
8041     V1_6::RadioResponseInfo responseInfo = {};
8042     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
8043 
8044     // If we don't have a radio service, there's nothing we can do
8045     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
8046         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
8047         return 0;
8048     }
8049 
8050     Return<void> retStatus =
8051             radioService[slotId]->mRadioResponseV1_6->setAllowedNetworkTypesBitmapResponse(
8052             responseInfo);
8053     radioService[slotId]->checkReturnStatus(retStatus);
8054     return 0;
8055 }
8056 
getAllowedNetworkTypesBitmapResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8057 int radio_1_6::getAllowedNetworkTypesBitmapResponse(int slotId,
8058                                           int responseType, int serial, RIL_Errno e,
8059                                           void *response, size_t responseLen) {
8060 #if VDBG
8061     RLOGD("getAllowedNetworkTypesBitmapResponse: serial %d", serial);
8062 #endif
8063 
8064     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
8065       V1_6::RadioResponseInfo responseInfo = {};
8066         int ret = responseInt_1_6(responseInfo, serial, responseType, e, response, responseLen);
8067         Return<void> retStatus
8068                 = radioService[slotId]->mRadioResponseV1_6->getAllowedNetworkTypesBitmapResponse(
8069                 responseInfo,
8070                 (const ::android::hardware::hidl_bitfield<
8071                 ::android::hardware::radio::V1_4::RadioAccessFamily>) ret);
8072         radioService[slotId]->checkReturnStatus(retStatus);
8073     } else {
8074         RLOGE("getAllowedNetworkTypesBitmapResponse: radioService[%d]->mRadioResponseV1_6 == NULL",
8075                 slotId);
8076     }
8077 
8078     return 0;
8079 }
8080 
getPreferredNetworkTypeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8081 int radio_1_6::getPreferredNetworkTypeResponse(int slotId,
8082                                           int responseType, int serial, RIL_Errno e,
8083                                           void *response, size_t responseLen) {
8084 #if VDBG
8085     RLOGD("getPreferredNetworkTypeResponse: serial %d", serial);
8086 #endif
8087 
8088     if (radioService[slotId]->mRadioResponse != NULL) {
8089         RadioResponseInfo responseInfo = {};
8090         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8091         Return<void> retStatus
8092                 = radioService[slotId]->mRadioResponse->getPreferredNetworkTypeResponse(
8093                 responseInfo, (PreferredNetworkType) ret);
8094         radioService[slotId]->checkReturnStatus(retStatus);
8095     } else {
8096         RLOGE("getPreferredNetworkTypeResponse: radioService[%d]->mRadioResponse == NULL",
8097                 slotId);
8098     }
8099 
8100     return 0;
8101 }
8102 
setPreferredNetworkTypeBitmapResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8103 int radio_1_6::setPreferredNetworkTypeBitmapResponse(int slotId,
8104                                  int responseType, int serial, RIL_Errno e,
8105                                  void *response, size_t responseLen) {
8106 #if VDBG
8107     RLOGD("setPreferredNetworkTypeBitmapResponse: serial %d", serial);
8108 #endif
8109 
8110     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
8111         RadioResponseInfo responseInfo = {};
8112         populateResponseInfo(responseInfo, serial, responseType, e);
8113         Return<void> retStatus
8114                 = radioService[slotId]->mRadioResponseV1_4->setPreferredNetworkTypeBitmapResponse(
8115                 responseInfo);
8116         radioService[slotId]->checkReturnStatus(retStatus);
8117     } else {
8118         RLOGE("setPreferredNetworkTypeBitmapResponse: radioService[%d]->mRadioResponseV1_4 == NULL",
8119                 slotId);
8120     }
8121 
8122     return 0;
8123 }
8124 
8125 
getPreferredNetworkTypeBitmapResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8126 int radio_1_6::getPreferredNetworkTypeBitmapResponse(int slotId,
8127                                           int responseType, int serial, RIL_Errno e,
8128                                           void *response, size_t responseLen) {
8129 #if VDBG
8130     RLOGD("getPreferredNetworkTypeBitmapResponse: serial %d", serial);
8131 #endif
8132 
8133     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
8134         RadioResponseInfo responseInfo = {};
8135         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8136         Return<void> retStatus
8137                 = radioService[slotId]->mRadioResponseV1_4->getPreferredNetworkTypeBitmapResponse(
8138                 responseInfo,
8139                 (const ::android::hardware::hidl_bitfield<
8140                 ::android::hardware::radio::V1_4::RadioAccessFamily>) ret);
8141         radioService[slotId]->checkReturnStatus(retStatus);
8142     } else {
8143         RLOGE("getPreferredNetworkTypeBitmapResponse: radioService[%d]->mRadioResponseV1_4 == NULL",
8144                 slotId);
8145     }
8146 
8147     return 0;
8148 }
8149 
getNeighboringCidsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8150 int radio_1_6::getNeighboringCidsResponse(int slotId,
8151                                      int responseType, int serial, RIL_Errno e,
8152                                      void *response, size_t responseLen) {
8153 #if VDBG
8154     RLOGD("getNeighboringCidsResponse: serial %d", serial);
8155 #endif
8156 
8157     if (radioService[slotId]->mRadioResponse != NULL) {
8158         RadioResponseInfo responseInfo = {};
8159         populateResponseInfo(responseInfo, serial, responseType, e);
8160         hidl_vec<NeighboringCell> cells;
8161 
8162         if ((response == NULL && responseLen != 0)
8163                 || responseLen % sizeof(RIL_NeighboringCell *) != 0) {
8164             RLOGE("getNeighboringCidsResponse Invalid response: NULL");
8165             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8166         } else {
8167             int num = responseLen / sizeof(RIL_NeighboringCell *);
8168             cells.resize(num);
8169             for (int i = 0 ; i < num; i++) {
8170                 RIL_NeighboringCell *resp = ((RIL_NeighboringCell **) response)[i];
8171                 cells[i].cid = convertCharPtrToHidlString(resp->cid);
8172                 cells[i].rssi = resp->rssi;
8173             }
8174         }
8175 
8176         Return<void> retStatus
8177                 = radioService[slotId]->mRadioResponse->getNeighboringCidsResponse(responseInfo,
8178                 cells);
8179         radioService[slotId]->checkReturnStatus(retStatus);
8180     } else {
8181         RLOGE("getNeighboringCidsResponse: radioService[%d]->mRadioResponse == NULL",
8182                 slotId);
8183     }
8184 
8185     return 0;
8186 }
8187 
setLocationUpdatesResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8188 int radio_1_6::setLocationUpdatesResponse(int slotId,
8189                                      int responseType, int serial, RIL_Errno e,
8190                                      void *response, size_t responseLen) {
8191 #if VDBG
8192     RLOGD("setLocationUpdatesResponse: serial %d", serial);
8193 #endif
8194 
8195     if (radioService[slotId]->mRadioResponse != NULL) {
8196         RadioResponseInfo responseInfo = {};
8197         populateResponseInfo(responseInfo, serial, responseType, e);
8198         Return<void> retStatus
8199                 = radioService[slotId]->mRadioResponse->setLocationUpdatesResponse(responseInfo);
8200         radioService[slotId]->checkReturnStatus(retStatus);
8201     } else {
8202         RLOGE("setLocationUpdatesResponse: radioService[%d]->mRadioResponse == NULL",
8203                 slotId);
8204     }
8205 
8206     return 0;
8207 }
8208 
setCdmaSubscriptionSourceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8209 int radio_1_6::setCdmaSubscriptionSourceResponse(int slotId,
8210                                  int responseType, int serial, RIL_Errno e,
8211                                  void *response, size_t responseLen) {
8212 #if VDBG
8213     RLOGD("setCdmaSubscriptionSourceResponse: serial %d", serial);
8214 #endif
8215 
8216     if (radioService[slotId]->mRadioResponse != NULL) {
8217         RadioResponseInfo responseInfo = {};
8218         populateResponseInfo(responseInfo, serial, responseType, e);
8219         Return<void> retStatus
8220                 = radioService[slotId]->mRadioResponse->setCdmaSubscriptionSourceResponse(
8221                 responseInfo);
8222         radioService[slotId]->checkReturnStatus(retStatus);
8223     } else {
8224         RLOGE("setCdmaSubscriptionSourceResponse: radioService[%d]->mRadioResponse == NULL",
8225                 slotId);
8226     }
8227 
8228     return 0;
8229 }
8230 
setCdmaRoamingPreferenceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8231 int radio_1_6::setCdmaRoamingPreferenceResponse(int slotId,
8232                                  int responseType, int serial, RIL_Errno e,
8233                                  void *response, size_t responseLen) {
8234 #if VDBG
8235     RLOGD("setCdmaRoamingPreferenceResponse: serial %d", serial);
8236 #endif
8237 
8238     if (radioService[slotId]->mRadioResponse != NULL) {
8239         RadioResponseInfo responseInfo = {};
8240         populateResponseInfo(responseInfo, serial, responseType, e);
8241         Return<void> retStatus
8242                 = radioService[slotId]->mRadioResponse->setCdmaRoamingPreferenceResponse(
8243                 responseInfo);
8244         radioService[slotId]->checkReturnStatus(retStatus);
8245     } else {
8246         RLOGE("setCdmaRoamingPreferenceResponse: radioService[%d]->mRadioResponse == NULL",
8247                 slotId);
8248     }
8249 
8250     return 0;
8251 }
8252 
getCdmaRoamingPreferenceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8253 int radio_1_6::getCdmaRoamingPreferenceResponse(int slotId,
8254                                            int responseType, int serial, RIL_Errno e,
8255                                            void *response, size_t responseLen) {
8256 #if VDBG
8257     RLOGD("getCdmaRoamingPreferenceResponse: serial %d", serial);
8258 #endif
8259 
8260     if (radioService[slotId]->mRadioResponse != NULL) {
8261         RadioResponseInfo responseInfo = {};
8262         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8263         Return<void> retStatus
8264                 = radioService[slotId]->mRadioResponse->getCdmaRoamingPreferenceResponse(
8265                 responseInfo, (CdmaRoamingType) ret);
8266         radioService[slotId]->checkReturnStatus(retStatus);
8267     } else {
8268         RLOGE("getCdmaRoamingPreferenceResponse: radioService[%d]->mRadioResponse == NULL",
8269                 slotId);
8270     }
8271 
8272     return 0;
8273 }
8274 
setTTYModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8275 int radio_1_6::setTTYModeResponse(int slotId,
8276                              int responseType, int serial, RIL_Errno e,
8277                              void *response, size_t responseLen) {
8278 #if VDBG
8279     RLOGD("setTTYModeResponse: serial %d", serial);
8280 #endif
8281 
8282     if (radioService[slotId]->mRadioResponse != NULL) {
8283         RadioResponseInfo responseInfo = {};
8284         populateResponseInfo(responseInfo, serial, responseType, e);
8285         Return<void> retStatus
8286                 = radioService[slotId]->mRadioResponse->setTTYModeResponse(responseInfo);
8287         radioService[slotId]->checkReturnStatus(retStatus);
8288     } else {
8289         RLOGE("setTTYModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8290     }
8291 
8292     return 0;
8293 }
8294 
getTTYModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8295 int radio_1_6::getTTYModeResponse(int slotId,
8296                              int responseType, int serial, RIL_Errno e,
8297                              void *response, size_t responseLen) {
8298 #if VDBG
8299     RLOGD("getTTYModeResponse: serial %d", serial);
8300 #endif
8301 
8302     if (radioService[slotId]->mRadioResponse != NULL) {
8303         RadioResponseInfo responseInfo = {};
8304         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8305         Return<void> retStatus
8306                 = radioService[slotId]->mRadioResponse->getTTYModeResponse(responseInfo,
8307                 (TtyMode) ret);
8308         radioService[slotId]->checkReturnStatus(retStatus);
8309     } else {
8310         RLOGE("getTTYModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8311     }
8312 
8313     return 0;
8314 }
8315 
setPreferredVoicePrivacyResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8316 int radio_1_6::setPreferredVoicePrivacyResponse(int slotId,
8317                                  int responseType, int serial, RIL_Errno e,
8318                                  void *response, size_t responseLen) {
8319 #if VDBG
8320     RLOGD("setPreferredVoicePrivacyResponse: serial %d", serial);
8321 #endif
8322 
8323     if (radioService[slotId]->mRadioResponse != NULL) {
8324         RadioResponseInfo responseInfo = {};
8325         populateResponseInfo(responseInfo, serial, responseType, e);
8326         Return<void> retStatus
8327                 = radioService[slotId]->mRadioResponse->setPreferredVoicePrivacyResponse(
8328                 responseInfo);
8329         radioService[slotId]->checkReturnStatus(retStatus);
8330     } else {
8331         RLOGE("setPreferredVoicePrivacyResponse: radioService[%d]->mRadioResponse == NULL",
8332                 slotId);
8333     }
8334 
8335     return 0;
8336 }
8337 
getPreferredVoicePrivacyResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8338 int radio_1_6::getPreferredVoicePrivacyResponse(int slotId,
8339                                            int responseType, int serial, RIL_Errno e,
8340                                            void *response, size_t responseLen) {
8341 #if VDBG
8342     RLOGD("getPreferredVoicePrivacyResponse: serial %d", serial);
8343 #endif
8344 
8345     if (radioService[slotId]->mRadioResponse != NULL) {
8346         RadioResponseInfo responseInfo = {};
8347         populateResponseInfo(responseInfo, serial, responseType, e);
8348         bool enable = false;
8349         int numInts = responseLen / sizeof(int);
8350         if (response == NULL || numInts != 1) {
8351             RLOGE("getPreferredVoicePrivacyResponse Invalid response: NULL");
8352             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8353         } else {
8354             int *pInt = (int *) response;
8355             enable = pInt[0] == 1 ? true : false;
8356         }
8357         Return<void> retStatus
8358                 = radioService[slotId]->mRadioResponse->getPreferredVoicePrivacyResponse(
8359                 responseInfo, enable);
8360         radioService[slotId]->checkReturnStatus(retStatus);
8361     } else {
8362         RLOGE("getPreferredVoicePrivacyResponse: radioService[%d]->mRadioResponse == NULL",
8363                 slotId);
8364     }
8365 
8366     return 0;
8367 }
8368 
sendCDMAFeatureCodeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8369 int radio_1_6::sendCDMAFeatureCodeResponse(int slotId,
8370                                  int responseType, int serial, RIL_Errno e,
8371                                  void *response, size_t responseLen) {
8372 #if VDBG
8373     RLOGD("sendCDMAFeatureCodeResponse: serial %d", serial);
8374 #endif
8375 
8376     if (radioService[slotId]->mRadioResponse != NULL) {
8377         RadioResponseInfo responseInfo = {};
8378         populateResponseInfo(responseInfo, serial, responseType, e);
8379         Return<void> retStatus
8380                 = radioService[slotId]->mRadioResponse->sendCDMAFeatureCodeResponse(responseInfo);
8381         radioService[slotId]->checkReturnStatus(retStatus);
8382     } else {
8383         RLOGE("sendCDMAFeatureCodeResponse: radioService[%d]->mRadioResponse == NULL",
8384                 slotId);
8385     }
8386 
8387     return 0;
8388 }
8389 
sendBurstDtmfResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8390 int radio_1_6::sendBurstDtmfResponse(int slotId,
8391                                  int responseType, int serial, RIL_Errno e,
8392                                  void *response, size_t responseLen) {
8393 #if VDBG
8394     RLOGD("sendBurstDtmfResponse: serial %d", serial);
8395 #endif
8396 
8397     if (radioService[slotId]->mRadioResponse != NULL) {
8398         RadioResponseInfo responseInfo = {};
8399         populateResponseInfo(responseInfo, serial, responseType, e);
8400         Return<void> retStatus
8401                 = radioService[slotId]->mRadioResponse->sendBurstDtmfResponse(responseInfo);
8402         radioService[slotId]->checkReturnStatus(retStatus);
8403     } else {
8404         RLOGE("sendBurstDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8405     }
8406 
8407     return 0;
8408 }
8409 
sendCdmaSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8410 int radio_1_6::sendCdmaSmsResponse(int slotId,
8411                               int responseType, int serial, RIL_Errno e, void *response,
8412                               size_t responseLen) {
8413 #if VDBG
8414     RLOGD("sendCdmaSmsResponse: serial %d", serial);
8415 #endif
8416 
8417     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
8418         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
8419         SendSmsResult result = makeSendSmsResult_1_6(responseInfo_1_6, serial, responseType, e,
8420                 response, responseLen);
8421 
8422         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
8423                 ->sendCdmaSmsResponse_1_6(responseInfo_1_6, result);
8424         radioService[slotId]->checkReturnStatus(retStatus);
8425     } else if (radioService[slotId]->mRadioResponse != NULL) {
8426         RadioResponseInfo responseInfo = {};
8427         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
8428                 responseLen);
8429 
8430         Return<void> retStatus
8431                 = radioService[slotId]->mRadioResponse->sendCdmaSmsResponse(responseInfo, result);
8432         radioService[slotId]->checkReturnStatus(retStatus);
8433     } else {
8434         RLOGE("sendCdmaSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8435     }
8436 
8437     return 0;
8438 }
8439 
acknowledgeLastIncomingCdmaSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8440 int radio_1_6::acknowledgeLastIncomingCdmaSmsResponse(int slotId,
8441                                                  int responseType, int serial, RIL_Errno e,
8442                                                  void *response, size_t responseLen) {
8443 #if VDBG
8444     RLOGD("acknowledgeLastIncomingCdmaSmsResponse: serial %d", serial);
8445 #endif
8446 
8447     if (radioService[slotId]->mRadioResponse != NULL) {
8448         RadioResponseInfo responseInfo = {};
8449         populateResponseInfo(responseInfo, serial, responseType, e);
8450         Return<void> retStatus
8451                 = radioService[slotId]->mRadioResponse->acknowledgeLastIncomingCdmaSmsResponse(
8452                 responseInfo);
8453         radioService[slotId]->checkReturnStatus(retStatus);
8454     } else {
8455         RLOGE("acknowledgeLastIncomingCdmaSmsResponse: radioService[%d]->mRadioResponse "
8456                 "== NULL", slotId);
8457     }
8458 
8459     return 0;
8460 }
8461 
getGsmBroadcastConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8462 int radio_1_6::getGsmBroadcastConfigResponse(int slotId,
8463                                         int responseType, int serial, RIL_Errno e,
8464                                         void *response, size_t responseLen) {
8465 #if VDBG
8466     RLOGD("getGsmBroadcastConfigResponse: serial %d", serial);
8467 #endif
8468 
8469     if (radioService[slotId]->mRadioResponse != NULL) {
8470         RadioResponseInfo responseInfo = {};
8471         populateResponseInfo(responseInfo, serial, responseType, e);
8472         hidl_vec<GsmBroadcastSmsConfigInfo> configs;
8473 
8474         if ((response == NULL && responseLen != 0)
8475                 || responseLen % sizeof(RIL_GSM_BroadcastSmsConfigInfo *) != 0) {
8476             RLOGE("getGsmBroadcastConfigResponse Invalid response: NULL");
8477             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8478         } else {
8479             int num = responseLen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
8480             configs.resize(num);
8481             for (int i = 0 ; i < num; i++) {
8482                 RIL_GSM_BroadcastSmsConfigInfo *resp =
8483                         ((RIL_GSM_BroadcastSmsConfigInfo **) response)[i];
8484                 configs[i].fromServiceId = resp->fromServiceId;
8485                 configs[i].toServiceId = resp->toServiceId;
8486                 configs[i].fromCodeScheme = resp->fromCodeScheme;
8487                 configs[i].toCodeScheme = resp->toCodeScheme;
8488                 configs[i].selected = resp->selected == 1 ? true : false;
8489             }
8490         }
8491 
8492         Return<void> retStatus
8493                 = radioService[slotId]->mRadioResponse->getGsmBroadcastConfigResponse(responseInfo,
8494                 configs);
8495         radioService[slotId]->checkReturnStatus(retStatus);
8496     } else {
8497         RLOGE("getGsmBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
8498                 slotId);
8499     }
8500 
8501     return 0;
8502 }
8503 
setGsmBroadcastConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8504 int radio_1_6::setGsmBroadcastConfigResponse(int slotId,
8505                                         int responseType, int serial, RIL_Errno e,
8506                                         void *response, size_t responseLen) {
8507 #if VDBG
8508     RLOGD("setGsmBroadcastConfigResponse: serial %d", serial);
8509 #endif
8510 
8511     if (radioService[slotId]->mRadioResponse != NULL) {
8512         RadioResponseInfo responseInfo = {};
8513         populateResponseInfo(responseInfo, serial, responseType, e);
8514         Return<void> retStatus
8515                 = radioService[slotId]->mRadioResponse->setGsmBroadcastConfigResponse(responseInfo);
8516         radioService[slotId]->checkReturnStatus(retStatus);
8517     } else {
8518         RLOGE("setGsmBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
8519                 slotId);
8520     }
8521 
8522     return 0;
8523 }
8524 
setGsmBroadcastActivationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8525 int radio_1_6::setGsmBroadcastActivationResponse(int slotId,
8526                                             int responseType, int serial, RIL_Errno e,
8527                                             void *response, size_t responseLen) {
8528 #if VDBG
8529     RLOGD("setGsmBroadcastActivationResponse: serial %d", serial);
8530 #endif
8531 
8532     if (radioService[slotId]->mRadioResponse != NULL) {
8533         RadioResponseInfo responseInfo = {};
8534         populateResponseInfo(responseInfo, serial, responseType, e);
8535         Return<void> retStatus
8536                 = radioService[slotId]->mRadioResponse->setGsmBroadcastActivationResponse(
8537                 responseInfo);
8538         radioService[slotId]->checkReturnStatus(retStatus);
8539     } else {
8540         RLOGE("setGsmBroadcastActivationResponse: radioService[%d]->mRadioResponse == NULL",
8541                 slotId);
8542     }
8543 
8544     return 0;
8545 }
8546 
getCdmaBroadcastConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8547 int radio_1_6::getCdmaBroadcastConfigResponse(int slotId,
8548                                          int responseType, int serial, RIL_Errno e,
8549                                          void *response, size_t responseLen) {
8550 #if VDBG
8551     RLOGD("getCdmaBroadcastConfigResponse: serial %d", serial);
8552 #endif
8553 
8554     if (radioService[slotId]->mRadioResponse != NULL) {
8555         RadioResponseInfo responseInfo = {};
8556         populateResponseInfo(responseInfo, serial, responseType, e);
8557         hidl_vec<CdmaBroadcastSmsConfigInfo> configs;
8558 
8559         if ((response == NULL && responseLen != 0)
8560                 || responseLen % sizeof(RIL_CDMA_BroadcastSmsConfigInfo *) != 0) {
8561             RLOGE("getCdmaBroadcastConfigResponse Invalid response: NULL");
8562             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8563         } else {
8564             int num = responseLen / sizeof(RIL_CDMA_BroadcastSmsConfigInfo *);
8565             configs.resize(num);
8566             for (int i = 0 ; i < num; i++) {
8567                 RIL_CDMA_BroadcastSmsConfigInfo *resp =
8568                         ((RIL_CDMA_BroadcastSmsConfigInfo **) response)[i];
8569                 configs[i].serviceCategory = resp->service_category;
8570                 configs[i].language = resp->language;
8571                 configs[i].selected = resp->selected == 1 ? true : false;
8572             }
8573         }
8574 
8575         Return<void> retStatus
8576                 = radioService[slotId]->mRadioResponse->getCdmaBroadcastConfigResponse(responseInfo,
8577                 configs);
8578         radioService[slotId]->checkReturnStatus(retStatus);
8579     } else {
8580         RLOGE("getCdmaBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
8581                 slotId);
8582     }
8583 
8584     return 0;
8585 }
8586 
setCdmaBroadcastConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8587 int radio_1_6::setCdmaBroadcastConfigResponse(int slotId,
8588                                          int responseType, int serial, RIL_Errno e,
8589                                          void *response, size_t responseLen) {
8590 #if VDBG
8591     RLOGD("setCdmaBroadcastConfigResponse: serial %d", serial);
8592 #endif
8593 
8594     if (radioService[slotId]->mRadioResponse != NULL) {
8595         RadioResponseInfo responseInfo = {};
8596         populateResponseInfo(responseInfo, serial, responseType, e);
8597         Return<void> retStatus
8598                 = radioService[slotId]->mRadioResponse->setCdmaBroadcastConfigResponse(
8599                 responseInfo);
8600         radioService[slotId]->checkReturnStatus(retStatus);
8601     } else {
8602         RLOGE("setCdmaBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
8603                 slotId);
8604     }
8605 
8606     return 0;
8607 }
8608 
setCdmaBroadcastActivationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8609 int radio_1_6::setCdmaBroadcastActivationResponse(int slotId,
8610                                              int responseType, int serial, RIL_Errno e,
8611                                              void *response, size_t responseLen) {
8612 #if VDBG
8613     RLOGD("setCdmaBroadcastActivationResponse: serial %d", serial);
8614 #endif
8615 
8616     if (radioService[slotId]->mRadioResponse != NULL) {
8617         RadioResponseInfo responseInfo = {};
8618         populateResponseInfo(responseInfo, serial, responseType, e);
8619         Return<void> retStatus
8620                 = radioService[slotId]->mRadioResponse->setCdmaBroadcastActivationResponse(
8621                 responseInfo);
8622         radioService[slotId]->checkReturnStatus(retStatus);
8623     } else {
8624         RLOGE("setCdmaBroadcastActivationResponse: radioService[%d]->mRadioResponse == NULL",
8625                 slotId);
8626     }
8627 
8628     return 0;
8629 }
8630 
getCDMASubscriptionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8631 int radio_1_6::getCDMASubscriptionResponse(int slotId,
8632                                       int responseType, int serial, RIL_Errno e, void *response,
8633                                       size_t responseLen) {
8634 #if VDBG
8635     RLOGD("getCDMASubscriptionResponse: serial %d", serial);
8636 #endif
8637 
8638     if (radioService[slotId]->mRadioResponse != NULL) {
8639         RadioResponseInfo responseInfo = {};
8640         populateResponseInfo(responseInfo, serial, responseType, e);
8641 
8642         int numStrings = responseLen / sizeof(char *);
8643         hidl_string emptyString;
8644         if (response == NULL || numStrings != 5) {
8645             RLOGE("getOperatorResponse Invalid response: NULL");
8646             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8647             Return<void> retStatus
8648                     = radioService[slotId]->mRadioResponse->getCDMASubscriptionResponse(
8649                     responseInfo, emptyString, emptyString, emptyString, emptyString, emptyString);
8650             radioService[slotId]->checkReturnStatus(retStatus);
8651         } else {
8652             char **resp = (char **) response;
8653             Return<void> retStatus
8654                     = radioService[slotId]->mRadioResponse->getCDMASubscriptionResponse(
8655                     responseInfo,
8656                     convertCharPtrToHidlString(resp[0]),
8657                     convertCharPtrToHidlString(resp[1]),
8658                     convertCharPtrToHidlString(resp[2]),
8659                     convertCharPtrToHidlString(resp[3]),
8660                     convertCharPtrToHidlString(resp[4]));
8661             radioService[slotId]->checkReturnStatus(retStatus);
8662         }
8663     } else {
8664         RLOGE("getCDMASubscriptionResponse: radioService[%d]->mRadioResponse == NULL",
8665                 slotId);
8666     }
8667 
8668     return 0;
8669 }
8670 
writeSmsToRuimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8671 int radio_1_6::writeSmsToRuimResponse(int slotId,
8672                                  int responseType, int serial, RIL_Errno e,
8673                                  void *response, size_t responseLen) {
8674 #if VDBG
8675     RLOGD("writeSmsToRuimResponse: serial %d", serial);
8676 #endif
8677 
8678     if (radioService[slotId]->mRadioResponse != NULL) {
8679         RadioResponseInfo responseInfo = {};
8680         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8681         Return<void> retStatus
8682                 = radioService[slotId]->mRadioResponse->writeSmsToRuimResponse(responseInfo, ret);
8683         radioService[slotId]->checkReturnStatus(retStatus);
8684     } else {
8685         RLOGE("writeSmsToRuimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8686     }
8687 
8688     return 0;
8689 }
8690 
deleteSmsOnRuimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8691 int radio_1_6::deleteSmsOnRuimResponse(int slotId,
8692                                   int responseType, int serial, RIL_Errno e,
8693                                   void *response, size_t responseLen) {
8694 #if VDBG
8695     RLOGD("deleteSmsOnRuimResponse: serial %d", serial);
8696 #endif
8697 
8698     if (radioService[slotId]->mRadioResponse != NULL) {
8699         RadioResponseInfo responseInfo = {};
8700         populateResponseInfo(responseInfo, serial, responseType, e);
8701         Return<void> retStatus
8702                 = radioService[slotId]->mRadioResponse->deleteSmsOnRuimResponse(responseInfo);
8703         radioService[slotId]->checkReturnStatus(retStatus);
8704     } else {
8705         RLOGE("deleteSmsOnRuimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8706     }
8707 
8708     return 0;
8709 }
8710 
getDeviceIdentityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8711 int radio_1_6::getDeviceIdentityResponse(int slotId,
8712                                     int responseType, int serial, RIL_Errno e, void *response,
8713                                     size_t responseLen) {
8714 #if VDBG
8715     RLOGD("getDeviceIdentityResponse: serial %d", serial);
8716 #endif
8717 
8718     if (radioService[slotId]->mRadioResponse != NULL) {
8719         RadioResponseInfo responseInfo = {};
8720         populateResponseInfo(responseInfo, serial, responseType, e);
8721 
8722         int numStrings = responseLen / sizeof(char *);
8723         hidl_string emptyString;
8724         if (response == NULL || numStrings != 4) {
8725             RLOGE("getDeviceIdentityResponse Invalid response: NULL");
8726             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8727             Return<void> retStatus
8728                     = radioService[slotId]->mRadioResponse->getDeviceIdentityResponse(responseInfo,
8729                     emptyString, emptyString, emptyString, emptyString);
8730             radioService[slotId]->checkReturnStatus(retStatus);
8731         } else {
8732             char **resp = (char **) response;
8733             Return<void> retStatus
8734                     = radioService[slotId]->mRadioResponse->getDeviceIdentityResponse(responseInfo,
8735                     convertCharPtrToHidlString(resp[0]),
8736                     convertCharPtrToHidlString(resp[1]),
8737                     convertCharPtrToHidlString(resp[2]),
8738                     convertCharPtrToHidlString(resp[3]));
8739             radioService[slotId]->checkReturnStatus(retStatus);
8740         }
8741     } else {
8742         RLOGE("getDeviceIdentityResponse: radioService[%d]->mRadioResponse == NULL",
8743                 slotId);
8744     }
8745 
8746     return 0;
8747 }
8748 
exitEmergencyCallbackModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8749 int radio_1_6::exitEmergencyCallbackModeResponse(int slotId,
8750                                             int responseType, int serial, RIL_Errno e,
8751                                             void *response, size_t responseLen) {
8752 #if VDBG
8753     RLOGD("exitEmergencyCallbackModeResponse: serial %d", serial);
8754 #endif
8755 
8756     if (radioService[slotId]->mRadioResponse != NULL) {
8757         RadioResponseInfo responseInfo = {};
8758         populateResponseInfo(responseInfo, serial, responseType, e);
8759         Return<void> retStatus
8760                 = radioService[slotId]->mRadioResponse->exitEmergencyCallbackModeResponse(
8761                 responseInfo);
8762         radioService[slotId]->checkReturnStatus(retStatus);
8763     } else {
8764         RLOGE("exitEmergencyCallbackModeResponse: radioService[%d]->mRadioResponse == NULL",
8765                 slotId);
8766     }
8767 
8768     return 0;
8769 }
8770 
getSmscAddressResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8771 int radio_1_6::getSmscAddressResponse(int slotId,
8772                                   int responseType, int serial, RIL_Errno e,
8773                                   void *response, size_t responseLen) {
8774 #if VDBG
8775     RLOGD("getSmscAddressResponse: serial %d", serial);
8776 #endif
8777 
8778     if (radioService[slotId]->mRadioResponse != NULL) {
8779         RadioResponseInfo responseInfo = {};
8780         populateResponseInfo(responseInfo, serial, responseType, e);
8781         Return<void> retStatus
8782                 = radioService[slotId]->mRadioResponse->getSmscAddressResponse(responseInfo,
8783                 convertCharPtrToHidlString((char *) response));
8784         radioService[slotId]->checkReturnStatus(retStatus);
8785     } else {
8786         RLOGE("getSmscAddressResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8787     }
8788 
8789     return 0;
8790 }
8791 
setSmscAddressResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8792 int radio_1_6::setSmscAddressResponse(int slotId,
8793                                              int responseType, int serial, RIL_Errno e,
8794                                              void *response, size_t responseLen) {
8795 #if VDBG
8796     RLOGD("setSmscAddressResponse: serial %d", serial);
8797 #endif
8798 
8799     if (radioService[slotId]->mRadioResponse != NULL) {
8800         RadioResponseInfo responseInfo = {};
8801         populateResponseInfo(responseInfo, serial, responseType, e);
8802         Return<void> retStatus
8803                 = radioService[slotId]->mRadioResponse->setSmscAddressResponse(responseInfo);
8804         radioService[slotId]->checkReturnStatus(retStatus);
8805     } else {
8806         RLOGE("setSmscAddressResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8807     }
8808 
8809     return 0;
8810 }
8811 
reportSmsMemoryStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8812 int radio_1_6::reportSmsMemoryStatusResponse(int slotId,
8813                                         int responseType, int serial, RIL_Errno e,
8814                                         void *response, size_t responseLen) {
8815 #if VDBG
8816     RLOGD("reportSmsMemoryStatusResponse: serial %d", serial);
8817 #endif
8818 
8819     if (radioService[slotId]->mRadioResponse != NULL) {
8820         RadioResponseInfo responseInfo = {};
8821         populateResponseInfo(responseInfo, serial, responseType, e);
8822         Return<void> retStatus
8823                 = radioService[slotId]->mRadioResponse->reportSmsMemoryStatusResponse(responseInfo);
8824         radioService[slotId]->checkReturnStatus(retStatus);
8825     } else {
8826         RLOGE("reportSmsMemoryStatusResponse: radioService[%d]->mRadioResponse == NULL",
8827                 slotId);
8828     }
8829 
8830     return 0;
8831 }
8832 
reportStkServiceIsRunningResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8833 int radio_1_6::reportStkServiceIsRunningResponse(int slotId,
8834                                              int responseType, int serial, RIL_Errno e,
8835                                              void *response, size_t responseLen) {
8836 #if VDBG
8837     RLOGD("reportStkServiceIsRunningResponse: serial %d", serial);
8838 #endif
8839 
8840     if (radioService[slotId]->mRadioResponse != NULL) {
8841         RadioResponseInfo responseInfo = {};
8842         populateResponseInfo(responseInfo, serial, responseType, e);
8843         Return<void> retStatus = radioService[slotId]->mRadioResponse->
8844                 reportStkServiceIsRunningResponse(responseInfo);
8845         radioService[slotId]->checkReturnStatus(retStatus);
8846     } else {
8847         RLOGE("reportStkServiceIsRunningResponse: radioService[%d]->mRadioResponse == NULL",
8848                 slotId);
8849     }
8850 
8851     return 0;
8852 }
8853 
getCdmaSubscriptionSourceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8854 int radio_1_6::getCdmaSubscriptionSourceResponse(int slotId,
8855                                             int responseType, int serial, RIL_Errno e,
8856                                             void *response, size_t responseLen) {
8857 #if VDBG
8858     RLOGD("getCdmaSubscriptionSourceResponse: serial %d", serial);
8859 #endif
8860 
8861     if (radioService[slotId]->mRadioResponse != NULL) {
8862         RadioResponseInfo responseInfo = {};
8863         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8864         Return<void> retStatus
8865                 = radioService[slotId]->mRadioResponse->getCdmaSubscriptionSourceResponse(
8866                 responseInfo, (CdmaSubscriptionSource) ret);
8867         radioService[slotId]->checkReturnStatus(retStatus);
8868     } else {
8869         RLOGE("getCdmaSubscriptionSourceResponse: radioService[%d]->mRadioResponse == NULL",
8870                 slotId);
8871     }
8872 
8873     return 0;
8874 }
8875 
requestIsimAuthenticationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8876 int radio_1_6::requestIsimAuthenticationResponse(int slotId,
8877                                             int responseType, int serial, RIL_Errno e,
8878                                             void *response, size_t responseLen) {
8879 #if VDBG
8880     RLOGD("requestIsimAuthenticationResponse: serial %d", serial);
8881 #endif
8882 
8883     if (radioService[slotId]->mRadioResponse != NULL) {
8884         RadioResponseInfo responseInfo = {};
8885         populateResponseInfo(responseInfo, serial, responseType, e);
8886         Return<void> retStatus
8887                 = radioService[slotId]->mRadioResponse->requestIsimAuthenticationResponse(
8888                 responseInfo,
8889                 convertCharPtrToHidlString((char *) response));
8890         radioService[slotId]->checkReturnStatus(retStatus);
8891     } else {
8892         RLOGE("requestIsimAuthenticationResponse: radioService[%d]->mRadioResponse == NULL",
8893                 slotId);
8894     }
8895 
8896     return 0;
8897 }
8898 
acknowledgeIncomingGsmSmsWithPduResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8899 int radio_1_6::acknowledgeIncomingGsmSmsWithPduResponse(int slotId,
8900                                                    int responseType,
8901                                                    int serial, RIL_Errno e, void *response,
8902                                                    size_t responseLen) {
8903 #if VDBG
8904     RLOGD("acknowledgeIncomingGsmSmsWithPduResponse: serial %d", serial);
8905 #endif
8906 
8907     if (radioService[slotId]->mRadioResponse != NULL) {
8908         RadioResponseInfo responseInfo = {};
8909         populateResponseInfo(responseInfo, serial, responseType, e);
8910         Return<void> retStatus
8911                 = radioService[slotId]->mRadioResponse->acknowledgeIncomingGsmSmsWithPduResponse(
8912                 responseInfo);
8913         radioService[slotId]->checkReturnStatus(retStatus);
8914     } else {
8915         RLOGE("acknowledgeIncomingGsmSmsWithPduResponse: radioService[%d]->mRadioResponse "
8916                 "== NULL", slotId);
8917     }
8918 
8919     return 0;
8920 }
8921 
sendEnvelopeWithStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8922 int radio_1_6::sendEnvelopeWithStatusResponse(int slotId,
8923                                          int responseType, int serial, RIL_Errno e, void *response,
8924                                          size_t responseLen) {
8925 #if VDBG
8926     RLOGD("sendEnvelopeWithStatusResponse: serial %d", serial);
8927 #endif
8928 
8929     if (radioService[slotId]->mRadioResponse != NULL) {
8930         RadioResponseInfo responseInfo = {};
8931         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e,
8932                 response, responseLen);
8933 
8934         Return<void> retStatus
8935                 = radioService[slotId]->mRadioResponse->sendEnvelopeWithStatusResponse(responseInfo,
8936                 result);
8937         radioService[slotId]->checkReturnStatus(retStatus);
8938     } else {
8939         RLOGE("sendEnvelopeWithStatusResponse: radioService[%d]->mRadioResponse == NULL",
8940                 slotId);
8941     }
8942 
8943     return 0;
8944 }
8945 
getVoiceRadioTechnologyResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8946 int radio_1_6::getVoiceRadioTechnologyResponse(int slotId,
8947                                           int responseType, int serial, RIL_Errno e,
8948                                           void *response, size_t responseLen) {
8949 #if VDBG
8950     RLOGD("getVoiceRadioTechnologyResponse: serial %d", serial);
8951 #endif
8952 
8953     if (radioService[slotId]->mRadioResponse != NULL) {
8954         RadioResponseInfo responseInfo = {};
8955         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8956         Return<void> retStatus
8957                 = radioService[slotId]->mRadioResponse->getVoiceRadioTechnologyResponse(
8958                 responseInfo, (RadioTechnology) ret);
8959         radioService[slotId]->checkReturnStatus(retStatus);
8960     } else {
8961         RLOGE("getVoiceRadioTechnologyResponse: radioService[%d]->mRadioResponse == NULL",
8962                 slotId);
8963     }
8964 
8965     return 0;
8966 }
8967 
getCellInfoListResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8968 int radio_1_6::getCellInfoListResponse(int slotId, int responseType, int serial, RIL_Errno e,
8969                                        void* response, size_t responseLen) {
8970 #if VDBG
8971     RLOGD("getCellInfoListResponse: serial %d", serial);
8972 #endif
8973     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
8974         V1_6::RadioResponseInfo responseInfo = {};
8975         populateResponseInfo_1_6(responseInfo, serial, responseType, e);
8976         hidl_vec<V1_6::CellInfo> ret;
8977         Return<void> retStatus;
8978         if (response != NULL && responseLen != 0 && responseLen % sizeof(RIL_CellInfo_v16) == 0) {
8979             convertRilCellInfoListToHal_1_6(response, responseLen, ret);
8980         } else {
8981             RLOGE("getCellInfoListResponse_1_6: Invalid response");
8982             if (e == RIL_E_SUCCESS) responseInfo.error = V1_6::RadioError::INVALID_RESPONSE;
8983         }
8984         retStatus = radioService[slotId]->mRadioResponseV1_6->getCellInfoListResponse_1_6(
8985                 responseInfo, ret);
8986         radioService[slotId]->checkReturnStatus(retStatus);
8987     } else if (radioService[slotId]->mRadioResponse != NULL ||
8988                radioService[slotId]->mRadioResponseV1_2 != NULL ||
8989                radioService[slotId]->mRadioResponseV1_4 != NULL ||
8990                radioService[slotId]->mRadioResponseV1_5 != NULL) {
8991         RadioResponseInfo responseInfo = {};
8992         populateResponseInfo(responseInfo, serial, responseType, e);
8993         bool error = response == NULL && responseLen != 0;
8994         Return<void> retStatus;
8995         if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
8996             hidl_vec<V1_5::CellInfo> ret;
8997             if (!error && responseLen % sizeof(RIL_CellInfo_v16) != 0) {
8998                 convertRilCellInfoListToHal_1_5(response, responseLen, ret);
8999             } else {
9000                 RLOGE("getCellInfoListResponse_1_5: Invalid response");
9001                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9002             }
9003             retStatus = radioService[slotId]->mRadioResponseV1_5->getCellInfoListResponse_1_5(
9004                     responseInfo, ret);
9005         } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9006             hidl_vec<V1_4::CellInfo> ret;
9007             if (!error && responseLen % sizeof(RIL_CellInfo_v16) != 0) {
9008                 convertRilCellInfoListToHal_1_4(response, responseLen, ret);
9009             } else {
9010                 RLOGE("getCellInfoListResponse_1_4: Invalid response");
9011                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9012             }
9013             radioService[slotId]->mRadioResponseV1_4->getCellInfoListResponse_1_4(responseInfo,
9014                                                                                   ret);
9015         } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
9016             hidl_vec<V1_2::CellInfo> ret;
9017             if (!error && responseLen % sizeof(RIL_CellInfo_v12) != 0) {
9018                 convertRilCellInfoListToHal_1_2(response, responseLen, ret);
9019             } else {
9020                 RLOGE("getCellInfoListResponse_1_2: Invalid response");
9021                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9022             }
9023             radioService[slotId]->mRadioResponseV1_2->getCellInfoListResponse_1_2(responseInfo,
9024                                                                                   ret);
9025         } else {
9026             hidl_vec<CellInfo> ret;
9027             if (!error && responseLen % sizeof(RIL_CellInfo) != 0) {
9028                 convertRilCellInfoListToHal(response, responseLen, ret);
9029             } else {
9030                 RLOGE("getCellInfoListResponse: Invalid response");
9031                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9032             }
9033             radioService[slotId]->mRadioResponse->getCellInfoListResponse(responseInfo, ret);
9034         }
9035         radioService[slotId]->checkReturnStatus(retStatus);
9036     } else {
9037         RLOGE("getCellInfoListResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9038     }
9039 
9040     return 0;
9041 }
9042 
setCellInfoListRateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9043 int radio_1_6::setCellInfoListRateResponse(int slotId,
9044                                        int responseType,
9045                                        int serial, RIL_Errno e, void *response,
9046                                        size_t responseLen) {
9047 #if VDBG
9048     RLOGD("setCellInfoListRateResponse: serial %d", serial);
9049 #endif
9050 
9051     if (radioService[slotId]->mRadioResponse != NULL) {
9052         RadioResponseInfo responseInfo = {};
9053         populateResponseInfo(responseInfo, serial, responseType, e);
9054         Return<void> retStatus
9055                 = radioService[slotId]->mRadioResponse->setCellInfoListRateResponse(responseInfo);
9056         radioService[slotId]->checkReturnStatus(retStatus);
9057     } else {
9058         RLOGE("setCellInfoListRateResponse: radioService[%d]->mRadioResponse == NULL",
9059                 slotId);
9060     }
9061 
9062     return 0;
9063 }
9064 
setInitialAttachApnResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9065 int radio_1_6::setInitialAttachApnResponse(int slotId, int responseType, int serial, RIL_Errno e,
9066                                            void* response, size_t responseLen) {
9067 #if VDBG
9068     RLOGD("setInitialAttachApnResponse: serial %d", serial);
9069 #endif
9070 
9071     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
9072         RadioResponseInfo responseInfo = {};
9073         populateResponseInfo(responseInfo, serial, responseType, e);
9074         Return<void> retStatus =
9075                 radioService[slotId]->mRadioResponseV1_5->setInitialAttachApnResponse_1_5(
9076                         responseInfo);
9077         radioService[slotId]->checkReturnStatus(retStatus);
9078     } else if (radioService[slotId]->mRadioResponse != NULL) {
9079         RadioResponseInfo responseInfo = {};
9080         populateResponseInfo(responseInfo, serial, responseType, e);
9081         Return<void> retStatus =
9082                 radioService[slotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo);
9083         radioService[slotId]->checkReturnStatus(retStatus);
9084     } else {
9085         RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9086     }
9087 
9088     return 0;
9089 }
9090 
getImsRegistrationStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9091 int radio_1_6::getImsRegistrationStateResponse(int slotId,
9092                                            int responseType, int serial, RIL_Errno e,
9093                                            void *response, size_t responseLen) {
9094 #if VDBG
9095     RLOGD("getImsRegistrationStateResponse: serial %d", serial);
9096 #endif
9097 
9098     if (radioService[slotId]->mRadioResponse != NULL) {
9099         RadioResponseInfo responseInfo = {};
9100         populateResponseInfo(responseInfo, serial, responseType, e);
9101         bool isRegistered = false;
9102         int ratFamily = 0;
9103         int numInts = responseLen / sizeof(int);
9104         if (response == NULL || numInts != 2) {
9105             RLOGE("getImsRegistrationStateResponse Invalid response: NULL");
9106             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9107         } else {
9108             int *pInt = (int *) response;
9109             isRegistered = pInt[0] == 1 ? true : false;
9110             ratFamily = pInt[1];
9111         }
9112         Return<void> retStatus
9113                 = radioService[slotId]->mRadioResponse->getImsRegistrationStateResponse(
9114                 responseInfo, isRegistered, (RadioTechnologyFamily) ratFamily);
9115         radioService[slotId]->checkReturnStatus(retStatus);
9116     } else {
9117         RLOGE("getImsRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
9118                 slotId);
9119     }
9120 
9121     return 0;
9122 }
9123 
sendImsSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9124 int radio_1_6::sendImsSmsResponse(int slotId,
9125                               int responseType, int serial, RIL_Errno e, void *response,
9126                               size_t responseLen) {
9127 #if VDBG
9128     RLOGD("sendImsSmsResponse: serial %d", serial);
9129 #endif
9130 
9131     if (radioService[slotId]->mRadioResponse != NULL) {
9132         RadioResponseInfo responseInfo = {};
9133         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
9134                 responseLen);
9135 
9136         Return<void> retStatus
9137                 = radioService[slotId]->mRadioResponse->sendImsSmsResponse(responseInfo, result);
9138         radioService[slotId]->checkReturnStatus(retStatus);
9139     } else {
9140         RLOGE("sendSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9141     }
9142 
9143     return 0;
9144 }
9145 
iccTransmitApduBasicChannelResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9146 int radio_1_6::iccTransmitApduBasicChannelResponse(int slotId,
9147                                                int responseType, int serial, RIL_Errno e,
9148                                                void *response, size_t responseLen) {
9149 #if VDBG
9150     RLOGD("iccTransmitApduBasicChannelResponse: serial %d", serial);
9151 #endif
9152 
9153     if (radioService[slotId]->mRadioResponse != NULL) {
9154         RadioResponseInfo responseInfo = {};
9155         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
9156                 responseLen);
9157 
9158         Return<void> retStatus
9159                 = radioService[slotId]->mRadioResponse->iccTransmitApduBasicChannelResponse(
9160                 responseInfo, result);
9161         radioService[slotId]->checkReturnStatus(retStatus);
9162     } else {
9163         RLOGE("iccTransmitApduBasicChannelResponse: radioService[%d]->mRadioResponse "
9164                 "== NULL", slotId);
9165     }
9166 
9167     return 0;
9168 }
9169 
iccOpenLogicalChannelResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9170 int radio_1_6::iccOpenLogicalChannelResponse(int slotId,
9171                                          int responseType, int serial, RIL_Errno e, void *response,
9172                                          size_t responseLen) {
9173 #if VDBG
9174     RLOGD("iccOpenLogicalChannelResponse: serial %d", serial);
9175 #endif
9176 
9177     if (radioService[slotId]->mRadioResponse != NULL) {
9178         RadioResponseInfo responseInfo = {};
9179         populateResponseInfo(responseInfo, serial, responseType, e);
9180         int channelId = -1;
9181         hidl_vec<int8_t> selectResponse;
9182         int numInts = responseLen / sizeof(int);
9183         if (response == NULL || responseLen % sizeof(int) != 0) {
9184             RLOGE("iccOpenLogicalChannelResponse Invalid response: NULL");
9185             if (response != NULL) {
9186                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9187             }
9188         } else {
9189             int *pInt = (int *) response;
9190             channelId = pInt[0];
9191             selectResponse.resize(numInts - 1);
9192             for (int i = 1; i < numInts; i++) {
9193                 selectResponse[i - 1] = (int8_t) pInt[i];
9194             }
9195         }
9196         Return<void> retStatus
9197                 = radioService[slotId]->mRadioResponse->iccOpenLogicalChannelResponse(responseInfo,
9198                 channelId, selectResponse);
9199         radioService[slotId]->checkReturnStatus(retStatus);
9200     } else {
9201         RLOGE("iccOpenLogicalChannelResponse: radioService[%d]->mRadioResponse == NULL",
9202                 slotId);
9203     }
9204 
9205     return 0;
9206 }
9207 
iccCloseLogicalChannelResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9208 int radio_1_6::iccCloseLogicalChannelResponse(int slotId,
9209                                           int responseType, int serial, RIL_Errno e,
9210                                           void *response, size_t responseLen) {
9211 #if VDBG
9212     RLOGD("iccCloseLogicalChannelResponse: serial %d", serial);
9213 #endif
9214 
9215     if (radioService[slotId]->mRadioResponse != NULL) {
9216         RadioResponseInfo responseInfo = {};
9217         populateResponseInfo(responseInfo, serial, responseType, e);
9218         Return<void> retStatus
9219                 = radioService[slotId]->mRadioResponse->iccCloseLogicalChannelResponse(
9220                 responseInfo);
9221         radioService[slotId]->checkReturnStatus(retStatus);
9222     } else {
9223         RLOGE("iccCloseLogicalChannelResponse: radioService[%d]->mRadioResponse == NULL",
9224                 slotId);
9225     }
9226 
9227     return 0;
9228 }
9229 
iccTransmitApduLogicalChannelResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9230 int radio_1_6::iccTransmitApduLogicalChannelResponse(int slotId,
9231                                                  int responseType, int serial, RIL_Errno e,
9232                                                  void *response, size_t responseLen) {
9233 #if VDBG
9234     RLOGD("iccTransmitApduLogicalChannelResponse: serial %d", serial);
9235 #endif
9236 
9237     if (radioService[slotId]->mRadioResponse != NULL) {
9238         RadioResponseInfo responseInfo = {};
9239         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
9240                 responseLen);
9241 
9242         Return<void> retStatus
9243                 = radioService[slotId]->mRadioResponse->iccTransmitApduLogicalChannelResponse(
9244                 responseInfo, result);
9245         radioService[slotId]->checkReturnStatus(retStatus);
9246     } else {
9247         RLOGE("iccTransmitApduLogicalChannelResponse: radioService[%d]->mRadioResponse "
9248                 "== NULL", slotId);
9249     }
9250 
9251     return 0;
9252 }
9253 
nvReadItemResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9254 int radio_1_6::nvReadItemResponse(int slotId,
9255                               int responseType, int serial, RIL_Errno e,
9256                               void *response, size_t responseLen) {
9257 #if VDBG
9258     RLOGD("nvReadItemResponse: serial %d", serial);
9259 #endif
9260 
9261     if (radioService[slotId]->mRadioResponse != NULL) {
9262         RadioResponseInfo responseInfo = {};
9263         populateResponseInfo(responseInfo, serial, responseType, e);
9264         Return<void> retStatus = radioService[slotId]->mRadioResponse->nvReadItemResponse(
9265                 responseInfo,
9266                 convertCharPtrToHidlString((char *) response));
9267         radioService[slotId]->checkReturnStatus(retStatus);
9268     } else {
9269         RLOGE("nvReadItemResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9270     }
9271 
9272     return 0;
9273 }
9274 
nvWriteItemResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9275 int radio_1_6::nvWriteItemResponse(int slotId,
9276                                int responseType, int serial, RIL_Errno e,
9277                                void *response, size_t responseLen) {
9278 #if VDBG
9279     RLOGD("nvWriteItemResponse: serial %d", serial);
9280 #endif
9281 
9282     if (radioService[slotId]->mRadioResponse != NULL) {
9283         RadioResponseInfo responseInfo = {};
9284         populateResponseInfo(responseInfo, serial, responseType, e);
9285         Return<void> retStatus
9286                 = radioService[slotId]->mRadioResponse->nvWriteItemResponse(responseInfo);
9287         radioService[slotId]->checkReturnStatus(retStatus);
9288     } else {
9289         RLOGE("nvWriteItemResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9290     }
9291 
9292     return 0;
9293 }
9294 
nvWriteCdmaPrlResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9295 int radio_1_6::nvWriteCdmaPrlResponse(int slotId,
9296                                   int responseType, int serial, RIL_Errno e,
9297                                   void *response, size_t responseLen) {
9298 #if VDBG
9299     RLOGD("nvWriteCdmaPrlResponse: serial %d", serial);
9300 #endif
9301 
9302     if (radioService[slotId]->mRadioResponse != NULL) {
9303         RadioResponseInfo responseInfo = {};
9304         populateResponseInfo(responseInfo, serial, responseType, e);
9305         Return<void> retStatus
9306                 = radioService[slotId]->mRadioResponse->nvWriteCdmaPrlResponse(responseInfo);
9307         radioService[slotId]->checkReturnStatus(retStatus);
9308     } else {
9309         RLOGE("nvWriteCdmaPrlResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9310     }
9311 
9312     return 0;
9313 }
9314 
nvResetConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9315 int radio_1_6::nvResetConfigResponse(int slotId,
9316                                  int responseType, int serial, RIL_Errno e,
9317                                  void *response, size_t responseLen) {
9318 #if VDBG
9319     RLOGD("nvResetConfigResponse: serial %d", serial);
9320 #endif
9321 
9322     if (radioService[slotId]->mRadioResponse != NULL) {
9323         RadioResponseInfo responseInfo = {};
9324         populateResponseInfo(responseInfo, serial, responseType, e);
9325         Return<void> retStatus
9326                 = radioService[slotId]->mRadioResponse->nvResetConfigResponse(responseInfo);
9327         radioService[slotId]->checkReturnStatus(retStatus);
9328     } else {
9329         RLOGE("nvResetConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9330     }
9331 
9332     return 0;
9333 }
9334 
setUiccSubscriptionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9335 int radio_1_6::setUiccSubscriptionResponse(int slotId,
9336                                        int responseType, int serial, RIL_Errno e,
9337                                        void *response, size_t responseLen) {
9338 #if VDBG
9339     RLOGD("setUiccSubscriptionResponse: serial %d", serial);
9340 #endif
9341 
9342     if (radioService[slotId]->mRadioResponse != NULL) {
9343         RadioResponseInfo responseInfo = {};
9344         populateResponseInfo(responseInfo, serial, responseType, e);
9345         Return<void> retStatus
9346                 = radioService[slotId]->mRadioResponse->setUiccSubscriptionResponse(responseInfo);
9347         radioService[slotId]->checkReturnStatus(retStatus);
9348     } else {
9349         RLOGE("setUiccSubscriptionResponse: radioService[%d]->mRadioResponse == NULL",
9350                 slotId);
9351     }
9352 
9353     return 0;
9354 }
9355 
setDataAllowedResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9356 int radio_1_6::setDataAllowedResponse(int slotId,
9357                                   int responseType, int serial, RIL_Errno e,
9358                                   void *response, size_t responseLen) {
9359 #if VDBG
9360     RLOGD("setDataAllowedResponse: serial %d", serial);
9361 #endif
9362 
9363     if (radioService[slotId]->mRadioResponse != NULL) {
9364         RadioResponseInfo responseInfo = {};
9365         populateResponseInfo(responseInfo, serial, responseType, e);
9366         Return<void> retStatus
9367                 = radioService[slotId]->mRadioResponse->setDataAllowedResponse(responseInfo);
9368         radioService[slotId]->checkReturnStatus(retStatus);
9369     } else {
9370         RLOGE("setDataAllowedResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9371     }
9372 
9373     return 0;
9374 }
9375 
getHardwareConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9376 int radio_1_6::getHardwareConfigResponse(int slotId,
9377                                      int responseType, int serial, RIL_Errno e,
9378                                      void *response, size_t responseLen) {
9379 #if VDBG
9380     RLOGD("getHardwareConfigResponse: serial %d", serial);
9381 #endif
9382 
9383     if (radioService[slotId]->mRadioResponse != NULL) {
9384         RadioResponseInfo responseInfo = {};
9385         populateResponseInfo(responseInfo, serial, responseType, e);
9386 
9387         hidl_vec<HardwareConfig> result;
9388         if ((response == NULL && responseLen != 0)
9389                 || responseLen % sizeof(RIL_HardwareConfig) != 0) {
9390             RLOGE("hardwareConfigChangedInd: invalid response");
9391             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9392         } else {
9393             convertRilHardwareConfigListToHal(response, responseLen, result);
9394         }
9395 
9396         Return<void> retStatus = radioService[slotId]->mRadioResponse->getHardwareConfigResponse(
9397                 responseInfo, result);
9398         radioService[slotId]->checkReturnStatus(retStatus);
9399     } else {
9400         RLOGE("getHardwareConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9401     }
9402 
9403     return 0;
9404 }
9405 
requestIccSimAuthenticationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9406 int radio_1_6::requestIccSimAuthenticationResponse(int slotId,
9407                                                int responseType, int serial, RIL_Errno e,
9408                                                void *response, size_t responseLen) {
9409 #if VDBG
9410     RLOGD("requestIccSimAuthenticationResponse: serial %d", serial);
9411 #endif
9412 
9413     if (radioService[slotId]->mRadioResponse != NULL) {
9414         RadioResponseInfo responseInfo = {};
9415         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
9416                 responseLen);
9417 
9418         Return<void> retStatus
9419                 = radioService[slotId]->mRadioResponse->requestIccSimAuthenticationResponse(
9420                 responseInfo, result);
9421         radioService[slotId]->checkReturnStatus(retStatus);
9422     } else {
9423         RLOGE("requestIccSimAuthenticationResponse: radioService[%d]->mRadioResponse "
9424                 "== NULL", slotId);
9425     }
9426 
9427     return 0;
9428 }
9429 
setDataProfileResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9430 int radio_1_6::setDataProfileResponse(int slotId,
9431                                   int responseType, int serial, RIL_Errno e,
9432                                   void *response, size_t responseLen) {
9433 #if VDBG
9434     RLOGD("setDataProfileResponse: serial %d", serial);
9435 #endif
9436 
9437     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
9438         RadioResponseInfo responseInfo = {};
9439         populateResponseInfo(responseInfo, serial, responseType, e);
9440         Return<void> retStatus
9441                 = radioService[slotId]->mRadioResponseV1_5->setDataProfileResponse_1_5(
9442                 responseInfo);
9443     } else if (radioService[slotId]->mRadioResponse != NULL) {
9444         RadioResponseInfo responseInfo = {};
9445         populateResponseInfo(responseInfo, serial, responseType, e);
9446         Return<void> retStatus
9447                 = radioService[slotId]->mRadioResponse->setDataProfileResponse(responseInfo);
9448         radioService[slotId]->checkReturnStatus(retStatus);
9449     } else {
9450         RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9451     }
9452 
9453     return 0;
9454 }
9455 
requestShutdownResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9456 int radio_1_6::requestShutdownResponse(int slotId,
9457                                   int responseType, int serial, RIL_Errno e,
9458                                   void *response, size_t responseLen) {
9459 #if VDBG
9460     RLOGD("requestShutdownResponse: serial %d", serial);
9461 #endif
9462 
9463     if (radioService[slotId]->mRadioResponse != NULL) {
9464         RadioResponseInfo responseInfo = {};
9465         populateResponseInfo(responseInfo, serial, responseType, e);
9466         Return<void> retStatus
9467                 = radioService[slotId]->mRadioResponse->requestShutdownResponse(responseInfo);
9468         radioService[slotId]->checkReturnStatus(retStatus);
9469     } else {
9470         RLOGE("requestShutdownResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9471     }
9472 
9473     return 0;
9474 }
9475 
responseRadioCapability(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen,RadioCapability & rc)9476 void responseRadioCapability(RadioResponseInfo& responseInfo, int serial,
9477         int responseType, RIL_Errno e, void *response, size_t responseLen, RadioCapability& rc) {
9478     populateResponseInfo(responseInfo, serial, responseType, e);
9479 
9480     if (response == NULL || responseLen != sizeof(RIL_RadioCapability)) {
9481         RLOGE("responseRadioCapability: Invalid response");
9482         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9483         rc.logicalModemUuid = hidl_string();
9484     } else {
9485         convertRilRadioCapabilityToHal(response, responseLen, rc);
9486     }
9487 }
9488 
getRadioCapabilityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9489 int radio_1_6::getRadioCapabilityResponse(int slotId,
9490                                      int responseType, int serial, RIL_Errno e,
9491                                      void *response, size_t responseLen) {
9492 #if VDBG
9493     RLOGD("getRadioCapabilityResponse: serial %d", serial);
9494 #endif
9495 
9496     if (radioService[slotId]->mRadioResponse != NULL) {
9497         RadioResponseInfo responseInfo = {};
9498         RadioCapability result = {};
9499         responseRadioCapability(responseInfo, serial, responseType, e, response, responseLen,
9500                 result);
9501         Return<void> retStatus = radioService[slotId]->mRadioResponse->getRadioCapabilityResponse(
9502                 responseInfo, result);
9503         radioService[slotId]->checkReturnStatus(retStatus);
9504     } else {
9505         RLOGE("getRadioCapabilityResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9506     }
9507 
9508     return 0;
9509 }
9510 
setRadioCapabilityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9511 int radio_1_6::setRadioCapabilityResponse(int slotId,
9512                                      int responseType, int serial, RIL_Errno e,
9513                                      void *response, size_t responseLen) {
9514 #if VDBG
9515     RLOGD("setRadioCapabilityResponse: serial %d", serial);
9516 #endif
9517 
9518     if (radioService[slotId]->mRadioResponse != NULL) {
9519         RadioResponseInfo responseInfo = {};
9520         RadioCapability result = {};
9521         responseRadioCapability(responseInfo, serial, responseType, e, response, responseLen,
9522                 result);
9523         Return<void> retStatus = radioService[slotId]->mRadioResponse->setRadioCapabilityResponse(
9524                 responseInfo, result);
9525         radioService[slotId]->checkReturnStatus(retStatus);
9526     } else {
9527         RLOGE("setRadioCapabilityResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9528     }
9529 
9530     return 0;
9531 }
9532 
responseLceStatusInfo(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)9533 LceStatusInfo responseLceStatusInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
9534                                     RIL_Errno e, void *response, size_t responseLen) {
9535     populateResponseInfo(responseInfo, serial, responseType, e);
9536     LceStatusInfo result = {};
9537 
9538     if (response == NULL || responseLen != sizeof(RIL_LceStatusInfo)) {
9539         RLOGE("Invalid response: NULL");
9540         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9541     } else {
9542         RIL_LceStatusInfo *resp = (RIL_LceStatusInfo *) response;
9543         result.lceStatus = (LceStatus) resp->lce_status;
9544         result.actualIntervalMs = (uint8_t) resp->actual_interval_ms;
9545     }
9546     return result;
9547 }
9548 
startLceServiceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9549 int radio_1_6::startLceServiceResponse(int slotId,
9550                                    int responseType, int serial, RIL_Errno e,
9551                                    void *response, size_t responseLen) {
9552 #if VDBG
9553     RLOGD("startLceServiceResponse: serial %d", serial);
9554 #endif
9555 
9556     if (radioService[slotId]->mRadioResponse != NULL) {
9557         RadioResponseInfo responseInfo = {};
9558         LceStatusInfo result = responseLceStatusInfo(responseInfo, serial, responseType, e,
9559                 response, responseLen);
9560 
9561         Return<void> retStatus
9562                 = radioService[slotId]->mRadioResponse->startLceServiceResponse(responseInfo,
9563                 result);
9564         radioService[slotId]->checkReturnStatus(retStatus);
9565     } else {
9566         RLOGE("startLceServiceResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9567     }
9568 
9569     return 0;
9570 }
9571 
stopLceServiceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9572 int radio_1_6::stopLceServiceResponse(int slotId,
9573                                   int responseType, int serial, RIL_Errno e,
9574                                   void *response, size_t responseLen) {
9575 #if VDBG
9576     RLOGD("stopLceServiceResponse: serial %d", serial);
9577 #endif
9578 
9579     if (radioService[slotId]->mRadioResponse != NULL) {
9580         RadioResponseInfo responseInfo = {};
9581         LceStatusInfo result = responseLceStatusInfo(responseInfo, serial, responseType, e,
9582                 response, responseLen);
9583 
9584         Return<void> retStatus
9585                 = radioService[slotId]->mRadioResponse->stopLceServiceResponse(responseInfo,
9586                 result);
9587         radioService[slotId]->checkReturnStatus(retStatus);
9588     } else {
9589         RLOGE("stopLceServiceResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9590     }
9591 
9592     return 0;
9593 }
9594 
pullLceDataResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9595 int radio_1_6::pullLceDataResponse(int slotId,
9596                                int responseType, int serial, RIL_Errno e,
9597                                void *response, size_t responseLen) {
9598 #if VDBG
9599     RLOGD("pullLceDataResponse: serial %d", serial);
9600 #endif
9601 
9602     if (radioService[slotId]->mRadioResponse != NULL) {
9603         RadioResponseInfo responseInfo = {};
9604         populateResponseInfo(responseInfo, serial, responseType, e);
9605 
9606         LceDataInfo result = {};
9607         if (response == NULL || responseLen != sizeof(RIL_LceDataInfo)) {
9608             RLOGE("pullLceDataResponse: Invalid response");
9609             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9610         } else {
9611             convertRilLceDataInfoToHal(response, responseLen, result);
9612         }
9613 
9614         Return<void> retStatus = radioService[slotId]->mRadioResponse->pullLceDataResponse(
9615                 responseInfo, result);
9616         radioService[slotId]->checkReturnStatus(retStatus);
9617     } else {
9618         RLOGE("pullLceDataResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9619     }
9620 
9621     return 0;
9622 }
9623 
getModemActivityInfoResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9624 int radio_1_6::getModemActivityInfoResponse(int slotId,
9625                                         int responseType, int serial, RIL_Errno e,
9626                                         void *response, size_t responseLen) {
9627 #if VDBG
9628     RLOGD("getModemActivityInfoResponse: serial %d", serial);
9629 #endif
9630 
9631     if (radioService[slotId]->mRadioResponse != NULL) {
9632         RadioResponseInfo responseInfo = {};
9633         populateResponseInfo(responseInfo, serial, responseType, e);
9634         ActivityStatsInfo info;
9635         if (response == NULL || responseLen != sizeof(RIL_ActivityStatsInfo)) {
9636             RLOGE("getModemActivityInfoResponse Invalid response: NULL");
9637             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9638         } else {
9639             RIL_ActivityStatsInfo *resp = (RIL_ActivityStatsInfo *)response;
9640             info.sleepModeTimeMs = resp->sleep_mode_time_ms;
9641             info.idleModeTimeMs = resp->idle_mode_time_ms;
9642             for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
9643                 info.txmModetimeMs[i] = resp->tx_mode_time_ms[i];
9644             }
9645             info.rxModeTimeMs = resp->rx_mode_time_ms;
9646         }
9647 
9648         Return<void> retStatus
9649                 = radioService[slotId]->mRadioResponse->getModemActivityInfoResponse(responseInfo,
9650                 info);
9651         radioService[slotId]->checkReturnStatus(retStatus);
9652     } else {
9653         RLOGE("getModemActivityInfoResponse: radioService[%d]->mRadioResponse == NULL",
9654                 slotId);
9655     }
9656 
9657     return 0;
9658 }
9659 
setAllowedCarriersResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9660 int radio_1_6::setAllowedCarriersResponse(int slotId,
9661                                       int responseType, int serial, RIL_Errno e,
9662                                       void *response, size_t responseLen) {
9663 #if VDBG
9664     RLOGD("setAllowedCarriersResponse: serial %d", serial);
9665 #endif
9666     RadioResponseInfo responseInfo = {};
9667     populateResponseInfo(responseInfo, serial, responseType, e);
9668 
9669     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9670         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4
9671                 ->setAllowedCarriersResponse_1_4(responseInfo);
9672         radioService[slotId]->checkReturnStatus(retStatus);
9673     } else if (radioService[slotId]->mRadioResponse != NULL) {
9674         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
9675         Return<void> retStatus = radioService[slotId]->mRadioResponse
9676                 ->setAllowedCarriersResponse(responseInfo, ret);
9677         radioService[slotId]->checkReturnStatus(retStatus);
9678     } else {
9679         RLOGE("setAllowedCarriersResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9680     }
9681 
9682     return 0;
9683 }
9684 
prepareCarrierRestrictionsResponse(hidl_vec<Carrier> & allowedCarriers,hidl_vec<Carrier> & excludedCarriers,bool & allAllowed,const RIL_CarrierRestrictions * pCr)9685 void prepareCarrierRestrictionsResponse(hidl_vec<Carrier>& allowedCarriers,
9686                                        hidl_vec<Carrier>& excludedCarriers,
9687                                        bool& allAllowed,
9688                                        const RIL_CarrierRestrictions* pCr) {
9689     if (pCr->len_allowed_carriers > 0 || pCr->len_excluded_carriers > 0) {
9690         allAllowed = false;
9691     }
9692     allowedCarriers.resize(pCr->len_allowed_carriers);
9693     for(int i = 0; i < pCr->len_allowed_carriers; i++) {
9694         RIL_Carrier *carrier = pCr->allowed_carriers + i;
9695         allowedCarriers[i].mcc = convertCharPtrToHidlString(carrier->mcc);
9696         allowedCarriers[i].mnc = convertCharPtrToHidlString(carrier->mnc);
9697         allowedCarriers[i].matchType = (CarrierMatchType) carrier->match_type;
9698         allowedCarriers[i].matchData =
9699                 convertCharPtrToHidlString(carrier->match_data);
9700     }
9701 
9702     excludedCarriers.resize(pCr->len_excluded_carriers);
9703     for(int i = 0; i < pCr->len_excluded_carriers; i++) {
9704         RIL_Carrier *carrier = pCr->excluded_carriers + i;
9705         excludedCarriers[i].mcc = convertCharPtrToHidlString(carrier->mcc);
9706         excludedCarriers[i].mnc = convertCharPtrToHidlString(carrier->mnc);
9707         excludedCarriers[i].matchType = (CarrierMatchType) carrier->match_type;
9708         excludedCarriers[i].matchData =
9709                 convertCharPtrToHidlString(carrier->match_data);
9710     }
9711 }
9712 
getAllowedCarriersResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9713 int radio_1_6::getAllowedCarriersResponse(int slotId,
9714                                       int responseType, int serial, RIL_Errno e,
9715                                       void *response, size_t responseLen) {
9716 #if VDBG
9717     RLOGD("getAllowedCarriersResponse: serial %d", serial);
9718 #endif
9719     RadioResponseInfo responseInfo = {};
9720     populateResponseInfo(responseInfo, serial, responseType, e);
9721 
9722     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9723         V1_4::CarrierRestrictionsWithPriority carrierInfo = {};
9724         V1_4::SimLockMultiSimPolicy multiSimPolicy =
9725                 V1_4::SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
9726         bool allAllowed = true;
9727 
9728         if (response == NULL) {
9729 #if VDBG
9730             RLOGD("getAllowedCarriersResponse response is NULL: all allowed");
9731 #endif
9732             carrierInfo.allowedCarriers.resize(0);
9733             carrierInfo.excludedCarriers.resize(0);
9734             carrierInfo.allowedCarriersPrioritized = false;
9735         } else if (responseLen != sizeof(RIL_CarrierRestrictionsWithPriority)) {
9736             RLOGE("getAllowedCarriersResponse Invalid response");
9737             if (e == RIL_E_SUCCESS) {
9738                 responseInfo.error = RadioError::INVALID_RESPONSE;
9739             }
9740         } else {
9741             RIL_CarrierRestrictionsWithPriority *pCrExt =
9742                     (RIL_CarrierRestrictionsWithPriority *)response;
9743 
9744             // Convert into the structure used in IRadio 1.0 to reuse existing code
9745             RIL_CarrierRestrictions cr = {};
9746             cr.len_allowed_carriers = pCrExt->len_allowed_carriers;
9747             cr.len_excluded_carriers = pCrExt->len_excluded_carriers;
9748             cr.allowed_carriers = pCrExt->allowed_carriers;
9749             cr.excluded_carriers = pCrExt->excluded_carriers;
9750             prepareCarrierRestrictionsResponse(carrierInfo.allowedCarriers,
9751                     carrierInfo.excludedCarriers, allAllowed, &cr);
9752 
9753             carrierInfo.allowedCarriersPrioritized = (bool)pCrExt->allowedCarriersPrioritized;
9754             multiSimPolicy = (V1_4::SimLockMultiSimPolicy)pCrExt->multiSimPolicy;
9755         }
9756 
9757         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4
9758                 ->getAllowedCarriersResponse_1_4(responseInfo, carrierInfo, multiSimPolicy);
9759         radioService[slotId]->checkReturnStatus(retStatus);
9760     } else if (radioService[slotId]->mRadioResponse != NULL) {
9761         CarrierRestrictions carrierInfo = {};
9762         bool allAllowed = true;
9763         if (response == NULL) {
9764 #if VDBG
9765             RLOGD("getAllowedCarriersResponse response is NULL: all allowed");
9766 #endif
9767             carrierInfo.allowedCarriers.resize(0);
9768             carrierInfo.excludedCarriers.resize(0);
9769         } else if (responseLen != sizeof(RIL_CarrierRestrictions)) {
9770             RLOGE("getAllowedCarriersResponse Invalid response");
9771             if (e == RIL_E_SUCCESS) {
9772                 responseInfo.error = RadioError::INVALID_RESPONSE;
9773             }
9774         } else {
9775             RIL_CarrierRestrictions *pCr = (RIL_CarrierRestrictions *)response;
9776             prepareCarrierRestrictionsResponse(carrierInfo.allowedCarriers,
9777                     carrierInfo.excludedCarriers, allAllowed, pCr);
9778         }
9779 
9780         Return<void> retStatus = radioService[slotId]->mRadioResponse
9781                 ->getAllowedCarriersResponse(responseInfo, allAllowed, carrierInfo);
9782         radioService[slotId]->checkReturnStatus(retStatus);
9783     } else {
9784         RLOGE("getAllowedCarriersResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9785     }
9786 
9787     return 0;
9788 }
9789 
sendDeviceStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responselen)9790 int radio_1_6::sendDeviceStateResponse(int slotId,
9791                               int responseType, int serial, RIL_Errno e,
9792                               void *response, size_t responselen) {
9793 #if VDBG
9794     RLOGD("sendDeviceStateResponse: serial %d", serial);
9795 #endif
9796 
9797     if (radioService[slotId]->mRadioResponse != NULL) {
9798         RadioResponseInfo responseInfo = {};
9799         populateResponseInfo(responseInfo, serial, responseType, e);
9800         Return<void> retStatus
9801                 = radioService[slotId]->mRadioResponse->sendDeviceStateResponse(responseInfo);
9802         radioService[slotId]->checkReturnStatus(retStatus);
9803     } else {
9804         RLOGE("sendDeviceStateResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9805     }
9806 
9807     return 0;
9808 }
9809 
setCarrierInfoForImsiEncryptionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9810 int radio_1_6::setCarrierInfoForImsiEncryptionResponse(int slotId,
9811                                int responseType, int serial, RIL_Errno e,
9812                                void *response, size_t responseLen) {
9813   RLOGD("setCarrierInfoForImsiEncryptionResponse: serial %d", serial);
9814   if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
9815       RadioResponseInfo responseInfo = {};
9816       populateResponseInfo(responseInfo, serial, responseType, e);
9817       Return<void> retStatus = radioService[slotId]->mRadioResponseV1_1->
9818               setCarrierInfoForImsiEncryptionResponse(responseInfo);
9819       radioService[slotId]->checkReturnStatus(retStatus);
9820   } else {
9821       RLOGE("setCarrierInfoForImsiEncryptionResponse: radioService[%d]->mRadioResponseV1_1 == "
9822               "NULL", slotId);
9823   }
9824   return 0;
9825 }
9826 
setIndicationFilterResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responselen)9827 int radio_1_6::setIndicationFilterResponse(int slotId,
9828                               int responseType, int serial, RIL_Errno e,
9829                               void *response, size_t responselen) {
9830 #if VDBG
9831     RLOGD("setIndicationFilterResponse: serial %d", serial);
9832 #endif
9833     RadioResponseInfo responseInfo = {};
9834     populateResponseInfo(responseInfo, serial, responseType, e);
9835 
9836     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
9837         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
9838                 ->setIndicationFilterResponse_1_5(responseInfo);
9839         radioService[slotId]->checkReturnStatus(retStatus);
9840     } else if (radioService[slotId]->mRadioResponse != NULL) {
9841         Return<void> retStatus = radioService[slotId]->mRadioResponse
9842                 ->setIndicationFilterResponse(responseInfo);
9843         radioService[slotId]->checkReturnStatus(retStatus);
9844     } else {
9845         RLOGE("setIndicationFilterResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9846     }
9847 
9848     return 0;
9849 }
9850 
setSimCardPowerResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9851 int radio_1_6::setSimCardPowerResponse(int slotId,
9852                                    int responseType, int serial, RIL_Errno e,
9853                                    void *response, size_t responseLen) {
9854 #if VDBG
9855     RLOGD("setSimCardPowerResponse: serial %d", serial);
9856 #endif
9857 
9858     if (radioService[slotId]->mRadioResponse != NULL
9859             || radioService[slotId]->mRadioResponseV1_1 != NULL
9860             || radioService[slotId]->mRadioResponseV1_6 != NULL) {
9861         if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
9862             ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo = {};
9863             populateResponseInfo_1_6(responseInfo, serial, responseType, e);
9864             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6->
9865                     setSimCardPowerResponse_1_6(responseInfo);
9866             radioService[slotId]->checkReturnStatus(retStatus);
9867         } else if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
9868             RLOGD("setSimCardPowerResponse: radioService[%d]->mRadioResponseV1_6 == NULL", slotId);
9869             RadioResponseInfo responseInfo = {};
9870             populateResponseInfo(responseInfo, serial, responseType, e);
9871             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_1->
9872                     setSimCardPowerResponse_1_1(responseInfo);
9873             radioService[slotId]->checkReturnStatus(retStatus);
9874         } else {
9875             RLOGD("setSimCardPowerResponse: radioService[%d]->mRadioResponseV1_6 and V1_1 == NULL",
9876                     slotId);
9877             RadioResponseInfo responseInfo = {};
9878             populateResponseInfo(responseInfo, serial, responseType, e);
9879             Return<void> retStatus = radioService[slotId]->mRadioResponse
9880                     ->setSimCardPowerResponse(responseInfo);
9881             radioService[slotId]->checkReturnStatus(retStatus);
9882         }
9883     } else {
9884         RLOGE("setSimCardPowerResponse: radioService[%d]->mRadioResponse == NULL && "
9885                 "radioService[%d]->mRadioResponseV1_1 and V1_6 == NULL", slotId, slotId);
9886     }
9887     return 0;
9888 }
9889 
startNetworkScanResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9890 int radio_1_6::startNetworkScanResponse(int slotId, int responseType, int serial, RIL_Errno e,
9891                                         void *response, size_t responseLen) {
9892 #if VDBG
9893     RLOGD("startNetworkScanResponse: serial %d", serial);
9894 #endif
9895 
9896     if (radioService[slotId]->mRadioResponseV1_1 != NULL ||
9897           radioService[slotId]->mRadioResponseV1_2 != NULL ||
9898           radioService[slotId]->mRadioResponseV1_4 != NULL ||
9899           radioService[slotId]->mRadioResponseV1_6 != NULL) {
9900         RadioResponseInfo responseInfo = {};
9901         populateResponseInfo(responseInfo, serial, responseType, e);
9902 
9903         if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
9904             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
9905                     ->startNetworkScanResponse_1_5(responseInfo);
9906             radioService[slotId]->checkReturnStatus(retStatus);
9907         } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9908             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4
9909                     ->startNetworkScanResponse_1_4(responseInfo);
9910             radioService[slotId]->checkReturnStatus(retStatus);
9911         } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
9912             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2
9913                     ->startNetworkScanResponse(responseInfo);
9914             radioService[slotId]->checkReturnStatus(retStatus);
9915         }  else if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
9916           Return<void> retStatus = radioService[slotId]->mRadioResponseV1_1
9917                   ->startNetworkScanResponse(responseInfo);
9918           radioService[slotId]->checkReturnStatus(retStatus);
9919         } else {
9920             RLOGE("startNetworkScanResponse: radioService[%d]->mRadioResponseV1_1 == NULL or "
9921                     "radioService[%d]->mRadioResponseV1_4 == NULL", slotId, slotId);
9922         }
9923     }
9924 
9925     return 0;
9926 }
9927 
stopNetworkScanResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9928 int radio_1_6::stopNetworkScanResponse(int slotId, int responseType, int serial, RIL_Errno e,
9929                                    void *response, size_t responseLen) {
9930 #if VDBG
9931     RLOGD("stopNetworkScanResponse: serial %d", serial);
9932 #endif
9933 
9934     if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
9935         RadioResponseInfo responseInfo = {};
9936         populateResponseInfo(responseInfo, serial, responseType, e);
9937         Return<void> retStatus
9938                 = radioService[slotId]->mRadioResponseV1_1->stopNetworkScanResponse(responseInfo);
9939         radioService[slotId]->checkReturnStatus(retStatus);
9940     } else {
9941         RLOGE("stopNetworkScanResponse: radioService[%d]->mRadioResponseV1_1 == NULL", slotId);
9942     }
9943 
9944     return 0;
9945 }
9946 
emergencyDialResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9947 int radio_1_6::emergencyDialResponse(int slotId, int responseType, int serial, RIL_Errno e,
9948                                     void *response, size_t responseLen) {
9949 #if VDBG
9950     RLOGD("emergencyDialResponse: serial %d", serial);
9951 #endif
9952 
9953     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9954         RadioResponseInfo responseInfo = {};
9955         populateResponseInfo(responseInfo, serial, responseType, e);
9956         Return<void> retStatus
9957                 = radioService[slotId]->mRadioResponseV1_4->emergencyDialResponse(responseInfo);
9958         radioService[slotId]->checkReturnStatus(retStatus);
9959     } else {
9960         RLOGE("emergencyDialResponse: radioService[%d]->mRadioResponseV1_4 == NULL", slotId);
9961     }
9962     return 0;
9963 }
9964 
convertRilKeepaliveStatusToHal(const RIL_KeepaliveStatus * rilStatus,V1_1::KeepaliveStatus & halStatus)9965 void convertRilKeepaliveStatusToHal(const RIL_KeepaliveStatus *rilStatus,
9966         V1_1::KeepaliveStatus& halStatus) {
9967     halStatus.sessionHandle = rilStatus->sessionHandle;
9968     halStatus.code = static_cast<V1_1::KeepaliveStatusCode>(rilStatus->code);
9969 }
9970 
startKeepaliveResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9971 int radio_1_6::startKeepaliveResponse(int slotId, int responseType, int serial, RIL_Errno e,
9972                                     void *response, size_t responseLen) {
9973 #if VDBG
9974     RLOGD("%s(): %d", __FUNCTION__, serial);
9975 #endif
9976     RadioResponseInfo responseInfo = {};
9977     populateResponseInfo(responseInfo, serial, responseType, e);
9978 
9979     // If we don't have a radio service, there's nothing we can do
9980     if (radioService[slotId]->mRadioResponseV1_1 == NULL) {
9981         RLOGE("%s: radioService[%d]->mRadioResponseV1_1 == NULL", __FUNCTION__, slotId);
9982         return 0;
9983     }
9984 
9985     V1_1::KeepaliveStatus ks = {};
9986     if (response == NULL || responseLen != sizeof(V1_1::KeepaliveStatus)) {
9987         RLOGE("%s: invalid response - %d", __FUNCTION__, static_cast<int>(e));
9988         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9989     } else {
9990         convertRilKeepaliveStatusToHal(static_cast<RIL_KeepaliveStatus*>(response), ks);
9991     }
9992 
9993     Return<void> retStatus =
9994             radioService[slotId]->mRadioResponseV1_1->startKeepaliveResponse(responseInfo, ks);
9995     radioService[slotId]->checkReturnStatus(retStatus);
9996     return 0;
9997 }
9998 
stopKeepaliveResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9999 int radio_1_6::stopKeepaliveResponse(int slotId, int responseType, int serial, RIL_Errno e,
10000                                     void *response, size_t responseLen) {
10001 #if VDBG
10002     RLOGD("%s(): %d", __FUNCTION__, serial);
10003 #endif
10004     RadioResponseInfo responseInfo = {};
10005     populateResponseInfo(responseInfo, serial, responseType, e);
10006 
10007     // If we don't have a radio service, there's nothing we can do
10008     if (radioService[slotId]->mRadioResponseV1_1 == NULL) {
10009         RLOGE("%s: radioService[%d]->mRadioResponseV1_1 == NULL", __FUNCTION__, slotId);
10010         return 0;
10011     }
10012 
10013     Return<void> retStatus =
10014             radioService[slotId]->mRadioResponseV1_1->stopKeepaliveResponse(responseInfo);
10015     radioService[slotId]->checkReturnStatus(retStatus);
10016     return 0;
10017 }
10018 
getModemStackStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10019 int radio_1_6::getModemStackStatusResponse(int slotId, int responseType, int serial, RIL_Errno e,
10020                                     void *response, size_t responseLen) {
10021 #if VDBG
10022     RLOGD("%s(): %d", __FUNCTION__, serial);
10023 #endif
10024     RadioResponseInfo responseInfo = {};
10025     populateResponseInfo(responseInfo, serial, responseType, e);
10026 
10027     // If we don't have a radio service, there's nothing we can do
10028     if (radioService[slotId]->mRadioResponseV1_3 == NULL) {
10029         RLOGE("%s: radioService[%d]->mRadioResponseV1_3 == NULL", __FUNCTION__, slotId);
10030         return 0;
10031     }
10032 
10033     Return<void> retStatus =
10034             radioService[slotId]->mRadioResponseV1_3->getModemStackStatusResponse(
10035             responseInfo, true);
10036     radioService[slotId]->checkReturnStatus(retStatus);
10037     return 0;
10038 }
10039 
enableModemResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10040 int radio_1_6::enableModemResponse(int slotId, int responseType, int serial, RIL_Errno e,
10041                                     void *response, size_t responseLen) {
10042 #if VDBG
10043     RLOGD("%s(): %d", __FUNCTION__, serial);
10044 #endif
10045     RadioResponseInfo responseInfo = {};
10046     populateResponseInfo(responseInfo, serial, responseType, e);
10047 
10048     // If we don't have a radio service, there's nothing we can do
10049     if (radioService[slotId]->mRadioResponseV1_3 == NULL) {
10050         RLOGE("%s: radioService[%d]->mRadioResponseV1_3 == NULL", __FUNCTION__, slotId);
10051         return 0;
10052     }
10053 
10054     Return<void> retStatus =
10055             radioService[slotId]->mRadioResponseV1_3->enableModemResponse(responseInfo);
10056     radioService[slotId]->checkReturnStatus(retStatus);
10057     return 0;
10058 }
10059 
sendRequestRawResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10060 int radio_1_6::sendRequestRawResponse(int slotId,
10061                                   int responseType, int serial, RIL_Errno e,
10062                                   void *response, size_t responseLen) {
10063 #if VDBG
10064    RLOGD("sendRequestRawResponse: serial %d", serial);
10065 #endif
10066 
10067     if (!kOemHookEnabled) return 0;
10068 
10069     if (oemHookService[slotId]->mOemHookResponse != NULL) {
10070         RadioResponseInfo responseInfo = {};
10071         populateResponseInfo(responseInfo, serial, responseType, e);
10072         hidl_vec<uint8_t> data;
10073 
10074         if (response == NULL) {
10075             RLOGE("sendRequestRawResponse: Invalid response");
10076             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
10077         } else {
10078             data.setToExternal((uint8_t *) response, responseLen);
10079         }
10080         Return<void> retStatus = oemHookService[slotId]->mOemHookResponse->
10081                 sendRequestRawResponse(responseInfo, data);
10082         checkReturnStatus(slotId, retStatus, false);
10083     } else {
10084         RLOGE("sendRequestRawResponse: oemHookService[%d]->mOemHookResponse == NULL",
10085                 slotId);
10086     }
10087 
10088     return 0;
10089 }
10090 
sendRequestStringsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10091 int radio_1_6::sendRequestStringsResponse(int slotId,
10092                                       int responseType, int serial, RIL_Errno e,
10093                                       void *response, size_t responseLen) {
10094 #if VDBG
10095     RLOGD("sendRequestStringsResponse: serial %d", serial);
10096 #endif
10097 
10098     if (!kOemHookEnabled) return 0;
10099 
10100     if (oemHookService[slotId]->mOemHookResponse != NULL) {
10101         RadioResponseInfo responseInfo = {};
10102         populateResponseInfo(responseInfo, serial, responseType, e);
10103         hidl_vec<hidl_string> data;
10104 
10105         if ((response == NULL && responseLen != 0) || responseLen % sizeof(char *) != 0) {
10106             RLOGE("sendRequestStringsResponse Invalid response: NULL");
10107             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
10108         } else {
10109             char **resp = (char **) response;
10110             int numStrings = responseLen / sizeof(char *);
10111             data.resize(numStrings);
10112             for (int i = 0; i < numStrings; i++) {
10113                 data[i] = convertCharPtrToHidlString(resp[i]);
10114             }
10115         }
10116         Return<void> retStatus
10117                 = oemHookService[slotId]->mOemHookResponse->sendRequestStringsResponse(
10118                 responseInfo, data);
10119         checkReturnStatus(slotId, retStatus, false);
10120     } else {
10121         RLOGE("sendRequestStringsResponse: oemHookService[%d]->mOemHookResponse == "
10122                 "NULL", slotId);
10123     }
10124 
10125     return 0;
10126 }
10127 
setSystemSelectionChannelsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10128 int radio_1_6::setSystemSelectionChannelsResponse(int slotId, int responseType, int serial,
10129                                         RIL_Errno e, void* response, size_t responseLen) {
10130 #if VDBG
10131     RLOGD("setSystemSelectionChannelsResponse: serial %d", serial);
10132 #endif
10133     RadioResponseInfo responseInfo = {};
10134     populateResponseInfo(responseInfo, serial, responseType, e);
10135 
10136     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10137         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
10138                 ->setSystemSelectionChannelsResponse_1_5(responseInfo);
10139         radioService[slotId]->checkReturnStatus(retStatus);
10140     } else if (radioService[slotId]->mRadioResponseV1_3 != NULL) {
10141         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_3
10142                 ->setSystemSelectionChannelsResponse(responseInfo);
10143         radioService[slotId]->checkReturnStatus(retStatus);
10144     } else {
10145         RLOGE("setSystemSelectionChannelsResponse: radioService[%d]->mRadioResponse == NULL",
10146                 slotId);
10147     }
10148 
10149     return 0;
10150 }
10151 
getSystemSelectionChannelsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10152 int radio_1_6::getSystemSelectionChannelsResponse(int slotId, int responseType, int serial,
10153                                         RIL_Errno e, void* response, size_t responseLen) {
10154 #if VDBG
10155     RLOGD("getSystemSelectionChannelsResponse: serial %d", serial);
10156 #endif
10157     V1_6::RadioResponseInfo responseInfo = {};
10158     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10159 
10160     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
10161       hidl_vec<::android::hardware::radio::V1_5::RadioAccessSpecifier> ret;
10162       Return<void> retStatus =
10163           radioService[slotId]
10164               ->mRadioResponseV1_6->getSystemSelectionChannelsResponse(
10165                   responseInfo, ret);
10166       radioService[slotId]->checkReturnStatus(retStatus);
10167     } else {
10168         RLOGE("getSystemSelectionChannelsResponse: radioService[%d]->mRadioResponse == NULL",
10169                 slotId);
10170     }
10171 
10172     return 0;
10173 }
10174 
setSignalStrengthReportingCriteriaResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10175 int radio_1_6::setSignalStrengthReportingCriteriaResponse(int slotId, int responseType, int serial,
10176                                         RIL_Errno e, void* response, size_t responseLen) {
10177 #if VDBG
10178     RLOGD("setSignalStrengthReportingCriteriaResponse: serial %d", serial);
10179 #endif
10180     RadioResponseInfo responseInfo = {};
10181     populateResponseInfo(responseInfo, serial, responseType, e);
10182 
10183     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10184         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
10185                 ->setSignalStrengthReportingCriteriaResponse_1_5(responseInfo);
10186         radioService[slotId]->checkReturnStatus(retStatus);
10187     } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
10188         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2
10189                 ->setSignalStrengthReportingCriteriaResponse(responseInfo);
10190         radioService[slotId]->checkReturnStatus(retStatus);
10191     } else {
10192         RLOGE("setSignalStrengthReportingCriteriaResponse: radioService[%d]->mRadioResponse "
10193                 "== NULL", slotId);
10194     }
10195 
10196     return 0;
10197 }
10198 
setLinkCapacityReportingCriteriaResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10199 int radio_1_6::setLinkCapacityReportingCriteriaResponse(int slotId, int responseType, int serial,
10200                                         RIL_Errno e, void* response, size_t responseLen) {
10201 #if VDBG
10202     RLOGD("setLinkCapacityReportingCriteriaResponse: serial %d", serial);
10203 #endif
10204     RadioResponseInfo responseInfo = {};
10205     populateResponseInfo(responseInfo, serial, responseType, e);
10206 
10207     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10208         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
10209                 ->setLinkCapacityReportingCriteriaResponse_1_5(responseInfo);
10210         radioService[slotId]->checkReturnStatus(retStatus);
10211     } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
10212         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2
10213                 ->setLinkCapacityReportingCriteriaResponse(responseInfo);
10214         radioService[slotId]->checkReturnStatus(retStatus);
10215     } else {
10216         RLOGE("setLinkCapacityReportingCriteriaResponse: radioService[%d]->mRadioResponse "
10217                 "== NULL", slotId);
10218     }
10219 
10220     return 0;
10221 }
10222 
enableUiccApplicationsResponse(int slotId,int responseType,int serial,RIL_Errno e,void *,size_t responseLen)10223 int radio_1_6::enableUiccApplicationsResponse(int slotId, int responseType, int serial,
10224                                     RIL_Errno e, void* /* response */, size_t responseLen) {
10225 #if VDBG
10226     RLOGD("%s(): %d", __FUNCTION__, serial);
10227 #endif
10228     RadioResponseInfo responseInfo = {};
10229     populateResponseInfo(responseInfo, serial, responseType, e);
10230 
10231     // If we don't have a radio service, there's nothing we can do
10232     if (radioService[slotId]->mRadioResponseV1_5 == NULL) {
10233         RLOGE("%s: radioService[%d]->mRadioResponseV1_5 == NULL", __FUNCTION__, slotId);
10234         return 0;
10235     }
10236 
10237     Return<void> retStatus =
10238             radioService[slotId]->mRadioResponseV1_5->enableUiccApplicationsResponse(
10239             responseInfo);
10240     radioService[slotId]->checkReturnStatus(retStatus);
10241     return 0;
10242 }
10243 
areUiccApplicationsEnabledResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10244 int radio_1_6::areUiccApplicationsEnabledResponse(int slotId, int responseType, int serial,
10245                                         RIL_Errno e, void* response, size_t responseLen) {
10246 #if VDBG
10247     RLOGD("%s(): %d", __FUNCTION__, serial);
10248 #endif
10249     RadioResponseInfo responseInfo = {};
10250     populateResponseInfo(responseInfo, serial, responseType, e);
10251 
10252     // If we don't have a radio service, there's nothing we can do
10253     if (radioService[slotId]->mRadioResponseV1_5 == NULL) {
10254         RLOGE("%s: radioService[%d]->mRadioResponseV1_5 == NULL", __FUNCTION__, slotId);
10255         return 0;
10256     }
10257 
10258     bool enable = false;
10259     if (response == NULL || responseLen != sizeof(bool)) {
10260         RLOGE("isSimDetachedFromNetwork Invalid response.");
10261     } else {
10262         enable = (*((bool *) response));
10263     }
10264 
10265     Return<void> retStatus =
10266             radioService[slotId]->mRadioResponseV1_5->areUiccApplicationsEnabledResponse(
10267             responseInfo, enable);
10268     radioService[slotId]->checkReturnStatus(retStatus);
10269     return 0;
10270 }
10271 
getBarringInfoResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responselen)10272 int radio_1_6::getBarringInfoResponse(int slotId,
10273                               int responseType, int serial, RIL_Errno e,
10274                               void *response, size_t responselen) {
10275 #if VDBG
10276     RLOGD("getBarringInfoResponse: serial %d", serial);
10277 #endif
10278 
10279     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10280         RadioResponseInfo responseInfo = {};
10281         populateResponseInfo(responseInfo, serial, responseType, e);
10282         ::android::hardware::radio::V1_5::CellIdentity cellIdentity;
10283         hidl_vec<::android::hardware::radio::V1_5::BarringInfo> barringInfos = {};
10284 
10285         if (response == NULL) { /* data for vts */
10286             V1_5::BarringInfo barringInfo = {};
10287             barringInfo.serviceType = V1_5::BarringInfo::ServiceType::CS_SERVICE;
10288             barringInfo.barringType = V1_5::BarringInfo::BarringType::NONE;
10289 
10290             V1_5::CellIdentityLte cellIdentityLte = {};
10291             cellIdentity.lte(cellIdentityLte);
10292             barringInfos.resize(1);
10293             barringInfos[0] = barringInfo;
10294 
10295         Return<void> retStatus
10296                 = radioService[slotId]->mRadioResponseV1_5->
10297                         getBarringInfoResponse(responseInfo, cellIdentity, barringInfos);
10298         radioService[slotId]->checkReturnStatus(retStatus);
10299       } else {
10300           RLOGE("getBarringInfoResponse: radioService[%d]->mRadioResponse == NULL",
10301                   slotId);
10302       }
10303     }
10304     return 0;
10305 }
10306 
sendCdmaSmsExpectMoreResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10307 int radio_1_6::sendCdmaSmsExpectMoreResponse(int slotId, int responseType, int serial, RIL_Errno e,
10308                                              void *response, size_t responseLen) {
10309 #if VDBG
10310     RLOGD("sendCdmaSmsExpectMoreResponse: serial %d", serial);
10311 #endif
10312 
10313     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
10314         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
10315         SendSmsResult result = makeSendSmsResult_1_6(responseInfo_1_6, serial, responseType, e,
10316                 response, responseLen);
10317 
10318         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
10319                 ->sendCdmaSmsExpectMoreResponse_1_6(responseInfo_1_6, result);
10320         radioService[slotId]->checkReturnStatus(retStatus);
10321     } else if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10322         RadioResponseInfo responseInfo = {};
10323         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
10324                 responseLen);
10325 
10326         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
10327                 ->sendCdmaSmsExpectMoreResponse(responseInfo, result);
10328         radioService[slotId]->checkReturnStatus(retStatus);
10329     } else {
10330         RLOGE("sendCdmaSmsExpectMoreResponse: radioService[%d]->mRadioResponse == NULL", slotId);
10331     }
10332 
10333     return 0;
10334 }
10335 
supplySimDepersonalizationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10336 int radio_1_6::supplySimDepersonalizationResponse(int slotId, int responseType, int serial,
10337                                                   RIL_Errno e, void *response, size_t responseLen) {
10338 #if VDBG
10339     RLOGD("supplySimDepersonalizationResponse: serial %d", serial);
10340 #endif
10341 
10342     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10343         RadioResponseInfo responseInfo = {};
10344         int persoType = -1, remainingRetries = -1;
10345         int numInts = responseLen / sizeof(int);
10346         if (response == NULL || numInts != 2) {
10347             RLOGE("getClirResponse Invalid response: NULL");
10348             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
10349         } else {
10350             int *pInt = (int *) response;
10351             persoType = pInt[0];
10352             remainingRetries = pInt[1];
10353         }
10354         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
10355                 ->supplySimDepersonalizationResponse(responseInfo, (V1_5::PersoSubstate) persoType,
10356                 remainingRetries);
10357         radioService[slotId]->checkReturnStatus(retStatus);
10358     } else {
10359         RLOGE("supplySimDepersonalizationResponse: radioService[%d]->mRadioResponseV1_5 == "
10360                 "NULL", slotId);
10361     }
10362 
10363     return 0;
10364 }
10365 
setNrDualConnectivityStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void *,size_t responseLen)10366 int radio_1_6::setNrDualConnectivityStateResponse(int slotId, int responseType, int serial,
10367                                     RIL_Errno e, void* /* response */, size_t responseLen) {
10368 #if VDBG
10369     RLOGD("%s(): %d", __FUNCTION__, serial);
10370 #endif
10371     V1_6::RadioResponseInfo responseInfo = {};
10372     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10373 
10374     // If we don't have a radio service, there's nothing we can do
10375     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10376         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10377         return 0;
10378     }
10379 
10380     Return<void> retStatus =
10381             radioService[slotId]->mRadioResponseV1_6->setNrDualConnectivityStateResponse(
10382             responseInfo);
10383     radioService[slotId]->checkReturnStatus(retStatus);
10384     return 0;
10385 }
10386 
isNrDualConnectivityEnabledResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10387 int radio_1_6::isNrDualConnectivityEnabledResponse(int slotId, int responseType, int serial,
10388                                         RIL_Errno e, void* response, size_t responseLen) {
10389 #if VDBG
10390     RLOGD("%s(): %d", __FUNCTION__, serial);
10391 #endif
10392     V1_6::RadioResponseInfo responseInfo = {};
10393     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10394 
10395     // If we don't have a radio service, there's nothing we can do
10396     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10397         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10398         return 0;
10399     }
10400 
10401     bool enable = false;
10402     if (response == NULL || responseLen != sizeof(bool)) {
10403         RLOGE("isNrDualConnectivityEnabledResponseInvalid response.");
10404     } else {
10405         enable = (*((bool *) response));
10406     }
10407 
10408     Return<void> retStatus =
10409             radioService[slotId]->mRadioResponseV1_6->isNrDualConnectivityEnabledResponse(
10410             responseInfo, enable);
10411     radioService[slotId]->checkReturnStatus(retStatus);
10412     return 0;
10413 }
10414 
allocatePduSessionIdResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10415 int radio_1_6::allocatePduSessionIdResponse(int slotId, int responseType, int serial,
10416                                         RIL_Errno e, void* response, size_t responseLen) {
10417 #if VDBG
10418     RLOGD("%s(): %d", __FUNCTION__, serial);
10419 #endif
10420     // If we don't have a radio service, there's nothing we can do
10421     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10422       RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10423       return 0;
10424     }
10425     V1_6::RadioResponseInfo responseInfo = {};
10426     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10427 
10428     Return<void> retStatus =
10429             radioService[slotId]->mRadioResponseV1_6->allocatePduSessionIdResponse(responseInfo, -1);
10430     radioService[slotId]->checkReturnStatus(retStatus);
10431     return 0;
10432 }
10433 
releasePduSessionIdResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10434 int radio_1_6::releasePduSessionIdResponse(int slotId, int responseType, int serial,
10435                                         RIL_Errno e, void* response, size_t responseLen) {
10436 #if VDBG
10437     RLOGD("%s(): %d", __FUNCTION__, serial);
10438 #endif
10439     // If we don't have a radio service, there's nothing we can do
10440     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10441         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10442         return 0;
10443     }
10444 
10445     V1_6::RadioResponseInfo responseInfo = {};
10446     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10447 
10448     Return<void> retStatus =
10449             radioService[slotId]->mRadioResponseV1_6->releasePduSessionIdResponse(responseInfo);
10450     radioService[slotId]->checkReturnStatus(retStatus);
10451     return 0;
10452 }
10453 
startHandoverResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10454 int radio_1_6::startHandoverResponse(int slotId, int responseType, int serial,
10455                                         RIL_Errno e, void* response, size_t responseLen) {
10456     // If we don't have a radio service, there's nothing we can do
10457     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10458         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10459         return 0;
10460     }
10461     V1_6::RadioResponseInfo responseInfo = {};
10462     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10463 
10464     Return<void> retStatus =
10465             radioService[slotId]->mRadioResponseV1_6->startHandoverResponse(responseInfo);
10466 
10467 #if VDBG
10468     RLOGD("%s(): %d", __FUNCTION__, serial);
10469 #endif
10470     return 0;
10471 }
10472 
cancelHandoverResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10473 int radio_1_6::cancelHandoverResponse(int slotId, int responseType, int serial,
10474                                         RIL_Errno e, void* response, size_t responseLen) {
10475     // If we don't have a radio service, there's nothing we can do
10476     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10477         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10478         return 0;
10479     }
10480     V1_6::RadioResponseInfo responseInfo = {};
10481     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10482 
10483     Return<void> retStatus =
10484             radioService[slotId]->mRadioResponseV1_6->cancelHandoverResponse(responseInfo);
10485 
10486 #if VDBG
10487     RLOGD("%s(): %d", __FUNCTION__, serial);
10488 #endif
10489     return 0;
10490 }
10491 
10492 
setDataThrottlingResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responselen)10493 int radio_1_6::setDataThrottlingResponse(int slotId, int responseType,
10494                    int serial, RIL_Errno e, void *response, size_t responselen) {
10495 #if VDBG
10496     RLOGD("setDataThrottlingResponse: serial %d", serial);
10497 #endif
10498 
10499    if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10500        RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10501        return 0;
10502    }
10503 
10504    V1_6::RadioResponseInfo responseInfo = {};
10505    populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10506 
10507 
10508    Return<void> retstatus =
10509         radioService[slotId]->mRadioResponseV1_6->setDataThrottlingResponse(
10510                     responseInfo);
10511    radioService[slotId]->checkReturnStatus(retstatus);
10512    return 0;
10513 }
10514 
getSlicingConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10515 int radio_1_6::getSlicingConfigResponse(int slotId, int responseType, int serial,
10516                                         RIL_Errno e, void* response, size_t responseLen) {
10517 #if VDBG
10518     RLOGD("getSlicingConfigResponse: serial %d", serial);
10519 #endif
10520 
10521     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
10522         V1_6::RadioResponseInfo responseInfo = {};
10523         populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10524 
10525         V1_6::SlicingConfig slicingConfig = {};
10526         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6->
10527                 getSlicingConfigResponse(responseInfo, slicingConfig);
10528         radioService[slotId]->checkReturnStatus(retStatus);
10529     } else {
10530         RLOGE("getSlicingConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId);
10531     }
10532 
10533     return 0;
10534 }
10535 
getSimPhonebookRecordsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10536 int radio_1_6::getSimPhonebookRecordsResponse(int slotId, int responseType, int serial,
10537                              RIL_Errno e, void *response, size_t responseLen) {
10538 #if VDBG
10539     RLOGD("getSimPhonebookRecordsResponse: serial %d", serial);
10540 #endif
10541 
10542     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
10543         V1_6::RadioResponseInfo responseInfo = {};
10544         populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10545 
10546         Return<void> retStatus =
10547                 radioService[slotId]->mRadioResponseV1_6->getSimPhonebookRecordsResponse(
10548                         responseInfo);
10549         radioService[slotId]->checkReturnStatus(retStatus);
10550     } else {
10551         RLOGE("getSimPhonebookRecordsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
10552     }
10553 
10554     return 0;
10555 }
10556 
getSimPhonebookCapacityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10557 int radio_1_6::getSimPhonebookCapacityResponse(int slotId, int responseType, int serial,
10558                              RIL_Errno e, void *response, size_t responseLen) {
10559 #if VDBG
10560     RLOGD("getSimPhonebookCapacityResponse: serial %d", serial);
10561 #endif
10562 
10563     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
10564         V1_6::RadioResponseInfo responseInfo = {};
10565         populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10566 
10567         V1_6::PhonebookCapacity phonebookCapacity = {};
10568         Return<void> retStatus =
10569                 radioService[slotId]->mRadioResponseV1_6->getSimPhonebookCapacityResponse(
10570                         responseInfo, phonebookCapacity);
10571         radioService[slotId]->checkReturnStatus(retStatus);
10572     } else {
10573         RLOGE("getSimPhonebookCapacityResponse: radioService[%d]->mRadioResponse == NULL", slotId);
10574     }
10575 
10576     return 0;
10577 }
10578 
updateSimPhonebookRecordsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10579 int radio_1_6::updateSimPhonebookRecordsResponse(int slotId, int responseType, int serial,
10580                              RIL_Errno e, void *response, size_t responseLen) {
10581 #if VDBG
10582     RLOGD("updateSimPhonebookRecordsResponse: serial %d", serial);
10583 #endif
10584 
10585     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
10586         V1_6::RadioResponseInfo responseInfo = {};
10587         populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10588 
10589         int32_t updatedRecordIndex = 0;
10590         Return<void> retStatus =
10591                 radioService[slotId]->mRadioResponseV1_6->updateSimPhonebookRecordsResponse(
10592                         responseInfo, updatedRecordIndex);
10593         radioService[slotId]->checkReturnStatus(retStatus);
10594     } else {
10595         RLOGE("updateSimPhonebookRecordsResponse: radioService[%d]->mRadioResponse == NULL",
10596               slotId);
10597     }
10598 
10599     return 0;
10600 }
10601 
10602 /***************************************************************************************************
10603  * INDICATION FUNCTIONS
10604  * The below function handle unsolicited messages coming from the Radio
10605  * (messages for which there is no pending request)
10606  **************************************************************************************************/
10607 
convertIntToRadioIndicationType(int indicationType)10608 RadioIndicationType convertIntToRadioIndicationType(int indicationType) {
10609     return indicationType == RESPONSE_UNSOLICITED ? (RadioIndicationType::UNSOLICITED) :
10610             (RadioIndicationType::UNSOLICITED_ACK_EXP);
10611 }
10612 
radioStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10613 int radio_1_6::radioStateChangedInd(int slotId,
10614                                  int indicationType, int token, RIL_Errno e, void *response,
10615                                  size_t responseLen) {
10616     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10617         RadioState radioState =
10618                 (RadioState) CALL_ONSTATEREQUEST(slotId);
10619         RLOGD("radioStateChangedInd: radioState %d", radioState);
10620         Return<void> retStatus = radioService[slotId]->mRadioIndication->radioStateChanged(
10621                 convertIntToRadioIndicationType(indicationType), radioState);
10622         radioService[slotId]->checkReturnStatus(retStatus);
10623     } else {
10624         RLOGE("radioStateChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
10625     }
10626 
10627     return 0;
10628 }
10629 
callStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10630 int radio_1_6::callStateChangedInd(int slotId,
10631                                int indicationType, int token, RIL_Errno e, void *response,
10632                                size_t responseLen) {
10633     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10634 #if VDBG
10635         RLOGD("callStateChangedInd");
10636 #endif
10637         Return<void> retStatus = radioService[slotId]->mRadioIndication->callStateChanged(
10638                 convertIntToRadioIndicationType(indicationType));
10639         radioService[slotId]->checkReturnStatus(retStatus);
10640     } else {
10641         RLOGE("callStateChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
10642     }
10643 
10644     return 0;
10645 }
10646 
networkStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10647 int radio_1_6::networkStateChangedInd(int slotId,
10648                                   int indicationType, int token, RIL_Errno e, void *response,
10649                                   size_t responseLen) {
10650     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10651 #if VDBG
10652         RLOGD("networkStateChangedInd");
10653 #endif
10654         Return<void> retStatus = radioService[slotId]->mRadioIndication->networkStateChanged(
10655                 convertIntToRadioIndicationType(indicationType));
10656         radioService[slotId]->checkReturnStatus(retStatus);
10657     } else {
10658         RLOGE("networkStateChangedInd: radioService[%d]->mRadioIndication == NULL",
10659                 slotId);
10660     }
10661 
10662     return 0;
10663 }
10664 
cellularIdentifierDisclosedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responselen)10665 int radio_aidl::cellularIdentifierDisclosedInd(int slotId, int indicationType, int token,
10666                                                RIL_Errno e, void* response, size_t responselen) {
10667     if (radioService[slotId] == NULL || radioService[slotId]->mCallbackManager == NULL) {
10668         RLOGE("cellularIdentifierDisclosedInd: radioService[%d]->mCallbackManager == NULL", slotId);
10669         return 0;
10670     }
10671     auto networkCb = radioService[slotId]->mCallbackManager->indication().networkCb();
10672 
10673     if (!networkCb) {
10674         RLOGE("networkCB is null");
10675         return 0;
10676     }
10677 
10678     RIL_CellularIdentifierDisclosure* rawDisclosure =
10679             static_cast<RIL_CellularIdentifierDisclosure*>(response);
10680 
10681     aidl_radio::network::CellularIdentifierDisclosure disclosure;
10682     disclosure.identifier =
10683             static_cast<aidl_radio::network::CellularIdentifier>(rawDisclosure->identifierType);
10684     disclosure.protocolMessage =
10685             static_cast<aidl_radio::network::NasProtocolMessage>(rawDisclosure->protocolMessage);
10686     disclosure.plmn = rawDisclosure->plmn;
10687     disclosure.isEmergency = rawDisclosure->isEmergency;
10688 
10689     networkCb->cellularIdentifierDisclosed(aidl_radio::RadioIndicationType(indicationType),
10690                                            disclosure);
10691 
10692     return 0;
10693 }
10694 
securityAlgorithmUpdatedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responselen)10695 int radio_aidl::securityAlgorithmUpdatedInd(int slotId, int indicationType, int token, RIL_Errno e,
10696                                             void* response, size_t responselen) {
10697     if (radioService[slotId] == NULL || radioService[slotId]->mCallbackManager == NULL) {
10698         RLOGE("securityAlgorithmUpdatedInd: radioService[%d]->mCallbackManager == NULL", slotId);
10699         return 0;
10700     }
10701     auto networkCb = radioService[slotId]->mCallbackManager->indication().networkCb();
10702 
10703     if (!networkCb) {
10704         RLOGE("networkCB is null");
10705         return 0;
10706     }
10707 
10708     RIL_SecurityAlgorithmUpdate* rawUpdate = static_cast<RIL_SecurityAlgorithmUpdate*>(response);
10709 
10710     aidl_radio::network::SecurityAlgorithmUpdate update;
10711     update.connectionEvent =
10712             static_cast<aidl_radio::network::ConnectionEvent>(rawUpdate->connectionEvent);
10713     update.encryption = static_cast<aidl_radio::network::SecurityAlgorithm>(rawUpdate->encryption);
10714     update.integrity = static_cast<aidl_radio::network::SecurityAlgorithm>(rawUpdate->integrity);
10715     update.isUnprotectedEmergency = rawUpdate->isUnprotectedEmergency;
10716 
10717     networkCb->securityAlgorithmsUpdated(aidl_radio::RadioIndicationType(indicationType), update);
10718 
10719     return 0;
10720 }
10721 
hexCharToInt(uint8_t c)10722 extern "C" uint8_t hexCharToInt(uint8_t c) {
10723     if (c >= '0' && c <= '9') return (c - '0');
10724     if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
10725     if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
10726 
10727     return INVALID_HEX_CHAR;
10728 }
10729 
convertHexStringToBytes(void * response,size_t responseLen)10730 extern "C" uint8_t * convertHexStringToBytes(void *response, size_t responseLen) {
10731     if (responseLen % 2 != 0) {
10732         return NULL;
10733     }
10734 
10735     uint8_t *bytes = (uint8_t *)calloc(responseLen/2, sizeof(uint8_t));
10736     if (bytes == NULL) {
10737         RLOGE("convertHexStringToBytes: cannot allocate memory for bytes string");
10738         return NULL;
10739     }
10740     uint8_t *hexString = (uint8_t *)response;
10741 
10742     for (size_t i = 0; i < responseLen; i += 2) {
10743         uint8_t hexChar1 = hexCharToInt(hexString[i]);
10744         uint8_t hexChar2 = hexCharToInt(hexString[i + 1]);
10745 
10746         if (hexChar1 == INVALID_HEX_CHAR || hexChar2 == INVALID_HEX_CHAR) {
10747             RLOGE("convertHexStringToBytes: invalid hex char %d %d",
10748                     hexString[i], hexString[i + 1]);
10749             free(bytes);
10750             return NULL;
10751         }
10752         bytes[i/2] = ((hexChar1 << 4) | hexChar2);
10753     }
10754 
10755     return bytes;
10756 }
10757 
newSmsInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10758 int radio_1_6::newSmsInd(int slotId, int indicationType,
10759                      int token, RIL_Errno e, void *response, size_t responseLen) {
10760     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10761         if (response == NULL || responseLen == 0) {
10762             RLOGE("newSmsInd: invalid response");
10763             return 0;
10764         }
10765 
10766         uint8_t *bytes = convertHexStringToBytes(response, responseLen);
10767         if (bytes == NULL) {
10768             RLOGE("newSmsInd: convertHexStringToBytes failed");
10769             return 0;
10770         }
10771 
10772         hidl_vec<uint8_t> pdu;
10773         pdu.setToExternal(bytes, responseLen/2);
10774 #if VDBG
10775         RLOGD("newSmsInd");
10776 #endif
10777         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSms(
10778                 convertIntToRadioIndicationType(indicationType), pdu);
10779         radioService[slotId]->checkReturnStatus(retStatus);
10780         free(bytes);
10781     } else {
10782         RLOGE("newSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
10783     }
10784 
10785     return 0;
10786 }
10787 
newSmsStatusReportInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10788 int radio_1_6::newSmsStatusReportInd(int slotId,
10789                                  int indicationType, int token, RIL_Errno e, void *response,
10790                                  size_t responseLen) {
10791     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10792         if (response == NULL || responseLen == 0) {
10793             RLOGE("newSmsStatusReportInd: invalid response");
10794             return 0;
10795         }
10796 
10797         uint8_t *bytes = convertHexStringToBytes(response, responseLen);
10798         if (bytes == NULL) {
10799             RLOGE("newSmsStatusReportInd: convertHexStringToBytes failed");
10800             return 0;
10801         }
10802 
10803         hidl_vec<uint8_t> pdu;
10804         pdu.setToExternal(bytes, responseLen/2);
10805 #if VDBG
10806         RLOGD("newSmsStatusReportInd");
10807 #endif
10808         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSmsStatusReport(
10809                 convertIntToRadioIndicationType(indicationType), pdu);
10810         radioService[slotId]->checkReturnStatus(retStatus);
10811         free(bytes);
10812     } else {
10813         RLOGE("newSmsStatusReportInd: radioService[%d]->mRadioIndication == NULL", slotId);
10814     }
10815 
10816     return 0;
10817 }
10818 
newSmsOnSimInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10819 int radio_1_6::newSmsOnSimInd(int slotId, int indicationType,
10820                           int token, RIL_Errno e, void *response, size_t responseLen) {
10821     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10822         if (response == NULL || responseLen != sizeof(int)) {
10823             RLOGE("newSmsOnSimInd: invalid response");
10824             return 0;
10825         }
10826         int32_t recordNumber = ((int32_t *) response)[0];
10827 #if VDBG
10828         RLOGD("newSmsOnSimInd: slotIndex %d", recordNumber);
10829 #endif
10830         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSmsOnSim(
10831                 convertIntToRadioIndicationType(indicationType), recordNumber);
10832         radioService[slotId]->checkReturnStatus(retStatus);
10833     } else {
10834         RLOGE("newSmsOnSimInd: radioService[%d]->mRadioIndication == NULL", slotId);
10835     }
10836 
10837     return 0;
10838 }
10839 
onUssdInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10840 int radio_1_6::onUssdInd(int slotId, int indicationType,
10841                      int token, RIL_Errno e, void *response, size_t responseLen) {
10842     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10843         if (response == NULL || responseLen != 2 * sizeof(char *)) {
10844             RLOGE("onUssdInd: invalid response");
10845             return 0;
10846         }
10847         char **strings = (char **) response;
10848         char *mode = strings[0];
10849         hidl_string msg = convertCharPtrToHidlString(strings[1]);
10850         UssdModeType modeType = (UssdModeType) atoi(mode);
10851 #if VDBG
10852         RLOGD("onUssdInd: mode %s", mode);
10853 #endif
10854         Return<void> retStatus = radioService[slotId]->mRadioIndication->onUssd(
10855                 convertIntToRadioIndicationType(indicationType), modeType, msg);
10856         radioService[slotId]->checkReturnStatus(retStatus);
10857     } else {
10858         RLOGE("onUssdInd: radioService[%d]->mRadioIndication == NULL", slotId);
10859     }
10860 
10861     return 0;
10862 }
10863 
nitzTimeReceivedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10864 int radio_1_6::nitzTimeReceivedInd(int slotId,
10865                                int indicationType, int token, RIL_Errno e, void *response,
10866                                size_t responseLen) {
10867     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10868         if (response == NULL || responseLen == 0) {
10869             RLOGE("nitzTimeReceivedInd: invalid response");
10870             return 0;
10871         }
10872         hidl_string nitzTime = convertCharPtrToHidlString((char *) response);
10873 #if VDBG
10874         RLOGD("nitzTimeReceivedInd: nitzTime %s receivedTime %" PRId64, nitzTime.c_str(),
10875                 nitzTimeReceived[slotId]);
10876 #endif
10877         Return<void> retStatus = radioService[slotId]->mRadioIndication->nitzTimeReceived(
10878                 convertIntToRadioIndicationType(indicationType), nitzTime,
10879                 nitzTimeReceived[slotId]);
10880         radioService[slotId]->checkReturnStatus(retStatus);
10881     } else {
10882         RLOGE("nitzTimeReceivedInd: radioService[%d]->mRadioIndication == NULL", slotId);
10883         return -1;
10884     }
10885 
10886     return 0;
10887 }
10888 
convertRilSignalStrengthToHal(void * response,size_t responseLen,SignalStrength & signalStrength)10889 void convertRilSignalStrengthToHal(void *response, size_t responseLen,
10890         SignalStrength& signalStrength) {
10891     RIL_SignalStrength_v12 *rilSignalStrength = (RIL_SignalStrength_v12 *) response;
10892 
10893     // Fixup LTE for backwards compatibility
10894     // signalStrength: -1 -> 99
10895     if (rilSignalStrength->LTE_SignalStrength.signalStrength == -1) {
10896         rilSignalStrength->LTE_SignalStrength.signalStrength = 99;
10897     }
10898     // rsrp: -1 -> INT_MAX all other negative value to positive.
10899     // So remap here
10900     if (rilSignalStrength->LTE_SignalStrength.rsrp == -1) {
10901         rilSignalStrength->LTE_SignalStrength.rsrp = INT_MAX;
10902     } else if (rilSignalStrength->LTE_SignalStrength.rsrp < -1) {
10903         rilSignalStrength->LTE_SignalStrength.rsrp = -rilSignalStrength->LTE_SignalStrength.rsrp;
10904     }
10905     // rsrq: -1 -> INT_MAX
10906     if (rilSignalStrength->LTE_SignalStrength.rsrq == -1) {
10907         rilSignalStrength->LTE_SignalStrength.rsrq = INT_MAX;
10908     }
10909     // Not remapping rssnr is already using INT_MAX
10910     // cqi: -1 -> INT_MAX
10911     if (rilSignalStrength->LTE_SignalStrength.cqi == -1) {
10912         rilSignalStrength->LTE_SignalStrength.cqi = INT_MAX;
10913     }
10914 
10915     signalStrength.gw.signalStrength = rilSignalStrength->GW_SignalStrength.signalStrength;
10916     signalStrength.gw.bitErrorRate = rilSignalStrength->GW_SignalStrength.bitErrorRate;
10917     // RIL_SignalStrength_v10 not support gw.timingAdvance. Set to INT_MAX as
10918     // invalid value.
10919     signalStrength.gw.timingAdvance = INT_MAX;
10920 
10921     signalStrength.cdma.dbm = rilSignalStrength->CDMA_SignalStrength.dbm;
10922     signalStrength.cdma.ecio = rilSignalStrength->CDMA_SignalStrength.ecio;
10923     signalStrength.evdo.dbm = rilSignalStrength->EVDO_SignalStrength.dbm;
10924     signalStrength.evdo.ecio = rilSignalStrength->EVDO_SignalStrength.ecio;
10925     signalStrength.evdo.signalNoiseRatio =
10926             rilSignalStrength->EVDO_SignalStrength.signalNoiseRatio;
10927     signalStrength.lte.signalStrength = rilSignalStrength->LTE_SignalStrength.signalStrength;
10928     signalStrength.lte.rsrp = rilSignalStrength->LTE_SignalStrength.rsrp;
10929     signalStrength.lte.rsrq = rilSignalStrength->LTE_SignalStrength.rsrq;
10930     signalStrength.lte.rssnr = rilSignalStrength->LTE_SignalStrength.rssnr;
10931     signalStrength.lte.cqi = rilSignalStrength->LTE_SignalStrength.cqi;
10932     signalStrength.lte.timingAdvance = rilSignalStrength->LTE_SignalStrength.timingAdvance;
10933     signalStrength.tdScdma.rscp = rilSignalStrength->TD_SCDMA_SignalStrength.rscp;
10934 }
10935 
convertRilSignalStrengthToHal_1_2(void * response,size_t responseLen,V1_2::SignalStrength & signalStrength_1_2)10936 void convertRilSignalStrengthToHal_1_2(void* response, size_t responseLen,
10937                                        V1_2::SignalStrength& signalStrength_1_2) {
10938     SignalStrength signalStrength = {};
10939     convertRilSignalStrengthToHal(response, responseLen, signalStrength);
10940     signalStrength_1_2.gsm = signalStrength.gw;
10941     signalStrength_1_2.cdma = signalStrength.cdma;
10942     signalStrength_1_2.evdo = signalStrength.evdo;
10943     signalStrength_1_2.lte = signalStrength.lte;
10944 
10945     RIL_SignalStrength_v12* rilSignalStrength = (RIL_SignalStrength_v12*)response;
10946     signalStrength_1_2.wcdma.base.signalStrength =
10947             rilSignalStrength->WCDMA_SignalStrength.signalStrength;
10948     signalStrength_1_2.wcdma.base.bitErrorRate =
10949             rilSignalStrength->WCDMA_SignalStrength.bitErrorRate;
10950     signalStrength_1_2.wcdma.rscp = INT_MAX;
10951     signalStrength_1_2.wcdma.ecno = INT_MAX;
10952 
10953     signalStrength_1_2.tdScdma.rscp = INT_MAX;
10954 }
10955 
convertRilSignalStrengthToHal_1_4(void * response,size_t responseLen,V1_4::SignalStrength & signalStrength_1_4)10956 void convertRilSignalStrengthToHal_1_4(void *response, size_t responseLen,
10957         V1_4::SignalStrength& signalStrength_1_4) {
10958     SignalStrength signalStrength = {};
10959     convertRilSignalStrengthToHal(response, responseLen, signalStrength);
10960     signalStrength_1_4.gsm = signalStrength.gw;
10961     signalStrength_1_4.cdma = signalStrength.cdma;
10962     signalStrength_1_4.evdo = signalStrength.evdo;
10963     signalStrength_1_4.lte = signalStrength.lte;
10964 
10965     RIL_SignalStrength_v12 *rilSignalStrength = (RIL_SignalStrength_v12 *) response;
10966     signalStrength_1_4.wcdma.base.signalStrength =
10967         rilSignalStrength->WCDMA_SignalStrength.signalStrength;
10968     signalStrength_1_4.wcdma.base.bitErrorRate =
10969         rilSignalStrength->WCDMA_SignalStrength.bitErrorRate;
10970     signalStrength_1_4.wcdma.rscp = INT_MAX;
10971     signalStrength_1_4.wcdma.ecno = INT_MAX;
10972 
10973     signalStrength_1_4.tdscdma.signalStrength = INT_MAX;
10974     signalStrength_1_4.tdscdma.bitErrorRate = INT_MAX;
10975     signalStrength_1_4.tdscdma.rscp = INT_MAX;
10976 
10977     signalStrength_1_4.nr.ssRsrp = rilSignalStrength->NR_SignalStrength.ssRsrp;
10978     signalStrength_1_4.nr.ssRsrq = rilSignalStrength->NR_SignalStrength.ssRsrq;
10979     signalStrength_1_4.nr.ssSinr = rilSignalStrength->NR_SignalStrength.ssSinr;
10980     signalStrength_1_4.nr.csiRsrp = rilSignalStrength->NR_SignalStrength.csiRsrp;
10981     signalStrength_1_4.nr.csiRsrq = rilSignalStrength->NR_SignalStrength.csiRsrq;
10982     signalStrength_1_4.nr.csiSinr = rilSignalStrength->NR_SignalStrength.ssSinr;
10983 }
10984 
convertRilSignalStrengthToHal_1_6(void * response,size_t responseLen,V1_6::SignalStrength & signalStrength_1_6)10985 void convertRilSignalStrengthToHal_1_6(void* response, size_t responseLen,
10986                                        V1_6::SignalStrength& signalStrength_1_6) {
10987     SignalStrength signalStrength = {};
10988     convertRilSignalStrengthToHal(response, responseLen, signalStrength);
10989     signalStrength_1_6.gsm = signalStrength.gw;
10990     signalStrength_1_6.cdma = signalStrength.cdma;
10991     signalStrength_1_6.evdo = signalStrength.evdo;
10992     signalStrength_1_6.lte.base = signalStrength.lte;
10993 
10994     RIL_SignalStrength_v12* rilSignalStrength = (RIL_SignalStrength_v12*)response;
10995     signalStrength_1_6.wcdma.base.signalStrength =
10996             rilSignalStrength->WCDMA_SignalStrength.signalStrength;
10997     signalStrength_1_6.wcdma.base.bitErrorRate =
10998             rilSignalStrength->WCDMA_SignalStrength.bitErrorRate;
10999     signalStrength_1_6.wcdma.rscp = INT_MAX;
11000     signalStrength_1_6.wcdma.ecno = INT_MAX;
11001 
11002     signalStrength_1_6.tdscdma.signalStrength = INT_MAX;
11003     signalStrength_1_6.tdscdma.bitErrorRate = INT_MAX;
11004     signalStrength_1_6.tdscdma.rscp = INT_MAX;
11005 
11006     signalStrength_1_6.nr.base.ssRsrp = rilSignalStrength->NR_SignalStrength.ssRsrp;
11007     signalStrength_1_6.nr.base.ssRsrq = rilSignalStrength->NR_SignalStrength.ssRsrq;
11008     signalStrength_1_6.nr.base.ssSinr = rilSignalStrength->NR_SignalStrength.ssSinr;
11009     signalStrength_1_6.nr.base.csiRsrp = rilSignalStrength->NR_SignalStrength.csiRsrp;
11010     signalStrength_1_6.nr.base.csiRsrq = rilSignalStrength->NR_SignalStrength.csiRsrq;
11011     signalStrength_1_6.nr.base.csiSinr = rilSignalStrength->NR_SignalStrength.ssSinr;
11012 }
11013 
currentSignalStrengthInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11014 int radio_1_6::currentSignalStrengthInd(int slotId, int indicationType, int token, RIL_Errno e,
11015                                         void* response, size_t responseLen) {
11016     if (radioService[slotId] != NULL && (radioService[slotId]->mRadioIndication != NULL ||
11017                                          radioService[slotId]->mRadioIndicationV1_2 != NULL ||
11018                                          radioService[slotId]->mRadioIndicationV1_4 != NULL ||
11019                                          radioService[slotId]->mRadioIndicationV1_6 != NULL)) {
11020         if (response == NULL || responseLen != sizeof(RIL_SignalStrength_v12)) {
11021             RLOGE("currentSignalStrengthInd: invalid response");
11022             return 0;
11023         }
11024 
11025 #if VDBG
11026         RLOGD("currentSignalStrengthInd");
11027 #endif
11028         Return<void> retStatus;
11029         if (radioService[slotId]->mRadioIndicationV1_6 != NULL) {
11030             V1_6::SignalStrength signalStrength_1_6 = {};
11031             convertRilSignalStrengthToHal_1_6(response, responseLen, signalStrength_1_6);
11032             retStatus = radioService[slotId]->mRadioIndicationV1_6->currentSignalStrength_1_6(
11033                     convertIntToRadioIndicationType(indicationType), signalStrength_1_6);
11034         } else if (radioService[slotId]->mRadioIndicationV1_4 != NULL) {
11035             V1_4::SignalStrength signalStrength_1_4 = {};
11036             convertRilSignalStrengthToHal_1_4(response, responseLen, signalStrength_1_4);
11037             retStatus = radioService[slotId]->mRadioIndicationV1_4->currentSignalStrength_1_4(
11038                     convertIntToRadioIndicationType(indicationType), signalStrength_1_4);
11039         } else if (radioService[slotId]->mRadioIndicationV1_2 != NULL) {
11040             V1_2::SignalStrength signalStrength_1_2 = {};
11041             convertRilSignalStrengthToHal_1_2(response, responseLen, signalStrength_1_2);
11042             retStatus = radioService[slotId]->mRadioIndicationV1_2->currentSignalStrength_1_2(
11043                     convertIntToRadioIndicationType(indicationType), signalStrength_1_2);
11044         } else {
11045             SignalStrength signalStrength = {};
11046             convertRilSignalStrengthToHal(response, responseLen, signalStrength);
11047             retStatus = radioService[slotId]->mRadioIndication->currentSignalStrength(
11048                     convertIntToRadioIndicationType(indicationType), signalStrength);
11049         }
11050         radioService[slotId]->checkReturnStatus(retStatus);
11051     } else {
11052         RLOGE("currentSignalStrengthInd: radioService[%d]->mRadioIndication == NULL",
11053                 slotId);
11054     }
11055 
11056     return 0;
11057 }
11058 
convertRilDataCallToHal(RIL_Data_Call_Response_v11 * dcResponse,SetupDataCallResult & dcResult)11059 void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse,
11060         SetupDataCallResult& dcResult) {
11061     dcResult.status = (DataCallFailCause) dcResponse->status;
11062     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
11063     dcResult.cid = dcResponse->cid;
11064     dcResult.active = dcResponse->active;
11065     dcResult.type = convertCharPtrToHidlString(dcResponse->type);
11066     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
11067     dcResult.addresses = convertCharPtrToHidlString(dcResponse->addresses);
11068     dcResult.dnses = convertCharPtrToHidlString(dcResponse->dnses);
11069     dcResult.gateways = convertCharPtrToHidlString(dcResponse->gateways);
11070     dcResult.pcscf = convertCharPtrToHidlString(dcResponse->pcscf);
11071     dcResult.mtu = dcResponse->mtu;
11072 }
11073 
split(hidl_string str)11074 hidl_vec<hidl_string> split(hidl_string str) {
11075     std::vector<hidl_string> ret;
11076     std::stringstream ss(static_cast<std::string>(str));
11077 
11078     std::string tok;
11079 
11080     while(getline(ss, tok, ' ')) {
11081         ret.push_back(hidl_string(tok));
11082     }
11083 
11084     return ret;
11085 }
11086 
convertToPdpProtocolType(hidl_string str)11087 ::android::hardware::radio::V1_4::PdpProtocolType convertToPdpProtocolType(hidl_string str) {
11088     if (strncmp("IP", str.c_str(), 2) == 0) {
11089         return ::android::hardware::radio::V1_4::PdpProtocolType::IP;
11090     } else if (strncmp("IPV6", str.c_str(), 4) == 0) {
11091         return ::android::hardware::radio::V1_4::PdpProtocolType::IPV6;
11092     } else if (strncmp("IPV4V6", str.c_str(), 6) == 0) {
11093         return ::android::hardware::radio::V1_4::PdpProtocolType::IPV4V6;
11094     } else if (strncmp("PPP", str.c_str(), 3) == 0) {
11095         return ::android::hardware::radio::V1_4::PdpProtocolType::PPP;
11096     } else if (strncmp("NON_IP", str.c_str(), 6) == 0) {
11097         return ::android::hardware::radio::V1_4::PdpProtocolType::NON_IP;
11098     } else if (strncmp("UNSTRUCTURED", str.c_str(), 12) == 0) {
11099         return ::android::hardware::radio::V1_4::PdpProtocolType::UNSTRUCTURED;
11100     } else {
11101         return ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
11102     }
11103 }
11104 
convertRilDataCallToHal(RIL_Data_Call_Response_v11 * dcResponse,::android::hardware::radio::V1_4::SetupDataCallResult & dcResult)11105 void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse,
11106         ::android::hardware::radio::V1_4::SetupDataCallResult& dcResult) {
11107     dcResult.cause = (::android::hardware::radio::V1_4::DataCallFailCause) dcResponse->status;
11108     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
11109     dcResult.cid = dcResponse->cid;
11110     dcResult.active = (::android::hardware::radio::V1_4::DataConnActiveStatus)dcResponse->active;
11111     dcResult.type = convertToPdpProtocolType(convertCharPtrToHidlString(dcResponse->type));
11112     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
11113     dcResult.addresses = split(convertCharPtrToHidlString(dcResponse->addresses));
11114     dcResult.dnses = split(convertCharPtrToHidlString(dcResponse->dnses));
11115     dcResult.gateways = split(convertCharPtrToHidlString(dcResponse->gateways));
11116     dcResult.pcscf = split(convertCharPtrToHidlString(dcResponse->pcscf));
11117     dcResult.mtu = dcResponse->mtu;
11118 }
11119 
convertRilDataCallToHal(RIL_Data_Call_Response_v11 * dcResponse,::android::hardware::radio::V1_5::SetupDataCallResult & dcResult)11120 void convertRilDataCallToHal(RIL_Data_Call_Response_v11* dcResponse,
11121                              ::android::hardware::radio::V1_5::SetupDataCallResult& dcResult) {
11122     dcResult.cause = (::android::hardware::radio::V1_4::DataCallFailCause) dcResponse->status;
11123     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
11124     dcResult.cid = dcResponse->cid;
11125     dcResult.active = (::android::hardware::radio::V1_4::DataConnActiveStatus)dcResponse->active;
11126     dcResult.type = convertToPdpProtocolType(convertCharPtrToHidlString(dcResponse->type));
11127     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
11128 
11129     std::vector<::android::hardware::radio::V1_5::LinkAddress> linkAddresses;
11130     if (dcResponse->addresses != NULL) {
11131         std::stringstream ss(static_cast<std::string>(dcResponse->addresses));
11132         std::string tok;
11133         while (getline(ss, tok, ' ')) {
11134             ::android::hardware::radio::V1_5::LinkAddress la;
11135             la.address = hidl_string(tok);
11136             la.properties = 0;
11137             la.deprecationTime = INT64_MAX;  // LinkAddress.java LIFETIME_PERMANENT = Long.MAX_VALUE
11138             la.expirationTime = INT64_MAX;   // --"--
11139             linkAddresses.push_back(la);
11140         }
11141     }
11142 
11143     dcResult.addresses = linkAddresses;
11144     dcResult.dnses = split(convertCharPtrToHidlString(dcResponse->dnses));
11145     dcResult.gateways = split(convertCharPtrToHidlString(dcResponse->gateways));
11146     dcResult.pcscf = split(convertCharPtrToHidlString(dcResponse->pcscf));
11147     dcResult.mtuV4 = dcResponse->mtu;
11148     dcResult.mtuV6 = dcResponse->mtu;
11149 }
11150 
convertRilDataCallToHal(RIL_Data_Call_Response_v11 * dcResponse,::android::hardware::radio::V1_6::SetupDataCallResult & dcResult)11151 void convertRilDataCallToHal(RIL_Data_Call_Response_v11* dcResponse,
11152                              ::android::hardware::radio::V1_6::SetupDataCallResult& dcResult) {
11153     dcResult.cause = (::android::hardware::radio::V1_6::DataCallFailCause) dcResponse->status;
11154     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
11155     dcResult.cid = dcResponse->cid;
11156     dcResult.active = (::android::hardware::radio::V1_4::DataConnActiveStatus)dcResponse->active;
11157     dcResult.type = convertToPdpProtocolType(convertCharPtrToHidlString(dcResponse->type));
11158     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
11159 
11160     std::vector<::android::hardware::radio::V1_5::LinkAddress> linkAddresses;
11161     std::stringstream ss(static_cast<std::string>(dcResponse->addresses));
11162     std::string tok;
11163     while(getline(ss, tok, ' ')) {
11164         ::android::hardware::radio::V1_5::LinkAddress la;
11165         la.address = hidl_string(tok);
11166         la.properties = 0;
11167         la.deprecationTime = INT64_MAX;  // LinkAddress.java LIFETIME_PERMANENT = Long.MAX_VALUE
11168         la.expirationTime = INT64_MAX;  // --"--
11169         linkAddresses.push_back(la);
11170     }
11171 
11172     dcResult.addresses = linkAddresses;
11173     dcResult.dnses = split(convertCharPtrToHidlString(dcResponse->dnses));
11174     dcResult.gateways = split(convertCharPtrToHidlString(dcResponse->gateways));
11175     dcResult.pcscf = split(convertCharPtrToHidlString(dcResponse->pcscf));
11176     dcResult.mtuV4 = dcResponse->mtu;
11177     dcResult.mtuV6 = dcResponse->mtu;
11178 
11179     std::vector<::android::hardware::radio::V1_6::TrafficDescriptor> trafficDescriptors;
11180     ::android::hardware::radio::V1_6::TrafficDescriptor trafficDescriptor;
11181     ::android::hardware::radio::V1_6::OsAppId osAppId;
11182     osAppId.osAppId = osAppIdVec;
11183     trafficDescriptor.osAppId.value(osAppId);
11184     trafficDescriptors.push_back(trafficDescriptor);
11185     dcResult.trafficDescriptors = trafficDescriptors;
11186 }
11187 
convertRilDataCallListToHal(void * response,size_t responseLen,hidl_vec<SetupDataCallResult> & dcResultList)11188 void convertRilDataCallListToHal(void *response, size_t responseLen,
11189         hidl_vec<SetupDataCallResult>& dcResultList) {
11190     int num = responseLen / sizeof(RIL_Data_Call_Response_v11);
11191 
11192     RIL_Data_Call_Response_v11 *dcResponse = (RIL_Data_Call_Response_v11 *) response;
11193     dcResultList.resize(num);
11194     for (int i = 0; i < num; i++) {
11195         convertRilDataCallToHal(&dcResponse[i], dcResultList[i]);
11196     }
11197 }
11198 
convertRilDataCallListToHal_1_4(void * response,size_t responseLen,hidl_vec<V1_4::SetupDataCallResult> & dcResultList)11199 void convertRilDataCallListToHal_1_4(void* response, size_t responseLen,
11200                                      hidl_vec<V1_4::SetupDataCallResult>& dcResultList) {
11201     int num = responseLen / sizeof(RIL_Data_Call_Response_v11);
11202 
11203     RIL_Data_Call_Response_v11* dcResponse = (RIL_Data_Call_Response_v11*)response;
11204     dcResultList.resize(num);
11205     for (int i = 0; i < num; i++) {
11206         convertRilDataCallToHal(&dcResponse[i], dcResultList[i]);
11207     }
11208 }
11209 
convertRilDataCallListToHal_1_5(void * response,size_t responseLen,hidl_vec<V1_5::SetupDataCallResult> & dcResultList)11210 void convertRilDataCallListToHal_1_5(void* response, size_t responseLen,
11211                                      hidl_vec<V1_5::SetupDataCallResult>& dcResultList) {
11212     int num = responseLen / sizeof(RIL_Data_Call_Response_v11);
11213 
11214     RIL_Data_Call_Response_v11* dcResponse = (RIL_Data_Call_Response_v11*)response;
11215     dcResultList.resize(num);
11216     for (int i = 0; i < num; i++) {
11217         convertRilDataCallToHal(&dcResponse[i], dcResultList[i]);
11218     }
11219 }
11220 
convertRilDataCallListToHal_1_6(void * response,size_t responseLen,hidl_vec<V1_6::SetupDataCallResult> & dcResultList)11221 void convertRilDataCallListToHal_1_6(void* response, size_t responseLen,
11222                                      hidl_vec<V1_6::SetupDataCallResult>& dcResultList) {
11223     int num = responseLen / sizeof(RIL_Data_Call_Response_v11);
11224 
11225     RIL_Data_Call_Response_v11* dcResponse = (RIL_Data_Call_Response_v11*)response;
11226     dcResultList.resize(num);
11227     for (int i = 0; i < num; i++) {
11228         convertRilDataCallToHal(&dcResponse[i], dcResultList[i]);
11229     }
11230 }
11231 
dataCallListChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11232 int radio_1_6::dataCallListChangedInd(int slotId,
11233                                   int indicationType, int token, RIL_Errno e, void *response,
11234                                   size_t responseLen) {
11235     if (radioService[slotId] != NULL && (radioService[slotId]->mRadioIndication != NULL ||
11236                                          radioService[slotId]->mRadioIndicationV1_4 != NULL ||
11237                                          radioService[slotId]->mRadioIndicationV1_5 != NULL ||
11238                                          radioService[slotId]->mRadioIndicationV1_6 != NULL)) {
11239         if ((response == NULL && responseLen != 0)
11240                 || responseLen % sizeof(RIL_Data_Call_Response_v11) != 0) {
11241             RLOGE("dataCallListChangedInd: invalid response");
11242             return 0;
11243         }
11244 #if VDBG
11245         RLOGD("dataCallListChangedInd");
11246 #endif
11247         Return<void> retStatus;
11248         if (radioService[slotId]->mRadioIndicationV1_6 != NULL) {
11249             hidl_vec<V1_6::SetupDataCallResult> dcList;
11250             convertRilDataCallListToHal_1_6(response, responseLen, dcList);
11251             retStatus = radioService[slotId]->mRadioIndicationV1_6->dataCallListChanged_1_6(
11252                     convertIntToRadioIndicationType(indicationType), dcList);
11253         } else if (radioService[slotId]->mRadioIndicationV1_5 != NULL) {
11254             hidl_vec<V1_5::SetupDataCallResult> dcList;
11255             convertRilDataCallListToHal_1_5(response, responseLen, dcList);
11256             retStatus = radioService[slotId]->mRadioIndicationV1_5->dataCallListChanged_1_5(
11257                     convertIntToRadioIndicationType(indicationType), dcList);
11258         } else if (radioService[slotId]->mRadioIndicationV1_4 != NULL) {
11259             hidl_vec<V1_4::SetupDataCallResult> dcList;
11260             convertRilDataCallListToHal_1_4(response, responseLen, dcList);
11261             retStatus = radioService[slotId]->mRadioIndicationV1_4->dataCallListChanged_1_4(
11262                     convertIntToRadioIndicationType(indicationType), dcList);
11263         } else {
11264             hidl_vec<SetupDataCallResult> dcList;
11265             convertRilDataCallListToHal(response, responseLen, dcList);
11266             retStatus = radioService[slotId]->mRadioIndication->dataCallListChanged(
11267                     convertIntToRadioIndicationType(indicationType), dcList);
11268         }
11269         radioService[slotId]->checkReturnStatus(retStatus);
11270     } else {
11271         RLOGE("dataCallListChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
11272     }
11273 
11274     return 0;
11275 }
11276 
suppSvcNotifyInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11277 int radio_1_6::suppSvcNotifyInd(int slotId, int indicationType,
11278                             int token, RIL_Errno e, void *response, size_t responseLen) {
11279     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11280         if (response == NULL || responseLen != sizeof(RIL_SuppSvcNotification)) {
11281             RLOGE("suppSvcNotifyInd: invalid response");
11282             return 0;
11283         }
11284 
11285         SuppSvcNotification suppSvc = {};
11286         RIL_SuppSvcNotification *ssn = (RIL_SuppSvcNotification *) response;
11287         suppSvc.isMT = ssn->notificationType;
11288         suppSvc.code = ssn->code;
11289         suppSvc.index = ssn->index;
11290         suppSvc.type = ssn->type;
11291         suppSvc.number = convertCharPtrToHidlString(ssn->number);
11292 
11293 #if VDBG
11294         RLOGD("suppSvcNotifyInd: isMT %d code %d index %d type %d",
11295                 suppSvc.isMT, suppSvc.code, suppSvc.index, suppSvc.type);
11296 #endif
11297         Return<void> retStatus = radioService[slotId]->mRadioIndication->suppSvcNotify(
11298                 convertIntToRadioIndicationType(indicationType), suppSvc);
11299         radioService[slotId]->checkReturnStatus(retStatus);
11300     } else {
11301         RLOGE("suppSvcNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
11302     }
11303 
11304     return 0;
11305 }
11306 
stkSessionEndInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11307 int radio_1_6::stkSessionEndInd(int slotId, int indicationType,
11308                             int token, RIL_Errno e, void *response, size_t responseLen) {
11309     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11310 #if VDBG
11311         RLOGD("stkSessionEndInd");
11312 #endif
11313         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkSessionEnd(
11314                 convertIntToRadioIndicationType(indicationType));
11315         radioService[slotId]->checkReturnStatus(retStatus);
11316     } else {
11317         RLOGE("stkSessionEndInd: radioService[%d]->mRadioIndication == NULL", slotId);
11318     }
11319 
11320     return 0;
11321 }
11322 
stkProactiveCommandInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11323 int radio_1_6::stkProactiveCommandInd(int slotId,
11324                                   int indicationType, int token, RIL_Errno e, void *response,
11325                                   size_t responseLen) {
11326     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11327         if (response == NULL || responseLen == 0) {
11328             RLOGE("stkProactiveCommandInd: invalid response");
11329             return 0;
11330         }
11331 #if VDBG
11332         RLOGD("stkProactiveCommandInd");
11333 #endif
11334         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkProactiveCommand(
11335                 convertIntToRadioIndicationType(indicationType),
11336                 convertCharPtrToHidlString((char *) response));
11337         radioService[slotId]->checkReturnStatus(retStatus);
11338     } else {
11339         RLOGE("stkProactiveCommandInd: radioService[%d]->mRadioIndication == NULL", slotId);
11340     }
11341 
11342     return 0;
11343 }
11344 
stkEventNotifyInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11345 int radio_1_6::stkEventNotifyInd(int slotId, int indicationType,
11346                              int token, RIL_Errno e, void *response, size_t responseLen) {
11347     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11348         if (response == NULL || responseLen == 0) {
11349             RLOGE("stkEventNotifyInd: invalid response");
11350             return 0;
11351         }
11352 #if VDBG
11353         RLOGD("stkEventNotifyInd");
11354 #endif
11355         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkEventNotify(
11356                 convertIntToRadioIndicationType(indicationType),
11357                 convertCharPtrToHidlString((char *) response));
11358         radioService[slotId]->checkReturnStatus(retStatus);
11359     } else {
11360         RLOGE("stkEventNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
11361     }
11362 
11363     return 0;
11364 }
11365 
stkCallSetupInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11366 int radio_1_6::stkCallSetupInd(int slotId, int indicationType,
11367                            int token, RIL_Errno e, void *response, size_t responseLen) {
11368     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11369         if (response == NULL || responseLen != sizeof(int)) {
11370             RLOGE("stkCallSetupInd: invalid response");
11371             return 0;
11372         }
11373         int32_t timeout = ((int32_t *) response)[0];
11374 #if VDBG
11375         RLOGD("stkCallSetupInd: timeout %d", timeout);
11376 #endif
11377         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkCallSetup(
11378                 convertIntToRadioIndicationType(indicationType), timeout);
11379         radioService[slotId]->checkReturnStatus(retStatus);
11380     } else {
11381         RLOGE("stkCallSetupInd: radioService[%d]->mRadioIndication == NULL", slotId);
11382     }
11383 
11384     return 0;
11385 }
11386 
simSmsStorageFullInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11387 int radio_1_6::simSmsStorageFullInd(int slotId,
11388                                 int indicationType, int token, RIL_Errno e, void *response,
11389                                 size_t responseLen) {
11390     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11391 #if VDBG
11392         RLOGD("simSmsStorageFullInd");
11393 #endif
11394         Return<void> retStatus = radioService[slotId]->mRadioIndication->simSmsStorageFull(
11395                 convertIntToRadioIndicationType(indicationType));
11396         radioService[slotId]->checkReturnStatus(retStatus);
11397     } else {
11398         RLOGE("simSmsStorageFullInd: radioService[%d]->mRadioIndication == NULL", slotId);
11399     }
11400 
11401     return 0;
11402 }
11403 
simRefreshInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11404 int radio_1_6::simRefreshInd(int slotId, int indicationType,
11405                          int token, RIL_Errno e, void *response, size_t responseLen) {
11406     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11407         if (response == NULL || responseLen != sizeof(RIL_SimRefreshResponse_v7)) {
11408             RLOGE("simRefreshInd: invalid response");
11409             return 0;
11410         }
11411 
11412         SimRefreshResult refreshResult = {};
11413         RIL_SimRefreshResponse_v7 *simRefreshResponse = ((RIL_SimRefreshResponse_v7 *) response);
11414         refreshResult.type =
11415                 (V1_0::SimRefreshType) simRefreshResponse->result;
11416         refreshResult.efId = simRefreshResponse->ef_id;
11417         refreshResult.aid = convertCharPtrToHidlString(simRefreshResponse->aid);
11418 
11419 #if VDBG
11420         RLOGD("simRefreshInd: type %d efId %d", refreshResult.type, refreshResult.efId);
11421 #endif
11422         Return<void> retStatus = radioService[slotId]->mRadioIndication->simRefresh(
11423                 convertIntToRadioIndicationType(indicationType), refreshResult);
11424         radioService[slotId]->checkReturnStatus(retStatus);
11425     } else {
11426         RLOGE("simRefreshInd: radioService[%d]->mRadioIndication == NULL", slotId);
11427     }
11428 
11429     return 0;
11430 }
11431 
convertRilCdmaSignalInfoRecordToHal(RIL_CDMA_SignalInfoRecord * signalInfoRecord,CdmaSignalInfoRecord & record)11432 void convertRilCdmaSignalInfoRecordToHal(RIL_CDMA_SignalInfoRecord *signalInfoRecord,
11433         CdmaSignalInfoRecord& record) {
11434     record.isPresent = signalInfoRecord->isPresent;
11435     record.signalType = signalInfoRecord->signalType;
11436     record.alertPitch = signalInfoRecord->alertPitch;
11437     record.signal = signalInfoRecord->signal;
11438 }
11439 
callRingInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11440 int radio_1_6::callRingInd(int slotId, int indicationType,
11441                        int token, RIL_Errno e, void *response, size_t responseLen) {
11442     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11443         bool isGsm;
11444         CdmaSignalInfoRecord record = {};
11445         if (response == NULL || responseLen == 0) {
11446             isGsm = true;
11447         } else {
11448             isGsm = false;
11449             if (responseLen != sizeof (RIL_CDMA_SignalInfoRecord)) {
11450                 RLOGE("callRingInd: invalid response");
11451                 return 0;
11452             }
11453             convertRilCdmaSignalInfoRecordToHal((RIL_CDMA_SignalInfoRecord *) response, record);
11454         }
11455 
11456 #if VDBG
11457         RLOGD("callRingInd: isGsm %d", isGsm);
11458 #endif
11459         Return<void> retStatus = radioService[slotId]->mRadioIndication->callRing(
11460                 convertIntToRadioIndicationType(indicationType), isGsm, record);
11461         radioService[slotId]->checkReturnStatus(retStatus);
11462     } else {
11463         RLOGE("callRingInd: radioService[%d]->mRadioIndication == NULL", slotId);
11464     }
11465 
11466     return 0;
11467 }
11468 
simStatusChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11469 int radio_1_6::simStatusChangedInd(int slotId,
11470                                int indicationType, int token, RIL_Errno e, void *response,
11471                                size_t responseLen) {
11472     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11473 #if VDBG
11474         RLOGD("simStatusChangedInd");
11475 #endif
11476         Return<void> retStatus = radioService[slotId]->mRadioIndication->simStatusChanged(
11477                 convertIntToRadioIndicationType(indicationType));
11478         radioService[slotId]->checkReturnStatus(retStatus);
11479     } else {
11480         RLOGE("simStatusChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
11481     }
11482 
11483     return 0;
11484 }
11485 
cdmaNewSmsInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11486 int radio_1_6::cdmaNewSmsInd(int slotId, int indicationType,
11487                          int token, RIL_Errno e, void *response, size_t responseLen) {
11488     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11489         if (response == NULL || responseLen != sizeof(RIL_CDMA_SMS_Message)) {
11490             RLOGE("cdmaNewSmsInd: invalid response");
11491             return 0;
11492         }
11493 
11494         CdmaSmsMessage msg = {};
11495         RIL_CDMA_SMS_Message *rilMsg = (RIL_CDMA_SMS_Message *) response;
11496         msg.teleserviceId = rilMsg->uTeleserviceID;
11497         msg.isServicePresent = rilMsg->bIsServicePresent;
11498         msg.serviceCategory = rilMsg->uServicecategory;
11499         msg.address.digitMode =
11500                 (V1_0::CdmaSmsDigitMode) rilMsg->sAddress.digit_mode;
11501         msg.address.numberMode =
11502                 (V1_0::CdmaSmsNumberMode) rilMsg->sAddress.number_mode;
11503         msg.address.numberType =
11504                 (V1_0::CdmaSmsNumberType) rilMsg->sAddress.number_type;
11505         msg.address.numberPlan =
11506                 (V1_0::CdmaSmsNumberPlan) rilMsg->sAddress.number_plan;
11507 
11508         int digitLimit = MIN((rilMsg->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
11509         msg.address.digits.setToExternal(rilMsg->sAddress.digits, digitLimit);
11510 
11511         msg.subAddress.subaddressType = (V1_0::CdmaSmsSubaddressType)
11512                 rilMsg->sSubAddress.subaddressType;
11513         msg.subAddress.odd = rilMsg->sSubAddress.odd;
11514 
11515         digitLimit= MIN((rilMsg->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
11516         msg.subAddress.digits.setToExternal(rilMsg->sSubAddress.digits, digitLimit);
11517 
11518         digitLimit = MIN((rilMsg->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
11519         msg.bearerData.setToExternal(rilMsg->aBearerData, digitLimit);
11520 
11521 #if VDBG
11522         RLOGD("cdmaNewSmsInd");
11523 #endif
11524         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaNewSms(
11525                 convertIntToRadioIndicationType(indicationType), msg);
11526         radioService[slotId]->checkReturnStatus(retStatus);
11527     } else {
11528         RLOGE("cdmaNewSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
11529     }
11530 
11531     return 0;
11532 }
11533 
newBroadcastSmsInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11534 int radio_1_6::newBroadcastSmsInd(int slotId,
11535                               int indicationType, int token, RIL_Errno e, void *response,
11536                               size_t responseLen) {
11537     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11538         if (response == NULL || responseLen == 0) {
11539             RLOGE("newBroadcastSmsInd: invalid response");
11540             return 0;
11541         }
11542 
11543         hidl_vec<uint8_t> data;
11544         data.setToExternal((uint8_t *) response, responseLen);
11545 #if VDBG
11546         RLOGD("newBroadcastSmsInd");
11547 #endif
11548         Return<void> retStatus = radioService[slotId]->mRadioIndication->newBroadcastSms(
11549                 convertIntToRadioIndicationType(indicationType), data);
11550         radioService[slotId]->checkReturnStatus(retStatus);
11551     } else {
11552         RLOGE("newBroadcastSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
11553     }
11554 
11555     return 0;
11556 }
11557 
cdmaRuimSmsStorageFullInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11558 int radio_1_6::cdmaRuimSmsStorageFullInd(int slotId,
11559                                      int indicationType, int token, RIL_Errno e, void *response,
11560                                      size_t responseLen) {
11561     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11562 #if VDBG
11563         RLOGD("cdmaRuimSmsStorageFullInd");
11564 #endif
11565         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaRuimSmsStorageFull(
11566                 convertIntToRadioIndicationType(indicationType));
11567         radioService[slotId]->checkReturnStatus(retStatus);
11568     } else {
11569         RLOGE("cdmaRuimSmsStorageFullInd: radioService[%d]->mRadioIndication == NULL",
11570                 slotId);
11571     }
11572 
11573     return 0;
11574 }
11575 
restrictedStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11576 int radio_1_6::restrictedStateChangedInd(int slotId,
11577                                      int indicationType, int token, RIL_Errno e, void *response,
11578                                      size_t responseLen) {
11579     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11580         if (response == NULL || responseLen != sizeof(int)) {
11581             RLOGE("restrictedStateChangedInd: invalid response");
11582             return 0;
11583         }
11584         int32_t state = ((int32_t *) response)[0];
11585 #if VDBG
11586         RLOGD("restrictedStateChangedInd: state %d", state);
11587 #endif
11588         Return<void> retStatus = radioService[slotId]->mRadioIndication->restrictedStateChanged(
11589                 convertIntToRadioIndicationType(indicationType), (PhoneRestrictedState) state);
11590         radioService[slotId]->checkReturnStatus(retStatus);
11591     } else {
11592         RLOGE("restrictedStateChangedInd: radioService[%d]->mRadioIndication == NULL",
11593                 slotId);
11594     }
11595 
11596     return 0;
11597 }
11598 
enterEmergencyCallbackModeInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11599 int radio_1_6::enterEmergencyCallbackModeInd(int slotId,
11600                                          int indicationType, int token, RIL_Errno e, void *response,
11601                                          size_t responseLen) {
11602     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11603 #if VDBG
11604         RLOGD("enterEmergencyCallbackModeInd");
11605 #endif
11606         Return<void> retStatus = radioService[slotId]->mRadioIndication->enterEmergencyCallbackMode(
11607                 convertIntToRadioIndicationType(indicationType));
11608         radioService[slotId]->checkReturnStatus(retStatus);
11609     } else {
11610         RLOGE("enterEmergencyCallbackModeInd: radioService[%d]->mRadioIndication == NULL",
11611                 slotId);
11612     }
11613 
11614     return 0;
11615 }
11616 
cdmaCallWaitingInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11617 int radio_1_6::cdmaCallWaitingInd(int slotId,
11618                               int indicationType, int token, RIL_Errno e, void *response,
11619                               size_t responseLen) {
11620     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11621         if (response == NULL || responseLen != sizeof(RIL_CDMA_CallWaiting_v6)) {
11622             RLOGE("cdmaCallWaitingInd: invalid response");
11623             return 0;
11624         }
11625 
11626         CdmaCallWaiting callWaitingRecord = {};
11627         RIL_CDMA_CallWaiting_v6 *callWaitingRil = ((RIL_CDMA_CallWaiting_v6 *) response);
11628         callWaitingRecord.number = convertCharPtrToHidlString(callWaitingRil->number);
11629         callWaitingRecord.numberPresentation =
11630                 (CdmaCallWaitingNumberPresentation) callWaitingRil->numberPresentation;
11631         callWaitingRecord.name = convertCharPtrToHidlString(callWaitingRil->name);
11632         convertRilCdmaSignalInfoRecordToHal(&callWaitingRil->signalInfoRecord,
11633                 callWaitingRecord.signalInfoRecord);
11634         callWaitingRecord.numberType = (CdmaCallWaitingNumberType) callWaitingRil->number_type;
11635         callWaitingRecord.numberPlan = (CdmaCallWaitingNumberPlan) callWaitingRil->number_plan;
11636 
11637 #if VDBG
11638         RLOGD("cdmaCallWaitingInd");
11639 #endif
11640         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaCallWaiting(
11641                 convertIntToRadioIndicationType(indicationType), callWaitingRecord);
11642         radioService[slotId]->checkReturnStatus(retStatus);
11643     } else {
11644         RLOGE("cdmaCallWaitingInd: radioService[%d]->mRadioIndication == NULL", slotId);
11645     }
11646 
11647     return 0;
11648 }
11649 
cdmaOtaProvisionStatusInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11650 int radio_1_6::cdmaOtaProvisionStatusInd(int slotId,
11651                                      int indicationType, int token, RIL_Errno e, void *response,
11652                                      size_t responseLen) {
11653     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11654         if (response == NULL || responseLen != sizeof(int)) {
11655             RLOGE("cdmaOtaProvisionStatusInd: invalid response");
11656             return 0;
11657         }
11658         int32_t status = ((int32_t *) response)[0];
11659 #if VDBG
11660         RLOGD("cdmaOtaProvisionStatusInd: status %d", status);
11661 #endif
11662         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaOtaProvisionStatus(
11663                 convertIntToRadioIndicationType(indicationType), (CdmaOtaProvisionStatus) status);
11664         radioService[slotId]->checkReturnStatus(retStatus);
11665     } else {
11666         RLOGE("cdmaOtaProvisionStatusInd: radioService[%d]->mRadioIndication == NULL",
11667                 slotId);
11668     }
11669 
11670     return 0;
11671 }
11672 
cdmaInfoRecInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11673 int radio_1_6::cdmaInfoRecInd(int slotId,
11674                           int indicationType, int token, RIL_Errno e, void *response,
11675                           size_t responseLen) {
11676     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11677         if (response == NULL || responseLen != sizeof(RIL_CDMA_InformationRecords)) {
11678             RLOGE("cdmaInfoRecInd: invalid response");
11679             return 0;
11680         }
11681 
11682         CdmaInformationRecords records = {};
11683         RIL_CDMA_InformationRecords *recordsRil = (RIL_CDMA_InformationRecords *) response;
11684 
11685         char* string8 = NULL;
11686         int num = MIN(recordsRil->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
11687         if (recordsRil->numberOfInfoRecs > RIL_CDMA_MAX_NUMBER_OF_INFO_RECS) {
11688             RLOGE("cdmaInfoRecInd: received %d recs which is more than %d, dropping "
11689                     "additional ones", recordsRil->numberOfInfoRecs,
11690                     RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
11691         }
11692         records.infoRec.resize(num);
11693         for (int i = 0 ; i < num ; i++) {
11694             CdmaInformationRecord *record = &records.infoRec[i];
11695             RIL_CDMA_InformationRecord *infoRec = &recordsRil->infoRec[i];
11696             record->name = (CdmaInfoRecName) infoRec->name;
11697             // All vectors should be size 0 except one which will be size 1. Set everything to
11698             // size 0 initially.
11699             record->display.resize(0);
11700             record->number.resize(0);
11701             record->signal.resize(0);
11702             record->redir.resize(0);
11703             record->lineCtrl.resize(0);
11704             record->clir.resize(0);
11705             record->audioCtrl.resize(0);
11706             switch (infoRec->name) {
11707                 case RIL_CDMA_DISPLAY_INFO_REC:
11708                 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC: {
11709                     if (infoRec->rec.display.alpha_len > CDMA_ALPHA_INFO_BUFFER_LENGTH) {
11710                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
11711                                 "expected not more than %d", (int) infoRec->rec.display.alpha_len,
11712                                 CDMA_ALPHA_INFO_BUFFER_LENGTH);
11713                         return 0;
11714                     }
11715                     string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1) * sizeof(char));
11716                     if (string8 == NULL) {
11717                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
11718                                 "responseCdmaInformationRecords");
11719                         return 0;
11720                     }
11721                     memcpy(string8, infoRec->rec.display.alpha_buf, infoRec->rec.display.alpha_len);
11722                     string8[(int)infoRec->rec.display.alpha_len] = '\0';
11723 
11724                     record->display.resize(1);
11725                     record->display[0].alphaBuf = string8;
11726                     free(string8);
11727                     string8 = NULL;
11728                     break;
11729                 }
11730 
11731                 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
11732                 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
11733                 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC: {
11734                     if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
11735                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
11736                                 "expected not more than %d", (int) infoRec->rec.number.len,
11737                                 CDMA_NUMBER_INFO_BUFFER_LENGTH);
11738                         return 0;
11739                     }
11740                     string8 = (char*) malloc((infoRec->rec.number.len + 1) * sizeof(char));
11741                     if (string8 == NULL) {
11742                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
11743                                 "responseCdmaInformationRecords");
11744                         return 0;
11745                     }
11746                     memcpy(string8, infoRec->rec.number.buf, infoRec->rec.number.len);
11747                     string8[(int)infoRec->rec.number.len] = '\0';
11748 
11749                     record->number.resize(1);
11750                     record->number[0].number = string8;
11751                     free(string8);
11752                     string8 = NULL;
11753                     record->number[0].numberType = infoRec->rec.number.number_type;
11754                     record->number[0].numberPlan = infoRec->rec.number.number_plan;
11755                     record->number[0].pi = infoRec->rec.number.pi;
11756                     record->number[0].si = infoRec->rec.number.si;
11757                     break;
11758                 }
11759 
11760                 case RIL_CDMA_SIGNAL_INFO_REC: {
11761                     record->signal.resize(1);
11762                     record->signal[0].isPresent = infoRec->rec.signal.isPresent;
11763                     record->signal[0].signalType = infoRec->rec.signal.signalType;
11764                     record->signal[0].alertPitch = infoRec->rec.signal.alertPitch;
11765                     record->signal[0].signal = infoRec->rec.signal.signal;
11766                     break;
11767                 }
11768 
11769                 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC: {
11770                     if (infoRec->rec.redir.redirectingNumber.len >
11771                                                   CDMA_NUMBER_INFO_BUFFER_LENGTH) {
11772                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
11773                                 "expected not more than %d\n",
11774                                 (int)infoRec->rec.redir.redirectingNumber.len,
11775                                 CDMA_NUMBER_INFO_BUFFER_LENGTH);
11776                         return 0;
11777                     }
11778                     string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber.len + 1) *
11779                             sizeof(char));
11780                     if (string8 == NULL) {
11781                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
11782                                 "responseCdmaInformationRecords");
11783                         return 0;
11784                     }
11785                     memcpy(string8, infoRec->rec.redir.redirectingNumber.buf,
11786                             infoRec->rec.redir.redirectingNumber.len);
11787                     string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
11788 
11789                     record->redir.resize(1);
11790                     record->redir[0].redirectingNumber.number = string8;
11791                     free(string8);
11792                     string8 = NULL;
11793                     record->redir[0].redirectingNumber.numberType =
11794                             infoRec->rec.redir.redirectingNumber.number_type;
11795                     record->redir[0].redirectingNumber.numberPlan =
11796                             infoRec->rec.redir.redirectingNumber.number_plan;
11797                     record->redir[0].redirectingNumber.pi = infoRec->rec.redir.redirectingNumber.pi;
11798                     record->redir[0].redirectingNumber.si = infoRec->rec.redir.redirectingNumber.si;
11799                     record->redir[0].redirectingReason =
11800                             (CdmaRedirectingReason) infoRec->rec.redir.redirectingReason;
11801                     break;
11802                 }
11803 
11804                 case RIL_CDMA_LINE_CONTROL_INFO_REC: {
11805                     record->lineCtrl.resize(1);
11806                     record->lineCtrl[0].lineCtrlPolarityIncluded =
11807                             infoRec->rec.lineCtrl.lineCtrlPolarityIncluded;
11808                     record->lineCtrl[0].lineCtrlToggle = infoRec->rec.lineCtrl.lineCtrlToggle;
11809                     record->lineCtrl[0].lineCtrlReverse = infoRec->rec.lineCtrl.lineCtrlReverse;
11810                     record->lineCtrl[0].lineCtrlPowerDenial =
11811                             infoRec->rec.lineCtrl.lineCtrlPowerDenial;
11812                     break;
11813                 }
11814 
11815                 case RIL_CDMA_T53_CLIR_INFO_REC: {
11816                     record->clir.resize(1);
11817                     record->clir[0].cause = infoRec->rec.clir.cause;
11818                     break;
11819                 }
11820 
11821                 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC: {
11822                     record->audioCtrl.resize(1);
11823                     record->audioCtrl[0].upLink = infoRec->rec.audioCtrl.upLink;
11824                     record->audioCtrl[0].downLink = infoRec->rec.audioCtrl.downLink;
11825                     break;
11826                 }
11827 
11828                 case RIL_CDMA_T53_RELEASE_INFO_REC:
11829                     RLOGE("cdmaInfoRecInd: RIL_CDMA_T53_RELEASE_INFO_REC: INVALID");
11830                     return 0;
11831 
11832                 default:
11833                     RLOGE("cdmaInfoRecInd: Incorrect name value");
11834                     return 0;
11835             }
11836         }
11837 
11838 #if VDBG
11839         RLOGD("cdmaInfoRecInd");
11840 #endif
11841         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaInfoRec(
11842                 convertIntToRadioIndicationType(indicationType), records);
11843         radioService[slotId]->checkReturnStatus(retStatus);
11844     } else {
11845         RLOGE("cdmaInfoRecInd: radioService[%d]->mRadioIndication == NULL", slotId);
11846     }
11847 
11848     return 0;
11849 }
11850 
indicateRingbackToneInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11851 int radio_1_6::indicateRingbackToneInd(int slotId,
11852                                    int indicationType, int token, RIL_Errno e, void *response,
11853                                    size_t responseLen) {
11854     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11855         if (response == NULL || responseLen != sizeof(int)) {
11856             RLOGE("indicateRingbackToneInd: invalid response");
11857             return 0;
11858         }
11859         bool start = ((int32_t *) response)[0];
11860 #if VDBG
11861         RLOGD("indicateRingbackToneInd: start %d", start);
11862 #endif
11863         Return<void> retStatus = radioService[slotId]->mRadioIndication->indicateRingbackTone(
11864                 convertIntToRadioIndicationType(indicationType), start);
11865         radioService[slotId]->checkReturnStatus(retStatus);
11866     } else {
11867         RLOGE("indicateRingbackToneInd: radioService[%d]->mRadioIndication == NULL", slotId);
11868     }
11869 
11870     return 0;
11871 }
11872 
resendIncallMuteInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11873 int radio_1_6::resendIncallMuteInd(int slotId,
11874                                int indicationType, int token, RIL_Errno e, void *response,
11875                                size_t responseLen) {
11876     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11877 #if VDBG
11878         RLOGD("resendIncallMuteInd");
11879 #endif
11880         Return<void> retStatus = radioService[slotId]->mRadioIndication->resendIncallMute(
11881                 convertIntToRadioIndicationType(indicationType));
11882         radioService[slotId]->checkReturnStatus(retStatus);
11883     } else {
11884         RLOGE("resendIncallMuteInd: radioService[%d]->mRadioIndication == NULL", slotId);
11885     }
11886 
11887     return 0;
11888 }
11889 
cdmaSubscriptionSourceChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11890 int radio_1_6::cdmaSubscriptionSourceChangedInd(int slotId,
11891                                             int indicationType, int token, RIL_Errno e,
11892                                             void *response, size_t responseLen) {
11893     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11894         if (response == NULL || responseLen != sizeof(int)) {
11895             RLOGE("cdmaSubscriptionSourceChangedInd: invalid response");
11896             return 0;
11897         }
11898         int32_t cdmaSource = ((int32_t *) response)[0];
11899 #if VDBG
11900         RLOGD("cdmaSubscriptionSourceChangedInd: cdmaSource %d", cdmaSource);
11901 #endif
11902         Return<void> retStatus = radioService[slotId]->mRadioIndication->
11903                 cdmaSubscriptionSourceChanged(convertIntToRadioIndicationType(indicationType),
11904                 (CdmaSubscriptionSource) cdmaSource);
11905         radioService[slotId]->checkReturnStatus(retStatus);
11906     } else {
11907         RLOGE("cdmaSubscriptionSourceChangedInd: radioService[%d]->mRadioIndication == NULL",
11908                 slotId);
11909     }
11910 
11911     return 0;
11912 }
11913 
cdmaPrlChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11914 int radio_1_6::cdmaPrlChangedInd(int slotId,
11915                              int indicationType, int token, RIL_Errno e, void *response,
11916                              size_t responseLen) {
11917     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11918         if (response == NULL || responseLen != sizeof(int)) {
11919             RLOGE("cdmaPrlChangedInd: invalid response");
11920             return 0;
11921         }
11922         int32_t version = ((int32_t *) response)[0];
11923 #if VDBG
11924         RLOGD("cdmaPrlChangedInd: version %d", version);
11925 #endif
11926         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaPrlChanged(
11927                 convertIntToRadioIndicationType(indicationType), version);
11928         radioService[slotId]->checkReturnStatus(retStatus);
11929     } else {
11930         RLOGE("cdmaPrlChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
11931     }
11932 
11933     return 0;
11934 }
11935 
exitEmergencyCallbackModeInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11936 int radio_1_6::exitEmergencyCallbackModeInd(int slotId,
11937                                         int indicationType, int token, RIL_Errno e, void *response,
11938                                         size_t responseLen) {
11939     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11940 #if VDBG
11941         RLOGD("exitEmergencyCallbackModeInd");
11942 #endif
11943         Return<void> retStatus = radioService[slotId]->mRadioIndication->exitEmergencyCallbackMode(
11944                 convertIntToRadioIndicationType(indicationType));
11945         radioService[slotId]->checkReturnStatus(retStatus);
11946     } else {
11947         RLOGE("exitEmergencyCallbackModeInd: radioService[%d]->mRadioIndication == NULL",
11948                 slotId);
11949     }
11950 
11951     return 0;
11952 }
11953 
rilConnectedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11954 int radio_1_6::rilConnectedInd(int slotId,
11955                            int indicationType, int token, RIL_Errno e, void *response,
11956                            size_t responseLen) {
11957     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11958         RLOGD("rilConnectedInd");
11959         Return<void> retStatus = radioService[slotId]->mRadioIndication->rilConnected(
11960                 convertIntToRadioIndicationType(indicationType));
11961         radioService[slotId]->checkReturnStatus(retStatus);
11962     } else {
11963         RLOGE("rilConnectedInd: radioService[%d]->mRadioIndication == NULL", slotId);
11964     }
11965 
11966     return 0;
11967 }
11968 
voiceRadioTechChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11969 int radio_1_6::voiceRadioTechChangedInd(int slotId,
11970                                     int indicationType, int token, RIL_Errno e, void *response,
11971                                     size_t responseLen) {
11972     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11973         if (response == NULL || responseLen != sizeof(int)) {
11974             RLOGE("voiceRadioTechChangedInd: invalid response");
11975             return 0;
11976         }
11977         int32_t rat = ((int32_t *) response)[0];
11978 #if VDBG
11979         RLOGD("voiceRadioTechChangedInd: rat %d", rat);
11980 #endif
11981         Return<void> retStatus = radioService[slotId]->mRadioIndication->voiceRadioTechChanged(
11982                 convertIntToRadioIndicationType(indicationType), (RadioTechnology) rat);
11983         radioService[slotId]->checkReturnStatus(retStatus);
11984     } else {
11985         RLOGE("voiceRadioTechChangedInd: radioService[%d]->mRadioIndication == NULL",
11986                 slotId);
11987     }
11988 
11989     return 0;
11990 }
11991 
convertRilCellInfoListToHal(void * response,size_t responseLen,hidl_vec<CellInfo> & records)11992 void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<CellInfo>& records) {
11993     int num = responseLen / sizeof(RIL_CellInfo_v12);
11994     records.resize(num);
11995 
11996     RIL_CellInfo_v12 *rillCellInfo = (RIL_CellInfo_v12 *) response;
11997     for (int i = 0; i < num; i++) {
11998         records[i].cellInfoType = (CellInfoType) rillCellInfo->cellInfoType;
11999         records[i].registered = rillCellInfo->registered;
12000         records[i].timeStampType = (TimeStampType) rillCellInfo->timeStampType;
12001         records[i].timeStamp = rillCellInfo->timeStamp;
12002         // All vectors should be size 0 except one which will be size 1. Set everything to
12003         // size 0 initially.
12004         records[i].gsm.resize(0);
12005         records[i].wcdma.resize(0);
12006         records[i].cdma.resize(0);
12007         records[i].lte.resize(0);
12008         records[i].tdscdma.resize(0);
12009         switch(rillCellInfo->cellInfoType) {
12010             case RIL_CELL_INFO_TYPE_GSM: {
12011                 records[i].gsm.resize(1);
12012                 CellInfoGsm *cellInfoGsm = &records[i].gsm[0];
12013                 cellInfoGsm->cellIdentityGsm.mcc =
12014                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
12015                 cellInfoGsm->cellIdentityGsm.mnc =
12016                         ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
12017                 cellInfoGsm->cellIdentityGsm.lac =
12018                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
12019                 cellInfoGsm->cellIdentityGsm.cid =
12020                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
12021                 cellInfoGsm->cellIdentityGsm.arfcn =
12022                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
12023                 cellInfoGsm->cellIdentityGsm.bsic =
12024                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
12025                 cellInfoGsm->signalStrengthGsm.signalStrength =
12026                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
12027                 cellInfoGsm->signalStrengthGsm.bitErrorRate =
12028                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
12029                 cellInfoGsm->signalStrengthGsm.timingAdvance =
12030                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
12031                 break;
12032             }
12033 
12034             case RIL_CELL_INFO_TYPE_WCDMA: {
12035                 records[i].wcdma.resize(1);
12036                 CellInfoWcdma *cellInfoWcdma = &records[i].wcdma[0];
12037                 cellInfoWcdma->cellIdentityWcdma.mcc =
12038                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
12039                 cellInfoWcdma->cellIdentityWcdma.mnc =
12040                         ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
12041                 cellInfoWcdma->cellIdentityWcdma.lac =
12042                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
12043                 cellInfoWcdma->cellIdentityWcdma.cid =
12044                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
12045                 cellInfoWcdma->cellIdentityWcdma.psc =
12046                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
12047                 cellInfoWcdma->cellIdentityWcdma.uarfcn =
12048                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
12049                 cellInfoWcdma->signalStrengthWcdma.signalStrength =
12050                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
12051                 cellInfoWcdma->signalStrengthWcdma.bitErrorRate =
12052                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
12053                 break;
12054             }
12055 
12056             case RIL_CELL_INFO_TYPE_CDMA: {
12057                 records[i].cdma.resize(1);
12058                 CellInfoCdma *cellInfoCdma = &records[i].cdma[0];
12059                 cellInfoCdma->cellIdentityCdma.networkId =
12060                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
12061                 cellInfoCdma->cellIdentityCdma.systemId =
12062                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
12063                 cellInfoCdma->cellIdentityCdma.baseStationId =
12064                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
12065                 cellInfoCdma->cellIdentityCdma.longitude =
12066                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
12067                 cellInfoCdma->cellIdentityCdma.latitude =
12068                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
12069                 cellInfoCdma->signalStrengthCdma.dbm =
12070                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
12071                 cellInfoCdma->signalStrengthCdma.ecio =
12072                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
12073                 cellInfoCdma->signalStrengthEvdo.dbm =
12074                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
12075                 cellInfoCdma->signalStrengthEvdo.ecio =
12076                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
12077                 cellInfoCdma->signalStrengthEvdo.signalNoiseRatio =
12078                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
12079                 break;
12080             }
12081 
12082             case RIL_CELL_INFO_TYPE_LTE: {
12083                 records[i].lte.resize(1);
12084                 CellInfoLte *cellInfoLte = &records[i].lte[0];
12085                 cellInfoLte->cellIdentityLte.mcc =
12086                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
12087                 cellInfoLte->cellIdentityLte.mnc =
12088                         ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
12089                 cellInfoLte->cellIdentityLte.ci =
12090                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
12091                 cellInfoLte->cellIdentityLte.pci =
12092                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
12093                 cellInfoLte->cellIdentityLte.tac =
12094                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
12095                 cellInfoLte->cellIdentityLte.earfcn =
12096                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
12097                 cellInfoLte->signalStrengthLte.signalStrength =
12098                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
12099                 cellInfoLte->signalStrengthLte.rsrp =
12100                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
12101                 cellInfoLte->signalStrengthLte.rsrq =
12102                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
12103                 cellInfoLte->signalStrengthLte.rssnr =
12104                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
12105                 cellInfoLte->signalStrengthLte.cqi =
12106                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
12107                 cellInfoLte->signalStrengthLte.timingAdvance =
12108                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
12109                 break;
12110             }
12111 
12112             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
12113                 records[i].tdscdma.resize(1);
12114                 CellInfoTdscdma *cellInfoTdscdma = &records[i].tdscdma[0];
12115                 cellInfoTdscdma->cellIdentityTdscdma.mcc =
12116                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
12117                 cellInfoTdscdma->cellIdentityTdscdma.mnc =
12118                         ril::util::mnc::decode(
12119                                 rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
12120                 cellInfoTdscdma->cellIdentityTdscdma.lac =
12121                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
12122                 cellInfoTdscdma->cellIdentityTdscdma.cid =
12123                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
12124                 cellInfoTdscdma->cellIdentityTdscdma.cpid =
12125                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
12126                 cellInfoTdscdma->signalStrengthTdscdma.rscp =
12127                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
12128                 break;
12129             }
12130             default: {
12131                 break;
12132             }
12133         }
12134         rillCellInfo += 1;
12135     }
12136 }
12137 
convertRilCellInfoListToHal_1_2(void * response,size_t responseLen,hidl_vec<V1_2::CellInfo> & records)12138 void convertRilCellInfoListToHal_1_2(void *response, size_t responseLen, hidl_vec<V1_2::CellInfo>& records) {
12139     int num = responseLen / sizeof(RIL_CellInfo_v12);
12140     records.resize(num);
12141     RIL_CellInfo_v12 *rillCellInfo = (RIL_CellInfo_v12 *) response;
12142     for (int i = 0; i < num; i++) {
12143         records[i].cellInfoType = (CellInfoType) rillCellInfo->cellInfoType;
12144         records[i].registered = rillCellInfo->registered;
12145         records[i].timeStampType = (TimeStampType) rillCellInfo->timeStampType;
12146         records[i].timeStamp = rillCellInfo->timeStamp;
12147         records[i].connectionStatus =(V1_2::CellConnectionStatus)0;
12148         // All vectors should be size 0 except one which will be size 1. Set everything to
12149         // size 0 initially.
12150         records[i].gsm.resize(0);
12151         records[i].wcdma.resize(0);
12152         records[i].cdma.resize(0);
12153         records[i].lte.resize(0);
12154         records[i].tdscdma.resize(0);
12155         switch(rillCellInfo->cellInfoType) {
12156             case RIL_CELL_INFO_TYPE_GSM: {
12157                 records[i].gsm.resize(1);
12158                 V1_2::CellInfoGsm *cellInfoGsm = &records[i].gsm[0];
12159                 cellInfoGsm->cellIdentityGsm.base.mcc =
12160                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
12161                 cellInfoGsm->cellIdentityGsm.base.mnc =
12162                         ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
12163                 cellInfoGsm->cellIdentityGsm.base.lac =
12164                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
12165                 cellInfoGsm->cellIdentityGsm.base.cid =
12166                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
12167                 cellInfoGsm->cellIdentityGsm.base.arfcn =
12168                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
12169                 cellInfoGsm->cellIdentityGsm.base.bsic =
12170                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
12171                 cellInfoGsm->signalStrengthGsm.signalStrength =
12172                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
12173                 cellInfoGsm->signalStrengthGsm.bitErrorRate =
12174                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
12175                 cellInfoGsm->signalStrengthGsm.timingAdvance =
12176                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
12177                 break;
12178             }
12179 
12180             case RIL_CELL_INFO_TYPE_WCDMA: {
12181                 records[i].wcdma.resize(1);
12182                 V1_2::CellInfoWcdma *cellInfoWcdma = &records[i].wcdma[0];
12183                 cellInfoWcdma->cellIdentityWcdma.base.mcc =
12184                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
12185                 cellInfoWcdma->cellIdentityWcdma.base.mnc =
12186                         ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
12187                 cellInfoWcdma->cellIdentityWcdma.base.lac =
12188                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
12189                 cellInfoWcdma->cellIdentityWcdma.base.cid =
12190                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
12191                 cellInfoWcdma->cellIdentityWcdma.base.psc =
12192                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
12193                 cellInfoWcdma->cellIdentityWcdma.base.uarfcn =
12194                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
12195                 cellInfoWcdma->signalStrengthWcdma.base.signalStrength =
12196                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
12197                 cellInfoWcdma->signalStrengthWcdma.base.bitErrorRate =
12198                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
12199                 break;
12200             }
12201 
12202             case RIL_CELL_INFO_TYPE_CDMA: {
12203                 records[i].cdma.resize(1);
12204                 V1_2::CellInfoCdma *cellInfoCdma = &records[i].cdma[0];
12205                 cellInfoCdma->cellIdentityCdma.base.networkId =
12206                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
12207                 cellInfoCdma->cellIdentityCdma.base.systemId =
12208                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
12209                 cellInfoCdma->cellIdentityCdma.base.baseStationId =
12210                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
12211                 cellInfoCdma->cellIdentityCdma.base.longitude =
12212                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
12213                 cellInfoCdma->cellIdentityCdma.base.latitude =
12214                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
12215                 cellInfoCdma->signalStrengthCdma.dbm =
12216                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
12217                 cellInfoCdma->signalStrengthCdma.ecio =
12218                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
12219                 cellInfoCdma->signalStrengthEvdo.dbm =
12220                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
12221                 cellInfoCdma->signalStrengthEvdo.ecio =
12222                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
12223                 cellInfoCdma->signalStrengthEvdo.signalNoiseRatio =
12224                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
12225                 break;
12226             }
12227 
12228             case RIL_CELL_INFO_TYPE_LTE: {
12229                 records[i].lte.resize(1);
12230                 V1_2::CellInfoLte *cellInfoLte = &records[i].lte[0];
12231                 cellInfoLte->cellIdentityLte.base.mcc =
12232                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
12233                 cellInfoLte->cellIdentityLte.base.mnc =
12234                         ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
12235                 cellInfoLte->cellIdentityLte.base.ci =
12236                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
12237                 cellInfoLte->cellIdentityLte.base.pci =
12238                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
12239                 cellInfoLte->cellIdentityLte.base.tac =
12240                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
12241                 cellInfoLte->cellIdentityLte.base.earfcn =
12242                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
12243                 cellInfoLte->signalStrengthLte.signalStrength =
12244                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
12245                 cellInfoLte->signalStrengthLte.rsrp =
12246                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
12247                 cellInfoLte->signalStrengthLte.rsrq =
12248                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
12249                 cellInfoLte->signalStrengthLte.rssnr =
12250                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
12251                 cellInfoLte->signalStrengthLte.cqi =
12252                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
12253                 cellInfoLte->signalStrengthLte.timingAdvance =
12254                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
12255                 break;
12256             }
12257 
12258             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
12259                 records[i].tdscdma.resize(1);
12260                 V1_2::CellInfoTdscdma *cellInfoTdscdma = &records[i].tdscdma[0];
12261                 cellInfoTdscdma->cellIdentityTdscdma.base.mcc =
12262                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
12263                 cellInfoTdscdma->cellIdentityTdscdma.base.mnc =
12264                         ril::util::mnc::decode(
12265                                 rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
12266                 cellInfoTdscdma->cellIdentityTdscdma.base.lac =
12267                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
12268                 cellInfoTdscdma->cellIdentityTdscdma.base.cid =
12269                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
12270                 cellInfoTdscdma->cellIdentityTdscdma.base.cpid =
12271                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
12272                 cellInfoTdscdma->signalStrengthTdscdma.rscp =
12273                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
12274                 break;
12275             }
12276             default: {
12277                 break;
12278             }
12279         }
12280         rillCellInfo += 1;
12281     }
12282 }
12283 
convertRilCellInfoListToHal_1_4(void * response,size_t responseLen,hidl_vec<V1_4::CellInfo> & records)12284 void convertRilCellInfoListToHal_1_4(void *response, size_t responseLen, hidl_vec<V1_4::CellInfo>& records) {
12285     int num = responseLen / sizeof(RIL_CellInfo_v16);
12286     records.resize(num);
12287     RIL_CellInfo_v16 *rillCellInfo = (RIL_CellInfo_v16 *) response;
12288     for (int i = 0; i < num; i++) {
12289         records[i].isRegistered = rillCellInfo->registered;
12290         records[i].connectionStatus = (V1_2::CellConnectionStatus)rillCellInfo->connectionStatus;
12291 
12292         switch(rillCellInfo->cellInfoType) {
12293             case RIL_CELL_INFO_TYPE_GSM: {
12294                 V1_2::CellInfoGsm cellInfoGsm;
12295                 cellInfoGsm.cellIdentityGsm.base.mcc =
12296                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
12297                 cellInfoGsm.cellIdentityGsm.base.mnc =
12298                         ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
12299                 cellInfoGsm.cellIdentityGsm.base.lac =
12300                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
12301                 cellInfoGsm.cellIdentityGsm.base.cid =
12302                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
12303                 cellInfoGsm.cellIdentityGsm.base.arfcn =
12304                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
12305                 cellInfoGsm.cellIdentityGsm.base.bsic =
12306                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
12307                 cellInfoGsm.signalStrengthGsm.signalStrength =
12308                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
12309                 cellInfoGsm.signalStrengthGsm.bitErrorRate =
12310                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
12311                 cellInfoGsm.signalStrengthGsm.timingAdvance =
12312                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
12313                 records[i].info.gsm(cellInfoGsm);
12314                 break;
12315             }
12316 
12317             case RIL_CELL_INFO_TYPE_WCDMA: {
12318                 V1_2::CellInfoWcdma cellInfoWcdma;
12319                 cellInfoWcdma.cellIdentityWcdma.base.mcc =
12320                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
12321                 cellInfoWcdma.cellIdentityWcdma.base.mnc =
12322                         ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
12323                 cellInfoWcdma.cellIdentityWcdma.base.lac =
12324                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
12325                 cellInfoWcdma.cellIdentityWcdma.base.cid =
12326                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
12327                 cellInfoWcdma.cellIdentityWcdma.base.psc =
12328                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
12329                 cellInfoWcdma.cellIdentityWcdma.base.uarfcn =
12330                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
12331                 cellInfoWcdma.signalStrengthWcdma.base.signalStrength =
12332                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
12333                 cellInfoWcdma.signalStrengthWcdma.base.bitErrorRate =
12334                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
12335                 records[i].info.wcdma(cellInfoWcdma);
12336                 break;
12337             }
12338 
12339             case RIL_CELL_INFO_TYPE_CDMA: {
12340                 V1_2::CellInfoCdma cellInfoCdma;
12341                 cellInfoCdma.cellIdentityCdma.base.networkId =
12342                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
12343                 cellInfoCdma.cellIdentityCdma.base.systemId =
12344                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
12345                 cellInfoCdma.cellIdentityCdma.base.baseStationId =
12346                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
12347                 cellInfoCdma.cellIdentityCdma.base.longitude =
12348                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
12349                 cellInfoCdma.cellIdentityCdma.base.latitude =
12350                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
12351                 cellInfoCdma.signalStrengthCdma.dbm =
12352                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
12353                 cellInfoCdma.signalStrengthCdma.ecio =
12354                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
12355                 cellInfoCdma.signalStrengthEvdo.dbm =
12356                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
12357                 cellInfoCdma.signalStrengthEvdo.ecio =
12358                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
12359                 cellInfoCdma.signalStrengthEvdo.signalNoiseRatio =
12360                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
12361                 records[i].info.cdma(cellInfoCdma);
12362                 break;
12363             }
12364 
12365             case RIL_CELL_INFO_TYPE_LTE: {
12366                 V1_4::CellInfoLte cellInfoLte;
12367                 cellInfoLte.base.cellIdentityLte.base.mcc =
12368                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
12369                 cellInfoLte.base.cellIdentityLte.base.mnc =
12370                         ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
12371                 cellInfoLte.base.cellIdentityLte.base.ci =
12372                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
12373                 cellInfoLte.base.cellIdentityLte.base.pci =
12374                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
12375                 cellInfoLte.base.cellIdentityLte.base.tac =
12376                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
12377                 cellInfoLte.base.cellIdentityLte.base.earfcn =
12378                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
12379                 cellInfoLte.base.signalStrengthLte.signalStrength =
12380                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
12381                 cellInfoLte.base.signalStrengthLte.rsrp =
12382                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
12383                 cellInfoLte.base.signalStrengthLte.rsrq =
12384                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
12385                 cellInfoLte.base.signalStrengthLte.rssnr =
12386                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
12387                 cellInfoLte.base.signalStrengthLte.cqi =
12388                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
12389                 cellInfoLte.base.signalStrengthLte.timingAdvance =
12390                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
12391                 records[i].info.lte(cellInfoLte);
12392                 break;
12393             }
12394 
12395             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
12396                 V1_2::CellInfoTdscdma cellInfoTdscdma;
12397                 cellInfoTdscdma.cellIdentityTdscdma.base.mcc =
12398                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
12399                 cellInfoTdscdma.cellIdentityTdscdma.base.mnc =
12400                         ril::util::mnc::decode(
12401                                 rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
12402                 cellInfoTdscdma.cellIdentityTdscdma.base.lac =
12403                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
12404                 cellInfoTdscdma.cellIdentityTdscdma.base.cid =
12405                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
12406                 cellInfoTdscdma.cellIdentityTdscdma.base.cpid =
12407                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
12408                 cellInfoTdscdma.signalStrengthTdscdma.rscp =
12409                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
12410                 records[i].info.tdscdma(cellInfoTdscdma);
12411                 break;
12412             }
12413 
12414             case RIL_CELL_INFO_TYPE_NR: {
12415                 V1_4::CellInfoNr cellInfoNr;
12416                 cellInfoNr.cellidentity.mcc =
12417                         std::to_string(rillCellInfo->CellInfo.nr.cellidentity.mcc);
12418                 cellInfoNr.cellidentity.mnc =
12419                         ril::util::mnc::decode(
12420                                 rillCellInfo->CellInfo.nr.cellidentity.mnc);
12421                 cellInfoNr.cellidentity.nci =
12422                         rillCellInfo->CellInfo.nr.cellidentity.nci;
12423                 cellInfoNr.cellidentity.pci =
12424                         rillCellInfo->CellInfo.nr.cellidentity.pci;
12425                 cellInfoNr.cellidentity.tac =
12426                         rillCellInfo->CellInfo.nr.cellidentity.tac;
12427                 cellInfoNr.cellidentity.nrarfcn =
12428                         rillCellInfo->CellInfo.nr.cellidentity.nrarfcn;
12429                 cellInfoNr.cellidentity.operatorNames.alphaLong =
12430                         convertCharPtrToHidlString(rillCellInfo->CellInfo.nr.cellidentity.operatorNames.alphaLong);
12431                 cellInfoNr.cellidentity.operatorNames.alphaShort =
12432                         convertCharPtrToHidlString(rillCellInfo->CellInfo.nr.cellidentity.operatorNames.alphaShort);
12433 
12434                 cellInfoNr.signalStrength.ssRsrp =
12435                         rillCellInfo->CellInfo.nr.signalStrength.ssRsrp;
12436                 cellInfoNr.signalStrength.ssRsrq =
12437                         rillCellInfo->CellInfo.nr.signalStrength.ssRsrq;
12438                 cellInfoNr.signalStrength.ssSinr =
12439                         rillCellInfo->CellInfo.nr.signalStrength.ssSinr;
12440                 cellInfoNr.signalStrength.csiRsrp =
12441                         rillCellInfo->CellInfo.nr.signalStrength.csiRsrp;
12442                 cellInfoNr.signalStrength.csiRsrq =
12443                         rillCellInfo->CellInfo.nr.signalStrength.csiRsrq;
12444                 cellInfoNr.signalStrength.csiSinr =
12445                         rillCellInfo->CellInfo.nr.signalStrength.csiSinr;
12446                 records[i].info.nr(cellInfoNr);
12447                 break;
12448             }
12449             default: {
12450                 break;
12451             }
12452         }
12453         rillCellInfo += 1;
12454     }
12455 }
12456 
convertRilCellInfoListToHal_1_5(void * response,size_t responseLen,hidl_vec<V1_5::CellInfo> & records)12457 void convertRilCellInfoListToHal_1_5(void* response, size_t responseLen,
12458                                      hidl_vec<V1_5::CellInfo>& records) {
12459     int num = responseLen / sizeof(RIL_CellInfo_v16);
12460     records.resize(num);
12461     RIL_CellInfo_v16* rillCellInfo = (RIL_CellInfo_v16*)response;
12462     for (int i = 0; i < num; i++) {
12463         records[i].registered = rillCellInfo->registered;
12464         records[i].connectionStatus = (V1_2::CellConnectionStatus)rillCellInfo->connectionStatus;
12465 
12466         switch (rillCellInfo->cellInfoType) {
12467             case RIL_CELL_INFO_TYPE_GSM: {
12468                 V1_5::CellInfoGsm cellInfoGsm;
12469                 cellInfoGsm.cellIdentityGsm.base.base.mcc =
12470                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
12471                 cellInfoGsm.cellIdentityGsm.base.base.mnc =
12472                         ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
12473                 cellInfoGsm.cellIdentityGsm.base.base.lac =
12474                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
12475                 cellInfoGsm.cellIdentityGsm.base.base.cid =
12476                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
12477                 cellInfoGsm.cellIdentityGsm.base.base.arfcn =
12478                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
12479                 cellInfoGsm.cellIdentityGsm.base.base.bsic =
12480                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
12481                 cellInfoGsm.signalStrengthGsm.signalStrength =
12482                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
12483                 cellInfoGsm.signalStrengthGsm.bitErrorRate =
12484                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
12485                 cellInfoGsm.signalStrengthGsm.timingAdvance =
12486                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
12487                 records[i].ratSpecificInfo.gsm(cellInfoGsm);
12488                 break;
12489             }
12490 
12491             case RIL_CELL_INFO_TYPE_WCDMA: {
12492                 V1_5::CellInfoWcdma cellInfoWcdma;
12493                 cellInfoWcdma.cellIdentityWcdma.base.base.mcc =
12494                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
12495                 cellInfoWcdma.cellIdentityWcdma.base.base.mnc =
12496                         ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
12497                 cellInfoWcdma.cellIdentityWcdma.base.base.lac =
12498                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
12499                 cellInfoWcdma.cellIdentityWcdma.base.base.cid =
12500                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
12501                 cellInfoWcdma.cellIdentityWcdma.base.base.psc =
12502                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
12503                 cellInfoWcdma.cellIdentityWcdma.base.base.uarfcn =
12504                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
12505                 cellInfoWcdma.signalStrengthWcdma.base.signalStrength =
12506                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
12507                 cellInfoWcdma.signalStrengthWcdma.base.bitErrorRate =
12508                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
12509                 records[i].ratSpecificInfo.wcdma(cellInfoWcdma);
12510                 break;
12511             }
12512 
12513             case RIL_CELL_INFO_TYPE_CDMA: {
12514                 V1_2::CellInfoCdma cellInfoCdma;
12515                 cellInfoCdma.cellIdentityCdma.base.networkId =
12516                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
12517                 cellInfoCdma.cellIdentityCdma.base.systemId =
12518                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
12519                 cellInfoCdma.cellIdentityCdma.base.baseStationId =
12520                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
12521                 cellInfoCdma.cellIdentityCdma.base.longitude =
12522                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
12523                 cellInfoCdma.cellIdentityCdma.base.latitude =
12524                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
12525                 cellInfoCdma.signalStrengthCdma.dbm =
12526                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
12527                 cellInfoCdma.signalStrengthCdma.ecio =
12528                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
12529                 cellInfoCdma.signalStrengthEvdo.dbm =
12530                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
12531                 cellInfoCdma.signalStrengthEvdo.ecio =
12532                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
12533                 cellInfoCdma.signalStrengthEvdo.signalNoiseRatio =
12534                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
12535                 records[i].ratSpecificInfo.cdma(cellInfoCdma);
12536                 break;
12537             }
12538 
12539             case RIL_CELL_INFO_TYPE_LTE: {
12540                 V1_5::CellInfoLte cellInfoLte;
12541                 cellInfoLte.cellIdentityLte.base.base.mcc =
12542                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
12543                 cellInfoLte.cellIdentityLte.base.base.mnc =
12544                         ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
12545                 cellInfoLte.cellIdentityLte.base.base.ci =
12546                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
12547                 cellInfoLte.cellIdentityLte.base.base.pci =
12548                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
12549                 cellInfoLte.cellIdentityLte.base.base.tac =
12550                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
12551                 cellInfoLte.cellIdentityLte.base.base.earfcn =
12552                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
12553                 cellInfoLte.signalStrengthLte.signalStrength =
12554                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
12555                 cellInfoLte.signalStrengthLte.rsrp =
12556                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
12557                 cellInfoLte.signalStrengthLte.rsrq =
12558                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
12559                 cellInfoLte.signalStrengthLte.rssnr =
12560                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
12561                 cellInfoLte.signalStrengthLte.cqi =
12562                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
12563                 cellInfoLte.signalStrengthLte.timingAdvance =
12564                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
12565                 records[i].ratSpecificInfo.lte(cellInfoLte);
12566                 break;
12567             }
12568 
12569             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
12570                 V1_5::CellInfoTdscdma cellInfoTdscdma;
12571                 cellInfoTdscdma.cellIdentityTdscdma.base.base.mcc =
12572                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
12573                 cellInfoTdscdma.cellIdentityTdscdma.base.base.mnc = ril::util::mnc::decode(
12574                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
12575                 cellInfoTdscdma.cellIdentityTdscdma.base.base.lac =
12576                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
12577                 cellInfoTdscdma.cellIdentityTdscdma.base.base.cid =
12578                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
12579                 cellInfoTdscdma.cellIdentityTdscdma.base.base.cpid =
12580                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
12581                 cellInfoTdscdma.signalStrengthTdscdma.rscp =
12582                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
12583                 records[i].ratSpecificInfo.tdscdma(cellInfoTdscdma);
12584                 break;
12585             }
12586 
12587             case RIL_CELL_INFO_TYPE_NR: {
12588                 V1_5::CellInfoNr cellInfoNr;
12589                 cellInfoNr.cellIdentityNr.base.mcc =
12590                         std::to_string(rillCellInfo->CellInfo.nr.cellidentity.mcc);
12591                 cellInfoNr.cellIdentityNr.base.mnc =
12592                         ril::util::mnc::decode(rillCellInfo->CellInfo.nr.cellidentity.mnc);
12593                 cellInfoNr.cellIdentityNr.base.nci = rillCellInfo->CellInfo.nr.cellidentity.nci;
12594                 cellInfoNr.cellIdentityNr.base.pci = rillCellInfo->CellInfo.nr.cellidentity.pci;
12595                 cellInfoNr.cellIdentityNr.base.tac = rillCellInfo->CellInfo.nr.cellidentity.tac;
12596                 cellInfoNr.cellIdentityNr.base.nrarfcn =
12597                         rillCellInfo->CellInfo.nr.cellidentity.nrarfcn;
12598                 cellInfoNr.cellIdentityNr.base.operatorNames.alphaLong = convertCharPtrToHidlString(
12599                         rillCellInfo->CellInfo.nr.cellidentity.operatorNames.alphaLong);
12600                 cellInfoNr.cellIdentityNr.base.operatorNames.alphaShort =
12601                         convertCharPtrToHidlString(
12602                                 rillCellInfo->CellInfo.nr.cellidentity.operatorNames.alphaShort);
12603 
12604                 cellInfoNr.signalStrengthNr.ssRsrp =
12605                         rillCellInfo->CellInfo.nr.signalStrength.ssRsrp;
12606                 cellInfoNr.signalStrengthNr.ssRsrq =
12607                         rillCellInfo->CellInfo.nr.signalStrength.ssRsrq;
12608                 cellInfoNr.signalStrengthNr.ssSinr =
12609                         rillCellInfo->CellInfo.nr.signalStrength.ssSinr;
12610                 cellInfoNr.signalStrengthNr.csiRsrp =
12611                         rillCellInfo->CellInfo.nr.signalStrength.csiRsrp;
12612                 cellInfoNr.signalStrengthNr.csiRsrq =
12613                         rillCellInfo->CellInfo.nr.signalStrength.csiRsrq;
12614                 cellInfoNr.signalStrengthNr.csiSinr =
12615                         rillCellInfo->CellInfo.nr.signalStrength.csiSinr;
12616                 records[i].ratSpecificInfo.nr(cellInfoNr);
12617                 break;
12618             }
12619             default: {
12620                 break;
12621             }
12622         }
12623         rillCellInfo += 1;
12624     }
12625 }
12626 
convertRilCellInfoListToHal_1_6(void * response,size_t responseLen,hidl_vec<V1_6::CellInfo> & records)12627 void convertRilCellInfoListToHal_1_6(void* response, size_t responseLen,
12628                                      hidl_vec<V1_6::CellInfo>& records) {
12629     int num = responseLen / sizeof(RIL_CellInfo_v16);
12630     records.resize(num);
12631     RIL_CellInfo_v16* rillCellInfo = (RIL_CellInfo_v16*)response;
12632     for (int i = 0; i < num; i++) {
12633         records[i].registered = rillCellInfo->registered;
12634         records[i].connectionStatus = (V1_2::CellConnectionStatus)rillCellInfo->connectionStatus;
12635 
12636         switch (rillCellInfo->cellInfoType) {
12637             case RIL_CELL_INFO_TYPE_GSM: {
12638                 V1_5::CellInfoGsm cellInfoGsm;
12639                 cellInfoGsm.cellIdentityGsm.base.base.mcc =
12640                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
12641                 cellInfoGsm.cellIdentityGsm.base.base.mnc =
12642                         ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
12643                 cellInfoGsm.cellIdentityGsm.base.base.lac =
12644                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
12645                 cellInfoGsm.cellIdentityGsm.base.base.cid =
12646                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
12647                 cellInfoGsm.cellIdentityGsm.base.base.arfcn =
12648                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
12649                 cellInfoGsm.cellIdentityGsm.base.base.bsic =
12650                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
12651                 cellInfoGsm.signalStrengthGsm.signalStrength =
12652                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
12653                 cellInfoGsm.signalStrengthGsm.bitErrorRate =
12654                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
12655                 cellInfoGsm.signalStrengthGsm.timingAdvance =
12656                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
12657                 records[i].ratSpecificInfo.gsm(cellInfoGsm);
12658                 break;
12659             }
12660 
12661             case RIL_CELL_INFO_TYPE_WCDMA: {
12662                 V1_5::CellInfoWcdma cellInfoWcdma;
12663                 cellInfoWcdma.cellIdentityWcdma.base.base.mcc =
12664                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
12665                 cellInfoWcdma.cellIdentityWcdma.base.base.mnc =
12666                         ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
12667                 cellInfoWcdma.cellIdentityWcdma.base.base.lac =
12668                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
12669                 cellInfoWcdma.cellIdentityWcdma.base.base.cid =
12670                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
12671                 cellInfoWcdma.cellIdentityWcdma.base.base.psc =
12672                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
12673                 cellInfoWcdma.cellIdentityWcdma.base.base.uarfcn =
12674                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
12675                 cellInfoWcdma.signalStrengthWcdma.base.signalStrength =
12676                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
12677                 cellInfoWcdma.signalStrengthWcdma.base.bitErrorRate =
12678                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
12679                 records[i].ratSpecificInfo.wcdma(cellInfoWcdma);
12680                 break;
12681             }
12682 
12683             case RIL_CELL_INFO_TYPE_CDMA: {
12684                 V1_2::CellInfoCdma cellInfoCdma;
12685                 cellInfoCdma.cellIdentityCdma.base.networkId =
12686                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
12687                 cellInfoCdma.cellIdentityCdma.base.systemId =
12688                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
12689                 cellInfoCdma.cellIdentityCdma.base.baseStationId =
12690                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
12691                 cellInfoCdma.cellIdentityCdma.base.longitude =
12692                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
12693                 cellInfoCdma.cellIdentityCdma.base.latitude =
12694                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
12695                 cellInfoCdma.signalStrengthCdma.dbm =
12696                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
12697                 cellInfoCdma.signalStrengthCdma.ecio =
12698                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
12699                 cellInfoCdma.signalStrengthEvdo.dbm =
12700                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
12701                 cellInfoCdma.signalStrengthEvdo.ecio =
12702                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
12703                 cellInfoCdma.signalStrengthEvdo.signalNoiseRatio =
12704                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
12705                 records[i].ratSpecificInfo.cdma(cellInfoCdma);
12706                 break;
12707             }
12708 
12709             case RIL_CELL_INFO_TYPE_LTE: {
12710                 V1_6::CellInfoLte cellInfoLte;
12711                 cellInfoLte.cellIdentityLte.base.base.mcc =
12712                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
12713                 cellInfoLte.cellIdentityLte.base.base.mnc =
12714                         ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
12715                 cellInfoLte.cellIdentityLte.base.base.ci =
12716                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
12717                 cellInfoLte.cellIdentityLte.base.base.pci =
12718                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
12719                 cellInfoLte.cellIdentityLte.base.base.tac =
12720                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
12721                 cellInfoLte.cellIdentityLte.base.base.earfcn =
12722                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
12723                 cellInfoLte.cellIdentityLte.base.bandwidth = INT_MAX;
12724                 hidl_vec<V1_5::EutranBands> bands;
12725                 bands.resize(1);
12726                 bands[0] = V1_5::EutranBands::BAND_1;
12727                 cellInfoLte.cellIdentityLte.bands = bands;
12728                 cellInfoLte.signalStrengthLte.base.signalStrength =
12729                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
12730                 cellInfoLte.signalStrengthLte.base.rsrp =
12731                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
12732                 cellInfoLte.signalStrengthLte.base.rsrq =
12733                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
12734                 cellInfoLte.signalStrengthLte.base.rssnr =
12735                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
12736                 cellInfoLte.signalStrengthLte.base.cqi =
12737                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
12738                 cellInfoLte.signalStrengthLte.base.timingAdvance =
12739                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
12740                 records[i].ratSpecificInfo.lte(cellInfoLte);
12741                 break;
12742             }
12743 
12744             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
12745                 V1_5::CellInfoTdscdma cellInfoTdscdma;
12746                 cellInfoTdscdma.cellIdentityTdscdma.base.base.mcc =
12747                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
12748                 cellInfoTdscdma.cellIdentityTdscdma.base.base.mnc = ril::util::mnc::decode(
12749                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
12750                 cellInfoTdscdma.cellIdentityTdscdma.base.base.lac =
12751                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
12752                 cellInfoTdscdma.cellIdentityTdscdma.base.base.cid =
12753                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
12754                 cellInfoTdscdma.cellIdentityTdscdma.base.base.cpid =
12755                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
12756                 cellInfoTdscdma.signalStrengthTdscdma.rscp =
12757                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
12758                 records[i].ratSpecificInfo.tdscdma(cellInfoTdscdma);
12759                 break;
12760             }
12761 
12762             case RIL_CELL_INFO_TYPE_NR: {
12763                 V1_6::CellInfoNr cellInfoNr;
12764                 cellInfoNr.cellIdentityNr.base.mcc =
12765                         std::to_string(rillCellInfo->CellInfo.nr.cellidentity.mcc);
12766                 cellInfoNr.cellIdentityNr.base.mnc =
12767                         ril::util::mnc::decode(rillCellInfo->CellInfo.nr.cellidentity.mnc);
12768                 cellInfoNr.cellIdentityNr.base.nci = rillCellInfo->CellInfo.nr.cellidentity.nci;
12769                 cellInfoNr.cellIdentityNr.base.pci = rillCellInfo->CellInfo.nr.cellidentity.pci;
12770                 cellInfoNr.cellIdentityNr.base.tac = rillCellInfo->CellInfo.nr.cellidentity.tac;
12771                 cellInfoNr.cellIdentityNr.base.nrarfcn =
12772                         rillCellInfo->CellInfo.nr.cellidentity.nrarfcn;
12773                 cellInfoNr.cellIdentityNr.base.operatorNames.alphaLong = convertCharPtrToHidlString(
12774                         rillCellInfo->CellInfo.nr.cellidentity.operatorNames.alphaLong);
12775                 cellInfoNr.cellIdentityNr.base.operatorNames.alphaShort =
12776                         convertCharPtrToHidlString(
12777                                 rillCellInfo->CellInfo.nr.cellidentity.operatorNames.alphaShort);
12778 
12779                 cellInfoNr.signalStrengthNr.base.ssRsrp =
12780                         rillCellInfo->CellInfo.nr.signalStrength.ssRsrp;
12781                 cellInfoNr.signalStrengthNr.base.ssRsrq =
12782                         rillCellInfo->CellInfo.nr.signalStrength.ssRsrq;
12783                 cellInfoNr.signalStrengthNr.base.ssSinr =
12784                         rillCellInfo->CellInfo.nr.signalStrength.ssSinr;
12785                 cellInfoNr.signalStrengthNr.base.csiRsrp =
12786                         rillCellInfo->CellInfo.nr.signalStrength.csiRsrp;
12787                 cellInfoNr.signalStrengthNr.base.csiRsrq =
12788                         rillCellInfo->CellInfo.nr.signalStrength.csiRsrq;
12789                 cellInfoNr.signalStrengthNr.base.csiSinr =
12790                         rillCellInfo->CellInfo.nr.signalStrength.csiSinr;
12791                 records[i].ratSpecificInfo.nr(cellInfoNr);
12792                 break;
12793             }
12794             default: {
12795                 break;
12796             }
12797         }
12798         rillCellInfo += 1;
12799     }
12800 }
12801 
cellInfoListInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12802 int radio_1_6::cellInfoListInd(int slotId,
12803                            int indicationType, int token, RIL_Errno e, void *response,
12804                            size_t responseLen) {
12805     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12806         if ((response == NULL && responseLen != 0) || responseLen % sizeof(RIL_CellInfo_v12) != 0) {
12807             RLOGE("cellInfoListInd: invalid response");
12808             return 0;
12809         }
12810 
12811         hidl_vec<CellInfo> records;
12812         convertRilCellInfoListToHal(response, responseLen, records);
12813 
12814 #if VDBG
12815         RLOGD("cellInfoListInd");
12816 #endif
12817         Return<void> retStatus = radioService[slotId]->mRadioIndication->cellInfoList(
12818                 convertIntToRadioIndicationType(indicationType), records);
12819         radioService[slotId]->checkReturnStatus(retStatus);
12820     } else {
12821         RLOGE("cellInfoListInd: radioService[%d]->mRadioIndication == NULL", slotId);
12822     }
12823 
12824     return 0;
12825 }
12826 
imsNetworkStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12827 int radio_1_6::imsNetworkStateChangedInd(int slotId,
12828                                      int indicationType, int token, RIL_Errno e, void *response,
12829                                      size_t responseLen) {
12830     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12831 #if VDBG
12832         RLOGD("imsNetworkStateChangedInd");
12833 #endif
12834         Return<void> retStatus = radioService[slotId]->mRadioIndication->imsNetworkStateChanged(
12835                 convertIntToRadioIndicationType(indicationType));
12836         radioService[slotId]->checkReturnStatus(retStatus);
12837     } else {
12838         RLOGE("imsNetworkStateChangedInd: radioService[%d]->mRadioIndication == NULL",
12839                 slotId);
12840     }
12841 
12842     return 0;
12843 }
12844 
subscriptionStatusChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12845 int radio_1_6::subscriptionStatusChangedInd(int slotId,
12846                                         int indicationType, int token, RIL_Errno e, void *response,
12847                                         size_t responseLen) {
12848     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12849         if (response == NULL || responseLen != sizeof(int)) {
12850             RLOGE("subscriptionStatusChangedInd: invalid response");
12851             return 0;
12852         }
12853         bool activate = ((int32_t *) response)[0];
12854 #if VDBG
12855         RLOGD("subscriptionStatusChangedInd: activate %d", activate);
12856 #endif
12857         Return<void> retStatus = radioService[slotId]->mRadioIndication->subscriptionStatusChanged(
12858                 convertIntToRadioIndicationType(indicationType), activate);
12859         radioService[slotId]->checkReturnStatus(retStatus);
12860     } else {
12861         RLOGE("subscriptionStatusChangedInd: radioService[%d]->mRadioIndication == NULL",
12862                 slotId);
12863     }
12864 
12865     return 0;
12866 }
12867 
srvccStateNotifyInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12868 int radio_1_6::srvccStateNotifyInd(int slotId,
12869                                int indicationType, int token, RIL_Errno e, void *response,
12870                                size_t responseLen) {
12871     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12872         if (response == NULL || responseLen != sizeof(int)) {
12873             RLOGE("srvccStateNotifyInd: invalid response");
12874             return 0;
12875         }
12876         int32_t state = ((int32_t *) response)[0];
12877 #if VDBG
12878         RLOGD("srvccStateNotifyInd: rat %d", state);
12879 #endif
12880         Return<void> retStatus = radioService[slotId]->mRadioIndication->srvccStateNotify(
12881                 convertIntToRadioIndicationType(indicationType), (SrvccState) state);
12882         radioService[slotId]->checkReturnStatus(retStatus);
12883     } else {
12884         RLOGE("srvccStateNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
12885     }
12886 
12887     return 0;
12888 }
12889 
convertRilHardwareConfigListToHal(void * response,size_t responseLen,hidl_vec<HardwareConfig> & records)12890 void convertRilHardwareConfigListToHal(void *response, size_t responseLen,
12891         hidl_vec<HardwareConfig>& records) {
12892     int num = responseLen / sizeof(RIL_HardwareConfig);
12893     records.resize(num);
12894 
12895     RIL_HardwareConfig *rilHardwareConfig = (RIL_HardwareConfig *) response;
12896     for (int i = 0; i < num; i++) {
12897         records[i].type = (HardwareConfigType) rilHardwareConfig[i].type;
12898         records[i].uuid = convertCharPtrToHidlString(rilHardwareConfig[i].uuid);
12899         records[i].state = (HardwareConfigState) rilHardwareConfig[i].state;
12900         switch (rilHardwareConfig[i].type) {
12901             case RIL_HARDWARE_CONFIG_MODEM: {
12902                 records[i].modem.resize(1);
12903                 records[i].sim.resize(0);
12904                 HardwareConfigModem *hwConfigModem = &records[i].modem[0];
12905                 hwConfigModem->rat = rilHardwareConfig[i].cfg.modem.rat;
12906                 hwConfigModem->maxVoice = rilHardwareConfig[i].cfg.modem.maxVoice;
12907                 hwConfigModem->maxData = rilHardwareConfig[i].cfg.modem.maxData;
12908                 hwConfigModem->maxStandby = rilHardwareConfig[i].cfg.modem.maxStandby;
12909                 break;
12910             }
12911 
12912             case RIL_HARDWARE_CONFIG_SIM: {
12913                 records[i].sim.resize(1);
12914                 records[i].modem.resize(0);
12915                 records[i].sim[0].modemUuid =
12916                         convertCharPtrToHidlString(rilHardwareConfig[i].cfg.sim.modemUuid);
12917                 break;
12918             }
12919         }
12920     }
12921 }
12922 
hardwareConfigChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12923 int radio_1_6::hardwareConfigChangedInd(int slotId,
12924                                     int indicationType, int token, RIL_Errno e, void *response,
12925                                     size_t responseLen) {
12926     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12927         if ((response == NULL && responseLen != 0)
12928                 || responseLen % sizeof(RIL_HardwareConfig) != 0) {
12929             RLOGE("hardwareConfigChangedInd: invalid response");
12930             return 0;
12931         }
12932 
12933         hidl_vec<HardwareConfig> configs;
12934         convertRilHardwareConfigListToHal(response, responseLen, configs);
12935 
12936 #if VDBG
12937         RLOGD("hardwareConfigChangedInd");
12938 #endif
12939         Return<void> retStatus = radioService[slotId]->mRadioIndication->hardwareConfigChanged(
12940                 convertIntToRadioIndicationType(indicationType), configs);
12941         radioService[slotId]->checkReturnStatus(retStatus);
12942     } else {
12943         RLOGE("hardwareConfigChangedInd: radioService[%d]->mRadioIndication == NULL",
12944                 slotId);
12945     }
12946 
12947     return 0;
12948 }
12949 
convertRilRadioCapabilityToHal(void * response,size_t responseLen,RadioCapability & rc)12950 void convertRilRadioCapabilityToHal(void *response, size_t responseLen, RadioCapability& rc) {
12951     RIL_RadioCapability *rilRadioCapability = (RIL_RadioCapability *) response;
12952     rc.session = rilRadioCapability->session;
12953     rc.phase = (V1_0::RadioCapabilityPhase) rilRadioCapability->phase;
12954     rc.raf = rilRadioCapability->rat;
12955     rc.logicalModemUuid = convertCharPtrToHidlString(rilRadioCapability->logicalModemUuid);
12956     rc.status = (V1_0::RadioCapabilityStatus) rilRadioCapability->status;
12957 }
12958 
radioCapabilityIndicationInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12959 int radio_1_6::radioCapabilityIndicationInd(int slotId,
12960                                         int indicationType, int token, RIL_Errno e, void *response,
12961                                         size_t responseLen) {
12962     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12963         if (response == NULL || responseLen != sizeof(RIL_RadioCapability)) {
12964             RLOGE("radioCapabilityIndicationInd: invalid response");
12965             return 0;
12966         }
12967 
12968         RadioCapability rc = {};
12969         convertRilRadioCapabilityToHal(response, responseLen, rc);
12970 
12971 #if VDBG
12972         RLOGD("radioCapabilityIndicationInd");
12973 #endif
12974         Return<void> retStatus = radioService[slotId]->mRadioIndication->radioCapabilityIndication(
12975                 convertIntToRadioIndicationType(indicationType), rc);
12976         radioService[slotId]->checkReturnStatus(retStatus);
12977     } else {
12978         RLOGE("radioCapabilityIndicationInd: radioService[%d]->mRadioIndication == NULL",
12979                 slotId);
12980     }
12981 
12982     return 0;
12983 }
12984 
isServiceTypeCfQuery(RIL_SsServiceType serType,RIL_SsRequestType reqType)12985 bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
12986     if ((reqType == SS_INTERROGATION) &&
12987         (serType == SS_CFU ||
12988          serType == SS_CF_BUSY ||
12989          serType == SS_CF_NO_REPLY ||
12990          serType == SS_CF_NOT_REACHABLE ||
12991          serType == SS_CF_ALL ||
12992          serType == SS_CF_ALL_CONDITIONAL)) {
12993         return true;
12994     }
12995     return false;
12996 }
12997 
onSupplementaryServiceIndicationInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12998 int radio_1_6::onSupplementaryServiceIndicationInd(int slotId,
12999                                                int indicationType, int token, RIL_Errno e,
13000                                                void *response, size_t responseLen) {
13001     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
13002         if (response == NULL || responseLen != sizeof(RIL_StkCcUnsolSsResponse)) {
13003             RLOGE("onSupplementaryServiceIndicationInd: invalid response");
13004             return 0;
13005         }
13006 
13007         RIL_StkCcUnsolSsResponse *rilSsResponse = (RIL_StkCcUnsolSsResponse *) response;
13008         StkCcUnsolSsResult ss = {};
13009         ss.serviceType = (SsServiceType) rilSsResponse->serviceType;
13010         ss.requestType = (SsRequestType) rilSsResponse->requestType;
13011         ss.teleserviceType = (SsTeleserviceType) rilSsResponse->teleserviceType;
13012         ss.serviceClass = rilSsResponse->serviceClass;
13013         ss.result = (RadioError) rilSsResponse->result;
13014 
13015         if (isServiceTypeCfQuery(rilSsResponse->serviceType, rilSsResponse->requestType)) {
13016 #if VDBG
13017             RLOGD("onSupplementaryServiceIndicationInd CF type, num of Cf elements %d",
13018                     rilSsResponse->cfData.numValidIndexes);
13019 #endif
13020             if (rilSsResponse->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
13021                 RLOGE("onSupplementaryServiceIndicationInd numValidIndexes is greater than "
13022                         "max value %d, truncating it to max value", NUM_SERVICE_CLASSES);
13023                 rilSsResponse->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
13024             }
13025 
13026             ss.cfData.resize(1);
13027             ss.ssInfo.resize(0);
13028 
13029             /* number of call info's */
13030             ss.cfData[0].cfInfo.resize(rilSsResponse->cfData.numValidIndexes);
13031 
13032             for (int i = 0; i < rilSsResponse->cfData.numValidIndexes; i++) {
13033                  RIL_CallForwardInfo cf = rilSsResponse->cfData.cfInfo[i];
13034                  CallForwardInfo *cfInfo = &ss.cfData[0].cfInfo[i];
13035 
13036                  cfInfo->status = (CallForwardInfoStatus) cf.status;
13037                  cfInfo->reason = cf.reason;
13038                  cfInfo->serviceClass = cf.serviceClass;
13039                  cfInfo->toa = cf.toa;
13040                  cfInfo->number = convertCharPtrToHidlString(cf.number);
13041                  cfInfo->timeSeconds = cf.timeSeconds;
13042 #if VDBG
13043                  RLOGD("onSupplementaryServiceIndicationInd: "
13044                         "Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
13045                         cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
13046 #endif
13047             }
13048         } else {
13049             ss.ssInfo.resize(1);
13050             ss.cfData.resize(0);
13051 
13052             /* each int */
13053             ss.ssInfo[0].ssInfo.resize(SS_INFO_MAX);
13054             for (int i = 0; i < SS_INFO_MAX; i++) {
13055 #if VDBG
13056                  RLOGD("onSupplementaryServiceIndicationInd: Data: %d",
13057                         rilSsResponse->ssInfo[i]);
13058 #endif
13059                  ss.ssInfo[0].ssInfo[i] = rilSsResponse->ssInfo[i];
13060             }
13061         }
13062 
13063 #if VDBG
13064         RLOGD("onSupplementaryServiceIndicationInd");
13065 #endif
13066         Return<void> retStatus = radioService[slotId]->mRadioIndication->
13067                 onSupplementaryServiceIndication(convertIntToRadioIndicationType(indicationType),
13068                 ss);
13069         radioService[slotId]->checkReturnStatus(retStatus);
13070     } else {
13071         RLOGE("onSupplementaryServiceIndicationInd: "
13072                 "radioService[%d]->mRadioIndication == NULL", slotId);
13073     }
13074 
13075     return 0;
13076 }
13077 
stkCallControlAlphaNotifyInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13078 int radio_1_6::stkCallControlAlphaNotifyInd(int slotId,
13079                                         int indicationType, int token, RIL_Errno e, void *response,
13080                                         size_t responseLen) {
13081     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
13082         if (response == NULL || responseLen == 0) {
13083             RLOGE("stkCallControlAlphaNotifyInd: invalid response");
13084             return 0;
13085         }
13086 #if VDBG
13087         RLOGD("stkCallControlAlphaNotifyInd");
13088 #endif
13089         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkCallControlAlphaNotify(
13090                 convertIntToRadioIndicationType(indicationType),
13091                 convertCharPtrToHidlString((char *) response));
13092         radioService[slotId]->checkReturnStatus(retStatus);
13093     } else {
13094         RLOGE("stkCallControlAlphaNotifyInd: radioService[%d]->mRadioIndication == NULL",
13095                 slotId);
13096     }
13097 
13098     return 0;
13099 }
13100 
convertRilLceDataInfoToHal(void * response,size_t responseLen,LceDataInfo & lce)13101 void convertRilLceDataInfoToHal(void *response, size_t responseLen, LceDataInfo& lce) {
13102     RIL_LceDataInfo *rilLceDataInfo = (RIL_LceDataInfo *)response;
13103     lce.lastHopCapacityKbps = rilLceDataInfo->last_hop_capacity_kbps;
13104     lce.confidenceLevel = rilLceDataInfo->confidence_level;
13105     lce.lceSuspended = rilLceDataInfo->lce_suspended;
13106 }
13107 
lceDataInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13108 int radio_1_6::lceDataInd(int slotId,
13109                       int indicationType, int token, RIL_Errno e, void *response,
13110                       size_t responseLen) {
13111     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
13112         if (response == NULL || responseLen != sizeof(RIL_LceDataInfo)) {
13113             RLOGE("lceDataInd: invalid response");
13114             return 0;
13115         }
13116 
13117         LceDataInfo lce = {};
13118         convertRilLceDataInfoToHal(response, responseLen, lce);
13119 #if VDBG
13120         RLOGD("lceDataInd");
13121 #endif
13122         Return<void> retStatus = radioService[slotId]->mRadioIndication->lceData(
13123                 convertIntToRadioIndicationType(indicationType), lce);
13124         radioService[slotId]->checkReturnStatus(retStatus);
13125     } else {
13126         RLOGE("lceDataInd: radioService[%d]->mRadioIndication == NULL", slotId);
13127     }
13128 
13129     return 0;
13130 }
13131 
pcoDataInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13132 int radio_1_6::pcoDataInd(int slotId,
13133                       int indicationType, int token, RIL_Errno e, void *response,
13134                       size_t responseLen) {
13135     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
13136         if (response == NULL || responseLen != sizeof(RIL_PCO_Data)) {
13137             RLOGE("pcoDataInd: invalid response");
13138             return 0;
13139         }
13140 
13141         PcoDataInfo pco = {};
13142         RIL_PCO_Data *rilPcoData = (RIL_PCO_Data *)response;
13143         pco.cid = rilPcoData->cid;
13144         pco.bearerProto = convertCharPtrToHidlString(rilPcoData->bearer_proto);
13145         pco.pcoId = rilPcoData->pco_id;
13146         pco.contents.setToExternal((uint8_t *) rilPcoData->contents, rilPcoData->contents_length);
13147 
13148 #if VDBG
13149         RLOGD("pcoDataInd");
13150 #endif
13151         Return<void> retStatus = radioService[slotId]->mRadioIndication->pcoData(
13152                 convertIntToRadioIndicationType(indicationType), pco);
13153         radioService[slotId]->checkReturnStatus(retStatus);
13154     } else {
13155         RLOGE("pcoDataInd: radioService[%d]->mRadioIndication == NULL", slotId);
13156     }
13157 
13158     return 0;
13159 }
13160 
modemResetInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13161 int radio_1_6::modemResetInd(int slotId,
13162                          int indicationType, int token, RIL_Errno e, void *response,
13163                          size_t responseLen) {
13164     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
13165         if (response == NULL || responseLen == 0) {
13166             RLOGE("modemResetInd: invalid response");
13167             return 0;
13168         }
13169 #if VDBG
13170         RLOGD("modemResetInd");
13171 #endif
13172         Return<void> retStatus = radioService[slotId]->mRadioIndication->modemReset(
13173                 convertIntToRadioIndicationType(indicationType),
13174                 convertCharPtrToHidlString((char *) response));
13175         radioService[slotId]->checkReturnStatus(retStatus);
13176     } else {
13177         RLOGE("modemResetInd: radioService[%d]->mRadioIndication == NULL", slotId);
13178     }
13179 
13180     return 0;
13181 }
13182 
networkScanResultInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13183 int radio_1_6::networkScanResultInd(int slotId, int indicationType, int token, RIL_Errno e,
13184                                     void* response, size_t responseLen) {
13185 #if VDBG
13186     RLOGD("networkScanResultInd");
13187 #endif
13188     if (radioService[slotId] != NULL && (radioService[slotId]->mRadioIndicationV1_6 != NULL ||
13189                                          radioService[slotId]->mRadioIndicationV1_5 != NULL ||
13190                                          radioService[slotId]->mRadioIndicationV1_4 != NULL ||
13191                                          radioService[slotId]->mRadioIndicationV1_2 != NULL ||
13192                                          radioService[slotId]->mRadioIndicationV1_1 != NULL)) {
13193         if (response == NULL || responseLen == 0) {
13194             RLOGE("networkScanResultInd: invalid response");
13195             return 0;
13196         }
13197         RLOGD("networkScanResultInd");
13198 
13199         RIL_NetworkScanResult *networkScanResult = (RIL_NetworkScanResult *) response;
13200         Return<void> retStatus;
13201         if (radioService[slotId]->mRadioIndicationV1_6 != NULL) {
13202             V1_6::NetworkScanResult result;
13203             result.status = (V1_1::ScanStatus)networkScanResult->status;
13204             result.error = (V1_6::RadioError)networkScanResult->error;
13205             convertRilCellInfoListToHal_1_6(
13206                     networkScanResult->network_infos,
13207                     networkScanResult->network_infos_length * sizeof(RIL_CellInfo_v16),
13208                     result.networkInfos);
13209             retStatus = radioService[slotId]->mRadioIndicationV1_6->networkScanResult_1_6(
13210                     convertIntToRadioIndicationType(indicationType), result);
13211         } else if (radioService[slotId]->mRadioIndicationV1_5 != NULL) {
13212             V1_5::NetworkScanResult result;
13213             result.status = (V1_1::ScanStatus)networkScanResult->status;
13214             result.error = (RadioError)networkScanResult->error;
13215             convertRilCellInfoListToHal_1_5(
13216                     networkScanResult->network_infos,
13217                     networkScanResult->network_infos_length * sizeof(RIL_CellInfo_v12),
13218                     result.networkInfos);
13219             retStatus = radioService[slotId]->mRadioIndicationV1_5->networkScanResult_1_5(
13220                     convertIntToRadioIndicationType(indicationType), result);
13221         } else if (radioService[slotId]->mRadioIndicationV1_4 != NULL) {
13222             V1_4::NetworkScanResult result;
13223             result.status = (V1_1::ScanStatus)networkScanResult->status;
13224             result.error = (RadioError)networkScanResult->error;
13225             convertRilCellInfoListToHal_1_4(
13226                     networkScanResult->network_infos,
13227                     networkScanResult->network_infos_length * sizeof(RIL_CellInfo_v12),
13228                     result.networkInfos);
13229             retStatus = radioService[slotId]->mRadioIndicationV1_4->networkScanResult_1_4(
13230                     convertIntToRadioIndicationType(indicationType), result);
13231         } else if (radioService[slotId]->mRadioIndicationV1_2 != NULL) {
13232             V1_2::NetworkScanResult result;
13233             result.status = (V1_1::ScanStatus)networkScanResult->status;
13234             result.error = (RadioError)networkScanResult->error;
13235             convertRilCellInfoListToHal_1_2(
13236                     networkScanResult->network_infos,
13237                     networkScanResult->network_infos_length * sizeof(RIL_CellInfo_v12),
13238                     result.networkInfos);
13239             retStatus = radioService[slotId]->mRadioIndicationV1_2->networkScanResult_1_2(
13240                     convertIntToRadioIndicationType(indicationType), result);
13241         } else {
13242             V1_1::NetworkScanResult result;
13243             result.status = (V1_1::ScanStatus)networkScanResult->status;
13244             result.error = (RadioError)networkScanResult->error;
13245             convertRilCellInfoListToHal(
13246                     networkScanResult->network_infos,
13247                     networkScanResult->network_infos_length * sizeof(RIL_CellInfo),
13248                     result.networkInfos);
13249             retStatus = radioService[slotId]->mRadioIndicationV1_1->networkScanResult(
13250                     convertIntToRadioIndicationType(indicationType), result);
13251         }
13252         radioService[slotId]->checkReturnStatus(retStatus);
13253     } else {
13254         RLOGE("networkScanResultInd: radioService[%d]->mRadioIndication == NULL", slotId);
13255     }
13256     return 0;
13257 }
13258 
carrierInfoForImsiEncryption(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13259 int radio_1_6::carrierInfoForImsiEncryption(int slotId, int indicationType, int token, RIL_Errno e,
13260                                             void* response, size_t responseLen) {
13261     if (radioService[slotId] != NULL && (radioService[slotId]->mRadioIndicationV1_2 != NULL)) {
13262         if (response == NULL || responseLen == 0) {
13263             RLOGE("carrierInfoForImsiEncryption: invalid response");
13264             return 0;
13265         }
13266         RLOGD("carrierInfoForImsiEncryption");
13267         Return<void> retStatus =
13268                 radioService[slotId]->mRadioIndicationV1_2->carrierInfoForImsiEncryption(
13269                         convertIntToRadioIndicationType(indicationType));
13270         radioService[slotId]->checkReturnStatus(retStatus);
13271     } else {
13272         RLOGE("carrierInfoForImsiEncryption: radioService[%d]->mRadioIndication == NULL", slotId);
13273     }
13274 
13275     return 0;
13276 }
13277 
reportPhysicalChannelConfigs(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13278 int radio_1_6::reportPhysicalChannelConfigs(int slotId, int indicationType, int token, RIL_Errno e,
13279                                             void* response, size_t responseLen) {
13280     if (radioService[slotId] != NULL && (radioService[slotId]->mRadioIndicationV1_6 != NULL ||
13281                                          radioService[slotId]->mRadioIndicationV1_4 != NULL ||
13282                                          radioService[slotId]->mRadioIndicationV1_2 != NULL)) {
13283         int* configs = (int*)response;
13284         if (radioService[slotId]->mRadioIndicationV1_6 != NULL) {
13285             hidl_vec<V1_6::PhysicalChannelConfig> physChanConfig;
13286             physChanConfig.resize(1);
13287             physChanConfig[0].status = (V1_2::CellConnectionStatus)configs[0];
13288             physChanConfig[0].cellBandwidthDownlinkKhz = configs[1];
13289             physChanConfig[0].rat = (V1_4::RadioTechnology)configs[2];
13290             physChanConfig[0].contextIds.resize(1);
13291             physChanConfig[0].contextIds[0] = configs[4];
13292             RLOGD("reportPhysicalChannelConfigs_1_6: %d %d %d %d %d", configs[0], configs[1],
13293                   configs[2], configs[3], configs[4]);
13294             Return<void> retStatus =
13295                     radioService[slotId]->mRadioIndicationV1_6->currentPhysicalChannelConfigs_1_6(
13296                             RadioIndicationType::UNSOLICITED, physChanConfig);
13297             radioService[slotId]->checkReturnStatus(retStatus);
13298             // checkReturnStatus() call might set mRadioIndicationV1_6 to NULL
13299             if (radioService[slotId]->mRadioIndicationV1_6 != NULL) {
13300                 // Just send the link estimate along with physical channel config, as it has
13301                 // at least the downlink bandwidth.
13302                 // Note: the bandwidth is just some hardcoded value, as there is not way to get
13303                 // that reliably on virtual devices, as of now.
13304                 V1_6::LinkCapacityEstimate lce = {
13305                         .downlinkCapacityKbps = static_cast<uint32_t>(configs[1]),
13306                         .uplinkCapacityKbps = static_cast<uint32_t>(configs[1])};
13307                 RLOGD("reporting link capacity estimate download: %d upload: %d",
13308                       lce.downlinkCapacityKbps, lce.uplinkCapacityKbps);
13309                 Return<void> retStatus =
13310                         radioService[slotId]->mRadioIndicationV1_6->currentLinkCapacityEstimate_1_6(
13311                                 RadioIndicationType::UNSOLICITED, lce);
13312                 radioService[slotId]->checkReturnStatus(retStatus);
13313             }
13314         } else if (radioService[slotId]->mRadioIndicationV1_4 != NULL) {
13315             hidl_vec<PhysicalChannelConfigV1_4> physChanConfig;
13316             physChanConfig.resize(1);
13317             physChanConfig[0].base.status = (V1_2::CellConnectionStatus)configs[0];
13318             physChanConfig[0].base.cellBandwidthDownlink = configs[1];
13319             physChanConfig[0].rat = (V1_4::RadioTechnology)configs[2];
13320             physChanConfig[0].rfInfo.range((V1_4::FrequencyRange)configs[3]);
13321             physChanConfig[0].contextIds.resize(1);
13322             physChanConfig[0].contextIds[0] = configs[4];
13323             RLOGD("reportPhysicalChannelConfigs_1_4: %d %d %d %d %d", configs[0], configs[1],
13324                   configs[2], configs[3], configs[4]);
13325             Return<void> retStatus =
13326                     radioService[slotId]->mRadioIndicationV1_4->currentPhysicalChannelConfigs_1_4(
13327                             RadioIndicationType::UNSOLICITED, physChanConfig);
13328             radioService[slotId]->checkReturnStatus(retStatus);
13329             // checkReturnStatus() call might set mRadioIndicationV1_4 to NULL
13330             if (radioService[slotId]->mRadioIndicationV1_4 != NULL) {
13331                 // Just send the link estimate along with physical channel config, as it has
13332                 // at least the downlink bandwidth.
13333                 // Note: the bandwidth is just some hardcoded value, as there is not way to get
13334                 // that reliably on virtual devices, as of now.
13335                 V1_2::LinkCapacityEstimate lce = {
13336                         .downlinkCapacityKbps = static_cast<uint32_t>(configs[1]),
13337                         .uplinkCapacityKbps = static_cast<uint32_t>(configs[1])};
13338                 RLOGD("reporting link capacity estimate download: %d upload: %d",
13339                       lce.downlinkCapacityKbps, lce.uplinkCapacityKbps);
13340                 Return<void> retStatus =
13341                         radioService[slotId]->mRadioIndicationV1_4->currentLinkCapacityEstimate(
13342                                 RadioIndicationType::UNSOLICITED, lce);
13343                 radioService[slotId]->checkReturnStatus(retStatus);
13344             }
13345         } else if (radioService[slotId]->mRadioIndicationV1_2 != NULL) {
13346             hidl_vec<V1_2::PhysicalChannelConfig> physChanConfig;
13347             physChanConfig.resize(1);
13348             physChanConfig[0].status = (V1_2::CellConnectionStatus)configs[0];
13349             physChanConfig[0].cellBandwidthDownlink = configs[1];
13350             RLOGD("reportPhysicalChannelConfigs_1_2: %d %d", configs[0], configs[1]);
13351             Return<void> retStatus =
13352                     radioService[slotId]->mRadioIndicationV1_2->currentPhysicalChannelConfigs(
13353                             RadioIndicationType::UNSOLICITED, physChanConfig);
13354             radioService[slotId]->checkReturnStatus(retStatus);
13355             // checkReturnStatus() call might set mRadioIndicationV1_2 to NULL
13356             if (radioService[slotId]->mRadioIndicationV1_2 != NULL) {
13357                 // Just send the link estimate along with physical channel config, as it has
13358                 // at least the downlink bandwidth.
13359                 // Note: the bandwidth is just some hardcoded value, as there is not way to get
13360                 // that reliably on virtual devices, as of now.
13361                 V1_2::LinkCapacityEstimate lce = {
13362                         .downlinkCapacityKbps = static_cast<uint32_t>(configs[1]),
13363                         .uplinkCapacityKbps = static_cast<uint32_t>(configs[1])};
13364                 RLOGD("reporting link capacity estimate download: %d upload: %d",
13365                       lce.downlinkCapacityKbps, lce.uplinkCapacityKbps);
13366                 Return<void> retStatus =
13367                         radioService[slotId]->mRadioIndicationV1_2->currentLinkCapacityEstimate(
13368                                 RadioIndicationType::UNSOLICITED, lce);
13369                 radioService[slotId]->checkReturnStatus(retStatus);
13370             }
13371         }
13372     } else {
13373         RLOGE("reportPhysicalChannelConfigs: radioService[%d]->mRadioIndication == NULL", slotId);
13374         return -1;
13375     }
13376     return 0;
13377 }
13378 
keepaliveStatusInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13379 int radio_1_6::keepaliveStatusInd(int slotId,
13380                          int indicationType, int token, RIL_Errno e, void *response,
13381                          size_t responseLen) {
13382 #if VDBG
13383     RLOGD("%s(): token=%d", __FUNCTION__, token);
13384 #endif
13385     if (radioService[slotId] == NULL || radioService[slotId]->mRadioIndication == NULL) {
13386         RLOGE("%s: radioService[%d]->mRadioIndication == NULL", __FUNCTION__, slotId);
13387         return 0;
13388     }
13389 
13390     auto ret = V1_1::IRadioIndication::castFrom(
13391         radioService[slotId]->mRadioIndication);
13392     if (!ret.isOk()) {
13393         RLOGE("%s: ret.isOk() == false for radioService[%d]", __FUNCTION__, slotId);
13394         return 0;
13395     }
13396     sp<V1_1::IRadioIndication> radioIndicationV1_1 = ret;
13397 
13398     if (response == NULL || responseLen != sizeof(V1_1::KeepaliveStatus)) {
13399         RLOGE("%s: invalid response", __FUNCTION__);
13400         return 0;
13401     }
13402 
13403     V1_1::KeepaliveStatus ks;
13404     convertRilKeepaliveStatusToHal(static_cast<RIL_KeepaliveStatus*>(response), ks);
13405 
13406     Return<void> retStatus = radioIndicationV1_1->keepaliveStatus(
13407             convertIntToRadioIndicationType(indicationType), ks);
13408     radioService[slotId]->checkReturnStatus(retStatus);
13409     return 0;
13410 }
13411 
oemHookRawInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)13412 int radio_1_6::oemHookRawInd(int slotId,
13413                          int indicationType, int token, RIL_Errno e, void *response,
13414                          size_t responseLen) {
13415     if (!kOemHookEnabled) return 0;
13416 
13417     if (oemHookService[slotId] != NULL && oemHookService[slotId]->mOemHookIndication != NULL) {
13418         if (response == NULL || responseLen == 0) {
13419             RLOGE("oemHookRawInd: invalid response");
13420             return 0;
13421         }
13422 
13423         hidl_vec<uint8_t> data;
13424         data.setToExternal((uint8_t *) response, responseLen);
13425 #if VDBG
13426         RLOGD("oemHookRawInd");
13427 #endif
13428         Return<void> retStatus = oemHookService[slotId]->mOemHookIndication->oemHookRaw(
13429                 convertIntToRadioIndicationType(indicationType), data);
13430         checkReturnStatus(slotId, retStatus, false);
13431     } else {
13432         RLOGE("oemHookRawInd: oemHookService[%d]->mOemHookIndication == NULL", slotId);
13433     }
13434 
13435     return 0;
13436 }
13437 
13438 template <typename T>
publishRadioHal(std::shared_ptr<compat::DriverContext> ctx,sp<V1_5::IRadio> hidlHal,std::shared_ptr<compat::CallbackManager> cm,const std::string & slot)13439 static void publishRadioHal(std::shared_ptr<compat::DriverContext> ctx, sp<V1_5::IRadio> hidlHal,
13440                             std::shared_ptr<compat::CallbackManager> cm, const std::string& slot) {
13441     static std::vector<std::shared_ptr<ndk::ICInterface>> gPublishedHals;
13442 
13443     const auto instance = T::descriptor + "/"s + slot;
13444     RLOGD("Publishing %s", instance.c_str());
13445 
13446     if (!AServiceManager_isDeclared(instance.c_str())) {
13447         RLOGW("%s is not declared in VINTF (this may be intentional on `next` when interface is "
13448               "not frozen)",
13449               instance.c_str());
13450         return;
13451     }
13452 
13453     auto aidlHal = ndk::SharedRefBase::make<T>(ctx, hidlHal, cm);
13454     gPublishedHals.push_back(aidlHal);
13455     const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
13456     CHECK_EQ(status, STATUS_OK);
13457 }
13458 
registerService(RIL_RadioFunctions * callbacks,CommandInfo * commands)13459 void radio_1_6::registerService(RIL_RadioFunctions *callbacks, CommandInfo *commands) {
13460     using namespace android::hardware;
13461     int simCount = 1;
13462     const char *serviceNames[] = {
13463             android::RIL_getServiceName()
13464             #if (SIM_COUNT >= 2)
13465             , RIL2_SERVICE_NAME
13466             #if (SIM_COUNT >= 3)
13467             , RIL3_SERVICE_NAME
13468             #if (SIM_COUNT >= 4)
13469             , RIL4_SERVICE_NAME
13470             #endif
13471             #endif
13472             #endif
13473             };
13474 
13475     #if (SIM_COUNT >= 2)
13476     simCount = SIM_COUNT;
13477     #endif
13478 
13479     s_vendorFunctions = callbacks;
13480     s_commands = commands;
13481 
13482     for (int i = 0; i < simCount; i++) {
13483         pthread_rwlock_t *radioServiceRwlockPtr = getRadioServiceRwlock(i);
13484         int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
13485         CHECK_EQ(ret, 0);
13486 
13487         RLOGD("sim i = %d registering ...", i);
13488 
13489         radioService[i] = new RadioImpl_1_6;
13490         radioService[i]->mSlotId = i;
13491         RLOGD("registerService: initializing power state to POWER_UP");
13492         radioService[i]->mSimCardPowerState = V1_1::CardPowerState::POWER_UP;
13493         RLOGD("registerService: starting android::hardware::radio::V1_6::IRadio %s for slot %d",
13494                 serviceNames[i], i);
13495 
13496         // use a compat shim to convert HIDL interface to AIDL and publish it
13497         // TODO(bug 220004469): replace with a full AIDL implementation
13498         auto radioHidl = radioService[i];
13499         const auto slot = serviceNames[i];
13500         auto context = std::make_shared<compat::DriverContext>();
13501         auto callbackMgr = std::make_shared<compat::CallbackManager>(context, radioHidl);
13502         radioService[i]->mCallbackManager = callbackMgr;
13503         publishRadioHal<compat::RadioData>(context, radioHidl, callbackMgr, slot);
13504         publishRadioHal<compat::RadioMessaging>(context, radioHidl, callbackMgr, slot);
13505         publishRadioHal<compat::RadioModem>(context, radioHidl, callbackMgr, slot);
13506         publishRadioHal<cf::ril::RefRadioNetwork>(context, radioHidl, callbackMgr, slot);
13507         publishRadioHal<compat::RadioSim>(context, radioHidl, callbackMgr, slot);
13508         publishRadioHal<compat::RadioVoice>(context, radioHidl, callbackMgr, slot);
13509         publishRadioHal<cf::ril::RefRadioIms>(context, radioHidl, callbackMgr, slot);
13510         publishRadioHal<cf::ril::RefImsMedia>(context, radioHidl, callbackMgr,
13511                                               std::string("default"));
13512         publishRadioHal<cf::ril::RefRadioModem>(context, radioHidl, callbackMgr, slot);
13513         publishRadioHal<cf::ril::RefRadioSim>(context, radioHidl, callbackMgr, slot);
13514 
13515         RLOGD("registerService: OemHook is enabled = %s", kOemHookEnabled ? "true" : "false");
13516         if (kOemHookEnabled) {
13517             oemHookService[i] = new OemHookImpl;
13518             oemHookService[i]->mSlotId = i;
13519             // status = oemHookService[i]->registerAsService(serviceNames[i]);
13520         }
13521         ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
13522         CHECK_EQ(ret, 0);
13523     }
13524 }
13525 
rilc_thread_pool()13526 void rilc_thread_pool() {
13527     ABinderProcess_joinThreadPool();
13528 }
13529 
getRadioServiceRwlock(int slotId)13530 pthread_rwlock_t * radio_1_6::getRadioServiceRwlock(int slotId) {
13531     pthread_rwlock_t *radioServiceRwlockPtr = &radioServiceRwlock;
13532 
13533     #if (SIM_COUNT >= 2)
13534     if (slotId == 2) radioServiceRwlockPtr = &radioServiceRwlock2;
13535     #if (SIM_COUNT >= 3)
13536     if (slotId == 3) radioServiceRwlockPtr = &radioServiceRwlock3;
13537     #if (SIM_COUNT >= 4)
13538     if (slotId == 4) radioServiceRwlockPtr = &radioServiceRwlock4;
13539     #endif
13540     #endif
13541     #endif
13542 
13543     return radioServiceRwlockPtr;
13544 }
13545 
13546 // should acquire write lock for the corresponding service before calling this
setNitzTimeReceived(int slotId,long timeReceived)13547 void radio_1_6::setNitzTimeReceived(int slotId, long timeReceived) {
13548     nitzTimeReceived[slotId] = timeReceived;
13549 }
13550