• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "RILC"
18 
19 #include <android/hardware/radio/1.6/IRadio.h>
20 #include <android/hardware/radio/1.6/IRadioIndication.h>
21 #include <android/hardware/radio/1.6/IRadioResponse.h>
22 #include <android/hardware/radio/1.6/types.h>
23 
24 #include <android/hardware/radio/deprecated/1.0/IOemHook.h>
25 
26 #include <hwbinder/IPCThreadState.h>
27 #include <hwbinder/ProcessState.h>
28 #include <guest/hals/ril/reference-libril/ril.h>
29 #include <telephony/ril_mnc.h>
30 #include <guest/hals/ril/reference-libril/ril_service.h>
31 #include <hidl/HidlTransportSupport.h>
32 #include <utils/SystemClock.h>
33 #include <inttypes.h>
34 
35 #define INVALID_HEX_CHAR 16
36 
37 using namespace android::hardware::radio;
38 using namespace android::hardware::radio::V1_0;
39 using namespace android::hardware::radio::deprecated::V1_0;
40 using ::android::hardware::configureRpcThreadpool;
41 using ::android::hardware::joinRpcThreadpool;
42 using ::android::hardware::Return;
43 using ::android::hardware::hidl_bitfield;
44 using ::android::hardware::hidl_string;
45 using ::android::hardware::hidl_vec;
46 using ::android::hardware::hidl_array;
47 using ::android::hardware::Void;
48 using android::CommandInfo;
49 using android::RequestInfo;
50 using android::requestToString;
51 using android::sp;
52 
53 using RegStateResultV1_6 = android::hardware::radio::V1_6::RegStateResult;
54 using RegStateResultV1_5 = android::hardware::radio::V1_5::RegStateResult;
55 using PhysicalChannelConfigV1_4 =
56     android::hardware::radio::V1_4::PhysicalChannelConfig;
57 using RadioTechnologyV1_4 = android::hardware::radio::V1_4::RadioTechnology;
58 
59 #define BOOL_TO_INT(x) (x ? 1 : 0)
60 #define ATOI_NULL_HANDLED(x) (x ? atoi(x) : -1)
61 #define ATOI_NULL_HANDLED_DEF(x, defaultVal) (x ? atoi(x) : defaultVal)
62 
63 #if defined(ANDROID_MULTI_SIM)
64 #define CALL_ONREQUEST(a, b, c, d, e) \
65         s_vendorFunctions->onRequest((a), (b), (c), (d), ((RIL_SOCKET_ID)(e)))
66 #define CALL_ONSTATEREQUEST(a) s_vendorFunctions->onStateRequest((RIL_SOCKET_ID)(a))
67 #else
68 #define CALL_ONREQUEST(a, b, c, d, e) s_vendorFunctions->onRequest((a), (b), (c), (d))
69 #define CALL_ONSTATEREQUEST(a) s_vendorFunctions->onStateRequest()
70 #endif
71 
72 #ifdef OEM_HOOK_DISABLED
73 constexpr bool kOemHookEnabled = false;
74 #else
75 constexpr bool kOemHookEnabled = true;
76 #endif
77 
78 RIL_RadioFunctions *s_vendorFunctions = NULL;
79 static CommandInfo *s_commands;
80 
81 struct RadioImpl_1_6;
82 struct OemHookImpl;
83 
84 #if (SIM_COUNT >= 2)
85 sp<RadioImpl_1_6> radioService[SIM_COUNT];
86 sp<OemHookImpl> oemHookService[SIM_COUNT];
87 int64_t nitzTimeReceived[SIM_COUNT];
88 // counter used for synchronization. It is incremented every time response callbacks are updated.
89 volatile int32_t mCounterRadio[SIM_COUNT];
90 volatile int32_t mCounterOemHook[SIM_COUNT];
91 #else
92 sp<RadioImpl_1_6> radioService[1];
93 sp<OemHookImpl> oemHookService[1];
94 int64_t nitzTimeReceived[1];
95 // counter used for synchronization. It is incremented every time response callbacks are updated.
96 volatile int32_t mCounterRadio[1];
97 volatile int32_t mCounterOemHook[1];
98 #endif
99 
100 static pthread_rwlock_t radioServiceRwlock = PTHREAD_RWLOCK_INITIALIZER;
101 
102 #if (SIM_COUNT >= 2)
103 static pthread_rwlock_t radioServiceRwlock2 = PTHREAD_RWLOCK_INITIALIZER;
104 #if (SIM_COUNT >= 3)
105 static pthread_rwlock_t radioServiceRwlock3 = PTHREAD_RWLOCK_INITIALIZER;
106 #if (SIM_COUNT >= 4)
107 static pthread_rwlock_t radioServiceRwlock4 = PTHREAD_RWLOCK_INITIALIZER;
108 #endif
109 #endif
110 #endif
111 
112 void convertRilHardwareConfigListToHal(void *response, size_t responseLen,
113         hidl_vec<HardwareConfig>& records);
114 
115 void convertRilRadioCapabilityToHal(void *response, size_t responseLen, RadioCapability& rc);
116 
117 void convertRilLceDataInfoToHal(void *response, size_t responseLen, LceDataInfo& lce);
118 
119 void convertRilSignalStrengthToHal(void *response, size_t responseLen,
120         SignalStrength& signalStrength);
121 
122 void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse,
123         SetupDataCallResult& dcResult);
124 
125 void convertRilSignalStrengthToHal_1_4(void *response, size_t responseLen,
126         V1_4::SignalStrength& signalStrength);
127 
128 void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse,
129         ::android::hardware::radio::V1_4::SetupDataCallResult& dcResult);
130 
131 void convertRilDataCallToHal(RIL_Data_Call_Response_v12 *dcResponse,
132         ::android::hardware::radio::V1_5::SetupDataCallResult& dcResult);
133 
134 void convertRilDataCallToHal(RIL_Data_Call_Response_v12 *dcResponse,
135         ::android::hardware::radio::V1_6::SetupDataCallResult& dcResult);
136 
137 void convertRilDataCallListToHal(void *response, size_t responseLen,
138         hidl_vec<SetupDataCallResult>& dcResultList);
139 
140 void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<CellInfo>& records);
141 void convertRilCellInfoListToHal_1_2(void *response, size_t responseLen, hidl_vec<V1_2::CellInfo>& records);
142 
143 void populateResponseInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
144                          RIL_Errno e);
145 
146 void populateResponseInfo_1_6(
147     ::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo,
148     int serial, int responseType, RIL_Errno e);
149 
150 struct RadioImpl_1_6 : public V1_6::IRadio {
151     int32_t mSlotId;
152     V1_1::CardPowerState mSimCardPowerState;
153     sp<IRadioResponse> mRadioResponse;
154     sp<IRadioIndication> mRadioIndication;
155     sp<V1_1::IRadioResponse> mRadioResponseV1_1;
156     sp<V1_1::IRadioIndication> mRadioIndicationV1_1;
157     sp<V1_2::IRadioResponse> mRadioResponseV1_2;
158     sp<V1_2::IRadioIndication> mRadioIndicationV1_2;
159     sp<V1_3::IRadioResponse> mRadioResponseV1_3;
160     sp<V1_3::IRadioIndication> mRadioIndicationV1_3;
161     sp<V1_4::IRadioResponse> mRadioResponseV1_4;
162     sp<V1_4::IRadioIndication> mRadioIndicationV1_4;
163     sp<V1_5::IRadioResponse> mRadioResponseV1_5;
164     sp<V1_5::IRadioIndication> mRadioIndicationV1_5;
165     sp<V1_6::IRadioResponse> mRadioResponseV1_6;
166     sp<V1_6::IRadioIndication> mRadioIndicationV1_6;
167 
168     Return<void> setResponseFunctions(
169             const ::android::sp<IRadioResponse>& radioResponse,
170             const ::android::sp<IRadioIndication>& radioIndication);
171 
172     Return<void> getIccCardStatus(int32_t serial);
173 
174     Return<void> supplyIccPinForApp(int32_t serial, const hidl_string& pin,
175             const hidl_string& aid);
176 
177     Return<void> supplyIccPukForApp(int32_t serial, const hidl_string& puk,
178             const hidl_string& pin, const hidl_string& aid);
179 
180     Return<void> supplyIccPin2ForApp(int32_t serial,
181             const hidl_string& pin2,
182             const hidl_string& aid);
183 
184     Return<void> supplyIccPuk2ForApp(int32_t serial, const hidl_string& puk2,
185             const hidl_string& pin2, const hidl_string& aid);
186 
187     Return<void> changeIccPinForApp(int32_t serial, const hidl_string& oldPin,
188             const hidl_string& newPin, const hidl_string& aid);
189 
190     Return<void> changeIccPin2ForApp(int32_t serial, const hidl_string& oldPin2,
191             const hidl_string& newPin2, const hidl_string& aid);
192 
193     Return<void> supplyNetworkDepersonalization(int32_t serial, const hidl_string& netPin);
194 
195     Return<void> getCurrentCalls(int32_t serial);
196 
197     Return<void> getCurrentCalls_1_6(int32_t serial);
198 
199     Return<void> dial(int32_t serial, const Dial& dialInfo);
200 
201     Return<void> getImsiForApp(int32_t serial,
202             const ::android::hardware::hidl_string& aid);
203 
204     Return<void> hangup(int32_t serial, int32_t gsmIndex);
205 
206     Return<void> hangupWaitingOrBackground(int32_t serial);
207 
208     Return<void> hangupForegroundResumeBackground(int32_t serial);
209 
210     Return<void> switchWaitingOrHoldingAndActive(int32_t serial);
211 
212     Return<void> conference(int32_t serial);
213 
214     Return<void> rejectCall(int32_t serial);
215 
216     Return<void> getLastCallFailCause(int32_t serial);
217 
218     Return<void> getSignalStrength(int32_t serial);
219 
220     Return<void> getSignalStrength_1_6(int32_t serial);
221 
222     Return<void> getVoiceRegistrationState(int32_t serial);
223 
224     Return<void> getDataRegistrationState(int32_t serial);
225 
226     Return<void> getOperator(int32_t serial);
227 
228     Return<void> setRadioPower(int32_t serial, bool on);
229 
230     Return<void> sendDtmf(int32_t serial,
231             const ::android::hardware::hidl_string& s);
232 
233     Return<void> sendSms(int32_t serial, const GsmSmsMessage& message);
234 
235     Return<void> sendSMSExpectMore(int32_t serial, const GsmSmsMessage& message);
236 
237     Return<void> setupDataCall(int32_t serial,
238             RadioTechnology radioTechnology,
239             const DataProfileInfo& profileInfo,
240             bool modemCognitive,
241             bool roamingAllowed,
242             bool isRoaming);
243 
244     Return<void> iccIOForApp(int32_t serial,
245             const IccIo& iccIo);
246 
247     Return<void> sendUssd(int32_t serial,
248             const ::android::hardware::hidl_string& ussd);
249 
250     Return<void> cancelPendingUssd(int32_t serial);
251 
252     Return<void> getClir(int32_t serial);
253 
254     Return<void> setClir(int32_t serial, int32_t status);
255 
256     Return<void> getCallForwardStatus(int32_t serial,
257             const CallForwardInfo& callInfo);
258 
259     Return<void> setCallForward(int32_t serial,
260             const CallForwardInfo& callInfo);
261 
262     Return<void> getCallWaiting(int32_t serial, int32_t serviceClass);
263 
264     Return<void> setCallWaiting(int32_t serial, bool enable, int32_t serviceClass);
265 
266     Return<void> acknowledgeLastIncomingGsmSms(int32_t serial,
267             bool success, SmsAcknowledgeFailCause cause);
268 
269     Return<void> acceptCall(int32_t serial);
270 
271     Return<void> deactivateDataCall(int32_t serial,
272             int32_t cid, bool reasonRadioShutDown);
273 
274     Return<void> getFacilityLockForApp(int32_t serial,
275             const ::android::hardware::hidl_string& facility,
276             const ::android::hardware::hidl_string& password,
277             int32_t serviceClass,
278             const ::android::hardware::hidl_string& appId);
279 
280     Return<void> setFacilityLockForApp(int32_t serial,
281             const ::android::hardware::hidl_string& facility,
282             bool lockState,
283             const ::android::hardware::hidl_string& password,
284             int32_t serviceClass,
285             const ::android::hardware::hidl_string& appId);
286 
287     Return<void> setBarringPassword(int32_t serial,
288             const ::android::hardware::hidl_string& facility,
289             const ::android::hardware::hidl_string& oldPassword,
290             const ::android::hardware::hidl_string& newPassword);
291 
292     Return<void> getNetworkSelectionMode(int32_t serial);
293 
294     Return<void> setNetworkSelectionModeAutomatic(int32_t serial);
295 
296     Return<void> setNetworkSelectionModeManual(int32_t serial,
297             const ::android::hardware::hidl_string& operatorNumeric);
298 
299     Return<void> getAvailableNetworks(int32_t serial);
300 
301     Return<void> startNetworkScan(int32_t serial, const V1_1::NetworkScanRequest& request);
302 
303     Return<void> stopNetworkScan(int32_t serial);
304 
305     Return<void> startDtmf(int32_t serial,
306             const ::android::hardware::hidl_string& s);
307 
308     Return<void> stopDtmf(int32_t serial);
309 
310     Return<void> getBasebandVersion(int32_t serial);
311 
312     Return<void> separateConnection(int32_t serial, int32_t gsmIndex);
313 
314     Return<void> setMute(int32_t serial, bool enable);
315 
316     Return<void> getMute(int32_t serial);
317 
318     Return<void> getClip(int32_t serial);
319 
320     Return<void> getDataCallList(int32_t serial);
321 
322     Return<void> setSuppServiceNotifications(int32_t serial, bool enable);
323 
324     Return<void> writeSmsToSim(int32_t serial,
325             const SmsWriteArgs& smsWriteArgs);
326 
327     Return<void> deleteSmsOnSim(int32_t serial, int32_t index);
328 
329     Return<void> setBandMode(int32_t serial, RadioBandMode mode);
330 
331     Return<void> getAvailableBandModes(int32_t serial);
332 
333     Return<void> sendEnvelope(int32_t serial,
334             const ::android::hardware::hidl_string& command);
335 
336     Return<void> sendTerminalResponseToSim(int32_t serial,
337             const ::android::hardware::hidl_string& commandResponse);
338 
339     Return<void> handleStkCallSetupRequestFromSim(int32_t serial, bool accept);
340 
341     Return<void> explicitCallTransfer(int32_t serial);
342 
343     Return<void> setPreferredNetworkType(int32_t serial, PreferredNetworkType nwType);
344 
345     Return<void> getPreferredNetworkType(int32_t serial);
346 
347     Return<void> getNeighboringCids(int32_t serial);
348 
349     Return<void> setLocationUpdates(int32_t serial, bool enable);
350 
351     Return<void> setCdmaSubscriptionSource(int32_t serial,
352             CdmaSubscriptionSource cdmaSub);
353 
354     Return<void> setCdmaRoamingPreference(int32_t serial, CdmaRoamingType type);
355 
356     Return<void> getCdmaRoamingPreference(int32_t serial);
357 
358     Return<void> setTTYMode(int32_t serial, TtyMode mode);
359 
360     Return<void> getTTYMode(int32_t serial);
361 
362     Return<void> setPreferredVoicePrivacy(int32_t serial, bool enable);
363 
364     Return<void> getPreferredVoicePrivacy(int32_t serial);
365 
366     Return<void> sendCDMAFeatureCode(int32_t serial,
367             const ::android::hardware::hidl_string& featureCode);
368 
369     Return<void> sendBurstDtmf(int32_t serial,
370             const ::android::hardware::hidl_string& dtmf,
371             int32_t on,
372             int32_t off);
373 
374     Return<void> sendCdmaSms(int32_t serial, const CdmaSmsMessage& sms);
375 
376     Return<void> acknowledgeLastIncomingCdmaSms(int32_t serial,
377             const CdmaSmsAck& smsAck);
378 
379     Return<void> getGsmBroadcastConfig(int32_t serial);
380 
381     Return<void> setGsmBroadcastConfig(int32_t serial,
382             const hidl_vec<GsmBroadcastSmsConfigInfo>& configInfo);
383 
384     Return<void> setGsmBroadcastActivation(int32_t serial, bool activate);
385 
386     Return<void> getCdmaBroadcastConfig(int32_t serial);
387 
388     Return<void> setCdmaBroadcastConfig(int32_t serial,
389             const hidl_vec<CdmaBroadcastSmsConfigInfo>& configInfo);
390 
391     Return<void> setCdmaBroadcastActivation(int32_t serial, bool activate);
392 
393     Return<void> getCDMASubscription(int32_t serial);
394 
395     Return<void> writeSmsToRuim(int32_t serial, const CdmaSmsWriteArgs& cdmaSms);
396 
397     Return<void> deleteSmsOnRuim(int32_t serial, int32_t index);
398 
399     Return<void> getDeviceIdentity(int32_t serial);
400 
401     Return<void> exitEmergencyCallbackMode(int32_t serial);
402 
403     Return<void> getSmscAddress(int32_t serial);
404 
405     Return<void> setSmscAddress(int32_t serial,
406             const ::android::hardware::hidl_string& smsc);
407 
408     Return<void> reportSmsMemoryStatus(int32_t serial, bool available);
409 
410     Return<void> reportStkServiceIsRunning(int32_t serial);
411 
412     Return<void> getCdmaSubscriptionSource(int32_t serial);
413 
414     Return<void> requestIsimAuthentication(int32_t serial,
415             const ::android::hardware::hidl_string& challenge);
416 
417     Return<void> acknowledgeIncomingGsmSmsWithPdu(int32_t serial,
418             bool success,
419             const ::android::hardware::hidl_string& ackPdu);
420 
421     Return<void> sendEnvelopeWithStatus(int32_t serial,
422             const ::android::hardware::hidl_string& contents);
423 
424     Return<void> getVoiceRadioTechnology(int32_t serial);
425 
426     Return<void> getCellInfoList(int32_t serial);
427 
428     Return<void> getCellInfoList_1_6(int32_t serial);
429 
430     Return<void> setCellInfoListRate(int32_t serial, int32_t rate);
431 
432     Return<void> setInitialAttachApn(int32_t serial, const DataProfileInfo& dataProfileInfo,
433             bool modemCognitive, bool isRoaming);
434 
435     Return<void> getImsRegistrationState(int32_t serial);
436 
437     Return<void> sendImsSms(int32_t serial, const ImsSmsMessage& message);
438 
439     Return<void> iccTransmitApduBasicChannel(int32_t serial, const SimApdu& message);
440 
441     Return<void> iccOpenLogicalChannel(int32_t serial,
442             const ::android::hardware::hidl_string& aid, int32_t p2);
443 
444     Return<void> iccCloseLogicalChannel(int32_t serial, int32_t channelId);
445 
446     Return<void> iccTransmitApduLogicalChannel(int32_t serial, const SimApdu& message);
447 
448     Return<void> nvReadItem(int32_t serial, NvItem itemId);
449 
450     Return<void> nvWriteItem(int32_t serial, const NvWriteItem& item);
451 
452     Return<void> nvWriteCdmaPrl(int32_t serial,
453             const ::android::hardware::hidl_vec<uint8_t>& prl);
454 
455     Return<void> nvResetConfig(int32_t serial, ResetNvType resetType);
456 
457     Return<void> setUiccSubscription(int32_t serial, const SelectUiccSub& uiccSub);
458 
459     Return<void> setDataAllowed(int32_t serial, bool allow);
460 
461     Return<void> getHardwareConfig(int32_t serial);
462 
463     Return<void> requestIccSimAuthentication(int32_t serial,
464             int32_t authContext,
465             const ::android::hardware::hidl_string& authData,
466             const ::android::hardware::hidl_string& aid);
467 
468     Return<void> setDataProfile(int32_t serial,
469             const ::android::hardware::hidl_vec<DataProfileInfo>& profiles, bool isRoaming);
470 
471     Return<void> requestShutdown(int32_t serial);
472 
473     Return<void> getRadioCapability(int32_t serial);
474 
475     Return<void> setRadioCapability(int32_t serial, const RadioCapability& rc);
476 
477     Return<void> startLceService(int32_t serial, int32_t reportInterval, bool pullMode);
478 
479     Return<void> stopLceService(int32_t serial);
480 
481     Return<void> pullLceData(int32_t serial);
482 
483     Return<void> getModemActivityInfo(int32_t serial);
484 
485     Return<void> setAllowedCarriers(int32_t serial,
486             bool allAllowed,
487             const CarrierRestrictions& carriers);
488 
489     Return<void> getAllowedCarriers(int32_t serial);
490 
491     Return<void> sendDeviceState(int32_t serial, DeviceStateType deviceStateType, bool state);
492 
493     Return<void> setIndicationFilter(int32_t serial, int32_t indicationFilter);
494 
495     Return<void> startKeepalive(int32_t serial, const V1_1::KeepaliveRequest& keepalive);
496 
497     Return<void> stopKeepalive(int32_t serial, int32_t sessionHandle);
498 
499     Return<void> setSimCardPower(int32_t serial, bool powerUp);
500     Return<void> setSimCardPower_1_1(int32_t serial,
501             const V1_1::CardPowerState state);
502     Return<void> setSimCardPower_1_6(int32_t serial,
503             const V1_1::CardPowerState state);
504 
505     Return<void> responseAcknowledgement();
506 
507     Return<void> setCarrierInfoForImsiEncryption(int32_t serial,
508             const V1_1::ImsiEncryptionInfo& message);
509 
510     void checkReturnStatus(Return<void>& ret);
511 
512     // Methods from ::android::hardware::radio::V1_2::IRadio follow.
513     Return<void> startNetworkScan_1_2(int32_t serial,
514             const ::android::hardware::radio::V1_2::NetworkScanRequest& request);
515     Return<void> setIndicationFilter_1_2(int32_t serial,
516             hidl_bitfield<::android::hardware::radio::V1_2::IndicationFilter> indicationFilter);
517     Return<void> setSignalStrengthReportingCriteria(int32_t serial, int32_t hysteresisMs,
518             int32_t hysteresisDb, const hidl_vec<int32_t>& thresholdsDbm,
519             ::android::hardware::radio::V1_2::AccessNetwork accessNetwork);
520     Return<void> setLinkCapacityReportingCriteria(int32_t serial, int32_t hysteresisMs,
521             int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
522             const hidl_vec<int32_t>& thresholdsDownlinkKbps,
523             const hidl_vec<int32_t>& thresholdsUplinkKbps,
524             ::android::hardware::radio::V1_2::AccessNetwork accessNetwork);
525     Return<void> setupDataCall_1_2(int32_t serial,
526             ::android::hardware::radio::V1_2::AccessNetwork accessNetwork,
527             const ::android::hardware::radio::V1_0::DataProfileInfo& dataProfileInfo,
528             bool modemCognitive, bool roamingAllowed, bool isRoaming,
529             ::android::hardware::radio::V1_2::DataRequestReason reason,
530             const hidl_vec<hidl_string>& addresses, const hidl_vec<hidl_string>& dnses);
531     Return<void> deactivateDataCall_1_2(int32_t serial, int32_t cid,
532             ::android::hardware::radio::V1_2::DataRequestReason reason);
533 
534     // Methods from ::android::hardware::radio::V1_3::IRadio follow.
535     Return<void> setSystemSelectionChannels(int32_t serial, bool specifyChannels,
536             const hidl_vec<::android::hardware::radio::V1_1::RadioAccessSpecifier>& specifiers);
537     Return<void> enableModem(int32_t serial, bool on);
538     Return<void> getModemStackStatus(int32_t serial);
539 
540     // Methods from ::android::hardware::radio::V1_4::IRadio follow.
541     Return<void> setupDataCall_1_4(int32_t serial,
542             ::android::hardware::radio::V1_4::AccessNetwork accessNetwork,
543             const ::android::hardware::radio::V1_4::DataProfileInfo& dataProfileInfo,
544             bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason reason,
545             const hidl_vec<hidl_string>& addresses, const hidl_vec<hidl_string>& dnses);
546     Return<void> setInitialAttachApn_1_4(int32_t serial,
547             const ::android::hardware::radio::V1_4::DataProfileInfo& dataProfileInfo);
548     Return<void> setDataProfile_1_4(int32_t serial,
549             const hidl_vec<::android::hardware::radio::V1_4::DataProfileInfo>& profiles);
550     Return<void> emergencyDial(int32_t serial,
551             const ::android::hardware::radio::V1_0::Dial& dialInfo,
552             hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,
553             const hidl_vec<hidl_string>& urns,
554             ::android::hardware::radio::V1_4::EmergencyCallRouting routing,
555             bool fromEmergencyDialer, bool isTesting);
556     Return<void> emergencyDial_1_6(int32_t serial,
557             const ::android::hardware::radio::V1_0::Dial& dialInfo,
558             hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,
559             const hidl_vec<hidl_string>& urns,
560             ::android::hardware::radio::V1_4::EmergencyCallRouting routing,
561             bool fromEmergencyDialer, bool isTesting);
562     Return<void> startNetworkScan_1_4(int32_t serial,
563             const ::android::hardware::radio::V1_2::NetworkScanRequest& request);
564     Return<void> getPreferredNetworkTypeBitmap(int32_t serial);
565     Return<void> setPreferredNetworkTypeBitmap(
566             int32_t serial, hidl_bitfield<RadioAccessFamily> networkTypeBitmap);
567     Return<void> setAllowedCarriers_1_4(int32_t serial,
568             const ::android::hardware::radio::V1_4::CarrierRestrictionsWithPriority& carriers,
569             ::android::hardware::radio::V1_4::SimLockMultiSimPolicy multiSimPolicy);
570     Return<void> getAllowedCarriers_1_4(int32_t serial);
571     Return<void> getSignalStrength_1_4(int32_t serial);
572 
573     // Methods from ::android::hardware::radio::V1_5::IRadio follow.
574     Return<void> setSignalStrengthReportingCriteria_1_5(int32_t serial,
575             const ::android::hardware::radio::V1_5::SignalThresholdInfo& signalThresholdInfo,
576             const ::android::hardware::radio::V1_5::AccessNetwork accessNetwork);
577     Return<void> setLinkCapacityReportingCriteria_1_5(int32_t serial, int32_t hysteresisMs,
578             int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
579             const hidl_vec<int32_t>& thresholdsDownlinkKbps,
580             const hidl_vec<int32_t>& thresholdsUplinkKbps,
581             V1_5::AccessNetwork accessNetwork);
582     Return<void> enableUiccApplications(int32_t serial, bool detach);
583     Return<void> areUiccApplicationsEnabled(int32_t serial);
584     Return<void> setSystemSelectionChannels_1_5(int32_t serial, bool specifyChannels,
585             const hidl_vec<::android::hardware::radio::V1_5::RadioAccessSpecifier>& specifiers);
586     Return<void> startNetworkScan_1_5(int32_t serial,
587             const ::android::hardware::radio::V1_5::NetworkScanRequest& request);
588     Return<void> setupDataCall_1_5(int32_t serial,
589             ::android::hardware::radio::V1_5::AccessNetwork accessNetwork,
590             const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
591             bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason reason,
592             const hidl_vec<::android::hardware::radio::V1_5::LinkAddress>& addresses,
593             const hidl_vec<hidl_string>& dnses);
594     Return<void> setInitialAttachApn_1_5(int32_t serial,
595             const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo);
596     Return<void> setDataProfile_1_5(int32_t serial,
597             const hidl_vec<::android::hardware::radio::V1_5::DataProfileInfo>& profiles);
598     Return<void> setRadioPower_1_5(int32_t serial, bool powerOn, bool forEmergencyCall,
599             bool preferredForEmergencyCall);
600     Return<void> setIndicationFilter_1_5(int32_t serial,
601             hidl_bitfield<::android::hardware::radio::V1_5::IndicationFilter> indicationFilter);
602     Return<void> getBarringInfo(int32_t serial);
603     Return<void> getVoiceRegistrationState_1_5(int32_t serial);
604     Return<void> getDataRegistrationState_1_5(int32_t serial);
605     Return<void> setNetworkSelectionModeManual_1_5(int32_t serial,
606             const hidl_string& operatorNumeric, V1_5::RadioAccessNetworks ran);
607     Return<void> sendCdmaSmsExpectMore(int32_t serial, const CdmaSmsMessage& sms);
608     Return<void> supplySimDepersonalization(int32_t serial, V1_5::PersoSubstate persoType,
609                                             const hidl_string& controlKey);
610     Return<void> setNrDualConnectivityState(int32_t serial,
611             V1_6::NrDualConnectivityState nrDualConnectivityState);
612     Return<void> isNrDualConnectivityEnabled(int32_t serial);
613 
614     // Methods from ::android::hardware::radio::V1_6::IRadio follow.
615     Return<void> getDataCallList_1_6(int32_t serial);
616     Return<void> setupDataCall_1_6(int32_t serial,
617             ::android::hardware::radio::V1_5::AccessNetwork accessNetwork,
618             const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
619             bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason reason,
620             const hidl_vec<::android::hardware::radio::V1_5::LinkAddress>& addresses,
621             const hidl_vec<hidl_string>& dnses,
622             int32_t pduSessionId,
623             const ::android::hardware::radio::V1_6::OptionalSliceInfo& sliceInfo,
624             const ::android::hardware::radio::V1_6::OptionalTrafficDescriptor& trafficDescriptor,
625             bool matchAllRuleAllowed);
626     Return<void> sendSms_1_6(int32_t serial, const GsmSmsMessage& message);
627     Return<void> sendSmsExpectMore_1_6(int32_t serial, const GsmSmsMessage& message);
628     Return<void> sendCdmaSms_1_6(int32_t serial, const CdmaSmsMessage& sms);
629     Return<void> sendCdmaSmsExpectMore_1_6(int32_t serial, const CdmaSmsMessage& sms);
630     Return<void> setRadioPower_1_6(int32_t serial, bool powerOn, bool forEmergencyCall,
631             bool preferredForEmergencyCall);
632     Return<void> allocatePduSessionId(int32_t serial);
633     Return<void> releasePduSessionId(int32_t serial, int32_t id);
634     Return<void> startHandover(int32_t serial, int32_t callId);
635     Return<void> cancelHandover(int32_t serial, int32_t callId);
636     Return<void> setAllowedNetworkTypesBitmap(uint32_t serial,
637             hidl_bitfield<::android::hardware::radio::V1_4::RadioAccessFamily> networkTypeBitmap);
638     Return<void> setDataThrottling(int32_t serial,
639             V1_6::DataThrottlingAction dataThrottlingAction,
640             int64_t completionDurationMillis);
641     Return<void> getSystemSelectionChannels(int32_t serial);
642     Return<void> getVoiceRegistrationState_1_6(int32_t serial);
643     Return<void> getDataRegistrationState_1_6(int32_t serial);
644     Return<void> getAllowedNetworkTypesBitmap(int32_t serial);
645     Return<void> getSlicingConfig(int32_t serial);
646     Return<void> setCarrierInfoForImsiEncryption_1_6(
647             int32_t serial,
648             const ::android::hardware::radio::V1_6::ImsiEncryptionInfo& imsiEncryptionInfo);
649     Return<void> getSimPhonebookRecords(int32_t serial);
650     Return<void> getSimPhonebookCapacity(int32_t serial);
651     Return<void> updateSimPhonebookRecords(
652             int32_t serial,
653             const ::android::hardware::radio::V1_6::PhonebookRecordInfo& recordInfo);
654 };
655 
656 struct OemHookImpl : public IOemHook {
657     int32_t mSlotId;
658     sp<IOemHookResponse> mOemHookResponse;
659     sp<IOemHookIndication> mOemHookIndication;
660 
661     Return<void> setResponseFunctions(
662             const ::android::sp<IOemHookResponse>& oemHookResponse,
663             const ::android::sp<IOemHookIndication>& oemHookIndication);
664 
665     Return<void> sendRequestRaw(int32_t serial,
666             const ::android::hardware::hidl_vec<uint8_t>& data);
667 
668     Return<void> sendRequestStrings(int32_t serial,
669             const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& data);
670 };
671 
memsetAndFreeStrings(int numPointers,...)672 void memsetAndFreeStrings(int numPointers, ...) {
673     va_list ap;
674     va_start(ap, numPointers);
675     for (int i = 0; i < numPointers; i++) {
676         char *ptr = va_arg(ap, char *);
677         if (ptr) {
678 #ifdef MEMSET_FREED
679 #define MAX_STRING_LENGTH 4096
680             memset(ptr, 0, strnlen(ptr, MAX_STRING_LENGTH));
681 #endif
682             free(ptr);
683         }
684     }
685     va_end(ap);
686 }
687 
sendErrorResponse(RequestInfo * pRI,RIL_Errno err)688 void sendErrorResponse(RequestInfo *pRI, RIL_Errno err) {
689     pRI->pCI->responseFunction((int) pRI->socket_id,
690             (int) RadioResponseType::SOLICITED, pRI->token, err, NULL, 0);
691 }
692 
693 /**
694  * Copies over src to dest. If memory allocation fails, responseFunction() is called for the
695  * request with error RIL_E_NO_MEMORY. The size() method is used to determine the size of the
696  * destination buffer into which the HIDL string is copied. If there is a discrepancy between
697  * the string length reported by the size() method, and the length of the string returned by
698  * the c_str() method, the function will return false indicating a failure.
699  *
700  * Returns true on success, and false on failure.
701  */
copyHidlStringToRil(char ** dest,const hidl_string & src,RequestInfo * pRI,bool allowEmpty)702 bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI, bool allowEmpty) {
703     size_t len = src.size();
704     if (len == 0 && !allowEmpty) {
705         *dest = NULL;
706         return true;
707     }
708     *dest = (char *) calloc(len + 1, sizeof(char));
709     if (*dest == NULL) {
710         RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
711         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
712         return false;
713     }
714     if (strlcpy(*dest, src.c_str(), len + 1) >= (len + 1)) {
715         RLOGE("Copy of the HIDL string has been truncated, as "
716               "the string length reported by size() does not "
717               "match the length of string returned by c_str().");
718         free(*dest);
719         *dest = NULL;
720         sendErrorResponse(pRI, RIL_E_INTERNAL_ERR);
721         return false;
722     }
723     return true;
724 }
725 
copyHidlStringToRil(char ** dest,const hidl_string & src,RequestInfo * pRI)726 bool copyHidlStringToRil(char **dest, const hidl_string &src, RequestInfo *pRI) {
727     return copyHidlStringToRil(dest, src, pRI, false);
728 }
729 
convertCharPtrToHidlString(const char * ptr)730 hidl_string convertCharPtrToHidlString(const char *ptr) {
731     hidl_string ret;
732     if (ptr != NULL) {
733         // TODO: replace this with strnlen
734         ret.setToExternal(ptr, strlen(ptr));
735     }
736     return ret;
737 }
738 
dispatchVoid(int serial,int slotId,int request)739 bool dispatchVoid(int serial, int slotId, int request) {
740     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
741     if (pRI == NULL) {
742         return false;
743     }
744     CALL_ONREQUEST(request, NULL, 0, pRI, slotId);
745     return true;
746 }
747 
dispatchString(int serial,int slotId,int request,const char * str)748 bool dispatchString(int serial, int slotId, int request, const char * str) {
749     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
750     if (pRI == NULL) {
751         return false;
752     }
753 
754     char *pString;
755     if (!copyHidlStringToRil(&pString, str, pRI)) {
756         return false;
757     }
758 
759     CALL_ONREQUEST(request, pString, sizeof(char *), pRI, slotId);
760 
761     memsetAndFreeStrings(1, pString);
762     return true;
763 }
764 
dispatchStrings(int serial,int slotId,int request,bool allowEmpty,int countStrings,...)765 bool dispatchStrings(int serial, int slotId, int request, bool allowEmpty, int countStrings, ...) {
766     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
767     if (pRI == NULL) {
768         return false;
769     }
770 
771     char **pStrings;
772     pStrings = (char **)calloc(countStrings, sizeof(char *));
773     if (pStrings == NULL) {
774         RLOGE("Memory allocation failed for request %s", requestToString(request));
775         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
776         return false;
777     }
778     va_list ap;
779     va_start(ap, countStrings);
780     for (int i = 0; i < countStrings; i++) {
781         const char* str = va_arg(ap, const char *);
782         if (!copyHidlStringToRil(&pStrings[i], hidl_string(str), pRI, allowEmpty)) {
783             va_end(ap);
784             for (int j = 0; j < i; j++) {
785                 memsetAndFreeStrings(1, pStrings[j]);
786             }
787             free(pStrings);
788             return false;
789         }
790     }
791     va_end(ap);
792 
793     CALL_ONREQUEST(request, pStrings, countStrings * sizeof(char *), pRI, slotId);
794 
795     if (pStrings != NULL) {
796         for (int i = 0 ; i < countStrings ; i++) {
797             memsetAndFreeStrings(1, pStrings[i]);
798         }
799 
800 #ifdef MEMSET_FREED
801         memset(pStrings, 0, countStrings * sizeof(char *));
802 #endif
803         free(pStrings);
804     }
805     return true;
806 }
807 
dispatchStrings(int serial,int slotId,int request,const hidl_vec<hidl_string> & data)808 bool dispatchStrings(int serial, int slotId, int request, const hidl_vec<hidl_string>& data) {
809     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
810     if (pRI == NULL) {
811         return false;
812     }
813 
814     int countStrings = data.size();
815     char **pStrings;
816     pStrings = (char **)calloc(countStrings, sizeof(char *));
817     if (pStrings == NULL) {
818         RLOGE("Memory allocation failed for request %s", requestToString(request));
819         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
820         return false;
821     }
822 
823     for (int i = 0; i < countStrings; i++) {
824         if (!copyHidlStringToRil(&pStrings[i], data[i], pRI)) {
825             for (int j = 0; j < i; j++) {
826                 memsetAndFreeStrings(1, pStrings[j]);
827             }
828             free(pStrings);
829             return false;
830         }
831     }
832 
833     CALL_ONREQUEST(request, pStrings, countStrings * sizeof(char *), pRI, slotId);
834 
835     if (pStrings != NULL) {
836         for (int i = 0 ; i < countStrings ; i++) {
837             memsetAndFreeStrings(1, pStrings[i]);
838         }
839 
840 #ifdef MEMSET_FREED
841         memset(pStrings, 0, countStrings * sizeof(char *));
842 #endif
843         free(pStrings);
844     }
845     return true;
846 }
847 
dispatchInts(int serial,int slotId,int request,int countInts,...)848 bool dispatchInts(int serial, int slotId, int request, int countInts, ...) {
849     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
850     if (pRI == NULL) {
851         return false;
852     }
853 
854     int *pInts = (int *)calloc(countInts, sizeof(int));
855 
856     if (pInts == NULL) {
857         RLOGE("Memory allocation failed for request %s", requestToString(request));
858         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
859         return false;
860     }
861     va_list ap;
862     va_start(ap, countInts);
863     for (int i = 0; i < countInts; i++) {
864         pInts[i] = va_arg(ap, int);
865     }
866     va_end(ap);
867 
868     CALL_ONREQUEST(request, pInts, countInts * sizeof(int), pRI, slotId);
869 
870     if (pInts != NULL) {
871 #ifdef MEMSET_FREED
872         memset(pInts, 0, countInts * sizeof(int));
873 #endif
874         free(pInts);
875     }
876     return true;
877 }
878 
dispatchCallForwardStatus(int serial,int slotId,int request,const CallForwardInfo & callInfo)879 bool dispatchCallForwardStatus(int serial, int slotId, int request,
880                               const CallForwardInfo& callInfo) {
881     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
882     if (pRI == NULL) {
883         return false;
884     }
885 
886     RIL_CallForwardInfo cf;
887     cf.status = (int) callInfo.status;
888     cf.reason = callInfo.reason;
889     cf.serviceClass = callInfo.serviceClass;
890     cf.toa = callInfo.toa;
891     cf.timeSeconds = callInfo.timeSeconds;
892 
893     if (!copyHidlStringToRil(&cf.number, callInfo.number, pRI)) {
894         return false;
895     }
896 
897     CALL_ONREQUEST(request, &cf, sizeof(cf), pRI, slotId);
898 
899     memsetAndFreeStrings(1, cf.number);
900 
901     return true;
902 }
903 
dispatchRaw(int serial,int slotId,int request,const hidl_vec<uint8_t> & rawBytes)904 bool dispatchRaw(int serial, int slotId, int request, const hidl_vec<uint8_t>& rawBytes) {
905     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
906     if (pRI == NULL) {
907         return false;
908     }
909 
910     const uint8_t *uData = rawBytes.data();
911 
912     CALL_ONREQUEST(request, (void *) uData, rawBytes.size(), pRI, slotId);
913 
914     return true;
915 }
916 
dispatchIccApdu(int serial,int slotId,int request,const SimApdu & message)917 bool dispatchIccApdu(int serial, int slotId, int request, const SimApdu& message) {
918     RequestInfo *pRI = android::addRequestToList(serial, slotId, request);
919     if (pRI == NULL) {
920         return false;
921     }
922 
923     RIL_SIM_APDU apdu = {};
924 
925     apdu.sessionid = message.sessionId;
926     apdu.cla = message.cla;
927     apdu.instruction = message.instruction;
928     apdu.p1 = message.p1;
929     apdu.p2 = message.p2;
930     apdu.p3 = message.p3;
931 
932     if (!copyHidlStringToRil(&apdu.data, message.data, pRI)) {
933         return false;
934     }
935 
936     CALL_ONREQUEST(request, &apdu, sizeof(apdu), pRI, slotId);
937 
938     memsetAndFreeStrings(1, apdu.data);
939 
940     return true;
941 }
942 
checkReturnStatus(int32_t slotId,Return<void> & ret,bool isRadioService)943 void checkReturnStatus(int32_t slotId, Return<void>& ret, bool isRadioService) {
944     if (ret.isOk() == false) {
945         RLOGE("checkReturnStatus: unable to call response/indication callback");
946         // Remote process hosting the callbacks must be dead. Reset the callback objects;
947         // there's no other recovery to be done here. When the client process is back up, it will
948         // call setResponseFunctions()
949 
950         // Caller should already hold rdlock, release that first
951         // note the current counter to avoid overwriting updates made by another thread before
952         // write lock is acquired.
953         int counter = isRadioService ? mCounterRadio[slotId] : mCounterOemHook[slotId];
954         pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(slotId);
955         int ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
956         assert(ret == 0);
957 
958         // acquire wrlock
959         ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
960         assert(ret == 0);
961 
962         // make sure the counter value has not changed
963         if (counter == (isRadioService ? mCounterRadio[slotId] : mCounterOemHook[slotId])) {
964             if (isRadioService) {
965                 radioService[slotId]->mRadioResponse = NULL;
966                 radioService[slotId]->mRadioIndication = NULL;
967                 radioService[slotId]->mRadioResponseV1_2 = NULL;
968                 radioService[slotId]->mRadioIndicationV1_2 = NULL;
969                 radioService[slotId]->mRadioResponseV1_3 = NULL;
970                 radioService[slotId]->mRadioIndicationV1_3 = NULL;
971                 radioService[slotId]->mRadioResponseV1_4 = NULL;
972                 radioService[slotId]->mRadioIndicationV1_4 = NULL;
973                 radioService[slotId]->mRadioResponseV1_5 = NULL;
974                 radioService[slotId]->mRadioIndicationV1_5 = NULL;
975                 radioService[slotId]->mRadioResponseV1_6 = NULL;
976                 radioService[slotId]->mRadioIndicationV1_6 = NULL;
977             } else {
978                 oemHookService[slotId]->mOemHookResponse = NULL;
979                 oemHookService[slotId]->mOemHookIndication = NULL;
980             }
981             isRadioService ? mCounterRadio[slotId]++ : mCounterOemHook[slotId]++;
982         } else {
983             RLOGE("checkReturnStatus: not resetting responseFunctions as they likely "
984                     "got updated on another thread");
985         }
986 
987         // release wrlock
988         ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
989         assert(ret == 0);
990 
991         // Reacquire rdlock
992         ret = pthread_rwlock_rdlock(radioServiceRwlockPtr);
993         assert(ret == 0);
994     }
995 }
996 
checkReturnStatus(Return<void> & ret)997 void RadioImpl_1_6::checkReturnStatus(Return<void>& ret) {
998     ::checkReturnStatus(mSlotId, ret, true);
999 }
1000 
setResponseFunctions(const::android::sp<IRadioResponse> & radioResponseParam,const::android::sp<IRadioIndication> & radioIndicationParam)1001 Return<void> RadioImpl_1_6::setResponseFunctions(
1002         const ::android::sp<IRadioResponse>& radioResponseParam,
1003         const ::android::sp<IRadioIndication>& radioIndicationParam) {
1004     RLOGD("setResponseFunctions");
1005 
1006     pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(mSlotId);
1007     int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
1008     assert(ret == 0);
1009 
1010     mRadioResponse = radioResponseParam;
1011     mRadioIndication = radioIndicationParam;
1012 
1013    mRadioResponseV1_6 = V1_6::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1014    mRadioIndicationV1_6 = V1_6::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1015    if (mRadioResponseV1_6 == nullptr || mRadioIndicationV1_6 == nullptr) {
1016        mRadioResponseV1_6 = nullptr;
1017        mRadioIndicationV1_6 = nullptr;
1018    }
1019 
1020    mRadioResponseV1_5 = V1_5::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1021    mRadioIndicationV1_5 = V1_5::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1022    if (mRadioResponseV1_5 == nullptr || mRadioIndicationV1_5 == nullptr) {
1023        mRadioResponseV1_5 = nullptr;
1024        mRadioIndicationV1_5 = nullptr;
1025    }
1026 
1027     mRadioResponseV1_4 = V1_4::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1028     mRadioIndicationV1_4 = V1_4::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1029     if (mRadioResponseV1_4 == nullptr || mRadioIndicationV1_4 == nullptr) {
1030         mRadioResponseV1_4 = nullptr;
1031         mRadioIndicationV1_4 = nullptr;
1032     }
1033 
1034     mRadioResponseV1_3 = V1_3::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1035     mRadioIndicationV1_3 = V1_3::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1036     if (mRadioResponseV1_3 == nullptr || mRadioIndicationV1_3 == nullptr) {
1037         mRadioResponseV1_3 = nullptr;
1038         mRadioIndicationV1_3 = nullptr;
1039     }
1040 
1041     mRadioResponseV1_2 = V1_2::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1042     mRadioIndicationV1_2 = V1_2::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1043     if (mRadioResponseV1_2 == nullptr || mRadioIndicationV1_2 == nullptr) {
1044         mRadioResponseV1_2 = nullptr;
1045         mRadioIndicationV1_2 = nullptr;
1046     }
1047 
1048     mRadioResponseV1_1 = V1_1::IRadioResponse::castFrom(mRadioResponse).withDefault(nullptr);
1049     mRadioIndicationV1_1 = V1_1::IRadioIndication::castFrom(mRadioIndication).withDefault(nullptr);
1050     if (mRadioResponseV1_1 == nullptr || mRadioIndicationV1_1 == nullptr) {
1051         mRadioResponseV1_1 = nullptr;
1052         mRadioIndicationV1_1 = nullptr;
1053     }
1054 
1055     mCounterRadio[mSlotId]++;
1056 
1057     ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
1058     assert(ret == 0);
1059 
1060     // client is connected. Send initial indications.
1061     android::onNewCommandConnect((RIL_SOCKET_ID) mSlotId);
1062 
1063     return Void();
1064 }
1065 
getIccCardStatus(int32_t serial)1066 Return<void> RadioImpl_1_6::getIccCardStatus(int32_t serial) {
1067 #if VDBG
1068     RLOGD("getIccCardStatus: serial %d", serial);
1069 #endif
1070     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SIM_STATUS);
1071     return Void();
1072 }
1073 
supplyIccPinForApp(int32_t serial,const hidl_string & pin,const hidl_string & aid)1074 Return<void> RadioImpl_1_6::supplyIccPinForApp(int32_t serial, const hidl_string& pin,
1075         const hidl_string& aid) {
1076 #if VDBG
1077     RLOGD("supplyIccPinForApp: serial %d", serial);
1078 #endif
1079     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN, true,
1080             2, pin.c_str(), aid.c_str());
1081     return Void();
1082 }
1083 
supplyIccPukForApp(int32_t serial,const hidl_string & puk,const hidl_string & pin,const hidl_string & aid)1084 Return<void> RadioImpl_1_6::supplyIccPukForApp(int32_t serial, const hidl_string& puk,
1085                                            const hidl_string& pin, const hidl_string& aid) {
1086 #if VDBG
1087     RLOGD("supplyIccPukForApp: serial %d", serial);
1088 #endif
1089     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK, true,
1090             3, puk.c_str(), pin.c_str(), aid.c_str());
1091     return Void();
1092 }
1093 
supplyIccPin2ForApp(int32_t serial,const hidl_string & pin2,const hidl_string & aid)1094 Return<void> RadioImpl_1_6::supplyIccPin2ForApp(int32_t serial, const hidl_string& pin2,
1095                                             const hidl_string& aid) {
1096 #if VDBG
1097     RLOGD("supplyIccPin2ForApp: serial %d", serial);
1098 #endif
1099     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PIN2, true,
1100             2, pin2.c_str(), aid.c_str());
1101     return Void();
1102 }
1103 
supplyIccPuk2ForApp(int32_t serial,const hidl_string & puk2,const hidl_string & pin2,const hidl_string & aid)1104 Return<void> RadioImpl_1_6::supplyIccPuk2ForApp(int32_t serial, const hidl_string& puk2,
1105                                             const hidl_string& pin2, const hidl_string& aid) {
1106 #if VDBG
1107     RLOGD("supplyIccPuk2ForApp: serial %d", serial);
1108 #endif
1109     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_PUK2, true,
1110             3, puk2.c_str(), pin2.c_str(), aid.c_str());
1111     return Void();
1112 }
1113 
changeIccPinForApp(int32_t serial,const hidl_string & oldPin,const hidl_string & newPin,const hidl_string & aid)1114 Return<void> RadioImpl_1_6::changeIccPinForApp(int32_t serial, const hidl_string& oldPin,
1115                                            const hidl_string& newPin, const hidl_string& aid) {
1116 #if VDBG
1117     RLOGD("changeIccPinForApp: serial %d", serial);
1118 #endif
1119     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN, true,
1120             3, oldPin.c_str(), newPin.c_str(), aid.c_str());
1121     return Void();
1122 }
1123 
changeIccPin2ForApp(int32_t serial,const hidl_string & oldPin2,const hidl_string & newPin2,const hidl_string & aid)1124 Return<void> RadioImpl_1_6::changeIccPin2ForApp(int32_t serial, const hidl_string& oldPin2,
1125                                             const hidl_string& newPin2, const hidl_string& aid) {
1126 #if VDBG
1127     RLOGD("changeIccPin2ForApp: serial %d", serial);
1128 #endif
1129     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_SIM_PIN2, true,
1130             3, oldPin2.c_str(), newPin2.c_str(), aid.c_str());
1131     return Void();
1132 }
1133 
supplyNetworkDepersonalization(int32_t serial,const hidl_string & netPin)1134 Return<void> RadioImpl_1_6::supplyNetworkDepersonalization(int32_t serial,
1135                                                        const hidl_string& netPin) {
1136 #if VDBG
1137     RLOGD("supplyNetworkDepersonalization: serial %d", serial);
1138 #endif
1139     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION, true,
1140             1, netPin.c_str());
1141     return Void();
1142 }
1143 
getCurrentCalls(int32_t serial)1144 Return<void> RadioImpl_1_6::getCurrentCalls(int32_t serial) {
1145 #if VDBG
1146     RLOGD("getCurrentCalls: serial %d", serial);
1147 #endif
1148     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CURRENT_CALLS);
1149     return Void();
1150 }
1151 
getCurrentCalls_1_6(int32_t serial)1152 Return<void> RadioImpl_1_6::getCurrentCalls_1_6(int32_t serial) {
1153 #if VDBG
1154     RLOGD("getCurrentCalls_1_6: serial %d", serial);
1155 #endif
1156     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CURRENT_CALLS);
1157     return Void();
1158 }
1159 
dial(int32_t serial,const Dial & dialInfo)1160 Return<void> RadioImpl_1_6::dial(int32_t serial, const Dial& dialInfo) {
1161 #if VDBG
1162     RLOGD("dial: serial %d", serial);
1163 #endif
1164     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_DIAL);
1165     if (pRI == NULL) {
1166         return Void();
1167     }
1168     RIL_Dial dial = {};
1169     RIL_UUS_Info uusInfo = {};
1170     int32_t sizeOfDial = sizeof(dial);
1171 
1172     if (!copyHidlStringToRil(&dial.address, dialInfo.address, pRI)) {
1173         return Void();
1174     }
1175     dial.clir = (int) dialInfo.clir;
1176 
1177     if (dialInfo.uusInfo.size() != 0) {
1178         uusInfo.uusType = (RIL_UUS_Type) dialInfo.uusInfo[0].uusType;
1179         uusInfo.uusDcs = (RIL_UUS_DCS) dialInfo.uusInfo[0].uusDcs;
1180 
1181         if (dialInfo.uusInfo[0].uusData.size() == 0) {
1182             uusInfo.uusData = NULL;
1183             uusInfo.uusLength = 0;
1184         } else {
1185             if (!copyHidlStringToRil(&uusInfo.uusData, dialInfo.uusInfo[0].uusData, pRI)) {
1186                 memsetAndFreeStrings(1, dial.address);
1187                 return Void();
1188             }
1189             uusInfo.uusLength = dialInfo.uusInfo[0].uusData.size();
1190         }
1191 
1192         dial.uusInfo = &uusInfo;
1193     }
1194 
1195     CALL_ONREQUEST(RIL_REQUEST_DIAL, &dial, sizeOfDial, pRI, mSlotId);
1196 
1197     memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
1198 
1199     return Void();
1200 }
1201 
getImsiForApp(int32_t serial,const hidl_string & aid)1202 Return<void> RadioImpl_1_6::getImsiForApp(int32_t serial, const hidl_string& aid) {
1203 #if VDBG
1204     RLOGD("getImsiForApp: serial %d", serial);
1205 #endif
1206     dispatchStrings(serial, mSlotId, RIL_REQUEST_GET_IMSI, false,
1207             1, aid.c_str());
1208     return Void();
1209 }
1210 
hangup(int32_t serial,int32_t gsmIndex)1211 Return<void> RadioImpl_1_6::hangup(int32_t serial, int32_t gsmIndex) {
1212 #if VDBG
1213     RLOGD("hangup: serial %d", serial);
1214 #endif
1215     dispatchInts(serial, mSlotId, RIL_REQUEST_HANGUP, 1, gsmIndex);
1216     return Void();
1217 }
1218 
hangupWaitingOrBackground(int32_t serial)1219 Return<void> RadioImpl_1_6::hangupWaitingOrBackground(int32_t serial) {
1220 #if VDBG
1221     RLOGD("hangupWaitingOrBackground: serial %d", serial);
1222 #endif
1223     dispatchVoid(serial, mSlotId, RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND);
1224     return Void();
1225 }
1226 
hangupForegroundResumeBackground(int32_t serial)1227 Return<void> RadioImpl_1_6::hangupForegroundResumeBackground(int32_t serial) {
1228 #if VDBG
1229     RLOGD("hangupForegroundResumeBackground: serial %d", serial);
1230 #endif
1231     dispatchVoid(serial, mSlotId, RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND);
1232     return Void();
1233 }
1234 
switchWaitingOrHoldingAndActive(int32_t serial)1235 Return<void> RadioImpl_1_6::switchWaitingOrHoldingAndActive(int32_t serial) {
1236 #if VDBG
1237     RLOGD("switchWaitingOrHoldingAndActive: serial %d", serial);
1238 #endif
1239     dispatchVoid(serial, mSlotId, RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE);
1240     return Void();
1241 }
1242 
conference(int32_t serial)1243 Return<void> RadioImpl_1_6::conference(int32_t serial) {
1244 #if VDBG
1245     RLOGD("conference: serial %d", serial);
1246 #endif
1247     dispatchVoid(serial, mSlotId, RIL_REQUEST_CONFERENCE);
1248     return Void();
1249 }
1250 
rejectCall(int32_t serial)1251 Return<void> RadioImpl_1_6::rejectCall(int32_t serial) {
1252 #if VDBG
1253     RLOGD("rejectCall: serial %d", serial);
1254 #endif
1255     dispatchVoid(serial, mSlotId, RIL_REQUEST_UDUB);
1256     return Void();
1257 }
1258 
getLastCallFailCause(int32_t serial)1259 Return<void> RadioImpl_1_6::getLastCallFailCause(int32_t serial) {
1260 #if VDBG
1261     RLOGD("getLastCallFailCause: serial %d", serial);
1262 #endif
1263     dispatchVoid(serial, mSlotId, RIL_REQUEST_LAST_CALL_FAIL_CAUSE);
1264     return Void();
1265 }
1266 
getSignalStrength(int32_t serial)1267 Return<void> RadioImpl_1_6::getSignalStrength(int32_t serial) {
1268 #if VDBG
1269     RLOGD("getSignalStrength: serial %d", serial);
1270 #endif
1271     dispatchVoid(serial, mSlotId, RIL_REQUEST_SIGNAL_STRENGTH);
1272     return Void();
1273 }
1274 
getVoiceRegistrationState(int32_t serial)1275 Return<void> RadioImpl_1_6::getVoiceRegistrationState(int32_t serial) {
1276 #if VDBG
1277     RLOGD("getVoiceRegistrationState: serial %d", serial);
1278 #endif
1279     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_REGISTRATION_STATE);
1280     return Void();
1281 }
1282 
getDataRegistrationState(int32_t serial)1283 Return<void> RadioImpl_1_6::getDataRegistrationState(int32_t serial) {
1284 #if VDBG
1285     RLOGD("getDataRegistrationState: serial %d", serial);
1286 #endif
1287     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_REGISTRATION_STATE);
1288     return Void();
1289 }
1290 
getOperator(int32_t serial)1291 Return<void> RadioImpl_1_6::getOperator(int32_t serial) {
1292 #if VDBG
1293     RLOGD("getOperator: serial %d", serial);
1294 #endif
1295     dispatchVoid(serial, mSlotId, RIL_REQUEST_OPERATOR);
1296     return Void();
1297 }
1298 
setRadioPower(int32_t serial,bool on)1299 Return<void> RadioImpl_1_6::setRadioPower(int32_t serial, bool on) {
1300 #if VDBG
1301     RLOGD("setRadioPower: serial %d on %d", serial, on);
1302 #endif
1303     dispatchInts(serial, mSlotId, RIL_REQUEST_RADIO_POWER, 1, BOOL_TO_INT(on));
1304     return Void();
1305 }
1306 
sendDtmf(int32_t serial,const hidl_string & s)1307 Return<void> RadioImpl_1_6::sendDtmf(int32_t serial, const hidl_string& s) {
1308 #if VDBG
1309     RLOGD("sendDtmf: serial %d", serial);
1310 #endif
1311     dispatchString(serial, mSlotId, RIL_REQUEST_DTMF, s.c_str());
1312     return Void();
1313 }
1314 
sendSms(int32_t serial,const GsmSmsMessage & message)1315 Return<void> RadioImpl_1_6::sendSms(int32_t serial, const GsmSmsMessage& message) {
1316 #if VDBG
1317     RLOGD("sendSms: serial %d", serial);
1318 #endif
1319     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS, false,
1320             2, message.smscPdu.c_str(), message.pdu.c_str());
1321     return Void();
1322 }
1323 
sendSms_1_6(int32_t serial,const GsmSmsMessage & message)1324 Return<void> RadioImpl_1_6::sendSms_1_6(int32_t serial, const GsmSmsMessage& message) {
1325 #if VDBG
1326     RLOGD("sendSms: serial %d", serial);
1327 #endif
1328     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS, false,
1329             2, message.smscPdu.c_str(), message.pdu.c_str());
1330     return Void();
1331 }
1332 
sendSMSExpectMore(int32_t serial,const GsmSmsMessage & message)1333 Return<void> RadioImpl_1_6::sendSMSExpectMore(int32_t serial, const GsmSmsMessage& message) {
1334 #if VDBG
1335     RLOGD("sendSmsExpectMore: serial %d", serial);
1336 #endif
1337     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS_EXPECT_MORE, false,
1338             2, message.smscPdu.c_str(), message.pdu.c_str());
1339     return Void();
1340 }
1341 
sendSmsExpectMore_1_6(int32_t serial,const GsmSmsMessage & message)1342 Return<void> RadioImpl_1_6::sendSmsExpectMore_1_6(int32_t serial, const GsmSmsMessage& message) {
1343 #if VDBG
1344     RLOGD("sendSmsExpectMore: serial %d", serial);
1345 #endif
1346     dispatchStrings(serial, mSlotId, RIL_REQUEST_SEND_SMS_EXPECT_MORE, false,
1347             2, message.smscPdu.c_str(), message.pdu.c_str());
1348     return Void();
1349 }
1350 
convertMvnoTypeToString(MvnoType type,char * & str)1351 static bool convertMvnoTypeToString(MvnoType type, char *&str) {
1352     switch (type) {
1353         case MvnoType::IMSI:
1354             str = (char *)"imsi";
1355             return true;
1356         case MvnoType::GID:
1357             str = (char *)"gid";
1358             return true;
1359         case MvnoType::SPN:
1360             str = (char *)"spn";
1361             return true;
1362         case MvnoType::NONE:
1363             str = (char *)"";
1364             return true;
1365     }
1366     return false;
1367 }
1368 
setupDataCall(int32_t serial,RadioTechnology radioTechnology,const DataProfileInfo & dataProfileInfo,bool modemCognitive,bool roamingAllowed,bool isRoaming)1369 Return<void> RadioImpl_1_6::setupDataCall(int32_t serial, RadioTechnology radioTechnology,
1370                                       const DataProfileInfo& dataProfileInfo, bool modemCognitive,
1371                                       bool roamingAllowed, bool isRoaming) {
1372 
1373 #if VDBG
1374     RLOGD("setupDataCall: serial %d", serial);
1375 #endif
1376 
1377     if (s_vendorFunctions->version >= 4 && s_vendorFunctions->version <= 14) {
1378         const hidl_string &protocol =
1379                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
1380         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 7,
1381             std::to_string((int) radioTechnology + 2).c_str(),
1382             std::to_string((int) dataProfileInfo.profileId).c_str(),
1383             dataProfileInfo.apn.c_str(),
1384             dataProfileInfo.user.c_str(),
1385             dataProfileInfo.password.c_str(),
1386             std::to_string((int) dataProfileInfo.authType).c_str(),
1387             protocol.c_str());
1388     } else if (s_vendorFunctions->version == 15) {
1389         char *mvnoTypeStr = NULL;
1390         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) {
1391             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
1392                     RIL_REQUEST_SETUP_DATA_CALL);
1393             if (pRI != NULL) {
1394                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1395             }
1396             return Void();
1397         }
1398         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15,
1399             std::to_string((int) radioTechnology + 2).c_str(),
1400             std::to_string((int) dataProfileInfo.profileId).c_str(),
1401             dataProfileInfo.apn.c_str(),
1402             dataProfileInfo.user.c_str(),
1403             dataProfileInfo.password.c_str(),
1404             std::to_string((int) dataProfileInfo.authType).c_str(),
1405             dataProfileInfo.protocol.c_str(),
1406             dataProfileInfo.roamingProtocol.c_str(),
1407             std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
1408             std::to_string(dataProfileInfo.bearerBitmap).c_str(),
1409             modemCognitive ? "1" : "0",
1410             std::to_string(dataProfileInfo.mtu).c_str(),
1411             mvnoTypeStr,
1412             dataProfileInfo.mvnoMatchData.c_str(),
1413             roamingAllowed ? "1" : "0");
1414     } else if (s_vendorFunctions->version >= 16) {
1415         char *mvnoTypeStr = NULL;
1416         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) {
1417             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
1418                     RIL_REQUEST_SETUP_DATA_CALL);
1419             if (pRI != NULL) {
1420                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1421             }
1422             return Void();
1423         }
1424         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 16,
1425             std::to_string((int) radioTechnology + 2).c_str(),
1426             std::to_string((int) dataProfileInfo.profileId).c_str(),
1427             dataProfileInfo.apn.c_str(),
1428             dataProfileInfo.user.c_str(),
1429             dataProfileInfo.password.c_str(),
1430             std::to_string((int) dataProfileInfo.authType).c_str(),
1431             dataProfileInfo.protocol.c_str(),
1432             dataProfileInfo.roamingProtocol.c_str(),
1433             std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
1434             std::to_string(dataProfileInfo.bearerBitmap).c_str(),
1435             modemCognitive ? "1" : "0",
1436             std::to_string(dataProfileInfo.mtu).c_str(),
1437             mvnoTypeStr,
1438             dataProfileInfo.mvnoMatchData.c_str(),
1439             roamingAllowed ? "1" : "0",
1440             "-1",
1441             "");
1442     } else {
1443         RLOGE("Unsupported RIL version %d, min version expected 4", s_vendorFunctions->version);
1444         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
1445                 RIL_REQUEST_SETUP_DATA_CALL);
1446         if (pRI != NULL) {
1447             sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
1448         }
1449     }
1450     return Void();
1451 }
1452 
iccIOForApp(int32_t serial,const IccIo & iccIo)1453 Return<void> RadioImpl_1_6::iccIOForApp(int32_t serial, const IccIo& iccIo) {
1454 #if VDBG
1455     RLOGD("iccIOForApp: serial %d", serial);
1456 #endif
1457     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_IO);
1458     if (pRI == NULL) {
1459         return Void();
1460     }
1461 
1462     RIL_SIM_IO_v6 rilIccIo = {};
1463     rilIccIo.command = iccIo.command;
1464     rilIccIo.fileid = iccIo.fileId;
1465     if (!copyHidlStringToRil(&rilIccIo.path, iccIo.path, pRI)) {
1466         return Void();
1467     }
1468 
1469     rilIccIo.p1 = iccIo.p1;
1470     rilIccIo.p2 = iccIo.p2;
1471     rilIccIo.p3 = iccIo.p3;
1472 
1473     if (!copyHidlStringToRil(&rilIccIo.data, iccIo.data, pRI)) {
1474         memsetAndFreeStrings(1, rilIccIo.path);
1475         return Void();
1476     }
1477 
1478     if (!copyHidlStringToRil(&rilIccIo.pin2, iccIo.pin2, pRI)) {
1479         memsetAndFreeStrings(2, rilIccIo.path, rilIccIo.data);
1480         return Void();
1481     }
1482 
1483     if (!copyHidlStringToRil(&rilIccIo.aidPtr, iccIo.aid, pRI)) {
1484         memsetAndFreeStrings(3, rilIccIo.path, rilIccIo.data, rilIccIo.pin2);
1485         return Void();
1486     }
1487 
1488     CALL_ONREQUEST(RIL_REQUEST_SIM_IO, &rilIccIo, sizeof(rilIccIo), pRI, mSlotId);
1489 
1490     memsetAndFreeStrings(4, rilIccIo.path, rilIccIo.data, rilIccIo.pin2, rilIccIo.aidPtr);
1491 
1492     return Void();
1493 }
1494 
sendUssd(int32_t serial,const hidl_string & ussd)1495 Return<void> RadioImpl_1_6::sendUssd(int32_t serial, const hidl_string& ussd) {
1496 #if VDBG
1497     RLOGD("sendUssd: serial %d", serial);
1498 #endif
1499     dispatchString(serial, mSlotId, RIL_REQUEST_SEND_USSD, ussd.c_str());
1500     return Void();
1501 }
1502 
cancelPendingUssd(int32_t serial)1503 Return<void> RadioImpl_1_6::cancelPendingUssd(int32_t serial) {
1504 #if VDBG
1505     RLOGD("cancelPendingUssd: serial %d", serial);
1506 #endif
1507     dispatchVoid(serial, mSlotId, RIL_REQUEST_CANCEL_USSD);
1508     return Void();
1509 }
1510 
getClir(int32_t serial)1511 Return<void> RadioImpl_1_6::getClir(int32_t serial) {
1512 #if VDBG
1513     RLOGD("getClir: serial %d", serial);
1514 #endif
1515     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CLIR);
1516     return Void();
1517 }
1518 
setClir(int32_t serial,int32_t status)1519 Return<void> RadioImpl_1_6::setClir(int32_t serial, int32_t status) {
1520 #if VDBG
1521     RLOGD("setClir: serial %d", serial);
1522 #endif
1523     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_CLIR, 1, status);
1524     return Void();
1525 }
1526 
getCallForwardStatus(int32_t serial,const CallForwardInfo & callInfo)1527 Return<void> RadioImpl_1_6::getCallForwardStatus(int32_t serial, const CallForwardInfo& callInfo) {
1528 #if VDBG
1529     RLOGD("getCallForwardStatus: serial %d", serial);
1530 #endif
1531     dispatchCallForwardStatus(serial, mSlotId, RIL_REQUEST_QUERY_CALL_FORWARD_STATUS,
1532             callInfo);
1533     return Void();
1534 }
1535 
setCallForward(int32_t serial,const CallForwardInfo & callInfo)1536 Return<void> RadioImpl_1_6::setCallForward(int32_t serial, const CallForwardInfo& callInfo) {
1537 #if VDBG
1538     RLOGD("setCallForward: serial %d", serial);
1539 #endif
1540     dispatchCallForwardStatus(serial, mSlotId, RIL_REQUEST_SET_CALL_FORWARD,
1541             callInfo);
1542     return Void();
1543 }
1544 
getCallWaiting(int32_t serial,int32_t serviceClass)1545 Return<void> RadioImpl_1_6::getCallWaiting(int32_t serial, int32_t serviceClass) {
1546 #if VDBG
1547     RLOGD("getCallWaiting: serial %d", serial);
1548 #endif
1549     dispatchInts(serial, mSlotId, RIL_REQUEST_QUERY_CALL_WAITING, 1, serviceClass);
1550     return Void();
1551 }
1552 
setCallWaiting(int32_t serial,bool enable,int32_t serviceClass)1553 Return<void> RadioImpl_1_6::setCallWaiting(int32_t serial, bool enable, int32_t serviceClass) {
1554 #if VDBG
1555     RLOGD("setCallWaiting: serial %d", serial);
1556 #endif
1557     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_CALL_WAITING, 2, BOOL_TO_INT(enable),
1558             serviceClass);
1559     return Void();
1560 }
1561 
acknowledgeLastIncomingGsmSms(int32_t serial,bool success,SmsAcknowledgeFailCause cause)1562 Return<void> RadioImpl_1_6::acknowledgeLastIncomingGsmSms(int32_t serial,
1563                                                       bool success, SmsAcknowledgeFailCause cause) {
1564 #if VDBG
1565     RLOGD("acknowledgeLastIncomingGsmSms: serial %d", serial);
1566 #endif
1567     dispatchInts(serial, mSlotId, RIL_REQUEST_SMS_ACKNOWLEDGE, 2, BOOL_TO_INT(success),
1568             cause);
1569     return Void();
1570 }
1571 
acceptCall(int32_t serial)1572 Return<void> RadioImpl_1_6::acceptCall(int32_t serial) {
1573 #if VDBG
1574     RLOGD("acceptCall: serial %d", serial);
1575 #endif
1576     dispatchVoid(serial, mSlotId, RIL_REQUEST_ANSWER);
1577     return Void();
1578 }
1579 
deactivateDataCall(int32_t serial,int32_t cid,bool reasonRadioShutDown)1580 Return<void> RadioImpl_1_6::deactivateDataCall(int32_t serial,
1581                                            int32_t cid, bool reasonRadioShutDown) {
1582 #if VDBG
1583     RLOGD("deactivateDataCall: serial %d", serial);
1584 #endif
1585     dispatchStrings(serial, mSlotId, RIL_REQUEST_DEACTIVATE_DATA_CALL, false,
1586             2, (std::to_string(cid)).c_str(), reasonRadioShutDown ? "1" : "0");
1587     return Void();
1588 }
1589 
getFacilityLockForApp(int32_t serial,const hidl_string & facility,const hidl_string & password,int32_t serviceClass,const hidl_string & appId)1590 Return<void> RadioImpl_1_6::getFacilityLockForApp(int32_t serial, const hidl_string& facility,
1591                                               const hidl_string& password, int32_t serviceClass,
1592                                               const hidl_string& appId) {
1593 #if VDBG
1594     RLOGD("getFacilityLockForApp: serial %d", serial);
1595 #endif
1596     dispatchStrings(serial, mSlotId, RIL_REQUEST_QUERY_FACILITY_LOCK, true,
1597             4, facility.c_str(), password.c_str(),
1598             (std::to_string(serviceClass)).c_str(), appId.c_str());
1599     return Void();
1600 }
1601 
setFacilityLockForApp(int32_t serial,const hidl_string & facility,bool lockState,const hidl_string & password,int32_t serviceClass,const hidl_string & appId)1602 Return<void> RadioImpl_1_6::setFacilityLockForApp(int32_t serial, const hidl_string& facility,
1603                                               bool lockState, const hidl_string& password,
1604                                               int32_t serviceClass, const hidl_string& appId) {
1605 #if VDBG
1606     RLOGD("setFacilityLockForApp: serial %d", serial);
1607 #endif
1608     dispatchStrings(serial, mSlotId, RIL_REQUEST_SET_FACILITY_LOCK, true,
1609             5, facility.c_str(), lockState ? "1" : "0", password.c_str(),
1610             (std::to_string(serviceClass)).c_str(), appId.c_str() );
1611     return Void();
1612 }
1613 
setBarringPassword(int32_t serial,const hidl_string & facility,const hidl_string & oldPassword,const hidl_string & newPassword)1614 Return<void> RadioImpl_1_6::setBarringPassword(int32_t serial, const hidl_string& facility,
1615                                            const hidl_string& oldPassword,
1616                                            const hidl_string& newPassword) {
1617 #if VDBG
1618     RLOGD("setBarringPassword: serial %d", serial);
1619 #endif
1620     dispatchStrings(serial, mSlotId, RIL_REQUEST_CHANGE_BARRING_PASSWORD, true,
1621             3, facility.c_str(), oldPassword.c_str(), newPassword.c_str());
1622     return Void();
1623 }
1624 
getNetworkSelectionMode(int32_t serial)1625 Return<void> RadioImpl_1_6::getNetworkSelectionMode(int32_t serial) {
1626 #if VDBG
1627     RLOGD("getNetworkSelectionMode: serial %d", serial);
1628 #endif
1629     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE);
1630     return Void();
1631 }
1632 
setNetworkSelectionModeAutomatic(int32_t serial)1633 Return<void> RadioImpl_1_6::setNetworkSelectionModeAutomatic(int32_t serial) {
1634 #if VDBG
1635     RLOGD("setNetworkSelectionModeAutomatic: serial %d", serial);
1636 #endif
1637     dispatchVoid(serial, mSlotId, RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC);
1638     return Void();
1639 }
1640 
setNetworkSelectionModeManual(int32_t serial,const hidl_string & operatorNumeric)1641 Return<void> RadioImpl_1_6::setNetworkSelectionModeManual(int32_t serial,
1642                                                       const hidl_string& operatorNumeric) {
1643 #if VDBG
1644     RLOGD("setNetworkSelectionModeManual: serial %d", serial);
1645 #endif
1646     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
1647         RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL);
1648     if (pRI == NULL) {
1649         return Void();
1650     }
1651 
1652     RIL_NetworkOperator networkOperator = {};
1653 
1654     networkOperator.act = UNKNOWN;
1655     if (!copyHidlStringToRil(&networkOperator.operatorNumeric, operatorNumeric, pRI)) {
1656         return Void();
1657     }
1658     CALL_ONREQUEST(pRI->pCI->requestNumber, &networkOperator,
1659         sizeof(networkOperator), pRI, mSlotId);
1660 
1661     return Void();
1662 }
1663 
getAvailableNetworks(int32_t serial)1664 Return<void> RadioImpl_1_6::getAvailableNetworks(int32_t serial) {
1665 #if VDBG
1666     RLOGD("getAvailableNetworks: serial %d", serial);
1667 #endif
1668     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_AVAILABLE_NETWORKS);
1669     return Void();
1670 }
1671 
startNetworkScan(int32_t serial,const V1_1::NetworkScanRequest & request)1672 Return<void> RadioImpl_1_6::startNetworkScan(int32_t serial, const V1_1::NetworkScanRequest& request) {
1673 #if VDBG
1674     RLOGD("startNetworkScan: serial %d", serial);
1675 #endif
1676 
1677     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
1678     if (pRI == NULL) {
1679         return Void();
1680     }
1681 
1682     if (request.specifiers.size() > MAX_RADIO_ACCESS_NETWORKS) {
1683         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1684         return Void();
1685     }
1686 
1687     RIL_NetworkScanRequest scan_request = {};
1688 
1689     scan_request.type = (RIL_ScanType) request.type;
1690     scan_request.interval = request.interval;
1691     scan_request.specifiers_length = request.specifiers.size();
1692     for (size_t i = 0; i < request.specifiers.size(); ++i) {
1693         if (request.specifiers[i].geranBands.size() > MAX_BANDS ||
1694             request.specifiers[i].utranBands.size() > MAX_BANDS ||
1695             request.specifiers[i].eutranBands.size() > MAX_BANDS ||
1696             request.specifiers[i].channels.size() > MAX_CHANNELS) {
1697             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1698             return Void();
1699         }
1700         const V1_1::RadioAccessSpecifier& ras_from =
1701                 request.specifiers[i];
1702         RIL_RadioAccessSpecifier& ras_to = scan_request.specifiers[i];
1703 
1704         ras_to.radio_access_network = (RIL_RadioAccessNetworks) ras_from.radioAccessNetwork;
1705         ras_to.channels_length = ras_from.channels.size();
1706 
1707         std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
1708         const std::vector<uint32_t> * bands = nullptr;
1709         switch (request.specifiers[i].radioAccessNetwork) {
1710             case V1_1::RadioAccessNetworks::GERAN:
1711                 ras_to.bands_length = ras_from.geranBands.size();
1712                 bands = (std::vector<uint32_t> *) &ras_from.geranBands;
1713                 break;
1714             case V1_1::RadioAccessNetworks::UTRAN:
1715                 ras_to.bands_length = ras_from.utranBands.size();
1716                 bands = (std::vector<uint32_t> *) &ras_from.utranBands;
1717                 break;
1718             case V1_1::RadioAccessNetworks::EUTRAN:
1719                 ras_to.bands_length = ras_from.eutranBands.size();
1720                 bands = (std::vector<uint32_t> *) &ras_from.eutranBands;
1721                 break;
1722             default:
1723                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
1724                 return Void();
1725         }
1726         // safe to copy to geran_bands because it's a union member
1727         for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
1728             ras_to.bands.geran_bands[idx] = (RIL_GeranBands) (*bands)[idx];
1729         }
1730     }
1731 
1732     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
1733             mSlotId);
1734 
1735     return Void();
1736 }
1737 
stopNetworkScan(int32_t serial)1738 Return<void> RadioImpl_1_6::stopNetworkScan(int32_t serial) {
1739 #if VDBG
1740     RLOGD("stopNetworkScan: serial %d", serial);
1741 #endif
1742     dispatchVoid(serial, mSlotId, RIL_REQUEST_STOP_NETWORK_SCAN);
1743     return Void();
1744 }
1745 
startDtmf(int32_t serial,const hidl_string & s)1746 Return<void> RadioImpl_1_6::startDtmf(int32_t serial, const hidl_string& s) {
1747 #if VDBG
1748     RLOGD("startDtmf: serial %d", serial);
1749 #endif
1750     dispatchString(serial, mSlotId, RIL_REQUEST_DTMF_START,
1751             s.c_str());
1752     return Void();
1753 }
1754 
stopDtmf(int32_t serial)1755 Return<void> RadioImpl_1_6::stopDtmf(int32_t serial) {
1756 #if VDBG
1757     RLOGD("stopDtmf: serial %d", serial);
1758 #endif
1759     dispatchVoid(serial, mSlotId, RIL_REQUEST_DTMF_STOP);
1760     return Void();
1761 }
1762 
getBasebandVersion(int32_t serial)1763 Return<void> RadioImpl_1_6::getBasebandVersion(int32_t serial) {
1764 #if VDBG
1765     RLOGD("getBasebandVersion: serial %d", serial);
1766 #endif
1767     dispatchVoid(serial, mSlotId, RIL_REQUEST_BASEBAND_VERSION);
1768     return Void();
1769 }
1770 
separateConnection(int32_t serial,int32_t gsmIndex)1771 Return<void> RadioImpl_1_6::separateConnection(int32_t serial, int32_t gsmIndex) {
1772 #if VDBG
1773     RLOGD("separateConnection: serial %d", serial);
1774 #endif
1775     dispatchInts(serial, mSlotId, RIL_REQUEST_SEPARATE_CONNECTION, 1, gsmIndex);
1776     return Void();
1777 }
1778 
setMute(int32_t serial,bool enable)1779 Return<void> RadioImpl_1_6::setMute(int32_t serial, bool enable) {
1780 #if VDBG
1781     RLOGD("setMute: serial %d", serial);
1782 #endif
1783     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_MUTE, 1, BOOL_TO_INT(enable));
1784     return Void();
1785 }
1786 
getMute(int32_t serial)1787 Return<void> RadioImpl_1_6::getMute(int32_t serial) {
1788 #if VDBG
1789     RLOGD("getMute: serial %d", serial);
1790 #endif
1791     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_MUTE);
1792     return Void();
1793 }
1794 
getClip(int32_t serial)1795 Return<void> RadioImpl_1_6::getClip(int32_t serial) {
1796 #if VDBG
1797     RLOGD("getClip: serial %d", serial);
1798 #endif
1799     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_CLIP);
1800     return Void();
1801 }
1802 
getDataCallList(int32_t serial)1803 Return<void> RadioImpl_1_6::getDataCallList(int32_t serial) {
1804 #if VDBG
1805     RLOGD("getDataCallList: serial %d", serial);
1806 #endif
1807     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_CALL_LIST);
1808     return Void();
1809 }
1810 
getDataCallList_1_6(int32_t serial)1811 Return<void> RadioImpl_1_6::getDataCallList_1_6(int32_t serial) {
1812 #if VDBG
1813     RLOGD("getDataCallList_1_6: serial %d", serial);
1814 #endif
1815     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_CALL_LIST);
1816     return Void();
1817 }
1818 
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)1819 Return<void> RadioImpl_1_6::emergencyDial_1_6(int32_t serial,
1820         const ::android::hardware::radio::V1_0::Dial& dialInfo,
1821         hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,
1822         const hidl_vec<hidl_string>&  urns ,
1823         ::android::hardware::radio::V1_4::EmergencyCallRouting routing,
1824         bool fromEmergencyDialer, bool /* isTesting */) {
1825 #if VDBG
1826     RLOGD("emergencyDial: serial %d", serial);
1827 #endif
1828 
1829     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_EMERGENCY_DIAL);
1830     if (pRI == NULL) {
1831         return Void();
1832     }
1833 
1834     RIL_EmergencyDial eccDial = {};
1835     RIL_Dial& dial = eccDial.dialInfo;
1836     RIL_UUS_Info uusInfo = {};
1837 
1838     if (!copyHidlStringToRil(&dial.address, dialInfo.address, pRI)) {
1839         return Void();
1840     }
1841     dial.clir = (int) dialInfo.clir;
1842 
1843     if (dialInfo.uusInfo.size() != 0) {
1844         uusInfo.uusType = (RIL_UUS_Type) dialInfo.uusInfo[0].uusType;
1845         uusInfo.uusDcs = (RIL_UUS_DCS) dialInfo.uusInfo[0].uusDcs;
1846 
1847         if (dialInfo.uusInfo[0].uusData.size() == 0) {
1848             uusInfo.uusData = NULL;
1849             uusInfo.uusLength = 0;
1850         } else {
1851             if (!copyHidlStringToRil(&uusInfo.uusData, dialInfo.uusInfo[0].uusData, pRI)) {
1852                 memsetAndFreeStrings(1, dial.address);
1853                 return Void();
1854             }
1855             uusInfo.uusLength = dialInfo.uusInfo[0].uusData.size();
1856         }
1857 
1858         dial.uusInfo = &uusInfo;
1859     }
1860 
1861     eccDial.urnsNumber = urns.size();
1862     if (eccDial.urnsNumber != 0) {
1863         char **ppUrns = (char **)calloc(eccDial.urnsNumber, sizeof(char *));
1864         if (ppUrns == NULL) {
1865             RLOGE("Memory allocation failed for request %s",
1866                     requestToString(pRI->pCI->requestNumber));
1867             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
1868             memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
1869             return Void();
1870         }
1871         for (uint32_t i = 0; i < eccDial.urnsNumber; i++) {
1872             if (!copyHidlStringToRil(&ppUrns[i], hidl_string(urns[i]), pRI)) {
1873                 for (uint32_t j = 0; j < i; j++) {
1874                     memsetAndFreeStrings(1, ppUrns[j]);
1875                 }
1876                 memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
1877                 free(ppUrns);
1878                 return Void();
1879             }
1880         }
1881         eccDial.urns = ppUrns;
1882     }
1883 
1884     eccDial.categories = (RIL_EmergencyServiceCategory)categories;
1885     eccDial.routing = (RIL_EmergencyCallRouting)routing;
1886     eccDial.fromEmergencyDialer = fromEmergencyDialer;
1887 
1888     CALL_ONREQUEST(RIL_REQUEST_EMERGENCY_DIAL, &eccDial, sizeof(RIL_EmergencyDial), pRI, mSlotId);
1889 
1890     memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
1891     if (eccDial.urns != NULL) {
1892         for (size_t i = 0; i < eccDial.urnsNumber; i++) {
1893             memsetAndFreeStrings(1, eccDial.urns[i]);
1894         }
1895         free(eccDial.urns);
1896     }
1897     return Void();
1898 }
1899 
setSuppServiceNotifications(int32_t serial,bool enable)1900 Return<void> RadioImpl_1_6::setSuppServiceNotifications(int32_t serial, bool enable) {
1901 #if VDBG
1902     RLOGD("setSuppServiceNotifications: serial %d", serial);
1903 #endif
1904     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION, 1,
1905             BOOL_TO_INT(enable));
1906     return Void();
1907 }
1908 
writeSmsToSim(int32_t serial,const SmsWriteArgs & smsWriteArgs)1909 Return<void> RadioImpl_1_6::writeSmsToSim(int32_t serial, const SmsWriteArgs& smsWriteArgs) {
1910 #if VDBG
1911     RLOGD("writeSmsToSim: serial %d", serial);
1912 #endif
1913     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_WRITE_SMS_TO_SIM);
1914     if (pRI == NULL) {
1915         return Void();
1916     }
1917 
1918     RIL_SMS_WriteArgs args;
1919     args.status = (int) smsWriteArgs.status;
1920 
1921     if (!copyHidlStringToRil(&args.pdu, smsWriteArgs.pdu, pRI)) {
1922         return Void();
1923     }
1924 
1925     if (!copyHidlStringToRil(&args.smsc, smsWriteArgs.smsc, pRI)) {
1926         memsetAndFreeStrings(1, args.pdu);
1927         return Void();
1928     }
1929 
1930     CALL_ONREQUEST(RIL_REQUEST_WRITE_SMS_TO_SIM, &args, sizeof(args), pRI, mSlotId);
1931 
1932     memsetAndFreeStrings(2, args.smsc, args.pdu);
1933 
1934     return Void();
1935 }
1936 
deleteSmsOnSim(int32_t serial,int32_t index)1937 Return<void> RadioImpl_1_6::deleteSmsOnSim(int32_t serial, int32_t index) {
1938 #if VDBG
1939     RLOGD("deleteSmsOnSim: serial %d", serial);
1940 #endif
1941     dispatchInts(serial, mSlotId, RIL_REQUEST_DELETE_SMS_ON_SIM, 1, index);
1942     return Void();
1943 }
1944 
setBandMode(int32_t serial,RadioBandMode mode)1945 Return<void> RadioImpl_1_6::setBandMode(int32_t serial, RadioBandMode mode) {
1946 #if VDBG
1947     RLOGD("setBandMode: serial %d", serial);
1948 #endif
1949     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_BAND_MODE, 1, mode);
1950     return Void();
1951 }
1952 
getAvailableBandModes(int32_t serial)1953 Return<void> RadioImpl_1_6::getAvailableBandModes(int32_t serial) {
1954 #if VDBG
1955     RLOGD("getAvailableBandModes: serial %d", serial);
1956 #endif
1957     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE);
1958     return Void();
1959 }
1960 
sendEnvelope(int32_t serial,const hidl_string & command)1961 Return<void> RadioImpl_1_6::sendEnvelope(int32_t serial, const hidl_string& command) {
1962 #if VDBG
1963     RLOGD("sendEnvelope: serial %d", serial);
1964 #endif
1965     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND,
1966             command.c_str());
1967     return Void();
1968 }
1969 
sendTerminalResponseToSim(int32_t serial,const hidl_string & commandResponse)1970 Return<void> RadioImpl_1_6::sendTerminalResponseToSim(int32_t serial,
1971                                                   const hidl_string& commandResponse) {
1972 #if VDBG
1973     RLOGD("sendTerminalResponseToSim: serial %d", serial);
1974 #endif
1975     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE,
1976             commandResponse.c_str());
1977     return Void();
1978 }
1979 
handleStkCallSetupRequestFromSim(int32_t serial,bool accept)1980 Return<void> RadioImpl_1_6::handleStkCallSetupRequestFromSim(int32_t serial, bool accept) {
1981 #if VDBG
1982     RLOGD("handleStkCallSetupRequestFromSim: serial %d", serial);
1983 #endif
1984     dispatchInts(serial, mSlotId, RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM,
1985             1, BOOL_TO_INT(accept));
1986     return Void();
1987 }
1988 
explicitCallTransfer(int32_t serial)1989 Return<void> RadioImpl_1_6::explicitCallTransfer(int32_t serial) {
1990 #if VDBG
1991     RLOGD("explicitCallTransfer: serial %d", serial);
1992 #endif
1993     dispatchVoid(serial, mSlotId, RIL_REQUEST_EXPLICIT_CALL_TRANSFER);
1994     return Void();
1995 }
1996 
setPreferredNetworkType(int32_t serial,PreferredNetworkType nwType)1997 Return<void> RadioImpl_1_6::setPreferredNetworkType(int32_t serial, PreferredNetworkType nwType) {
1998 #if VDBG
1999     RLOGD("setPreferredNetworkType: serial %d", serial);
2000 #endif
2001     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, 1, nwType);
2002     return Void();
2003 }
2004 
getPreferredNetworkType(int32_t serial)2005 Return<void> RadioImpl_1_6::getPreferredNetworkType(int32_t serial) {
2006 #if VDBG
2007     RLOGD("getPreferredNetworkType: serial %d", serial);
2008 #endif
2009     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE);
2010     return Void();
2011 }
2012 
getNeighboringCids(int32_t serial)2013 Return<void> RadioImpl_1_6::getNeighboringCids(int32_t serial) {
2014 #if VDBG
2015     RLOGD("getNeighboringCids: serial %d", serial);
2016 #endif
2017     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_NEIGHBORING_CELL_IDS);
2018     return Void();
2019 }
2020 
setLocationUpdates(int32_t serial,bool enable)2021 Return<void> RadioImpl_1_6::setLocationUpdates(int32_t serial, bool enable) {
2022 #if VDBG
2023     RLOGD("setLocationUpdates: serial %d", serial);
2024 #endif
2025     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_LOCATION_UPDATES, 1, BOOL_TO_INT(enable));
2026     return Void();
2027 }
2028 
setCdmaSubscriptionSource(int32_t serial,CdmaSubscriptionSource cdmaSub)2029 Return<void> RadioImpl_1_6::setCdmaSubscriptionSource(int32_t serial, CdmaSubscriptionSource cdmaSub) {
2030 #if VDBG
2031     RLOGD("setCdmaSubscriptionSource: serial %d", serial);
2032 #endif
2033     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE, 1, cdmaSub);
2034     return Void();
2035 }
2036 
setCdmaRoamingPreference(int32_t serial,CdmaRoamingType type)2037 Return<void> RadioImpl_1_6::setCdmaRoamingPreference(int32_t serial, CdmaRoamingType type) {
2038 #if VDBG
2039     RLOGD("setCdmaRoamingPreference: serial %d", serial);
2040 #endif
2041     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE, 1, type);
2042     return Void();
2043 }
2044 
getCdmaRoamingPreference(int32_t serial)2045 Return<void> RadioImpl_1_6::getCdmaRoamingPreference(int32_t serial) {
2046 #if VDBG
2047     RLOGD("getCdmaRoamingPreference: serial %d", serial);
2048 #endif
2049     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE);
2050     return Void();
2051 }
2052 
setTTYMode(int32_t serial,TtyMode mode)2053 Return<void> RadioImpl_1_6::setTTYMode(int32_t serial, TtyMode mode) {
2054 #if VDBG
2055     RLOGD("setTTYMode: serial %d", serial);
2056 #endif
2057     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_TTY_MODE, 1, mode);
2058     return Void();
2059 }
2060 
getTTYMode(int32_t serial)2061 Return<void> RadioImpl_1_6::getTTYMode(int32_t serial) {
2062 #if VDBG
2063     RLOGD("getTTYMode: serial %d", serial);
2064 #endif
2065     dispatchVoid(serial, mSlotId, RIL_REQUEST_QUERY_TTY_MODE);
2066     return Void();
2067 }
2068 
setPreferredVoicePrivacy(int32_t serial,bool enable)2069 Return<void> RadioImpl_1_6::setPreferredVoicePrivacy(int32_t serial, bool enable) {
2070 #if VDBG
2071     RLOGD("setPreferredVoicePrivacy: serial %d", serial);
2072 #endif
2073     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE,
2074             1, BOOL_TO_INT(enable));
2075     return Void();
2076 }
2077 
getPreferredVoicePrivacy(int32_t serial)2078 Return<void> RadioImpl_1_6::getPreferredVoicePrivacy(int32_t serial) {
2079 #if VDBG
2080     RLOGD("getPreferredVoicePrivacy: serial %d", serial);
2081 #endif
2082     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE);
2083     return Void();
2084 }
2085 
sendCDMAFeatureCode(int32_t serial,const hidl_string & featureCode)2086 Return<void> RadioImpl_1_6::sendCDMAFeatureCode(int32_t serial, const hidl_string& featureCode) {
2087 #if VDBG
2088     RLOGD("sendCDMAFeatureCode: serial %d", serial);
2089 #endif
2090     dispatchString(serial, mSlotId, RIL_REQUEST_CDMA_FLASH,
2091             featureCode.c_str());
2092     return Void();
2093 }
2094 
sendBurstDtmf(int32_t serial,const hidl_string & dtmf,int32_t on,int32_t off)2095 Return<void> RadioImpl_1_6::sendBurstDtmf(int32_t serial, const hidl_string& dtmf, int32_t on,
2096                                       int32_t off) {
2097 #if VDBG
2098     RLOGD("sendBurstDtmf: serial %d", serial);
2099 #endif
2100     dispatchStrings(serial, mSlotId, RIL_REQUEST_CDMA_BURST_DTMF, false,
2101             3, dtmf.c_str(), (std::to_string(on)).c_str(),
2102             (std::to_string(off)).c_str());
2103     return Void();
2104 }
2105 
constructCdmaSms(RIL_CDMA_SMS_Message & rcsm,const CdmaSmsMessage & sms)2106 void constructCdmaSms(RIL_CDMA_SMS_Message &rcsm, const CdmaSmsMessage& sms) {
2107     rcsm.uTeleserviceID = sms.teleserviceId;
2108     rcsm.bIsServicePresent = BOOL_TO_INT(sms.isServicePresent);
2109     rcsm.uServicecategory = sms.serviceCategory;
2110     rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) sms.address.digitMode;
2111     rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) sms.address.numberMode;
2112     rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) sms.address.numberType;
2113     rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) sms.address.numberPlan;
2114 
2115     rcsm.sAddress.number_of_digits = sms.address.digits.size();
2116     int digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
2117     for (int i = 0; i < digitLimit; i++) {
2118         rcsm.sAddress.digits[i] = sms.address.digits[i];
2119     }
2120 
2121     rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) sms.subAddress.subaddressType;
2122     rcsm.sSubAddress.odd = BOOL_TO_INT(sms.subAddress.odd);
2123 
2124     rcsm.sSubAddress.number_of_digits = sms.subAddress.digits.size();
2125     digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
2126     for (int i = 0; i < digitLimit; i++) {
2127         rcsm.sSubAddress.digits[i] = sms.subAddress.digits[i];
2128     }
2129 
2130     rcsm.uBearerDataLen = sms.bearerData.size();
2131     digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
2132     for (int i = 0; i < digitLimit; i++) {
2133         rcsm.aBearerData[i] = sms.bearerData[i];
2134     }
2135 }
2136 
sendCdmaSms(int32_t serial,const CdmaSmsMessage & sms)2137 Return<void> RadioImpl_1_6::sendCdmaSms(int32_t serial, const CdmaSmsMessage& sms) {
2138 #if VDBG
2139     RLOGD("sendCdmaSms: serial %d", serial);
2140 #endif
2141     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SEND_SMS);
2142     if (pRI == NULL) {
2143         return Void();
2144     }
2145 
2146     RIL_CDMA_SMS_Message rcsm = {};
2147     constructCdmaSms(rcsm, sms);
2148 
2149     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
2150     return Void();
2151 }
2152 
sendCdmaSms_1_6(int32_t serial,const CdmaSmsMessage & sms)2153 Return<void> RadioImpl_1_6::sendCdmaSms_1_6(int32_t serial, const CdmaSmsMessage& sms) {
2154 #if VDBG
2155     RLOGD("sendCdmaSms: serial %d", serial);
2156 #endif
2157     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SEND_SMS);
2158     if (pRI == NULL) {
2159         return Void();
2160     }
2161 
2162     RIL_CDMA_SMS_Message rcsm = {};
2163     constructCdmaSms(rcsm, sms);
2164 
2165     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
2166     return Void();
2167 }
2168 
acknowledgeLastIncomingCdmaSms(int32_t serial,const CdmaSmsAck & smsAck)2169 Return<void> RadioImpl_1_6::acknowledgeLastIncomingCdmaSms(int32_t serial, const CdmaSmsAck& smsAck) {
2170 #if VDBG
2171     RLOGD("acknowledgeLastIncomingCdmaSms: serial %d", serial);
2172 #endif
2173     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE);
2174     if (pRI == NULL) {
2175         return Void();
2176     }
2177 
2178     RIL_CDMA_SMS_Ack rcsa = {};
2179 
2180     rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) smsAck.errorClass;
2181     rcsa.uSMSCauseCode = smsAck.smsCauseCode;
2182 
2183     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa), pRI, mSlotId);
2184     return Void();
2185 }
2186 
getGsmBroadcastConfig(int32_t serial)2187 Return<void> RadioImpl_1_6::getGsmBroadcastConfig(int32_t serial) {
2188 #if VDBG
2189     RLOGD("getGsmBroadcastConfig: serial %d", serial);
2190 #endif
2191     dispatchVoid(serial, mSlotId, RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG);
2192     return Void();
2193 }
2194 
setGsmBroadcastConfig(int32_t serial,const hidl_vec<GsmBroadcastSmsConfigInfo> & configInfo)2195 Return<void> RadioImpl_1_6::setGsmBroadcastConfig(int32_t serial,
2196                                               const hidl_vec<GsmBroadcastSmsConfigInfo>&
2197                                               configInfo) {
2198 #if VDBG
2199     RLOGD("setGsmBroadcastConfig: serial %d", serial);
2200 #endif
2201     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2202             RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG);
2203     if (pRI == NULL) {
2204         return Void();
2205     }
2206 
2207     int num = configInfo.size();
2208     if (num > MAX_BROADCAST_SMS_CONFIG_INFO) {
2209         RLOGE("setGsmBroadcastConfig: Invalid configInfo length %s",
2210                 requestToString(pRI->pCI->requestNumber));
2211         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2212         return Void();
2213     }
2214     RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
2215     RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
2216 
2217     for (int i = 0 ; i < num ; i++ ) {
2218         gsmBciPtrs[i] = &gsmBci[i];
2219         gsmBci[i].fromServiceId = configInfo[i].fromServiceId;
2220         gsmBci[i].toServiceId = configInfo[i].toServiceId;
2221         gsmBci[i].fromCodeScheme = configInfo[i].fromCodeScheme;
2222         gsmBci[i].toCodeScheme = configInfo[i].toCodeScheme;
2223         gsmBci[i].selected = BOOL_TO_INT(configInfo[i].selected);
2224     }
2225 
2226     CALL_ONREQUEST(pRI->pCI->requestNumber, gsmBciPtrs,
2227             num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *), pRI, mSlotId);
2228     return Void();
2229 }
2230 
setGsmBroadcastActivation(int32_t serial,bool activate)2231 Return<void> RadioImpl_1_6::setGsmBroadcastActivation(int32_t serial, bool activate) {
2232 #if VDBG
2233     RLOGD("setGsmBroadcastActivation: serial %d", serial);
2234 #endif
2235     dispatchInts(serial, mSlotId, RIL_REQUEST_GSM_SMS_BROADCAST_ACTIVATION,
2236             1, BOOL_TO_INT(!activate));
2237     return Void();
2238 }
2239 
getCdmaBroadcastConfig(int32_t serial)2240 Return<void> RadioImpl_1_6::getCdmaBroadcastConfig(int32_t serial) {
2241 #if VDBG
2242     RLOGD("getCdmaBroadcastConfig: serial %d", serial);
2243 #endif
2244     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG);
2245     return Void();
2246 }
2247 
setCdmaBroadcastConfig(int32_t serial,const hidl_vec<CdmaBroadcastSmsConfigInfo> & configInfo)2248 Return<void> RadioImpl_1_6::setCdmaBroadcastConfig(int32_t serial,
2249                                                const hidl_vec<CdmaBroadcastSmsConfigInfo>&
2250                                                configInfo) {
2251 #if VDBG
2252     RLOGD("setCdmaBroadcastConfig: serial %d", serial);
2253 #endif
2254     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2255             RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG);
2256     if (pRI == NULL) {
2257         return Void();
2258     }
2259 
2260     int num = configInfo.size();
2261     if (num > MAX_BROADCAST_SMS_CONFIG_INFO) {
2262         RLOGE("setCdmaBroadcastConfig: Invalid configInfo length %s",
2263                 requestToString(pRI->pCI->requestNumber));
2264         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2265         return Void();
2266     }
2267     RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
2268     RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
2269 
2270     for (int i = 0 ; i < num ; i++ ) {
2271         cdmaBciPtrs[i] = &cdmaBci[i];
2272         cdmaBci[i].service_category = configInfo[i].serviceCategory;
2273         cdmaBci[i].language = configInfo[i].language;
2274         cdmaBci[i].selected = BOOL_TO_INT(configInfo[i].selected);
2275     }
2276 
2277     CALL_ONREQUEST(pRI->pCI->requestNumber, cdmaBciPtrs,
2278             num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *), pRI, mSlotId);
2279     return Void();
2280 }
2281 
setCdmaBroadcastActivation(int32_t serial,bool activate)2282 Return<void> RadioImpl_1_6::setCdmaBroadcastActivation(int32_t serial, bool activate) {
2283 #if VDBG
2284     RLOGD("setCdmaBroadcastActivation: serial %d", serial);
2285 #endif
2286     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION,
2287             1, BOOL_TO_INT(!activate));
2288     return Void();
2289 }
2290 
getCDMASubscription(int32_t serial)2291 Return<void> RadioImpl_1_6::getCDMASubscription(int32_t serial) {
2292 #if VDBG
2293     RLOGD("getCDMASubscription: serial %d", serial);
2294 #endif
2295     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_SUBSCRIPTION);
2296     return Void();
2297 }
2298 
writeSmsToRuim(int32_t serial,const CdmaSmsWriteArgs & cdmaSms)2299 Return<void> RadioImpl_1_6::writeSmsToRuim(int32_t serial, const CdmaSmsWriteArgs& cdmaSms) {
2300 #if VDBG
2301     RLOGD("writeSmsToRuim: serial %d", serial);
2302 #endif
2303     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2304             RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM);
2305     if (pRI == NULL) {
2306         return Void();
2307     }
2308 
2309     RIL_CDMA_SMS_WriteArgs rcsw = {};
2310     rcsw.status = (int) cdmaSms.status;
2311     constructCdmaSms(rcsw.message, cdmaSms.message);
2312 
2313     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw), pRI, mSlotId);
2314     return Void();
2315 }
2316 
deleteSmsOnRuim(int32_t serial,int32_t index)2317 Return<void> RadioImpl_1_6::deleteSmsOnRuim(int32_t serial, int32_t index) {
2318 #if VDBG
2319     RLOGD("deleteSmsOnRuim: serial %d", serial);
2320 #endif
2321     dispatchInts(serial, mSlotId, RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM, 1, index);
2322     return Void();
2323 }
2324 
getDeviceIdentity(int32_t serial)2325 Return<void> RadioImpl_1_6::getDeviceIdentity(int32_t serial) {
2326 #if VDBG
2327     RLOGD("getDeviceIdentity: serial %d", serial);
2328 #endif
2329     dispatchVoid(serial, mSlotId, RIL_REQUEST_DEVICE_IDENTITY);
2330     return Void();
2331 }
2332 
exitEmergencyCallbackMode(int32_t serial)2333 Return<void> RadioImpl_1_6::exitEmergencyCallbackMode(int32_t serial) {
2334 #if VDBG
2335     RLOGD("exitEmergencyCallbackMode: serial %d", serial);
2336 #endif
2337     dispatchVoid(serial, mSlotId, RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE);
2338     return Void();
2339 }
2340 
getSmscAddress(int32_t serial)2341 Return<void> RadioImpl_1_6::getSmscAddress(int32_t serial) {
2342 #if VDBG
2343     RLOGD("getSmscAddress: serial %d", serial);
2344 #endif
2345     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SMSC_ADDRESS);
2346     return Void();
2347 }
2348 
setSmscAddress(int32_t serial,const hidl_string & smsc)2349 Return<void> RadioImpl_1_6::setSmscAddress(int32_t serial, const hidl_string& smsc) {
2350 #if VDBG
2351     RLOGD("setSmscAddress: serial %d", serial);
2352 #endif
2353     dispatchString(serial, mSlotId, RIL_REQUEST_SET_SMSC_ADDRESS,
2354             smsc.c_str());
2355     return Void();
2356 }
2357 
reportSmsMemoryStatus(int32_t serial,bool available)2358 Return<void> RadioImpl_1_6::reportSmsMemoryStatus(int32_t serial, bool available) {
2359 #if VDBG
2360     RLOGD("reportSmsMemoryStatus: serial %d", serial);
2361 #endif
2362     dispatchInts(serial, mSlotId, RIL_REQUEST_REPORT_SMS_MEMORY_STATUS, 1,
2363             BOOL_TO_INT(available));
2364     return Void();
2365 }
2366 
reportStkServiceIsRunning(int32_t serial)2367 Return<void> RadioImpl_1_6::reportStkServiceIsRunning(int32_t serial) {
2368 #if VDBG
2369     RLOGD("reportStkServiceIsRunning: serial %d", serial);
2370 #endif
2371     dispatchVoid(serial, mSlotId, RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING);
2372     return Void();
2373 }
2374 
getCdmaSubscriptionSource(int32_t serial)2375 Return<void> RadioImpl_1_6::getCdmaSubscriptionSource(int32_t serial) {
2376 #if VDBG
2377     RLOGD("getCdmaSubscriptionSource: serial %d", serial);
2378 #endif
2379     dispatchVoid(serial, mSlotId, RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE);
2380     return Void();
2381 }
2382 
requestIsimAuthentication(int32_t serial,const hidl_string & challenge)2383 Return<void> RadioImpl_1_6::requestIsimAuthentication(int32_t serial, const hidl_string& challenge) {
2384 #if VDBG
2385     RLOGD("requestIsimAuthentication: serial %d", serial);
2386 #endif
2387     dispatchString(serial, mSlotId, RIL_REQUEST_ISIM_AUTHENTICATION,
2388             challenge.c_str());
2389     return Void();
2390 }
2391 
acknowledgeIncomingGsmSmsWithPdu(int32_t serial,bool success,const hidl_string & ackPdu)2392 Return<void> RadioImpl_1_6::acknowledgeIncomingGsmSmsWithPdu(int32_t serial, bool success,
2393                                                          const hidl_string& ackPdu) {
2394 #if VDBG
2395     RLOGD("acknowledgeIncomingGsmSmsWithPdu: serial %d", serial);
2396 #endif
2397     dispatchStrings(serial, mSlotId, RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU, false,
2398             2, success ? "1" : "0", ackPdu.c_str());
2399     return Void();
2400 }
2401 
sendEnvelopeWithStatus(int32_t serial,const hidl_string & contents)2402 Return<void> RadioImpl_1_6::sendEnvelopeWithStatus(int32_t serial, const hidl_string& contents) {
2403 #if VDBG
2404     RLOGD("sendEnvelopeWithStatus: serial %d", serial);
2405 #endif
2406     dispatchString(serial, mSlotId, RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS,
2407             contents.c_str());
2408     return Void();
2409 }
2410 
getVoiceRadioTechnology(int32_t serial)2411 Return<void> RadioImpl_1_6::getVoiceRadioTechnology(int32_t serial) {
2412 #if VDBG
2413     RLOGD("getVoiceRadioTechnology: serial %d", serial);
2414 #endif
2415     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_RADIO_TECH);
2416     return Void();
2417 }
2418 
getCellInfoList(int32_t serial)2419 Return<void> RadioImpl_1_6::getCellInfoList(int32_t serial) {
2420 #if VDBG
2421     RLOGD("getCellInfoList: serial %d", serial);
2422 #endif
2423     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CELL_INFO_LIST);
2424     return Void();
2425 }
2426 
getCellInfoList_1_6(int32_t serial)2427 Return<void> RadioImpl_1_6::getCellInfoList_1_6(int32_t serial) {
2428 #if VDBG
2429     RLOGD("getCellInfoList_1_6: serial %d", serial);
2430 #endif
2431     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CELL_INFO_LIST);
2432     return Void();
2433 }
2434 
setCellInfoListRate(int32_t serial,int32_t rate)2435 Return<void> RadioImpl_1_6::setCellInfoListRate(int32_t serial, int32_t rate) {
2436 #if VDBG
2437     RLOGD("setCellInfoListRate: serial %d", serial);
2438 #endif
2439     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE, 1, rate);
2440     return Void();
2441 }
2442 
setInitialAttachApn(int32_t serial,const DataProfileInfo & dataProfileInfo,bool modemCognitive,bool isRoaming)2443 Return<void> RadioImpl_1_6::setInitialAttachApn(int32_t serial, const DataProfileInfo& dataProfileInfo,
2444                                             bool modemCognitive, bool isRoaming) {
2445 #if VDBG
2446     RLOGD("setInitialAttachApn: serial %d", serial);
2447 #endif
2448     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2449             RIL_REQUEST_SET_INITIAL_ATTACH_APN);
2450     if (pRI == NULL) {
2451         return Void();
2452     }
2453 
2454     if (s_vendorFunctions->version <= 14) {
2455         RIL_InitialAttachApn iaa = {};
2456 
2457         if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) {
2458             return Void();
2459         }
2460 
2461         const hidl_string &protocol =
2462                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
2463 
2464         if (!copyHidlStringToRil(&iaa.protocol, protocol, pRI)) {
2465             memsetAndFreeStrings(1, iaa.apn);
2466             return Void();
2467         }
2468         iaa.authtype = (int) dataProfileInfo.authType;
2469         if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) {
2470             memsetAndFreeStrings(2, iaa.apn, iaa.protocol);
2471             return Void();
2472         }
2473         if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) {
2474             memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.username);
2475             return Void();
2476         }
2477 
2478         CALL_ONREQUEST(RIL_REQUEST_SET_INITIAL_ATTACH_APN, &iaa, sizeof(iaa), pRI, mSlotId);
2479 
2480         memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.username, iaa.password);
2481     } else {
2482         RIL_InitialAttachApn_v15 iaa = {};
2483 
2484         if (!copyHidlStringToRil(&iaa.apn, dataProfileInfo.apn, pRI, true)) {
2485             return Void();
2486         }
2487 
2488         if (!copyHidlStringToRil(&iaa.protocol, dataProfileInfo.protocol, pRI)) {
2489             memsetAndFreeStrings(1, iaa.apn);
2490             return Void();
2491         }
2492         if (!copyHidlStringToRil(&iaa.roamingProtocol, dataProfileInfo.roamingProtocol, pRI)) {
2493             memsetAndFreeStrings(2, iaa.apn, iaa.protocol);
2494             return Void();
2495         }
2496         iaa.authtype = (int) dataProfileInfo.authType;
2497         if (!copyHidlStringToRil(&iaa.username, dataProfileInfo.user, pRI)) {
2498             memsetAndFreeStrings(3, iaa.apn, iaa.protocol, iaa.roamingProtocol);
2499             return Void();
2500         }
2501         if (!copyHidlStringToRil(&iaa.password, dataProfileInfo.password, pRI)) {
2502             memsetAndFreeStrings(4, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username);
2503             return Void();
2504         }
2505         iaa.supportedTypesBitmask = dataProfileInfo.supportedApnTypesBitmap;
2506         iaa.bearerBitmask = dataProfileInfo.bearerBitmap;
2507         iaa.modemCognitive = BOOL_TO_INT(modemCognitive);
2508         iaa.mtu = dataProfileInfo.mtu;
2509 
2510         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, iaa.mvnoType)) {
2511             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2512             memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
2513                     iaa.password);
2514             return Void();
2515         }
2516 
2517         if (!copyHidlStringToRil(&iaa.mvnoMatchData, dataProfileInfo.mvnoMatchData, pRI)) {
2518             memsetAndFreeStrings(5, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
2519                     iaa.password);
2520             return Void();
2521         }
2522 
2523         CALL_ONREQUEST(RIL_REQUEST_SET_INITIAL_ATTACH_APN, &iaa, sizeof(iaa), pRI, mSlotId);
2524 
2525         memsetAndFreeStrings(6, iaa.apn, iaa.protocol, iaa.roamingProtocol, iaa.username,
2526                 iaa.password, iaa.mvnoMatchData);
2527     }
2528 
2529     return Void();
2530 }
2531 
getImsRegistrationState(int32_t serial)2532 Return<void> RadioImpl_1_6::getImsRegistrationState(int32_t serial) {
2533 #if VDBG
2534     RLOGD("getImsRegistrationState: serial %d", serial);
2535 #endif
2536     dispatchVoid(serial, mSlotId, RIL_REQUEST_IMS_REGISTRATION_STATE);
2537     return Void();
2538 }
2539 
dispatchImsGsmSms(const ImsSmsMessage & message,RequestInfo * pRI)2540 bool dispatchImsGsmSms(const ImsSmsMessage& message, RequestInfo *pRI) {
2541     RIL_IMS_SMS_Message rism = {};
2542     char **pStrings;
2543     int countStrings = 2;
2544     int dataLen = sizeof(char *) * countStrings;
2545 
2546     rism.tech = RADIO_TECH_3GPP;
2547     rism.retry = BOOL_TO_INT(message.retry);
2548     rism.messageRef = message.messageRef;
2549 
2550     if (message.gsmMessage.size() != 1) {
2551         RLOGE("dispatchImsGsmSms: Invalid len %s", requestToString(pRI->pCI->requestNumber));
2552         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2553         return false;
2554     }
2555 
2556     pStrings = (char **)calloc(countStrings, sizeof(char *));
2557     if (pStrings == NULL) {
2558         RLOGE("dispatchImsGsmSms: Memory allocation failed for request %s",
2559                 requestToString(pRI->pCI->requestNumber));
2560         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
2561         return false;
2562     }
2563 
2564     if (!copyHidlStringToRil(&pStrings[0], message.gsmMessage[0].smscPdu, pRI)) {
2565 #ifdef MEMSET_FREED
2566         memset(pStrings, 0, dataLen);
2567 #endif
2568         free(pStrings);
2569         return false;
2570     }
2571 
2572     if (!copyHidlStringToRil(&pStrings[1], message.gsmMessage[0].pdu, pRI)) {
2573         memsetAndFreeStrings(1, pStrings[0]);
2574 #ifdef MEMSET_FREED
2575         memset(pStrings, 0, dataLen);
2576 #endif
2577         free(pStrings);
2578         return false;
2579     }
2580 
2581     rism.message.gsmMessage = pStrings;
2582     CALL_ONREQUEST(pRI->pCI->requestNumber, &rism, sizeof(RIL_RadioTechnologyFamily) +
2583             sizeof(uint8_t) + sizeof(int32_t) + dataLen, pRI, pRI->socket_id);
2584 
2585     for (int i = 0 ; i < countStrings ; i++) {
2586         memsetAndFreeStrings(1, pStrings[i]);
2587     }
2588 
2589 #ifdef MEMSET_FREED
2590     memset(pStrings, 0, dataLen);
2591 #endif
2592     free(pStrings);
2593 
2594     return true;
2595 }
2596 
2597 struct ImsCdmaSms {
2598     RIL_IMS_SMS_Message imsSms;
2599     RIL_CDMA_SMS_Message cdmaSms;
2600 };
2601 
dispatchImsCdmaSms(const ImsSmsMessage & message,RequestInfo * pRI)2602 bool dispatchImsCdmaSms(const ImsSmsMessage& message, RequestInfo *pRI) {
2603     ImsCdmaSms temp = {};
2604 
2605     if (message.cdmaMessage.size() != 1) {
2606         RLOGE("dispatchImsCdmaSms: Invalid len %s", requestToString(pRI->pCI->requestNumber));
2607         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2608         return false;
2609     }
2610 
2611     temp.imsSms.tech = RADIO_TECH_3GPP2;
2612     temp.imsSms.retry = BOOL_TO_INT(message.retry);
2613     temp.imsSms.messageRef = message.messageRef;
2614     temp.imsSms.message.cdmaMessage = &temp.cdmaSms;
2615 
2616     constructCdmaSms(temp.cdmaSms, message.cdmaMessage[0]);
2617 
2618     // Vendor code expects payload length to include actual msg payload
2619     // (sizeof(RIL_CDMA_SMS_Message)) instead of (RIL_CDMA_SMS_Message *) + size of other fields in
2620     // RIL_IMS_SMS_Message
2621     int payloadLen = sizeof(RIL_RadioTechnologyFamily) + sizeof(uint8_t) + sizeof(int32_t)
2622             + sizeof(RIL_CDMA_SMS_Message);
2623 
2624     CALL_ONREQUEST(pRI->pCI->requestNumber, &temp.imsSms, payloadLen, pRI, pRI->socket_id);
2625 
2626     return true;
2627 }
2628 
sendImsSms(int32_t serial,const ImsSmsMessage & message)2629 Return<void> RadioImpl_1_6::sendImsSms(int32_t serial, const ImsSmsMessage& message) {
2630 #if VDBG
2631     RLOGD("sendImsSms: serial %d", serial);
2632 #endif
2633     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_IMS_SEND_SMS);
2634     if (pRI == NULL) {
2635         return Void();
2636     }
2637 
2638     RIL_RadioTechnologyFamily format = (RIL_RadioTechnologyFamily) message.tech;
2639 
2640     if (RADIO_TECH_3GPP == format) {
2641         dispatchImsGsmSms(message, pRI);
2642     } else if (RADIO_TECH_3GPP2 == format) {
2643         dispatchImsCdmaSms(message, pRI);
2644     } else {
2645         RLOGE("sendImsSms: Invalid radio tech %s",
2646                 requestToString(pRI->pCI->requestNumber));
2647         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
2648     }
2649     return Void();
2650 }
2651 
iccTransmitApduBasicChannel(int32_t serial,const SimApdu & message)2652 Return<void> RadioImpl_1_6::iccTransmitApduBasicChannel(int32_t serial, const SimApdu& message) {
2653 #if VDBG
2654     RLOGD("iccTransmitApduBasicChannel: serial %d", serial);
2655 #endif
2656     dispatchIccApdu(serial, mSlotId, RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC, message);
2657     return Void();
2658 }
2659 
iccOpenLogicalChannel(int32_t serial,const hidl_string & aid,int32_t p2)2660 Return<void> RadioImpl_1_6::iccOpenLogicalChannel(int32_t serial, const hidl_string& aid, int32_t p2) {
2661 #if VDBG
2662     RLOGD("iccOpenLogicalChannel: serial %d", serial);
2663 #endif
2664     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_OPEN_CHANNEL);
2665     if (pRI == NULL) {
2666         return Void();
2667     }
2668 
2669     RIL_OpenChannelParams params = {};
2670 
2671     params.p2 = p2;
2672 
2673     if (!copyHidlStringToRil(&params.aidPtr, aid, pRI)) {
2674         return Void();
2675     }
2676 
2677     CALL_ONREQUEST(pRI->pCI->requestNumber, &params, sizeof(params), pRI, mSlotId);
2678 
2679     memsetAndFreeStrings(1, params.aidPtr);
2680     return Void();
2681 }
2682 
iccCloseLogicalChannel(int32_t serial,int32_t channelId)2683 Return<void> RadioImpl_1_6::iccCloseLogicalChannel(int32_t serial, int32_t channelId) {
2684 #if VDBG
2685     RLOGD("iccCloseLogicalChannel: serial %d", serial);
2686 #endif
2687     dispatchInts(serial, mSlotId, RIL_REQUEST_SIM_CLOSE_CHANNEL, 1, channelId);
2688     return Void();
2689 }
2690 
iccTransmitApduLogicalChannel(int32_t serial,const SimApdu & message)2691 Return<void> RadioImpl_1_6::iccTransmitApduLogicalChannel(int32_t serial, const SimApdu& message) {
2692 #if VDBG
2693     RLOGD("iccTransmitApduLogicalChannel: serial %d", serial);
2694 #endif
2695     dispatchIccApdu(serial, mSlotId, RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL, message);
2696     return Void();
2697 }
2698 
nvReadItem(int32_t serial,NvItem itemId)2699 Return<void> RadioImpl_1_6::nvReadItem(int32_t serial, NvItem itemId) {
2700 #if VDBG
2701     RLOGD("nvReadItem: serial %d", serial);
2702 #endif
2703     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_NV_READ_ITEM);
2704     if (pRI == NULL) {
2705         return Void();
2706     }
2707 
2708     RIL_NV_ReadItem nvri = {};
2709     nvri.itemID = (RIL_NV_Item) itemId;
2710 
2711     CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, mSlotId);
2712     return Void();
2713 }
2714 
nvWriteItem(int32_t serial,const NvWriteItem & item)2715 Return<void> RadioImpl_1_6::nvWriteItem(int32_t serial, const NvWriteItem& item) {
2716 #if VDBG
2717     RLOGD("nvWriteItem: serial %d", serial);
2718 #endif
2719     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_NV_WRITE_ITEM);
2720     if (pRI == NULL) {
2721         return Void();
2722     }
2723 
2724     RIL_NV_WriteItem nvwi = {};
2725 
2726     nvwi.itemID = (RIL_NV_Item) item.itemId;
2727 
2728     if (!copyHidlStringToRil(&nvwi.value, item.value, pRI)) {
2729         return Void();
2730     }
2731 
2732     CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, mSlotId);
2733 
2734     memsetAndFreeStrings(1, nvwi.value);
2735     return Void();
2736 }
2737 
nvWriteCdmaPrl(int32_t serial,const hidl_vec<uint8_t> & prl)2738 Return<void> RadioImpl_1_6::nvWriteCdmaPrl(int32_t serial, const hidl_vec<uint8_t>& prl) {
2739 #if VDBG
2740     RLOGD("nvWriteCdmaPrl: serial %d", serial);
2741 #endif
2742     dispatchRaw(serial, mSlotId, RIL_REQUEST_NV_WRITE_CDMA_PRL, prl);
2743     return Void();
2744 }
2745 
nvResetConfig(int32_t serial,ResetNvType resetType)2746 Return<void> RadioImpl_1_6::nvResetConfig(int32_t serial, ResetNvType resetType) {
2747     int rilResetType = -1;
2748 #if VDBG
2749     RLOGD("nvResetConfig: serial %d", serial);
2750 #endif
2751     /* Convert ResetNvType to RIL.h values
2752      * RIL_REQUEST_NV_RESET_CONFIG
2753      * 1 - reload all NV items
2754      * 2 - erase NV reset (SCRTN)
2755      * 3 - factory reset (RTN)
2756      */
2757     switch(resetType) {
2758       case ResetNvType::RELOAD:
2759         rilResetType = 1;
2760         break;
2761       case ResetNvType::ERASE:
2762         rilResetType = 2;
2763         break;
2764       case ResetNvType::FACTORY_RESET:
2765         rilResetType = 3;
2766         break;
2767     }
2768     dispatchInts(serial, mSlotId, RIL_REQUEST_NV_RESET_CONFIG, 1, rilResetType);
2769     return Void();
2770 }
2771 
setUiccSubscription(int32_t serial,const SelectUiccSub & uiccSub)2772 Return<void> RadioImpl_1_6::setUiccSubscription(int32_t serial, const SelectUiccSub& uiccSub) {
2773 #if VDBG
2774     RLOGD("setUiccSubscription: serial %d", serial);
2775 #endif
2776     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
2777             RIL_REQUEST_SET_UICC_SUBSCRIPTION);
2778     if (pRI == NULL) {
2779         return Void();
2780     }
2781 
2782     RIL_SelectUiccSub rilUiccSub = {};
2783 
2784     rilUiccSub.slot = uiccSub.slot;
2785     rilUiccSub.app_index = uiccSub.appIndex;
2786     rilUiccSub.sub_type = (RIL_SubscriptionType) uiccSub.subType;
2787     rilUiccSub.act_status = (RIL_UiccSubActStatus) uiccSub.actStatus;
2788 
2789     CALL_ONREQUEST(pRI->pCI->requestNumber, &rilUiccSub, sizeof(rilUiccSub), pRI, mSlotId);
2790     return Void();
2791 }
2792 
setDataAllowed(int32_t serial,bool allow)2793 Return<void> RadioImpl_1_6::setDataAllowed(int32_t serial, bool allow) {
2794 #if VDBG
2795     RLOGD("setDataAllowed: serial %d", serial);
2796 #endif
2797     dispatchInts(serial, mSlotId, RIL_REQUEST_ALLOW_DATA, 1, BOOL_TO_INT(allow));
2798     return Void();
2799 }
2800 
getHardwareConfig(int32_t serial)2801 Return<void> RadioImpl_1_6::getHardwareConfig(int32_t serial) {
2802 #if VDBG
2803     RLOGD("getHardwareConfig: serial %d", serial);
2804 #endif
2805     RLOGD("getHardwareConfig: serial %d, mSlotId = %d", serial, mSlotId);
2806     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_HARDWARE_CONFIG);
2807     return Void();
2808 }
2809 
requestIccSimAuthentication(int32_t serial,int32_t authContext,const hidl_string & authData,const hidl_string & aid)2810 Return<void> RadioImpl_1_6::requestIccSimAuthentication(int32_t serial, int32_t authContext,
2811         const hidl_string& authData, const hidl_string& aid) {
2812 #if VDBG
2813     RLOGD("requestIccSimAuthentication: serial %d", serial);
2814 #endif
2815     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SIM_AUTHENTICATION);
2816     if (pRI == NULL) {
2817         return Void();
2818     }
2819 
2820     RIL_SimAuthentication pf = {};
2821 
2822     pf.authContext = authContext;
2823 
2824     if (!copyHidlStringToRil(&pf.authData, authData, pRI)) {
2825         return Void();
2826     }
2827 
2828     if (!copyHidlStringToRil(&pf.aid, aid, pRI)) {
2829         memsetAndFreeStrings(1, pf.authData);
2830         return Void();
2831     }
2832 
2833     CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, mSlotId);
2834 
2835     memsetAndFreeStrings(2, pf.authData, pf.aid);
2836     return Void();
2837 }
2838 
2839 /**
2840  * @param numProfiles number of data profile
2841  * @param dataProfiles the pointer to the actual data profiles. The acceptable type is
2842           RIL_DataProfileInfo or RIL_DataProfileInfo_v15.
2843  * @param dataProfilePtrs the pointer to the pointers that point to each data profile structure
2844  * @param numfields number of string-type member in the data profile structure
2845  * @param ... the variadic parameters are pointers to each string-type member
2846  **/
2847 template <typename T>
freeSetDataProfileData(int numProfiles,T * dataProfiles,T ** dataProfilePtrs,int numfields,...)2848 void freeSetDataProfileData(int numProfiles, T *dataProfiles, T **dataProfilePtrs,
2849                             int numfields, ...) {
2850     va_list args;
2851     va_start(args, numfields);
2852 
2853     // Iterate through each string-type field that need to be free.
2854     for (int i = 0; i < numfields; i++) {
2855         // Iterate through each data profile and free that specific string-type field.
2856         // The type 'char *T::*' is a type of pointer to a 'char *' member inside T structure.
2857         char *T::*ptr = va_arg(args, char *T::*);
2858         for (int j = 0; j < numProfiles; j++) {
2859             memsetAndFreeStrings(1, dataProfiles[j].*ptr);
2860         }
2861     }
2862 
2863     va_end(args);
2864 
2865 #ifdef MEMSET_FREED
2866     memset(dataProfiles, 0, numProfiles * sizeof(T));
2867     memset(dataProfilePtrs, 0, numProfiles * sizeof(T *));
2868 #endif
2869     free(dataProfiles);
2870     free(dataProfilePtrs);
2871 }
2872 
setDataProfile(int32_t serial,const hidl_vec<DataProfileInfo> & profiles,bool isRoaming)2873 Return<void> RadioImpl_1_6::setDataProfile(int32_t serial, const hidl_vec<DataProfileInfo>& profiles,
2874                                        bool isRoaming) {
2875 #if VDBG
2876     RLOGD("setDataProfile: serial %d", serial);
2877 #endif
2878     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SET_DATA_PROFILE);
2879     if (pRI == NULL) {
2880         return Void();
2881     }
2882 
2883     size_t num = profiles.size();
2884     bool success = false;
2885 
2886     if (s_vendorFunctions->version <= 14) {
2887 
2888         RIL_DataProfileInfo *dataProfiles =
2889             (RIL_DataProfileInfo *) calloc(num, sizeof(RIL_DataProfileInfo));
2890 
2891         if (dataProfiles == NULL) {
2892             RLOGE("Memory allocation failed for request %s",
2893                     requestToString(pRI->pCI->requestNumber));
2894             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
2895             return Void();
2896         }
2897 
2898         RIL_DataProfileInfo **dataProfilePtrs =
2899             (RIL_DataProfileInfo **) calloc(num, sizeof(RIL_DataProfileInfo *));
2900         if (dataProfilePtrs == NULL) {
2901             RLOGE("Memory allocation failed for request %s",
2902                     requestToString(pRI->pCI->requestNumber));
2903             free(dataProfiles);
2904             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
2905             return Void();
2906         }
2907 
2908         for (size_t i = 0; i < num; i++) {
2909             dataProfilePtrs[i] = &dataProfiles[i];
2910 
2911             success = copyHidlStringToRil(&dataProfiles[i].apn, profiles[i].apn, pRI, true);
2912 
2913             const hidl_string &protocol =
2914                     (isRoaming ? profiles[i].roamingProtocol : profiles[i].protocol);
2915 
2916             if (success && !copyHidlStringToRil(&dataProfiles[i].protocol, protocol, pRI, true)) {
2917                 success = false;
2918             }
2919 
2920             if (success && !copyHidlStringToRil(&dataProfiles[i].user, profiles[i].user, pRI,
2921                     true)) {
2922                 success = false;
2923             }
2924             if (success && !copyHidlStringToRil(&dataProfiles[i].password, profiles[i].password,
2925                     pRI, true)) {
2926                 success = false;
2927             }
2928 
2929             if (!success) {
2930                 freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 4,
2931                     &RIL_DataProfileInfo::apn, &RIL_DataProfileInfo::protocol,
2932                     &RIL_DataProfileInfo::user, &RIL_DataProfileInfo::password);
2933                 return Void();
2934             }
2935 
2936             dataProfiles[i].profileId = (RIL_DataProfile) profiles[i].profileId;
2937             dataProfiles[i].authType = (int) profiles[i].authType;
2938             dataProfiles[i].type = (int) profiles[i].type;
2939             dataProfiles[i].maxConnsTime = profiles[i].maxConnsTime;
2940             dataProfiles[i].maxConns = profiles[i].maxConns;
2941             dataProfiles[i].waitTime = profiles[i].waitTime;
2942             dataProfiles[i].enabled = BOOL_TO_INT(profiles[i].enabled);
2943         }
2944 
2945         CALL_ONREQUEST(RIL_REQUEST_SET_DATA_PROFILE, dataProfilePtrs,
2946                 num * sizeof(RIL_DataProfileInfo *), pRI, mSlotId);
2947 
2948         freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 4,
2949                 &RIL_DataProfileInfo::apn, &RIL_DataProfileInfo::protocol,
2950                 &RIL_DataProfileInfo::user, &RIL_DataProfileInfo::password);
2951     } else {
2952         RIL_DataProfileInfo_v15 *dataProfiles =
2953             (RIL_DataProfileInfo_v15 *) calloc(num, sizeof(RIL_DataProfileInfo_v15));
2954 
2955         if (dataProfiles == NULL) {
2956             RLOGE("Memory allocation failed for request %s",
2957                     requestToString(pRI->pCI->requestNumber));
2958             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
2959             return Void();
2960         }
2961 
2962         RIL_DataProfileInfo_v15 **dataProfilePtrs =
2963             (RIL_DataProfileInfo_v15 **) calloc(num, sizeof(RIL_DataProfileInfo_v15 *));
2964         if (dataProfilePtrs == NULL) {
2965             RLOGE("Memory allocation failed for request %s",
2966                     requestToString(pRI->pCI->requestNumber));
2967             free(dataProfiles);
2968             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
2969             return Void();
2970         }
2971 
2972         for (size_t i = 0; i < num; i++) {
2973             dataProfilePtrs[i] = &dataProfiles[i];
2974 
2975             success = copyHidlStringToRil(&dataProfiles[i].apn, profiles[i].apn, pRI, true);
2976             if (success && !copyHidlStringToRil(&dataProfiles[i].protocol, profiles[i].protocol,
2977                     pRI)) {
2978                 success = false;
2979             }
2980             if (success && !copyHidlStringToRil(&dataProfiles[i].roamingProtocol,
2981                     profiles[i].roamingProtocol, pRI, true)) {
2982                 success = false;
2983             }
2984             if (success && !copyHidlStringToRil(&dataProfiles[i].user, profiles[i].user, pRI,
2985                     true)) {
2986                 success = false;
2987             }
2988             if (success && !copyHidlStringToRil(&dataProfiles[i].password, profiles[i].password,
2989                     pRI, true)) {
2990                 success = false;
2991             }
2992             if (success && !copyHidlStringToRil(&dataProfiles[i].mvnoMatchData,
2993                     profiles[i].mvnoMatchData, pRI, true)) {
2994                 success = false;
2995             }
2996 
2997             if (success && !convertMvnoTypeToString(profiles[i].mvnoType,
2998                     dataProfiles[i].mvnoType)) {
2999                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3000                 success = false;
3001             }
3002 
3003             if (!success) {
3004                 freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 6,
3005                     &RIL_DataProfileInfo_v15::apn, &RIL_DataProfileInfo_v15::protocol,
3006                     &RIL_DataProfileInfo_v15::roamingProtocol, &RIL_DataProfileInfo_v15::user,
3007                     &RIL_DataProfileInfo_v15::password, &RIL_DataProfileInfo_v15::mvnoMatchData);
3008                 return Void();
3009             }
3010 
3011             dataProfiles[i].profileId = (RIL_DataProfile) profiles[i].profileId;
3012             dataProfiles[i].authType = (int) profiles[i].authType;
3013             dataProfiles[i].type = (int) profiles[i].type;
3014             dataProfiles[i].maxConnsTime = profiles[i].maxConnsTime;
3015             dataProfiles[i].maxConns = profiles[i].maxConns;
3016             dataProfiles[i].waitTime = profiles[i].waitTime;
3017             dataProfiles[i].enabled = BOOL_TO_INT(profiles[i].enabled);
3018             dataProfiles[i].supportedTypesBitmask = profiles[i].supportedApnTypesBitmap;
3019             dataProfiles[i].bearerBitmask = profiles[i].bearerBitmap;
3020             dataProfiles[i].mtu = profiles[i].mtu;
3021         }
3022 
3023         CALL_ONREQUEST(RIL_REQUEST_SET_DATA_PROFILE, dataProfilePtrs,
3024                 num * sizeof(RIL_DataProfileInfo_v15 *), pRI, mSlotId);
3025 
3026         freeSetDataProfileData(num, dataProfiles, dataProfilePtrs, 6,
3027                 &RIL_DataProfileInfo_v15::apn, &RIL_DataProfileInfo_v15::protocol,
3028                 &RIL_DataProfileInfo_v15::roamingProtocol, &RIL_DataProfileInfo_v15::user,
3029                 &RIL_DataProfileInfo_v15::password, &RIL_DataProfileInfo_v15::mvnoMatchData);
3030     }
3031 
3032     return Void();
3033 }
3034 
requestShutdown(int32_t serial)3035 Return<void> RadioImpl_1_6::requestShutdown(int32_t serial) {
3036 #if VDBG
3037     RLOGD("requestShutdown: serial %d", serial);
3038 #endif
3039     dispatchVoid(serial, mSlotId, RIL_REQUEST_SHUTDOWN);
3040     return Void();
3041 }
3042 
getRadioCapability(int32_t serial)3043 Return<void> RadioImpl_1_6::getRadioCapability(int32_t serial) {
3044 #if VDBG
3045     RLOGD("getRadioCapability: serial %d", serial);
3046 #endif
3047     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_RADIO_CAPABILITY);
3048     return Void();
3049 }
3050 
setRadioCapability(int32_t serial,const RadioCapability & rc)3051 Return<void> RadioImpl_1_6::setRadioCapability(int32_t serial, const RadioCapability& rc) {
3052 #if VDBG
3053     RLOGD("setRadioCapability: serial %d", serial);
3054 #endif
3055     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_SET_RADIO_CAPABILITY);
3056     if (pRI == NULL) {
3057         return Void();
3058     }
3059 
3060     RIL_RadioCapability rilRc = {};
3061 
3062     // TODO : set rilRc.version using HIDL version ?
3063     rilRc.session = rc.session;
3064     rilRc.phase = (int) rc.phase;
3065     rilRc.rat = (int) rc.raf;
3066     rilRc.status = (int) rc.status;
3067     strlcpy(rilRc.logicalModemUuid, rc.logicalModemUuid.c_str(), sizeof(rilRc.logicalModemUuid));
3068 
3069     CALL_ONREQUEST(pRI->pCI->requestNumber, &rilRc, sizeof(rilRc), pRI, mSlotId);
3070 
3071     return Void();
3072 }
3073 
startLceService(int32_t serial,int32_t reportInterval,bool pullMode)3074 Return<void> RadioImpl_1_6::startLceService(int32_t serial, int32_t reportInterval, bool pullMode) {
3075 #if VDBG
3076     RLOGD("startLceService: serial %d", serial);
3077 #endif
3078     dispatchInts(serial, mSlotId, RIL_REQUEST_START_LCE, 2, reportInterval,
3079             BOOL_TO_INT(pullMode));
3080     return Void();
3081 }
3082 
stopLceService(int32_t serial)3083 Return<void> RadioImpl_1_6::stopLceService(int32_t serial) {
3084 #if VDBG
3085     RLOGD("stopLceService: serial %d", serial);
3086 #endif
3087     dispatchVoid(serial, mSlotId, RIL_REQUEST_STOP_LCE);
3088     return Void();
3089 }
3090 
pullLceData(int32_t serial)3091 Return<void> RadioImpl_1_6::pullLceData(int32_t serial) {
3092 #if VDBG
3093     RLOGD("pullLceData: serial %d", serial);
3094 #endif
3095     dispatchVoid(serial, mSlotId, RIL_REQUEST_PULL_LCEDATA);
3096     return Void();
3097 }
3098 
getModemActivityInfo(int32_t serial)3099 Return<void> RadioImpl_1_6::getModemActivityInfo(int32_t serial) {
3100 #if VDBG
3101     RLOGD("getModemActivityInfo: serial %d", serial);
3102 #endif
3103     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_ACTIVITY_INFO);
3104     return Void();
3105 }
3106 
prepareCarrierRestrictions(RIL_CarrierRestrictions & request,bool allAllowed,const hidl_vec<Carrier> & allowedList,const hidl_vec<Carrier> & excludedList,RequestInfo * pRI)3107 int prepareCarrierRestrictions(RIL_CarrierRestrictions &request, bool allAllowed,
3108                                const hidl_vec<Carrier>& allowedList,
3109                                const hidl_vec<Carrier>& excludedList,
3110                                RequestInfo *pRI) {
3111     RIL_Carrier *allowedCarriers = NULL;
3112     RIL_Carrier *excludedCarriers = NULL;
3113 
3114     request.len_allowed_carriers = allowedList.size();
3115     allowedCarriers = (RIL_Carrier *)calloc(request.len_allowed_carriers, sizeof(RIL_Carrier));
3116     if (allowedCarriers == NULL) {
3117         RLOGE("prepareCarrierRestrictions: Memory allocation failed for request %s",
3118                 requestToString(pRI->pCI->requestNumber));
3119         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3120         return -1;
3121     }
3122     request.allowed_carriers = allowedCarriers;
3123 
3124     request.len_excluded_carriers = excludedList.size();
3125     excludedCarriers = (RIL_Carrier *)calloc(request.len_excluded_carriers, sizeof(RIL_Carrier));
3126     if (excludedCarriers == NULL) {
3127         RLOGE("prepareCarrierRestrictions: Memory allocation failed for request %s",
3128                 requestToString(pRI->pCI->requestNumber));
3129         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3130 #ifdef MEMSET_FREED
3131         memset(allowedCarriers, 0, request.len_allowed_carriers * sizeof(RIL_Carrier));
3132 #endif
3133         free(allowedCarriers);
3134         return -1;
3135     }
3136     request.excluded_carriers = excludedCarriers;
3137 
3138     for (int i = 0; i < request.len_allowed_carriers; i++) {
3139         allowedCarriers[i].mcc = allowedList[i].mcc.c_str();
3140         allowedCarriers[i].mnc = allowedList[i].mnc.c_str();
3141         allowedCarriers[i].match_type = (RIL_CarrierMatchType) allowedList[i].matchType;
3142         allowedCarriers[i].match_data = allowedList[i].matchData.c_str();
3143     }
3144 
3145     for (int i = 0; i < request.len_excluded_carriers; i++) {
3146         excludedCarriers[i].mcc = excludedList[i].mcc.c_str();
3147         excludedCarriers[i].mnc = excludedList[i].mnc.c_str();
3148         excludedCarriers[i].match_type =
3149                 (RIL_CarrierMatchType) excludedList[i].matchType;
3150         excludedCarriers[i].match_data = excludedList[i].matchData.c_str();
3151     }
3152 
3153     return 0;
3154 }
3155 
freeCarrierRestrictions(RIL_CarrierRestrictions & request)3156 void freeCarrierRestrictions(RIL_CarrierRestrictions &request) {
3157     if (request.allowed_carriers != NULL) {
3158 #ifdef MEMSET_FREED
3159         memset(request.allowed_carriers, 0, request.len_allowed_carriers * sizeof(RIL_Carrier));
3160 #endif
3161         free(request.allowed_carriers);
3162     }
3163     if (request.excluded_carriers != NULL) {
3164 #ifdef MEMSET_FREED
3165         memset(request.excluded_carriers, 0, request.len_excluded_carriers * sizeof(RIL_Carrier));
3166 #endif
3167         free(request.excluded_carriers);
3168     }
3169 }
3170 
setAllowedCarriers(int32_t serial,bool allAllowed,const CarrierRestrictions & carriers)3171 Return<void> RadioImpl_1_6::setAllowedCarriers(int32_t serial, bool allAllowed,
3172                                            const CarrierRestrictions& carriers) {
3173 #if VDBG
3174     RLOGD("setAllowedCarriers: serial %d", serial);
3175 #endif
3176     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3177             RIL_REQUEST_SET_CARRIER_RESTRICTIONS);
3178     if (pRI == NULL) {
3179         return Void();
3180     }
3181 
3182     RIL_CarrierRestrictions cr = {};
3183     if (prepareCarrierRestrictions(cr, allAllowed, carriers.allowedCarriers,
3184             carriers.excludedCarriers, pRI) < 0) {
3185         return Void();
3186     }
3187 
3188     CALL_ONREQUEST(pRI->pCI->requestNumber, &cr, sizeof(RIL_CarrierRestrictions), pRI, mSlotId);
3189 
3190     freeCarrierRestrictions(cr);
3191 
3192     return Void();
3193 }
3194 
getAllowedCarriers(int32_t serial)3195 Return<void> RadioImpl_1_6::getAllowedCarriers(int32_t serial) {
3196 #if VDBG
3197     RLOGD("getAllowedCarriers: serial %d", serial);
3198 #endif
3199     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CARRIER_RESTRICTIONS);
3200     return Void();
3201 }
3202 
sendDeviceState(int32_t serial,DeviceStateType deviceStateType,bool state)3203 Return<void> RadioImpl_1_6::sendDeviceState(int32_t serial, DeviceStateType deviceStateType,
3204                                         bool state) {
3205 #if VDBG
3206     RLOGD("sendDeviceState: serial %d", serial);
3207 #endif
3208     if (s_vendorFunctions->version < 15) {
3209         if (deviceStateType ==  DeviceStateType::LOW_DATA_EXPECTED) {
3210             RLOGD("sendDeviceState: calling screen state %d", BOOL_TO_INT(!state));
3211             dispatchInts(serial, mSlotId, RIL_REQUEST_SCREEN_STATE, 1, BOOL_TO_INT(!state));
3212         } else {
3213             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3214                     RIL_REQUEST_SEND_DEVICE_STATE);
3215             sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
3216         }
3217         return Void();
3218     }
3219     dispatchInts(serial, mSlotId, RIL_REQUEST_SEND_DEVICE_STATE, 2, (int) deviceStateType,
3220             BOOL_TO_INT(state));
3221     return Void();
3222 }
3223 
setIndicationFilter(int32_t serial,int32_t indicationFilter)3224 Return<void> RadioImpl_1_6::setIndicationFilter(int32_t serial, int32_t indicationFilter) {
3225 #if VDBG
3226     RLOGD("setIndicationFilter: serial %d", serial);
3227 #endif
3228     if (s_vendorFunctions->version < 15) {
3229         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3230                 RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER);
3231         sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
3232         return Void();
3233     }
3234     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER, 1, indicationFilter);
3235     return Void();
3236 }
3237 
setSimCardPower(int32_t serial,bool powerUp)3238 Return<void> RadioImpl_1_6::setSimCardPower(int32_t serial, bool powerUp) {
3239 #if VDBG
3240     RLOGD("setSimCardPower: serial %d", serial);
3241 #endif
3242     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, BOOL_TO_INT(powerUp));
3243     return Void();
3244 }
3245 
setSimCardPower_1_1(int32_t serial,const V1_1::CardPowerState state)3246 Return<void> RadioImpl_1_6::setSimCardPower_1_1(int32_t serial, const V1_1::CardPowerState state) {
3247 #if VDBG
3248     RLOGD("setSimCardPower_1_1: serial %d state %d", serial, state);
3249 #endif
3250     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, state);
3251     return Void();
3252 }
3253 
setSimCardPower_1_6(int32_t serial,const V1_1::CardPowerState state)3254 Return<void> RadioImpl_1_6::setSimCardPower_1_6(int32_t serial, const V1_1::CardPowerState state) {
3255 #if VDBG
3256     RLOGD("setSimCardPower_1_6: serial %d state %d", serial, state);
3257 #endif
3258     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_SIM_CARD_POWER, 1, state);
3259     mSimCardPowerState = state;
3260     return Void();
3261 }
3262 
setCarrierInfoForImsiEncryption(int32_t serial,const V1_1::ImsiEncryptionInfo & data)3263 Return<void> RadioImpl_1_6::setCarrierInfoForImsiEncryption(int32_t serial,
3264         const V1_1::ImsiEncryptionInfo& data) {
3265 #if VDBG
3266     RLOGD("setCarrierInfoForImsiEncryption: serial %d", serial);
3267 #endif
3268     RequestInfo *pRI = android::addRequestToList(
3269             serial, mSlotId, RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION);
3270     if (pRI == NULL) {
3271         return Void();
3272     }
3273 
3274     RIL_CarrierInfoForImsiEncryption imsiEncryption = {};
3275 
3276     if (!copyHidlStringToRil(&imsiEncryption.mnc, data.mnc, pRI)) {
3277         return Void();
3278     }
3279     if (!copyHidlStringToRil(&imsiEncryption.mcc, data.mcc, pRI)) {
3280         memsetAndFreeStrings(1, imsiEncryption.mnc);
3281         return Void();
3282     }
3283     if (!copyHidlStringToRil(&imsiEncryption.keyIdentifier, data.keyIdentifier, pRI)) {
3284         memsetAndFreeStrings(2, imsiEncryption.mnc, imsiEncryption.mcc);
3285         return Void();
3286     }
3287     imsiEncryption.carrierKeyLength = data.carrierKey.size();
3288     imsiEncryption.carrierKey = new uint8_t[imsiEncryption.carrierKeyLength];
3289     memcpy(imsiEncryption.carrierKey, data.carrierKey.data(), imsiEncryption.carrierKeyLength);
3290     imsiEncryption.expirationTime = data.expirationTime;
3291     CALL_ONREQUEST(pRI->pCI->requestNumber, &imsiEncryption,
3292             sizeof(RIL_CarrierInfoForImsiEncryption), pRI, mSlotId);
3293     delete(imsiEncryption.carrierKey);
3294     return Void();
3295 }
3296 
startKeepalive(int32_t serial,const V1_1::KeepaliveRequest & keepalive)3297 Return<void> RadioImpl_1_6::startKeepalive(int32_t serial, const V1_1::KeepaliveRequest& keepalive) {
3298 #if VDBG
3299     RLOGD("%s(): %d", __FUNCTION__, serial);
3300 #endif
3301     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_KEEPALIVE);
3302     if (pRI == NULL) {
3303         return Void();
3304     }
3305 
3306     RIL_KeepaliveRequest kaReq = {};
3307 
3308     kaReq.type = static_cast<RIL_KeepaliveType>(keepalive.type);
3309     switch(kaReq.type) {
3310         case NATT_IPV4:
3311             if (keepalive.sourceAddress.size() != 4 ||
3312                     keepalive.destinationAddress.size() != 4) {
3313                 RLOGE("Invalid address for keepalive!");
3314                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3315                 return Void();
3316             }
3317             break;
3318         case NATT_IPV6:
3319             if (keepalive.sourceAddress.size() != 16 ||
3320                     keepalive.destinationAddress.size() != 16) {
3321                 RLOGE("Invalid address for keepalive!");
3322                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3323                 return Void();
3324             }
3325             break;
3326         default:
3327             RLOGE("Unknown packet keepalive type!");
3328             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3329             return Void();
3330     }
3331 
3332     ::memcpy(kaReq.sourceAddress, keepalive.sourceAddress.data(), keepalive.sourceAddress.size());
3333     kaReq.sourcePort = keepalive.sourcePort;
3334 
3335     ::memcpy(kaReq.destinationAddress,
3336             keepalive.destinationAddress.data(), keepalive.destinationAddress.size());
3337     kaReq.destinationPort = keepalive.destinationPort;
3338 
3339     kaReq.maxKeepaliveIntervalMillis = keepalive.maxKeepaliveIntervalMillis;
3340     kaReq.cid = keepalive.cid; // This is the context ID of the data call
3341 
3342     CALL_ONREQUEST(pRI->pCI->requestNumber, &kaReq, sizeof(RIL_KeepaliveRequest), pRI, mSlotId);
3343     return Void();
3344 }
3345 
stopKeepalive(int32_t serial,int32_t sessionHandle)3346 Return<void> RadioImpl_1_6::stopKeepalive(int32_t serial, int32_t sessionHandle) {
3347 #if VDBG
3348     RLOGD("%s(): %d", __FUNCTION__, serial);
3349 #endif
3350     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_STOP_KEEPALIVE);
3351     if (pRI == NULL) {
3352         return Void();
3353     }
3354 
3355     CALL_ONREQUEST(pRI->pCI->requestNumber, &sessionHandle, sizeof(uint32_t), pRI, mSlotId);
3356     return Void();
3357 }
3358 
responseAcknowledgement()3359 Return<void> RadioImpl_1_6::responseAcknowledgement() {
3360     android::releaseWakeLock();
3361     return Void();
3362 }
3363 
3364 // 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)3365 int prepareNetworkScanRequest_1_2(RIL_NetworkScanRequest &scan_request,
3366     const ::android::hardware::radio::V1_2::NetworkScanRequest& request,
3367     RequestInfo *pRI) {
3368 
3369     scan_request.type = (RIL_ScanType) request.type;
3370     scan_request.interval = request.interval;
3371     scan_request.specifiers_length = request.specifiers.size();
3372 
3373     int intervalLow = static_cast<int>(::android::hardware::radio::V1_2::ScanIntervalRange::MIN);
3374     int intervalHigh = static_cast<int>(::android::hardware::radio::V1_2::ScanIntervalRange::MAX);
3375     int maxSearchTimeLow =
3376         static_cast<int>(::android::hardware::radio::V1_2::MaxSearchTimeRange::MIN);
3377     int maxSearchTimeHigh =
3378         static_cast<int>(::android::hardware::radio::V1_2::MaxSearchTimeRange::MAX);
3379     int incrementalResultsPeriodicityRangeLow =
3380         static_cast<int>(::android::hardware::radio::V1_2::IncrementalResultsPeriodicityRange::MIN);
3381     int incrementalResultsPeriodicityRangeHigh =
3382         static_cast<int>(::android::hardware::radio::V1_2::IncrementalResultsPeriodicityRange::MAX);
3383     uint maxSpecifierSize =
3384         static_cast<uint>(::android::hardware::radio::V1_2::RadioConst
3385             ::RADIO_ACCESS_SPECIFIER_MAX_SIZE);
3386 
3387     if (request.interval < intervalLow || request.interval > intervalHigh) {
3388         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3389         return -1;
3390     }
3391     // If defined, must fall in correct range.
3392     if (request.maxSearchTime != 0
3393         && (request.maxSearchTime < maxSearchTimeLow
3394             || request.maxSearchTime > maxSearchTimeHigh)) {
3395         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3396         return -1;
3397     }
3398     if (request.maxSearchTime != 0
3399         && (request.incrementalResultsPeriodicity < incrementalResultsPeriodicityRangeLow
3400             || request.incrementalResultsPeriodicity > incrementalResultsPeriodicityRangeHigh
3401             || request.incrementalResultsPeriodicity > request.maxSearchTime)) {
3402         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3403         return -1;
3404     }
3405     if (request.specifiers.size() == 0 || request.specifiers.size() > maxSpecifierSize) {
3406         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3407         return -1;
3408     }
3409 
3410     for (size_t i = 0; i < request.specifiers.size(); ++i) {
3411         if (request.specifiers[i].geranBands.size() > MAX_BANDS ||
3412             request.specifiers[i].utranBands.size() > MAX_BANDS ||
3413             request.specifiers[i].eutranBands.size() > MAX_BANDS ||
3414             request.specifiers[i].channels.size() > MAX_CHANNELS) {
3415             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3416             return -1;
3417         }
3418         const V1_1::RadioAccessSpecifier& ras_from =
3419                 request.specifiers[i];
3420         RIL_RadioAccessSpecifier& ras_to = scan_request.specifiers[i];
3421 
3422         ras_to.radio_access_network = (RIL_RadioAccessNetworks) ras_from.radioAccessNetwork;
3423         ras_to.channels_length = ras_from.channels.size();
3424 
3425         std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
3426         const std::vector<uint32_t> * bands = nullptr;
3427         switch (request.specifiers[i].radioAccessNetwork) {
3428             case V1_1::RadioAccessNetworks::GERAN:
3429                 ras_to.bands_length = ras_from.geranBands.size();
3430                 bands = (std::vector<uint32_t> *) &ras_from.geranBands;
3431                 break;
3432             case V1_1::RadioAccessNetworks::UTRAN:
3433                 ras_to.bands_length = ras_from.utranBands.size();
3434                 bands = (std::vector<uint32_t> *) &ras_from.utranBands;
3435                 break;
3436             case V1_1::RadioAccessNetworks::EUTRAN:
3437                 ras_to.bands_length = ras_from.eutranBands.size();
3438                 bands = (std::vector<uint32_t> *) &ras_from.eutranBands;
3439                 break;
3440             default:
3441                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3442                 return -1;
3443         }
3444         // safe to copy to geran_bands because it's a union member
3445         for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
3446             ras_to.bands.geran_bands[idx] = (RIL_GeranBands) (*bands)[idx];
3447         }
3448     }
3449 
3450     return 0;
3451 }
3452 
startNetworkScan_1_2(int32_t serial,const::android::hardware::radio::V1_2::NetworkScanRequest & request)3453 Return<void> RadioImpl_1_6::startNetworkScan_1_2(int32_t serial,
3454         const ::android::hardware::radio::V1_2::NetworkScanRequest& request) {
3455 #if VDBG
3456     RLOGD("startNetworkScan_1_2: serial %d", serial);
3457 #endif
3458 
3459     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
3460     if (pRI == NULL) {
3461         return Void();
3462     }
3463 
3464     RIL_NetworkScanRequest scan_request = {};
3465 
3466     if (prepareNetworkScanRequest_1_2(scan_request, request, pRI) < 0) {
3467         return Void();
3468     }
3469 
3470     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
3471             mSlotId);
3472 
3473     return Void();
3474 }
3475 
setIndicationFilter_1_2(int32_t serial,::android::hardware::hidl_bitfield<V1_2::IndicationFilter> indicationFilter)3476 Return<void> RadioImpl_1_6::setIndicationFilter_1_2(int32_t serial,
3477         ::android::hardware::hidl_bitfield<V1_2::IndicationFilter> indicationFilter) {
3478 #if VDBG
3479     RLOGD("setIndicationFilter_1_2: serial %d", serial);
3480 #endif
3481 
3482     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3483             RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER);
3484     sendErrorResponse(pRI, RIL_E_SUCCESS);  // TODO: for vts
3485     return Void();
3486 }
3487 
setSignalStrengthReportingCriteria(int32_t serial,int32_t hysteresisMs,int32_t hysteresisDb,const hidl_vec<int32_t> & thresholdsDbm,::android::hardware::radio::V1_2::AccessNetwork accessNetwork)3488 Return<void> RadioImpl_1_6::setSignalStrengthReportingCriteria(int32_t serial,
3489         int32_t hysteresisMs, int32_t hysteresisDb,
3490         const hidl_vec<int32_t>& thresholdsDbm,
3491         ::android::hardware::radio::V1_2::AccessNetwork  accessNetwork) {
3492 #if VDBG
3493     RLOGD("setSignalStrengthReportingCriteria: %d", serial);
3494 #endif
3495     RIL_Errno e;
3496     if (radioService[mSlotId]->mRadioResponseV1_2 != NULL) {
3497          RadioResponseInfo responseInfo = {};
3498          if (hysteresisDb >= 10) {
3499              e = RIL_E_INVALID_ARGUMENTS;
3500          } else {
3501              e = RIL_E_SUCCESS;
3502          }
3503          populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, e);
3504          Return<void> retStatus
3505                    = radioService[mSlotId]->mRadioResponseV1_2->setSignalStrengthReportingCriteriaResponse(responseInfo);
3506          radioService[mSlotId]->checkReturnStatus(retStatus);
3507     } else {
3508         RLOGE("setIndicationFilterResponse: radioService[%d]->mRadioResponse == NULL",
3509            mSlotId);
3510     }
3511     return Void();
3512 }
3513 
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)3514 Return<void> RadioImpl_1_6::setLinkCapacityReportingCriteria(int32_t serial,
3515        int32_t hysteresisMs, int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
3516        const hidl_vec<int32_t>& thresholdsDownlinkKbps,
3517         const hidl_vec<int32_t>& thresholdsUplinkKbps,
3518         V1_2::AccessNetwork accessNetwork) {
3519 #if VDBG
3520     RLOGE("[%04d]< %s", serial, "Method is not implemented");
3521     RLOGD("setLinkCapacityReportingCriteria: %d", serial);
3522 #endif
3523 
3524     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3525             RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA);
3526     if (pRI == NULL) {
3527         return Void();
3528     }
3529     // TODO: for vts. hysteresisDlKbps and hysteresisUlKbps range not confirmed
3530     if (hysteresisDlKbps >= 5000 || hysteresisUlKbps >= 1000) {
3531         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3532         return Void();
3533     } else {
3534         sendErrorResponse(pRI, RIL_E_SUCCESS);
3535     }
3536     return Void();
3537 }
3538 
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)3539 Return<void> RadioImpl_1_6::setupDataCall_1_2(int32_t serial, V1_2::AccessNetwork accessNetwork,
3540         const V1_0::DataProfileInfo& dataProfileInfo, bool modemCognitive,
3541         bool roamingAllowed, bool isRoaming, V1_2::DataRequestReason reason,
3542         const hidl_vec<hidl_string>& addresses, const hidl_vec<hidl_string>& dnses) {
3543 #if VDBG
3544     RLOGE("[%04d]< %s", serial, "Method is not implemented");
3545     RLOGD("setupDataCall_1_2: serial %d", serial);
3546 #endif
3547 
3548     if (s_vendorFunctions->version >= 4 && s_vendorFunctions->version <= 14) {
3549         const hidl_string &protocol =
3550                 (isRoaming ? dataProfileInfo.roamingProtocol : dataProfileInfo.protocol);
3551         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 7,
3552             std::to_string((int)accessNetwork).c_str(),
3553             std::to_string((int)dataProfileInfo.profileId).c_str(),
3554             dataProfileInfo.apn.c_str(),
3555             dataProfileInfo.user.c_str(),
3556             dataProfileInfo.password.c_str(),
3557             std::to_string((int)dataProfileInfo.authType).c_str(),
3558             protocol.c_str());
3559     } else if (s_vendorFunctions->version >= 15) {
3560         char *mvnoTypeStr = NULL;
3561         if (!convertMvnoTypeToString(dataProfileInfo.mvnoType, mvnoTypeStr)) {
3562             RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3563                     RIL_REQUEST_SETUP_DATA_CALL);
3564             if (pRI != NULL) {
3565                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3566             }
3567             return Void();
3568         }
3569         dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15,
3570             std::to_string((int)accessNetwork).c_str(),
3571             std::to_string((int)dataProfileInfo.profileId).c_str(),
3572             dataProfileInfo.apn.c_str(),
3573             dataProfileInfo.user.c_str(),
3574             dataProfileInfo.password.c_str(),
3575             std::to_string((int) dataProfileInfo.authType).c_str(),
3576             dataProfileInfo.protocol.c_str(),
3577             dataProfileInfo.roamingProtocol.c_str(),
3578             std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
3579             std::to_string(dataProfileInfo.bearerBitmap).c_str(),
3580             modemCognitive ? "1" : "0",
3581             std::to_string(dataProfileInfo.mtu).c_str(),
3582             mvnoTypeStr,
3583             dataProfileInfo.mvnoMatchData.c_str(),
3584             roamingAllowed ? "1" : "0");
3585     } else {
3586         RLOGE("Unsupported RIL version %d, min version expected 4", s_vendorFunctions->version);
3587         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3588                 RIL_REQUEST_SETUP_DATA_CALL);
3589         if (pRI != NULL) {
3590             sendErrorResponse(pRI, RIL_E_REQUEST_NOT_SUPPORTED);
3591         }
3592     }
3593     return Void();
3594 }
3595 
deactivateDataCall_1_2(int32_t serial,int32_t cid,::android::hardware::radio::V1_2::DataRequestReason reason)3596 Return<void> RadioImpl_1_6::deactivateDataCall_1_2(int32_t serial, int32_t cid,
3597         ::android::hardware::radio::V1_2::DataRequestReason reason) {
3598 #if VDBG
3599     RLOGD("deactivateDataCall_1_2: serial %d", serial);
3600 #endif
3601 
3602     RIL_DataRequestReason dataRequestReason = (RIL_DataRequestReason)reason;
3603     const char *reasonStr = NULL;
3604     switch (dataRequestReason) {
3605         case DATA_REQ_REASOPN_NORMAL:
3606             reasonStr = "normal";
3607             break;
3608         case DATA_REQ_REASOPN_SHUTDOWN:
3609             reasonStr = "shutdown";
3610             break;
3611         case DATA_REQ_REASOPN_HANDOVER:
3612             reasonStr = "handover";
3613             break;
3614         default:
3615             reasonStr = "unknown";
3616             break;
3617     }
3618 
3619     dispatchStrings(serial, mSlotId, RIL_REQUEST_DEACTIVATE_DATA_CALL, false,
3620             2, (std::to_string(cid)).c_str(), reasonStr);
3621     return Void();
3622 }
3623 
3624 // Methods from ::android::hardware::radio::V1_3::IRadio follow.
setSystemSelectionChannels(int32_t serial,bool,const hidl_vec<::android::hardware::radio::V1_1::RadioAccessSpecifier> &)3625 Return<void> RadioImpl_1_6::setSystemSelectionChannels(int32_t serial, bool /* specifyChannels */,
3626         const hidl_vec<::android::hardware::radio::V1_1::RadioAccessSpecifier>& /* specifiers */) {
3627 #if VDBG
3628     RLOGD("setSystemSelectionChannels: serial %d", serial);
3629 #endif
3630     dispatchVoid(serial, mSlotId, RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS);
3631     return Void();
3632 }
3633 
enableModem(int32_t serial,bool)3634 Return<void> RadioImpl_1_6::enableModem(int32_t serial, bool /* on */) {
3635 #if VDBG
3636     RLOGE("enableModem: serial = %d", serial);
3637 #endif
3638     dispatchVoid(serial, mSlotId, RIL_REQUEST_ENABLE_MODEM);
3639     return Void();
3640 }
3641 
getModemStackStatus(int32_t serial)3642 Return<void> RadioImpl_1_6::getModemStackStatus(int32_t serial) {
3643 #if VDBG
3644     RLOGD("getModemStackStatus: serial %d", serial);
3645 #endif
3646     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_MODEM_STACK_STATUS);
3647     return Void();
3648 }
3649 
getProtocolString(const::android::hardware::radio::V1_4::PdpProtocolType protocolVal)3650 const char * getProtocolString(const ::android::hardware::radio::V1_4::PdpProtocolType protocolVal) {
3651     switch(protocolVal) {
3652         case ::android::hardware::radio::V1_4::PdpProtocolType::IP:
3653             return "IP";
3654         case ::android::hardware::radio::V1_4::PdpProtocolType::IPV6:
3655             return "IPV6";
3656         case ::android::hardware::radio::V1_4::PdpProtocolType::IPV4V6:
3657             return "IPV4V6";
3658         case ::android::hardware::radio::V1_4::PdpProtocolType::PPP:
3659             return "PPP";
3660         case ::android::hardware::radio::V1_4::PdpProtocolType::NON_IP:
3661             return "NON_IP";
3662         case ::android::hardware::radio::V1_4::PdpProtocolType::UNSTRUCTURED:
3663             return "UNSTRUCTURED";
3664         default:
3665             return "UNKNOWN";
3666     }
3667 }
3668 
3669 // Methods from ::android::hardware::radio::V1_4::IRadio follow.
setAllowedCarriers_1_4(int32_t serial,const V1_4::CarrierRestrictionsWithPriority & carriers,V1_4::SimLockMultiSimPolicy multiSimPolicy)3670 Return<void> RadioImpl_1_6::setAllowedCarriers_1_4(int32_t  serial,
3671         const V1_4::CarrierRestrictionsWithPriority& carriers,
3672         V1_4::SimLockMultiSimPolicy multiSimPolicy) {
3673 #if VDBG
3674     RLOGD("setAllowedCarriers_1_4: serial %d", serial);
3675 #endif
3676 
3677     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3678             RIL_REQUEST_SET_CARRIER_RESTRICTIONS);
3679     if (pRI == NULL) {
3680         return Void();
3681     }
3682 
3683     // Prepare legacy structure (defined in IRadio 1.0) to re-use existing code.
3684     RIL_CarrierRestrictions cr = {};
3685     if (prepareCarrierRestrictions(cr, false, carriers.allowedCarriers, carriers.excludedCarriers,
3686             pRI) < 0) {
3687         return Void();
3688     }
3689     // Copy the legacy structure into the new structure (defined in IRadio 1.4)
3690     RIL_CarrierRestrictionsWithPriority crExt = {};
3691     crExt.len_allowed_carriers = cr.len_allowed_carriers;
3692     crExt.allowed_carriers = cr.allowed_carriers;
3693     crExt.len_excluded_carriers = cr.len_excluded_carriers;
3694     crExt.excluded_carriers = cr.excluded_carriers;
3695     crExt.allowedCarriersPrioritized = BOOL_TO_INT(carriers.allowedCarriersPrioritized);
3696     crExt.multiSimPolicy = (RIL_SimLockMultiSimPolicy)multiSimPolicy;
3697 
3698     CALL_ONREQUEST(pRI->pCI->requestNumber, &crExt, sizeof(RIL_CarrierRestrictionsWithPriority),
3699             pRI, mSlotId);
3700 
3701     freeCarrierRestrictions(cr);
3702 
3703     return Void();
3704 }
3705 
getAllowedCarriers_1_4(int32_t serial)3706 Return<void> RadioImpl_1_6::getAllowedCarriers_1_4(int32_t serial) {
3707 #if VDBG
3708     RLOGD("getAllowedCarriers_1_4: serial %d", serial);
3709 #endif
3710     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_CARRIER_RESTRICTIONS);
3711     return Void();
3712 }
3713 
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> &)3714 Return<void> RadioImpl_1_6::setupDataCall_1_4(int32_t serial ,
3715         ::android::hardware::radio::V1_4::AccessNetwork /* accessNetwork */,
3716         const ::android::hardware::radio::V1_4::DataProfileInfo& dataProfileInfo,
3717         bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason /* reason */,
3718         const hidl_vec<hidl_string>& /* addresses */, const hidl_vec<hidl_string>& /* dnses */) {
3719 
3720 #if VDBG
3721     RLOGD("setupDataCall_1_4: serial %d", serial);
3722 #endif
3723 
3724     char *mvnoTypeStr = NULL;
3725     if (!convertMvnoTypeToString(MvnoType::IMSI, mvnoTypeStr)) {
3726         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3727                 RIL_REQUEST_SETUP_DATA_CALL);
3728         if (pRI != NULL) {
3729             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3730         }
3731         return Void();
3732     }
3733     dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 16,
3734         std::to_string((int) RadioTechnology::UNKNOWN + 2).c_str(),
3735         std::to_string((int) dataProfileInfo.profileId).c_str(),
3736         dataProfileInfo.apn.c_str(),
3737         dataProfileInfo.user.c_str(),
3738         dataProfileInfo.password.c_str(),
3739         std::to_string((int) dataProfileInfo.authType).c_str(),
3740         getProtocolString(dataProfileInfo.protocol),
3741         getProtocolString(dataProfileInfo.roamingProtocol),
3742         std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
3743         std::to_string(dataProfileInfo.bearerBitmap).c_str(),
3744         dataProfileInfo.persistent ? "1" : "0",
3745         std::to_string(dataProfileInfo.mtu).c_str(),
3746         mvnoTypeStr,
3747         "302720x94",
3748         roamingAllowed ? "1" : "0",
3749         "-1");
3750     return Void();
3751 }
3752 
setInitialAttachApn_1_4(int32_t serial,const::android::hardware::radio::V1_4::DataProfileInfo & dataProfileInfo)3753 Return<void> RadioImpl_1_6::setInitialAttachApn_1_4(int32_t  serial ,
3754         const ::android::hardware::radio::V1_4::DataProfileInfo& dataProfileInfo) {
3755     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3756             RIL_REQUEST_SET_INITIAL_ATTACH_APN);
3757     if (pRI == NULL) {
3758         return Void();
3759     }
3760 
3761     RadioResponseInfo responseInfo = {};
3762     populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
3763 
3764     if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
3765         Return<void> retStatus
3766                 = radioService[mSlotId]->mRadioResponseV1_4->setInitialAttachApnResponse(responseInfo);
3767         radioService[mSlotId]->checkReturnStatus(retStatus);
3768     } else if (radioService[mSlotId]->mRadioResponse != NULL) {
3769         Return<void> retStatus
3770                 = radioService[mSlotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo);
3771         radioService[mSlotId]->checkReturnStatus(retStatus);
3772     } else {
3773         RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
3774     }
3775 
3776     return Void();
3777 }
3778 
setDataProfile_1_4(int32_t serial,const hidl_vec<::android::hardware::radio::V1_4::DataProfileInfo> &)3779 Return<void> RadioImpl_1_6::setDataProfile_1_4(int32_t  serial ,
3780         const hidl_vec<::android::hardware::radio::V1_4::DataProfileInfo>& /* profiles */) {
3781     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3782             RIL_REQUEST_SET_DATA_PROFILE);
3783     if (pRI == NULL) {
3784         return Void();
3785     }
3786 
3787     RadioResponseInfo responseInfo = {};
3788     populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
3789 
3790     if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
3791         Return<void> retStatus
3792                 = radioService[mSlotId]->mRadioResponseV1_4->setDataProfileResponse(responseInfo);
3793         radioService[mSlotId]->checkReturnStatus(retStatus);
3794     } else if (radioService[mSlotId]->mRadioResponse != NULL) {
3795         Return<void> retStatus
3796                 = radioService[mSlotId]->mRadioResponse->setDataProfileResponse(responseInfo);
3797         radioService[mSlotId]->checkReturnStatus(retStatus);
3798     } else {
3799         RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
3800     }
3801 
3802     return Void();
3803 }
3804 
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)3805 Return<void> RadioImpl_1_6::emergencyDial(int32_t serial,
3806         const ::android::hardware::radio::V1_0::Dial& dialInfo,
3807         hidl_bitfield<android::hardware::radio::V1_4::EmergencyServiceCategory> categories,
3808         const hidl_vec<hidl_string>&  urns ,
3809         ::android::hardware::radio::V1_4::EmergencyCallRouting routing,
3810         bool fromEmergencyDialer, bool /* isTesting */) {
3811 #if VDBG
3812     RLOGD("emergencyDial: serial %d", serial);
3813 #endif
3814 
3815     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_EMERGENCY_DIAL);
3816     if (pRI == NULL) {
3817         return Void();
3818     }
3819 
3820     RIL_EmergencyDial eccDial = {};
3821     RIL_Dial& dial = eccDial.dialInfo;
3822     RIL_UUS_Info uusInfo = {};
3823 
3824     if (!copyHidlStringToRil(&dial.address, dialInfo.address, pRI)) {
3825         return Void();
3826     }
3827     dial.clir = (int) dialInfo.clir;
3828 
3829     if (dialInfo.uusInfo.size() != 0) {
3830         uusInfo.uusType = (RIL_UUS_Type) dialInfo.uusInfo[0].uusType;
3831         uusInfo.uusDcs = (RIL_UUS_DCS) dialInfo.uusInfo[0].uusDcs;
3832 
3833         if (dialInfo.uusInfo[0].uusData.size() == 0) {
3834             uusInfo.uusData = NULL;
3835             uusInfo.uusLength = 0;
3836         } else {
3837             if (!copyHidlStringToRil(&uusInfo.uusData, dialInfo.uusInfo[0].uusData, pRI)) {
3838                 memsetAndFreeStrings(1, dial.address);
3839                 return Void();
3840             }
3841             uusInfo.uusLength = dialInfo.uusInfo[0].uusData.size();
3842         }
3843 
3844         dial.uusInfo = &uusInfo;
3845     }
3846 
3847     eccDial.urnsNumber = urns.size();
3848     if (eccDial.urnsNumber != 0) {
3849         char **ppUrns = (char **)calloc(eccDial.urnsNumber, sizeof(char *));
3850         if (ppUrns == NULL) {
3851             RLOGE("Memory allocation failed for request %s",
3852                     requestToString(pRI->pCI->requestNumber));
3853             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3854             memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
3855             return Void();
3856         }
3857         for (uint32_t i = 0; i < eccDial.urnsNumber; i++) {
3858             if (!copyHidlStringToRil(&ppUrns[i], hidl_string(urns[i]), pRI)) {
3859                 for (uint32_t j = 0; j < i; j++) {
3860                     memsetAndFreeStrings(1, ppUrns[j]);
3861                 }
3862                 memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
3863                 free(ppUrns);
3864                 return Void();
3865             }
3866         }
3867         eccDial.urns = ppUrns;
3868     }
3869 
3870     eccDial.categories = (RIL_EmergencyServiceCategory)categories;
3871     eccDial.routing = (RIL_EmergencyCallRouting)routing;
3872     eccDial.fromEmergencyDialer = fromEmergencyDialer;
3873 
3874     CALL_ONREQUEST(RIL_REQUEST_EMERGENCY_DIAL, &eccDial, sizeof(RIL_EmergencyDial), pRI, mSlotId);
3875 
3876     memsetAndFreeStrings(2, dial.address, uusInfo.uusData);
3877     if (eccDial.urns != NULL) {
3878         for (size_t i = 0; i < eccDial.urnsNumber; i++) {
3879             memsetAndFreeStrings(1, eccDial.urns[i]);
3880         }
3881         free(eccDial.urns);
3882     }
3883     return Void();
3884 }
3885 
startNetworkScan_1_4(int32_t serial,const::android::hardware::radio::V1_2::NetworkScanRequest & request)3886 Return<void> RadioImpl_1_6::startNetworkScan_1_4(int32_t serial,
3887         const ::android::hardware::radio::V1_2::NetworkScanRequest& request) {
3888 #if VDBG
3889     RLOGD("startNetworkScan_1_4: serial %d", serial);
3890 #endif
3891 
3892     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
3893     if (pRI == NULL) {
3894         return Void();
3895     }
3896 
3897     RIL_NetworkScanRequest scan_request = {};
3898 
3899     if (prepareNetworkScanRequest_1_2(scan_request, request, pRI) < 0) {
3900         return Void();
3901     }
3902 
3903     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
3904             mSlotId);
3905 
3906     return Void();
3907 }
3908 
getPreferredNetworkTypeBitmap(int32_t serial)3909 Return<void> RadioImpl_1_6::getPreferredNetworkTypeBitmap(int32_t serial ) {
3910 #if VDBG
3911     RLOGD("getPreferredNetworkTypeBitmap: serial %d", serial);
3912 #endif
3913     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE_BITMAP);
3914     return Void();
3915 }
3916 
setPreferredNetworkTypeBitmap(int32_t serial,hidl_bitfield<RadioAccessFamily> networkTypeBitmap)3917 Return<void> RadioImpl_1_6::setPreferredNetworkTypeBitmap(
3918         int32_t serial, hidl_bitfield<RadioAccessFamily> networkTypeBitmap) {
3919 #if VDBG
3920     RLOGD("setPreferredNetworkTypeBitmap: serial %d", serial);
3921 #endif
3922     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE_BITMAP, 1, networkTypeBitmap);
3923     return Void();
3924 }
3925 
setAllowedNetworkTypesBitmap(uint32_t serial,hidl_bitfield<RadioAccessFamily> networkTypeBitmap)3926 Return<void> RadioImpl_1_6::setAllowedNetworkTypesBitmap(
3927         uint32_t serial, hidl_bitfield<RadioAccessFamily> networkTypeBitmap) {
3928 #if VDBG
3929     RLOGD("setAllowedNetworkTypesBitmap: serial %d", serial);
3930 #endif
3931     dispatchInts(serial, mSlotId, RIL_REQUEST_SET_ALLOWED_NETWORK_TYPES_BITMAP, 1, networkTypeBitmap);
3932     return Void();
3933 }
3934 
getAllowedNetworkTypesBitmap(int32_t serial)3935 Return<void> RadioImpl_1_6::getAllowedNetworkTypesBitmap(int32_t serial) {
3936 #if VDBG
3937     RLOGD("getAllowedNetworkTypesBitmap: serial %d", serial);
3938 #endif
3939     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_ALLOWED_NETWORK_TYPES_BITMAP);
3940     return Void();
3941 }
3942 
getSignalStrength_1_4(int32_t serial)3943 Return<void> RadioImpl_1_6::getSignalStrength_1_4(int32_t serial) {
3944 #if VDBG
3945     RLOGD("getSignalStrength_1_4: serial %d", serial);
3946 #endif
3947     dispatchVoid(serial, mSlotId, RIL_REQUEST_SIGNAL_STRENGTH);
3948     return Void();
3949 }
3950 
getSignalStrength_1_6(int32_t serial)3951 Return<void> RadioImpl_1_6::getSignalStrength_1_6(int32_t serial) {
3952 #if VDBG
3953     RLOGD("getSignalStrength_1_6: serial %d", serial);
3954 #endif
3955     dispatchVoid(serial, mSlotId, RIL_REQUEST_SIGNAL_STRENGTH);
3956     return Void();
3957 }
3958 
3959 // Methods from ::android::hardware::radio::V1_5::IRadio follow.
setSignalStrengthReportingCriteria_1_5(int32_t serial,const V1_5::SignalThresholdInfo & signalThresholdInfo,V1_5::AccessNetwork accessNetwork)3960 Return<void> RadioImpl_1_6::setSignalStrengthReportingCriteria_1_5(int32_t serial,
3961         const V1_5::SignalThresholdInfo& signalThresholdInfo,
3962         V1_5::AccessNetwork accessNetwork) {
3963 #if VDBG
3964     RLOGD("setSignalStrengthReportingCriteria_1_5: %d", serial);
3965 #endif
3966 
3967     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
3968             RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA);
3969     if (pRI == NULL) {
3970         return Void();
3971     }
3972 
3973     if (signalThresholdInfo.hysteresisDb >= 10) {  // TODO: for vts. hysteresisDb range not checked
3974         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
3975         return Void();
3976     }
3977 
3978     RIL_SignalStrengthReportingCriteria_v1_5 *criteria = (RIL_SignalStrengthReportingCriteria_v1_5 *)
3979             calloc(1, sizeof(RIL_SignalStrengthReportingCriteria_v1_5));
3980     if (criteria == NULL) {
3981         RLOGE("Memory allocation failed for request %s",
3982                 requestToString(pRI->pCI->requestNumber));
3983         sendErrorResponse(pRI, RIL_E_NO_MEMORY);
3984         return Void();
3985     }
3986 
3987     criteria->signalMeasurement = (SignalMeasurementType)signalThresholdInfo.signalMeasurement;
3988     criteria->isEnabled = signalThresholdInfo.isEnabled;
3989     criteria->hysteresisMs = signalThresholdInfo.hysteresisMs;
3990     criteria->hysteresisDb = signalThresholdInfo.hysteresisDb;
3991     criteria->thresholdsDbmNumber = signalThresholdInfo.thresholds.size();
3992     criteria->thresholdsDbm = new int32_t[criteria->thresholdsDbmNumber];
3993     memcpy(criteria->thresholdsDbm, signalThresholdInfo.thresholds.data(),
3994             criteria->thresholdsDbmNumber * sizeof(int32_t));
3995     criteria->accessNetwork = (RIL_RadioAccessNetworks_v1_5)accessNetwork;
3996 
3997     CALL_ONREQUEST(pRI->pCI->requestNumber, criteria,
3998             sizeof(RIL_SignalStrengthReportingCriteria_v1_5), pRI, mSlotId);
3999 
4000     return Void();
4001 }
4002 
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)4003 Return<void> RadioImpl_1_6::setLinkCapacityReportingCriteria_1_5(int32_t serial,
4004     int32_t hysteresisMs, int32_t hysteresisDlKbps, int32_t hysteresisUlKbps,
4005      const hidl_vec<int32_t>& thresholdsDownlinkKbps,
4006      const hidl_vec<int32_t>& thresholdsUplinkKbps,
4007      V1_5::AccessNetwork accessNetwork) {
4008 #if VDBG
4009  RLOGD("setLinkCapacityReportingCriteria_1_5: %d", serial);
4010 #endif
4011 
4012      RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4013              RIL_REQUEST_SET_LINK_CAPACITY_REPORTING_CRITERIA);
4014      if (pRI == NULL) {
4015          return Void();
4016      }
4017      // TODO: for vts. hysteresisDlKbps and hysteresisUlKbps range not confirmed
4018      if (hysteresisDlKbps >= 5000 || hysteresisUlKbps >= 1000) {
4019          sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4020          return Void();
4021      }
4022 
4023      RIL_LinkCapacityReportingCriteria *criteria = (RIL_LinkCapacityReportingCriteria *)
4024              calloc(1, sizeof(RIL_LinkCapacityReportingCriteria));
4025      if (criteria == NULL) {
4026          RLOGE("Memory allocation failed for request %s",
4027                  requestToString(pRI->pCI->requestNumber));
4028          sendErrorResponse(pRI, RIL_E_NO_MEMORY);
4029          return Void();
4030      }
4031 
4032      criteria->hysteresisMs = hysteresisMs;
4033      criteria->hysteresisDlKbps = hysteresisDlKbps;
4034      criteria->hysteresisUlKbps = hysteresisUlKbps;
4035      criteria->thresholdsDownlinkKbpsLength = thresholdsDownlinkKbps.size();
4036      criteria->thresholdsUplinkKbpsLength = thresholdsUplinkKbps.size();
4037      criteria->thresholdsDownlinkKbps = new int32_t[criteria->thresholdsDownlinkKbpsLength];
4038      criteria->thresholdsUplinkKbps = new int32_t[criteria->thresholdsUplinkKbpsLength];
4039      memcpy(criteria->thresholdsDownlinkKbps, thresholdsDownlinkKbps.data(),
4040              criteria->thresholdsDownlinkKbpsLength * sizeof(int32_t));
4041      memcpy(criteria->thresholdsUplinkKbps, thresholdsUplinkKbps.data(),
4042              criteria->thresholdsUplinkKbpsLength * sizeof(int32_t));
4043      criteria->accessNetwork = (RIL_RadioAccessNetworks_v1_5)accessNetwork;
4044 
4045      CALL_ONREQUEST(pRI->pCI->requestNumber, criteria,
4046              sizeof(RIL_LinkCapacityReportingCriteria), pRI, pRI->socket_id);
4047 
4048      return Void();
4049 }
4050 
enableUiccApplications(int32_t serial,bool enable)4051 Return<void> RadioImpl_1_6::enableUiccApplications(int32_t serial, bool enable) {
4052 #if VDBG
4053     RLOGD("enableUiccApplications: serial %d enable %d", serial, enable);
4054 #endif
4055     dispatchInts(serial, mSlotId, RIL_REQUEST_ENABLE_UICC_APPLICATIONS, 1, BOOL_TO_INT(enable));
4056     return Void();
4057 }
4058 
setRadioPower_1_5(int32_t serial,bool powerOn,bool forEmergencyCall,bool preferredForEmergencyCall)4059 Return<void> RadioImpl_1_6::setRadioPower_1_5(int32_t serial, bool powerOn, bool forEmergencyCall,
4060                                           bool preferredForEmergencyCall) {
4061 #if VDBG
4062     RLOGD("setRadioPower_1_6: serial %d powerOn %d forEmergency %d preferredForEmergencyCall %d",
4063         serial, powerOn, forEmergencyCall, preferredForEmergencyCall);
4064 #endif
4065     dispatchInts(serial, mSlotId, RIL_REQUEST_RADIO_POWER, 1, BOOL_TO_INT(powerOn));
4066     return Void();
4067 }
4068 
setRadioPower_1_6(int32_t serial,bool powerOn,bool forEmergencyCall,bool preferredForEmergencyCall)4069 Return<void> RadioImpl_1_6::setRadioPower_1_6(int32_t serial, bool powerOn, bool forEmergencyCall,
4070                                           bool preferredForEmergencyCall) {
4071 #if VDBG
4072     RLOGD("setRadioPower_1_6: serial %d powerOn %d forEmergency %d preferredForEmergencyCall %d",
4073         serial, powerOn, forEmergencyCall, preferredForEmergencyCall);
4074 #endif
4075     dispatchInts(serial, mSlotId, RIL_REQUEST_RADIO_POWER, 1, BOOL_TO_INT(powerOn));
4076     return Void();
4077 }
4078 
areUiccApplicationsEnabled(int32_t serial)4079 Return<void> RadioImpl_1_6::areUiccApplicationsEnabled(int32_t serial) {
4080 #if VDBG
4081     RLOGD("areUiccApplicationsEnabled: serial %d", serial);
4082 #endif
4083     dispatchVoid(serial, mSlotId, RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED);
4084     return Void();
4085 }
4086 
getVoiceRegistrationState_1_5(int32_t serial)4087 Return<void> RadioImpl_1_6::getVoiceRegistrationState_1_5(int32_t serial) {
4088 #if VDBG
4089     RLOGD("getVoiceRegistrationState_1_5: serial %d", serial);
4090 #endif
4091     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_REGISTRATION_STATE);
4092     return Void();
4093 }
4094 
getDataRegistrationState_1_5(int32_t serial)4095 Return<void> RadioImpl_1_6::getDataRegistrationState_1_5(int32_t serial) {
4096 #if VDBG
4097     RLOGD("getDataRegistrationState_1_5: serial %d", serial);
4098 #endif
4099     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_REGISTRATION_STATE);
4100     return Void();
4101 }
4102 
getVoiceRegistrationState_1_6(int32_t serial)4103 Return<void> RadioImpl_1_6::getVoiceRegistrationState_1_6(int32_t serial) {
4104 #if VDBG
4105     RLOGD("getVoiceRegistrationState_1_6: serial %d", serial);
4106 #endif
4107     dispatchVoid(serial, mSlotId, RIL_REQUEST_VOICE_REGISTRATION_STATE);
4108     return Void();
4109 }
4110 
getDataRegistrationState_1_6(int32_t serial)4111 Return<void> RadioImpl_1_6::getDataRegistrationState_1_6(int32_t serial) {
4112 #if VDBG
4113     RLOGD("getDataRegistrationState_1_6: serial %d", serial);
4114 #endif
4115     dispatchVoid(serial, mSlotId, RIL_REQUEST_DATA_REGISTRATION_STATE);
4116     return Void();
4117 }
4118 
setSystemSelectionChannels_1_5(int32_t serial,bool specifyChannels,const hidl_vec<V1_5::RadioAccessSpecifier> & specifiers)4119 Return<void> RadioImpl_1_6::setSystemSelectionChannels_1_5(int32_t serial,
4120         bool specifyChannels, const hidl_vec<V1_5::RadioAccessSpecifier>& specifiers) {
4121 
4122 #if VDBG
4123 RLOGD("setSystemSelectionChannels_1_5: %d", serial);
4124 #endif
4125 
4126     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4127                   RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS);
4128     if (pRI == NULL) {
4129       return Void();
4130     }
4131 
4132     if (specifiers.size() > RIL_RADIO_ACCESS_SPECIFIER_MAX_SIZE) {
4133       sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4134       return Void();
4135     }
4136 
4137     RIL_SystemSelectionChannels_v1_5 *sysSelectionChannels =
4138           (RIL_SystemSelectionChannels_v1_5 *)calloc(1, sizeof(RIL_SystemSelectionChannels_v1_5));
4139     if (sysSelectionChannels == NULL) {
4140       RLOGE("Memory allocation failed for request %s",
4141               requestToString(pRI->pCI->requestNumber));
4142       sendErrorResponse(pRI, RIL_E_NO_MEMORY);
4143       return Void();
4144     }
4145     sysSelectionChannels->specifyChannels = specifyChannels;
4146     sysSelectionChannels->specifiers_length = specifiers.size();
4147     for (size_t i = 0; i < specifiers.size(); ++i) {
4148       const V1_5::RadioAccessSpecifier& ras_from = specifiers[i];
4149       RIL_RadioAccessSpecifier_v1_5 &ras_to = sysSelectionChannels->specifiers[i];
4150 
4151       ras_to.radio_access_network = (RIL_RadioAccessNetworks_v1_5)ras_from.radioAccessNetwork;
4152       ras_to.channels_length = ras_from.channels.size();
4153 
4154       std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
4155       const std::vector<uint32_t> * bands = nullptr;
4156       switch (specifiers[i].radioAccessNetwork) {
4157           case V1_5::RadioAccessNetworks::GERAN:
4158               ras_to.bands_length = ras_from.bands.geranBands().size();
4159               bands = (std::vector<uint32_t> *) &ras_from.bands.geranBands();
4160               break;
4161           case V1_5::RadioAccessNetworks::UTRAN:
4162               ras_to.bands_length = ras_from.bands.utranBands().size();
4163               bands = (std::vector<uint32_t> *) &ras_from.bands.utranBands();
4164               break;
4165           case V1_5::RadioAccessNetworks::EUTRAN:
4166               ras_to.bands_length = ras_from.bands.eutranBands().size();
4167               bands = (std::vector<uint32_t> *) &ras_from.bands.eutranBands();
4168               break;
4169           case V1_5::RadioAccessNetworks::NGRAN:
4170               ras_to.bands_length = ras_from.bands.ngranBands().size();
4171               bands = (std::vector<uint32_t> *) &ras_from.bands.ngranBands();
4172               break;
4173           default: {
4174               sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4175               free(sysSelectionChannels);
4176               return Void();
4177           }
4178       }
4179       // safe to copy to geran_bands because it's a union member
4180       for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4181           ras_to.bands.geran_bands[idx] = (RIL_GeranBands)(*bands)[idx];
4182       }
4183     }
4184 
4185     CALL_ONREQUEST(RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS, sysSelectionChannels,
4186           sizeof(RIL_SystemSelectionChannels_v1_5), pRI, mSlotId);
4187 
4188     return Void();
4189 }
4190 
prepareNetworkScanRequest_1_5(RIL_NetworkScanRequest_v1_5 & scan_request,const V1_5::NetworkScanRequest & request,RequestInfo * pRI)4191 int prepareNetworkScanRequest_1_5(RIL_NetworkScanRequest_v1_5 &scan_request,
4192         const V1_5::NetworkScanRequest& request, RequestInfo *pRI) {
4193     scan_request.type = (RIL_ScanType) request.type;
4194     scan_request.interval = request.interval;
4195     scan_request.specifiers_length = request.specifiers.size();
4196     scan_request.maxSearchTime = request.maxSearchTime;
4197     scan_request.incrementalResults = request.incrementalResults;
4198     scan_request.incrementalResultsPeriodicity = request.incrementalResultsPeriodicity;
4199     scan_request.mccMncsNumbers = request.mccMncs.size();
4200 
4201     int intervalLow = static_cast<int>(V1_2::ScanIntervalRange::MIN);
4202     int intervalHigh = static_cast<int>(V1_2::ScanIntervalRange::MAX);
4203     int maxSearchTimeLow = static_cast<int>(V1_2::MaxSearchTimeRange::MIN);
4204     int maxSearchTimeHigh = static_cast<int>(V1_2::MaxSearchTimeRange::MAX);
4205     int incrementalResultsPeriodicityRangeLow =
4206             static_cast<int>(V1_2::IncrementalResultsPeriodicityRange::MIN);
4207     int incrementalResultsPeriodicityRangeHigh =
4208             static_cast<int>(V1_2::IncrementalResultsPeriodicityRange::MAX);
4209     uint maxSpecifierSize = static_cast<uint>(V1_2::RadioConst::RADIO_ACCESS_SPECIFIER_MAX_SIZE);
4210 
4211     if (request.interval < intervalLow || request.interval > intervalHigh) {
4212         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4213         return -1;
4214     }
4215     // If defined, must fall in correct range.
4216     if (request.maxSearchTime != 0 && (request.maxSearchTime < maxSearchTimeLow
4217             || request.maxSearchTime > maxSearchTimeHigh)) {
4218         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4219         return -1;
4220     }
4221     if (request.maxSearchTime != 0
4222             && (request.incrementalResultsPeriodicity < incrementalResultsPeriodicityRangeLow
4223             || request.incrementalResultsPeriodicity > incrementalResultsPeriodicityRangeHigh
4224             || request.incrementalResultsPeriodicity > request.maxSearchTime)) {
4225         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4226         return -1;
4227     }
4228     if (request.specifiers.size() == 0 || request.specifiers.size() > maxSpecifierSize) {
4229         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4230         return -1;
4231     }
4232 
4233     for (size_t i = 0; i < request.specifiers.size(); ++i) {
4234         if (request.specifiers[i].channels.size() > MAX_CHANNELS) {
4235             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4236             return -1;
4237         }
4238         switch (request.specifiers[i].bands.getDiscriminator()) {
4239             case V1_5::RadioAccessSpecifier::Bands::hidl_discriminator::geranBands:
4240                 if (request.specifiers[i].bands.geranBands().size() > MAX_BANDS) {
4241                   sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4242                   return -1;
4243                 }
4244                 break;
4245             case V1_5::RadioAccessSpecifier::Bands::hidl_discriminator::utranBands:
4246                 if (request.specifiers[i].bands.utranBands().size() > MAX_BANDS) {
4247                   sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4248                   return -1;
4249                 }
4250                 break;
4251             case V1_5::RadioAccessSpecifier::Bands::hidl_discriminator::eutranBands:
4252                 if (request.specifiers[i].bands.eutranBands().size() > MAX_BANDS) {
4253                   sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4254                   return -1;
4255                 }
4256                 break;
4257             case V1_5::RadioAccessSpecifier::Bands::hidl_discriminator::ngranBands:
4258                 if (request.specifiers[i].bands.ngranBands().size() > MAX_BANDS) {
4259                   sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4260                   return -1;
4261                 }
4262                 break;
4263             default:
4264               sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4265               return -1;
4266         }
4267 
4268         if (request.specifiers[i].channels.size() > MAX_CHANNELS) {
4269             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4270             return -1;
4271         }
4272 
4273         const V1_5::RadioAccessSpecifier& ras_from = request.specifiers[i];
4274         RIL_RadioAccessSpecifier_v1_5& ras_to = scan_request.specifiers[i];
4275 
4276         ras_to.radio_access_network = (RIL_RadioAccessNetworks_v1_5) ras_from.radioAccessNetwork;
4277         ras_to.channels_length = ras_from.channels.size();
4278 
4279         std::copy(ras_from.channels.begin(), ras_from.channels.end(), ras_to.channels);
4280         const std::vector<uint32_t> * bands = nullptr;
4281         switch (request.specifiers[i].radioAccessNetwork) {
4282             case V1_5::RadioAccessNetworks::GERAN:
4283                 ras_to.bands_length = ras_from.bands.geranBands().size();
4284 
4285                 bands = (std::vector<uint32_t> *) &ras_from.bands.geranBands();
4286                 // safe to copy to geran_bands because it's a union member
4287                 for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4288                     ras_to.bands.geran_bands[idx] = (RIL_GeranBands) (*bands)[idx];
4289                 }
4290                 break;
4291             case V1_5::RadioAccessNetworks::UTRAN:
4292                 ras_to.bands_length = ras_from.bands.utranBands().size();
4293                 bands = (std::vector<uint32_t> *) &ras_from.bands;
4294                 // safe to copy to geran_bands because it's a union member
4295                 for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4296                     ras_to.bands.utran_bands[idx] = (RIL_UtranBands) (*bands)[idx];
4297                 }
4298                 break;
4299             case V1_5::RadioAccessNetworks::EUTRAN:
4300                 ras_to.bands_length = ras_from.bands.eutranBands().size();
4301                 bands = (std::vector<uint32_t> *) &ras_from.bands;
4302                 // safe to copy to geran_bands because it's a union member
4303                 for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4304                     ras_to.bands.eutran_bands[idx] = (RIL_EutranBands) (*bands)[idx];
4305                 }
4306                 break;
4307             case V1_5::RadioAccessNetworks::NGRAN:
4308                 ras_to.bands_length = ras_from.bands.ngranBands().size();
4309                 bands = (std::vector<uint32_t> *) &ras_from.bands;
4310                 // safe to copy to geran_bands because it's a union member
4311                 for (size_t idx = 0; idx < ras_to.bands_length; ++idx) {
4312                     ras_to.bands.ngran_bands[idx] = (RIL_NgranBands) (*bands)[idx];
4313                 }
4314                 break;
4315             default:
4316                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4317                 return -1;
4318         }
4319     }
4320     if (scan_request.mccMncsNumbers != 0) {
4321         char **pStrings = (char **)calloc(scan_request.mccMncsNumbers, sizeof(char *));
4322         if (pStrings == NULL) {
4323             RLOGE("Memory allocation failed for request %s",
4324                     requestToString(pRI->pCI->requestNumber));
4325             sendErrorResponse(pRI, RIL_E_NO_MEMORY);
4326             return -1;
4327         }
4328         for (size_t i = 0; i < request.mccMncs.size(); ++i) {
4329             if (!copyHidlStringToRil(&pStrings[i], hidl_string(request.mccMncs[i]), pRI)) {
4330                 for (size_t j = 0; j < i; j++) {
4331                     memsetAndFreeStrings(1, pStrings[j]);
4332                 }
4333                 free(pStrings);
4334                 return -1;
4335             }
4336         }
4337         scan_request.mccMncs = pStrings;
4338     }
4339     return 0;
4340 }
4341 
startNetworkScan_1_5(int32_t serial,const::android::hardware::radio::V1_5::NetworkScanRequest & request)4342 Return<void> RadioImpl_1_6::startNetworkScan_1_5(int32_t serial,
4343         const ::android::hardware::radio::V1_5::NetworkScanRequest& request) {
4344 #if VDBG
4345     RLOGD("startNetworkScan_1_6: serial %d", serial);
4346 #endif
4347 
4348     RequestInfo *pRI = android::addRequestToList(serial, mSlotId, RIL_REQUEST_START_NETWORK_SCAN);
4349     if (pRI == NULL) {
4350         return Void();
4351     }
4352 
4353     RIL_NetworkScanRequest_v1_5 scan_request = {};
4354 
4355     if (prepareNetworkScanRequest_1_5(scan_request, request, pRI) < 0) {
4356         return Void();
4357     }
4358 
4359     CALL_ONREQUEST(RIL_REQUEST_START_NETWORK_SCAN, &scan_request, sizeof(scan_request), pRI,
4360             mSlotId);
4361 
4362     return Void();
4363 }
4364 
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> &)4365 Return<void> RadioImpl_1_6::setupDataCall_1_5(int32_t serial ,
4366         ::android::hardware::radio::V1_5::AccessNetwork /* accessNetwork */,
4367         const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
4368         bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason /* reason */,
4369         const hidl_vec<::android::hardware::radio::V1_5::LinkAddress>& /* addresses */,
4370         const hidl_vec<hidl_string>& /* dnses */) {
4371 
4372 #if VDBG
4373     RLOGD("setupDataCall_1_5: serial %d", serial);
4374 #endif
4375 
4376     char *mvnoTypeStr = NULL;
4377     if (!convertMvnoTypeToString(MvnoType::IMSI, mvnoTypeStr)) {
4378         RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4379                 RIL_REQUEST_SETUP_DATA_CALL);
4380         if (pRI != NULL) {
4381             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
4382         }
4383         return Void();
4384     }
4385     dispatchStrings(serial, mSlotId, RIL_REQUEST_SETUP_DATA_CALL, true, 15,
4386         std::to_string((int) RadioTechnology::UNKNOWN + 2).c_str(),
4387         std::to_string((int) dataProfileInfo.profileId).c_str(),
4388         dataProfileInfo.apn.c_str(),
4389         dataProfileInfo.user.c_str(),
4390         dataProfileInfo.password.c_str(),
4391         std::to_string((int) dataProfileInfo.authType).c_str(),
4392         getProtocolString(dataProfileInfo.protocol),
4393         getProtocolString(dataProfileInfo.roamingProtocol),
4394         std::to_string(dataProfileInfo.supportedApnTypesBitmap).c_str(),
4395         std::to_string(dataProfileInfo.bearerBitmap).c_str(),
4396         dataProfileInfo.persistent ? "1" : "0",
4397         std::to_string(dataProfileInfo.mtuV4).c_str(),
4398         std::to_string(dataProfileInfo.mtuV6).c_str(),
4399         mvnoTypeStr,
4400         "302720x94",
4401         roamingAllowed ? "1" : "0");
4402     return Void();
4403 }
4404 
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 &,bool matchAllRuleAllowed)4405 Return<void> RadioImpl_1_6::setupDataCall_1_6(int32_t serial ,
4406         ::android::hardware::radio::V1_5::AccessNetwork /* accessNetwork */,
4407         const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo,
4408         bool roamingAllowed, ::android::hardware::radio::V1_2::DataRequestReason /* reason */,
4409         const hidl_vec<::android::hardware::radio::V1_5::LinkAddress>& /* addresses */,
4410         const hidl_vec<hidl_string>& /* dnses */,
4411         int32_t /* pduSessionId */,
4412         const ::android::hardware::radio::V1_6::OptionalSliceInfo& /* sliceInfo */,
4413         const ::android::hardware::radio::V1_6::OptionalTrafficDescriptor& /*trafficDescriptor*/,
4414         bool matchAllRuleAllowed) {
4415 
4416 #if VDBG
4417     RLOGD("setupDataCall_1_6: 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, 16,
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 
setInitialAttachApn_1_5(int32_t serial,const::android::hardware::radio::V1_5::DataProfileInfo & dataProfileInfo)4449 Return<void> RadioImpl_1_6::setInitialAttachApn_1_5(int32_t  serial ,
4450         const ::android::hardware::radio::V1_5::DataProfileInfo& dataProfileInfo) {
4451     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4452             RIL_REQUEST_SET_INITIAL_ATTACH_APN);
4453     if (pRI == NULL) {
4454         return Void();
4455     }
4456 
4457     RadioResponseInfo responseInfo = {};
4458     populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
4459 
4460     if (radioService[mSlotId]->mRadioResponseV1_5 != NULL) {
4461         Return<void> retStatus
4462                 = radioService[mSlotId]->mRadioResponseV1_5->setInitialAttachApnResponse(responseInfo);
4463     } else if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
4464         Return<void> retStatus
4465                 = radioService[mSlotId]->mRadioResponseV1_4->setInitialAttachApnResponse(responseInfo);
4466         radioService[mSlotId]->checkReturnStatus(retStatus);
4467     } else if (radioService[mSlotId]->mRadioResponse != NULL) {
4468         Return<void> retStatus
4469                 = radioService[mSlotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo);
4470         radioService[mSlotId]->checkReturnStatus(retStatus);
4471     } else {
4472         RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
4473     }
4474 
4475     return Void();
4476 }
4477 
setDataProfile_1_5(int32_t serial,const hidl_vec<::android::hardware::radio::V1_5::DataProfileInfo> &)4478 Return<void> RadioImpl_1_6::setDataProfile_1_5(int32_t  serial ,
4479         const hidl_vec<::android::hardware::radio::V1_5::DataProfileInfo>& /* profiles */) {
4480     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4481             RIL_REQUEST_SET_DATA_PROFILE);
4482     if (pRI == NULL) {
4483         return Void();
4484     }
4485 
4486     RadioResponseInfo responseInfo = {};
4487     populateResponseInfo(responseInfo, serial, RESPONSE_SOLICITED, RIL_E_SUCCESS);
4488 
4489     if (radioService[mSlotId]->mRadioResponseV1_5 != NULL) {
4490         Return<void> retStatus
4491                 = radioService[mSlotId]->mRadioResponseV1_5->setDataProfileResponse(responseInfo);
4492     } else if (radioService[mSlotId]->mRadioResponseV1_4 != NULL) {
4493         Return<void> retStatus
4494                 = radioService[mSlotId]->mRadioResponseV1_4->setDataProfileResponse(responseInfo);
4495         radioService[mSlotId]->checkReturnStatus(retStatus);
4496     } else if (radioService[mSlotId]->mRadioResponse != NULL) {
4497         Return<void> retStatus
4498                 = radioService[mSlotId]->mRadioResponse->setDataProfileResponse(responseInfo);
4499         radioService[mSlotId]->checkReturnStatus(retStatus);
4500     } else {
4501         RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", mSlotId);
4502     }
4503 
4504     return Void();
4505 }
4506 
setIndicationFilter_1_5(int32_t,hidl_bitfield<::android::hardware::radio::V1_5::IndicationFilter>)4507 Return<void> RadioImpl_1_6::setIndicationFilter_1_5(int32_t /* serial */,
4508         hidl_bitfield<::android::hardware::radio::V1_5::IndicationFilter> /* indicationFilter */) {
4509     // TODO implement
4510 #if VDBG
4511     RLOGE("setIndicationFilter_1_5: Method is not implemented");
4512 #endif
4513     return Void();
4514 }
4515 
getBarringInfo(int32_t serial)4516 Return<void> RadioImpl_1_6::getBarringInfo(int32_t serial) {
4517 #if VDBG
4518     RLOGD("getBarringInfo: serial %d", serial);
4519 #endif
4520     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_BARRING_INFO);
4521     return Void();
4522 }
4523 
setNetworkSelectionModeManual_1_5(int32_t serial,const hidl_string & operatorNumeric,V1_5::RadioAccessNetworks ran)4524 Return<void> RadioImpl_1_6::setNetworkSelectionModeManual_1_5(int32_t serial,
4525         const hidl_string& operatorNumeric, V1_5::RadioAccessNetworks ran) {
4526 #if VDBG
4527     RLOGD("setNetworkSelectionModeManual_1_6: serial %d", serial);
4528 #endif
4529     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4530         RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL);
4531     if (pRI == NULL) {
4532         return Void();
4533     }
4534 
4535     RIL_NetworkOperator networkOperator = {};
4536 
4537     networkOperator.act = (RIL_RadioAccessNetworks)ran;
4538     if (!copyHidlStringToRil(&networkOperator.operatorNumeric, operatorNumeric, pRI)) {
4539         return Void();
4540     }
4541     CALL_ONREQUEST(pRI->pCI->requestNumber, &networkOperator,
4542         sizeof(networkOperator), pRI, mSlotId);
4543 
4544     return Void();
4545 }
4546 
sendCdmaSmsExpectMore(int32_t serial,const CdmaSmsMessage & sms)4547 Return<void> RadioImpl_1_6::sendCdmaSmsExpectMore(int32_t serial, const CdmaSmsMessage& sms) {
4548 #if VDBG
4549     RLOGD("sendCdmaSmsExpectMore: serial %d", serial);
4550 #endif
4551     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4552             RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE);
4553     if (pRI == NULL) {
4554         return Void();
4555     }
4556 
4557     RIL_CDMA_SMS_Message rcsm = {};
4558     constructCdmaSms(rcsm, sms);
4559 
4560     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
4561     return Void();
4562 }
4563 
4564 // Methods from ::android::hardware::radio::V1_6::IRadio follow.
sendCdmaSmsExpectMore_1_6(int32_t serial,const CdmaSmsMessage & sms)4565 Return<void> RadioImpl_1_6::sendCdmaSmsExpectMore_1_6(int32_t serial, const CdmaSmsMessage& sms) {
4566 #if VDBG
4567     RLOGD("sendCdmaSmsExpectMore: serial %d", serial);
4568 #endif
4569     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
4570             RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE);
4571     if (pRI == NULL) {
4572         return Void();
4573     }
4574 
4575     RIL_CDMA_SMS_Message rcsm = {};
4576     constructCdmaSms(rcsm, sms);
4577 
4578     CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm), pRI, mSlotId);
4579     return Void();
4580 }
4581 
supplySimDepersonalization(int32_t serial,V1_5::PersoSubstate persoType,const hidl_string & controlKey)4582 Return<void> RadioImpl_1_6::supplySimDepersonalization(int32_t serial,
4583         V1_5::PersoSubstate persoType, const hidl_string& controlKey) {
4584 #if VDBG
4585     RLOGD("supplySimDepersonalization: serial %d", serial);
4586 #endif
4587     dispatchStrings(serial, mSlotId, RIL_REQUEST_ENTER_SIM_DEPERSONALIZATION, true, 1,
4588             controlKey.c_str());
4589     return Void();
4590 }
4591 
setNrDualConnectivityState(int32_t serial,V1_6::NrDualConnectivityState nrDualConnectivityState)4592 Return<void> RadioImpl_1_6::setNrDualConnectivityState(int32_t serial,
4593         V1_6::NrDualConnectivityState nrDualConnectivityState) {
4594 #if VDBG
4595     RLOGD("setNrDualConnectivityState: serial %d", serial);
4596 #endif
4597     dispatchInts(serial, mSlotId, RIL_REQUEST_ENABLE_NR_DUAL_CONNECTIVITY, 1,
4598             nrDualConnectivityState);
4599     return Void();
4600 }
4601 
isNrDualConnectivityEnabled(int32_t serial)4602 Return<void> RadioImpl_1_6::isNrDualConnectivityEnabled(int32_t serial) {
4603 #if VDBG
4604     RLOGD("isNrDualConnectivityEnabled: serial %d", serial);
4605 #endif
4606     dispatchVoid(serial, mSlotId, RIL_REQUEST_IS_NR_DUAL_CONNECTIVITY_ENABLED);
4607     return Void();
4608 }
4609 
allocatePduSessionId(int32_t serial)4610 Return<void> RadioImpl_1_6::allocatePduSessionId(int32_t serial) {
4611 #if VDBG
4612     RLOGD("allocatePduSessionId: serial %d", serial);
4613 #endif
4614     dispatchVoid(serial, mSlotId, RIL_REQUEST_ALLOCATE_PDU_SESSION_ID);
4615     return Void();
4616 }
4617 
releasePduSessionId(int32_t serial,int32_t id)4618 Return<void> RadioImpl_1_6::releasePduSessionId(int32_t serial, int32_t id) {
4619 #if VDBG
4620     RLOGD("releasePduSessionId: serial %d, pduSessionId: %d", serial, id);
4621 #endif
4622     dispatchVoid(serial, mSlotId, RIL_REQUEST_RELEASE_PDU_SESSION_ID);
4623     return Void();
4624 }
4625 
startHandover(int32_t serial,int32_t callId)4626 Return<void> RadioImpl_1_6::startHandover(int32_t serial, int32_t callId) {
4627 #if VDBG
4628     RLOGD("startHandover: serial %d, callId: %d", serial, callId);
4629 #endif
4630     dispatchVoid(serial, mSlotId, RIL_REQUEST_START_HANDOVER);
4631     return Void();
4632 }
4633 
cancelHandover(int32_t serial,int32_t callId)4634 Return<void> RadioImpl_1_6::cancelHandover(int32_t serial, int32_t callId) {
4635 #if VDBG
4636     RLOGD("cancelHandover: serial %d, callId: %d", serial, callId);
4637 #endif
4638     dispatchVoid(serial, mSlotId, RIL_REQUEST_CANCEL_HANDOVER);
4639     return Void();
4640 }
4641 
4642 
setDataThrottling(int32_t serial,V1_6::DataThrottlingAction dataThrottlingAction,int64_t completionDurationMillis)4643 Return<void> RadioImpl_1_6::setDataThrottling(int32_t serial, V1_6::DataThrottlingAction dataThrottlingAction, int64_t completionDurationMillis) {
4644    #if VDBG
4645        RLOGD("OemHookImpl::sendRequestRaw: serial %d", serial);
4646    #endif
4647        dispatchInts(serial, mSlotId, RIL_REQUEST_SET_DATA_THROTTLING, 2,
4648           dataThrottlingAction, completionDurationMillis);
4649        return Void();
4650 }
4651 
getSystemSelectionChannels(int32_t serial)4652 Return<void> RadioImpl_1_6::getSystemSelectionChannels(int32_t serial) {
4653 #if VDBG
4654     RLOGD("getSystemSelectionChannels: serial %d", serial);
4655 #endif
4656     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS);
4657     return Void();
4658 }
4659 
getSlicingConfig(int32_t serial)4660 Return<void> RadioImpl_1_6::getSlicingConfig(int32_t serial) {
4661 #if VDBG
4662     RLOGD("getSlicingConfig: serial %d", serial);
4663 #endif
4664     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SLICING_CONFIG);
4665     return Void();
4666 }
4667 
setCarrierInfoForImsiEncryption_1_6(int32_t serial,const V1_6::ImsiEncryptionInfo & data)4668 Return<void> RadioImpl_1_6::setCarrierInfoForImsiEncryption_1_6(
4669         int32_t serial, const V1_6::ImsiEncryptionInfo& data) {
4670 #if VDBG
4671     RLOGD("setCarrierInfoForImsiEncryption_1_6: serial %d", serial);
4672 #endif
4673     RequestInfo* pRI = android::addRequestToList(serial, mSlotId,
4674                                                  RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION);
4675     if (pRI == NULL) {
4676         return Void();
4677     }
4678 
4679     RIL_CarrierInfoForImsiEncryption_v16 imsiEncryption = {};
4680 
4681     if (!copyHidlStringToRil(&imsiEncryption.mnc, data.base.mnc, pRI)) {
4682         return Void();
4683     }
4684     if (!copyHidlStringToRil(&imsiEncryption.mcc, data.base.mcc, pRI)) {
4685         memsetAndFreeStrings(1, imsiEncryption.mnc);
4686         return Void();
4687     }
4688     if (!copyHidlStringToRil(&imsiEncryption.keyIdentifier, data.base.keyIdentifier, pRI)) {
4689         memsetAndFreeStrings(2, imsiEncryption.mnc, imsiEncryption.mcc);
4690         return Void();
4691     }
4692     imsiEncryption.carrierKeyLength = data.base.carrierKey.size();
4693     imsiEncryption.carrierKey = new uint8_t[imsiEncryption.carrierKeyLength];
4694     memcpy(imsiEncryption.carrierKey, data.base.carrierKey.data(), imsiEncryption.carrierKeyLength);
4695     imsiEncryption.expirationTime = data.base.expirationTime;
4696     imsiEncryption.keyType = (RIL_PublicKeyType)data.keyType;
4697 
4698     CALL_ONREQUEST(pRI->pCI->requestNumber, &imsiEncryption,
4699                    sizeof(RIL_CarrierInfoForImsiEncryption_v16), pRI, mSlotId);
4700     delete (imsiEncryption.carrierKey);
4701     return Void();
4702 }
4703 
4704 
getSimPhonebookRecords(int32_t serial)4705 Return<void> RadioImpl_1_6::getSimPhonebookRecords(int32_t serial) {
4706 #if VDBG
4707     RLOGD("getSimPhonebookRecords: serial %d", serial);
4708 #endif
4709     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SIM_PHONEBOOK_RECORDS);
4710     return Void();
4711 }
4712 
getSimPhonebookCapacity(int32_t serial)4713 Return<void> RadioImpl_1_6::getSimPhonebookCapacity(int32_t serial) {
4714 #if VDBG
4715     RLOGD("getSimPhonebookCapacity: serial %d", serial);
4716 #endif
4717     dispatchVoid(serial, mSlotId, RIL_REQUEST_GET_SIM_PHONEBOOK_CAPACITY);
4718     return Void();
4719 }
4720 
updateSimPhonebookRecords(int32_t serial,const::android::hardware::radio::V1_6::PhonebookRecordInfo & recordInfo)4721 Return<void> RadioImpl_1_6::updateSimPhonebookRecords(
4722     int32_t serial,
4723     const ::android::hardware::radio::V1_6::PhonebookRecordInfo& recordInfo) {
4724 #if VDBG
4725     RLOGD("updateSimPhonebookRecords: serial %d", serial);
4726 #endif
4727     dispatchVoid(serial, mSlotId, RIL_REQUEST_UPDATE_SIM_PHONEBOOK_RECORDS);
4728     return Void();
4729 }
4730 
4731 
4732 // OEM hook methods:
setResponseFunctions(const::android::sp<IOemHookResponse> & oemHookResponseParam,const::android::sp<IOemHookIndication> & oemHookIndicationParam)4733 Return<void> OemHookImpl::setResponseFunctions(
4734         const ::android::sp<IOemHookResponse>& oemHookResponseParam,
4735         const ::android::sp<IOemHookIndication>& oemHookIndicationParam) {
4736 #if VDBG
4737     RLOGD("OemHookImpl::setResponseFunctions");
4738 #endif
4739 
4740     pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(mSlotId);
4741     int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
4742     assert(ret == 0);
4743 
4744     mOemHookResponse = oemHookResponseParam;
4745     mOemHookIndication = oemHookIndicationParam;
4746     mCounterOemHook[mSlotId]++;
4747 
4748     ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
4749     assert(ret == 0);
4750 
4751     return Void();
4752 }
4753 
sendRequestRaw(int32_t serial,const hidl_vec<uint8_t> & data)4754 Return<void> OemHookImpl::sendRequestRaw(int32_t serial, const hidl_vec<uint8_t>& data) {
4755 #if VDBG
4756     RLOGD("OemHookImpl::sendRequestRaw: serial %d", serial);
4757 #endif
4758     dispatchRaw(serial, mSlotId, RIL_REQUEST_OEM_HOOK_RAW, data);
4759     return Void();
4760 }
4761 
sendRequestStrings(int32_t serial,const hidl_vec<hidl_string> & data)4762 Return<void> OemHookImpl::sendRequestStrings(int32_t serial,
4763         const hidl_vec<hidl_string>& data) {
4764 #if VDBG
4765     RLOGD("OemHookImpl::sendRequestStrings: serial %d", serial);
4766 #endif
4767     dispatchStrings(serial, mSlotId, RIL_REQUEST_OEM_HOOK_STRINGS, data);
4768     return Void();
4769 }
4770 
4771 /***************************************************************************************************
4772  * RESPONSE FUNCTIONS
4773  * Functions above are used for requests going from framework to vendor code. The ones below are
4774  * responses for those requests coming back from the vendor code.
4775  **************************************************************************************************/
4776 
acknowledgeRequest(int slotId,int serial)4777 void radio_1_6::acknowledgeRequest(int slotId, int serial) {
4778     if (radioService[slotId]->mRadioResponse != NULL) {
4779         Return<void> retStatus = radioService[slotId]->mRadioResponse->acknowledgeRequest(serial);
4780         radioService[slotId]->checkReturnStatus(retStatus);
4781     } else {
4782         RLOGE("acknowledgeRequest: radioService[%d]->mRadioResponse == NULL", slotId);
4783     }
4784 }
4785 
populateResponseInfo(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e)4786 void populateResponseInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
4787                          RIL_Errno e) {
4788     responseInfo.serial = serial;
4789     switch (responseType) {
4790         case RESPONSE_SOLICITED:
4791             responseInfo.type = RadioResponseType::SOLICITED;
4792             break;
4793         case RESPONSE_SOLICITED_ACK_EXP:
4794             responseInfo.type = RadioResponseType::SOLICITED_ACK_EXP;
4795             break;
4796     }
4797     responseInfo.error = (RadioError) e;
4798 }
4799 
populateResponseInfo_1_6(::android::hardware::radio::V1_6::RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e)4800 void populateResponseInfo_1_6(
4801     ::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo,
4802     int serial, int responseType, RIL_Errno e) {
4803   responseInfo.serial = serial;
4804   switch (responseType) {
4805     case RESPONSE_SOLICITED:
4806       responseInfo.type = RadioResponseType::SOLICITED;
4807       break;
4808     case RESPONSE_SOLICITED_ACK_EXP:
4809       responseInfo.type = RadioResponseType::SOLICITED_ACK_EXP;
4810       break;
4811   }
4812   responseInfo.error = (::android::hardware::radio::V1_6::RadioError)e;
4813 }
4814 
responseIntOrEmpty(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)4815 int responseIntOrEmpty(RadioResponseInfo& responseInfo, int serial, int responseType, RIL_Errno e,
4816                void *response, size_t responseLen) {
4817     populateResponseInfo(responseInfo, serial, responseType, e);
4818     int ret = -1;
4819 
4820     if (response == NULL && responseLen == 0) {
4821         // Earlier RILs did not send a response for some cases although the interface
4822         // expected an integer as response. Do not return error if response is empty. Instead
4823         // Return -1 in those cases to maintain backward compatibility.
4824     } else if (response == NULL || responseLen != sizeof(int)) {
4825         RLOGE("responseIntOrEmpty: Invalid response");
4826         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
4827     } else {
4828         int *p_int = (int *) response;
4829         ret = p_int[0];
4830     }
4831     return ret;
4832 }
4833 
responseInt(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)4834 int responseInt(RadioResponseInfo& responseInfo, int serial, int responseType, RIL_Errno e,
4835                void *response, size_t responseLen) {
4836     populateResponseInfo(responseInfo, serial, responseType, e);
4837     int ret = -1;
4838 
4839     if (response == NULL || responseLen != sizeof(int)) {
4840         RLOGE("responseInt: Invalid response");
4841         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
4842     } else {
4843         int *p_int = (int *) response;
4844         ret = p_int[0];
4845     }
4846     return ret;
4847 }
4848 
responseInt_1_6(::android::hardware::radio::V1_6::RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)4849 int responseInt_1_6(::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo, int serial, int responseType, RIL_Errno e,
4850                void *response, size_t responseLen) {
4851     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
4852     int ret = -1;
4853 
4854     if (response == NULL || responseLen != sizeof(int)) {
4855         RLOGE("responseInt_1_6: Invalid response");
4856         if (e == RIL_E_SUCCESS) responseInfo.error = ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
4857     } else {
4858         int *p_int = (int *) response;
4859         ret = p_int[0];
4860     }
4861     return ret;
4862 }
4863 
getIccCardStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)4864 int radio_1_6::getIccCardStatusResponse(int slotId,
4865                                    int responseType, int serial, RIL_Errno e,
4866                                    void *response, size_t responseLen) {
4867 #if VDBG
4868     RLOGD("getIccCardStatusResponse: serial %d", serial);
4869 #endif
4870     if (radioService[slotId]->mRadioResponseV1_5 != NULL
4871         || radioService[slotId]->mRadioResponseV1_4 != NULL
4872         || radioService[slotId]->mRadioResponseV1_2 != NULL
4873         || radioService[slotId]->mRadioResponse != NULL) {
4874         RadioResponseInfo responseInfo = {};
4875         populateResponseInfo(responseInfo, serial, responseType, e);
4876         CardStatus cardStatus = {CardState::ABSENT, PinState::UNKNOWN, -1, -1, -1, {}};
4877         RIL_AppStatus *rilAppStatus = NULL;
4878         RIL_CardStatus_v1_5 *p_cur = ((RIL_CardStatus_v1_5 *) response);
4879         if (response == NULL || responseLen != sizeof(RIL_CardStatus_v1_5)
4880                 || p_cur->base.base.base.gsm_umts_subscription_app_index >= p_cur->base.base.base.num_applications
4881                 || p_cur->base.base.base.cdma_subscription_app_index >= p_cur->base.base.base.num_applications
4882                 || p_cur->base.base.base.ims_subscription_app_index >= p_cur->base.base.base.num_applications) {
4883             RLOGE("getIccCardStatusResponse: Invalid response");
4884             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
4885         } else {
4886             cardStatus.cardState = (CardState) p_cur->base.base.base.card_state;
4887             cardStatus.universalPinState = (PinState) p_cur->base.base.base.universal_pin_state;
4888             cardStatus.gsmUmtsSubscriptionAppIndex = p_cur->base.base.base.gsm_umts_subscription_app_index;
4889             cardStatus.cdmaSubscriptionAppIndex = p_cur->base.base.base.cdma_subscription_app_index;
4890             cardStatus.imsSubscriptionAppIndex = p_cur->base.base.base.ims_subscription_app_index;
4891             rilAppStatus = p_cur->base.base.base.applications;
4892             cardStatus.applications.resize(p_cur->base.base.base.num_applications);
4893             AppStatus *appStatus = cardStatus.applications.data();
4894 #if VDBG
4895             RLOGD("getIccCardStatusResponse: num_applications %d", p_cur->base.base.base.num_applications);
4896 #endif
4897             for (int i = 0; i < p_cur->base.base.base.num_applications; i++) {
4898                 appStatus[i].appType = (AppType) rilAppStatus[i].app_type;
4899                 appStatus[i].appState = (AppState) rilAppStatus[i].app_state;
4900                 appStatus[i].persoSubstate = (PersoSubstate) rilAppStatus[i].perso_substate;
4901                 appStatus[i].aidPtr = convertCharPtrToHidlString(rilAppStatus[i].aid_ptr);
4902                 appStatus[i].appLabelPtr = convertCharPtrToHidlString(
4903                         rilAppStatus[i].app_label_ptr);
4904                 appStatus[i].pin1Replaced = rilAppStatus[i].pin1_replaced;
4905                 appStatus[i].pin1 = (PinState) rilAppStatus[i].pin1;
4906                 appStatus[i].pin2 = (PinState) rilAppStatus[i].pin2;
4907             }
4908         }
4909         if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
4910             ::android::hardware::radio::V1_2::CardStatus cardStatusV1_2;
4911             ::android::hardware::radio::V1_4::CardStatus cardStatusV1_4;
4912             ::android::hardware::radio::V1_5::CardStatus cardStatusV1_5;
4913             cardStatusV1_2.base = cardStatus;
4914             cardStatusV1_2.physicalSlotId = -1;
4915             cardStatusV1_2.iccid = convertCharPtrToHidlString(p_cur->base.base.iccid);
4916             cardStatusV1_4.base = cardStatusV1_2;
4917             cardStatusV1_5.base = cardStatusV1_4;
4918             cardStatusV1_5.applications.resize(p_cur->base.base.base.num_applications);
4919             for (int i = 0; i < p_cur->base.base.base.num_applications; i++) {
4920                 cardStatusV1_5.applications[i].base.appType = (AppType) rilAppStatus[i].app_type;
4921                 cardStatusV1_5.applications[i].base.appState = (AppState) rilAppStatus[i].app_state;
4922                 cardStatusV1_5.applications[i].base.persoSubstate = (PersoSubstate) rilAppStatus[i].perso_substate;
4923                 cardStatusV1_5.applications[i].base.aidPtr = convertCharPtrToHidlString(rilAppStatus[i].aid_ptr);
4924                 cardStatusV1_5.applications[i].base.appLabelPtr = convertCharPtrToHidlString(
4925                         rilAppStatus[i].app_label_ptr);
4926                 cardStatusV1_5.applications[i].base.pin1Replaced = rilAppStatus[i].pin1_replaced;
4927                 cardStatusV1_5.applications[i].base.pin1 = (PinState) rilAppStatus[i].pin1;
4928                 cardStatusV1_5.applications[i].base.pin2 = (PinState) rilAppStatus[i].pin2;
4929                 cardStatusV1_5.applications[i].persoSubstate = (V1_5::PersoSubstate)rilAppStatus[i].perso_substate;
4930             }
4931 
4932             // If POWER_DOWN then set applications to empty
4933             if (radioService[slotId]->mSimCardPowerState == V1_1::CardPowerState::POWER_DOWN) {
4934                 RLOGD("getIccCardStatusResponse: state is POWER_DOWN so clearing apps");
4935                 cardStatusV1_5.applications = {};
4936             }
4937             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5->
4938                     getIccCardStatusResponse_1_5(responseInfo, cardStatusV1_5);
4939             radioService[slotId]->checkReturnStatus(retStatus);
4940         } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
4941             ::android::hardware::radio::V1_2::CardStatus cardStatusV1_2;
4942             ::android::hardware::radio::V1_4::CardStatus cardStatusV1_4;
4943             cardStatusV1_2.base = cardStatus;
4944             cardStatusV1_2.physicalSlotId = -1;
4945             cardStatusV1_2.iccid = convertCharPtrToHidlString(p_cur->base.base.iccid);
4946             cardStatusV1_4.base = cardStatusV1_2;
4947             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4->
4948                     getIccCardStatusResponse_1_4(responseInfo, cardStatusV1_4);
4949             radioService[slotId]->checkReturnStatus(retStatus);
4950         } else if (radioService[slotId]->mRadioResponseV1_3 != NULL) {
4951             ::android::hardware::radio::V1_2::CardStatus cardStatusV1_2;
4952             cardStatusV1_2.base = cardStatus;
4953             cardStatusV1_2.physicalSlotId = -1;
4954             cardStatusV1_2.iccid = convertCharPtrToHidlString(p_cur->base.base.iccid);
4955             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_3->
4956                     getIccCardStatusResponse_1_2(responseInfo, cardStatusV1_2);
4957             radioService[slotId]->checkReturnStatus(retStatus);
4958         } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
4959             ::android::hardware::radio::V1_2::CardStatus cardStatusV1_2;
4960             cardStatusV1_2.base = cardStatus;
4961             cardStatusV1_2.physicalSlotId = -1;
4962             cardStatusV1_2.iccid = convertCharPtrToHidlString(p_cur->base.base.iccid);
4963             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2->
4964                     getIccCardStatusResponse_1_2(responseInfo, cardStatusV1_2);
4965             radioService[slotId]->checkReturnStatus(retStatus);
4966             // TODO: add 1.1 if needed.
4967         } else {
4968             Return<void> retStatus = radioService[slotId]->mRadioResponse->
4969                     getIccCardStatusResponse(responseInfo, cardStatus);
4970             radioService[slotId]->checkReturnStatus(retStatus);
4971         }
4972     } else {
4973         RLOGE("getIccCardStatusResponse: radioService[%d]->mRadioResponse == NULL", slotId);
4974     }
4975     return 0;
4976 }
4977 
supplyIccPinForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)4978 int radio_1_6::supplyIccPinForAppResponse(int slotId,
4979                                      int responseType, int serial, RIL_Errno e,
4980                                      void *response, size_t responseLen) {
4981 #if VDBG
4982     RLOGD("supplyIccPinForAppResponse: serial %d", serial);
4983 #endif
4984 
4985     if (radioService[slotId]->mRadioResponse != NULL) {
4986         RadioResponseInfo responseInfo = {};
4987         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
4988         Return<void> retStatus = radioService[slotId]->mRadioResponse->
4989                 supplyIccPinForAppResponse(responseInfo, ret);
4990         RLOGE("supplyIccPinForAppResponse: amit ret %d", ret);
4991         radioService[slotId]->checkReturnStatus(retStatus);
4992     } else {
4993         RLOGE("supplyIccPinForAppResponse: radioService[%d]->mRadioResponse == NULL",
4994                 slotId);
4995     }
4996 
4997     return 0;
4998 }
4999 
supplyIccPukForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5000 int radio_1_6::supplyIccPukForAppResponse(int slotId,
5001                                      int responseType, int serial, RIL_Errno e,
5002                                      void *response, size_t responseLen) {
5003 #if VDBG
5004     RLOGD("supplyIccPukForAppResponse: serial %d", serial);
5005 #endif
5006 
5007     if (radioService[slotId]->mRadioResponse != NULL) {
5008         RadioResponseInfo responseInfo = {};
5009         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5010         Return<void> retStatus = radioService[slotId]->mRadioResponse->supplyIccPukForAppResponse(
5011                 responseInfo, ret);
5012         radioService[slotId]->checkReturnStatus(retStatus);
5013     } else {
5014         RLOGE("supplyIccPukForAppResponse: radioService[%d]->mRadioResponse == NULL",
5015                 slotId);
5016     }
5017 
5018     return 0;
5019 }
5020 
supplyIccPin2ForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5021 int radio_1_6::supplyIccPin2ForAppResponse(int slotId,
5022                                       int responseType, int serial, RIL_Errno e,
5023                                       void *response, size_t responseLen) {
5024 #if VDBG
5025     RLOGD("supplyIccPin2ForAppResponse: serial %d", serial);
5026 #endif
5027 
5028     if (radioService[slotId]->mRadioResponse != NULL) {
5029         RadioResponseInfo responseInfo = {};
5030         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5031         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5032                 supplyIccPin2ForAppResponse(responseInfo, ret);
5033         radioService[slotId]->checkReturnStatus(retStatus);
5034     } else {
5035         RLOGE("supplyIccPin2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
5036                 slotId);
5037     }
5038 
5039     return 0;
5040 }
5041 
supplyIccPuk2ForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5042 int radio_1_6::supplyIccPuk2ForAppResponse(int slotId,
5043                                       int responseType, int serial, RIL_Errno e,
5044                                       void *response, size_t responseLen) {
5045 #if VDBG
5046     RLOGD("supplyIccPuk2ForAppResponse: serial %d", serial);
5047 #endif
5048 
5049     if (radioService[slotId]->mRadioResponse != NULL) {
5050         RadioResponseInfo responseInfo = {};
5051         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5052         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5053                 supplyIccPuk2ForAppResponse(responseInfo, ret);
5054         radioService[slotId]->checkReturnStatus(retStatus);
5055     } else {
5056         RLOGE("supplyIccPuk2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
5057                 slotId);
5058     }
5059 
5060     return 0;
5061 }
5062 
changeIccPinForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5063 int radio_1_6::changeIccPinForAppResponse(int slotId,
5064                                      int responseType, int serial, RIL_Errno e,
5065                                      void *response, size_t responseLen) {
5066 #if VDBG
5067     RLOGD("changeIccPinForAppResponse: serial %d", serial);
5068 #endif
5069 
5070     if (radioService[slotId]->mRadioResponse != NULL) {
5071         RadioResponseInfo responseInfo = {};
5072         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5073         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5074                 changeIccPinForAppResponse(responseInfo, ret);
5075         radioService[slotId]->checkReturnStatus(retStatus);
5076     } else {
5077         RLOGE("changeIccPinForAppResponse: radioService[%d]->mRadioResponse == NULL",
5078                 slotId);
5079     }
5080 
5081     return 0;
5082 }
5083 
changeIccPin2ForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5084 int radio_1_6::changeIccPin2ForAppResponse(int slotId,
5085                                       int responseType, int serial, RIL_Errno e,
5086                                       void *response, size_t responseLen) {
5087 #if VDBG
5088     RLOGD("changeIccPin2ForAppResponse: serial %d", serial);
5089 #endif
5090 
5091     if (radioService[slotId]->mRadioResponse != NULL) {
5092         RadioResponseInfo responseInfo = {};
5093         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5094         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5095                 changeIccPin2ForAppResponse(responseInfo, ret);
5096         radioService[slotId]->checkReturnStatus(retStatus);
5097     } else {
5098         RLOGE("changeIccPin2ForAppResponse: radioService[%d]->mRadioResponse == NULL",
5099                 slotId);
5100     }
5101 
5102     return 0;
5103 }
5104 
supplyNetworkDepersonalizationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5105 int radio_1_6::supplyNetworkDepersonalizationResponse(int slotId,
5106                                                  int responseType, int serial, RIL_Errno e,
5107                                                  void *response, size_t responseLen) {
5108 #if VDBG
5109     RLOGD("supplyNetworkDepersonalizationResponse: serial %d", serial);
5110 #endif
5111 
5112     if (radioService[slotId]->mRadioResponse != NULL) {
5113         RadioResponseInfo responseInfo = {};
5114         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
5115         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5116                 supplyNetworkDepersonalizationResponse(responseInfo, ret);
5117         radioService[slotId]->checkReturnStatus(retStatus);
5118     } else {
5119         RLOGE("supplyNetworkDepersonalizationResponse: radioService[%d]->mRadioResponse == "
5120                 "NULL", slotId);
5121     }
5122 
5123     return 0;
5124 }
5125 
getCurrentCallsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5126 int radio_1_6::getCurrentCallsResponse(int slotId,
5127                                   int responseType, int serial, RIL_Errno e,
5128                                   void *response, size_t responseLen) {
5129 #if VDBG
5130     RLOGD("getCurrentCallsResponse: serial %d", serial);
5131 #endif
5132 
5133     if (radioService[slotId]->mRadioResponse != NULL) {
5134         RadioResponseInfo responseInfo = {};
5135         populateResponseInfo(responseInfo, serial, responseType, e);
5136 
5137         hidl_vec<Call> calls;
5138         if ((response == NULL && responseLen != 0)
5139                 || (responseLen % sizeof(RIL_Call *)) != 0) {
5140             RLOGE("getCurrentCallsResponse: Invalid response");
5141             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
5142         } else {
5143             int num = responseLen / sizeof(RIL_Call *);
5144             calls.resize(num);
5145 
5146             for (int i = 0 ; i < num ; i++) {
5147                 RIL_Call *p_cur = ((RIL_Call **) response)[i];
5148                 /* each call info */
5149                 calls[i].state = (CallState) p_cur->state;
5150                 calls[i].index = p_cur->index;
5151                 calls[i].toa = p_cur->toa;
5152                 calls[i].isMpty = p_cur->isMpty;
5153                 calls[i].isMT = p_cur->isMT;
5154                 calls[i].als = p_cur->als;
5155                 calls[i].isVoice = p_cur->isVoice;
5156                 calls[i].isVoicePrivacy = p_cur->isVoicePrivacy;
5157                 calls[i].number = convertCharPtrToHidlString(p_cur->number);
5158                 calls[i].numberPresentation = (CallPresentation) p_cur->numberPresentation;
5159                 calls[i].name = convertCharPtrToHidlString(p_cur->name);
5160                 calls[i].namePresentation = (CallPresentation) p_cur->namePresentation;
5161                 if (p_cur->uusInfo != NULL && p_cur->uusInfo->uusData != NULL) {
5162                     RIL_UUS_Info *uusInfo = p_cur->uusInfo;
5163                     calls[i].uusInfo.resize(1);
5164                     calls[i].uusInfo[0].uusType = (UusType) uusInfo->uusType;
5165                     calls[i].uusInfo[0].uusDcs = (UusDcs) uusInfo->uusDcs;
5166                     // convert uusInfo->uusData to a null-terminated string
5167                     char *nullTermStr = strndup(uusInfo->uusData, uusInfo->uusLength);
5168                     calls[i].uusInfo[0].uusData = nullTermStr;
5169                     free(nullTermStr);
5170                 }
5171             }
5172         }
5173 
5174         Return<void> retStatus = radioService[slotId]->mRadioResponse->
5175                 getCurrentCallsResponse(responseInfo, calls);
5176         radioService[slotId]->checkReturnStatus(retStatus);
5177     } else {
5178         RLOGE("getCurrentCallsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
5179     }
5180 
5181     return 0;
5182 }
5183 
dialResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5184 int radio_1_6::dialResponse(int slotId,
5185                        int responseType, int serial, RIL_Errno e, void *response,
5186                        size_t responseLen) {
5187 #if VDBG
5188     RLOGD("dialResponse: serial %d", serial);
5189 #endif
5190 
5191     if (radioService[slotId]->mRadioResponse != NULL) {
5192         RadioResponseInfo responseInfo = {};
5193         populateResponseInfo(responseInfo, serial, responseType, e);
5194         Return<void> retStatus = radioService[slotId]->mRadioResponse->dialResponse(responseInfo);
5195         radioService[slotId]->checkReturnStatus(retStatus);
5196     } else {
5197         RLOGE("dialResponse: radioService[%d]->mRadioResponse == NULL", slotId);
5198     }
5199 
5200     return 0;
5201 }
5202 
getIMSIForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5203 int radio_1_6::getIMSIForAppResponse(int slotId,
5204                                 int responseType, int serial, RIL_Errno e, void *response,
5205                                 size_t responseLen) {
5206 #if VDBG
5207     RLOGD("getIMSIForAppResponse: serial %d", serial);
5208 #endif
5209 
5210     if (radioService[slotId]->mRadioResponse != NULL) {
5211         RadioResponseInfo responseInfo = {};
5212         populateResponseInfo(responseInfo, serial, responseType, e);
5213         Return<void> retStatus = radioService[slotId]->mRadioResponse->getIMSIForAppResponse(
5214                 responseInfo, convertCharPtrToHidlString((char *) response));
5215         radioService[slotId]->checkReturnStatus(retStatus);
5216     } else {
5217         RLOGE("getIMSIForAppResponse: radioService[%d]->mRadioResponse == NULL",
5218                 slotId);
5219     }
5220 
5221     return 0;
5222 }
5223 
hangupConnectionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5224 int radio_1_6::hangupConnectionResponse(int slotId,
5225                                    int responseType, int serial, RIL_Errno e,
5226                                    void *response, size_t responseLen) {
5227 #if VDBG
5228     RLOGD("hangupConnectionResponse: serial %d", serial);
5229 #endif
5230 
5231     if (radioService[slotId]->mRadioResponse != NULL) {
5232         RadioResponseInfo responseInfo = {};
5233         populateResponseInfo(responseInfo, serial, responseType, e);
5234         Return<void> retStatus = radioService[slotId]->mRadioResponse->hangupConnectionResponse(
5235                 responseInfo);
5236         radioService[slotId]->checkReturnStatus(retStatus);
5237     } else {
5238         RLOGE("hangupConnectionResponse: radioService[%d]->mRadioResponse == NULL",
5239                 slotId);
5240     }
5241 
5242     return 0;
5243 }
5244 
hangupWaitingOrBackgroundResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5245 int radio_1_6::hangupWaitingOrBackgroundResponse(int slotId,
5246                                             int responseType, int serial, RIL_Errno e,
5247                                             void *response, size_t responseLen) {
5248 #if VDBG
5249     RLOGD("hangupWaitingOrBackgroundResponse: serial %d", serial);
5250 #endif
5251 
5252     if (radioService[slotId]->mRadioResponse != NULL) {
5253         RadioResponseInfo responseInfo = {};
5254         populateResponseInfo(responseInfo, serial, responseType, e);
5255         Return<void> retStatus =
5256                 radioService[slotId]->mRadioResponse->hangupWaitingOrBackgroundResponse(
5257                 responseInfo);
5258         radioService[slotId]->checkReturnStatus(retStatus);
5259     } else {
5260         RLOGE("hangupWaitingOrBackgroundResponse: radioService[%d]->mRadioResponse == NULL",
5261                 slotId);
5262     }
5263 
5264     return 0;
5265 }
5266 
hangupForegroundResumeBackgroundResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5267 int radio_1_6::hangupForegroundResumeBackgroundResponse(int slotId, int responseType, int serial,
5268                                                     RIL_Errno e, void *response,
5269                                                     size_t responseLen) {
5270 #if VDBG
5271     RLOGD("hangupWaitingOrBackgroundResponse: serial %d", serial);
5272 #endif
5273 
5274     if (radioService[slotId]->mRadioResponse != NULL) {
5275         RadioResponseInfo responseInfo = {};
5276         populateResponseInfo(responseInfo, serial, responseType, e);
5277         Return<void> retStatus =
5278                 radioService[slotId]->mRadioResponse->hangupWaitingOrBackgroundResponse(
5279                 responseInfo);
5280         radioService[slotId]->checkReturnStatus(retStatus);
5281     } else {
5282         RLOGE("hangupWaitingOrBackgroundResponse: radioService[%d]->mRadioResponse == NULL",
5283                 slotId);
5284     }
5285 
5286     return 0;
5287 }
5288 
switchWaitingOrHoldingAndActiveResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5289 int radio_1_6::switchWaitingOrHoldingAndActiveResponse(int slotId, int responseType, int serial,
5290                                                    RIL_Errno e, void *response,
5291                                                    size_t responseLen) {
5292 #if VDBG
5293     RLOGD("switchWaitingOrHoldingAndActiveResponse: serial %d", serial);
5294 #endif
5295 
5296     if (radioService[slotId]->mRadioResponse != NULL) {
5297         RadioResponseInfo responseInfo = {};
5298         populateResponseInfo(responseInfo, serial, responseType, e);
5299         Return<void> retStatus =
5300                 radioService[slotId]->mRadioResponse->switchWaitingOrHoldingAndActiveResponse(
5301                 responseInfo);
5302         radioService[slotId]->checkReturnStatus(retStatus);
5303     } else {
5304         RLOGE("switchWaitingOrHoldingAndActiveResponse: radioService[%d]->mRadioResponse "
5305                 "== NULL", slotId);
5306     }
5307 
5308     return 0;
5309 }
5310 
conferenceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5311 int radio_1_6::conferenceResponse(int slotId, int responseType,
5312                              int serial, RIL_Errno e, void *response, size_t responseLen) {
5313 #if VDBG
5314     RLOGD("conferenceResponse: serial %d", serial);
5315 #endif
5316 
5317     if (radioService[slotId]->mRadioResponse != NULL) {
5318         RadioResponseInfo responseInfo = {};
5319         populateResponseInfo(responseInfo, serial, responseType, e);
5320         Return<void> retStatus = radioService[slotId]->mRadioResponse->conferenceResponse(
5321                 responseInfo);
5322         radioService[slotId]->checkReturnStatus(retStatus);
5323     } else {
5324         RLOGE("conferenceResponse: radioService[%d]->mRadioResponse == NULL",
5325                 slotId);
5326     }
5327 
5328     return 0;
5329 }
5330 
rejectCallResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5331 int radio_1_6::rejectCallResponse(int slotId, int responseType,
5332                              int serial, RIL_Errno e, void *response, size_t responseLen) {
5333 #if VDBG
5334     RLOGD("rejectCallResponse: serial %d", serial);
5335 #endif
5336 
5337     if (radioService[slotId]->mRadioResponse != NULL) {
5338         RadioResponseInfo responseInfo = {};
5339         populateResponseInfo(responseInfo, serial, responseType, e);
5340         Return<void> retStatus = radioService[slotId]->mRadioResponse->rejectCallResponse(
5341                 responseInfo);
5342         radioService[slotId]->checkReturnStatus(retStatus);
5343     } else {
5344         RLOGE("rejectCallResponse: radioService[%d]->mRadioResponse == NULL",
5345                 slotId);
5346     }
5347 
5348     return 0;
5349 }
5350 
getLastCallFailCauseResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5351 int radio_1_6::getLastCallFailCauseResponse(int slotId,
5352                                        int responseType, int serial, RIL_Errno e, void *response,
5353                                        size_t responseLen) {
5354 #if VDBG
5355     RLOGD("getLastCallFailCauseResponse: serial %d", serial);
5356 #endif
5357 
5358     if (radioService[slotId]->mRadioResponse != NULL) {
5359         RadioResponseInfo responseInfo = {};
5360         populateResponseInfo(responseInfo, serial, responseType, e);
5361 
5362         LastCallFailCauseInfo info = {};
5363         info.vendorCause = hidl_string();
5364         if (response == NULL) {
5365             RLOGE("getCurrentCallsResponse Invalid response: NULL");
5366             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
5367         } else if (responseLen == sizeof(int)) {
5368             int *pInt = (int *) response;
5369             info.causeCode = (LastCallFailCause) pInt[0];
5370         } else if (responseLen == sizeof(RIL_LastCallFailCauseInfo))  {
5371             RIL_LastCallFailCauseInfo *pFailCauseInfo = (RIL_LastCallFailCauseInfo *) response;
5372             info.causeCode = (LastCallFailCause) pFailCauseInfo->cause_code;
5373             info.vendorCause = convertCharPtrToHidlString(pFailCauseInfo->vendor_cause);
5374         } else {
5375             RLOGE("getCurrentCallsResponse Invalid response: NULL");
5376             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
5377         }
5378 
5379         Return<void> retStatus = radioService[slotId]->mRadioResponse->getLastCallFailCauseResponse(
5380                 responseInfo, info);
5381         radioService[slotId]->checkReturnStatus(retStatus);
5382     } else {
5383         RLOGE("getLastCallFailCauseResponse: radioService[%d]->mRadioResponse == NULL",
5384                 slotId);
5385     }
5386 
5387     return 0;
5388 }
5389 
getSignalStrengthResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)5390 int radio_1_6::getSignalStrengthResponse(int slotId,
5391                                      int responseType, int serial, RIL_Errno e,
5392                                      void *response, size_t responseLen) {
5393 #if VDBG
5394     RLOGD("getSignalStrengthResponse: serial %d", serial);
5395 #endif
5396 
5397     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
5398         RadioResponseInfo responseInfo = {};
5399         populateResponseInfo(responseInfo, serial, responseType, e);
5400         ::android::hardware::radio::V1_4::SignalStrength signalStrength_1_4 = {};
5401         if (response == NULL || responseLen != sizeof(RIL_SignalStrength_v12)) {
5402             RLOGE("getSignalStrengthResponse: Invalid response");
5403             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
5404         } else {
5405             convertRilSignalStrengthToHal_1_4(response, responseLen, signalStrength_1_4);
5406         }
5407 
5408         //TODO: future implementation needs to fill tdScdma, wcdma and nr signal strength.
5409 
5410         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4->
5411                 getSignalStrengthResponse_1_4(responseInfo, signalStrength_1_4);
5412         radioService[slotId]->checkReturnStatus(retStatus);
5413     } else if (radioService[slotId]->mRadioResponse != NULL) {
5414         RadioResponseInfo responseInfo = {};
5415         populateResponseInfo(responseInfo, serial, responseType, e);
5416         SignalStrength signalStrength = {};
5417         if (response == NULL || responseLen != sizeof(RIL_SignalStrength_v12)) {
5418             RLOGE("getSignalStrengthResponse: Invalid response");
5419             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
5420         } else {
5421             convertRilSignalStrengthToHal(response, responseLen, signalStrength);
5422         }
5423 
5424         Return<void> retStatus = radioService[slotId]->mRadioResponse->getSignalStrengthResponse(
5425                 responseInfo, signalStrength);
5426         radioService[slotId]->checkReturnStatus(retStatus);
5427     } else {
5428         RLOGE("getSignalStrengthResponse: radioService[%d]->mRadioResponse == NULL",
5429                 slotId);
5430     }
5431 
5432     return 0;
5433 }
5434 
getCellInfoTypeRadioTechnology(char * rat)5435 RIL_CellInfoType getCellInfoTypeRadioTechnology(char *rat) {
5436     if (rat == NULL) {
5437         return RIL_CELL_INFO_TYPE_NONE;
5438     }
5439 
5440     int radioTech = atoi(rat);
5441 
5442     switch(radioTech) {
5443 
5444         case RADIO_TECH_GPRS:
5445         case RADIO_TECH_EDGE:
5446         case RADIO_TECH_GSM: {
5447             return RIL_CELL_INFO_TYPE_GSM;
5448         }
5449 
5450         case RADIO_TECH_UMTS:
5451         case RADIO_TECH_HSDPA:
5452         case RADIO_TECH_HSUPA:
5453         case RADIO_TECH_HSPA:
5454         case RADIO_TECH_HSPAP: {
5455             return RIL_CELL_INFO_TYPE_WCDMA;
5456         }
5457 
5458         case RADIO_TECH_IS95A:
5459         case RADIO_TECH_IS95B:
5460         case RADIO_TECH_1xRTT:
5461         case RADIO_TECH_EVDO_0:
5462         case RADIO_TECH_EVDO_A:
5463         case RADIO_TECH_EVDO_B:
5464         case RADIO_TECH_EHRPD: {
5465             return RIL_CELL_INFO_TYPE_CDMA;
5466         }
5467 
5468         case RADIO_TECH_LTE:
5469         case RADIO_TECH_LTE_CA: {
5470             return RIL_CELL_INFO_TYPE_LTE;
5471         }
5472 
5473         case RADIO_TECH_TD_SCDMA: {
5474             return RIL_CELL_INFO_TYPE_TD_SCDMA;
5475         }
5476 
5477         default: {
5478             break;
5479         }
5480     }
5481 
5482     return RIL_CELL_INFO_TYPE_NONE;
5483 
5484 }
5485 
fillCellIdentityResponse(CellIdentity & cellIdentity,RIL_CellIdentity_v16 & rilCellIdentity)5486 void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 &rilCellIdentity) {
5487 
5488     cellIdentity.cellIdentityGsm.resize(0);
5489     cellIdentity.cellIdentityWcdma.resize(0);
5490     cellIdentity.cellIdentityCdma.resize(0);
5491     cellIdentity.cellIdentityTdscdma.resize(0);
5492     cellIdentity.cellIdentityLte.resize(0);
5493     cellIdentity.cellInfoType = (CellInfoType)rilCellIdentity.cellInfoType;
5494     switch(rilCellIdentity.cellInfoType) {
5495 
5496         case RIL_CELL_INFO_TYPE_GSM: {
5497             cellIdentity.cellIdentityGsm.resize(1);
5498             cellIdentity.cellIdentityGsm[0].mcc =
5499                     std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5500             cellIdentity.cellIdentityGsm[0].mnc =
5501                     ril::util::mnc::decode(rilCellIdentity.cellIdentityGsm.mnc);
5502             cellIdentity.cellIdentityGsm[0].lac = rilCellIdentity.cellIdentityGsm.lac;
5503             cellIdentity.cellIdentityGsm[0].cid = rilCellIdentity.cellIdentityGsm.cid;
5504             cellIdentity.cellIdentityGsm[0].arfcn = rilCellIdentity.cellIdentityGsm.arfcn;
5505             cellIdentity.cellIdentityGsm[0].bsic = rilCellIdentity.cellIdentityGsm.bsic;
5506             break;
5507         }
5508 
5509         case RIL_CELL_INFO_TYPE_WCDMA: {
5510             cellIdentity.cellIdentityWcdma.resize(1);
5511             cellIdentity.cellIdentityWcdma[0].mcc =
5512                     std::to_string(rilCellIdentity.cellIdentityWcdma.mcc);
5513             cellIdentity.cellIdentityWcdma[0].mnc =
5514                     ril::util::mnc::decode(rilCellIdentity.cellIdentityWcdma.mnc);
5515             cellIdentity.cellIdentityWcdma[0].lac = rilCellIdentity.cellIdentityWcdma.lac;
5516             cellIdentity.cellIdentityWcdma[0].cid = rilCellIdentity.cellIdentityWcdma.cid;
5517             cellIdentity.cellIdentityWcdma[0].psc = rilCellIdentity.cellIdentityWcdma.psc;
5518             cellIdentity.cellIdentityWcdma[0].uarfcn = rilCellIdentity.cellIdentityWcdma.uarfcn;
5519             break;
5520         }
5521 
5522         case RIL_CELL_INFO_TYPE_CDMA: {
5523             cellIdentity.cellIdentityCdma.resize(1);
5524             cellIdentity.cellIdentityCdma[0].networkId = rilCellIdentity.cellIdentityCdma.networkId;
5525             cellIdentity.cellIdentityCdma[0].systemId = rilCellIdentity.cellIdentityCdma.systemId;
5526             cellIdentity.cellIdentityCdma[0].baseStationId =
5527                     rilCellIdentity.cellIdentityCdma.basestationId;
5528             cellIdentity.cellIdentityCdma[0].longitude = rilCellIdentity.cellIdentityCdma.longitude;
5529             cellIdentity.cellIdentityCdma[0].latitude = rilCellIdentity.cellIdentityCdma.latitude;
5530             break;
5531         }
5532 
5533         case RIL_CELL_INFO_TYPE_LTE: {
5534             cellIdentity.cellIdentityLte.resize(1);
5535             cellIdentity.cellIdentityLte[0].mcc =
5536                     std::to_string(rilCellIdentity.cellIdentityLte.mcc);
5537             cellIdentity.cellIdentityLte[0].mnc =
5538                     ril::util::mnc::decode(rilCellIdentity.cellIdentityLte.mnc);
5539             cellIdentity.cellIdentityLte[0].ci = rilCellIdentity.cellIdentityLte.ci;
5540             cellIdentity.cellIdentityLte[0].pci = rilCellIdentity.cellIdentityLte.pci;
5541             cellIdentity.cellIdentityLte[0].tac = rilCellIdentity.cellIdentityLte.tac;
5542             cellIdentity.cellIdentityLte[0].earfcn = rilCellIdentity.cellIdentityLte.earfcn;
5543             break;
5544         }
5545 
5546         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
5547             cellIdentity.cellIdentityTdscdma.resize(1);
5548             cellIdentity.cellIdentityTdscdma[0].mcc =
5549                     std::to_string(rilCellIdentity.cellIdentityTdscdma.mcc);
5550             cellIdentity.cellIdentityTdscdma[0].mnc =
5551                     ril::util::mnc::decode(rilCellIdentity.cellIdentityTdscdma.mnc);
5552             cellIdentity.cellIdentityTdscdma[0].lac = rilCellIdentity.cellIdentityTdscdma.lac;
5553             cellIdentity.cellIdentityTdscdma[0].cid = rilCellIdentity.cellIdentityTdscdma.cid;
5554             cellIdentity.cellIdentityTdscdma[0].cpid = rilCellIdentity.cellIdentityTdscdma.cpid;
5555             break;
5556         }
5557 
5558         default: {
5559             break;
5560         }
5561     }
5562 }
5563 
fillCellIdentityResponse_1_5(V1_5::CellIdentity & cellIdentity,RIL_CellIdentity_v16 & rilCellIdentity)5564 void fillCellIdentityResponse_1_5(V1_5::CellIdentity &cellIdentity,
5565                                   RIL_CellIdentity_v16 &rilCellIdentity) {
5566 
5567     switch (rilCellIdentity.cellInfoType) {
5568         case RIL_CELL_INFO_TYPE_GSM: {
5569             V1_5::CellIdentityGsm gsm;
5570             gsm.base.base.mcc = std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5571             gsm.base.base.mnc = ril::util::mnc::decode(rilCellIdentity.cellIdentityGsm.mnc);
5572             if (gsm.base.base.mcc == "-1") {
5573                 gsm.base.base.mcc = "";
5574             }
5575             gsm.base.base.lac = rilCellIdentity.cellIdentityGsm.lac;
5576             gsm.base.base.cid = rilCellIdentity.cellIdentityGsm.cid;
5577             gsm.base.base.arfcn = rilCellIdentity.cellIdentityGsm.arfcn;
5578             gsm.base.base.bsic = rilCellIdentity.cellIdentityGsm.bsic;
5579             cellIdentity.gsm(gsm);
5580             break;
5581         }
5582 
5583         case RIL_CELL_INFO_TYPE_WCDMA: {
5584             V1_5::CellIdentityWcdma wcdma;
5585             wcdma.base.base.mcc = std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5586             wcdma.base.base.mnc = ril::util::mnc::decode(rilCellIdentity.cellIdentityWcdma.mnc);
5587             if (wcdma.base.base.mcc == "-1") {
5588                 wcdma.base.base.mcc = "";
5589             }
5590             wcdma.base.base.lac = rilCellIdentity.cellIdentityWcdma.lac;
5591             wcdma.base.base.cid = rilCellIdentity.cellIdentityWcdma.cid;
5592             wcdma.base.base.psc = rilCellIdentity.cellIdentityWcdma.psc;
5593             wcdma.base.base.uarfcn = rilCellIdentity.cellIdentityWcdma.uarfcn;
5594             cellIdentity.wcdma(wcdma);
5595             break;
5596         }
5597 
5598         case RIL_CELL_INFO_TYPE_CDMA: {
5599             V1_2::CellIdentityCdma cdma;
5600             cdma.base.networkId = rilCellIdentity.cellIdentityCdma.networkId;
5601             cdma.base.systemId = rilCellIdentity.cellIdentityCdma.systemId;
5602             cdma.base.baseStationId =
5603                     rilCellIdentity.cellIdentityCdma.basestationId;
5604             cdma.base.longitude = rilCellIdentity.cellIdentityCdma.longitude;
5605             cdma.base.latitude = rilCellIdentity.cellIdentityCdma.latitude;
5606             cellIdentity.cdma(cdma);
5607             break;
5608         }
5609 
5610         case RIL_CELL_INFO_TYPE_LTE: {
5611             V1_5::CellIdentityLte lte;
5612             lte.base.base.mcc = std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5613             lte.base.base.mnc = ril::util::mnc::decode(rilCellIdentity.cellIdentityLte.mnc);
5614             if (lte.base.base.mcc == "-1") {
5615                 lte.base.base.mcc = "";
5616             }
5617             lte.base.base.ci = rilCellIdentity.cellIdentityLte.ci;
5618             lte.base.base.pci = rilCellIdentity.cellIdentityLte.pci;
5619             lte.base.base.tac = rilCellIdentity.cellIdentityLte.tac;
5620             lte.base.base.earfcn = rilCellIdentity.cellIdentityLte.earfcn;
5621             cellIdentity.lte(lte);
5622             break;
5623         }
5624 
5625         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
5626             V1_5::CellIdentityTdscdma tdscdma;
5627             tdscdma.base.base.mcc = std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5628             tdscdma.base.base.mnc = ril::util::mnc::decode(rilCellIdentity.cellIdentityTdscdma.mnc);
5629             if (tdscdma.base.base.mcc == "-1") {
5630                 tdscdma.base.base.mcc = "";
5631             }
5632             tdscdma.base.base.lac = rilCellIdentity.cellIdentityTdscdma.lac;
5633             tdscdma.base.base.cid = rilCellIdentity.cellIdentityTdscdma.cid;
5634             tdscdma.base.base.cpid = rilCellIdentity.cellIdentityTdscdma.cpid;
5635             cellIdentity.tdscdma(tdscdma);
5636             break;
5637         }
5638 
5639         default: {
5640             break;
5641         }
5642     }
5643 }
5644 
fillCellIdentityResponse_1_2(V1_2::CellIdentity & cellIdentity,RIL_CellIdentity_v1_2 & rilCellIdentity)5645 void fillCellIdentityResponse_1_2(V1_2::CellIdentity &cellIdentity,
5646                                   RIL_CellIdentity_v1_2 &rilCellIdentity) {
5647     cellIdentity.cellIdentityGsm.resize(0);
5648     cellIdentity.cellIdentityWcdma.resize(0);
5649     cellIdentity.cellIdentityCdma.resize(0);
5650     cellIdentity.cellIdentityTdscdma.resize(0);
5651     cellIdentity.cellIdentityLte.resize(0);
5652     cellIdentity.cellInfoType = (CellInfoType)rilCellIdentity.cellInfoType;
5653     switch(rilCellIdentity.cellInfoType) {
5654 
5655         case RIL_CELL_INFO_TYPE_GSM: {
5656             cellIdentity.cellIdentityGsm.resize(1);
5657             cellIdentity.cellIdentityGsm[0].base.mcc =
5658                 std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
5659             cellIdentity.cellIdentityGsm[0].base.mnc =
5660                     ril::util::mnc::decode(rilCellIdentity.cellIdentityGsm.mnc);
5661 
5662             if (cellIdentity.cellIdentityGsm[0].base.mcc == "-1") {
5663                 cellIdentity.cellIdentityGsm[0].base.mcc = "";
5664             }
5665 
5666             cellIdentity.cellIdentityGsm[0].base.lac = rilCellIdentity.cellIdentityGsm.lac;
5667             cellIdentity.cellIdentityGsm[0].base.cid = rilCellIdentity.cellIdentityGsm.cid;
5668             cellIdentity.cellIdentityGsm[0].base.arfcn = rilCellIdentity.cellIdentityGsm.arfcn;
5669             cellIdentity.cellIdentityGsm[0].base.bsic = rilCellIdentity.cellIdentityGsm.bsic;
5670             break;
5671         }
5672 
5673         case RIL_CELL_INFO_TYPE_WCDMA: {
5674             cellIdentity.cellIdentityWcdma.resize(1);
5675             cellIdentity.cellIdentityWcdma[0].base.mcc =
5676                 std::to_string(rilCellIdentity.cellIdentityWcdma.mcc);
5677             cellIdentity.cellIdentityWcdma[0].base.mnc =
5678                     ril::util::mnc::decode(rilCellIdentity.cellIdentityWcdma.mnc);
5679 
5680             if (cellIdentity.cellIdentityWcdma[0].base.mcc == "-1") {
5681                 cellIdentity.cellIdentityWcdma[0].base.mcc = "";
5682             }
5683 
5684             cellIdentity.cellIdentityWcdma[0].base.lac = rilCellIdentity.cellIdentityWcdma.lac;
5685             cellIdentity.cellIdentityWcdma[0].base.cid = rilCellIdentity.cellIdentityWcdma.cid;
5686             cellIdentity.cellIdentityWcdma[0].base.psc = rilCellIdentity.cellIdentityWcdma.psc;
5687             cellIdentity.cellIdentityWcdma[0].base.uarfcn = rilCellIdentity.cellIdentityWcdma.uarfcn;
5688             break;
5689         }
5690 
5691         case RIL_CELL_INFO_TYPE_CDMA: {
5692             cellIdentity.cellIdentityCdma.resize(1);
5693             cellIdentity.cellIdentityCdma[0].base.networkId = rilCellIdentity.cellIdentityCdma.networkId;
5694             cellIdentity.cellIdentityCdma[0].base.systemId = rilCellIdentity.cellIdentityCdma.systemId;
5695             cellIdentity.cellIdentityCdma[0].base.baseStationId =
5696                     rilCellIdentity.cellIdentityCdma.basestationId;
5697             cellIdentity.cellIdentityCdma[0].base.longitude = rilCellIdentity.cellIdentityCdma.longitude;
5698             cellIdentity.cellIdentityCdma[0].base.latitude = rilCellIdentity.cellIdentityCdma.latitude;
5699             break;
5700         }
5701 
5702         case RIL_CELL_INFO_TYPE_LTE: {
5703             cellIdentity.cellIdentityLte.resize(1);
5704             cellIdentity.cellIdentityLte[0].base.mcc =
5705                 std::to_string(rilCellIdentity.cellIdentityLte.mcc);
5706             cellIdentity.cellIdentityLte[0].base.mnc =
5707                     ril::util::mnc::decode(rilCellIdentity.cellIdentityLte.mnc);
5708 
5709             if (cellIdentity.cellIdentityLte[0].base.mcc == "-1") {
5710                 cellIdentity.cellIdentityLte[0].base.mcc = "";
5711             }
5712 
5713             cellIdentity.cellIdentityLte[0].base.ci = rilCellIdentity.cellIdentityLte.ci;
5714             cellIdentity.cellIdentityLte[0].base.pci = rilCellIdentity.cellIdentityLte.pci;
5715             cellIdentity.cellIdentityLte[0].base.tac = rilCellIdentity.cellIdentityLte.tac;
5716             cellIdentity.cellIdentityLte[0].base.earfcn = rilCellIdentity.cellIdentityLte.earfcn;
5717             cellIdentity.cellIdentityLte[0].bandwidth = rilCellIdentity.cellIdentityLte.bandwidth;
5718             break;
5719         }
5720 
5721         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
5722             cellIdentity.cellIdentityTdscdma.resize(1);
5723             cellIdentity.cellIdentityTdscdma[0].base.mcc =
5724                 std::to_string(rilCellIdentity.cellIdentityTdscdma.mcc);
5725             cellIdentity.cellIdentityTdscdma[0].base.mnc =
5726                     ril::util::mnc::decode(rilCellIdentity.cellIdentityTdscdma.mnc);
5727 
5728             if (cellIdentity.cellIdentityTdscdma[0].base.mcc == "-1") {
5729                 cellIdentity.cellIdentityTdscdma[0].base.mcc = "";
5730             }
5731 
5732             cellIdentity.cellIdentityTdscdma[0].base.lac = rilCellIdentity.cellIdentityTdscdma.lac;
5733             cellIdentity.cellIdentityTdscdma[0].base.cid = rilCellIdentity.cellIdentityTdscdma.cid;
5734             cellIdentity.cellIdentityTdscdma[0].base.cpid = rilCellIdentity.cellIdentityTdscdma.cpid;
5735             cellIdentity.cellIdentityTdscdma[0].uarfcn = rilCellIdentity.cellIdentityTdscdma.uarfcn;
5736             break;
5737         }
5738 
5739         default: {
5740             break;
5741         }
5742     }
5743 }
5744 
convertResponseStringEntryToInt(char ** response,int index,int numStrings)5745 int convertResponseStringEntryToInt(char **response, int index, int numStrings) {
5746     if ((response != NULL) &&  (numStrings > index) && (response[index] != NULL)) {
5747         return atoi(response[index]);
5748     }
5749 
5750     return -1;
5751 }
5752 
convertResponseHexStringEntryToInt(char ** response,int index,int numStrings)5753 int convertResponseHexStringEntryToInt(char **response, int index, int numStrings) {
5754     const int hexBase = 16;
5755     if ((response != NULL) &&  (numStrings > index) && (response[index] != NULL)) {
5756         return strtol(response[index], NULL, hexBase);
5757     }
5758 
5759     return -1;
5760 }
5761 
5762 /* Fill Cell Identity info from Voice Registration State Response.
5763  * This fucntion is applicable only for RIL Version < 15.
5764  * Response is a  "char **".
5765  * First and Second entries are in hex string format
5766  * and rest are integers represented in ascii format. */
fillCellIdentityFromVoiceRegStateResponseString(V1_5::CellIdentity & cellIdentity,int numStrings,char ** response)5767 void fillCellIdentityFromVoiceRegStateResponseString(V1_5::CellIdentity &cellIdentity,
5768         int numStrings, char** response) {
5769 
5770     RIL_CellIdentity_v16 rilCellIdentity;
5771     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
5772 
5773     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
5774     switch(rilCellIdentity.cellInfoType) {
5775 
5776         case RIL_CELL_INFO_TYPE_GSM: {
5777             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5778             rilCellIdentity.cellIdentityGsm.lac =
5779                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5780 
5781             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5782             rilCellIdentity.cellIdentityGsm.cid =
5783                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5784 
5785             if (numStrings > 15) {
5786                 rilCellIdentity.cellIdentityGsm.mcc =
5787                         convertResponseStringEntryToInt(response, 15, numStrings);
5788 
5789                 rilCellIdentity.cellIdentityGsm.mnc =
5790                         convertResponseStringEntryToInt(response, 16, numStrings);
5791             }
5792             break;
5793         }
5794 
5795         case RIL_CELL_INFO_TYPE_WCDMA: {
5796             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5797             rilCellIdentity.cellIdentityWcdma.lac =
5798                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5799 
5800             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5801             rilCellIdentity.cellIdentityWcdma.cid =
5802                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5803             rilCellIdentity.cellIdentityWcdma.psc =
5804                     convertResponseStringEntryToInt(response, 14, numStrings);
5805 
5806             if (numStrings > 15) {
5807                 rilCellIdentity.cellIdentityGsm.mcc =
5808                         convertResponseStringEntryToInt(response, 15, numStrings);
5809 
5810                 rilCellIdentity.cellIdentityGsm.mnc =
5811                         convertResponseStringEntryToInt(response, 16, numStrings);
5812             }
5813             break;
5814         }
5815 
5816         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
5817             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5818             rilCellIdentity.cellIdentityTdscdma.lac =
5819                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5820 
5821             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5822             rilCellIdentity.cellIdentityTdscdma.cid =
5823                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5824 
5825             if (numStrings > 15) {
5826                 rilCellIdentity.cellIdentityGsm.mcc =
5827                         convertResponseStringEntryToInt(response, 15, numStrings);
5828 
5829                 rilCellIdentity.cellIdentityGsm.mnc =
5830                         convertResponseStringEntryToInt(response, 16, numStrings);
5831             }
5832             break;
5833         }
5834 
5835         case RIL_CELL_INFO_TYPE_CDMA:{
5836             rilCellIdentity.cellIdentityCdma.basestationId =
5837                     convertResponseStringEntryToInt(response, 4, numStrings);
5838             /* Order of Lat. and Long. swapped between RIL and HIDL interface versions. */
5839             rilCellIdentity.cellIdentityCdma.latitude =
5840                     convertResponseStringEntryToInt(response, 5, numStrings);
5841             rilCellIdentity.cellIdentityCdma.longitude =
5842                     convertResponseStringEntryToInt(response, 6, numStrings);
5843             rilCellIdentity.cellIdentityCdma.systemId =
5844                     convertResponseStringEntryToInt(response, 8, numStrings);
5845             rilCellIdentity.cellIdentityCdma.networkId =
5846                     convertResponseStringEntryToInt(response, 9, numStrings);
5847             break;
5848         }
5849 
5850         case RIL_CELL_INFO_TYPE_LTE:{
5851             /* valid TAC are hexstrings in the range 0x0000 - 0xffff */
5852             rilCellIdentity.cellIdentityLte.tac =
5853                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5854 
5855             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5856             rilCellIdentity.cellIdentityLte.ci =
5857                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5858 
5859             if (numStrings > 15) {
5860                 rilCellIdentity.cellIdentityGsm.mcc =
5861                         convertResponseStringEntryToInt(response, 15, numStrings);
5862 
5863                 rilCellIdentity.cellIdentityGsm.mnc =
5864                         convertResponseStringEntryToInt(response, 16, numStrings);
5865             }
5866             break;
5867         }
5868 
5869         default: {
5870             break;
5871         }
5872     }
5873 
5874     fillCellIdentityResponse_1_5(cellIdentity, rilCellIdentity);
5875 }
5876 
fillCellIdentityFromVoiceRegStateResponseString_1_2(V1_2::CellIdentity & cellIdentity,int numStrings,char ** response)5877 void fillCellIdentityFromVoiceRegStateResponseString_1_2(V1_2::CellIdentity &cellIdentity,
5878         int numStrings, char** response) {
5879     RIL_CellIdentity_v1_2 rilCellIdentity;
5880     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v1_2));
5881 
5882     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
5883 
5884     switch(rilCellIdentity.cellInfoType) {
5885         case RIL_CELL_INFO_TYPE_GSM: {
5886             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5887             rilCellIdentity.cellIdentityGsm.lac =
5888                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5889 
5890             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5891             rilCellIdentity.cellIdentityGsm.cid =
5892                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5893 
5894             if (numStrings > 15) {
5895                 rilCellIdentity.cellIdentityGsm.mcc =
5896                         convertResponseStringEntryToInt(response, 15, numStrings);
5897 
5898                 rilCellIdentity.cellIdentityGsm.mnc =
5899                         convertResponseStringEntryToInt(response, 16, numStrings);
5900             }
5901             break;
5902         }
5903 
5904         case RIL_CELL_INFO_TYPE_WCDMA: {
5905             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5906             rilCellIdentity.cellIdentityWcdma.lac =
5907                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5908 
5909             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5910             rilCellIdentity.cellIdentityWcdma.cid =
5911                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5912             rilCellIdentity.cellIdentityWcdma.psc =
5913                     convertResponseStringEntryToInt(response, 14, numStrings);
5914 
5915             if (numStrings > 15) {
5916                 rilCellIdentity.cellIdentityWcdma.mcc =
5917                         convertResponseStringEntryToInt(response, 15, numStrings);
5918 
5919                 rilCellIdentity.cellIdentityWcdma.mnc =
5920                         convertResponseStringEntryToInt(response, 16, numStrings);
5921             }
5922             break;
5923         }
5924 
5925         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
5926             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
5927             rilCellIdentity.cellIdentityTdscdma.lac =
5928                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5929 
5930             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5931             rilCellIdentity.cellIdentityTdscdma.cid =
5932                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5933 
5934             if (numStrings > 15) {
5935                 rilCellIdentity.cellIdentityTdscdma.mcc =
5936                         convertResponseStringEntryToInt(response, 15, numStrings);
5937 
5938                 rilCellIdentity.cellIdentityTdscdma.mnc =
5939                         convertResponseStringEntryToInt(response, 16, numStrings);
5940             }
5941             break;
5942         }
5943 
5944         case RIL_CELL_INFO_TYPE_CDMA:{
5945             rilCellIdentity.cellIdentityCdma.basestationId =
5946                     convertResponseStringEntryToInt(response, 4, numStrings);
5947             /* Order of Lat. and Long. swapped between RIL and HIDL interface versions. */
5948             rilCellIdentity.cellIdentityCdma.latitude =
5949                     convertResponseStringEntryToInt(response, 5, numStrings);
5950             rilCellIdentity.cellIdentityCdma.longitude =
5951                     convertResponseStringEntryToInt(response, 6, numStrings);
5952             rilCellIdentity.cellIdentityCdma.systemId =
5953                     convertResponseStringEntryToInt(response, 8, numStrings);
5954             rilCellIdentity.cellIdentityCdma.networkId =
5955                     convertResponseStringEntryToInt(response, 9, numStrings);
5956             break;
5957         }
5958 
5959         case RIL_CELL_INFO_TYPE_LTE:{
5960             /* valid TAC are hexstrings in the range 0x0000 - 0xffff */
5961             rilCellIdentity.cellIdentityLte.tac =
5962                     convertResponseHexStringEntryToInt(response, 1, numStrings);
5963 
5964             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
5965             rilCellIdentity.cellIdentityLte.ci =
5966                     convertResponseHexStringEntryToInt(response, 2, numStrings);
5967 
5968             if (numStrings > 15) {
5969                 rilCellIdentity.cellIdentityLte.mcc =
5970                         convertResponseStringEntryToInt(response, 15, numStrings);
5971 
5972                 rilCellIdentity.cellIdentityLte.mnc =
5973                         convertResponseStringEntryToInt(response, 16, numStrings);
5974             }
5975             rilCellIdentity.cellIdentityLte.bandwidth = INT_MAX;
5976             break;
5977         }
5978 
5979         default: {
5980             break;
5981         }
5982     }
5983 
5984     fillCellIdentityResponse_1_2(cellIdentity, rilCellIdentity);
5985 }
5986 
5987 /* Fill Cell Identity info from Data Registration State Response.
5988  * This fucntion is applicable only for RIL Version < 15.
5989  * Response is a  "char **".
5990  * First and Second entries are in hex string format
5991  * and rest are integers represented in ascii format. */
fillCellIdentityFromDataRegStateResponseString_1_5(V1_5::CellIdentity & cellIdentity,int numStrings,char ** response)5992 void fillCellIdentityFromDataRegStateResponseString_1_5(V1_5::CellIdentity &cellIdentity,
5993         int numStrings, char** response) {
5994 
5995     RIL_CellIdentity_v16 rilCellIdentity;
5996     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
5997 
5998     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
5999     switch(rilCellIdentity.cellInfoType) {
6000         case RIL_CELL_INFO_TYPE_GSM: {
6001             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6002             rilCellIdentity.cellIdentityGsm.lac =
6003                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6004 
6005             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6006             rilCellIdentity.cellIdentityGsm.cid =
6007                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6008 
6009             if (numStrings >= 13) {
6010                 rilCellIdentity.cellIdentityGsm.mcc =
6011                         convertResponseStringEntryToInt(response, 11, numStrings);
6012 
6013                 rilCellIdentity.cellIdentityGsm.mnc =
6014                         convertResponseStringEntryToInt(response, 12, numStrings);
6015             } else {
6016                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6017                 rilCellIdentity.cellIdentityGsm.mnc = 0;
6018                 rilCellIdentity.cellIdentityGsm.mcc = 0;
6019             }
6020             break;
6021         }
6022         case RIL_CELL_INFO_TYPE_WCDMA: {
6023             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6024             rilCellIdentity.cellIdentityWcdma.lac =
6025                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6026 
6027             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6028             rilCellIdentity.cellIdentityWcdma.cid =
6029                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6030 
6031             if (numStrings >= 13) {
6032                 rilCellIdentity.cellIdentityWcdma.mcc =
6033                         convertResponseStringEntryToInt(response, 11, numStrings);
6034 
6035                 rilCellIdentity.cellIdentityWcdma.mnc =
6036                         convertResponseStringEntryToInt(response, 12, numStrings);
6037             } else {
6038                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6039                 rilCellIdentity.cellIdentityWcdma.mnc = 0;
6040                 rilCellIdentity.cellIdentityWcdma.mcc = 0;
6041             }
6042             break;
6043         }
6044         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
6045             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6046             rilCellIdentity.cellIdentityTdscdma.lac =
6047                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6048 
6049             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6050             rilCellIdentity.cellIdentityTdscdma.cid =
6051                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6052 
6053             if (numStrings >= 13) {
6054                 rilCellIdentity.cellIdentityTdscdma.mcc =
6055                         convertResponseStringEntryToInt(response, 11, numStrings);
6056 
6057                 rilCellIdentity.cellIdentityTdscdma.mnc =
6058                         convertResponseStringEntryToInt(response, 12, numStrings);
6059             } else {
6060                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6061                 rilCellIdentity.cellIdentityTdscdma.mnc = 0;
6062                 rilCellIdentity.cellIdentityTdscdma.mcc = 0;
6063             }
6064             break;
6065         }
6066         case RIL_CELL_INFO_TYPE_LTE: {
6067             rilCellIdentity.cellIdentityLte.tac =
6068                     convertResponseStringEntryToInt(response, 6, numStrings);
6069             rilCellIdentity.cellIdentityLte.pci =
6070                     convertResponseStringEntryToInt(response, 7, numStrings);
6071             rilCellIdentity.cellIdentityLte.ci =
6072                     convertResponseStringEntryToInt(response, 8, numStrings);
6073 
6074             if (numStrings >= 13) {
6075                 rilCellIdentity.cellIdentityLte.mcc =
6076                         convertResponseStringEntryToInt(response, 11, numStrings);
6077 
6078                 rilCellIdentity.cellIdentityLte.mnc =
6079                         convertResponseStringEntryToInt(response, 12, numStrings);
6080             } else {
6081                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6082                 rilCellIdentity.cellIdentityLte.mnc = 0;
6083                 rilCellIdentity.cellIdentityLte.mcc = 0;
6084             }
6085             break;
6086         }
6087         default: {
6088             break;
6089         }
6090     }
6091 
6092     fillCellIdentityResponse_1_5(cellIdentity, rilCellIdentity);
6093 }
6094 
fillCellIdentityFromDataRegStateResponseString_1_2(V1_2::CellIdentity & cellIdentity,int numStrings,char ** response)6095 void fillCellIdentityFromDataRegStateResponseString_1_2(V1_2::CellIdentity &cellIdentity,
6096         int numStrings, char** response) {
6097 
6098     RIL_CellIdentity_v1_2 rilCellIdentity;
6099     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v1_2));
6100 
6101     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
6102     switch(rilCellIdentity.cellInfoType) {
6103         case RIL_CELL_INFO_TYPE_GSM: {
6104             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6105             rilCellIdentity.cellIdentityGsm.lac =
6106                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6107 
6108             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6109             rilCellIdentity.cellIdentityGsm.cid =
6110                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6111 
6112             if (numStrings >= 13) {
6113                 rilCellIdentity.cellIdentityGsm.mcc =
6114                         convertResponseStringEntryToInt(response, 11, numStrings);
6115 
6116                 rilCellIdentity.cellIdentityGsm.mnc =
6117                         convertResponseStringEntryToInt(response, 12, numStrings);
6118             } else {
6119                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6120                 rilCellIdentity.cellIdentityGsm.mnc = 0;
6121                 rilCellIdentity.cellIdentityGsm.mcc = 0;
6122             }
6123             break;
6124         }
6125         case RIL_CELL_INFO_TYPE_WCDMA: {
6126             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6127             rilCellIdentity.cellIdentityWcdma.lac =
6128                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6129 
6130             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6131             rilCellIdentity.cellIdentityWcdma.cid =
6132                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6133 
6134             if (numStrings >= 13) {
6135                 rilCellIdentity.cellIdentityWcdma.mcc =
6136                         convertResponseStringEntryToInt(response, 11, numStrings);
6137 
6138                 rilCellIdentity.cellIdentityWcdma.mnc =
6139                         convertResponseStringEntryToInt(response, 12, numStrings);
6140             } else {
6141                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6142                 rilCellIdentity.cellIdentityWcdma.mnc = 0;
6143                 rilCellIdentity.cellIdentityWcdma.mcc = 0;
6144             }
6145             break;
6146         }
6147         case RIL_CELL_INFO_TYPE_TD_SCDMA: {
6148             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6149             rilCellIdentity.cellIdentityTdscdma.lac =
6150                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6151 
6152             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6153             rilCellIdentity.cellIdentityTdscdma.cid =
6154                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6155 
6156             if (numStrings >= 13) {
6157                 rilCellIdentity.cellIdentityTdscdma.mcc =
6158                         convertResponseStringEntryToInt(response, 11, numStrings);
6159 
6160                 rilCellIdentity.cellIdentityTdscdma.mnc =
6161                         convertResponseStringEntryToInt(response, 12, numStrings);
6162             } else {
6163                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6164                 rilCellIdentity.cellIdentityTdscdma.mnc = 0;
6165                 rilCellIdentity.cellIdentityTdscdma.mcc = 0;
6166             }
6167             break;
6168         }
6169         case RIL_CELL_INFO_TYPE_LTE: {
6170             rilCellIdentity.cellIdentityLte.tac =
6171                     convertResponseStringEntryToInt(response, 6, numStrings);
6172             rilCellIdentity.cellIdentityLte.pci =
6173                     convertResponseStringEntryToInt(response, 7, numStrings);
6174             rilCellIdentity.cellIdentityLte.ci =
6175                     convertResponseStringEntryToInt(response, 8, numStrings);
6176 
6177             if (numStrings >= 13) {
6178                 rilCellIdentity.cellIdentityLte.mcc =
6179                         convertResponseStringEntryToInt(response, 11, numStrings);
6180 
6181                 rilCellIdentity.cellIdentityLte.mnc =
6182                         convertResponseStringEntryToInt(response, 12, numStrings);
6183             } else {
6184                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6185                 rilCellIdentity.cellIdentityLte.mnc = 0;
6186                 rilCellIdentity.cellIdentityLte.mcc = 0;
6187             }
6188             break;
6189         }
6190         case RIL_CELL_INFO_TYPE_CDMA: {
6191             break;
6192         }
6193         default: {
6194             break;
6195         }
6196     }
6197 
6198     fillCellIdentityResponse_1_2(cellIdentity, rilCellIdentity);
6199 }
6200 
fillCellIdentityFromDataRegStateResponseString(CellIdentity & cellIdentity,int numStrings,char ** response)6201 void fillCellIdentityFromDataRegStateResponseString(CellIdentity &cellIdentity,
6202         int numStrings, char** response) {
6203 
6204     RIL_CellIdentity_v16 rilCellIdentity;
6205     memset(&rilCellIdentity, -1, sizeof(RIL_CellIdentity_v16));
6206 
6207     rilCellIdentity.cellInfoType = getCellInfoTypeRadioTechnology(response[3]);
6208     switch(rilCellIdentity.cellInfoType) {
6209         case RIL_CELL_INFO_TYPE_GSM: {
6210             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6211             rilCellIdentity.cellIdentityGsm.lac =
6212                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6213 
6214             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6215             rilCellIdentity.cellIdentityGsm.cid =
6216                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6217 
6218             if (numStrings >= 13) {
6219                 rilCellIdentity.cellIdentityGsm.mcc =
6220                         convertResponseStringEntryToInt(response, 11, numStrings);
6221 
6222                 rilCellIdentity.cellIdentityGsm.mnc =
6223                         convertResponseStringEntryToInt(response, 12, numStrings);
6224             } else {
6225                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6226                 rilCellIdentity.cellIdentityGsm.mnc = 0;
6227                 rilCellIdentity.cellIdentityGsm.mcc = 0;
6228             }
6229             break;
6230         }
6231         case RIL_CELL_INFO_TYPE_WCDMA: {
6232             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6233             rilCellIdentity.cellIdentityWcdma.lac =
6234                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6235 
6236             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6237             rilCellIdentity.cellIdentityWcdma.cid =
6238                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6239 
6240             if (numStrings >= 13) {
6241                 rilCellIdentity.cellIdentityWcdma.mcc =
6242                         convertResponseStringEntryToInt(response, 11, numStrings);
6243 
6244                 rilCellIdentity.cellIdentityWcdma.mnc =
6245                         convertResponseStringEntryToInt(response, 12, numStrings);
6246             } else {
6247                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6248                 rilCellIdentity.cellIdentityWcdma.mnc = 0;
6249                 rilCellIdentity.cellIdentityWcdma.mcc = 0;
6250             }
6251 
6252             break;
6253         }
6254         case RIL_CELL_INFO_TYPE_TD_SCDMA:{
6255             /* valid LAC are hexstrings in the range 0x0000 - 0xffff */
6256             rilCellIdentity.cellIdentityTdscdma.lac =
6257                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6258 
6259             /* valid CID are hexstrings in the range 0x00000000 - 0xffffffff */
6260             rilCellIdentity.cellIdentityTdscdma.cid =
6261                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6262 
6263             if (numStrings >= 13) {
6264                 rilCellIdentity.cellIdentityTdscdma.mcc =
6265                         convertResponseStringEntryToInt(response, 11, numStrings);
6266 
6267                 rilCellIdentity.cellIdentityTdscdma.mnc =
6268                         convertResponseStringEntryToInt(response, 12, numStrings);
6269             } else {
6270                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6271                 rilCellIdentity.cellIdentityTdscdma.mnc = 0;
6272                 rilCellIdentity.cellIdentityTdscdma.mcc = 0;
6273             }
6274             break;
6275         }
6276         case RIL_CELL_INFO_TYPE_LTE: {
6277             rilCellIdentity.cellIdentityLte.tac =
6278                     convertResponseHexStringEntryToInt(response, 1, numStrings);
6279             rilCellIdentity.cellIdentityLte.ci =
6280                     convertResponseHexStringEntryToInt(response, 2, numStrings);
6281 
6282             if (numStrings >= 13) {
6283                 rilCellIdentity.cellIdentityLte.mcc =
6284                         convertResponseStringEntryToInt(response, 11, numStrings);
6285 
6286                 rilCellIdentity.cellIdentityLte.mnc =
6287                         convertResponseStringEntryToInt(response, 12, numStrings);
6288             } else {
6289                 /* vts check the mcc [0, 999] and mnc [0, 999]. */
6290                 rilCellIdentity.cellIdentityLte.mnc = 0;
6291                 rilCellIdentity.cellIdentityLte.mcc = 0;
6292             }
6293             break;
6294         }
6295         // TODO add CDMA
6296         default: {
6297             break;
6298         }
6299     }
6300 
6301     fillCellIdentityResponse(cellIdentity, rilCellIdentity);
6302 }
6303 
getVoiceRegistrationStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6304 int radio_1_6::getVoiceRegistrationStateResponse(int slotId,
6305                                             int responseType, int serial, RIL_Errno e,
6306                                             void *response, size_t responseLen) {
6307 #if VDBG
6308     RLOGD("getVoiceRegistrationStateResponse: serial %d", serial);
6309 #endif
6310 
6311     if (radioService[slotId]->mRadioResponse != NULL ||
6312         radioService[slotId]->mRadioResponseV1_2 != NULL ||
6313         radioService[slotId]->mRadioResponseV1_5 != NULL ||
6314         radioService[slotId]->mRadioResponseV1_6 != NULL) {
6315         RadioResponseInfo responseInfo = {};
6316         populateResponseInfo(responseInfo, serial, responseType, e);
6317 
6318         VoiceRegStateResult voiceRegResponse = {};
6319         int numStrings = responseLen / sizeof(char *);
6320         if (response == NULL) {
6321                RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
6322                if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6323         } else if (s_vendorFunctions->version >= 15 &&
6324                    radioService[slotId]->mRadioResponseV1_6 != NULL) {
6325             ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6326             populateResponseInfo_1_6(responseInfo_1_6, serial, responseType, e);
6327             RegStateResultV1_6 regResponse = {};
6328             if (numStrings != 18) {
6329                 RLOGE("getVoiceRegistrationStateResponse_1_6 Invalid response: NULL");
6330                 if (e == RIL_E_SUCCESS) responseInfo_1_6.error =
6331                         ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
6332             } else {
6333                 char **resp = (char **) response;
6334                 regResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6335                 int rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6336                 regResponse.rat = (V1_4::RadioTechnology)rat;
6337                 if (rat == RADIO_TECH_EVDO_0 || rat == RADIO_TECH_EVDO_A ||
6338                     rat == RADIO_TECH_EVDO_B || rat == RADIO_TECH_1xRTT ||
6339                     rat == RADIO_TECH_IS95A || rat == RADIO_TECH_IS95B ||
6340                     rat == RADIO_TECH_EHRPD) {
6341                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6342                             Cdma2000RegistrationInfo cdmaInfo;
6343                     cdmaInfo.cssSupported = ATOI_NULL_HANDLED_DEF(resp[7], 0);
6344                     cdmaInfo.roamingIndicator = ATOI_NULL_HANDLED(resp[10]);
6345                     cdmaInfo.systemIsInPrl = (V1_5::PrlIndicator)ATOI_NULL_HANDLED_DEF(resp[11], 0);
6346                     cdmaInfo.defaultRoamingIndicator= ATOI_NULL_HANDLED_DEF(resp[12], 0);
6347                     regResponse.accessTechnologySpecificInfo.cdmaInfo(cdmaInfo);
6348                 } else if (rat == RADIO_TECH_NR) {
6349                     // rat is NR only for NR SA
6350                     V1_6::NrVopsInfo nrVopsInfo;
6351                     nrVopsInfo.vopsSupported =
6352                             ::android::hardware::radio::V1_6::VopsIndicator::VOPS_NOT_SUPPORTED;
6353                     nrVopsInfo.emcSupported =
6354                             ::android::hardware::radio::V1_6::EmcIndicator::EMC_NOT_SUPPORTED;
6355                     nrVopsInfo.emfSupported =
6356                             ::android::hardware::radio::V1_6::EmfIndicator::EMF_NOT_SUPPORTED;
6357                     regResponse.accessTechnologySpecificInfo.ngranNrVopsInfo(nrVopsInfo);
6358 
6359                 } else {
6360                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6361                         EutranRegistrationInfo eutranInfo;
6362                     if (rat == RADIO_TECH_LTE || rat == RADIO_TECH_LTE_CA) {
6363                         eutranInfo.lteVopsInfo.isVopsSupported = false;
6364                         eutranInfo.lteVopsInfo.isEmcBearerSupported = false;
6365                     }
6366                     eutranInfo.nrIndicators.isEndcAvailable = false;
6367                     eutranInfo.nrIndicators.isDcNrRestricted = false;
6368                     eutranInfo.nrIndicators.isEndcAvailable = false;
6369                     regResponse.accessTechnologySpecificInfo.eutranInfo(eutranInfo);
6370                 }
6371                 regResponse.reasonForDenial = (V1_5::RegistrationFailCause)
6372                         ATOI_NULL_HANDLED_DEF(resp[13], 0);
6373                 regResponse.registeredPlmn = convertCharPtrToHidlString(resp[17]);
6374 
6375                 fillCellIdentityFromVoiceRegStateResponseString(regResponse.cellIdentity,
6376                         numStrings, resp);
6377 
6378                 Return<void> retStatus =
6379                     radioService[slotId]
6380                         ->mRadioResponseV1_6
6381                         ->getVoiceRegistrationStateResponse_1_6(
6382                             responseInfo_1_6, regResponse);
6383                 radioService[slotId]->checkReturnStatus(retStatus);
6384             }
6385         } else if (s_vendorFunctions->version <= 14 &&
6386                    radioService[slotId]->mRadioResponseV1_5 != NULL) {
6387             RegStateResultV1_5 regResponse = {};
6388             if (numStrings != 18) {
6389                 RLOGE("getVoiceRegistrationStateResponse_1_5 Invalid response: NULL");
6390                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6391             } else {
6392                 char **resp = (char **) response;
6393                 regResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6394                 int rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6395                 regResponse.rat = (V1_4::RadioTechnology)rat;
6396                 if (rat == RADIO_TECH_EVDO_0 || rat == RADIO_TECH_EVDO_A ||
6397                     rat == RADIO_TECH_EVDO_B || rat == RADIO_TECH_1xRTT ||
6398                     rat == RADIO_TECH_IS95A || rat == RADIO_TECH_IS95B ||
6399                     rat == RADIO_TECH_EHRPD) {
6400                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6401                             Cdma2000RegistrationInfo cdmaInfo;
6402                     cdmaInfo.cssSupported = ATOI_NULL_HANDLED_DEF(resp[7], 0);
6403                     cdmaInfo.roamingIndicator = ATOI_NULL_HANDLED(resp[10]);
6404                     cdmaInfo.systemIsInPrl = (V1_5::PrlIndicator)ATOI_NULL_HANDLED_DEF(resp[11], 0);
6405                     cdmaInfo.defaultRoamingIndicator= ATOI_NULL_HANDLED_DEF(resp[12], 0);
6406                     regResponse.accessTechnologySpecificInfo.cdmaInfo(cdmaInfo);
6407                 } else {
6408                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6409                         EutranRegistrationInfo eutranInfo;
6410                     if (rat == RADIO_TECH_LTE || rat == RADIO_TECH_LTE_CA ||
6411                         rat == RADIO_TECH_NR) {
6412                         eutranInfo.lteVopsInfo.isVopsSupported = false;
6413                         eutranInfo.lteVopsInfo.isEmcBearerSupported = false;
6414                     }
6415                     eutranInfo.nrIndicators.isEndcAvailable = false;
6416                     eutranInfo.nrIndicators.isDcNrRestricted = false;
6417                     eutranInfo.nrIndicators.isEndcAvailable = false;
6418                     regResponse.accessTechnologySpecificInfo.eutranInfo(eutranInfo);
6419                 }
6420                 regResponse.reasonForDenial = (V1_5::RegistrationFailCause)
6421                         ATOI_NULL_HANDLED_DEF(resp[13], 0);
6422                 regResponse.registeredPlmn = convertCharPtrToHidlString(resp[17]);
6423 
6424                 fillCellIdentityFromVoiceRegStateResponseString(regResponse.cellIdentity,
6425                         numStrings, resp);
6426 
6427                 Return<void> retStatus =
6428                     radioService[slotId]
6429                         ->mRadioResponseV1_5
6430                         ->getVoiceRegistrationStateResponse_1_5(
6431                             responseInfo, regResponse);
6432                 radioService[slotId]->checkReturnStatus(retStatus);
6433             }
6434         } else if (s_vendorFunctions->version <= 14 &&
6435                       radioService[slotId]->mRadioResponseV1_2 != NULL) {
6436             V1_2::VoiceRegStateResult voiceRegResponse = {};
6437             int numStrings = responseLen / sizeof(char *);
6438             if (numStrings != 18) {
6439                 RLOGE("getVoiceRegistrationStateResponse_1_21 Invalid response: NULL");
6440                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6441             } else {
6442                 char **resp = (char **) response;
6443                 voiceRegResponse.regState = (RegState) ATOI_NULL_HANDLED_DEF(resp[0], 4);
6444                 voiceRegResponse.rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6445                 voiceRegResponse.cssSupported = ATOI_NULL_HANDLED_DEF(resp[7], 0);
6446                 voiceRegResponse.roamingIndicator = ATOI_NULL_HANDLED(resp[10]);
6447                 voiceRegResponse.systemIsInPrl = ATOI_NULL_HANDLED_DEF(resp[11], 0);
6448                 voiceRegResponse.defaultRoamingIndicator = ATOI_NULL_HANDLED_DEF(resp[12], 0);
6449                 voiceRegResponse.reasonForDenial = ATOI_NULL_HANDLED_DEF(resp[13], 0);
6450                 fillCellIdentityFromVoiceRegStateResponseString_1_2(
6451                         voiceRegResponse.cellIdentity, numStrings, resp);
6452               }
6453             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2->
6454                     getVoiceRegistrationStateResponse_1_2(responseInfo, voiceRegResponse);
6455             radioService[slotId]->checkReturnStatus(retStatus);
6456         } else {
6457               RIL_VoiceRegistrationStateResponse *voiceRegState =
6458                     (RIL_VoiceRegistrationStateResponse *)response;
6459               if (responseLen != sizeof(RIL_VoiceRegistrationStateResponse)) {
6460                   RLOGE("getVoiceRegistrationStateResponse Invalid response: NULL");
6461                   if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6462               } else {
6463                   voiceRegResponse.regState = (RegState) voiceRegState->regState;
6464                   voiceRegResponse.rat = voiceRegState->rat;;
6465                   voiceRegResponse.cssSupported = voiceRegState->cssSupported;
6466                   voiceRegResponse.roamingIndicator = voiceRegState->roamingIndicator;
6467                   voiceRegResponse.systemIsInPrl = voiceRegState->systemIsInPrl;
6468                   voiceRegResponse.defaultRoamingIndicator = voiceRegState->defaultRoamingIndicator;
6469                   voiceRegResponse.reasonForDenial = voiceRegState->reasonForDenial;
6470                   fillCellIdentityResponse(voiceRegResponse.cellIdentity,
6471                           voiceRegState->cellIdentity);
6472               }
6473               Return<void> retStatus =
6474                       radioService[slotId]->mRadioResponse->getVoiceRegistrationStateResponse(
6475                       responseInfo, voiceRegResponse);
6476               radioService[slotId]->checkReturnStatus(retStatus);
6477         }
6478 
6479     } else {
6480         RLOGE("getVoiceRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
6481                 slotId);
6482     }
6483     return 0;
6484 }
6485 
getDataRegistrationStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6486 int radio_1_6::getDataRegistrationStateResponse(int slotId,
6487                                            int responseType, int serial, RIL_Errno e,
6488                                            void *response, size_t responseLen) {
6489 #if VDBG
6490     RLOGD("getDataRegistrationStateResponse: serial %d", serial);
6491 #endif
6492     if (radioService[slotId]->mRadioResponse != NULL ||
6493         radioService[slotId]->mRadioResponseV1_2 != NULL ||
6494         radioService[slotId]->mRadioResponseV1_5 != NULL ||
6495         radioService[slotId]->mRadioResponseV1_6 != NULL) {
6496         RadioResponseInfo responseInfo = {};
6497         DataRegStateResult dataRegResponse = {};
6498         populateResponseInfo(responseInfo, serial, responseType, e);
6499         if (response == NULL) {
6500             RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6501             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6502         } else if (s_vendorFunctions->version >= 15 &&
6503                    radioService[slotId]->mRadioResponseV1_6 != NULL) {
6504             ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6505             populateResponseInfo_1_6(responseInfo_1_6, serial, responseType, e);
6506             RegStateResultV1_6 regResponse = {};
6507             int numStrings = responseLen / sizeof(char *);
6508             if ((numStrings != 6) && (numStrings != 11) && (numStrings != 14)) {
6509                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6510                 if (e == RIL_E_SUCCESS) responseInfo_1_6.error =
6511                         ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
6512             } else {
6513                 char **resp = (char **) response;
6514                 int rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6515                 regResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6516                 regResponse.rat = (V1_4::RadioTechnology)rat;
6517                 regResponse.reasonForDenial =
6518                         (V1_5::RegistrationFailCause)ATOI_NULL_HANDLED(resp[4]);
6519                 if (numStrings > 13) {
6520                     regResponse.registeredPlmn = convertCharPtrToHidlString(resp[13]);
6521                 }
6522 
6523                 fillCellIdentityFromDataRegStateResponseString_1_5(regResponse.cellIdentity,
6524                         numStrings, resp);
6525                 if (rat == RADIO_TECH_NR) {
6526                     // rat is NR only for NR SA
6527                     V1_6::NrVopsInfo nrVopsInfo;
6528                     nrVopsInfo.vopsSupported =
6529                             ::android::hardware::radio::V1_6::VopsIndicator::VOPS_NOT_SUPPORTED;
6530                     nrVopsInfo.emcSupported =
6531                             ::android::hardware::radio::V1_6::EmcIndicator::EMC_NOT_SUPPORTED;
6532                     nrVopsInfo.emfSupported =
6533                             ::android::hardware::radio::V1_6::EmfIndicator::EMF_NOT_SUPPORTED;
6534                     regResponse.accessTechnologySpecificInfo.ngranNrVopsInfo(nrVopsInfo);
6535 
6536                 } else {
6537                     V1_5::RegStateResult::AccessTechnologySpecificInfo::
6538                             EutranRegistrationInfo eutranInfo;
6539                     if (rat == RADIO_TECH_LTE || rat == RADIO_TECH_LTE_CA) {
6540                         eutranInfo.lteVopsInfo.isVopsSupported = false;
6541                         eutranInfo.lteVopsInfo.isEmcBearerSupported = false;
6542                     }
6543                     eutranInfo.nrIndicators.isEndcAvailable = false;
6544                     eutranInfo.nrIndicators.isDcNrRestricted = false;
6545                     eutranInfo.nrIndicators.isEndcAvailable = false;
6546                     regResponse.accessTechnologySpecificInfo.eutranInfo(eutranInfo);
6547                 }
6548 
6549                 Return<void> retStatus =
6550                     radioService[slotId]
6551                         ->mRadioResponseV1_6
6552                         ->getVoiceRegistrationStateResponse_1_6(
6553                             responseInfo_1_6, regResponse);
6554                 radioService[slotId]->checkReturnStatus(retStatus);
6555             }
6556         } else if (s_vendorFunctions->version <= 14 &&
6557                    radioService[slotId]->mRadioResponseV1_5 != NULL) {
6558             RegStateResultV1_5 regResponse = {};
6559             int numStrings = responseLen / sizeof(char *);
6560             if ((numStrings != 6) && (numStrings != 11) && (numStrings != 14)) {
6561                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6562                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6563             } else {
6564                 char **resp = (char **) response;
6565                 int rat = ATOI_NULL_HANDLED_DEF(resp[3], 0);
6566                 regResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6567                 regResponse.rat = (V1_4::RadioTechnology)rat;
6568                 regResponse.reasonForDenial =
6569                         (V1_5::RegistrationFailCause)ATOI_NULL_HANDLED(resp[4]);
6570                 if (numStrings > 13) {
6571                     regResponse.registeredPlmn = convertCharPtrToHidlString(resp[13]);
6572                 }
6573 
6574                 V1_5::RegStateResult::AccessTechnologySpecificInfo::
6575                         EutranRegistrationInfo eutranInfo;
6576                 if (rat == RADIO_TECH_LTE || rat == RADIO_TECH_LTE_CA ||
6577                     rat == RADIO_TECH_NR) {
6578                     eutranInfo.lteVopsInfo.isVopsSupported = false;
6579                     eutranInfo.lteVopsInfo.isEmcBearerSupported = false;
6580                 }
6581                 eutranInfo.nrIndicators.isEndcAvailable = false;
6582                 eutranInfo.nrIndicators.isDcNrRestricted = false;
6583                 eutranInfo.nrIndicators.isEndcAvailable = false;
6584                 regResponse.accessTechnologySpecificInfo.eutranInfo(eutranInfo);
6585 
6586                 fillCellIdentityFromDataRegStateResponseString_1_5(regResponse.cellIdentity,
6587                         numStrings, resp);
6588 
6589                 Return<void> retStatus =
6590                     radioService[slotId]
6591                         ->mRadioResponseV1_5
6592                         ->getDataRegistrationStateResponse_1_5(
6593                             responseInfo, regResponse);
6594                 radioService[slotId]->checkReturnStatus(retStatus);
6595             }
6596         } else if (s_vendorFunctions->version <= 14 &&
6597                     radioService[slotId]->mRadioResponseV1_2 != NULL) {
6598             V1_2::DataRegStateResult dataRegResponse = {};
6599             int numStrings = responseLen / sizeof(char *);
6600             if ((numStrings != 11) && (numStrings != 13) && (numStrings != 14)) {
6601                 RLOGE("getDataRegistrationStateResponse_1_2 Invalid response: NULL");
6602                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6603             } else {
6604                 char **resp = (char **)response;
6605                 dataRegResponse.regState = (RegState)ATOI_NULL_HANDLED_DEF(resp[0], 4);
6606                 dataRegResponse.rat =  ATOI_NULL_HANDLED_DEF(resp[3], 0);
6607                 dataRegResponse.reasonDataDenied =  ATOI_NULL_HANDLED(resp[4]);
6608                 dataRegResponse.maxDataCalls =  ATOI_NULL_HANDLED_DEF(resp[5], 1);
6609                 fillCellIdentityFromDataRegStateResponseString_1_2(dataRegResponse.cellIdentity,
6610                         numStrings, resp);
6611                 Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2->
6612                         getDataRegistrationStateResponse_1_2(responseInfo, dataRegResponse);
6613                 radioService[slotId]->checkReturnStatus(retStatus);
6614             }
6615       } else if (s_vendorFunctions->version <= 14) {
6616             int numStrings = responseLen / sizeof(char *);
6617             if ((numStrings != 11) && (numStrings != 13) && (numStrings != 14)) {
6618                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6619                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6620             } else {
6621                 char **resp = (char **) response;
6622                 dataRegResponse.regState = (RegState) ATOI_NULL_HANDLED_DEF(resp[0], 4);
6623                 dataRegResponse.rat =  ATOI_NULL_HANDLED_DEF(resp[3], 0);
6624                 dataRegResponse.reasonDataDenied =  ATOI_NULL_HANDLED(resp[4]);
6625                 dataRegResponse.maxDataCalls =  ATOI_NULL_HANDLED_DEF(resp[5], 1);
6626                 fillCellIdentityFromDataRegStateResponseString(dataRegResponse.cellIdentity,
6627                         numStrings, resp);
6628             }
6629         } else {
6630             RIL_DataRegistrationStateResponse *dataRegState =
6631                     (RIL_DataRegistrationStateResponse *)response;
6632 
6633             if (responseLen != sizeof(RIL_DataRegistrationStateResponse)) {
6634                 RLOGE("getDataRegistrationStateResponse Invalid response: NULL");
6635                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6636             } else {
6637                 dataRegResponse.regState = (RegState) dataRegState->regState;
6638                 dataRegResponse.rat = dataRegState->rat;
6639                 dataRegResponse.reasonDataDenied = dataRegState->reasonDataDenied;
6640                 dataRegResponse.maxDataCalls = dataRegState->maxDataCalls;
6641                 fillCellIdentityResponse(dataRegResponse.cellIdentity, dataRegState->cellIdentity);
6642             }
6643         }
6644 
6645         Return<void> retStatus =
6646                 radioService[slotId]->mRadioResponse->getDataRegistrationStateResponse(
6647                         responseInfo, dataRegResponse);
6648         radioService[slotId]->checkReturnStatus(retStatus);
6649     } else {
6650         RLOGE("getDataRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
6651                 slotId);
6652     }
6653 
6654     return 0;
6655 }
6656 
getOperatorResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6657 int radio_1_6::getOperatorResponse(int slotId,
6658                               int responseType, int serial, RIL_Errno e, void *response,
6659                               size_t responseLen) {
6660 #if VDBG
6661     RLOGD("getOperatorResponse: serial %d", serial);
6662 #endif
6663 
6664     if (radioService[slotId]->mRadioResponse != NULL) {
6665         RadioResponseInfo responseInfo = {};
6666         populateResponseInfo(responseInfo, serial, responseType, e);
6667         hidl_string longName;
6668         hidl_string shortName;
6669         hidl_string numeric;
6670         int numStrings = responseLen / sizeof(char *);
6671         if (response == NULL || numStrings != 3) {
6672             RLOGE("getOperatorResponse Invalid response: NULL");
6673             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6674 
6675         } else {
6676             char **resp = (char **) response;
6677             longName = convertCharPtrToHidlString(resp[0]);
6678             shortName = convertCharPtrToHidlString(resp[1]);
6679             numeric = convertCharPtrToHidlString(resp[2]);
6680         }
6681         Return<void> retStatus = radioService[slotId]->mRadioResponse->getOperatorResponse(
6682                 responseInfo, longName, shortName, numeric);
6683         radioService[slotId]->checkReturnStatus(retStatus);
6684     } else {
6685         RLOGE("getOperatorResponse: radioService[%d]->mRadioResponse == NULL",
6686                 slotId);
6687     }
6688 
6689     return 0;
6690 }
6691 
setRadioPowerResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6692 int radio_1_6::setRadioPowerResponse(int slotId,
6693                                 int responseType, int serial, RIL_Errno e, void *response,
6694                                 size_t responseLen) {
6695 #if VDBG
6696     RLOGD("setRadioPowerResponse: serial %d", serial);
6697 #endif
6698     RadioResponseInfo responseInfo = {};
6699     ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6700     populateResponseInfo(responseInfo, serial, responseType, e);
6701     populateResponseInfo_1_6(responseInfo_1_6, serial, responseType, e);
6702 
6703     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
6704         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
6705                 ->setRadioPowerResponse_1_6(responseInfo_1_6);
6706         radioService[slotId]->checkReturnStatus(retStatus);
6707     } else if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
6708         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
6709                 ->setRadioPowerResponse_1_5(responseInfo);
6710         radioService[slotId]->checkReturnStatus(retStatus);
6711     } else if (radioService[slotId]->mRadioResponse != NULL) {
6712         Return<void> retStatus = radioService[slotId]->mRadioResponse
6713                 ->setRadioPowerResponse(responseInfo);
6714         radioService[slotId]->checkReturnStatus(retStatus);
6715     } else {
6716         RLOGE("setRadioPowerResponse: radioService[%d]->mRadioResponse == NULL", slotId);
6717     }
6718 
6719     return 0;
6720 }
6721 
sendDtmfResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6722 int radio_1_6::sendDtmfResponse(int slotId,
6723                            int responseType, int serial, RIL_Errno e, void *response,
6724                            size_t responseLen) {
6725 #if VDBG
6726     RLOGD("sendDtmfResponse: serial %d", serial);
6727 #endif
6728 
6729     if (radioService[slotId]->mRadioResponse != NULL) {
6730         RadioResponseInfo responseInfo = {};
6731         populateResponseInfo(responseInfo, serial, responseType, e);
6732         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendDtmfResponse(
6733                 responseInfo);
6734         radioService[slotId]->checkReturnStatus(retStatus);
6735     } else {
6736         RLOGE("sendDtmfResponse: radioService[%d]->mRadioResponse == NULL",
6737                 slotId);
6738     }
6739 
6740     return 0;
6741 }
6742 
makeSendSmsResult(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)6743 SendSmsResult makeSendSmsResult(RadioResponseInfo& responseInfo, int serial, int responseType,
6744                                 RIL_Errno e, void *response, size_t responseLen) {
6745     populateResponseInfo(responseInfo, serial, responseType, e);
6746     SendSmsResult result = {};
6747 
6748     if (response == NULL || responseLen != sizeof(RIL_SMS_Response)) {
6749         RLOGE("Invalid response: NULL");
6750         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6751         result.ackPDU = hidl_string();
6752     } else {
6753         RIL_SMS_Response *resp = (RIL_SMS_Response *) response;
6754         result.messageRef = resp->messageRef;
6755         result.ackPDU = convertCharPtrToHidlString(resp->ackPDU);
6756         result.errorCode = resp->errorCode;
6757     }
6758     return result;
6759 }
6760 
makeSendSmsResult_1_6(::android::hardware::radio::V1_6::RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)6761 SendSmsResult makeSendSmsResult_1_6(
6762         ::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo, int serial,
6763         int responseType, RIL_Errno e, void *response, size_t responseLen) {
6764     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
6765     SendSmsResult result = {};
6766 
6767     if (response == NULL || responseLen != sizeof(RIL_SMS_Response)) {
6768         RLOGE("Invalid response: NULL");
6769         if (e == RIL_E_SUCCESS) {
6770             responseInfo.error = ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
6771         }
6772         result.ackPDU = hidl_string();
6773     } else {
6774         RIL_SMS_Response *resp = (RIL_SMS_Response *) response;
6775         result.messageRef = resp->messageRef;
6776         result.ackPDU = convertCharPtrToHidlString(resp->ackPDU);
6777         result.errorCode = resp->errorCode;
6778     }
6779     return result;
6780 }
6781 
sendSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6782 int radio_1_6::sendSmsResponse(int slotId,
6783                           int responseType, int serial, RIL_Errno e, void *response,
6784                           size_t responseLen) {
6785 #if VDBG
6786     RLOGD("sendSmsResponse: serial %d", serial);
6787 #endif
6788 
6789     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
6790         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6791         SendSmsResult result = makeSendSmsResult_1_6(responseInfo_1_6, serial, responseType, e, response,
6792                 responseLen);
6793 
6794         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
6795                 ->sendSmsResponse_1_6(responseInfo_1_6, result);
6796         radioService[slotId]->checkReturnStatus(retStatus);
6797     } else if (radioService[slotId]->mRadioResponse != NULL) {
6798         RadioResponseInfo responseInfo = {};
6799         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
6800                 responseLen);
6801 
6802         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendSmsResponse(responseInfo,
6803                 result);
6804         radioService[slotId]->checkReturnStatus(retStatus);
6805     } else {
6806         RLOGE("sendSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
6807     }
6808 
6809     return 0;
6810 }
6811 
sendSmsExpectMoreResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6812 int radio_1_6::sendSmsExpectMoreResponse(int slotId,
6813                                     int responseType, int serial, RIL_Errno e, void *response,
6814                                     size_t responseLen) {
6815 #if VDBG
6816     RLOGD("sendSmsExpectMoreResponse: serial %d", serial);
6817 #endif
6818 
6819     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
6820         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6821         SendSmsResult result = makeSendSmsResult_1_6(responseInfo_1_6, serial, responseType, e, response,
6822                 responseLen);
6823 
6824         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
6825                 ->sendSmsExpectMoreResponse_1_6(responseInfo_1_6, result);
6826         radioService[slotId]->checkReturnStatus(retStatus);
6827     } else if (radioService[slotId]->mRadioResponse != NULL) {
6828         RadioResponseInfo responseInfo = {};
6829         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
6830                 responseLen);
6831 
6832         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendSMSExpectMoreResponse(
6833                 responseInfo, result);
6834         radioService[slotId]->checkReturnStatus(retStatus);
6835     } else {
6836         RLOGE("sendSMSExpectMoreResponse: radioService[%d]->mRadioResponse == NULL", slotId);
6837     }
6838 
6839     return 0;
6840 }
6841 
setupDataCallResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6842 int radio_1_6::setupDataCallResponse(int slotId,
6843                                  int responseType, int serial, RIL_Errno e, void *response,
6844                                  size_t responseLen) {
6845 #if VDBG
6846     RLOGD("setupDataCallResponse: serial %d", serial);
6847 #endif
6848     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
6849         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
6850         populateResponseInfo_1_6(responseInfo_1_6, serial, responseType, e);
6851         ::android::hardware::radio::V1_6::SetupDataCallResult result;
6852         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
6853             if (response != NULL) {
6854                 RLOGE("setupDataCallResponse_1_6: Invalid response");
6855                 if (e == RIL_E_SUCCESS) responseInfo_1_6.error =
6856                         ::android::hardware::radio::V1_6::RadioError::INVALID_RESPONSE;
6857             }
6858             result.cause = ::android::hardware::radio::V1_6::DataCallFailCause::ERROR_UNSPECIFIED;
6859             result.type = ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
6860             result.ifname = hidl_string();
6861             result.addresses = hidl_vec<::android::hardware::radio::V1_5::LinkAddress>();
6862             result.dnses = hidl_vec<hidl_string>();
6863             result.gateways = hidl_vec<hidl_string>();
6864             result.pcscf = hidl_vec<hidl_string>();
6865             result.trafficDescriptors =
6866                     hidl_vec<::android::hardware::radio::V1_6::TrafficDescriptor>();
6867         } else {
6868             convertRilDataCallToHal((RIL_Data_Call_Response_v12 *) response, result);
6869         }
6870 
6871         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6->setupDataCallResponse_1_6(
6872                 responseInfo_1_6, result);
6873         radioService[slotId]->checkReturnStatus(retStatus);
6874     } else if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
6875         RadioResponseInfo responseInfo = {};
6876         populateResponseInfo(responseInfo, serial, responseType, e);
6877         ::android::hardware::radio::V1_5::SetupDataCallResult result;
6878         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
6879             if (response != NULL) {
6880                 RLOGE("setupDataCallResponse_1_5: Invalid response");
6881                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6882             }
6883             result.cause = ::android::hardware::radio::V1_4::DataCallFailCause::ERROR_UNSPECIFIED;
6884             result.type = ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
6885             result.ifname = hidl_string();
6886             result.addresses = hidl_vec<::android::hardware::radio::V1_5::LinkAddress>();
6887             result.dnses = hidl_vec<hidl_string>();
6888             result.gateways = hidl_vec<hidl_string>();
6889             result.pcscf = hidl_vec<hidl_string>();
6890         } else {
6891             convertRilDataCallToHal((RIL_Data_Call_Response_v12 *) response, result);
6892         }
6893 
6894         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5->setupDataCallResponse_1_5(
6895                 responseInfo, result);
6896         radioService[slotId]->checkReturnStatus(retStatus);
6897     } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
6898         RadioResponseInfo responseInfo = {};
6899         populateResponseInfo(responseInfo, serial, responseType, e);
6900         ::android::hardware::radio::V1_4::SetupDataCallResult result;
6901         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
6902             if (response != NULL) {
6903                 RLOGE("setupDataCallResponse_1_4: Invalid response");
6904                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6905             }
6906             result.cause = ::android::hardware::radio::V1_4::DataCallFailCause::ERROR_UNSPECIFIED;
6907             result.type = ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
6908             result.ifname = hidl_string();
6909             result.addresses = hidl_vec<hidl_string>();
6910             result.dnses = hidl_vec<hidl_string>();
6911             result.gateways = hidl_vec<hidl_string>();
6912             result.pcscf = hidl_vec<hidl_string>();
6913         } else {
6914             convertRilDataCallToHal((RIL_Data_Call_Response_v11 *) response, result);
6915         }
6916 
6917         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4->setupDataCallResponse_1_4(
6918                 responseInfo, result);
6919         radioService[slotId]->checkReturnStatus(retStatus);
6920     } else if (radioService[slotId]->mRadioResponse != NULL) {
6921         RadioResponseInfo responseInfo = {};
6922         populateResponseInfo(responseInfo, serial, responseType, e);
6923 
6924         SetupDataCallResult result = {};
6925         if (response == NULL || (responseLen % sizeof(RIL_Data_Call_Response_v11)) != 0) {
6926            if (response != NULL) {
6927                RLOGE("setupDataCallResponse: Invalid response");
6928                if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6929            }
6930            result.status = DataCallFailCause::ERROR_UNSPECIFIED;
6931            result.type = hidl_string();
6932            result.ifname = hidl_string();
6933            result.addresses = hidl_string();
6934            result.dnses = hidl_string();
6935            result.gateways = hidl_string();
6936            result.pcscf = hidl_string();
6937         } else {
6938            convertRilDataCallToHal((RIL_Data_Call_Response_v11 *) response, result);
6939         }
6940 
6941         Return<void> retStatus = radioService[slotId]->mRadioResponse->setupDataCallResponse(
6942                responseInfo, result);
6943         radioService[slotId]->checkReturnStatus(retStatus);
6944     } else {
6945         RLOGE("setupDataCallResponse: radioService[%d]->mRadioResponse == NULL", slotId);
6946     }
6947 
6948     return 0;
6949 }
6950 
responseIccIo(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)6951 IccIoResult responseIccIo(RadioResponseInfo& responseInfo, int serial, int responseType,
6952                            RIL_Errno e, void *response, size_t responseLen) {
6953     populateResponseInfo(responseInfo, serial, responseType, e);
6954     IccIoResult result = {};
6955 
6956     if (response == NULL || responseLen != sizeof(RIL_SIM_IO_Response)) {
6957         RLOGE("Invalid response: NULL");
6958         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
6959         result.simResponse = hidl_string();
6960     } else {
6961         RIL_SIM_IO_Response *resp = (RIL_SIM_IO_Response *) response;
6962         result.sw1 = resp->sw1;
6963         result.sw2 = resp->sw2;
6964         result.simResponse = convertCharPtrToHidlString(resp->simResponse);
6965     }
6966     return result;
6967 }
6968 
iccIOForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6969 int radio_1_6::iccIOForAppResponse(int slotId,
6970                       int responseType, int serial, RIL_Errno e, void *response,
6971                       size_t responseLen) {
6972 #if VDBG
6973     RLOGD("iccIOForAppResponse: serial %d", serial);
6974 #endif
6975 
6976     if (radioService[slotId]->mRadioResponse != NULL) {
6977         RadioResponseInfo responseInfo = {};
6978         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
6979                 responseLen);
6980 
6981         Return<void> retStatus = radioService[slotId]->mRadioResponse->iccIOForAppResponse(
6982                 responseInfo, result);
6983         radioService[slotId]->checkReturnStatus(retStatus);
6984     } else {
6985         RLOGE("iccIOForAppResponse: radioService[%d]->mRadioResponse == NULL", slotId);
6986     }
6987 
6988     return 0;
6989 }
6990 
sendUssdResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)6991 int radio_1_6::sendUssdResponse(int slotId,
6992                            int responseType, int serial, RIL_Errno e, void *response,
6993                            size_t responseLen) {
6994 #if VDBG
6995     RLOGD("sendUssdResponse: serial %d", serial);
6996 #endif
6997 
6998     if (radioService[slotId]->mRadioResponse != NULL) {
6999         RadioResponseInfo responseInfo = {};
7000         populateResponseInfo(responseInfo, serial, responseType, e);
7001         Return<void> retStatus = radioService[slotId]->mRadioResponse->sendUssdResponse(
7002                 responseInfo);
7003         radioService[slotId]->checkReturnStatus(retStatus);
7004     } else {
7005         RLOGE("sendUssdResponse: radioService[%d]->mRadioResponse == NULL",
7006                 slotId);
7007     }
7008 
7009     return 0;
7010 }
7011 
cancelPendingUssdResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7012 int radio_1_6::cancelPendingUssdResponse(int slotId,
7013                                     int responseType, int serial, RIL_Errno e, void *response,
7014                                     size_t responseLen) {
7015 #if VDBG
7016     RLOGD("cancelPendingUssdResponse: serial %d", serial);
7017 #endif
7018 
7019     if (radioService[slotId]->mRadioResponse != NULL) {
7020         RadioResponseInfo responseInfo = {};
7021         populateResponseInfo(responseInfo, serial, responseType, e);
7022         Return<void> retStatus = radioService[slotId]->mRadioResponse->cancelPendingUssdResponse(
7023                 responseInfo);
7024         radioService[slotId]->checkReturnStatus(retStatus);
7025     } else {
7026         RLOGE("cancelPendingUssdResponse: radioService[%d]->mRadioResponse == NULL",
7027                 slotId);
7028     }
7029 
7030     return 0;
7031 }
7032 
getClirResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7033 int radio_1_6::getClirResponse(int slotId,
7034                               int responseType, int serial, RIL_Errno e, void *response,
7035                               size_t responseLen) {
7036 #if VDBG
7037     RLOGD("getClirResponse: serial %d", serial);
7038 #endif
7039 
7040     if (radioService[slotId]->mRadioResponse != NULL) {
7041         RadioResponseInfo responseInfo = {};
7042         populateResponseInfo(responseInfo, serial, responseType, e);
7043         int n = -1, m = -1;
7044         int numInts = responseLen / sizeof(int);
7045         if (response == NULL || numInts != 2) {
7046             RLOGE("getClirResponse Invalid response: NULL");
7047             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7048         } else {
7049             int *pInt = (int *) response;
7050             n = pInt[0];
7051             m = pInt[1];
7052         }
7053         Return<void> retStatus = radioService[slotId]->mRadioResponse->getClirResponse(responseInfo,
7054                 n, m);
7055         radioService[slotId]->checkReturnStatus(retStatus);
7056     } else {
7057         RLOGE("getClirResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7058     }
7059 
7060     return 0;
7061 }
7062 
setClirResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7063 int radio_1_6::setClirResponse(int slotId,
7064                           int responseType, int serial, RIL_Errno e, void *response,
7065                           size_t responseLen) {
7066 #if VDBG
7067     RLOGD("setClirResponse: serial %d", serial);
7068 #endif
7069 
7070     if (radioService[slotId]->mRadioResponse != NULL) {
7071         RadioResponseInfo responseInfo = {};
7072         populateResponseInfo(responseInfo, serial, responseType, e);
7073         Return<void> retStatus = radioService[slotId]->mRadioResponse->setClirResponse(
7074                 responseInfo);
7075         radioService[slotId]->checkReturnStatus(retStatus);
7076     } else {
7077         RLOGE("setClirResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7078     }
7079 
7080     return 0;
7081 }
7082 
getCallForwardStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7083 int radio_1_6::getCallForwardStatusResponse(int slotId,
7084                                        int responseType, int serial, RIL_Errno e,
7085                                        void *response, size_t responseLen) {
7086 #if VDBG
7087     RLOGD("getCallForwardStatusResponse: serial %d", serial);
7088 #endif
7089 
7090     if (radioService[slotId]->mRadioResponse != NULL) {
7091         RadioResponseInfo responseInfo = {};
7092         populateResponseInfo(responseInfo, serial, responseType, e);
7093         hidl_vec<CallForwardInfo> callForwardInfos;
7094 
7095         if ((response == NULL && responseLen != 0)
7096                 || responseLen % sizeof(RIL_CallForwardInfo *) != 0) {
7097             RLOGE("getCallForwardStatusResponse Invalid response: NULL");
7098             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7099         } else {
7100             int num = responseLen / sizeof(RIL_CallForwardInfo *);
7101             callForwardInfos.resize(num);
7102             for (int i = 0 ; i < num; i++) {
7103                 RIL_CallForwardInfo *resp = ((RIL_CallForwardInfo **) response)[i];
7104                 callForwardInfos[i].status = (CallForwardInfoStatus) resp->status;
7105                 callForwardInfos[i].reason = resp->reason;
7106                 callForwardInfos[i].serviceClass = resp->serviceClass;
7107                 callForwardInfos[i].toa = resp->toa;
7108                 callForwardInfos[i].number = convertCharPtrToHidlString(resp->number);
7109                 callForwardInfos[i].timeSeconds = resp->timeSeconds;
7110             }
7111         }
7112 
7113         Return<void> retStatus = radioService[slotId]->mRadioResponse->getCallForwardStatusResponse(
7114                 responseInfo, callForwardInfos);
7115         radioService[slotId]->checkReturnStatus(retStatus);
7116     } else {
7117         RLOGE("getCallForwardStatusResponse: radioService[%d]->mRadioResponse == NULL",
7118                 slotId);
7119     }
7120 
7121     return 0;
7122 }
7123 
setCallForwardResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7124 int radio_1_6::setCallForwardResponse(int slotId,
7125                                  int responseType, int serial, RIL_Errno e, void *response,
7126                                  size_t responseLen) {
7127 #if VDBG
7128     RLOGD("setCallForwardResponse: serial %d", serial);
7129 #endif
7130 
7131     if (radioService[slotId]->mRadioResponse != NULL) {
7132         RadioResponseInfo responseInfo = {};
7133         populateResponseInfo(responseInfo, serial, responseType, e);
7134         Return<void> retStatus = radioService[slotId]->mRadioResponse->setCallForwardResponse(
7135                 responseInfo);
7136         radioService[slotId]->checkReturnStatus(retStatus);
7137     } else {
7138         RLOGE("setCallForwardResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7139     }
7140 
7141     return 0;
7142 }
7143 
getCallWaitingResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7144 int radio_1_6::getCallWaitingResponse(int slotId,
7145                                  int responseType, int serial, RIL_Errno e, void *response,
7146                                  size_t responseLen) {
7147 #if VDBG
7148     RLOGD("getCallWaitingResponse: serial %d", serial);
7149 #endif
7150 
7151     if (radioService[slotId]->mRadioResponse != NULL) {
7152         RadioResponseInfo responseInfo = {};
7153         populateResponseInfo(responseInfo, serial, responseType, e);
7154         bool enable = false;
7155         int serviceClass = -1;
7156         int numInts = responseLen / sizeof(int);
7157         if (response == NULL || numInts != 2) {
7158             RLOGE("getCallWaitingResponse Invalid response: NULL");
7159             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7160         } else {
7161             int *pInt = (int *) response;
7162             enable = pInt[0] == 1 ? true : false;
7163             serviceClass = pInt[1];
7164         }
7165         Return<void> retStatus = radioService[slotId]->mRadioResponse->getCallWaitingResponse(
7166                 responseInfo, enable, serviceClass);
7167         radioService[slotId]->checkReturnStatus(retStatus);
7168     } else {
7169         RLOGE("getCallWaitingResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7170     }
7171 
7172     return 0;
7173 }
7174 
setCallWaitingResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7175 int radio_1_6::setCallWaitingResponse(int slotId,
7176                                  int responseType, int serial, RIL_Errno e, void *response,
7177                                  size_t responseLen) {
7178 #if VDBG
7179     RLOGD("setCallWaitingResponse: serial %d", serial);
7180 #endif
7181 
7182     if (radioService[slotId]->mRadioResponse != NULL) {
7183         RadioResponseInfo responseInfo = {};
7184         populateResponseInfo(responseInfo, serial, responseType, e);
7185         Return<void> retStatus = radioService[slotId]->mRadioResponse->setCallWaitingResponse(
7186                 responseInfo);
7187         radioService[slotId]->checkReturnStatus(retStatus);
7188     } else {
7189         RLOGE("setCallWaitingResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7190     }
7191 
7192     return 0;
7193 }
7194 
acknowledgeLastIncomingGsmSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7195 int radio_1_6::acknowledgeLastIncomingGsmSmsResponse(int slotId,
7196                                                 int responseType, int serial, RIL_Errno e,
7197                                                 void *response, size_t responseLen) {
7198 #if VDBG
7199     RLOGD("acknowledgeLastIncomingGsmSmsResponse: serial %d", serial);
7200 #endif
7201 
7202     if (radioService[slotId]->mRadioResponse != NULL) {
7203         RadioResponseInfo responseInfo = {};
7204         populateResponseInfo(responseInfo, serial, responseType, e);
7205         Return<void> retStatus =
7206                 radioService[slotId]->mRadioResponse->acknowledgeLastIncomingGsmSmsResponse(
7207                 responseInfo);
7208         radioService[slotId]->checkReturnStatus(retStatus);
7209     } else {
7210         RLOGE("acknowledgeLastIncomingGsmSmsResponse: radioService[%d]->mRadioResponse "
7211                 "== NULL", slotId);
7212     }
7213 
7214     return 0;
7215 }
7216 
acceptCallResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7217 int radio_1_6::acceptCallResponse(int slotId,
7218                              int responseType, int serial, RIL_Errno e,
7219                              void *response, size_t responseLen) {
7220 #if VDBG
7221     RLOGD("acceptCallResponse: serial %d", serial);
7222 #endif
7223 
7224     if (radioService[slotId]->mRadioResponse != NULL) {
7225         RadioResponseInfo responseInfo = {};
7226         populateResponseInfo(responseInfo, serial, responseType, e);
7227         Return<void> retStatus = radioService[slotId]->mRadioResponse->acceptCallResponse(
7228                 responseInfo);
7229         radioService[slotId]->checkReturnStatus(retStatus);
7230     } else {
7231         RLOGE("acceptCallResponse: radioService[%d]->mRadioResponse == NULL",
7232                 slotId);
7233     }
7234 
7235     return 0;
7236 }
7237 
deactivateDataCallResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7238 int radio_1_6::deactivateDataCallResponse(int slotId,
7239                                                 int responseType, int serial, RIL_Errno e,
7240                                                 void *response, size_t responseLen) {
7241 #if VDBG
7242     RLOGD("deactivateDataCallResponse: serial %d", serial);
7243 #endif
7244 
7245     if (radioService[slotId]->mRadioResponse != NULL) {
7246         RadioResponseInfo responseInfo = {};
7247         populateResponseInfo(responseInfo, serial, responseType, e);
7248         Return<void> retStatus = radioService[slotId]->mRadioResponse->deactivateDataCallResponse(
7249                 responseInfo);
7250         radioService[slotId]->checkReturnStatus(retStatus);
7251     } else {
7252         RLOGE("deactivateDataCallResponse: radioService[%d]->mRadioResponse == NULL",
7253                 slotId);
7254     }
7255 
7256     return 0;
7257 }
7258 
getFacilityLockForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7259 int radio_1_6::getFacilityLockForAppResponse(int slotId,
7260                                         int responseType, int serial, RIL_Errno e,
7261                                         void *response, size_t responseLen) {
7262 #if VDBG
7263     RLOGD("getFacilityLockForAppResponse: serial %d", serial);
7264 #endif
7265 
7266     if (radioService[slotId]->mRadioResponse != NULL) {
7267         RadioResponseInfo responseInfo = {};
7268         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
7269         Return<void> retStatus = radioService[slotId]->mRadioResponse->
7270                 getFacilityLockForAppResponse(responseInfo, ret);
7271         radioService[slotId]->checkReturnStatus(retStatus);
7272     } else {
7273         RLOGE("getFacilityLockForAppResponse: radioService[%d]->mRadioResponse == NULL",
7274                 slotId);
7275     }
7276 
7277     return 0;
7278 }
7279 
setFacilityLockForAppResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7280 int radio_1_6::setFacilityLockForAppResponse(int slotId,
7281                                       int responseType, int serial, RIL_Errno e,
7282                                       void *response, size_t responseLen) {
7283 #if VDBG
7284     RLOGD("setFacilityLockForAppResponse: serial %d", serial);
7285 #endif
7286 
7287     if (radioService[slotId]->mRadioResponse != NULL) {
7288         RadioResponseInfo responseInfo = {};
7289         int ret = responseIntOrEmpty(responseInfo, serial, responseType, e, response, responseLen);
7290         Return<void> retStatus
7291                 = radioService[slotId]->mRadioResponse->setFacilityLockForAppResponse(responseInfo,
7292                 ret);
7293         radioService[slotId]->checkReturnStatus(retStatus);
7294     } else {
7295         RLOGE("setFacilityLockForAppResponse: radioService[%d]->mRadioResponse == NULL",
7296                 slotId);
7297     }
7298 
7299     return 0;
7300 }
7301 
setBarringPasswordResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7302 int radio_1_6::setBarringPasswordResponse(int slotId,
7303                              int responseType, int serial, RIL_Errno e,
7304                              void *response, size_t responseLen) {
7305 #if VDBG
7306     RLOGD("acceptCallResponse: serial %d", serial);
7307 #endif
7308 
7309     if (radioService[slotId]->mRadioResponse != NULL) {
7310         RadioResponseInfo responseInfo = {};
7311         populateResponseInfo(responseInfo, serial, responseType, e);
7312         Return<void> retStatus
7313                 = radioService[slotId]->mRadioResponse->setBarringPasswordResponse(responseInfo);
7314         radioService[slotId]->checkReturnStatus(retStatus);
7315     } else {
7316         RLOGE("setBarringPasswordResponse: radioService[%d]->mRadioResponse == NULL",
7317                 slotId);
7318     }
7319 
7320     return 0;
7321 }
7322 
getNetworkSelectionModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7323 int radio_1_6::getNetworkSelectionModeResponse(int slotId,
7324                                           int responseType, int serial, RIL_Errno e, void *response,
7325                                           size_t responseLen) {
7326 #if VDBG
7327     RLOGD("getNetworkSelectionModeResponse: serial %d", serial);
7328 #endif
7329 
7330     if (radioService[slotId]->mRadioResponse != NULL) {
7331         RadioResponseInfo responseInfo = {};
7332         populateResponseInfo(responseInfo, serial, responseType, e);
7333         bool manual = false;
7334         if (response == NULL || responseLen != sizeof(int)) {
7335             RLOGE("getNetworkSelectionModeResponse Invalid response: NULL");
7336             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7337         } else {
7338             int *pInt = (int *) response;
7339             manual = pInt[0] == 1 ? true : false;
7340         }
7341         Return<void> retStatus
7342                 = radioService[slotId]->mRadioResponse->getNetworkSelectionModeResponse(
7343                 responseInfo,
7344                 manual);
7345         radioService[slotId]->checkReturnStatus(retStatus);
7346     } else {
7347         RLOGE("getNetworkSelectionModeResponse: radioService[%d]->mRadioResponse == NULL",
7348                 slotId);
7349     }
7350 
7351     return 0;
7352 }
7353 
setNetworkSelectionModeAutomaticResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7354 int radio_1_6::setNetworkSelectionModeAutomaticResponse(int slotId, int responseType, int serial,
7355                                                     RIL_Errno e, void *response,
7356                                                     size_t responseLen) {
7357 #if VDBG
7358     RLOGD("setNetworkSelectionModeAutomaticResponse: serial %d", serial);
7359 #endif
7360 
7361     if (radioService[slotId]->mRadioResponse != NULL) {
7362         RadioResponseInfo responseInfo = {};
7363         populateResponseInfo(responseInfo, serial, responseType, e);
7364         Return<void> retStatus
7365                 = radioService[slotId]->mRadioResponse->setNetworkSelectionModeAutomaticResponse(
7366                 responseInfo);
7367         radioService[slotId]->checkReturnStatus(retStatus);
7368     } else {
7369         RLOGE("setNetworkSelectionModeAutomaticResponse: radioService[%d]->mRadioResponse "
7370                 "== NULL", slotId);
7371     }
7372 
7373     return 0;
7374 }
7375 
setNetworkSelectionModeManualResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7376 int radio_1_6::setNetworkSelectionModeManualResponse(int slotId,
7377                              int responseType, int serial, RIL_Errno e,
7378                              void *response, size_t responseLen) {
7379 #if VDBG
7380     RLOGD("setNetworkSelectionModeManualResponse: serial %d", serial);
7381 #endif
7382     RadioResponseInfo responseInfo = {};
7383     populateResponseInfo(responseInfo, serial, responseType, e);
7384 
7385     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
7386         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
7387                 ->setNetworkSelectionModeManualResponse_1_5(responseInfo);
7388         radioService[slotId]->checkReturnStatus(retStatus);
7389     } else if (radioService[slotId]->mRadioResponse != NULL) {
7390         Return<void> retStatus = radioService[slotId]->mRadioResponse
7391                 ->setNetworkSelectionModeManualResponse(responseInfo);
7392         radioService[slotId]->checkReturnStatus(retStatus);
7393     } else {
7394         RLOGE("acceptCallResponse: radioService[%d]->setNetworkSelectionModeManualResponse "
7395                 "== NULL", slotId);
7396     }
7397 
7398     return 0;
7399 }
7400 
convertOperatorStatusToInt(const char * str)7401 int convertOperatorStatusToInt(const char *str) {
7402     if (strncmp("unknown", str, 9) == 0) {
7403         return (int) OperatorStatus::UNKNOWN;
7404     } else if (strncmp("available", str, 9) == 0) {
7405         return (int) OperatorStatus::AVAILABLE;
7406     } else if (strncmp("current", str, 9) == 0) {
7407         return (int) OperatorStatus::CURRENT;
7408     } else if (strncmp("forbidden", str, 9) == 0) {
7409         return (int) OperatorStatus::FORBIDDEN;
7410     } else {
7411         return -1;
7412     }
7413 }
7414 
getAvailableNetworksResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7415 int radio_1_6::getAvailableNetworksResponse(int slotId,
7416                               int responseType, int serial, RIL_Errno e, void *response,
7417                               size_t responseLen) {
7418 #if VDBG
7419     RLOGD("getAvailableNetworksResponse: serial %d", serial);
7420 #endif
7421 
7422     if (radioService[slotId]->mRadioResponse != NULL) {
7423         RadioResponseInfo responseInfo = {};
7424         populateResponseInfo(responseInfo, serial, responseType, e);
7425         hidl_vec<OperatorInfo> networks;
7426         if ((response == NULL && responseLen != 0)
7427                 || responseLen % (4 * sizeof(char *))!= 0) {
7428             RLOGE("getAvailableNetworksResponse Invalid response: NULL");
7429             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7430         } else {
7431             char **resp = (char **) response;
7432             int numStrings = responseLen / sizeof(char *);
7433             networks.resize(numStrings/4);
7434             for (int i = 0, j = 0; i < numStrings; i = i + 4, j++) {
7435                 networks[j].alphaLong = convertCharPtrToHidlString(resp[i]);
7436                 networks[j].alphaShort = convertCharPtrToHidlString(resp[i + 1]);
7437                 networks[j].operatorNumeric = convertCharPtrToHidlString(resp[i + 2]);
7438                 int status = convertOperatorStatusToInt(resp[i + 3]);
7439                 if (status == -1) {
7440                     if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7441                 } else {
7442                     networks[j].status = (OperatorStatus) status;
7443                 }
7444             }
7445         }
7446         Return<void> retStatus
7447                 = radioService[slotId]->mRadioResponse->getAvailableNetworksResponse(responseInfo,
7448                 networks);
7449         radioService[slotId]->checkReturnStatus(retStatus);
7450     } else {
7451         RLOGE("getAvailableNetworksResponse: radioService[%d]->mRadioResponse == NULL",
7452                 slotId);
7453     }
7454 
7455     return 0;
7456 }
7457 
startDtmfResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7458 int radio_1_6::startDtmfResponse(int slotId,
7459                             int responseType, int serial, RIL_Errno e,
7460                             void *response, size_t responseLen) {
7461 #if VDBG
7462     RLOGD("startDtmfResponse: serial %d", serial);
7463 #endif
7464 
7465     if (radioService[slotId]->mRadioResponse != NULL) {
7466         RadioResponseInfo responseInfo = {};
7467         populateResponseInfo(responseInfo, serial, responseType, e);
7468         Return<void> retStatus
7469                 = radioService[slotId]->mRadioResponse->startDtmfResponse(responseInfo);
7470         radioService[slotId]->checkReturnStatus(retStatus);
7471     } else {
7472         RLOGE("startDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7473     }
7474 
7475     return 0;
7476 }
7477 
stopDtmfResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7478 int radio_1_6::stopDtmfResponse(int slotId,
7479                            int responseType, int serial, RIL_Errno e,
7480                            void *response, size_t responseLen) {
7481 #if VDBG
7482     RLOGD("stopDtmfResponse: serial %d", serial);
7483 #endif
7484 
7485     if (radioService[slotId]->mRadioResponse != NULL) {
7486         RadioResponseInfo responseInfo = {};
7487         populateResponseInfo(responseInfo, serial, responseType, e);
7488         Return<void> retStatus
7489                 = radioService[slotId]->mRadioResponse->stopDtmfResponse(responseInfo);
7490         radioService[slotId]->checkReturnStatus(retStatus);
7491     } else {
7492         RLOGE("stopDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7493     }
7494 
7495     return 0;
7496 }
7497 
getBasebandVersionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7498 int radio_1_6::getBasebandVersionResponse(int slotId,
7499                                      int responseType, int serial, RIL_Errno e,
7500                                      void *response, size_t responseLen) {
7501 #if VDBG
7502     RLOGD("getBasebandVersionResponse: 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->getBasebandVersionResponse(responseInfo,
7510                 convertCharPtrToHidlString((char *) response));
7511         radioService[slotId]->checkReturnStatus(retStatus);
7512     } else {
7513         RLOGE("getBasebandVersionResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7514     }
7515 
7516     return 0;
7517 }
7518 
separateConnectionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7519 int radio_1_6::separateConnectionResponse(int slotId,
7520                                      int responseType, int serial, RIL_Errno e,
7521                                      void *response, size_t responseLen) {
7522 #if VDBG
7523     RLOGD("separateConnectionResponse: serial %d", serial);
7524 #endif
7525 
7526     if (radioService[slotId]->mRadioResponse != NULL) {
7527         RadioResponseInfo responseInfo = {};
7528         populateResponseInfo(responseInfo, serial, responseType, e);
7529         Return<void> retStatus
7530                 = radioService[slotId]->mRadioResponse->separateConnectionResponse(responseInfo);
7531         radioService[slotId]->checkReturnStatus(retStatus);
7532     } else {
7533         RLOGE("separateConnectionResponse: radioService[%d]->mRadioResponse == NULL",
7534                 slotId);
7535     }
7536 
7537     return 0;
7538 }
7539 
setMuteResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7540 int radio_1_6::setMuteResponse(int slotId,
7541                           int responseType, int serial, RIL_Errno e,
7542                           void *response, size_t responseLen) {
7543 #if VDBG
7544     RLOGD("setMuteResponse: serial %d", serial);
7545 #endif
7546 
7547     if (radioService[slotId]->mRadioResponse != NULL) {
7548         RadioResponseInfo responseInfo = {};
7549         populateResponseInfo(responseInfo, serial, responseType, e);
7550         Return<void> retStatus
7551                 = radioService[slotId]->mRadioResponse->setMuteResponse(responseInfo);
7552         radioService[slotId]->checkReturnStatus(retStatus);
7553     } else {
7554         RLOGE("setMuteResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7555     }
7556 
7557     return 0;
7558 }
7559 
getMuteResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7560 int radio_1_6::getMuteResponse(int slotId,
7561                           int responseType, int serial, RIL_Errno e, void *response,
7562                           size_t responseLen) {
7563 #if VDBG
7564     RLOGD("getMuteResponse: serial %d", serial);
7565 #endif
7566 
7567     if (radioService[slotId]->mRadioResponse != NULL) {
7568         RadioResponseInfo responseInfo = {};
7569         populateResponseInfo(responseInfo, serial, responseType, e);
7570         bool enable = false;
7571         if (response == NULL || responseLen != sizeof(int)) {
7572             RLOGE("getMuteResponse Invalid response: NULL");
7573             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7574         } else {
7575             int *pInt = (int *) response;
7576             enable = pInt[0] == 1 ? true : false;
7577         }
7578         Return<void> retStatus = radioService[slotId]->mRadioResponse->getMuteResponse(responseInfo,
7579                 enable);
7580         radioService[slotId]->checkReturnStatus(retStatus);
7581     } else {
7582         RLOGE("getMuteResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7583     }
7584 
7585     return 0;
7586 }
7587 
getClipResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7588 int radio_1_6::getClipResponse(int slotId,
7589                           int responseType, int serial, RIL_Errno e,
7590                           void *response, size_t responseLen) {
7591 #if VDBG
7592     RLOGD("getClipResponse: serial %d", serial);
7593 #endif
7594 
7595     if (radioService[slotId]->mRadioResponse != NULL) {
7596         RadioResponseInfo responseInfo = {};
7597         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
7598         Return<void> retStatus = radioService[slotId]->mRadioResponse->getClipResponse(responseInfo,
7599                 (ClipStatus) ret);
7600         radioService[slotId]->checkReturnStatus(retStatus);
7601     } else {
7602         RLOGE("getClipResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7603     }
7604 
7605     return 0;
7606 }
7607 
getDataCallListResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7608 int radio_1_6::getDataCallListResponse(int slotId,
7609                                    int responseType, int serial, RIL_Errno e,
7610                                    void *response, size_t responseLen) {
7611 #if VDBG
7612     RLOGD("getDataCallListResponse: serial %d", serial);
7613 #endif
7614 
7615     if (radioService[slotId]->mRadioResponse != NULL) {
7616         RadioResponseInfo responseInfo = {};
7617         populateResponseInfo(responseInfo, serial, responseType, e);
7618 
7619         hidl_vec<SetupDataCallResult> ret;
7620         if ((response == NULL && responseLen != 0)
7621                 || responseLen % sizeof(RIL_Data_Call_Response_v11) != 0) {
7622             RLOGE("getDataCallListResponse: invalid response");
7623             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7624         } else {
7625             convertRilDataCallListToHal(response, responseLen, ret);
7626         }
7627 
7628         Return<void> retStatus = radioService[slotId]->mRadioResponse->getDataCallListResponse(
7629                 responseInfo, ret);
7630         radioService[slotId]->checkReturnStatus(retStatus);
7631     } else {
7632         RLOGE("getDataCallListResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7633     }
7634 
7635     return 0;
7636 }
7637 
setSuppServiceNotificationsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7638 int radio_1_6::setSuppServiceNotificationsResponse(int slotId,
7639                                               int responseType, int serial, RIL_Errno e,
7640                                               void *response, size_t responseLen) {
7641 #if VDBG
7642     RLOGD("setSuppServiceNotificationsResponse: serial %d", serial);
7643 #endif
7644 
7645     if (radioService[slotId]->mRadioResponse != NULL) {
7646         RadioResponseInfo responseInfo = {};
7647         populateResponseInfo(responseInfo, serial, responseType, e);
7648         Return<void> retStatus
7649                 = radioService[slotId]->mRadioResponse->setSuppServiceNotificationsResponse(
7650                 responseInfo);
7651         radioService[slotId]->checkReturnStatus(retStatus);
7652     } else {
7653         RLOGE("setSuppServiceNotificationsResponse: radioService[%d]->mRadioResponse "
7654                 "== NULL", slotId);
7655     }
7656 
7657     return 0;
7658 }
7659 
deleteSmsOnSimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7660 int radio_1_6::deleteSmsOnSimResponse(int slotId,
7661                                  int responseType, int serial, RIL_Errno e,
7662                                  void *response, size_t responseLen) {
7663 #if VDBG
7664     RLOGD("deleteSmsOnSimResponse: serial %d", serial);
7665 #endif
7666 
7667     if (radioService[slotId]->mRadioResponse != NULL) {
7668         RadioResponseInfo responseInfo = {};
7669         populateResponseInfo(responseInfo, serial, responseType, e);
7670         Return<void> retStatus
7671                 = radioService[slotId]->mRadioResponse->deleteSmsOnSimResponse(responseInfo);
7672         radioService[slotId]->checkReturnStatus(retStatus);
7673     } else {
7674         RLOGE("deleteSmsOnSimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7675     }
7676 
7677     return 0;
7678 }
7679 
setBandModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7680 int radio_1_6::setBandModeResponse(int slotId,
7681                               int responseType, int serial, RIL_Errno e,
7682                               void *response, size_t responseLen) {
7683 #if VDBG
7684     RLOGD("setBandModeResponse: serial %d", serial);
7685 #endif
7686 
7687     if (radioService[slotId]->mRadioResponse != NULL) {
7688         RadioResponseInfo responseInfo = {};
7689         populateResponseInfo(responseInfo, serial, responseType, e);
7690         Return<void> retStatus
7691                 = radioService[slotId]->mRadioResponse->setBandModeResponse(responseInfo);
7692         radioService[slotId]->checkReturnStatus(retStatus);
7693     } else {
7694         RLOGE("setBandModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7695     }
7696 
7697     return 0;
7698 }
7699 
writeSmsToSimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7700 int radio_1_6::writeSmsToSimResponse(int slotId,
7701                                 int responseType, int serial, RIL_Errno e,
7702                                 void *response, size_t responseLen) {
7703 #if VDBG
7704     RLOGD("writeSmsToSimResponse: serial %d", serial);
7705 #endif
7706 
7707     if (radioService[slotId]->mRadioResponse != NULL) {
7708         RadioResponseInfo responseInfo = {};
7709         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
7710         Return<void> retStatus
7711                 = radioService[slotId]->mRadioResponse->writeSmsToSimResponse(responseInfo, ret);
7712         radioService[slotId]->checkReturnStatus(retStatus);
7713     } else {
7714         RLOGE("writeSmsToSimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7715     }
7716 
7717     return 0;
7718 }
7719 
getAvailableBandModesResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7720 int radio_1_6::getAvailableBandModesResponse(int slotId,
7721                                         int responseType, int serial, RIL_Errno e, void *response,
7722                                         size_t responseLen) {
7723 #if VDBG
7724     RLOGD("getAvailableBandModesResponse: serial %d", serial);
7725 #endif
7726 
7727     if (radioService[slotId]->mRadioResponse != NULL) {
7728         RadioResponseInfo responseInfo = {};
7729         populateResponseInfo(responseInfo, serial, responseType, e);
7730         hidl_vec<RadioBandMode> modes;
7731         if ((response == NULL && responseLen != 0)|| responseLen % sizeof(int) != 0) {
7732             RLOGE("getAvailableBandModesResponse Invalid response: NULL");
7733             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7734         } else {
7735             int *pInt = (int *) response;
7736             int numInts = responseLen / sizeof(int);
7737             modes.resize(numInts);
7738             for (int i = 0; i < numInts; i++) {
7739                 modes[i] = (RadioBandMode) pInt[i];
7740             }
7741         }
7742         Return<void> retStatus
7743                 = radioService[slotId]->mRadioResponse->getAvailableBandModesResponse(responseInfo,
7744                 modes);
7745         radioService[slotId]->checkReturnStatus(retStatus);
7746     } else {
7747         RLOGE("getAvailableBandModesResponse: radioService[%d]->mRadioResponse == NULL",
7748                 slotId);
7749     }
7750 
7751     return 0;
7752 }
7753 
sendEnvelopeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7754 int radio_1_6::sendEnvelopeResponse(int slotId,
7755                                int responseType, int serial, RIL_Errno e,
7756                                void *response, size_t responseLen) {
7757 #if VDBG
7758     RLOGD("sendEnvelopeResponse: serial %d", serial);
7759 #endif
7760 
7761     if (radioService[slotId]->mRadioResponse != NULL) {
7762         RadioResponseInfo responseInfo = {};
7763         populateResponseInfo(responseInfo, serial, responseType, e);
7764         Return<void> retStatus
7765                 = radioService[slotId]->mRadioResponse->sendEnvelopeResponse(responseInfo,
7766                 convertCharPtrToHidlString((char *) response));
7767         radioService[slotId]->checkReturnStatus(retStatus);
7768     } else {
7769         RLOGE("sendEnvelopeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
7770     }
7771 
7772     return 0;
7773 }
7774 
sendTerminalResponseToSimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7775 int radio_1_6::sendTerminalResponseToSimResponse(int slotId,
7776                                             int responseType, int serial, RIL_Errno e,
7777                                             void *response, size_t responseLen) {
7778 #if VDBG
7779     RLOGD("sendTerminalResponseToSimResponse: serial %d", serial);
7780 #endif
7781 
7782     if (radioService[slotId]->mRadioResponse != NULL) {
7783         RadioResponseInfo responseInfo = {};
7784         populateResponseInfo(responseInfo, serial, responseType, e);
7785         Return<void> retStatus
7786                 = radioService[slotId]->mRadioResponse->sendTerminalResponseToSimResponse(
7787                 responseInfo);
7788         radioService[slotId]->checkReturnStatus(retStatus);
7789     } else {
7790         RLOGE("sendTerminalResponseToSimResponse: radioService[%d]->mRadioResponse == NULL",
7791                 slotId);
7792     }
7793 
7794     return 0;
7795 }
7796 
handleStkCallSetupRequestFromSimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7797 int radio_1_6::handleStkCallSetupRequestFromSimResponse(int slotId,
7798                                                    int responseType, int serial,
7799                                                    RIL_Errno e, void *response,
7800                                                    size_t responseLen) {
7801 #if VDBG
7802     RLOGD("handleStkCallSetupRequestFromSimResponse: serial %d", serial);
7803 #endif
7804 
7805     if (radioService[slotId]->mRadioResponse != NULL) {
7806         RadioResponseInfo responseInfo = {};
7807         populateResponseInfo(responseInfo, serial, responseType, e);
7808         Return<void> retStatus
7809                 = radioService[slotId]->mRadioResponse->handleStkCallSetupRequestFromSimResponse(
7810                 responseInfo);
7811         radioService[slotId]->checkReturnStatus(retStatus);
7812     } else {
7813         RLOGE("handleStkCallSetupRequestFromSimResponse: radioService[%d]->mRadioResponse "
7814                 "== NULL", slotId);
7815     }
7816 
7817     return 0;
7818 }
7819 
explicitCallTransferResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7820 int radio_1_6::explicitCallTransferResponse(int slotId,
7821                                        int responseType, int serial, RIL_Errno e,
7822                                        void *response, size_t responseLen) {
7823 #if VDBG
7824     RLOGD("explicitCallTransferResponse: serial %d", serial);
7825 #endif
7826 
7827     if (radioService[slotId]->mRadioResponse != NULL) {
7828         RadioResponseInfo responseInfo = {};
7829         populateResponseInfo(responseInfo, serial, responseType, e);
7830         Return<void> retStatus
7831                 = radioService[slotId]->mRadioResponse->explicitCallTransferResponse(responseInfo);
7832         radioService[slotId]->checkReturnStatus(retStatus);
7833     } else {
7834         RLOGE("explicitCallTransferResponse: radioService[%d]->mRadioResponse == NULL",
7835                 slotId);
7836     }
7837 
7838     return 0;
7839 }
7840 
setPreferredNetworkTypeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7841 int radio_1_6::setPreferredNetworkTypeResponse(int slotId,
7842                                  int responseType, int serial, RIL_Errno e,
7843                                  void *response, size_t responseLen) {
7844 #if VDBG
7845     RLOGD("setPreferredNetworkTypeResponse: serial %d", serial);
7846 #endif
7847 
7848     if (radioService[slotId]->mRadioResponse != NULL) {
7849         RadioResponseInfo responseInfo = {};
7850         populateResponseInfo(responseInfo, serial, responseType, e);
7851         Return<void> retStatus
7852                 = radioService[slotId]->mRadioResponse->setPreferredNetworkTypeResponse(
7853                 responseInfo);
7854         radioService[slotId]->checkReturnStatus(retStatus);
7855     } else {
7856         RLOGE("setPreferredNetworkTypeResponse: radioService[%d]->mRadioResponse == NULL",
7857                 slotId);
7858     }
7859 
7860     return 0;
7861 }
7862 
setAllowedNetworkTypesBitmapResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7863 int radio_1_6::setAllowedNetworkTypesBitmapResponse(int slotId,
7864                                  int responseType, int serial, RIL_Errno e,
7865                                  void *response, size_t responseLen) {
7866 #if VDBG
7867     RLOGD("setAllowedNetworkTypesBitmapResponse: serial %d", serial);
7868 #endif
7869 
7870     V1_6::RadioResponseInfo responseInfo = {};
7871     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
7872 
7873     // If we don't have a radio service, there's nothing we can do
7874     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
7875         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
7876         return 0;
7877     }
7878 
7879     Return<void> retStatus =
7880             radioService[slotId]->mRadioResponseV1_6->setAllowedNetworkTypesBitmapResponse(
7881             responseInfo);
7882     radioService[slotId]->checkReturnStatus(retStatus);
7883     return 0;
7884 }
7885 
getAllowedNetworkTypesBitmapResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7886 int radio_1_6::getAllowedNetworkTypesBitmapResponse(int slotId,
7887                                           int responseType, int serial, RIL_Errno e,
7888                                           void *response, size_t responseLen) {
7889 #if VDBG
7890     RLOGD("getAllowedNetworkTypesBitmapResponse: serial %d", serial);
7891 #endif
7892 
7893     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
7894       V1_6::RadioResponseInfo responseInfo = {};
7895         int ret = responseInt_1_6(responseInfo, serial, responseType, e, response, responseLen);
7896         Return<void> retStatus
7897                 = radioService[slotId]->mRadioResponseV1_6->getAllowedNetworkTypesBitmapResponse(
7898                 responseInfo,
7899                 (const ::android::hardware::hidl_bitfield<
7900                 ::android::hardware::radio::V1_4::RadioAccessFamily>) ret);
7901         radioService[slotId]->checkReturnStatus(retStatus);
7902     } else {
7903         RLOGE("getAllowedNetworkTypesBitmapResponse: radioService[%d]->mRadioResponseV1_6 == NULL",
7904                 slotId);
7905     }
7906 
7907     return 0;
7908 }
7909 
getPreferredNetworkTypeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7910 int radio_1_6::getPreferredNetworkTypeResponse(int slotId,
7911                                           int responseType, int serial, RIL_Errno e,
7912                                           void *response, size_t responseLen) {
7913 #if VDBG
7914     RLOGD("getPreferredNetworkTypeResponse: serial %d", serial);
7915 #endif
7916 
7917     if (radioService[slotId]->mRadioResponse != NULL) {
7918         RadioResponseInfo responseInfo = {};
7919         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
7920         Return<void> retStatus
7921                 = radioService[slotId]->mRadioResponse->getPreferredNetworkTypeResponse(
7922                 responseInfo, (PreferredNetworkType) ret);
7923         radioService[slotId]->checkReturnStatus(retStatus);
7924     } else {
7925         RLOGE("getPreferredNetworkTypeResponse: radioService[%d]->mRadioResponse == NULL",
7926                 slotId);
7927     }
7928 
7929     return 0;
7930 }
7931 
setPreferredNetworkTypeBitmapResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7932 int radio_1_6::setPreferredNetworkTypeBitmapResponse(int slotId,
7933                                  int responseType, int serial, RIL_Errno e,
7934                                  void *response, size_t responseLen) {
7935 #if VDBG
7936     RLOGD("setPreferredNetworkTypeBitmapResponse: serial %d", serial);
7937 #endif
7938 
7939     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
7940         RadioResponseInfo responseInfo = {};
7941         populateResponseInfo(responseInfo, serial, responseType, e);
7942         Return<void> retStatus
7943                 = radioService[slotId]->mRadioResponseV1_4->setPreferredNetworkTypeBitmapResponse(
7944                 responseInfo);
7945         radioService[slotId]->checkReturnStatus(retStatus);
7946     } else {
7947         RLOGE("setPreferredNetworkTypeBitmapResponse: radioService[%d]->mRadioResponseV1_4 == NULL",
7948                 slotId);
7949     }
7950 
7951     return 0;
7952 }
7953 
7954 
getPreferredNetworkTypeBitmapResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7955 int radio_1_6::getPreferredNetworkTypeBitmapResponse(int slotId,
7956                                           int responseType, int serial, RIL_Errno e,
7957                                           void *response, size_t responseLen) {
7958 #if VDBG
7959     RLOGD("getPreferredNetworkTypeBitmapResponse: serial %d", serial);
7960 #endif
7961 
7962     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
7963         RadioResponseInfo responseInfo = {};
7964         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
7965         Return<void> retStatus
7966                 = radioService[slotId]->mRadioResponseV1_4->getPreferredNetworkTypeBitmapResponse(
7967                 responseInfo,
7968                 (const ::android::hardware::hidl_bitfield<
7969                 ::android::hardware::radio::V1_4::RadioAccessFamily>) ret);
7970         radioService[slotId]->checkReturnStatus(retStatus);
7971     } else {
7972         RLOGE("getPreferredNetworkTypeBitmapResponse: radioService[%d]->mRadioResponseV1_4 == NULL",
7973                 slotId);
7974     }
7975 
7976     return 0;
7977 }
7978 
getNeighboringCidsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)7979 int radio_1_6::getNeighboringCidsResponse(int slotId,
7980                                      int responseType, int serial, RIL_Errno e,
7981                                      void *response, size_t responseLen) {
7982 #if VDBG
7983     RLOGD("getNeighboringCidsResponse: serial %d", serial);
7984 #endif
7985 
7986     if (radioService[slotId]->mRadioResponse != NULL) {
7987         RadioResponseInfo responseInfo = {};
7988         populateResponseInfo(responseInfo, serial, responseType, e);
7989         hidl_vec<NeighboringCell> cells;
7990 
7991         if ((response == NULL && responseLen != 0)
7992                 || responseLen % sizeof(RIL_NeighboringCell *) != 0) {
7993             RLOGE("getNeighboringCidsResponse Invalid response: NULL");
7994             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
7995         } else {
7996             int num = responseLen / sizeof(RIL_NeighboringCell *);
7997             cells.resize(num);
7998             for (int i = 0 ; i < num; i++) {
7999                 RIL_NeighboringCell *resp = ((RIL_NeighboringCell **) response)[i];
8000                 cells[i].cid = convertCharPtrToHidlString(resp->cid);
8001                 cells[i].rssi = resp->rssi;
8002             }
8003         }
8004 
8005         Return<void> retStatus
8006                 = radioService[slotId]->mRadioResponse->getNeighboringCidsResponse(responseInfo,
8007                 cells);
8008         radioService[slotId]->checkReturnStatus(retStatus);
8009     } else {
8010         RLOGE("getNeighboringCidsResponse: radioService[%d]->mRadioResponse == NULL",
8011                 slotId);
8012     }
8013 
8014     return 0;
8015 }
8016 
setLocationUpdatesResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8017 int radio_1_6::setLocationUpdatesResponse(int slotId,
8018                                      int responseType, int serial, RIL_Errno e,
8019                                      void *response, size_t responseLen) {
8020 #if VDBG
8021     RLOGD("setLocationUpdatesResponse: serial %d", serial);
8022 #endif
8023 
8024     if (radioService[slotId]->mRadioResponse != NULL) {
8025         RadioResponseInfo responseInfo = {};
8026         populateResponseInfo(responseInfo, serial, responseType, e);
8027         Return<void> retStatus
8028                 = radioService[slotId]->mRadioResponse->setLocationUpdatesResponse(responseInfo);
8029         radioService[slotId]->checkReturnStatus(retStatus);
8030     } else {
8031         RLOGE("setLocationUpdatesResponse: radioService[%d]->mRadioResponse == NULL",
8032                 slotId);
8033     }
8034 
8035     return 0;
8036 }
8037 
setCdmaSubscriptionSourceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8038 int radio_1_6::setCdmaSubscriptionSourceResponse(int slotId,
8039                                  int responseType, int serial, RIL_Errno e,
8040                                  void *response, size_t responseLen) {
8041 #if VDBG
8042     RLOGD("setCdmaSubscriptionSourceResponse: serial %d", serial);
8043 #endif
8044 
8045     if (radioService[slotId]->mRadioResponse != NULL) {
8046         RadioResponseInfo responseInfo = {};
8047         populateResponseInfo(responseInfo, serial, responseType, e);
8048         Return<void> retStatus
8049                 = radioService[slotId]->mRadioResponse->setCdmaSubscriptionSourceResponse(
8050                 responseInfo);
8051         radioService[slotId]->checkReturnStatus(retStatus);
8052     } else {
8053         RLOGE("setCdmaSubscriptionSourceResponse: radioService[%d]->mRadioResponse == NULL",
8054                 slotId);
8055     }
8056 
8057     return 0;
8058 }
8059 
setCdmaRoamingPreferenceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8060 int radio_1_6::setCdmaRoamingPreferenceResponse(int slotId,
8061                                  int responseType, int serial, RIL_Errno e,
8062                                  void *response, size_t responseLen) {
8063 #if VDBG
8064     RLOGD("setCdmaRoamingPreferenceResponse: serial %d", serial);
8065 #endif
8066 
8067     if (radioService[slotId]->mRadioResponse != NULL) {
8068         RadioResponseInfo responseInfo = {};
8069         populateResponseInfo(responseInfo, serial, responseType, e);
8070         Return<void> retStatus
8071                 = radioService[slotId]->mRadioResponse->setCdmaRoamingPreferenceResponse(
8072                 responseInfo);
8073         radioService[slotId]->checkReturnStatus(retStatus);
8074     } else {
8075         RLOGE("setCdmaRoamingPreferenceResponse: radioService[%d]->mRadioResponse == NULL",
8076                 slotId);
8077     }
8078 
8079     return 0;
8080 }
8081 
getCdmaRoamingPreferenceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8082 int radio_1_6::getCdmaRoamingPreferenceResponse(int slotId,
8083                                            int responseType, int serial, RIL_Errno e,
8084                                            void *response, size_t responseLen) {
8085 #if VDBG
8086     RLOGD("getCdmaRoamingPreferenceResponse: serial %d", serial);
8087 #endif
8088 
8089     if (radioService[slotId]->mRadioResponse != NULL) {
8090         RadioResponseInfo responseInfo = {};
8091         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8092         Return<void> retStatus
8093                 = radioService[slotId]->mRadioResponse->getCdmaRoamingPreferenceResponse(
8094                 responseInfo, (CdmaRoamingType) ret);
8095         radioService[slotId]->checkReturnStatus(retStatus);
8096     } else {
8097         RLOGE("getCdmaRoamingPreferenceResponse: radioService[%d]->mRadioResponse == NULL",
8098                 slotId);
8099     }
8100 
8101     return 0;
8102 }
8103 
setTTYModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8104 int radio_1_6::setTTYModeResponse(int slotId,
8105                              int responseType, int serial, RIL_Errno e,
8106                              void *response, size_t responseLen) {
8107 #if VDBG
8108     RLOGD("setTTYModeResponse: serial %d", serial);
8109 #endif
8110 
8111     if (radioService[slotId]->mRadioResponse != NULL) {
8112         RadioResponseInfo responseInfo = {};
8113         populateResponseInfo(responseInfo, serial, responseType, e);
8114         Return<void> retStatus
8115                 = radioService[slotId]->mRadioResponse->setTTYModeResponse(responseInfo);
8116         radioService[slotId]->checkReturnStatus(retStatus);
8117     } else {
8118         RLOGE("setTTYModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8119     }
8120 
8121     return 0;
8122 }
8123 
getTTYModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8124 int radio_1_6::getTTYModeResponse(int slotId,
8125                              int responseType, int serial, RIL_Errno e,
8126                              void *response, size_t responseLen) {
8127 #if VDBG
8128     RLOGD("getTTYModeResponse: serial %d", serial);
8129 #endif
8130 
8131     if (radioService[slotId]->mRadioResponse != NULL) {
8132         RadioResponseInfo responseInfo = {};
8133         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8134         Return<void> retStatus
8135                 = radioService[slotId]->mRadioResponse->getTTYModeResponse(responseInfo,
8136                 (TtyMode) ret);
8137         radioService[slotId]->checkReturnStatus(retStatus);
8138     } else {
8139         RLOGE("getTTYModeResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8140     }
8141 
8142     return 0;
8143 }
8144 
setPreferredVoicePrivacyResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8145 int radio_1_6::setPreferredVoicePrivacyResponse(int slotId,
8146                                  int responseType, int serial, RIL_Errno e,
8147                                  void *response, size_t responseLen) {
8148 #if VDBG
8149     RLOGD("setPreferredVoicePrivacyResponse: serial %d", serial);
8150 #endif
8151 
8152     if (radioService[slotId]->mRadioResponse != NULL) {
8153         RadioResponseInfo responseInfo = {};
8154         populateResponseInfo(responseInfo, serial, responseType, e);
8155         Return<void> retStatus
8156                 = radioService[slotId]->mRadioResponse->setPreferredVoicePrivacyResponse(
8157                 responseInfo);
8158         radioService[slotId]->checkReturnStatus(retStatus);
8159     } else {
8160         RLOGE("setPreferredVoicePrivacyResponse: radioService[%d]->mRadioResponse == NULL",
8161                 slotId);
8162     }
8163 
8164     return 0;
8165 }
8166 
getPreferredVoicePrivacyResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8167 int radio_1_6::getPreferredVoicePrivacyResponse(int slotId,
8168                                            int responseType, int serial, RIL_Errno e,
8169                                            void *response, size_t responseLen) {
8170 #if VDBG
8171     RLOGD("getPreferredVoicePrivacyResponse: serial %d", serial);
8172 #endif
8173 
8174     if (radioService[slotId]->mRadioResponse != NULL) {
8175         RadioResponseInfo responseInfo = {};
8176         populateResponseInfo(responseInfo, serial, responseType, e);
8177         bool enable = false;
8178         int numInts = responseLen / sizeof(int);
8179         if (response == NULL || numInts != 1) {
8180             RLOGE("getPreferredVoicePrivacyResponse Invalid response: NULL");
8181             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8182         } else {
8183             int *pInt = (int *) response;
8184             enable = pInt[0] == 1 ? true : false;
8185         }
8186         Return<void> retStatus
8187                 = radioService[slotId]->mRadioResponse->getPreferredVoicePrivacyResponse(
8188                 responseInfo, enable);
8189         radioService[slotId]->checkReturnStatus(retStatus);
8190     } else {
8191         RLOGE("getPreferredVoicePrivacyResponse: radioService[%d]->mRadioResponse == NULL",
8192                 slotId);
8193     }
8194 
8195     return 0;
8196 }
8197 
sendCDMAFeatureCodeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8198 int radio_1_6::sendCDMAFeatureCodeResponse(int slotId,
8199                                  int responseType, int serial, RIL_Errno e,
8200                                  void *response, size_t responseLen) {
8201 #if VDBG
8202     RLOGD("sendCDMAFeatureCodeResponse: serial %d", serial);
8203 #endif
8204 
8205     if (radioService[slotId]->mRadioResponse != NULL) {
8206         RadioResponseInfo responseInfo = {};
8207         populateResponseInfo(responseInfo, serial, responseType, e);
8208         Return<void> retStatus
8209                 = radioService[slotId]->mRadioResponse->sendCDMAFeatureCodeResponse(responseInfo);
8210         radioService[slotId]->checkReturnStatus(retStatus);
8211     } else {
8212         RLOGE("sendCDMAFeatureCodeResponse: radioService[%d]->mRadioResponse == NULL",
8213                 slotId);
8214     }
8215 
8216     return 0;
8217 }
8218 
sendBurstDtmfResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8219 int radio_1_6::sendBurstDtmfResponse(int slotId,
8220                                  int responseType, int serial, RIL_Errno e,
8221                                  void *response, size_t responseLen) {
8222 #if VDBG
8223     RLOGD("sendBurstDtmfResponse: serial %d", serial);
8224 #endif
8225 
8226     if (radioService[slotId]->mRadioResponse != NULL) {
8227         RadioResponseInfo responseInfo = {};
8228         populateResponseInfo(responseInfo, serial, responseType, e);
8229         Return<void> retStatus
8230                 = radioService[slotId]->mRadioResponse->sendBurstDtmfResponse(responseInfo);
8231         radioService[slotId]->checkReturnStatus(retStatus);
8232     } else {
8233         RLOGE("sendBurstDtmfResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8234     }
8235 
8236     return 0;
8237 }
8238 
sendCdmaSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8239 int radio_1_6::sendCdmaSmsResponse(int slotId,
8240                               int responseType, int serial, RIL_Errno e, void *response,
8241                               size_t responseLen) {
8242 #if VDBG
8243     RLOGD("sendCdmaSmsResponse: serial %d", serial);
8244 #endif
8245 
8246     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
8247         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
8248         SendSmsResult result = makeSendSmsResult_1_6(responseInfo_1_6, serial, responseType, e,
8249                 response, responseLen);
8250 
8251         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
8252                 ->sendCdmaSmsResponse_1_6(responseInfo_1_6, result);
8253         radioService[slotId]->checkReturnStatus(retStatus);
8254     } else if (radioService[slotId]->mRadioResponse != NULL) {
8255         RadioResponseInfo responseInfo = {};
8256         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
8257                 responseLen);
8258 
8259         Return<void> retStatus
8260                 = radioService[slotId]->mRadioResponse->sendCdmaSmsResponse(responseInfo, result);
8261         radioService[slotId]->checkReturnStatus(retStatus);
8262     } else {
8263         RLOGE("sendCdmaSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8264     }
8265 
8266     return 0;
8267 }
8268 
acknowledgeLastIncomingCdmaSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8269 int radio_1_6::acknowledgeLastIncomingCdmaSmsResponse(int slotId,
8270                                                  int responseType, int serial, RIL_Errno e,
8271                                                  void *response, size_t responseLen) {
8272 #if VDBG
8273     RLOGD("acknowledgeLastIncomingCdmaSmsResponse: serial %d", serial);
8274 #endif
8275 
8276     if (radioService[slotId]->mRadioResponse != NULL) {
8277         RadioResponseInfo responseInfo = {};
8278         populateResponseInfo(responseInfo, serial, responseType, e);
8279         Return<void> retStatus
8280                 = radioService[slotId]->mRadioResponse->acknowledgeLastIncomingCdmaSmsResponse(
8281                 responseInfo);
8282         radioService[slotId]->checkReturnStatus(retStatus);
8283     } else {
8284         RLOGE("acknowledgeLastIncomingCdmaSmsResponse: radioService[%d]->mRadioResponse "
8285                 "== NULL", slotId);
8286     }
8287 
8288     return 0;
8289 }
8290 
getGsmBroadcastConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8291 int radio_1_6::getGsmBroadcastConfigResponse(int slotId,
8292                                         int responseType, int serial, RIL_Errno e,
8293                                         void *response, size_t responseLen) {
8294 #if VDBG
8295     RLOGD("getGsmBroadcastConfigResponse: serial %d", serial);
8296 #endif
8297 
8298     if (radioService[slotId]->mRadioResponse != NULL) {
8299         RadioResponseInfo responseInfo = {};
8300         populateResponseInfo(responseInfo, serial, responseType, e);
8301         hidl_vec<GsmBroadcastSmsConfigInfo> configs;
8302 
8303         if ((response == NULL && responseLen != 0)
8304                 || responseLen % sizeof(RIL_GSM_BroadcastSmsConfigInfo *) != 0) {
8305             RLOGE("getGsmBroadcastConfigResponse Invalid response: NULL");
8306             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8307         } else {
8308             int num = responseLen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
8309             configs.resize(num);
8310             for (int i = 0 ; i < num; i++) {
8311                 RIL_GSM_BroadcastSmsConfigInfo *resp =
8312                         ((RIL_GSM_BroadcastSmsConfigInfo **) response)[i];
8313                 configs[i].fromServiceId = resp->fromServiceId;
8314                 configs[i].toServiceId = resp->toServiceId;
8315                 configs[i].fromCodeScheme = resp->fromCodeScheme;
8316                 configs[i].toCodeScheme = resp->toCodeScheme;
8317                 configs[i].selected = resp->selected == 1 ? true : false;
8318             }
8319         }
8320 
8321         Return<void> retStatus
8322                 = radioService[slotId]->mRadioResponse->getGsmBroadcastConfigResponse(responseInfo,
8323                 configs);
8324         radioService[slotId]->checkReturnStatus(retStatus);
8325     } else {
8326         RLOGE("getGsmBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
8327                 slotId);
8328     }
8329 
8330     return 0;
8331 }
8332 
setGsmBroadcastConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8333 int radio_1_6::setGsmBroadcastConfigResponse(int slotId,
8334                                         int responseType, int serial, RIL_Errno e,
8335                                         void *response, size_t responseLen) {
8336 #if VDBG
8337     RLOGD("setGsmBroadcastConfigResponse: serial %d", serial);
8338 #endif
8339 
8340     if (radioService[slotId]->mRadioResponse != NULL) {
8341         RadioResponseInfo responseInfo = {};
8342         populateResponseInfo(responseInfo, serial, responseType, e);
8343         Return<void> retStatus
8344                 = radioService[slotId]->mRadioResponse->setGsmBroadcastConfigResponse(responseInfo);
8345         radioService[slotId]->checkReturnStatus(retStatus);
8346     } else {
8347         RLOGE("setGsmBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
8348                 slotId);
8349     }
8350 
8351     return 0;
8352 }
8353 
setGsmBroadcastActivationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8354 int radio_1_6::setGsmBroadcastActivationResponse(int slotId,
8355                                             int responseType, int serial, RIL_Errno e,
8356                                             void *response, size_t responseLen) {
8357 #if VDBG
8358     RLOGD("setGsmBroadcastActivationResponse: serial %d", serial);
8359 #endif
8360 
8361     if (radioService[slotId]->mRadioResponse != NULL) {
8362         RadioResponseInfo responseInfo = {};
8363         populateResponseInfo(responseInfo, serial, responseType, e);
8364         Return<void> retStatus
8365                 = radioService[slotId]->mRadioResponse->setGsmBroadcastActivationResponse(
8366                 responseInfo);
8367         radioService[slotId]->checkReturnStatus(retStatus);
8368     } else {
8369         RLOGE("setGsmBroadcastActivationResponse: radioService[%d]->mRadioResponse == NULL",
8370                 slotId);
8371     }
8372 
8373     return 0;
8374 }
8375 
getCdmaBroadcastConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8376 int radio_1_6::getCdmaBroadcastConfigResponse(int slotId,
8377                                          int responseType, int serial, RIL_Errno e,
8378                                          void *response, size_t responseLen) {
8379 #if VDBG
8380     RLOGD("getCdmaBroadcastConfigResponse: serial %d", serial);
8381 #endif
8382 
8383     if (radioService[slotId]->mRadioResponse != NULL) {
8384         RadioResponseInfo responseInfo = {};
8385         populateResponseInfo(responseInfo, serial, responseType, e);
8386         hidl_vec<CdmaBroadcastSmsConfigInfo> configs;
8387 
8388         if ((response == NULL && responseLen != 0)
8389                 || responseLen % sizeof(RIL_CDMA_BroadcastSmsConfigInfo *) != 0) {
8390             RLOGE("getCdmaBroadcastConfigResponse Invalid response: NULL");
8391             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8392         } else {
8393             int num = responseLen / sizeof(RIL_CDMA_BroadcastSmsConfigInfo *);
8394             configs.resize(num);
8395             for (int i = 0 ; i < num; i++) {
8396                 RIL_CDMA_BroadcastSmsConfigInfo *resp =
8397                         ((RIL_CDMA_BroadcastSmsConfigInfo **) response)[i];
8398                 configs[i].serviceCategory = resp->service_category;
8399                 configs[i].language = resp->language;
8400                 configs[i].selected = resp->selected == 1 ? true : false;
8401             }
8402         }
8403 
8404         Return<void> retStatus
8405                 = radioService[slotId]->mRadioResponse->getCdmaBroadcastConfigResponse(responseInfo,
8406                 configs);
8407         radioService[slotId]->checkReturnStatus(retStatus);
8408     } else {
8409         RLOGE("getCdmaBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
8410                 slotId);
8411     }
8412 
8413     return 0;
8414 }
8415 
setCdmaBroadcastConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8416 int radio_1_6::setCdmaBroadcastConfigResponse(int slotId,
8417                                          int responseType, int serial, RIL_Errno e,
8418                                          void *response, size_t responseLen) {
8419 #if VDBG
8420     RLOGD("setCdmaBroadcastConfigResponse: serial %d", serial);
8421 #endif
8422 
8423     if (radioService[slotId]->mRadioResponse != NULL) {
8424         RadioResponseInfo responseInfo = {};
8425         populateResponseInfo(responseInfo, serial, responseType, e);
8426         Return<void> retStatus
8427                 = radioService[slotId]->mRadioResponse->setCdmaBroadcastConfigResponse(
8428                 responseInfo);
8429         radioService[slotId]->checkReturnStatus(retStatus);
8430     } else {
8431         RLOGE("setCdmaBroadcastConfigResponse: radioService[%d]->mRadioResponse == NULL",
8432                 slotId);
8433     }
8434 
8435     return 0;
8436 }
8437 
setCdmaBroadcastActivationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8438 int radio_1_6::setCdmaBroadcastActivationResponse(int slotId,
8439                                              int responseType, int serial, RIL_Errno e,
8440                                              void *response, size_t responseLen) {
8441 #if VDBG
8442     RLOGD("setCdmaBroadcastActivationResponse: serial %d", serial);
8443 #endif
8444 
8445     if (radioService[slotId]->mRadioResponse != NULL) {
8446         RadioResponseInfo responseInfo = {};
8447         populateResponseInfo(responseInfo, serial, responseType, e);
8448         Return<void> retStatus
8449                 = radioService[slotId]->mRadioResponse->setCdmaBroadcastActivationResponse(
8450                 responseInfo);
8451         radioService[slotId]->checkReturnStatus(retStatus);
8452     } else {
8453         RLOGE("setCdmaBroadcastActivationResponse: radioService[%d]->mRadioResponse == NULL",
8454                 slotId);
8455     }
8456 
8457     return 0;
8458 }
8459 
getCDMASubscriptionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8460 int radio_1_6::getCDMASubscriptionResponse(int slotId,
8461                                       int responseType, int serial, RIL_Errno e, void *response,
8462                                       size_t responseLen) {
8463 #if VDBG
8464     RLOGD("getCDMASubscriptionResponse: serial %d", serial);
8465 #endif
8466 
8467     if (radioService[slotId]->mRadioResponse != NULL) {
8468         RadioResponseInfo responseInfo = {};
8469         populateResponseInfo(responseInfo, serial, responseType, e);
8470 
8471         int numStrings = responseLen / sizeof(char *);
8472         hidl_string emptyString;
8473         if (response == NULL || numStrings != 5) {
8474             RLOGE("getOperatorResponse Invalid response: NULL");
8475             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8476             Return<void> retStatus
8477                     = radioService[slotId]->mRadioResponse->getCDMASubscriptionResponse(
8478                     responseInfo, emptyString, emptyString, emptyString, emptyString, emptyString);
8479             radioService[slotId]->checkReturnStatus(retStatus);
8480         } else {
8481             char **resp = (char **) response;
8482             Return<void> retStatus
8483                     = radioService[slotId]->mRadioResponse->getCDMASubscriptionResponse(
8484                     responseInfo,
8485                     convertCharPtrToHidlString(resp[0]),
8486                     convertCharPtrToHidlString(resp[1]),
8487                     convertCharPtrToHidlString(resp[2]),
8488                     convertCharPtrToHidlString(resp[3]),
8489                     convertCharPtrToHidlString(resp[4]));
8490             radioService[slotId]->checkReturnStatus(retStatus);
8491         }
8492     } else {
8493         RLOGE("getCDMASubscriptionResponse: radioService[%d]->mRadioResponse == NULL",
8494                 slotId);
8495     }
8496 
8497     return 0;
8498 }
8499 
writeSmsToRuimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8500 int radio_1_6::writeSmsToRuimResponse(int slotId,
8501                                  int responseType, int serial, RIL_Errno e,
8502                                  void *response, size_t responseLen) {
8503 #if VDBG
8504     RLOGD("writeSmsToRuimResponse: serial %d", serial);
8505 #endif
8506 
8507     if (radioService[slotId]->mRadioResponse != NULL) {
8508         RadioResponseInfo responseInfo = {};
8509         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8510         Return<void> retStatus
8511                 = radioService[slotId]->mRadioResponse->writeSmsToRuimResponse(responseInfo, ret);
8512         radioService[slotId]->checkReturnStatus(retStatus);
8513     } else {
8514         RLOGE("writeSmsToRuimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8515     }
8516 
8517     return 0;
8518 }
8519 
deleteSmsOnRuimResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8520 int radio_1_6::deleteSmsOnRuimResponse(int slotId,
8521                                   int responseType, int serial, RIL_Errno e,
8522                                   void *response, size_t responseLen) {
8523 #if VDBG
8524     RLOGD("deleteSmsOnRuimResponse: serial %d", serial);
8525 #endif
8526 
8527     if (radioService[slotId]->mRadioResponse != NULL) {
8528         RadioResponseInfo responseInfo = {};
8529         populateResponseInfo(responseInfo, serial, responseType, e);
8530         Return<void> retStatus
8531                 = radioService[slotId]->mRadioResponse->deleteSmsOnRuimResponse(responseInfo);
8532         radioService[slotId]->checkReturnStatus(retStatus);
8533     } else {
8534         RLOGE("deleteSmsOnRuimResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8535     }
8536 
8537     return 0;
8538 }
8539 
getDeviceIdentityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8540 int radio_1_6::getDeviceIdentityResponse(int slotId,
8541                                     int responseType, int serial, RIL_Errno e, void *response,
8542                                     size_t responseLen) {
8543 #if VDBG
8544     RLOGD("getDeviceIdentityResponse: serial %d", serial);
8545 #endif
8546 
8547     if (radioService[slotId]->mRadioResponse != NULL) {
8548         RadioResponseInfo responseInfo = {};
8549         populateResponseInfo(responseInfo, serial, responseType, e);
8550 
8551         int numStrings = responseLen / sizeof(char *);
8552         hidl_string emptyString;
8553         if (response == NULL || numStrings != 4) {
8554             RLOGE("getDeviceIdentityResponse Invalid response: NULL");
8555             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8556             Return<void> retStatus
8557                     = radioService[slotId]->mRadioResponse->getDeviceIdentityResponse(responseInfo,
8558                     emptyString, emptyString, emptyString, emptyString);
8559             radioService[slotId]->checkReturnStatus(retStatus);
8560         } else {
8561             char **resp = (char **) response;
8562             Return<void> retStatus
8563                     = radioService[slotId]->mRadioResponse->getDeviceIdentityResponse(responseInfo,
8564                     convertCharPtrToHidlString(resp[0]),
8565                     convertCharPtrToHidlString(resp[1]),
8566                     convertCharPtrToHidlString(resp[2]),
8567                     convertCharPtrToHidlString(resp[3]));
8568             radioService[slotId]->checkReturnStatus(retStatus);
8569         }
8570     } else {
8571         RLOGE("getDeviceIdentityResponse: radioService[%d]->mRadioResponse == NULL",
8572                 slotId);
8573     }
8574 
8575     return 0;
8576 }
8577 
exitEmergencyCallbackModeResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8578 int radio_1_6::exitEmergencyCallbackModeResponse(int slotId,
8579                                             int responseType, int serial, RIL_Errno e,
8580                                             void *response, size_t responseLen) {
8581 #if VDBG
8582     RLOGD("exitEmergencyCallbackModeResponse: serial %d", serial);
8583 #endif
8584 
8585     if (radioService[slotId]->mRadioResponse != NULL) {
8586         RadioResponseInfo responseInfo = {};
8587         populateResponseInfo(responseInfo, serial, responseType, e);
8588         Return<void> retStatus
8589                 = radioService[slotId]->mRadioResponse->exitEmergencyCallbackModeResponse(
8590                 responseInfo);
8591         radioService[slotId]->checkReturnStatus(retStatus);
8592     } else {
8593         RLOGE("exitEmergencyCallbackModeResponse: radioService[%d]->mRadioResponse == NULL",
8594                 slotId);
8595     }
8596 
8597     return 0;
8598 }
8599 
getSmscAddressResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8600 int radio_1_6::getSmscAddressResponse(int slotId,
8601                                   int responseType, int serial, RIL_Errno e,
8602                                   void *response, size_t responseLen) {
8603 #if VDBG
8604     RLOGD("getSmscAddressResponse: serial %d", serial);
8605 #endif
8606 
8607     if (radioService[slotId]->mRadioResponse != NULL) {
8608         RadioResponseInfo responseInfo = {};
8609         populateResponseInfo(responseInfo, serial, responseType, e);
8610         Return<void> retStatus
8611                 = radioService[slotId]->mRadioResponse->getSmscAddressResponse(responseInfo,
8612                 convertCharPtrToHidlString((char *) response));
8613         radioService[slotId]->checkReturnStatus(retStatus);
8614     } else {
8615         RLOGE("getSmscAddressResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8616     }
8617 
8618     return 0;
8619 }
8620 
setSmscAddressResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8621 int radio_1_6::setSmscAddressResponse(int slotId,
8622                                              int responseType, int serial, RIL_Errno e,
8623                                              void *response, size_t responseLen) {
8624 #if VDBG
8625     RLOGD("setSmscAddressResponse: serial %d", serial);
8626 #endif
8627 
8628     if (radioService[slotId]->mRadioResponse != NULL) {
8629         RadioResponseInfo responseInfo = {};
8630         populateResponseInfo(responseInfo, serial, responseType, e);
8631         Return<void> retStatus
8632                 = radioService[slotId]->mRadioResponse->setSmscAddressResponse(responseInfo);
8633         radioService[slotId]->checkReturnStatus(retStatus);
8634     } else {
8635         RLOGE("setSmscAddressResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8636     }
8637 
8638     return 0;
8639 }
8640 
reportSmsMemoryStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8641 int radio_1_6::reportSmsMemoryStatusResponse(int slotId,
8642                                         int responseType, int serial, RIL_Errno e,
8643                                         void *response, size_t responseLen) {
8644 #if VDBG
8645     RLOGD("reportSmsMemoryStatusResponse: serial %d", serial);
8646 #endif
8647 
8648     if (radioService[slotId]->mRadioResponse != NULL) {
8649         RadioResponseInfo responseInfo = {};
8650         populateResponseInfo(responseInfo, serial, responseType, e);
8651         Return<void> retStatus
8652                 = radioService[slotId]->mRadioResponse->reportSmsMemoryStatusResponse(responseInfo);
8653         radioService[slotId]->checkReturnStatus(retStatus);
8654     } else {
8655         RLOGE("reportSmsMemoryStatusResponse: radioService[%d]->mRadioResponse == NULL",
8656                 slotId);
8657     }
8658 
8659     return 0;
8660 }
8661 
reportStkServiceIsRunningResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8662 int radio_1_6::reportStkServiceIsRunningResponse(int slotId,
8663                                              int responseType, int serial, RIL_Errno e,
8664                                              void *response, size_t responseLen) {
8665 #if VDBG
8666     RLOGD("reportStkServiceIsRunningResponse: serial %d", serial);
8667 #endif
8668 
8669     if (radioService[slotId]->mRadioResponse != NULL) {
8670         RadioResponseInfo responseInfo = {};
8671         populateResponseInfo(responseInfo, serial, responseType, e);
8672         Return<void> retStatus = radioService[slotId]->mRadioResponse->
8673                 reportStkServiceIsRunningResponse(responseInfo);
8674         radioService[slotId]->checkReturnStatus(retStatus);
8675     } else {
8676         RLOGE("reportStkServiceIsRunningResponse: radioService[%d]->mRadioResponse == NULL",
8677                 slotId);
8678     }
8679 
8680     return 0;
8681 }
8682 
getCdmaSubscriptionSourceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8683 int radio_1_6::getCdmaSubscriptionSourceResponse(int slotId,
8684                                             int responseType, int serial, RIL_Errno e,
8685                                             void *response, size_t responseLen) {
8686 #if VDBG
8687     RLOGD("getCdmaSubscriptionSourceResponse: serial %d", serial);
8688 #endif
8689 
8690     if (radioService[slotId]->mRadioResponse != NULL) {
8691         RadioResponseInfo responseInfo = {};
8692         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8693         Return<void> retStatus
8694                 = radioService[slotId]->mRadioResponse->getCdmaSubscriptionSourceResponse(
8695                 responseInfo, (CdmaSubscriptionSource) ret);
8696         radioService[slotId]->checkReturnStatus(retStatus);
8697     } else {
8698         RLOGE("getCdmaSubscriptionSourceResponse: radioService[%d]->mRadioResponse == NULL",
8699                 slotId);
8700     }
8701 
8702     return 0;
8703 }
8704 
requestIsimAuthenticationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8705 int radio_1_6::requestIsimAuthenticationResponse(int slotId,
8706                                             int responseType, int serial, RIL_Errno e,
8707                                             void *response, size_t responseLen) {
8708 #if VDBG
8709     RLOGD("requestIsimAuthenticationResponse: serial %d", serial);
8710 #endif
8711 
8712     if (radioService[slotId]->mRadioResponse != NULL) {
8713         RadioResponseInfo responseInfo = {};
8714         populateResponseInfo(responseInfo, serial, responseType, e);
8715         Return<void> retStatus
8716                 = radioService[slotId]->mRadioResponse->requestIsimAuthenticationResponse(
8717                 responseInfo,
8718                 convertCharPtrToHidlString((char *) response));
8719         radioService[slotId]->checkReturnStatus(retStatus);
8720     } else {
8721         RLOGE("requestIsimAuthenticationResponse: radioService[%d]->mRadioResponse == NULL",
8722                 slotId);
8723     }
8724 
8725     return 0;
8726 }
8727 
acknowledgeIncomingGsmSmsWithPduResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8728 int radio_1_6::acknowledgeIncomingGsmSmsWithPduResponse(int slotId,
8729                                                    int responseType,
8730                                                    int serial, RIL_Errno e, void *response,
8731                                                    size_t responseLen) {
8732 #if VDBG
8733     RLOGD("acknowledgeIncomingGsmSmsWithPduResponse: serial %d", serial);
8734 #endif
8735 
8736     if (radioService[slotId]->mRadioResponse != NULL) {
8737         RadioResponseInfo responseInfo = {};
8738         populateResponseInfo(responseInfo, serial, responseType, e);
8739         Return<void> retStatus
8740                 = radioService[slotId]->mRadioResponse->acknowledgeIncomingGsmSmsWithPduResponse(
8741                 responseInfo);
8742         radioService[slotId]->checkReturnStatus(retStatus);
8743     } else {
8744         RLOGE("acknowledgeIncomingGsmSmsWithPduResponse: radioService[%d]->mRadioResponse "
8745                 "== NULL", slotId);
8746     }
8747 
8748     return 0;
8749 }
8750 
sendEnvelopeWithStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8751 int radio_1_6::sendEnvelopeWithStatusResponse(int slotId,
8752                                          int responseType, int serial, RIL_Errno e, void *response,
8753                                          size_t responseLen) {
8754 #if VDBG
8755     RLOGD("sendEnvelopeWithStatusResponse: serial %d", serial);
8756 #endif
8757 
8758     if (radioService[slotId]->mRadioResponse != NULL) {
8759         RadioResponseInfo responseInfo = {};
8760         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e,
8761                 response, responseLen);
8762 
8763         Return<void> retStatus
8764                 = radioService[slotId]->mRadioResponse->sendEnvelopeWithStatusResponse(responseInfo,
8765                 result);
8766         radioService[slotId]->checkReturnStatus(retStatus);
8767     } else {
8768         RLOGE("sendEnvelopeWithStatusResponse: radioService[%d]->mRadioResponse == NULL",
8769                 slotId);
8770     }
8771 
8772     return 0;
8773 }
8774 
getVoiceRadioTechnologyResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8775 int radio_1_6::getVoiceRadioTechnologyResponse(int slotId,
8776                                           int responseType, int serial, RIL_Errno e,
8777                                           void *response, size_t responseLen) {
8778 #if VDBG
8779     RLOGD("getVoiceRadioTechnologyResponse: serial %d", serial);
8780 #endif
8781 
8782     if (radioService[slotId]->mRadioResponse != NULL) {
8783         RadioResponseInfo responseInfo = {};
8784         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
8785         Return<void> retStatus
8786                 = radioService[slotId]->mRadioResponse->getVoiceRadioTechnologyResponse(
8787                 responseInfo, (RadioTechnology) ret);
8788         radioService[slotId]->checkReturnStatus(retStatus);
8789     } else {
8790         RLOGE("getVoiceRadioTechnologyResponse: radioService[%d]->mRadioResponse == NULL",
8791                 slotId);
8792     }
8793 
8794     return 0;
8795 }
8796 
getCellInfoListResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8797 int radio_1_6::getCellInfoListResponse(int slotId,
8798                                    int responseType,
8799                                    int serial, RIL_Errno e, void *response,
8800                                    size_t responseLen) {
8801 #if VDBG
8802     RLOGD("getCellInfoListResponse: serial %d", serial);
8803 #endif
8804 
8805     if (radioService[slotId]->mRadioResponse != NULL ||
8806         radioService[slotId]->mRadioResponseV1_2 != NULL) {
8807         RadioResponseInfo responseInfo = {};
8808         populateResponseInfo(responseInfo, serial, responseType, e);
8809 
8810         Return<void> retStatus;
8811         hidl_vec<CellInfo> ret;
8812         if ((response == NULL && responseLen != 0)
8813                 || responseLen % sizeof(RIL_CellInfo_v12) != 0) {
8814             RLOGE("getCellInfoListResponse: Invalid response");
8815             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8816 
8817             if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
8818                 hidl_vec<V1_2::CellInfo> ret;
8819                 retStatus = radioService[slotId]->mRadioResponseV1_2->
8820                         getCellInfoListResponse_1_2(responseInfo, ret);
8821             } else {
8822                 hidl_vec<CellInfo> ret;
8823                 retStatus = radioService[slotId]->mRadioResponse->
8824                         getCellInfoListResponse(responseInfo, ret);
8825             }
8826         } else {
8827             if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
8828                 hidl_vec<V1_2::CellInfo> ret;
8829                 convertRilCellInfoListToHal_1_2(response, responseLen, ret);
8830                 retStatus = radioService[slotId]->mRadioResponseV1_2->
8831                         getCellInfoListResponse_1_2(responseInfo, ret);
8832             } else {
8833                 hidl_vec<CellInfo> ret;
8834                 convertRilCellInfoListToHal(response, responseLen, ret);
8835                 retStatus = radioService[slotId]->mRadioResponse->
8836                         getCellInfoListResponse(responseInfo, ret);
8837             }
8838         }
8839         radioService[slotId]->checkReturnStatus(retStatus);
8840     } else {
8841         RLOGE("getCellInfoListResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8842     }
8843 
8844     return 0;
8845 }
8846 
setCellInfoListRateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8847 int radio_1_6::setCellInfoListRateResponse(int slotId,
8848                                        int responseType,
8849                                        int serial, RIL_Errno e, void *response,
8850                                        size_t responseLen) {
8851 #if VDBG
8852     RLOGD("setCellInfoListRateResponse: serial %d", serial);
8853 #endif
8854 
8855     if (radioService[slotId]->mRadioResponse != NULL) {
8856         RadioResponseInfo responseInfo = {};
8857         populateResponseInfo(responseInfo, serial, responseType, e);
8858         Return<void> retStatus
8859                 = radioService[slotId]->mRadioResponse->setCellInfoListRateResponse(responseInfo);
8860         radioService[slotId]->checkReturnStatus(retStatus);
8861     } else {
8862         RLOGE("setCellInfoListRateResponse: radioService[%d]->mRadioResponse == NULL",
8863                 slotId);
8864     }
8865 
8866     return 0;
8867 }
8868 
setInitialAttachApnResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8869 int radio_1_6::setInitialAttachApnResponse(int slotId,
8870                                        int responseType, int serial, RIL_Errno e,
8871                                        void *response, size_t responseLen) {
8872 #if VDBG
8873     RLOGD("setInitialAttachApnResponse: serial %d", serial);
8874 #endif
8875 
8876     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
8877         RadioResponseInfo responseInfo = {};
8878         populateResponseInfo(responseInfo, serial, responseType, e);
8879         Return<void> retStatus
8880                 = radioService[slotId]->mRadioResponseV1_5->setInitialAttachApnResponse_1_5(
8881                 responseInfo);
8882     } else if (radioService[slotId]->mRadioResponse != NULL) {
8883         RadioResponseInfo responseInfo = {};
8884         populateResponseInfo(responseInfo, serial, responseType, e);
8885         Return<void> retStatus
8886                 = radioService[slotId]->mRadioResponse->setInitialAttachApnResponse(responseInfo);
8887         radioService[slotId]->checkReturnStatus(retStatus);
8888     } else {
8889         RLOGE("setInitialAttachApnResponse: radioService[%d]->mRadioResponse == NULL",
8890                 slotId);
8891     }
8892 
8893     return 0;
8894 }
8895 
getImsRegistrationStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8896 int radio_1_6::getImsRegistrationStateResponse(int slotId,
8897                                            int responseType, int serial, RIL_Errno e,
8898                                            void *response, size_t responseLen) {
8899 #if VDBG
8900     RLOGD("getImsRegistrationStateResponse: serial %d", serial);
8901 #endif
8902 
8903     if (radioService[slotId]->mRadioResponse != NULL) {
8904         RadioResponseInfo responseInfo = {};
8905         populateResponseInfo(responseInfo, serial, responseType, e);
8906         bool isRegistered = false;
8907         int ratFamily = 0;
8908         int numInts = responseLen / sizeof(int);
8909         if (response == NULL || numInts != 2) {
8910             RLOGE("getImsRegistrationStateResponse Invalid response: NULL");
8911             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8912         } else {
8913             int *pInt = (int *) response;
8914             isRegistered = pInt[0] == 1 ? true : false;
8915             ratFamily = pInt[1];
8916         }
8917         Return<void> retStatus
8918                 = radioService[slotId]->mRadioResponse->getImsRegistrationStateResponse(
8919                 responseInfo, isRegistered, (RadioTechnologyFamily) ratFamily);
8920         radioService[slotId]->checkReturnStatus(retStatus);
8921     } else {
8922         RLOGE("getImsRegistrationStateResponse: radioService[%d]->mRadioResponse == NULL",
8923                 slotId);
8924     }
8925 
8926     return 0;
8927 }
8928 
sendImsSmsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8929 int radio_1_6::sendImsSmsResponse(int slotId,
8930                               int responseType, int serial, RIL_Errno e, void *response,
8931                               size_t responseLen) {
8932 #if VDBG
8933     RLOGD("sendImsSmsResponse: serial %d", serial);
8934 #endif
8935 
8936     if (radioService[slotId]->mRadioResponse != NULL) {
8937         RadioResponseInfo responseInfo = {};
8938         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
8939                 responseLen);
8940 
8941         Return<void> retStatus
8942                 = radioService[slotId]->mRadioResponse->sendImsSmsResponse(responseInfo, result);
8943         radioService[slotId]->checkReturnStatus(retStatus);
8944     } else {
8945         RLOGE("sendSmsResponse: radioService[%d]->mRadioResponse == NULL", slotId);
8946     }
8947 
8948     return 0;
8949 }
8950 
iccTransmitApduBasicChannelResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8951 int radio_1_6::iccTransmitApduBasicChannelResponse(int slotId,
8952                                                int responseType, int serial, RIL_Errno e,
8953                                                void *response, size_t responseLen) {
8954 #if VDBG
8955     RLOGD("iccTransmitApduBasicChannelResponse: serial %d", serial);
8956 #endif
8957 
8958     if (radioService[slotId]->mRadioResponse != NULL) {
8959         RadioResponseInfo responseInfo = {};
8960         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
8961                 responseLen);
8962 
8963         Return<void> retStatus
8964                 = radioService[slotId]->mRadioResponse->iccTransmitApduBasicChannelResponse(
8965                 responseInfo, result);
8966         radioService[slotId]->checkReturnStatus(retStatus);
8967     } else {
8968         RLOGE("iccTransmitApduBasicChannelResponse: radioService[%d]->mRadioResponse "
8969                 "== NULL", slotId);
8970     }
8971 
8972     return 0;
8973 }
8974 
iccOpenLogicalChannelResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)8975 int radio_1_6::iccOpenLogicalChannelResponse(int slotId,
8976                                          int responseType, int serial, RIL_Errno e, void *response,
8977                                          size_t responseLen) {
8978 #if VDBG
8979     RLOGD("iccOpenLogicalChannelResponse: serial %d", serial);
8980 #endif
8981 
8982     if (radioService[slotId]->mRadioResponse != NULL) {
8983         RadioResponseInfo responseInfo = {};
8984         populateResponseInfo(responseInfo, serial, responseType, e);
8985         int channelId = -1;
8986         hidl_vec<int8_t> selectResponse;
8987         int numInts = responseLen / sizeof(int);
8988         if (response == NULL || responseLen % sizeof(int) != 0) {
8989             RLOGE("iccOpenLogicalChannelResponse Invalid response: NULL");
8990             if (response != NULL) {
8991                 if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
8992             }
8993         } else {
8994             int *pInt = (int *) response;
8995             channelId = pInt[0];
8996             selectResponse.resize(numInts - 1);
8997             for (int i = 1; i < numInts; i++) {
8998                 selectResponse[i - 1] = (int8_t) pInt[i];
8999             }
9000         }
9001         Return<void> retStatus
9002                 = radioService[slotId]->mRadioResponse->iccOpenLogicalChannelResponse(responseInfo,
9003                 channelId, selectResponse);
9004         radioService[slotId]->checkReturnStatus(retStatus);
9005     } else {
9006         RLOGE("iccOpenLogicalChannelResponse: radioService[%d]->mRadioResponse == NULL",
9007                 slotId);
9008     }
9009 
9010     return 0;
9011 }
9012 
iccCloseLogicalChannelResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9013 int radio_1_6::iccCloseLogicalChannelResponse(int slotId,
9014                                           int responseType, int serial, RIL_Errno e,
9015                                           void *response, size_t responseLen) {
9016 #if VDBG
9017     RLOGD("iccCloseLogicalChannelResponse: serial %d", serial);
9018 #endif
9019 
9020     if (radioService[slotId]->mRadioResponse != NULL) {
9021         RadioResponseInfo responseInfo = {};
9022         populateResponseInfo(responseInfo, serial, responseType, e);
9023         Return<void> retStatus
9024                 = radioService[slotId]->mRadioResponse->iccCloseLogicalChannelResponse(
9025                 responseInfo);
9026         radioService[slotId]->checkReturnStatus(retStatus);
9027     } else {
9028         RLOGE("iccCloseLogicalChannelResponse: radioService[%d]->mRadioResponse == NULL",
9029                 slotId);
9030     }
9031 
9032     return 0;
9033 }
9034 
iccTransmitApduLogicalChannelResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9035 int radio_1_6::iccTransmitApduLogicalChannelResponse(int slotId,
9036                                                  int responseType, int serial, RIL_Errno e,
9037                                                  void *response, size_t responseLen) {
9038 #if VDBG
9039     RLOGD("iccTransmitApduLogicalChannelResponse: serial %d", serial);
9040 #endif
9041 
9042     if (radioService[slotId]->mRadioResponse != NULL) {
9043         RadioResponseInfo responseInfo = {};
9044         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
9045                 responseLen);
9046 
9047         Return<void> retStatus
9048                 = radioService[slotId]->mRadioResponse->iccTransmitApduLogicalChannelResponse(
9049                 responseInfo, result);
9050         radioService[slotId]->checkReturnStatus(retStatus);
9051     } else {
9052         RLOGE("iccTransmitApduLogicalChannelResponse: radioService[%d]->mRadioResponse "
9053                 "== NULL", slotId);
9054     }
9055 
9056     return 0;
9057 }
9058 
nvReadItemResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9059 int radio_1_6::nvReadItemResponse(int slotId,
9060                               int responseType, int serial, RIL_Errno e,
9061                               void *response, size_t responseLen) {
9062 #if VDBG
9063     RLOGD("nvReadItemResponse: serial %d", serial);
9064 #endif
9065 
9066     if (radioService[slotId]->mRadioResponse != NULL) {
9067         RadioResponseInfo responseInfo = {};
9068         populateResponseInfo(responseInfo, serial, responseType, e);
9069         Return<void> retStatus = radioService[slotId]->mRadioResponse->nvReadItemResponse(
9070                 responseInfo,
9071                 convertCharPtrToHidlString((char *) response));
9072         radioService[slotId]->checkReturnStatus(retStatus);
9073     } else {
9074         RLOGE("nvReadItemResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9075     }
9076 
9077     return 0;
9078 }
9079 
nvWriteItemResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9080 int radio_1_6::nvWriteItemResponse(int slotId,
9081                                int responseType, int serial, RIL_Errno e,
9082                                void *response, size_t responseLen) {
9083 #if VDBG
9084     RLOGD("nvWriteItemResponse: serial %d", serial);
9085 #endif
9086 
9087     if (radioService[slotId]->mRadioResponse != NULL) {
9088         RadioResponseInfo responseInfo = {};
9089         populateResponseInfo(responseInfo, serial, responseType, e);
9090         Return<void> retStatus
9091                 = radioService[slotId]->mRadioResponse->nvWriteItemResponse(responseInfo);
9092         radioService[slotId]->checkReturnStatus(retStatus);
9093     } else {
9094         RLOGE("nvWriteItemResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9095     }
9096 
9097     return 0;
9098 }
9099 
nvWriteCdmaPrlResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9100 int radio_1_6::nvWriteCdmaPrlResponse(int slotId,
9101                                   int responseType, int serial, RIL_Errno e,
9102                                   void *response, size_t responseLen) {
9103 #if VDBG
9104     RLOGD("nvWriteCdmaPrlResponse: serial %d", serial);
9105 #endif
9106 
9107     if (radioService[slotId]->mRadioResponse != NULL) {
9108         RadioResponseInfo responseInfo = {};
9109         populateResponseInfo(responseInfo, serial, responseType, e);
9110         Return<void> retStatus
9111                 = radioService[slotId]->mRadioResponse->nvWriteCdmaPrlResponse(responseInfo);
9112         radioService[slotId]->checkReturnStatus(retStatus);
9113     } else {
9114         RLOGE("nvWriteCdmaPrlResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9115     }
9116 
9117     return 0;
9118 }
9119 
nvResetConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9120 int radio_1_6::nvResetConfigResponse(int slotId,
9121                                  int responseType, int serial, RIL_Errno e,
9122                                  void *response, size_t responseLen) {
9123 #if VDBG
9124     RLOGD("nvResetConfigResponse: serial %d", serial);
9125 #endif
9126 
9127     if (radioService[slotId]->mRadioResponse != NULL) {
9128         RadioResponseInfo responseInfo = {};
9129         populateResponseInfo(responseInfo, serial, responseType, e);
9130         Return<void> retStatus
9131                 = radioService[slotId]->mRadioResponse->nvResetConfigResponse(responseInfo);
9132         radioService[slotId]->checkReturnStatus(retStatus);
9133     } else {
9134         RLOGE("nvResetConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9135     }
9136 
9137     return 0;
9138 }
9139 
setUiccSubscriptionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9140 int radio_1_6::setUiccSubscriptionResponse(int slotId,
9141                                        int responseType, int serial, RIL_Errno e,
9142                                        void *response, size_t responseLen) {
9143 #if VDBG
9144     RLOGD("setUiccSubscriptionResponse: serial %d", serial);
9145 #endif
9146 
9147     if (radioService[slotId]->mRadioResponse != NULL) {
9148         RadioResponseInfo responseInfo = {};
9149         populateResponseInfo(responseInfo, serial, responseType, e);
9150         Return<void> retStatus
9151                 = radioService[slotId]->mRadioResponse->setUiccSubscriptionResponse(responseInfo);
9152         radioService[slotId]->checkReturnStatus(retStatus);
9153     } else {
9154         RLOGE("setUiccSubscriptionResponse: radioService[%d]->mRadioResponse == NULL",
9155                 slotId);
9156     }
9157 
9158     return 0;
9159 }
9160 
setDataAllowedResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9161 int radio_1_6::setDataAllowedResponse(int slotId,
9162                                   int responseType, int serial, RIL_Errno e,
9163                                   void *response, size_t responseLen) {
9164 #if VDBG
9165     RLOGD("setDataAllowedResponse: serial %d", serial);
9166 #endif
9167 
9168     if (radioService[slotId]->mRadioResponse != NULL) {
9169         RadioResponseInfo responseInfo = {};
9170         populateResponseInfo(responseInfo, serial, responseType, e);
9171         Return<void> retStatus
9172                 = radioService[slotId]->mRadioResponse->setDataAllowedResponse(responseInfo);
9173         radioService[slotId]->checkReturnStatus(retStatus);
9174     } else {
9175         RLOGE("setDataAllowedResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9176     }
9177 
9178     return 0;
9179 }
9180 
getHardwareConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9181 int radio_1_6::getHardwareConfigResponse(int slotId,
9182                                      int responseType, int serial, RIL_Errno e,
9183                                      void *response, size_t responseLen) {
9184 #if VDBG
9185     RLOGD("getHardwareConfigResponse: serial %d", serial);
9186 #endif
9187 
9188     if (radioService[slotId]->mRadioResponse != NULL) {
9189         RadioResponseInfo responseInfo = {};
9190         populateResponseInfo(responseInfo, serial, responseType, e);
9191 
9192         hidl_vec<HardwareConfig> result;
9193         if ((response == NULL && responseLen != 0)
9194                 || responseLen % sizeof(RIL_HardwareConfig) != 0) {
9195             RLOGE("hardwareConfigChangedInd: invalid response");
9196             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9197         } else {
9198             convertRilHardwareConfigListToHal(response, responseLen, result);
9199         }
9200 
9201         Return<void> retStatus = radioService[slotId]->mRadioResponse->getHardwareConfigResponse(
9202                 responseInfo, result);
9203         radioService[slotId]->checkReturnStatus(retStatus);
9204     } else {
9205         RLOGE("getHardwareConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9206     }
9207 
9208     return 0;
9209 }
9210 
requestIccSimAuthenticationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9211 int radio_1_6::requestIccSimAuthenticationResponse(int slotId,
9212                                                int responseType, int serial, RIL_Errno e,
9213                                                void *response, size_t responseLen) {
9214 #if VDBG
9215     RLOGD("requestIccSimAuthenticationResponse: serial %d", serial);
9216 #endif
9217 
9218     if (radioService[slotId]->mRadioResponse != NULL) {
9219         RadioResponseInfo responseInfo = {};
9220         IccIoResult result = responseIccIo(responseInfo, serial, responseType, e, response,
9221                 responseLen);
9222 
9223         Return<void> retStatus
9224                 = radioService[slotId]->mRadioResponse->requestIccSimAuthenticationResponse(
9225                 responseInfo, result);
9226         radioService[slotId]->checkReturnStatus(retStatus);
9227     } else {
9228         RLOGE("requestIccSimAuthenticationResponse: radioService[%d]->mRadioResponse "
9229                 "== NULL", slotId);
9230     }
9231 
9232     return 0;
9233 }
9234 
setDataProfileResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9235 int radio_1_6::setDataProfileResponse(int slotId,
9236                                   int responseType, int serial, RIL_Errno e,
9237                                   void *response, size_t responseLen) {
9238 #if VDBG
9239     RLOGD("setDataProfileResponse: serial %d", serial);
9240 #endif
9241 
9242     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
9243         RadioResponseInfo responseInfo = {};
9244         populateResponseInfo(responseInfo, serial, responseType, e);
9245         Return<void> retStatus
9246                 = radioService[slotId]->mRadioResponseV1_5->setDataProfileResponse_1_5(
9247                 responseInfo);
9248     } else if (radioService[slotId]->mRadioResponse != NULL) {
9249         RadioResponseInfo responseInfo = {};
9250         populateResponseInfo(responseInfo, serial, responseType, e);
9251         Return<void> retStatus
9252                 = radioService[slotId]->mRadioResponse->setDataProfileResponse(responseInfo);
9253         radioService[slotId]->checkReturnStatus(retStatus);
9254     } else {
9255         RLOGE("setDataProfileResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9256     }
9257 
9258     return 0;
9259 }
9260 
requestShutdownResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9261 int radio_1_6::requestShutdownResponse(int slotId,
9262                                   int responseType, int serial, RIL_Errno e,
9263                                   void *response, size_t responseLen) {
9264 #if VDBG
9265     RLOGD("requestShutdownResponse: serial %d", serial);
9266 #endif
9267 
9268     if (radioService[slotId]->mRadioResponse != NULL) {
9269         RadioResponseInfo responseInfo = {};
9270         populateResponseInfo(responseInfo, serial, responseType, e);
9271         Return<void> retStatus
9272                 = radioService[slotId]->mRadioResponse->requestShutdownResponse(responseInfo);
9273         radioService[slotId]->checkReturnStatus(retStatus);
9274     } else {
9275         RLOGE("requestShutdownResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9276     }
9277 
9278     return 0;
9279 }
9280 
responseRadioCapability(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen,RadioCapability & rc)9281 void responseRadioCapability(RadioResponseInfo& responseInfo, int serial,
9282         int responseType, RIL_Errno e, void *response, size_t responseLen, RadioCapability& rc) {
9283     populateResponseInfo(responseInfo, serial, responseType, e);
9284 
9285     if (response == NULL || responseLen != sizeof(RIL_RadioCapability)) {
9286         RLOGE("responseRadioCapability: Invalid response");
9287         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9288         rc.logicalModemUuid = hidl_string();
9289     } else {
9290         convertRilRadioCapabilityToHal(response, responseLen, rc);
9291     }
9292 }
9293 
getRadioCapabilityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9294 int radio_1_6::getRadioCapabilityResponse(int slotId,
9295                                      int responseType, int serial, RIL_Errno e,
9296                                      void *response, size_t responseLen) {
9297 #if VDBG
9298     RLOGD("getRadioCapabilityResponse: serial %d", serial);
9299 #endif
9300 
9301     if (radioService[slotId]->mRadioResponse != NULL) {
9302         RadioResponseInfo responseInfo = {};
9303         RadioCapability result = {};
9304         responseRadioCapability(responseInfo, serial, responseType, e, response, responseLen,
9305                 result);
9306         Return<void> retStatus = radioService[slotId]->mRadioResponse->getRadioCapabilityResponse(
9307                 responseInfo, result);
9308         radioService[slotId]->checkReturnStatus(retStatus);
9309     } else {
9310         RLOGE("getRadioCapabilityResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9311     }
9312 
9313     return 0;
9314 }
9315 
setRadioCapabilityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9316 int radio_1_6::setRadioCapabilityResponse(int slotId,
9317                                      int responseType, int serial, RIL_Errno e,
9318                                      void *response, size_t responseLen) {
9319 #if VDBG
9320     RLOGD("setRadioCapabilityResponse: serial %d", serial);
9321 #endif
9322 
9323     if (radioService[slotId]->mRadioResponse != NULL) {
9324         RadioResponseInfo responseInfo = {};
9325         RadioCapability result = {};
9326         responseRadioCapability(responseInfo, serial, responseType, e, response, responseLen,
9327                 result);
9328         Return<void> retStatus = radioService[slotId]->mRadioResponse->setRadioCapabilityResponse(
9329                 responseInfo, result);
9330         radioService[slotId]->checkReturnStatus(retStatus);
9331     } else {
9332         RLOGE("setRadioCapabilityResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9333     }
9334 
9335     return 0;
9336 }
9337 
responseLceStatusInfo(RadioResponseInfo & responseInfo,int serial,int responseType,RIL_Errno e,void * response,size_t responseLen)9338 LceStatusInfo responseLceStatusInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
9339                                     RIL_Errno e, void *response, size_t responseLen) {
9340     populateResponseInfo(responseInfo, serial, responseType, e);
9341     LceStatusInfo result = {};
9342 
9343     if (response == NULL || responseLen != sizeof(RIL_LceStatusInfo)) {
9344         RLOGE("Invalid response: NULL");
9345         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9346     } else {
9347         RIL_LceStatusInfo *resp = (RIL_LceStatusInfo *) response;
9348         result.lceStatus = (LceStatus) resp->lce_status;
9349         result.actualIntervalMs = (uint8_t) resp->actual_interval_ms;
9350     }
9351     return result;
9352 }
9353 
startLceServiceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9354 int radio_1_6::startLceServiceResponse(int slotId,
9355                                    int responseType, int serial, RIL_Errno e,
9356                                    void *response, size_t responseLen) {
9357 #if VDBG
9358     RLOGD("startLceServiceResponse: serial %d", serial);
9359 #endif
9360 
9361     if (radioService[slotId]->mRadioResponse != NULL) {
9362         RadioResponseInfo responseInfo = {};
9363         LceStatusInfo result = responseLceStatusInfo(responseInfo, serial, responseType, e,
9364                 response, responseLen);
9365 
9366         Return<void> retStatus
9367                 = radioService[slotId]->mRadioResponse->startLceServiceResponse(responseInfo,
9368                 result);
9369         radioService[slotId]->checkReturnStatus(retStatus);
9370     } else {
9371         RLOGE("startLceServiceResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9372     }
9373 
9374     return 0;
9375 }
9376 
stopLceServiceResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9377 int radio_1_6::stopLceServiceResponse(int slotId,
9378                                   int responseType, int serial, RIL_Errno e,
9379                                   void *response, size_t responseLen) {
9380 #if VDBG
9381     RLOGD("stopLceServiceResponse: serial %d", serial);
9382 #endif
9383 
9384     if (radioService[slotId]->mRadioResponse != NULL) {
9385         RadioResponseInfo responseInfo = {};
9386         LceStatusInfo result = responseLceStatusInfo(responseInfo, serial, responseType, e,
9387                 response, responseLen);
9388 
9389         Return<void> retStatus
9390                 = radioService[slotId]->mRadioResponse->stopLceServiceResponse(responseInfo,
9391                 result);
9392         radioService[slotId]->checkReturnStatus(retStatus);
9393     } else {
9394         RLOGE("stopLceServiceResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9395     }
9396 
9397     return 0;
9398 }
9399 
pullLceDataResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9400 int radio_1_6::pullLceDataResponse(int slotId,
9401                                int responseType, int serial, RIL_Errno e,
9402                                void *response, size_t responseLen) {
9403 #if VDBG
9404     RLOGD("pullLceDataResponse: serial %d", serial);
9405 #endif
9406 
9407     if (radioService[slotId]->mRadioResponse != NULL) {
9408         RadioResponseInfo responseInfo = {};
9409         populateResponseInfo(responseInfo, serial, responseType, e);
9410 
9411         LceDataInfo result = {};
9412         if (response == NULL || responseLen != sizeof(RIL_LceDataInfo)) {
9413             RLOGE("pullLceDataResponse: Invalid response");
9414             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9415         } else {
9416             convertRilLceDataInfoToHal(response, responseLen, result);
9417         }
9418 
9419         Return<void> retStatus = radioService[slotId]->mRadioResponse->pullLceDataResponse(
9420                 responseInfo, result);
9421         radioService[slotId]->checkReturnStatus(retStatus);
9422     } else {
9423         RLOGE("pullLceDataResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9424     }
9425 
9426     return 0;
9427 }
9428 
getModemActivityInfoResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9429 int radio_1_6::getModemActivityInfoResponse(int slotId,
9430                                         int responseType, int serial, RIL_Errno e,
9431                                         void *response, size_t responseLen) {
9432 #if VDBG
9433     RLOGD("getModemActivityInfoResponse: serial %d", serial);
9434 #endif
9435 
9436     if (radioService[slotId]->mRadioResponse != NULL) {
9437         RadioResponseInfo responseInfo = {};
9438         populateResponseInfo(responseInfo, serial, responseType, e);
9439         ActivityStatsInfo info;
9440         if (response == NULL || responseLen != sizeof(RIL_ActivityStatsInfo)) {
9441             RLOGE("getModemActivityInfoResponse Invalid response: NULL");
9442             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9443         } else {
9444             RIL_ActivityStatsInfo *resp = (RIL_ActivityStatsInfo *)response;
9445             info.sleepModeTimeMs = resp->sleep_mode_time_ms;
9446             info.idleModeTimeMs = resp->idle_mode_time_ms;
9447             for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
9448                 info.txmModetimeMs[i] = resp->tx_mode_time_ms[i];
9449             }
9450             info.rxModeTimeMs = resp->rx_mode_time_ms;
9451         }
9452 
9453         Return<void> retStatus
9454                 = radioService[slotId]->mRadioResponse->getModemActivityInfoResponse(responseInfo,
9455                 info);
9456         radioService[slotId]->checkReturnStatus(retStatus);
9457     } else {
9458         RLOGE("getModemActivityInfoResponse: radioService[%d]->mRadioResponse == NULL",
9459                 slotId);
9460     }
9461 
9462     return 0;
9463 }
9464 
setAllowedCarriersResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9465 int radio_1_6::setAllowedCarriersResponse(int slotId,
9466                                       int responseType, int serial, RIL_Errno e,
9467                                       void *response, size_t responseLen) {
9468 #if VDBG
9469     RLOGD("setAllowedCarriersResponse: serial %d", serial);
9470 #endif
9471     RadioResponseInfo responseInfo = {};
9472 
9473     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9474         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4
9475                 ->setAllowedCarriersResponse_1_4(responseInfo);
9476         radioService[slotId]->checkReturnStatus(retStatus);
9477     } else if (radioService[slotId]->mRadioResponse != NULL) {
9478         int ret = responseInt(responseInfo, serial, responseType, e, response, responseLen);
9479         Return<void> retStatus = radioService[slotId]->mRadioResponse
9480                 ->setAllowedCarriersResponse(responseInfo, ret);
9481         radioService[slotId]->checkReturnStatus(retStatus);
9482     } else {
9483         RLOGE("setAllowedCarriersResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9484     }
9485 
9486     return 0;
9487 }
9488 
prepareCarrierRestrictionsResponse(hidl_vec<Carrier> & allowedCarriers,hidl_vec<Carrier> & excludedCarriers,bool & allAllowed,const RIL_CarrierRestrictions * pCr)9489 void prepareCarrierRestrictionsResponse(hidl_vec<Carrier>& allowedCarriers,
9490                                        hidl_vec<Carrier>& excludedCarriers,
9491                                        bool& allAllowed,
9492                                        const RIL_CarrierRestrictions* pCr) {
9493     if (pCr->len_allowed_carriers > 0 || pCr->len_excluded_carriers > 0) {
9494         allAllowed = false;
9495     }
9496     allowedCarriers.resize(pCr->len_allowed_carriers);
9497     for(int i = 0; i < pCr->len_allowed_carriers; i++) {
9498         RIL_Carrier *carrier = pCr->allowed_carriers + i;
9499         allowedCarriers[i].mcc = convertCharPtrToHidlString(carrier->mcc);
9500         allowedCarriers[i].mnc = convertCharPtrToHidlString(carrier->mnc);
9501         allowedCarriers[i].matchType = (CarrierMatchType) carrier->match_type;
9502         allowedCarriers[i].matchData =
9503                 convertCharPtrToHidlString(carrier->match_data);
9504     }
9505 
9506     excludedCarriers.resize(pCr->len_excluded_carriers);
9507     for(int i = 0; i < pCr->len_excluded_carriers; i++) {
9508         RIL_Carrier *carrier = pCr->excluded_carriers + i;
9509         excludedCarriers[i].mcc = convertCharPtrToHidlString(carrier->mcc);
9510         excludedCarriers[i].mnc = convertCharPtrToHidlString(carrier->mnc);
9511         excludedCarriers[i].matchType = (CarrierMatchType) carrier->match_type;
9512         excludedCarriers[i].matchData =
9513                 convertCharPtrToHidlString(carrier->match_data);
9514     }
9515 }
9516 
getAllowedCarriersResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9517 int radio_1_6::getAllowedCarriersResponse(int slotId,
9518                                       int responseType, int serial, RIL_Errno e,
9519                                       void *response, size_t responseLen) {
9520 #if VDBG
9521     RLOGD("getAllowedCarriersResponse: serial %d", serial);
9522 #endif
9523     RadioResponseInfo responseInfo = {};
9524     populateResponseInfo(responseInfo, serial, responseType, e);
9525 
9526     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9527         V1_4::CarrierRestrictionsWithPriority carrierInfo = {};
9528         V1_4::SimLockMultiSimPolicy multiSimPolicy =
9529                 V1_4::SimLockMultiSimPolicy::NO_MULTISIM_POLICY;
9530         bool allAllowed = true;
9531 
9532         if (response == NULL) {
9533 #if VDBG
9534             RLOGD("getAllowedCarriersResponse response is NULL: all allowed");
9535 #endif
9536             carrierInfo.allowedCarriers.resize(0);
9537             carrierInfo.excludedCarriers.resize(0);
9538             carrierInfo.allowedCarriersPrioritized = false;
9539         } else if (responseLen != sizeof(RIL_CarrierRestrictionsWithPriority)) {
9540             RLOGE("getAllowedCarriersResponse Invalid response");
9541             if (e == RIL_E_SUCCESS) {
9542                 responseInfo.error = RadioError::INVALID_RESPONSE;
9543             }
9544         } else {
9545             RIL_CarrierRestrictionsWithPriority *pCrExt =
9546                     (RIL_CarrierRestrictionsWithPriority *)response;
9547 
9548             // Convert into the structure used in IRadio 1.0 to re-use existing code
9549             RIL_CarrierRestrictions cr = {};
9550             cr.len_allowed_carriers = pCrExt->len_allowed_carriers;
9551             cr.len_excluded_carriers = pCrExt->len_excluded_carriers;
9552             cr.allowed_carriers = pCrExt->allowed_carriers;
9553             cr.excluded_carriers = pCrExt->excluded_carriers;
9554             prepareCarrierRestrictionsResponse(carrierInfo.allowedCarriers,
9555                     carrierInfo.excludedCarriers, allAllowed, &cr);
9556 
9557             carrierInfo.allowedCarriersPrioritized = (bool)pCrExt->allowedCarriersPrioritized;
9558             multiSimPolicy = (V1_4::SimLockMultiSimPolicy)pCrExt->multiSimPolicy;
9559         }
9560 
9561         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4
9562                 ->getAllowedCarriersResponse_1_4(responseInfo, carrierInfo, multiSimPolicy);
9563         radioService[slotId]->checkReturnStatus(retStatus);
9564     } else if (radioService[slotId]->mRadioResponse != NULL) {
9565         CarrierRestrictions carrierInfo = {};
9566         bool allAllowed = true;
9567         if (response == NULL) {
9568 #if VDBG
9569             RLOGD("getAllowedCarriersResponse response is NULL: all allowed");
9570 #endif
9571             carrierInfo.allowedCarriers.resize(0);
9572             carrierInfo.excludedCarriers.resize(0);
9573         } else if (responseLen != sizeof(RIL_CarrierRestrictions)) {
9574             RLOGE("getAllowedCarriersResponse Invalid response");
9575             if (e == RIL_E_SUCCESS) {
9576                 responseInfo.error = RadioError::INVALID_RESPONSE;
9577             }
9578         } else {
9579             RIL_CarrierRestrictions *pCr = (RIL_CarrierRestrictions *)response;
9580             prepareCarrierRestrictionsResponse(carrierInfo.allowedCarriers,
9581                     carrierInfo.excludedCarriers, allAllowed, pCr);
9582         }
9583 
9584         Return<void> retStatus = radioService[slotId]->mRadioResponse
9585                 ->getAllowedCarriersResponse(responseInfo, allAllowed, carrierInfo);
9586         radioService[slotId]->checkReturnStatus(retStatus);
9587     } else {
9588         RLOGE("getAllowedCarriersResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9589     }
9590 
9591     return 0;
9592 }
9593 
sendDeviceStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responselen)9594 int radio_1_6::sendDeviceStateResponse(int slotId,
9595                               int responseType, int serial, RIL_Errno e,
9596                               void *response, size_t responselen) {
9597 #if VDBG
9598     RLOGD("sendDeviceStateResponse: serial %d", serial);
9599 #endif
9600 
9601     if (radioService[slotId]->mRadioResponse != NULL) {
9602         RadioResponseInfo responseInfo = {};
9603         populateResponseInfo(responseInfo, serial, responseType, e);
9604         Return<void> retStatus
9605                 = radioService[slotId]->mRadioResponse->sendDeviceStateResponse(responseInfo);
9606         radioService[slotId]->checkReturnStatus(retStatus);
9607     } else {
9608         RLOGE("sendDeviceStateResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9609     }
9610 
9611     return 0;
9612 }
9613 
setCarrierInfoForImsiEncryptionResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9614 int radio_1_6::setCarrierInfoForImsiEncryptionResponse(int slotId,
9615                                int responseType, int serial, RIL_Errno e,
9616                                void *response, size_t responseLen) {
9617   RLOGD("setCarrierInfoForImsiEncryptionResponse: serial %d", serial);
9618   if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
9619       RadioResponseInfo responseInfo = {};
9620       populateResponseInfo(responseInfo, serial, responseType, e);
9621       Return<void> retStatus = radioService[slotId]->mRadioResponseV1_1->
9622               setCarrierInfoForImsiEncryptionResponse(responseInfo);
9623       radioService[slotId]->checkReturnStatus(retStatus);
9624   } else {
9625       RLOGE("setCarrierInfoForImsiEncryptionResponse: radioService[%d]->mRadioResponseV1_1 == "
9626               "NULL", slotId);
9627   }
9628   return 0;
9629 }
9630 
setIndicationFilterResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responselen)9631 int radio_1_6::setIndicationFilterResponse(int slotId,
9632                               int responseType, int serial, RIL_Errno e,
9633                               void *response, size_t responselen) {
9634 #if VDBG
9635     RLOGD("setIndicationFilterResponse: serial %d", serial);
9636 #endif
9637     RadioResponseInfo responseInfo = {};
9638     populateResponseInfo(responseInfo, serial, responseType, e);
9639 
9640     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
9641         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
9642                 ->setIndicationFilterResponse_1_5(responseInfo);
9643         radioService[slotId]->checkReturnStatus(retStatus);
9644     } else if (radioService[slotId]->mRadioResponse != NULL) {
9645         Return<void> retStatus = radioService[slotId]->mRadioResponse
9646                 ->setIndicationFilterResponse(responseInfo);
9647         radioService[slotId]->checkReturnStatus(retStatus);
9648     } else {
9649         RLOGE("setIndicationFilterResponse: radioService[%d]->mRadioResponse == NULL", slotId);
9650     }
9651 
9652     return 0;
9653 }
9654 
setSimCardPowerResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9655 int radio_1_6::setSimCardPowerResponse(int slotId,
9656                                    int responseType, int serial, RIL_Errno e,
9657                                    void *response, size_t responseLen) {
9658 #if VDBG
9659     RLOGD("setSimCardPowerResponse: serial %d", serial);
9660 #endif
9661 
9662     if (radioService[slotId]->mRadioResponse != NULL
9663             || radioService[slotId]->mRadioResponseV1_1 != NULL
9664             || radioService[slotId]->mRadioResponseV1_6 != NULL) {
9665         if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
9666             ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo = {};
9667             populateResponseInfo_1_6(responseInfo, serial, responseType, e);
9668             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6->
9669                     setSimCardPowerResponse_1_6(responseInfo);
9670             radioService[slotId]->checkReturnStatus(retStatus);
9671         } else if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
9672             RLOGD("setSimCardPowerResponse: radioService[%d]->mRadioResponseV1_6 == NULL", slotId);
9673             RadioResponseInfo responseInfo = {};
9674             populateResponseInfo(responseInfo, serial, responseType, e);
9675             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_1->
9676                     setSimCardPowerResponse_1_1(responseInfo);
9677             radioService[slotId]->checkReturnStatus(retStatus);
9678         } else {
9679             RLOGD("setSimCardPowerResponse: radioService[%d]->mRadioResponseV1_6 and V1_1 == NULL",
9680                     slotId);
9681             RadioResponseInfo responseInfo = {};
9682             populateResponseInfo(responseInfo, serial, responseType, e);
9683             Return<void> retStatus = radioService[slotId]->mRadioResponse
9684                     ->setSimCardPowerResponse(responseInfo);
9685             radioService[slotId]->checkReturnStatus(retStatus);
9686         }
9687     } else {
9688         RLOGE("setSimCardPowerResponse: radioService[%d]->mRadioResponse == NULL && "
9689                 "radioService[%d]->mRadioResponseV1_1 and V1_6 == NULL", slotId, slotId);
9690     }
9691     return 0;
9692 }
9693 
startNetworkScanResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9694 int radio_1_6::startNetworkScanResponse(int slotId, int responseType, int serial, RIL_Errno e,
9695                                         void *response, size_t responseLen) {
9696 #if VDBG
9697     RLOGD("startNetworkScanResponse: serial %d", serial);
9698 #endif
9699 
9700     if (radioService[slotId]->mRadioResponseV1_1 != NULL ||
9701           radioService[slotId]->mRadioResponseV1_2 != NULL ||
9702           radioService[slotId]->mRadioResponseV1_4 != NULL ||
9703           radioService[slotId]->mRadioResponseV1_6 != NULL) {
9704         RadioResponseInfo responseInfo = {};
9705         populateResponseInfo(responseInfo, serial, responseType, e);
9706 
9707         if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
9708             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
9709                     ->startNetworkScanResponse_1_5(responseInfo);
9710             radioService[slotId]->checkReturnStatus(retStatus);
9711         } else if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9712             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_4
9713                     ->startNetworkScanResponse_1_4(responseInfo);
9714             radioService[slotId]->checkReturnStatus(retStatus);
9715         } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
9716             Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2
9717                     ->startNetworkScanResponse(responseInfo);
9718             radioService[slotId]->checkReturnStatus(retStatus);
9719         }  else if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
9720           Return<void> retStatus = radioService[slotId]->mRadioResponseV1_1
9721                   ->startNetworkScanResponse(responseInfo);
9722           radioService[slotId]->checkReturnStatus(retStatus);
9723         } else {
9724             RLOGE("startNetworkScanResponse: radioService[%d]->mRadioResponseV1_1 == NULL or "
9725                     "radioService[%d]->mRadioResponseV1_4 == NULL", slotId, slotId);
9726         }
9727     }
9728 
9729     return 0;
9730 }
9731 
stopNetworkScanResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9732 int radio_1_6::stopNetworkScanResponse(int slotId, int responseType, int serial, RIL_Errno e,
9733                                    void *response, size_t responseLen) {
9734 #if VDBG
9735     RLOGD("stopNetworkScanResponse: serial %d", serial);
9736 #endif
9737 
9738     if (radioService[slotId]->mRadioResponseV1_1 != NULL) {
9739         RadioResponseInfo responseInfo = {};
9740         populateResponseInfo(responseInfo, serial, responseType, e);
9741         Return<void> retStatus
9742                 = radioService[slotId]->mRadioResponseV1_1->stopNetworkScanResponse(responseInfo);
9743         radioService[slotId]->checkReturnStatus(retStatus);
9744     } else {
9745         RLOGE("stopNetworkScanResponse: radioService[%d]->mRadioResponseV1_1 == NULL", slotId);
9746     }
9747 
9748     return 0;
9749 }
9750 
emergencyDialResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9751 int radio_1_6::emergencyDialResponse(int slotId, int responseType, int serial, RIL_Errno e,
9752                                     void *response, size_t responseLen) {
9753 #if VDBG
9754     RLOGD("emergencyDialResponse: serial %d", serial);
9755 #endif
9756 
9757     if (radioService[slotId]->mRadioResponseV1_4 != NULL) {
9758         RadioResponseInfo responseInfo = {};
9759         populateResponseInfo(responseInfo, serial, responseType, e);
9760         Return<void> retStatus
9761                 = radioService[slotId]->mRadioResponseV1_4->emergencyDialResponse(responseInfo);
9762         radioService[slotId]->checkReturnStatus(retStatus);
9763     } else {
9764         RLOGE("emergencyDialResponse: radioService[%d]->mRadioResponseV1_4 == NULL", slotId);
9765     }
9766     return 0;
9767 }
9768 
convertRilKeepaliveStatusToHal(const RIL_KeepaliveStatus * rilStatus,V1_1::KeepaliveStatus & halStatus)9769 void convertRilKeepaliveStatusToHal(const RIL_KeepaliveStatus *rilStatus,
9770         V1_1::KeepaliveStatus& halStatus) {
9771     halStatus.sessionHandle = rilStatus->sessionHandle;
9772     halStatus.code = static_cast<V1_1::KeepaliveStatusCode>(rilStatus->code);
9773 }
9774 
startKeepaliveResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9775 int radio_1_6::startKeepaliveResponse(int slotId, int responseType, int serial, RIL_Errno e,
9776                                     void *response, size_t responseLen) {
9777 #if VDBG
9778     RLOGD("%s(): %d", __FUNCTION__, serial);
9779 #endif
9780     RadioResponseInfo responseInfo = {};
9781     populateResponseInfo(responseInfo, serial, responseType, e);
9782 
9783     // If we don't have a radio service, there's nothing we can do
9784     if (radioService[slotId]->mRadioResponseV1_1 == NULL) {
9785         RLOGE("%s: radioService[%d]->mRadioResponseV1_1 == NULL", __FUNCTION__, slotId);
9786         return 0;
9787     }
9788 
9789     V1_1::KeepaliveStatus ks = {};
9790     if (response == NULL || responseLen != sizeof(V1_1::KeepaliveStatus)) {
9791         RLOGE("%s: invalid response - %d", __FUNCTION__, static_cast<int>(e));
9792         if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9793     } else {
9794         convertRilKeepaliveStatusToHal(static_cast<RIL_KeepaliveStatus*>(response), ks);
9795     }
9796 
9797     Return<void> retStatus =
9798             radioService[slotId]->mRadioResponseV1_1->startKeepaliveResponse(responseInfo, ks);
9799     radioService[slotId]->checkReturnStatus(retStatus);
9800     return 0;
9801 }
9802 
stopKeepaliveResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9803 int radio_1_6::stopKeepaliveResponse(int slotId, int responseType, int serial, RIL_Errno e,
9804                                     void *response, size_t responseLen) {
9805 #if VDBG
9806     RLOGD("%s(): %d", __FUNCTION__, serial);
9807 #endif
9808     RadioResponseInfo responseInfo = {};
9809     populateResponseInfo(responseInfo, serial, responseType, e);
9810 
9811     // If we don't have a radio service, there's nothing we can do
9812     if (radioService[slotId]->mRadioResponseV1_1 == NULL) {
9813         RLOGE("%s: radioService[%d]->mRadioResponseV1_1 == NULL", __FUNCTION__, slotId);
9814         return 0;
9815     }
9816 
9817     Return<void> retStatus =
9818             radioService[slotId]->mRadioResponseV1_1->stopKeepaliveResponse(responseInfo);
9819     radioService[slotId]->checkReturnStatus(retStatus);
9820     return 0;
9821 }
9822 
getModemStackStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9823 int radio_1_6::getModemStackStatusResponse(int slotId, int responseType, int serial, RIL_Errno e,
9824                                     void *response, size_t responseLen) {
9825 #if VDBG
9826     RLOGD("%s(): %d", __FUNCTION__, serial);
9827 #endif
9828     RadioResponseInfo responseInfo = {};
9829     populateResponseInfo(responseInfo, serial, responseType, e);
9830 
9831     // If we don't have a radio service, there's nothing we can do
9832     if (radioService[slotId]->mRadioResponseV1_3 == NULL) {
9833         RLOGE("%s: radioService[%d]->mRadioResponseV1_3 == NULL", __FUNCTION__, slotId);
9834         return 0;
9835     }
9836 
9837     Return<void> retStatus =
9838             radioService[slotId]->mRadioResponseV1_3->getModemStackStatusResponse(
9839             responseInfo, true);
9840     radioService[slotId]->checkReturnStatus(retStatus);
9841     return 0;
9842 }
9843 
enableModemResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9844 int radio_1_6::enableModemResponse(int slotId, int responseType, int serial, RIL_Errno e,
9845                                     void *response, size_t responseLen) {
9846 #if VDBG
9847     RLOGD("%s(): %d", __FUNCTION__, serial);
9848 #endif
9849     RadioResponseInfo responseInfo = {};
9850     populateResponseInfo(responseInfo, serial, responseType, e);
9851 
9852     // If we don't have a radio service, there's nothing we can do
9853     if (radioService[slotId]->mRadioResponseV1_3 == NULL) {
9854         RLOGE("%s: radioService[%d]->mRadioResponseV1_3 == NULL", __FUNCTION__, slotId);
9855         return 0;
9856     }
9857 
9858     Return<void> retStatus =
9859             radioService[slotId]->mRadioResponseV1_3->enableModemResponse(responseInfo);
9860     radioService[slotId]->checkReturnStatus(retStatus);
9861     return 0;
9862 }
9863 
sendRequestRawResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9864 int radio_1_6::sendRequestRawResponse(int slotId,
9865                                   int responseType, int serial, RIL_Errno e,
9866                                   void *response, size_t responseLen) {
9867 #if VDBG
9868    RLOGD("sendRequestRawResponse: serial %d", serial);
9869 #endif
9870 
9871     if (!kOemHookEnabled) return 0;
9872 
9873     if (oemHookService[slotId]->mOemHookResponse != NULL) {
9874         RadioResponseInfo responseInfo = {};
9875         populateResponseInfo(responseInfo, serial, responseType, e);
9876         hidl_vec<uint8_t> data;
9877 
9878         if (response == NULL) {
9879             RLOGE("sendRequestRawResponse: Invalid response");
9880             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9881         } else {
9882             data.setToExternal((uint8_t *) response, responseLen);
9883         }
9884         Return<void> retStatus = oemHookService[slotId]->mOemHookResponse->
9885                 sendRequestRawResponse(responseInfo, data);
9886         checkReturnStatus(slotId, retStatus, false);
9887     } else {
9888         RLOGE("sendRequestRawResponse: oemHookService[%d]->mOemHookResponse == NULL",
9889                 slotId);
9890     }
9891 
9892     return 0;
9893 }
9894 
sendRequestStringsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9895 int radio_1_6::sendRequestStringsResponse(int slotId,
9896                                       int responseType, int serial, RIL_Errno e,
9897                                       void *response, size_t responseLen) {
9898 #if VDBG
9899     RLOGD("sendRequestStringsResponse: serial %d", serial);
9900 #endif
9901 
9902     if (!kOemHookEnabled) return 0;
9903 
9904     if (oemHookService[slotId]->mOemHookResponse != NULL) {
9905         RadioResponseInfo responseInfo = {};
9906         populateResponseInfo(responseInfo, serial, responseType, e);
9907         hidl_vec<hidl_string> data;
9908 
9909         if ((response == NULL && responseLen != 0) || responseLen % sizeof(char *) != 0) {
9910             RLOGE("sendRequestStringsResponse Invalid response: NULL");
9911             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
9912         } else {
9913             char **resp = (char **) response;
9914             int numStrings = responseLen / sizeof(char *);
9915             data.resize(numStrings);
9916             for (int i = 0; i < numStrings; i++) {
9917                 data[i] = convertCharPtrToHidlString(resp[i]);
9918             }
9919         }
9920         Return<void> retStatus
9921                 = oemHookService[slotId]->mOemHookResponse->sendRequestStringsResponse(
9922                 responseInfo, data);
9923         checkReturnStatus(slotId, retStatus, false);
9924     } else {
9925         RLOGE("sendRequestStringsResponse: oemHookService[%d]->mOemHookResponse == "
9926                 "NULL", slotId);
9927     }
9928 
9929     return 0;
9930 }
9931 
setSystemSelectionChannelsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9932 int radio_1_6::setSystemSelectionChannelsResponse(int slotId, int responseType, int serial,
9933                                         RIL_Errno e, void* response, size_t responseLen) {
9934 #if VDBG
9935     RLOGD("setSystemSelectionChannelsResponse: serial %d", serial);
9936 #endif
9937     RadioResponseInfo responseInfo = {};
9938     populateResponseInfo(responseInfo, serial, responseType, e);
9939 
9940     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
9941         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
9942                 ->setSystemSelectionChannelsResponse_1_5(responseInfo);
9943         radioService[slotId]->checkReturnStatus(retStatus);
9944     } else if (radioService[slotId]->mRadioResponseV1_3 != NULL) {
9945         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_3
9946                 ->setSystemSelectionChannelsResponse(responseInfo);
9947         radioService[slotId]->checkReturnStatus(retStatus);
9948     } else {
9949         RLOGE("setSystemSelectionChannelsResponse: radioService[%d]->mRadioResponse == NULL",
9950                 slotId);
9951     }
9952 
9953     return 0;
9954 }
9955 
getSystemSelectionChannelsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9956 int radio_1_6::getSystemSelectionChannelsResponse(int slotId, int responseType, int serial,
9957                                         RIL_Errno e, void* response, size_t responseLen) {
9958 #if VDBG
9959     RLOGD("getSystemSelectionChannelsResponse: serial %d", serial);
9960 #endif
9961     V1_6::RadioResponseInfo responseInfo = {};
9962     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
9963 
9964     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
9965       hidl_vec<::android::hardware::radio::V1_5::RadioAccessSpecifier> ret;
9966       Return<void> retStatus =
9967           radioService[slotId]
9968               ->mRadioResponseV1_6->getSystemSelectionChannelsResponse(
9969                   responseInfo, ret);
9970       radioService[slotId]->checkReturnStatus(retStatus);
9971     } else {
9972         RLOGE("getSystemSelectionChannelsResponse: radioService[%d]->mRadioResponse == NULL",
9973                 slotId);
9974     }
9975 
9976     return 0;
9977 }
9978 
setSignalStrengthReportingCriteriaResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)9979 int radio_1_6::setSignalStrengthReportingCriteriaResponse(int slotId, int responseType, int serial,
9980                                         RIL_Errno e, void* response, size_t responseLen) {
9981 #if VDBG
9982     RLOGD("setSignalStrengthReportingCriteriaResponse: serial %d", serial);
9983 #endif
9984     RadioResponseInfo responseInfo = {};
9985     populateResponseInfo(responseInfo, serial, responseType, e);
9986 
9987     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
9988         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
9989                 ->setSignalStrengthReportingCriteriaResponse_1_5(responseInfo);
9990         radioService[slotId]->checkReturnStatus(retStatus);
9991     } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
9992         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2
9993                 ->setSignalStrengthReportingCriteriaResponse(responseInfo);
9994         radioService[slotId]->checkReturnStatus(retStatus);
9995     } else {
9996         RLOGE("setSignalStrengthReportingCriteriaResponse: radioService[%d]->mRadioResponse "
9997                 "== NULL", slotId);
9998     }
9999 
10000     return 0;
10001 }
10002 
setLinkCapacityReportingCriteriaResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10003 int radio_1_6::setLinkCapacityReportingCriteriaResponse(int slotId, int responseType, int serial,
10004                                         RIL_Errno e, void* response, size_t responseLen) {
10005 #if VDBG
10006     RLOGD("setLinkCapacityReportingCriteriaResponse: serial %d", serial);
10007 #endif
10008     RadioResponseInfo responseInfo = {};
10009     populateResponseInfo(responseInfo, serial, responseType, e);
10010 
10011     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10012         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
10013                 ->setLinkCapacityReportingCriteriaResponse_1_5(responseInfo);
10014         radioService[slotId]->checkReturnStatus(retStatus);
10015     } else if (radioService[slotId]->mRadioResponseV1_2 != NULL) {
10016         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_2
10017                 ->setLinkCapacityReportingCriteriaResponse(responseInfo);
10018         radioService[slotId]->checkReturnStatus(retStatus);
10019     } else {
10020         RLOGE("setLinkCapacityReportingCriteriaResponse: radioService[%d]->mRadioResponse "
10021                 "== NULL", slotId);
10022     }
10023 
10024     return 0;
10025 }
10026 
enableUiccApplicationsResponse(int slotId,int responseType,int serial,RIL_Errno e,void *,size_t responseLen)10027 int radio_1_6::enableUiccApplicationsResponse(int slotId, int responseType, int serial,
10028                                     RIL_Errno e, void* /* response */, size_t responseLen) {
10029 #if VDBG
10030     RLOGD("%s(): %d", __FUNCTION__, serial);
10031 #endif
10032     RadioResponseInfo responseInfo = {};
10033     populateResponseInfo(responseInfo, serial, responseType, e);
10034 
10035     // If we don't have a radio service, there's nothing we can do
10036     if (radioService[slotId]->mRadioResponseV1_5 == NULL) {
10037         RLOGE("%s: radioService[%d]->mRadioResponseV1_5 == NULL", __FUNCTION__, slotId);
10038         return 0;
10039     }
10040 
10041     Return<void> retStatus =
10042             radioService[slotId]->mRadioResponseV1_5->enableUiccApplicationsResponse(
10043             responseInfo);
10044     radioService[slotId]->checkReturnStatus(retStatus);
10045     return 0;
10046 }
10047 
areUiccApplicationsEnabledResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10048 int radio_1_6::areUiccApplicationsEnabledResponse(int slotId, int responseType, int serial,
10049                                         RIL_Errno e, void* response, size_t responseLen) {
10050 #if VDBG
10051     RLOGD("%s(): %d", __FUNCTION__, serial);
10052 #endif
10053     RadioResponseInfo responseInfo = {};
10054     populateResponseInfo(responseInfo, serial, responseType, e);
10055 
10056     // If we don't have a radio service, there's nothing we can do
10057     if (radioService[slotId]->mRadioResponseV1_5 == NULL) {
10058         RLOGE("%s: radioService[%d]->mRadioResponseV1_5 == NULL", __FUNCTION__, slotId);
10059         return 0;
10060     }
10061 
10062     bool enable = false;
10063     if (response == NULL || responseLen != sizeof(bool)) {
10064         RLOGE("isSimDetachedFromNetwork Invalid response.");
10065     } else {
10066         enable = (*((bool *) response));
10067     }
10068 
10069     Return<void> retStatus =
10070             radioService[slotId]->mRadioResponseV1_5->areUiccApplicationsEnabledResponse(
10071             responseInfo, enable);
10072     radioService[slotId]->checkReturnStatus(retStatus);
10073     return 0;
10074 }
10075 
getBarringInfoResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responselen)10076 int radio_1_6::getBarringInfoResponse(int slotId,
10077                               int responseType, int serial, RIL_Errno e,
10078                               void *response, size_t responselen) {
10079 #if VDBG
10080     RLOGD("getBarringInfoResponse: serial %d", serial);
10081 #endif
10082 
10083     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10084         RadioResponseInfo responseInfo = {};
10085         populateResponseInfo(responseInfo, serial, responseType, e);
10086         ::android::hardware::radio::V1_5::CellIdentity cellIdentity;
10087         hidl_vec<::android::hardware::radio::V1_5::BarringInfo> barringInfos = {};
10088 
10089         if (response == NULL) { /* data for vts */
10090             V1_5::BarringInfo barringInfo = {};
10091             barringInfo.serviceType = V1_5::BarringInfo::ServiceType::CS_SERVICE;
10092             barringInfo.barringType = V1_5::BarringInfo::BarringType::NONE;
10093 
10094             V1_5::CellIdentityLte cellIdentityLte = {};
10095             cellIdentity.lte(cellIdentityLte);
10096             barringInfos.resize(1);
10097             barringInfos[0] = barringInfo;
10098 
10099         Return<void> retStatus
10100                 = radioService[slotId]->mRadioResponseV1_5->
10101                         getBarringInfoResponse(responseInfo, cellIdentity, barringInfos);
10102         radioService[slotId]->checkReturnStatus(retStatus);
10103       } else {
10104           RLOGE("getBarringInfoResponse: radioService[%d]->mRadioResponse == NULL",
10105                   slotId);
10106       }
10107     }
10108     return 0;
10109 }
10110 
sendCdmaSmsExpectMoreResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10111 int radio_1_6::sendCdmaSmsExpectMoreResponse(int slotId, int responseType, int serial, RIL_Errno e,
10112                                              void *response, size_t responseLen) {
10113 #if VDBG
10114     RLOGD("sendCdmaSmsExpectMoreResponse: serial %d", serial);
10115 #endif
10116 
10117     if (radioService[slotId]->mRadioResponseV1_6 != NULL) {
10118         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo_1_6 = {};
10119         SendSmsResult result = makeSendSmsResult_1_6(responseInfo_1_6, serial, responseType, e,
10120                 response, responseLen);
10121 
10122         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6
10123                 ->sendCdmaSmsExpectMoreResponse_1_6(responseInfo_1_6, result);
10124         radioService[slotId]->checkReturnStatus(retStatus);
10125     } else if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10126         RadioResponseInfo responseInfo = {};
10127         SendSmsResult result = makeSendSmsResult(responseInfo, serial, responseType, e, response,
10128                 responseLen);
10129 
10130         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
10131                 ->sendCdmaSmsExpectMoreResponse(responseInfo, result);
10132         radioService[slotId]->checkReturnStatus(retStatus);
10133     } else {
10134         RLOGE("sendCdmaSmsExpectMoreResponse: radioService[%d]->mRadioResponse == NULL", slotId);
10135     }
10136 
10137     return 0;
10138 }
10139 
supplySimDepersonalizationResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10140 int radio_1_6::supplySimDepersonalizationResponse(int slotId, int responseType, int serial,
10141                                                   RIL_Errno e, void *response, size_t responseLen) {
10142 #if VDBG
10143     RLOGD("supplySimDepersonalizationResponse: serial %d", serial);
10144 #endif
10145 
10146     if (radioService[slotId]->mRadioResponseV1_5 != NULL) {
10147         RadioResponseInfo responseInfo = {};
10148         int persoType = -1, remainingRetries = -1;
10149         int numInts = responseLen / sizeof(int);
10150         if (response == NULL || numInts != 2) {
10151             RLOGE("getClirResponse Invalid response: NULL");
10152             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
10153         } else {
10154             int *pInt = (int *) response;
10155             persoType = pInt[0];
10156             remainingRetries = pInt[1];
10157         }
10158         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_5
10159                 ->supplySimDepersonalizationResponse(responseInfo, (V1_5::PersoSubstate) persoType,
10160                 remainingRetries);
10161         radioService[slotId]->checkReturnStatus(retStatus);
10162     } else {
10163         RLOGE("supplySimDepersonalizationResponse: radioService[%d]->mRadioResponseV1_5 == "
10164                 "NULL", slotId);
10165     }
10166 
10167     return 0;
10168 }
10169 
setNrDualConnectivityStateResponse(int slotId,int responseType,int serial,RIL_Errno e,void *,size_t responseLen)10170 int radio_1_6::setNrDualConnectivityStateResponse(int slotId, int responseType, int serial,
10171                                     RIL_Errno e, void* /* response */, size_t responseLen) {
10172 #if VDBG
10173     RLOGD("%s(): %d", __FUNCTION__, serial);
10174 #endif
10175     V1_6::RadioResponseInfo responseInfo = {};
10176     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10177 
10178     // If we don't have a radio service, there's nothing we can do
10179     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10180         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10181         return 0;
10182     }
10183 
10184     Return<void> retStatus =
10185             radioService[slotId]->mRadioResponseV1_6->setNrDualConnectivityStateResponse(
10186             responseInfo);
10187     radioService[slotId]->checkReturnStatus(retStatus);
10188     return 0;
10189 }
10190 
isNrDualConnectivityEnabledResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10191 int radio_1_6::isNrDualConnectivityEnabledResponse(int slotId, int responseType, int serial,
10192                                         RIL_Errno e, void* response, size_t responseLen) {
10193 #if VDBG
10194     RLOGD("%s(): %d", __FUNCTION__, serial);
10195 #endif
10196     V1_6::RadioResponseInfo responseInfo = {};
10197     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10198 
10199     // If we don't have a radio service, there's nothing we can do
10200     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10201         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10202         return 0;
10203     }
10204 
10205     bool enable = false;
10206     if (response == NULL || responseLen != sizeof(bool)) {
10207         RLOGE("isNrDualConnectivityEnabledResponseInvalid response.");
10208     } else {
10209         enable = (*((bool *) response));
10210     }
10211 
10212     Return<void> retStatus =
10213             radioService[slotId]->mRadioResponseV1_6->isNrDualConnectivityEnabledResponse(
10214             responseInfo, enable);
10215     radioService[slotId]->checkReturnStatus(retStatus);
10216     return 0;
10217 }
10218 
allocatePduSessionIdResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10219 int radio_1_6::allocatePduSessionIdResponse(int slotId, int responseType, int serial,
10220                                         RIL_Errno e, void* response, size_t responseLen) {
10221 #if VDBG
10222     RLOGD("%s(): %d", __FUNCTION__, serial);
10223 #endif
10224     // If we don't have a radio service, there's nothing we can do
10225     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10226       RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10227       return 0;
10228     }
10229     V1_6::RadioResponseInfo responseInfo = {};
10230     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10231 
10232     Return<void> retStatus =
10233             radioService[slotId]->mRadioResponseV1_6->allocatePduSessionIdResponse(responseInfo, -1);
10234     radioService[slotId]->checkReturnStatus(retStatus);
10235     return 0;
10236 }
10237 
releasePduSessionIdResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10238 int radio_1_6::releasePduSessionIdResponse(int slotId, int responseType, int serial,
10239                                         RIL_Errno e, void* response, size_t responseLen) {
10240 #if VDBG
10241     RLOGD("%s(): %d", __FUNCTION__, serial);
10242 #endif
10243     // If we don't have a radio service, there's nothing we can do
10244     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10245         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10246         return 0;
10247     }
10248 
10249     V1_6::RadioResponseInfo responseInfo = {};
10250     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10251 
10252     Return<void> retStatus =
10253             radioService[slotId]->mRadioResponseV1_6->releasePduSessionIdResponse(responseInfo);
10254     radioService[slotId]->checkReturnStatus(retStatus);
10255     return 0;
10256 }
10257 
startHandoverResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10258 int radio_1_6::startHandoverResponse(int slotId, int responseType, int serial,
10259                                         RIL_Errno e, void* response, size_t responseLen) {
10260     // If we don't have a radio service, there's nothing we can do
10261     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10262         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10263         return 0;
10264     }
10265     V1_6::RadioResponseInfo responseInfo = {};
10266     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10267 
10268     Return<void> retStatus =
10269             radioService[slotId]->mRadioResponseV1_6->startHandoverResponse(responseInfo);
10270 
10271 #if VDBG
10272     RLOGD("%s(): %d", __FUNCTION__, serial);
10273 #endif
10274     return 0;
10275 }
10276 
cancelHandoverResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10277 int radio_1_6::cancelHandoverResponse(int slotId, int responseType, int serial,
10278                                         RIL_Errno e, void* response, size_t responseLen) {
10279     // If we don't have a radio service, there's nothing we can do
10280     if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10281         RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10282         return 0;
10283     }
10284     V1_6::RadioResponseInfo responseInfo = {};
10285     populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10286 
10287     Return<void> retStatus =
10288             radioService[slotId]->mRadioResponseV1_6->cancelHandoverResponse(responseInfo);
10289 
10290 #if VDBG
10291     RLOGD("%s(): %d", __FUNCTION__, serial);
10292 #endif
10293     return 0;
10294 }
10295 
10296 
setDataThrottlingResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responselen)10297 int radio_1_6::setDataThrottlingResponse(int slotId, int responseType,
10298                    int serial, RIL_Errno e, void *response, size_t responselen) {
10299 #if VDBG
10300     RLOGD("setDataThrottlingResponse: serial %d", serial);
10301 #endif
10302 
10303    if (radioService[slotId]->mRadioResponseV1_6 == NULL) {
10304        RLOGE("%s: radioService[%d]->mRadioResponseV1_6 == NULL", __FUNCTION__, slotId);
10305        return 0;
10306    }
10307 
10308    V1_6::RadioResponseInfo responseInfo = {};
10309    populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10310 
10311 
10312    Return<void> retstatus =
10313         radioService[slotId]->mRadioResponseV1_6->setDataThrottlingResponse(
10314                     responseInfo);
10315    radioService[slotId]->checkReturnStatus(retstatus);
10316    return 0;
10317 }
10318 
getSlicingConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10319 int radio_1_6::getSlicingConfigResponse(int slotId, int responseType, int serial,
10320                                         RIL_Errno e, void* response, size_t responseLen) {
10321 #if VDBG
10322     RLOGD("getSlicingConfigResponse: serial %d", serial);
10323 #endif
10324 
10325     if (radioService[slotId]->mRadioResponse != NULL) {
10326         V1_6::RadioResponseInfo responseInfo = {};
10327         populateResponseInfo_1_6(responseInfo, serial, responseType, e);
10328 
10329         V1_6::SlicingConfig slicingConfig = {};
10330         Return<void> retStatus = radioService[slotId]->mRadioResponseV1_6->
10331                 getSlicingConfigResponse(responseInfo, slicingConfig);
10332         radioService[slotId]->checkReturnStatus(retStatus);
10333     } else {
10334         RLOGE("getSlicingConfigResponse: radioService[%d]->mRadioResponse == NULL", slotId);
10335     }
10336 
10337     return 0;
10338 }
10339 
getSimPhonebookRecordsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10340 int radio_1_6::getSimPhonebookRecordsResponse(int slotId, int responseType, int serial,
10341                              RIL_Errno e, void *response, size_t responseLen) {
10342 #if VDBG
10343     RLOGD("getSimPhonebookRecordsResponse: serial %d", serial);
10344 #endif
10345     return 0;
10346 }
10347 
getSimPhonebookCapacityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10348 int radio_1_6::getSimPhonebookCapacityResponse(int slotId, int responseType, int serial,
10349                              RIL_Errno e, void *response, size_t responseLen) {
10350 #if VDBG
10351     RLOGD("getSimPhonebookRecordsResponse: serial %d", serial);
10352 #endif
10353     return 0;
10354 }
10355 
updateSimPhonebookRecordsResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)10356 int radio_1_6::updateSimPhonebookRecordsResponse(int slotId, int responseType, int serial,
10357                              RIL_Errno e, void *response, size_t responseLen) {
10358 #if VDBG
10359     RLOGD("getSimPhonebookRecordsResponse: serial %d", serial);
10360 #endif
10361     return 0;
10362 }
10363 
10364 /***************************************************************************************************
10365  * INDICATION FUNCTIONS
10366  * The below function handle unsolicited messages coming from the Radio
10367  * (messages for which there is no pending request)
10368  **************************************************************************************************/
10369 
convertIntToRadioIndicationType(int indicationType)10370 RadioIndicationType convertIntToRadioIndicationType(int indicationType) {
10371     return indicationType == RESPONSE_UNSOLICITED ? (RadioIndicationType::UNSOLICITED) :
10372             (RadioIndicationType::UNSOLICITED_ACK_EXP);
10373 }
10374 
radioStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10375 int radio_1_6::radioStateChangedInd(int slotId,
10376                                  int indicationType, int token, RIL_Errno e, void *response,
10377                                  size_t responseLen) {
10378     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10379         RadioState radioState =
10380                 (RadioState) CALL_ONSTATEREQUEST(slotId);
10381         RLOGD("radioStateChangedInd: radioState %d", radioState);
10382         Return<void> retStatus = radioService[slotId]->mRadioIndication->radioStateChanged(
10383                 convertIntToRadioIndicationType(indicationType), radioState);
10384         radioService[slotId]->checkReturnStatus(retStatus);
10385     } else {
10386         RLOGE("radioStateChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
10387     }
10388 
10389     return 0;
10390 }
10391 
callStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10392 int radio_1_6::callStateChangedInd(int slotId,
10393                                int indicationType, int token, RIL_Errno e, void *response,
10394                                size_t responseLen) {
10395     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10396 #if VDBG
10397         RLOGD("callStateChangedInd");
10398 #endif
10399         Return<void> retStatus = radioService[slotId]->mRadioIndication->callStateChanged(
10400                 convertIntToRadioIndicationType(indicationType));
10401         radioService[slotId]->checkReturnStatus(retStatus);
10402     } else {
10403         RLOGE("callStateChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
10404     }
10405 
10406     return 0;
10407 }
10408 
networkStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10409 int radio_1_6::networkStateChangedInd(int slotId,
10410                                   int indicationType, int token, RIL_Errno e, void *response,
10411                                   size_t responseLen) {
10412     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10413 #if VDBG
10414         RLOGD("networkStateChangedInd");
10415 #endif
10416         Return<void> retStatus = radioService[slotId]->mRadioIndication->networkStateChanged(
10417                 convertIntToRadioIndicationType(indicationType));
10418         radioService[slotId]->checkReturnStatus(retStatus);
10419     } else {
10420         RLOGE("networkStateChangedInd: radioService[%d]->mRadioIndication == NULL",
10421                 slotId);
10422     }
10423 
10424     return 0;
10425 }
10426 
hexCharToInt(uint8_t c)10427 extern "C" uint8_t hexCharToInt(uint8_t c) {
10428     if (c >= '0' && c <= '9') return (c - '0');
10429     if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
10430     if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
10431 
10432     return INVALID_HEX_CHAR;
10433 }
10434 
convertHexStringToBytes(void * response,size_t responseLen)10435 extern "C" uint8_t * convertHexStringToBytes(void *response, size_t responseLen) {
10436     if (responseLen % 2 != 0) {
10437         return NULL;
10438     }
10439 
10440     uint8_t *bytes = (uint8_t *)calloc(responseLen/2, sizeof(uint8_t));
10441     if (bytes == NULL) {
10442         RLOGE("convertHexStringToBytes: cannot allocate memory for bytes string");
10443         return NULL;
10444     }
10445     uint8_t *hexString = (uint8_t *)response;
10446 
10447     for (size_t i = 0; i < responseLen; i += 2) {
10448         uint8_t hexChar1 = hexCharToInt(hexString[i]);
10449         uint8_t hexChar2 = hexCharToInt(hexString[i + 1]);
10450 
10451         if (hexChar1 == INVALID_HEX_CHAR || hexChar2 == INVALID_HEX_CHAR) {
10452             RLOGE("convertHexStringToBytes: invalid hex char %d %d",
10453                     hexString[i], hexString[i + 1]);
10454             free(bytes);
10455             return NULL;
10456         }
10457         bytes[i/2] = ((hexChar1 << 4) | hexChar2);
10458     }
10459 
10460     return bytes;
10461 }
10462 
newSmsInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10463 int radio_1_6::newSmsInd(int slotId, int indicationType,
10464                      int token, RIL_Errno e, void *response, size_t responseLen) {
10465     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10466         if (response == NULL || responseLen == 0) {
10467             RLOGE("newSmsInd: invalid response");
10468             return 0;
10469         }
10470 
10471         uint8_t *bytes = convertHexStringToBytes(response, responseLen);
10472         if (bytes == NULL) {
10473             RLOGE("newSmsInd: convertHexStringToBytes failed");
10474             return 0;
10475         }
10476 
10477         hidl_vec<uint8_t> pdu;
10478         pdu.setToExternal(bytes, responseLen/2);
10479 #if VDBG
10480         RLOGD("newSmsInd");
10481 #endif
10482         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSms(
10483                 convertIntToRadioIndicationType(indicationType), pdu);
10484         radioService[slotId]->checkReturnStatus(retStatus);
10485         free(bytes);
10486     } else {
10487         RLOGE("newSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
10488     }
10489 
10490     return 0;
10491 }
10492 
newSmsStatusReportInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10493 int radio_1_6::newSmsStatusReportInd(int slotId,
10494                                  int indicationType, int token, RIL_Errno e, void *response,
10495                                  size_t responseLen) {
10496     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10497         if (response == NULL || responseLen == 0) {
10498             RLOGE("newSmsStatusReportInd: invalid response");
10499             return 0;
10500         }
10501 
10502         uint8_t *bytes = convertHexStringToBytes(response, responseLen);
10503         if (bytes == NULL) {
10504             RLOGE("newSmsStatusReportInd: convertHexStringToBytes failed");
10505             return 0;
10506         }
10507 
10508         hidl_vec<uint8_t> pdu;
10509         pdu.setToExternal(bytes, responseLen/2);
10510 #if VDBG
10511         RLOGD("newSmsStatusReportInd");
10512 #endif
10513         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSmsStatusReport(
10514                 convertIntToRadioIndicationType(indicationType), pdu);
10515         radioService[slotId]->checkReturnStatus(retStatus);
10516         free(bytes);
10517     } else {
10518         RLOGE("newSmsStatusReportInd: radioService[%d]->mRadioIndication == NULL", slotId);
10519     }
10520 
10521     return 0;
10522 }
10523 
newSmsOnSimInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10524 int radio_1_6::newSmsOnSimInd(int slotId, int indicationType,
10525                           int token, RIL_Errno e, void *response, size_t responseLen) {
10526     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10527         if (response == NULL || responseLen != sizeof(int)) {
10528             RLOGE("newSmsOnSimInd: invalid response");
10529             return 0;
10530         }
10531         int32_t recordNumber = ((int32_t *) response)[0];
10532 #if VDBG
10533         RLOGD("newSmsOnSimInd: slotIndex %d", recordNumber);
10534 #endif
10535         Return<void> retStatus = radioService[slotId]->mRadioIndication->newSmsOnSim(
10536                 convertIntToRadioIndicationType(indicationType), recordNumber);
10537         radioService[slotId]->checkReturnStatus(retStatus);
10538     } else {
10539         RLOGE("newSmsOnSimInd: radioService[%d]->mRadioIndication == NULL", slotId);
10540     }
10541 
10542     return 0;
10543 }
10544 
onUssdInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10545 int radio_1_6::onUssdInd(int slotId, int indicationType,
10546                      int token, RIL_Errno e, void *response, size_t responseLen) {
10547     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10548         if (response == NULL || responseLen != 2 * sizeof(char *)) {
10549             RLOGE("onUssdInd: invalid response");
10550             return 0;
10551         }
10552         char **strings = (char **) response;
10553         char *mode = strings[0];
10554         hidl_string msg = convertCharPtrToHidlString(strings[1]);
10555         UssdModeType modeType = (UssdModeType) atoi(mode);
10556 #if VDBG
10557         RLOGD("onUssdInd: mode %s", mode);
10558 #endif
10559         Return<void> retStatus = radioService[slotId]->mRadioIndication->onUssd(
10560                 convertIntToRadioIndicationType(indicationType), modeType, msg);
10561         radioService[slotId]->checkReturnStatus(retStatus);
10562     } else {
10563         RLOGE("onUssdInd: radioService[%d]->mRadioIndication == NULL", slotId);
10564     }
10565 
10566     return 0;
10567 }
10568 
nitzTimeReceivedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10569 int radio_1_6::nitzTimeReceivedInd(int slotId,
10570                                int indicationType, int token, RIL_Errno e, void *response,
10571                                size_t responseLen) {
10572     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10573         if (response == NULL || responseLen == 0) {
10574             RLOGE("nitzTimeReceivedInd: invalid response");
10575             return 0;
10576         }
10577         hidl_string nitzTime = convertCharPtrToHidlString((char *) response);
10578 #if VDBG
10579         RLOGD("nitzTimeReceivedInd: nitzTime %s receivedTime %" PRId64, nitzTime.c_str(),
10580                 nitzTimeReceived[slotId]);
10581 #endif
10582         Return<void> retStatus = radioService[slotId]->mRadioIndication->nitzTimeReceived(
10583                 convertIntToRadioIndicationType(indicationType), nitzTime,
10584                 nitzTimeReceived[slotId]);
10585         radioService[slotId]->checkReturnStatus(retStatus);
10586     } else {
10587         RLOGE("nitzTimeReceivedInd: radioService[%d]->mRadioIndication == NULL", slotId);
10588         return -1;
10589     }
10590 
10591     return 0;
10592 }
10593 
convertRilSignalStrengthToHal(void * response,size_t responseLen,SignalStrength & signalStrength)10594 void convertRilSignalStrengthToHal(void *response, size_t responseLen,
10595         SignalStrength& signalStrength) {
10596     RIL_SignalStrength_v12 *rilSignalStrength = (RIL_SignalStrength_v12 *) response;
10597 
10598     // Fixup LTE for backwards compatibility
10599     // signalStrength: -1 -> 99
10600     if (rilSignalStrength->LTE_SignalStrength.signalStrength == -1) {
10601         rilSignalStrength->LTE_SignalStrength.signalStrength = 99;
10602     }
10603     // rsrp: -1 -> INT_MAX all other negative value to positive.
10604     // So remap here
10605     if (rilSignalStrength->LTE_SignalStrength.rsrp == -1) {
10606         rilSignalStrength->LTE_SignalStrength.rsrp = INT_MAX;
10607     } else if (rilSignalStrength->LTE_SignalStrength.rsrp < -1) {
10608         rilSignalStrength->LTE_SignalStrength.rsrp = -rilSignalStrength->LTE_SignalStrength.rsrp;
10609     }
10610     // rsrq: -1 -> INT_MAX
10611     if (rilSignalStrength->LTE_SignalStrength.rsrq == -1) {
10612         rilSignalStrength->LTE_SignalStrength.rsrq = INT_MAX;
10613     }
10614     // Not remapping rssnr is already using INT_MAX
10615     // cqi: -1 -> INT_MAX
10616     if (rilSignalStrength->LTE_SignalStrength.cqi == -1) {
10617         rilSignalStrength->LTE_SignalStrength.cqi = INT_MAX;
10618     }
10619 
10620     signalStrength.gw.signalStrength = rilSignalStrength->GW_SignalStrength.signalStrength;
10621     signalStrength.gw.bitErrorRate = rilSignalStrength->GW_SignalStrength.bitErrorRate;
10622     // RIL_SignalStrength_v10 not support gw.timingAdvance. Set to INT_MAX as
10623     // invalid value.
10624     signalStrength.gw.timingAdvance = INT_MAX;
10625 
10626     signalStrength.cdma.dbm = rilSignalStrength->CDMA_SignalStrength.dbm;
10627     signalStrength.cdma.ecio = rilSignalStrength->CDMA_SignalStrength.ecio;
10628     signalStrength.evdo.dbm = rilSignalStrength->EVDO_SignalStrength.dbm;
10629     signalStrength.evdo.ecio = rilSignalStrength->EVDO_SignalStrength.ecio;
10630     signalStrength.evdo.signalNoiseRatio =
10631             rilSignalStrength->EVDO_SignalStrength.signalNoiseRatio;
10632     signalStrength.lte.signalStrength = rilSignalStrength->LTE_SignalStrength.signalStrength;
10633     signalStrength.lte.rsrp = rilSignalStrength->LTE_SignalStrength.rsrp;
10634     signalStrength.lte.rsrq = rilSignalStrength->LTE_SignalStrength.rsrq;
10635     signalStrength.lte.rssnr = rilSignalStrength->LTE_SignalStrength.rssnr;
10636     signalStrength.lte.cqi = rilSignalStrength->LTE_SignalStrength.cqi;
10637     signalStrength.lte.timingAdvance = rilSignalStrength->LTE_SignalStrength.timingAdvance;
10638     signalStrength.tdScdma.rscp = rilSignalStrength->TD_SCDMA_SignalStrength.rscp;
10639 }
10640 
convertRilSignalStrengthToHal_1_4(void * response,size_t responseLen,V1_4::SignalStrength & signalStrength_1_4)10641 void convertRilSignalStrengthToHal_1_4(void *response, size_t responseLen,
10642         V1_4::SignalStrength& signalStrength_1_4) {
10643     SignalStrength signalStrength = {};
10644     convertRilSignalStrengthToHal(response, responseLen, signalStrength);
10645     signalStrength_1_4.gsm = signalStrength.gw;
10646     signalStrength_1_4.cdma = signalStrength.cdma;
10647     signalStrength_1_4.evdo = signalStrength.evdo;
10648     signalStrength_1_4.lte = signalStrength.lte;
10649 
10650     RIL_SignalStrength_v12 *rilSignalStrength = (RIL_SignalStrength_v12 *) response;
10651     signalStrength_1_4.wcdma.base.signalStrength =
10652         rilSignalStrength->WCDMA_SignalStrength.signalStrength;
10653     signalStrength_1_4.wcdma.base.bitErrorRate =
10654         rilSignalStrength->WCDMA_SignalStrength.bitErrorRate;
10655     signalStrength_1_4.wcdma.rscp = INT_MAX;
10656     signalStrength_1_4.wcdma.ecno = INT_MAX;
10657 
10658     signalStrength_1_4.tdscdma.signalStrength = INT_MAX;
10659     signalStrength_1_4.tdscdma.bitErrorRate = INT_MAX;
10660     signalStrength_1_4.tdscdma.rscp = INT_MAX;
10661 
10662     signalStrength_1_4.nr.ssRsrp = rilSignalStrength->NR_SignalStrength.ssRsrp;
10663     signalStrength_1_4.nr.ssRsrq = rilSignalStrength->NR_SignalStrength.ssRsrq;
10664     signalStrength_1_4.nr.ssSinr = rilSignalStrength->NR_SignalStrength.ssSinr;
10665     signalStrength_1_4.nr.csiRsrp = rilSignalStrength->NR_SignalStrength.csiRsrp;
10666     signalStrength_1_4.nr.csiRsrq = rilSignalStrength->NR_SignalStrength.csiRsrq;
10667     signalStrength_1_4.nr.csiSinr = rilSignalStrength->NR_SignalStrength.ssSinr;
10668 }
10669 
currentSignalStrengthInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10670 int radio_1_6::currentSignalStrengthInd(int slotId,
10671                                     int indicationType, int token, RIL_Errno e,
10672                                     void *response, size_t responseLen) {
10673     if (radioService[slotId] != NULL &&
10674        (radioService[slotId]->mRadioIndication != NULL ||
10675         radioService[slotId]->mRadioIndicationV1_4 != NULL)) {
10676         if (response == NULL || responseLen != sizeof(RIL_SignalStrength_v12)) {
10677             RLOGE("currentSignalStrengthInd: invalid response");
10678             return 0;
10679         }
10680 
10681 #if VDBG
10682         RLOGD("currentSignalStrengthInd");
10683 #endif
10684         Return<void> retStatus;
10685         if (radioService[slotId]->mRadioIndicationV1_4 != NULL) {
10686           V1_4::SignalStrength signalStrength_1_4 = {};
10687           convertRilSignalStrengthToHal_1_4(response, responseLen, signalStrength_1_4);
10688           retStatus = radioService[slotId]->mRadioIndicationV1_4->currentSignalStrength_1_4(
10689                           convertIntToRadioIndicationType(indicationType), signalStrength_1_4);
10690         } else {
10691           SignalStrength signalStrength = {};
10692           convertRilSignalStrengthToHal(response, responseLen, signalStrength);
10693           retStatus = radioService[slotId]->mRadioIndication->currentSignalStrength(
10694                           convertIntToRadioIndicationType(indicationType), signalStrength);
10695         }
10696         radioService[slotId]->checkReturnStatus(retStatus);
10697     } else {
10698         RLOGE("currentSignalStrengthInd: radioService[%d]->mRadioIndication == NULL",
10699                 slotId);
10700     }
10701 
10702     return 0;
10703 }
10704 
convertRilDataCallToHal(RIL_Data_Call_Response_v11 * dcResponse,SetupDataCallResult & dcResult)10705 void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse,
10706         SetupDataCallResult& dcResult) {
10707     dcResult.status = (DataCallFailCause) dcResponse->status;
10708     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
10709     dcResult.cid = dcResponse->cid;
10710     dcResult.active = dcResponse->active;
10711     dcResult.type = convertCharPtrToHidlString(dcResponse->type);
10712     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
10713     dcResult.addresses = convertCharPtrToHidlString(dcResponse->addresses);
10714     dcResult.dnses = convertCharPtrToHidlString(dcResponse->dnses);
10715     dcResult.gateways = convertCharPtrToHidlString(dcResponse->gateways);
10716     dcResult.pcscf = convertCharPtrToHidlString(dcResponse->pcscf);
10717     dcResult.mtu = dcResponse->mtu;
10718 }
10719 
split(hidl_string str)10720 hidl_vec<hidl_string> split(hidl_string str) {
10721     std::vector<hidl_string> ret;
10722     std::stringstream ss(static_cast<std::string>(str));
10723 
10724     std::string tok;
10725 
10726     while(getline(ss, tok, ' ')) {
10727         ret.push_back(hidl_string(tok));
10728     }
10729 
10730     return ret;
10731 }
10732 
convertToPdpProtocolType(hidl_string str)10733 ::android::hardware::radio::V1_4::PdpProtocolType convertToPdpProtocolType(hidl_string str) {
10734     if (strncmp("IP", str.c_str(), 2) == 0) {
10735         return ::android::hardware::radio::V1_4::PdpProtocolType::IP;
10736     } else if (strncmp("IPV6", str.c_str(), 4) == 0) {
10737         return ::android::hardware::radio::V1_4::PdpProtocolType::IPV6;
10738     } else if (strncmp("IPV4V6", str.c_str(), 6) == 0) {
10739         return ::android::hardware::radio::V1_4::PdpProtocolType::IPV4V6;
10740     } else if (strncmp("PPP", str.c_str(), 3) == 0) {
10741         return ::android::hardware::radio::V1_4::PdpProtocolType::PPP;
10742     } else if (strncmp("NON_IP", str.c_str(), 6) == 0) {
10743         return ::android::hardware::radio::V1_4::PdpProtocolType::NON_IP;
10744     } else if (strncmp("UNSTRUCTURED", str.c_str(), 12) == 0) {
10745         return ::android::hardware::radio::V1_4::PdpProtocolType::UNSTRUCTURED;
10746     } else {
10747         return ::android::hardware::radio::V1_4::PdpProtocolType::UNKNOWN;
10748     }
10749 }
10750 
convertRilDataCallToHal(RIL_Data_Call_Response_v11 * dcResponse,::android::hardware::radio::V1_4::SetupDataCallResult & dcResult)10751 void convertRilDataCallToHal(RIL_Data_Call_Response_v11 *dcResponse,
10752         ::android::hardware::radio::V1_4::SetupDataCallResult& dcResult) {
10753     dcResult.cause = (::android::hardware::radio::V1_4::DataCallFailCause) dcResponse->status;
10754     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
10755     dcResult.cid = dcResponse->cid;
10756     dcResult.active = (::android::hardware::radio::V1_4::DataConnActiveStatus)dcResponse->active;
10757     dcResult.type = convertToPdpProtocolType(convertCharPtrToHidlString(dcResponse->type));
10758     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
10759     dcResult.addresses = split(convertCharPtrToHidlString(dcResponse->addresses));
10760     dcResult.dnses = split(convertCharPtrToHidlString(dcResponse->dnses));
10761     dcResult.gateways = split(convertCharPtrToHidlString(dcResponse->gateways));
10762     dcResult.pcscf = split(convertCharPtrToHidlString(dcResponse->pcscf));
10763     dcResult.mtu = dcResponse->mtu;
10764 }
10765 
convertRilDataCallToHal(RIL_Data_Call_Response_v12 * dcResponse,::android::hardware::radio::V1_5::SetupDataCallResult & dcResult)10766 void convertRilDataCallToHal(RIL_Data_Call_Response_v12 *dcResponse,
10767         ::android::hardware::radio::V1_5::SetupDataCallResult& dcResult) {
10768     dcResult.cause = (::android::hardware::radio::V1_4::DataCallFailCause) dcResponse->status;
10769     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
10770     dcResult.cid = dcResponse->cid;
10771     dcResult.active = (::android::hardware::radio::V1_4::DataConnActiveStatus)dcResponse->active;
10772     dcResult.type = convertToPdpProtocolType(convertCharPtrToHidlString(dcResponse->type));
10773     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
10774 
10775     std::vector<::android::hardware::radio::V1_5::LinkAddress> linkAddresses;
10776     std::stringstream ss(static_cast<std::string>(dcResponse->addresses));
10777     std::string tok;
10778     while(getline(ss, tok, ' ')) {
10779         ::android::hardware::radio::V1_5::LinkAddress la;
10780         la.address = hidl_string(tok);
10781         la.properties = 0;
10782         la.deprecationTime = 0;
10783         la.expirationTime = 0;
10784         linkAddresses.push_back(la);
10785     }
10786 
10787     dcResult.addresses = linkAddresses;
10788     dcResult.dnses = split(convertCharPtrToHidlString(dcResponse->dnses));
10789     dcResult.gateways = split(convertCharPtrToHidlString(dcResponse->gateways));
10790     dcResult.pcscf = split(convertCharPtrToHidlString(dcResponse->pcscf));
10791     dcResult.mtuV4 = dcResponse->mtuV4;
10792     dcResult.mtuV6 = dcResponse->mtuV6;
10793 }
10794 
convertRilDataCallToHal(RIL_Data_Call_Response_v12 * dcResponse,::android::hardware::radio::V1_6::SetupDataCallResult & dcResult)10795 void convertRilDataCallToHal(RIL_Data_Call_Response_v12 *dcResponse,
10796         ::android::hardware::radio::V1_6::SetupDataCallResult& dcResult) {
10797     dcResult.cause = (::android::hardware::radio::V1_6::DataCallFailCause) dcResponse->status;
10798     dcResult.suggestedRetryTime = dcResponse->suggestedRetryTime;
10799     dcResult.cid = dcResponse->cid;
10800     dcResult.active = (::android::hardware::radio::V1_4::DataConnActiveStatus)dcResponse->active;
10801     dcResult.type = convertToPdpProtocolType(convertCharPtrToHidlString(dcResponse->type));
10802     dcResult.ifname = convertCharPtrToHidlString(dcResponse->ifname);
10803 
10804     std::vector<::android::hardware::radio::V1_5::LinkAddress> linkAddresses;
10805     std::stringstream ss(static_cast<std::string>(dcResponse->addresses));
10806     std::string tok;
10807     while(getline(ss, tok, ' ')) {
10808         ::android::hardware::radio::V1_5::LinkAddress la;
10809         la.address = hidl_string(tok);
10810         la.properties = 0;
10811         la.deprecationTime = 0;
10812         la.expirationTime = 0;
10813         linkAddresses.push_back(la);
10814     }
10815 
10816     dcResult.addresses = linkAddresses;
10817     dcResult.dnses = split(convertCharPtrToHidlString(dcResponse->dnses));
10818     dcResult.gateways = split(convertCharPtrToHidlString(dcResponse->gateways));
10819     dcResult.pcscf = split(convertCharPtrToHidlString(dcResponse->pcscf));
10820     dcResult.mtuV4 = dcResponse->mtuV4;
10821     dcResult.mtuV6 = dcResponse->mtuV6;
10822 
10823     std::vector<::android::hardware::radio::V1_6::TrafficDescriptor> trafficDescriptors;
10824     ::android::hardware::radio::V1_6::TrafficDescriptor trafficDescriptor;
10825     ::android::hardware::radio::V1_6::OsAppId osAppId;
10826 
10827     osAppId.osAppId = 1;
10828     trafficDescriptor.osAppId.value(osAppId);
10829     trafficDescriptors.push_back(trafficDescriptor);
10830     dcResult.trafficDescriptors = trafficDescriptors;
10831 }
10832 
convertRilDataCallListToHal(void * response,size_t responseLen,hidl_vec<SetupDataCallResult> & dcResultList)10833 void convertRilDataCallListToHal(void *response, size_t responseLen,
10834         hidl_vec<SetupDataCallResult>& dcResultList) {
10835     int num = responseLen / sizeof(RIL_Data_Call_Response_v11);
10836 
10837     RIL_Data_Call_Response_v11 *dcResponse = (RIL_Data_Call_Response_v11 *) response;
10838     dcResultList.resize(num);
10839     for (int i = 0; i < num; i++) {
10840         convertRilDataCallToHal(&dcResponse[i], dcResultList[i]);
10841     }
10842 }
10843 
dataCallListChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10844 int radio_1_6::dataCallListChangedInd(int slotId,
10845                                   int indicationType, int token, RIL_Errno e, void *response,
10846                                   size_t responseLen) {
10847     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10848         if ((response == NULL && responseLen != 0)
10849                 || responseLen % sizeof(RIL_Data_Call_Response_v11) != 0) {
10850             RLOGE("dataCallListChangedInd: invalid response");
10851             return 0;
10852         }
10853         hidl_vec<SetupDataCallResult> dcList;
10854         convertRilDataCallListToHal(response, responseLen, dcList);
10855 #if VDBG
10856         RLOGD("dataCallListChangedInd");
10857 #endif
10858         Return<void> retStatus = radioService[slotId]->mRadioIndication->dataCallListChanged(
10859                 convertIntToRadioIndicationType(indicationType), dcList);
10860         radioService[slotId]->checkReturnStatus(retStatus);
10861     } else {
10862         RLOGE("dataCallListChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
10863     }
10864 
10865     return 0;
10866 }
10867 
suppSvcNotifyInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10868 int radio_1_6::suppSvcNotifyInd(int slotId, int indicationType,
10869                             int token, RIL_Errno e, void *response, size_t responseLen) {
10870     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10871         if (response == NULL || responseLen != sizeof(RIL_SuppSvcNotification)) {
10872             RLOGE("suppSvcNotifyInd: invalid response");
10873             return 0;
10874         }
10875 
10876         SuppSvcNotification suppSvc = {};
10877         RIL_SuppSvcNotification *ssn = (RIL_SuppSvcNotification *) response;
10878         suppSvc.isMT = ssn->notificationType;
10879         suppSvc.code = ssn->code;
10880         suppSvc.index = ssn->index;
10881         suppSvc.type = ssn->type;
10882         suppSvc.number = convertCharPtrToHidlString(ssn->number);
10883 
10884 #if VDBG
10885         RLOGD("suppSvcNotifyInd: isMT %d code %d index %d type %d",
10886                 suppSvc.isMT, suppSvc.code, suppSvc.index, suppSvc.type);
10887 #endif
10888         Return<void> retStatus = radioService[slotId]->mRadioIndication->suppSvcNotify(
10889                 convertIntToRadioIndicationType(indicationType), suppSvc);
10890         radioService[slotId]->checkReturnStatus(retStatus);
10891     } else {
10892         RLOGE("suppSvcNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
10893     }
10894 
10895     return 0;
10896 }
10897 
stkSessionEndInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10898 int radio_1_6::stkSessionEndInd(int slotId, int indicationType,
10899                             int token, RIL_Errno e, void *response, size_t responseLen) {
10900     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10901 #if VDBG
10902         RLOGD("stkSessionEndInd");
10903 #endif
10904         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkSessionEnd(
10905                 convertIntToRadioIndicationType(indicationType));
10906         radioService[slotId]->checkReturnStatus(retStatus);
10907     } else {
10908         RLOGE("stkSessionEndInd: radioService[%d]->mRadioIndication == NULL", slotId);
10909     }
10910 
10911     return 0;
10912 }
10913 
stkProactiveCommandInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10914 int radio_1_6::stkProactiveCommandInd(int slotId,
10915                                   int indicationType, int token, RIL_Errno e, void *response,
10916                                   size_t responseLen) {
10917     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10918         if (response == NULL || responseLen == 0) {
10919             RLOGE("stkProactiveCommandInd: invalid response");
10920             return 0;
10921         }
10922 #if VDBG
10923         RLOGD("stkProactiveCommandInd");
10924 #endif
10925         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkProactiveCommand(
10926                 convertIntToRadioIndicationType(indicationType),
10927                 convertCharPtrToHidlString((char *) response));
10928         radioService[slotId]->checkReturnStatus(retStatus);
10929     } else {
10930         RLOGE("stkProactiveCommandInd: radioService[%d]->mRadioIndication == NULL", slotId);
10931     }
10932 
10933     return 0;
10934 }
10935 
stkEventNotifyInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10936 int radio_1_6::stkEventNotifyInd(int slotId, int indicationType,
10937                              int token, RIL_Errno e, void *response, size_t responseLen) {
10938     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10939         if (response == NULL || responseLen == 0) {
10940             RLOGE("stkEventNotifyInd: invalid response");
10941             return 0;
10942         }
10943 #if VDBG
10944         RLOGD("stkEventNotifyInd");
10945 #endif
10946         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkEventNotify(
10947                 convertIntToRadioIndicationType(indicationType),
10948                 convertCharPtrToHidlString((char *) response));
10949         radioService[slotId]->checkReturnStatus(retStatus);
10950     } else {
10951         RLOGE("stkEventNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
10952     }
10953 
10954     return 0;
10955 }
10956 
stkCallSetupInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10957 int radio_1_6::stkCallSetupInd(int slotId, int indicationType,
10958                            int token, RIL_Errno e, void *response, size_t responseLen) {
10959     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10960         if (response == NULL || responseLen != sizeof(int)) {
10961             RLOGE("stkCallSetupInd: invalid response");
10962             return 0;
10963         }
10964         int32_t timeout = ((int32_t *) response)[0];
10965 #if VDBG
10966         RLOGD("stkCallSetupInd: timeout %d", timeout);
10967 #endif
10968         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkCallSetup(
10969                 convertIntToRadioIndicationType(indicationType), timeout);
10970         radioService[slotId]->checkReturnStatus(retStatus);
10971     } else {
10972         RLOGE("stkCallSetupInd: radioService[%d]->mRadioIndication == NULL", slotId);
10973     }
10974 
10975     return 0;
10976 }
10977 
simSmsStorageFullInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10978 int radio_1_6::simSmsStorageFullInd(int slotId,
10979                                 int indicationType, int token, RIL_Errno e, void *response,
10980                                 size_t responseLen) {
10981     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10982 #if VDBG
10983         RLOGD("simSmsStorageFullInd");
10984 #endif
10985         Return<void> retStatus = radioService[slotId]->mRadioIndication->simSmsStorageFull(
10986                 convertIntToRadioIndicationType(indicationType));
10987         radioService[slotId]->checkReturnStatus(retStatus);
10988     } else {
10989         RLOGE("simSmsStorageFullInd: radioService[%d]->mRadioIndication == NULL", slotId);
10990     }
10991 
10992     return 0;
10993 }
10994 
simRefreshInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)10995 int radio_1_6::simRefreshInd(int slotId, int indicationType,
10996                          int token, RIL_Errno e, void *response, size_t responseLen) {
10997     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
10998         if (response == NULL || responseLen != sizeof(RIL_SimRefreshResponse_v7)) {
10999             RLOGE("simRefreshInd: invalid response");
11000             return 0;
11001         }
11002 
11003         SimRefreshResult refreshResult = {};
11004         RIL_SimRefreshResponse_v7 *simRefreshResponse = ((RIL_SimRefreshResponse_v7 *) response);
11005         refreshResult.type =
11006                 (V1_0::SimRefreshType) simRefreshResponse->result;
11007         refreshResult.efId = simRefreshResponse->ef_id;
11008         refreshResult.aid = convertCharPtrToHidlString(simRefreshResponse->aid);
11009 
11010 #if VDBG
11011         RLOGD("simRefreshInd: type %d efId %d", refreshResult.type, refreshResult.efId);
11012 #endif
11013         Return<void> retStatus = radioService[slotId]->mRadioIndication->simRefresh(
11014                 convertIntToRadioIndicationType(indicationType), refreshResult);
11015         radioService[slotId]->checkReturnStatus(retStatus);
11016     } else {
11017         RLOGE("simRefreshInd: radioService[%d]->mRadioIndication == NULL", slotId);
11018     }
11019 
11020     return 0;
11021 }
11022 
convertRilCdmaSignalInfoRecordToHal(RIL_CDMA_SignalInfoRecord * signalInfoRecord,CdmaSignalInfoRecord & record)11023 void convertRilCdmaSignalInfoRecordToHal(RIL_CDMA_SignalInfoRecord *signalInfoRecord,
11024         CdmaSignalInfoRecord& record) {
11025     record.isPresent = signalInfoRecord->isPresent;
11026     record.signalType = signalInfoRecord->signalType;
11027     record.alertPitch = signalInfoRecord->alertPitch;
11028     record.signal = signalInfoRecord->signal;
11029 }
11030 
callRingInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11031 int radio_1_6::callRingInd(int slotId, int indicationType,
11032                        int token, RIL_Errno e, void *response, size_t responseLen) {
11033     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11034         bool isGsm;
11035         CdmaSignalInfoRecord record = {};
11036         if (response == NULL || responseLen == 0) {
11037             isGsm = true;
11038         } else {
11039             isGsm = false;
11040             if (responseLen != sizeof (RIL_CDMA_SignalInfoRecord)) {
11041                 RLOGE("callRingInd: invalid response");
11042                 return 0;
11043             }
11044             convertRilCdmaSignalInfoRecordToHal((RIL_CDMA_SignalInfoRecord *) response, record);
11045         }
11046 
11047 #if VDBG
11048         RLOGD("callRingInd: isGsm %d", isGsm);
11049 #endif
11050         Return<void> retStatus = radioService[slotId]->mRadioIndication->callRing(
11051                 convertIntToRadioIndicationType(indicationType), isGsm, record);
11052         radioService[slotId]->checkReturnStatus(retStatus);
11053     } else {
11054         RLOGE("callRingInd: radioService[%d]->mRadioIndication == NULL", slotId);
11055     }
11056 
11057     return 0;
11058 }
11059 
simStatusChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11060 int radio_1_6::simStatusChangedInd(int slotId,
11061                                int indicationType, int token, RIL_Errno e, void *response,
11062                                size_t responseLen) {
11063     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11064 #if VDBG
11065         RLOGD("simStatusChangedInd");
11066 #endif
11067         Return<void> retStatus = radioService[slotId]->mRadioIndication->simStatusChanged(
11068                 convertIntToRadioIndicationType(indicationType));
11069         radioService[slotId]->checkReturnStatus(retStatus);
11070     } else {
11071         RLOGE("simStatusChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
11072     }
11073 
11074     return 0;
11075 }
11076 
cdmaNewSmsInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11077 int radio_1_6::cdmaNewSmsInd(int slotId, int indicationType,
11078                          int token, RIL_Errno e, void *response, size_t responseLen) {
11079     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11080         if (response == NULL || responseLen != sizeof(RIL_CDMA_SMS_Message)) {
11081             RLOGE("cdmaNewSmsInd: invalid response");
11082             return 0;
11083         }
11084 
11085         CdmaSmsMessage msg = {};
11086         RIL_CDMA_SMS_Message *rilMsg = (RIL_CDMA_SMS_Message *) response;
11087         msg.teleserviceId = rilMsg->uTeleserviceID;
11088         msg.isServicePresent = rilMsg->bIsServicePresent;
11089         msg.serviceCategory = rilMsg->uServicecategory;
11090         msg.address.digitMode =
11091                 (V1_0::CdmaSmsDigitMode) rilMsg->sAddress.digit_mode;
11092         msg.address.numberMode =
11093                 (V1_0::CdmaSmsNumberMode) rilMsg->sAddress.number_mode;
11094         msg.address.numberType =
11095                 (V1_0::CdmaSmsNumberType) rilMsg->sAddress.number_type;
11096         msg.address.numberPlan =
11097                 (V1_0::CdmaSmsNumberPlan) rilMsg->sAddress.number_plan;
11098 
11099         int digitLimit = MIN((rilMsg->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
11100         msg.address.digits.setToExternal(rilMsg->sAddress.digits, digitLimit);
11101 
11102         msg.subAddress.subaddressType = (V1_0::CdmaSmsSubaddressType)
11103                 rilMsg->sSubAddress.subaddressType;
11104         msg.subAddress.odd = rilMsg->sSubAddress.odd;
11105 
11106         digitLimit= MIN((rilMsg->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
11107         msg.subAddress.digits.setToExternal(rilMsg->sSubAddress.digits, digitLimit);
11108 
11109         digitLimit = MIN((rilMsg->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
11110         msg.bearerData.setToExternal(rilMsg->aBearerData, digitLimit);
11111 
11112 #if VDBG
11113         RLOGD("cdmaNewSmsInd");
11114 #endif
11115         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaNewSms(
11116                 convertIntToRadioIndicationType(indicationType), msg);
11117         radioService[slotId]->checkReturnStatus(retStatus);
11118     } else {
11119         RLOGE("cdmaNewSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
11120     }
11121 
11122     return 0;
11123 }
11124 
newBroadcastSmsInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11125 int radio_1_6::newBroadcastSmsInd(int slotId,
11126                               int indicationType, int token, RIL_Errno e, void *response,
11127                               size_t responseLen) {
11128     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11129         if (response == NULL || responseLen == 0) {
11130             RLOGE("newBroadcastSmsInd: invalid response");
11131             return 0;
11132         }
11133 
11134         hidl_vec<uint8_t> data;
11135         data.setToExternal((uint8_t *) response, responseLen);
11136 #if VDBG
11137         RLOGD("newBroadcastSmsInd");
11138 #endif
11139         Return<void> retStatus = radioService[slotId]->mRadioIndication->newBroadcastSms(
11140                 convertIntToRadioIndicationType(indicationType), data);
11141         radioService[slotId]->checkReturnStatus(retStatus);
11142     } else {
11143         RLOGE("newBroadcastSmsInd: radioService[%d]->mRadioIndication == NULL", slotId);
11144     }
11145 
11146     return 0;
11147 }
11148 
cdmaRuimSmsStorageFullInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11149 int radio_1_6::cdmaRuimSmsStorageFullInd(int slotId,
11150                                      int indicationType, int token, RIL_Errno e, void *response,
11151                                      size_t responseLen) {
11152     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11153 #if VDBG
11154         RLOGD("cdmaRuimSmsStorageFullInd");
11155 #endif
11156         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaRuimSmsStorageFull(
11157                 convertIntToRadioIndicationType(indicationType));
11158         radioService[slotId]->checkReturnStatus(retStatus);
11159     } else {
11160         RLOGE("cdmaRuimSmsStorageFullInd: radioService[%d]->mRadioIndication == NULL",
11161                 slotId);
11162     }
11163 
11164     return 0;
11165 }
11166 
restrictedStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11167 int radio_1_6::restrictedStateChangedInd(int slotId,
11168                                      int indicationType, int token, RIL_Errno e, void *response,
11169                                      size_t responseLen) {
11170     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11171         if (response == NULL || responseLen != sizeof(int)) {
11172             RLOGE("restrictedStateChangedInd: invalid response");
11173             return 0;
11174         }
11175         int32_t state = ((int32_t *) response)[0];
11176 #if VDBG
11177         RLOGD("restrictedStateChangedInd: state %d", state);
11178 #endif
11179         Return<void> retStatus = radioService[slotId]->mRadioIndication->restrictedStateChanged(
11180                 convertIntToRadioIndicationType(indicationType), (PhoneRestrictedState) state);
11181         radioService[slotId]->checkReturnStatus(retStatus);
11182     } else {
11183         RLOGE("restrictedStateChangedInd: radioService[%d]->mRadioIndication == NULL",
11184                 slotId);
11185     }
11186 
11187     return 0;
11188 }
11189 
enterEmergencyCallbackModeInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11190 int radio_1_6::enterEmergencyCallbackModeInd(int slotId,
11191                                          int indicationType, int token, RIL_Errno e, void *response,
11192                                          size_t responseLen) {
11193     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11194 #if VDBG
11195         RLOGD("enterEmergencyCallbackModeInd");
11196 #endif
11197         Return<void> retStatus = radioService[slotId]->mRadioIndication->enterEmergencyCallbackMode(
11198                 convertIntToRadioIndicationType(indicationType));
11199         radioService[slotId]->checkReturnStatus(retStatus);
11200     } else {
11201         RLOGE("enterEmergencyCallbackModeInd: radioService[%d]->mRadioIndication == NULL",
11202                 slotId);
11203     }
11204 
11205     return 0;
11206 }
11207 
cdmaCallWaitingInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11208 int radio_1_6::cdmaCallWaitingInd(int slotId,
11209                               int indicationType, int token, RIL_Errno e, void *response,
11210                               size_t responseLen) {
11211     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11212         if (response == NULL || responseLen != sizeof(RIL_CDMA_CallWaiting_v6)) {
11213             RLOGE("cdmaCallWaitingInd: invalid response");
11214             return 0;
11215         }
11216 
11217         CdmaCallWaiting callWaitingRecord = {};
11218         RIL_CDMA_CallWaiting_v6 *callWaitingRil = ((RIL_CDMA_CallWaiting_v6 *) response);
11219         callWaitingRecord.number = convertCharPtrToHidlString(callWaitingRil->number);
11220         callWaitingRecord.numberPresentation =
11221                 (CdmaCallWaitingNumberPresentation) callWaitingRil->numberPresentation;
11222         callWaitingRecord.name = convertCharPtrToHidlString(callWaitingRil->name);
11223         convertRilCdmaSignalInfoRecordToHal(&callWaitingRil->signalInfoRecord,
11224                 callWaitingRecord.signalInfoRecord);
11225         callWaitingRecord.numberType = (CdmaCallWaitingNumberType) callWaitingRil->number_type;
11226         callWaitingRecord.numberPlan = (CdmaCallWaitingNumberPlan) callWaitingRil->number_plan;
11227 
11228 #if VDBG
11229         RLOGD("cdmaCallWaitingInd");
11230 #endif
11231         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaCallWaiting(
11232                 convertIntToRadioIndicationType(indicationType), callWaitingRecord);
11233         radioService[slotId]->checkReturnStatus(retStatus);
11234     } else {
11235         RLOGE("cdmaCallWaitingInd: radioService[%d]->mRadioIndication == NULL", slotId);
11236     }
11237 
11238     return 0;
11239 }
11240 
cdmaOtaProvisionStatusInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11241 int radio_1_6::cdmaOtaProvisionStatusInd(int slotId,
11242                                      int indicationType, int token, RIL_Errno e, void *response,
11243                                      size_t responseLen) {
11244     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11245         if (response == NULL || responseLen != sizeof(int)) {
11246             RLOGE("cdmaOtaProvisionStatusInd: invalid response");
11247             return 0;
11248         }
11249         int32_t status = ((int32_t *) response)[0];
11250 #if VDBG
11251         RLOGD("cdmaOtaProvisionStatusInd: status %d", status);
11252 #endif
11253         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaOtaProvisionStatus(
11254                 convertIntToRadioIndicationType(indicationType), (CdmaOtaProvisionStatus) status);
11255         radioService[slotId]->checkReturnStatus(retStatus);
11256     } else {
11257         RLOGE("cdmaOtaProvisionStatusInd: radioService[%d]->mRadioIndication == NULL",
11258                 slotId);
11259     }
11260 
11261     return 0;
11262 }
11263 
cdmaInfoRecInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11264 int radio_1_6::cdmaInfoRecInd(int slotId,
11265                           int indicationType, int token, RIL_Errno e, void *response,
11266                           size_t responseLen) {
11267     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11268         if (response == NULL || responseLen != sizeof(RIL_CDMA_InformationRecords)) {
11269             RLOGE("cdmaInfoRecInd: invalid response");
11270             return 0;
11271         }
11272 
11273         CdmaInformationRecords records = {};
11274         RIL_CDMA_InformationRecords *recordsRil = (RIL_CDMA_InformationRecords *) response;
11275 
11276         char* string8 = NULL;
11277         int num = MIN(recordsRil->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
11278         if (recordsRil->numberOfInfoRecs > RIL_CDMA_MAX_NUMBER_OF_INFO_RECS) {
11279             RLOGE("cdmaInfoRecInd: received %d recs which is more than %d, dropping "
11280                     "additional ones", recordsRil->numberOfInfoRecs,
11281                     RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
11282         }
11283         records.infoRec.resize(num);
11284         for (int i = 0 ; i < num ; i++) {
11285             CdmaInformationRecord *record = &records.infoRec[i];
11286             RIL_CDMA_InformationRecord *infoRec = &recordsRil->infoRec[i];
11287             record->name = (CdmaInfoRecName) infoRec->name;
11288             // All vectors should be size 0 except one which will be size 1. Set everything to
11289             // size 0 initially.
11290             record->display.resize(0);
11291             record->number.resize(0);
11292             record->signal.resize(0);
11293             record->redir.resize(0);
11294             record->lineCtrl.resize(0);
11295             record->clir.resize(0);
11296             record->audioCtrl.resize(0);
11297             switch (infoRec->name) {
11298                 case RIL_CDMA_DISPLAY_INFO_REC:
11299                 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC: {
11300                     if (infoRec->rec.display.alpha_len > CDMA_ALPHA_INFO_BUFFER_LENGTH) {
11301                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
11302                                 "expected not more than %d", (int) infoRec->rec.display.alpha_len,
11303                                 CDMA_ALPHA_INFO_BUFFER_LENGTH);
11304                         return 0;
11305                     }
11306                     string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1) * sizeof(char));
11307                     if (string8 == NULL) {
11308                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
11309                                 "responseCdmaInformationRecords");
11310                         return 0;
11311                     }
11312                     memcpy(string8, infoRec->rec.display.alpha_buf, infoRec->rec.display.alpha_len);
11313                     string8[(int)infoRec->rec.display.alpha_len] = '\0';
11314 
11315                     record->display.resize(1);
11316                     record->display[0].alphaBuf = string8;
11317                     free(string8);
11318                     string8 = NULL;
11319                     break;
11320                 }
11321 
11322                 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
11323                 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
11324                 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC: {
11325                     if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
11326                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
11327                                 "expected not more than %d", (int) infoRec->rec.number.len,
11328                                 CDMA_NUMBER_INFO_BUFFER_LENGTH);
11329                         return 0;
11330                     }
11331                     string8 = (char*) malloc((infoRec->rec.number.len + 1) * sizeof(char));
11332                     if (string8 == NULL) {
11333                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
11334                                 "responseCdmaInformationRecords");
11335                         return 0;
11336                     }
11337                     memcpy(string8, infoRec->rec.number.buf, infoRec->rec.number.len);
11338                     string8[(int)infoRec->rec.number.len] = '\0';
11339 
11340                     record->number.resize(1);
11341                     record->number[0].number = string8;
11342                     free(string8);
11343                     string8 = NULL;
11344                     record->number[0].numberType = infoRec->rec.number.number_type;
11345                     record->number[0].numberPlan = infoRec->rec.number.number_plan;
11346                     record->number[0].pi = infoRec->rec.number.pi;
11347                     record->number[0].si = infoRec->rec.number.si;
11348                     break;
11349                 }
11350 
11351                 case RIL_CDMA_SIGNAL_INFO_REC: {
11352                     record->signal.resize(1);
11353                     record->signal[0].isPresent = infoRec->rec.signal.isPresent;
11354                     record->signal[0].signalType = infoRec->rec.signal.signalType;
11355                     record->signal[0].alertPitch = infoRec->rec.signal.alertPitch;
11356                     record->signal[0].signal = infoRec->rec.signal.signal;
11357                     break;
11358                 }
11359 
11360                 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC: {
11361                     if (infoRec->rec.redir.redirectingNumber.len >
11362                                                   CDMA_NUMBER_INFO_BUFFER_LENGTH) {
11363                         RLOGE("cdmaInfoRecInd: invalid display info response length %d "
11364                                 "expected not more than %d\n",
11365                                 (int)infoRec->rec.redir.redirectingNumber.len,
11366                                 CDMA_NUMBER_INFO_BUFFER_LENGTH);
11367                         return 0;
11368                     }
11369                     string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber.len + 1) *
11370                             sizeof(char));
11371                     if (string8 == NULL) {
11372                         RLOGE("cdmaInfoRecInd: Memory allocation failed for "
11373                                 "responseCdmaInformationRecords");
11374                         return 0;
11375                     }
11376                     memcpy(string8, infoRec->rec.redir.redirectingNumber.buf,
11377                             infoRec->rec.redir.redirectingNumber.len);
11378                     string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
11379 
11380                     record->redir.resize(1);
11381                     record->redir[0].redirectingNumber.number = string8;
11382                     free(string8);
11383                     string8 = NULL;
11384                     record->redir[0].redirectingNumber.numberType =
11385                             infoRec->rec.redir.redirectingNumber.number_type;
11386                     record->redir[0].redirectingNumber.numberPlan =
11387                             infoRec->rec.redir.redirectingNumber.number_plan;
11388                     record->redir[0].redirectingNumber.pi = infoRec->rec.redir.redirectingNumber.pi;
11389                     record->redir[0].redirectingNumber.si = infoRec->rec.redir.redirectingNumber.si;
11390                     record->redir[0].redirectingReason =
11391                             (CdmaRedirectingReason) infoRec->rec.redir.redirectingReason;
11392                     break;
11393                 }
11394 
11395                 case RIL_CDMA_LINE_CONTROL_INFO_REC: {
11396                     record->lineCtrl.resize(1);
11397                     record->lineCtrl[0].lineCtrlPolarityIncluded =
11398                             infoRec->rec.lineCtrl.lineCtrlPolarityIncluded;
11399                     record->lineCtrl[0].lineCtrlToggle = infoRec->rec.lineCtrl.lineCtrlToggle;
11400                     record->lineCtrl[0].lineCtrlReverse = infoRec->rec.lineCtrl.lineCtrlReverse;
11401                     record->lineCtrl[0].lineCtrlPowerDenial =
11402                             infoRec->rec.lineCtrl.lineCtrlPowerDenial;
11403                     break;
11404                 }
11405 
11406                 case RIL_CDMA_T53_CLIR_INFO_REC: {
11407                     record->clir.resize(1);
11408                     record->clir[0].cause = infoRec->rec.clir.cause;
11409                     break;
11410                 }
11411 
11412                 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC: {
11413                     record->audioCtrl.resize(1);
11414                     record->audioCtrl[0].upLink = infoRec->rec.audioCtrl.upLink;
11415                     record->audioCtrl[0].downLink = infoRec->rec.audioCtrl.downLink;
11416                     break;
11417                 }
11418 
11419                 case RIL_CDMA_T53_RELEASE_INFO_REC:
11420                     RLOGE("cdmaInfoRecInd: RIL_CDMA_T53_RELEASE_INFO_REC: INVALID");
11421                     return 0;
11422 
11423                 default:
11424                     RLOGE("cdmaInfoRecInd: Incorrect name value");
11425                     return 0;
11426             }
11427         }
11428 
11429 #if VDBG
11430         RLOGD("cdmaInfoRecInd");
11431 #endif
11432         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaInfoRec(
11433                 convertIntToRadioIndicationType(indicationType), records);
11434         radioService[slotId]->checkReturnStatus(retStatus);
11435     } else {
11436         RLOGE("cdmaInfoRecInd: radioService[%d]->mRadioIndication == NULL", slotId);
11437     }
11438 
11439     return 0;
11440 }
11441 
indicateRingbackToneInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11442 int radio_1_6::indicateRingbackToneInd(int slotId,
11443                                    int indicationType, int token, RIL_Errno e, void *response,
11444                                    size_t responseLen) {
11445     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11446         if (response == NULL || responseLen != sizeof(int)) {
11447             RLOGE("indicateRingbackToneInd: invalid response");
11448             return 0;
11449         }
11450         bool start = ((int32_t *) response)[0];
11451 #if VDBG
11452         RLOGD("indicateRingbackToneInd: start %d", start);
11453 #endif
11454         Return<void> retStatus = radioService[slotId]->mRadioIndication->indicateRingbackTone(
11455                 convertIntToRadioIndicationType(indicationType), start);
11456         radioService[slotId]->checkReturnStatus(retStatus);
11457     } else {
11458         RLOGE("indicateRingbackToneInd: radioService[%d]->mRadioIndication == NULL", slotId);
11459     }
11460 
11461     return 0;
11462 }
11463 
resendIncallMuteInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11464 int radio_1_6::resendIncallMuteInd(int slotId,
11465                                int indicationType, int token, RIL_Errno e, void *response,
11466                                size_t responseLen) {
11467     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11468 #if VDBG
11469         RLOGD("resendIncallMuteInd");
11470 #endif
11471         Return<void> retStatus = radioService[slotId]->mRadioIndication->resendIncallMute(
11472                 convertIntToRadioIndicationType(indicationType));
11473         radioService[slotId]->checkReturnStatus(retStatus);
11474     } else {
11475         RLOGE("resendIncallMuteInd: radioService[%d]->mRadioIndication == NULL", slotId);
11476     }
11477 
11478     return 0;
11479 }
11480 
cdmaSubscriptionSourceChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11481 int radio_1_6::cdmaSubscriptionSourceChangedInd(int slotId,
11482                                             int indicationType, int token, RIL_Errno e,
11483                                             void *response, size_t responseLen) {
11484     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11485         if (response == NULL || responseLen != sizeof(int)) {
11486             RLOGE("cdmaSubscriptionSourceChangedInd: invalid response");
11487             return 0;
11488         }
11489         int32_t cdmaSource = ((int32_t *) response)[0];
11490 #if VDBG
11491         RLOGD("cdmaSubscriptionSourceChangedInd: cdmaSource %d", cdmaSource);
11492 #endif
11493         Return<void> retStatus = radioService[slotId]->mRadioIndication->
11494                 cdmaSubscriptionSourceChanged(convertIntToRadioIndicationType(indicationType),
11495                 (CdmaSubscriptionSource) cdmaSource);
11496         radioService[slotId]->checkReturnStatus(retStatus);
11497     } else {
11498         RLOGE("cdmaSubscriptionSourceChangedInd: radioService[%d]->mRadioIndication == NULL",
11499                 slotId);
11500     }
11501 
11502     return 0;
11503 }
11504 
cdmaPrlChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11505 int radio_1_6::cdmaPrlChangedInd(int slotId,
11506                              int indicationType, int token, RIL_Errno e, void *response,
11507                              size_t responseLen) {
11508     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11509         if (response == NULL || responseLen != sizeof(int)) {
11510             RLOGE("cdmaPrlChangedInd: invalid response");
11511             return 0;
11512         }
11513         int32_t version = ((int32_t *) response)[0];
11514 #if VDBG
11515         RLOGD("cdmaPrlChangedInd: version %d", version);
11516 #endif
11517         Return<void> retStatus = radioService[slotId]->mRadioIndication->cdmaPrlChanged(
11518                 convertIntToRadioIndicationType(indicationType), version);
11519         radioService[slotId]->checkReturnStatus(retStatus);
11520     } else {
11521         RLOGE("cdmaPrlChangedInd: radioService[%d]->mRadioIndication == NULL", slotId);
11522     }
11523 
11524     return 0;
11525 }
11526 
exitEmergencyCallbackModeInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11527 int radio_1_6::exitEmergencyCallbackModeInd(int slotId,
11528                                         int indicationType, int token, RIL_Errno e, void *response,
11529                                         size_t responseLen) {
11530     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11531 #if VDBG
11532         RLOGD("exitEmergencyCallbackModeInd");
11533 #endif
11534         Return<void> retStatus = radioService[slotId]->mRadioIndication->exitEmergencyCallbackMode(
11535                 convertIntToRadioIndicationType(indicationType));
11536         radioService[slotId]->checkReturnStatus(retStatus);
11537     } else {
11538         RLOGE("exitEmergencyCallbackModeInd: radioService[%d]->mRadioIndication == NULL",
11539                 slotId);
11540     }
11541 
11542     return 0;
11543 }
11544 
rilConnectedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11545 int radio_1_6::rilConnectedInd(int slotId,
11546                            int indicationType, int token, RIL_Errno e, void *response,
11547                            size_t responseLen) {
11548     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11549         RLOGD("rilConnectedInd");
11550         Return<void> retStatus = radioService[slotId]->mRadioIndication->rilConnected(
11551                 convertIntToRadioIndicationType(indicationType));
11552         radioService[slotId]->checkReturnStatus(retStatus);
11553     } else {
11554         RLOGE("rilConnectedInd: radioService[%d]->mRadioIndication == NULL", slotId);
11555     }
11556 
11557     return 0;
11558 }
11559 
voiceRadioTechChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)11560 int radio_1_6::voiceRadioTechChangedInd(int slotId,
11561                                     int indicationType, int token, RIL_Errno e, void *response,
11562                                     size_t responseLen) {
11563     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
11564         if (response == NULL || responseLen != sizeof(int)) {
11565             RLOGE("voiceRadioTechChangedInd: invalid response");
11566             return 0;
11567         }
11568         int32_t rat = ((int32_t *) response)[0];
11569 #if VDBG
11570         RLOGD("voiceRadioTechChangedInd: rat %d", rat);
11571 #endif
11572         Return<void> retStatus = radioService[slotId]->mRadioIndication->voiceRadioTechChanged(
11573                 convertIntToRadioIndicationType(indicationType), (RadioTechnology) rat);
11574         radioService[slotId]->checkReturnStatus(retStatus);
11575     } else {
11576         RLOGE("voiceRadioTechChangedInd: radioService[%d]->mRadioIndication == NULL",
11577                 slotId);
11578     }
11579 
11580     return 0;
11581 }
11582 
convertRilCellInfoListToHal(void * response,size_t responseLen,hidl_vec<CellInfo> & records)11583 void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<CellInfo>& records) {
11584     int num = responseLen / sizeof(RIL_CellInfo_v12);
11585     records.resize(num);
11586 
11587     RIL_CellInfo_v12 *rillCellInfo = (RIL_CellInfo_v12 *) response;
11588     for (int i = 0; i < num; i++) {
11589         records[i].cellInfoType = (CellInfoType) rillCellInfo->cellInfoType;
11590         records[i].registered = rillCellInfo->registered;
11591         records[i].timeStampType = (TimeStampType) rillCellInfo->timeStampType;
11592         records[i].timeStamp = rillCellInfo->timeStamp;
11593         // All vectors should be size 0 except one which will be size 1. Set everything to
11594         // size 0 initially.
11595         records[i].gsm.resize(0);
11596         records[i].wcdma.resize(0);
11597         records[i].cdma.resize(0);
11598         records[i].lte.resize(0);
11599         records[i].tdscdma.resize(0);
11600         switch(rillCellInfo->cellInfoType) {
11601             case RIL_CELL_INFO_TYPE_GSM: {
11602                 records[i].gsm.resize(1);
11603                 CellInfoGsm *cellInfoGsm = &records[i].gsm[0];
11604                 cellInfoGsm->cellIdentityGsm.mcc =
11605                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
11606                 cellInfoGsm->cellIdentityGsm.mnc =
11607                         ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
11608                 cellInfoGsm->cellIdentityGsm.lac =
11609                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
11610                 cellInfoGsm->cellIdentityGsm.cid =
11611                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
11612                 cellInfoGsm->cellIdentityGsm.arfcn =
11613                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
11614                 cellInfoGsm->cellIdentityGsm.bsic =
11615                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
11616                 cellInfoGsm->signalStrengthGsm.signalStrength =
11617                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
11618                 cellInfoGsm->signalStrengthGsm.bitErrorRate =
11619                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
11620                 cellInfoGsm->signalStrengthGsm.timingAdvance =
11621                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
11622                 break;
11623             }
11624 
11625             case RIL_CELL_INFO_TYPE_WCDMA: {
11626                 records[i].wcdma.resize(1);
11627                 CellInfoWcdma *cellInfoWcdma = &records[i].wcdma[0];
11628                 cellInfoWcdma->cellIdentityWcdma.mcc =
11629                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
11630                 cellInfoWcdma->cellIdentityWcdma.mnc =
11631                         ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
11632                 cellInfoWcdma->cellIdentityWcdma.lac =
11633                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
11634                 cellInfoWcdma->cellIdentityWcdma.cid =
11635                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
11636                 cellInfoWcdma->cellIdentityWcdma.psc =
11637                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
11638                 cellInfoWcdma->cellIdentityWcdma.uarfcn =
11639                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
11640                 cellInfoWcdma->signalStrengthWcdma.signalStrength =
11641                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
11642                 cellInfoWcdma->signalStrengthWcdma.bitErrorRate =
11643                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
11644                 break;
11645             }
11646 
11647             case RIL_CELL_INFO_TYPE_CDMA: {
11648                 records[i].cdma.resize(1);
11649                 CellInfoCdma *cellInfoCdma = &records[i].cdma[0];
11650                 cellInfoCdma->cellIdentityCdma.networkId =
11651                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
11652                 cellInfoCdma->cellIdentityCdma.systemId =
11653                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
11654                 cellInfoCdma->cellIdentityCdma.baseStationId =
11655                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
11656                 cellInfoCdma->cellIdentityCdma.longitude =
11657                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
11658                 cellInfoCdma->cellIdentityCdma.latitude =
11659                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
11660                 cellInfoCdma->signalStrengthCdma.dbm =
11661                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
11662                 cellInfoCdma->signalStrengthCdma.ecio =
11663                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
11664                 cellInfoCdma->signalStrengthEvdo.dbm =
11665                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
11666                 cellInfoCdma->signalStrengthEvdo.ecio =
11667                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
11668                 cellInfoCdma->signalStrengthEvdo.signalNoiseRatio =
11669                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
11670                 break;
11671             }
11672 
11673             case RIL_CELL_INFO_TYPE_LTE: {
11674                 records[i].lte.resize(1);
11675                 CellInfoLte *cellInfoLte = &records[i].lte[0];
11676                 cellInfoLte->cellIdentityLte.mcc =
11677                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
11678                 cellInfoLte->cellIdentityLte.mnc =
11679                         ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
11680                 cellInfoLte->cellIdentityLte.ci =
11681                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
11682                 cellInfoLte->cellIdentityLte.pci =
11683                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
11684                 cellInfoLte->cellIdentityLte.tac =
11685                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
11686                 cellInfoLte->cellIdentityLte.earfcn =
11687                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
11688                 cellInfoLte->signalStrengthLte.signalStrength =
11689                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
11690                 cellInfoLte->signalStrengthLte.rsrp =
11691                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
11692                 cellInfoLte->signalStrengthLte.rsrq =
11693                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
11694                 cellInfoLte->signalStrengthLte.rssnr =
11695                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
11696                 cellInfoLte->signalStrengthLte.cqi =
11697                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
11698                 cellInfoLte->signalStrengthLte.timingAdvance =
11699                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
11700                 break;
11701             }
11702 
11703             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
11704                 records[i].tdscdma.resize(1);
11705                 CellInfoTdscdma *cellInfoTdscdma = &records[i].tdscdma[0];
11706                 cellInfoTdscdma->cellIdentityTdscdma.mcc =
11707                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
11708                 cellInfoTdscdma->cellIdentityTdscdma.mnc =
11709                         ril::util::mnc::decode(
11710                                 rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
11711                 cellInfoTdscdma->cellIdentityTdscdma.lac =
11712                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
11713                 cellInfoTdscdma->cellIdentityTdscdma.cid =
11714                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
11715                 cellInfoTdscdma->cellIdentityTdscdma.cpid =
11716                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
11717                 cellInfoTdscdma->signalStrengthTdscdma.rscp =
11718                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
11719                 break;
11720             }
11721             default: {
11722                 break;
11723             }
11724         }
11725         rillCellInfo += 1;
11726     }
11727 }
11728 
convertRilCellInfoListToHal_1_2(void * response,size_t responseLen,hidl_vec<V1_2::CellInfo> & records)11729 void convertRilCellInfoListToHal_1_2(void *response, size_t responseLen, hidl_vec<V1_2::CellInfo>& records) {
11730     int num = responseLen / sizeof(RIL_CellInfo_v12);
11731     records.resize(num);
11732     RIL_CellInfo_v12 *rillCellInfo = (RIL_CellInfo_v12 *) response;
11733     for (int i = 0; i < num; i++) {
11734         records[i].cellInfoType = (CellInfoType) rillCellInfo->cellInfoType;
11735         records[i].registered = rillCellInfo->registered;
11736         records[i].timeStampType = (TimeStampType) rillCellInfo->timeStampType;
11737         records[i].timeStamp = rillCellInfo->timeStamp;
11738         records[i].connectionStatus =(V1_2::CellConnectionStatus)0;
11739         // All vectors should be size 0 except one which will be size 1. Set everything to
11740         // size 0 initially.
11741         records[i].gsm.resize(0);
11742         records[i].wcdma.resize(0);
11743         records[i].cdma.resize(0);
11744         records[i].lte.resize(0);
11745         records[i].tdscdma.resize(0);
11746         switch(rillCellInfo->cellInfoType) {
11747             case RIL_CELL_INFO_TYPE_GSM: {
11748                 records[i].gsm.resize(1);
11749                 V1_2::CellInfoGsm *cellInfoGsm = &records[i].gsm[0];
11750                 cellInfoGsm->cellIdentityGsm.base.mcc =
11751                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
11752                 cellInfoGsm->cellIdentityGsm.base.mnc =
11753                         ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
11754                 cellInfoGsm->cellIdentityGsm.base.lac =
11755                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
11756                 cellInfoGsm->cellIdentityGsm.base.cid =
11757                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
11758                 cellInfoGsm->cellIdentityGsm.base.arfcn =
11759                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
11760                 cellInfoGsm->cellIdentityGsm.base.bsic =
11761                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
11762                 cellInfoGsm->signalStrengthGsm.signalStrength =
11763                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
11764                 cellInfoGsm->signalStrengthGsm.bitErrorRate =
11765                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
11766                 cellInfoGsm->signalStrengthGsm.timingAdvance =
11767                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
11768                 break;
11769             }
11770 
11771             case RIL_CELL_INFO_TYPE_WCDMA: {
11772                 records[i].wcdma.resize(1);
11773                 V1_2::CellInfoWcdma *cellInfoWcdma = &records[i].wcdma[0];
11774                 cellInfoWcdma->cellIdentityWcdma.base.mcc =
11775                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
11776                 cellInfoWcdma->cellIdentityWcdma.base.mnc =
11777                         ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
11778                 cellInfoWcdma->cellIdentityWcdma.base.lac =
11779                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
11780                 cellInfoWcdma->cellIdentityWcdma.base.cid =
11781                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
11782                 cellInfoWcdma->cellIdentityWcdma.base.psc =
11783                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
11784                 cellInfoWcdma->cellIdentityWcdma.base.uarfcn =
11785                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
11786                 cellInfoWcdma->signalStrengthWcdma.base.signalStrength =
11787                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
11788                 cellInfoWcdma->signalStrengthWcdma.base.bitErrorRate =
11789                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
11790                 break;
11791             }
11792 
11793             case RIL_CELL_INFO_TYPE_CDMA: {
11794                 records[i].cdma.resize(1);
11795                 V1_2::CellInfoCdma *cellInfoCdma = &records[i].cdma[0];
11796                 cellInfoCdma->cellIdentityCdma.base.networkId =
11797                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
11798                 cellInfoCdma->cellIdentityCdma.base.systemId =
11799                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
11800                 cellInfoCdma->cellIdentityCdma.base.baseStationId =
11801                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
11802                 cellInfoCdma->cellIdentityCdma.base.longitude =
11803                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
11804                 cellInfoCdma->cellIdentityCdma.base.latitude =
11805                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
11806                 cellInfoCdma->signalStrengthCdma.dbm =
11807                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
11808                 cellInfoCdma->signalStrengthCdma.ecio =
11809                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
11810                 cellInfoCdma->signalStrengthEvdo.dbm =
11811                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
11812                 cellInfoCdma->signalStrengthEvdo.ecio =
11813                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
11814                 cellInfoCdma->signalStrengthEvdo.signalNoiseRatio =
11815                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
11816                 break;
11817             }
11818 
11819             case RIL_CELL_INFO_TYPE_LTE: {
11820                 records[i].lte.resize(1);
11821                 V1_2::CellInfoLte *cellInfoLte = &records[i].lte[0];
11822                 cellInfoLte->cellIdentityLte.base.mcc =
11823                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
11824                 cellInfoLte->cellIdentityLte.base.mnc =
11825                         ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
11826                 cellInfoLte->cellIdentityLte.base.ci =
11827                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
11828                 cellInfoLte->cellIdentityLte.base.pci =
11829                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
11830                 cellInfoLte->cellIdentityLte.base.tac =
11831                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
11832                 cellInfoLte->cellIdentityLte.base.earfcn =
11833                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
11834                 cellInfoLte->signalStrengthLte.signalStrength =
11835                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
11836                 cellInfoLte->signalStrengthLte.rsrp =
11837                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
11838                 cellInfoLte->signalStrengthLte.rsrq =
11839                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
11840                 cellInfoLte->signalStrengthLte.rssnr =
11841                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
11842                 cellInfoLte->signalStrengthLte.cqi =
11843                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
11844                 cellInfoLte->signalStrengthLte.timingAdvance =
11845                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
11846                 break;
11847             }
11848 
11849             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
11850                 records[i].tdscdma.resize(1);
11851                 V1_2::CellInfoTdscdma *cellInfoTdscdma = &records[i].tdscdma[0];
11852                 cellInfoTdscdma->cellIdentityTdscdma.base.mcc =
11853                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
11854                 cellInfoTdscdma->cellIdentityTdscdma.base.mnc =
11855                         ril::util::mnc::decode(
11856                                 rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
11857                 cellInfoTdscdma->cellIdentityTdscdma.base.lac =
11858                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
11859                 cellInfoTdscdma->cellIdentityTdscdma.base.cid =
11860                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
11861                 cellInfoTdscdma->cellIdentityTdscdma.base.cpid =
11862                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
11863                 cellInfoTdscdma->signalStrengthTdscdma.rscp =
11864                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
11865                 break;
11866             }
11867             default: {
11868                 break;
11869             }
11870         }
11871         rillCellInfo += 1;
11872     }
11873 }
11874 
convertRilCellInfoListToHal_1_4(void * response,size_t responseLen,hidl_vec<V1_4::CellInfo> & records)11875 void convertRilCellInfoListToHal_1_4(void *response, size_t responseLen, hidl_vec<V1_4::CellInfo>& records) {
11876     int num = responseLen / sizeof(RIL_CellInfo_v16);
11877     records.resize(num);
11878     RIL_CellInfo_v16 *rillCellInfo = (RIL_CellInfo_v16 *) response;
11879     for (int i = 0; i < num; i++) {
11880         records[i].isRegistered = rillCellInfo->registered;
11881         records[i].connectionStatus = (V1_2::CellConnectionStatus)rillCellInfo->connectionStatus;
11882 
11883         switch(rillCellInfo->cellInfoType) {
11884             case RIL_CELL_INFO_TYPE_GSM: {
11885                 V1_2::CellInfoGsm cellInfoGsm;
11886                 cellInfoGsm.cellIdentityGsm.base.mcc =
11887                         std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
11888                 cellInfoGsm.cellIdentityGsm.base.mnc =
11889                         ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
11890                 cellInfoGsm.cellIdentityGsm.base.lac =
11891                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.lac;
11892                 cellInfoGsm.cellIdentityGsm.base.cid =
11893                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.cid;
11894                 cellInfoGsm.cellIdentityGsm.base.arfcn =
11895                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.arfcn;
11896                 cellInfoGsm.cellIdentityGsm.base.bsic =
11897                         rillCellInfo->CellInfo.gsm.cellIdentityGsm.bsic;
11898                 cellInfoGsm.signalStrengthGsm.signalStrength =
11899                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.signalStrength;
11900                 cellInfoGsm.signalStrengthGsm.bitErrorRate =
11901                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.bitErrorRate;
11902                 cellInfoGsm.signalStrengthGsm.timingAdvance =
11903                         rillCellInfo->CellInfo.gsm.signalStrengthGsm.timingAdvance;
11904                 records[i].info.gsm(cellInfoGsm);
11905                 break;
11906             }
11907 
11908             case RIL_CELL_INFO_TYPE_WCDMA: {
11909                 V1_2::CellInfoWcdma cellInfoWcdma;
11910                 cellInfoWcdma.cellIdentityWcdma.base.mcc =
11911                         std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
11912                 cellInfoWcdma.cellIdentityWcdma.base.mnc =
11913                         ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
11914                 cellInfoWcdma.cellIdentityWcdma.base.lac =
11915                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.lac;
11916                 cellInfoWcdma.cellIdentityWcdma.base.cid =
11917                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.cid;
11918                 cellInfoWcdma.cellIdentityWcdma.base.psc =
11919                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.psc;
11920                 cellInfoWcdma.cellIdentityWcdma.base.uarfcn =
11921                         rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.uarfcn;
11922                 cellInfoWcdma.signalStrengthWcdma.base.signalStrength =
11923                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.signalStrength;
11924                 cellInfoWcdma.signalStrengthWcdma.base.bitErrorRate =
11925                         rillCellInfo->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate;
11926                 records[i].info.wcdma(cellInfoWcdma);
11927                 break;
11928             }
11929 
11930             case RIL_CELL_INFO_TYPE_CDMA: {
11931                 V1_2::CellInfoCdma cellInfoCdma;
11932                 cellInfoCdma.cellIdentityCdma.base.networkId =
11933                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.networkId;
11934                 cellInfoCdma.cellIdentityCdma.base.systemId =
11935                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.systemId;
11936                 cellInfoCdma.cellIdentityCdma.base.baseStationId =
11937                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.basestationId;
11938                 cellInfoCdma.cellIdentityCdma.base.longitude =
11939                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.longitude;
11940                 cellInfoCdma.cellIdentityCdma.base.latitude =
11941                         rillCellInfo->CellInfo.cdma.cellIdentityCdma.latitude;
11942                 cellInfoCdma.signalStrengthCdma.dbm =
11943                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.dbm;
11944                 cellInfoCdma.signalStrengthCdma.ecio =
11945                         rillCellInfo->CellInfo.cdma.signalStrengthCdma.ecio;
11946                 cellInfoCdma.signalStrengthEvdo.dbm =
11947                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.dbm;
11948                 cellInfoCdma.signalStrengthEvdo.ecio =
11949                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.ecio;
11950                 cellInfoCdma.signalStrengthEvdo.signalNoiseRatio =
11951                         rillCellInfo->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio;
11952                 records[i].info.cdma(cellInfoCdma);
11953                 break;
11954             }
11955 
11956             case RIL_CELL_INFO_TYPE_LTE: {
11957                 V1_4::CellInfoLte cellInfoLte;
11958                 cellInfoLte.base.cellIdentityLte.base.mcc =
11959                         std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
11960                 cellInfoLte.base.cellIdentityLte.base.mnc =
11961                         ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
11962                 cellInfoLte.base.cellIdentityLte.base.ci =
11963                         rillCellInfo->CellInfo.lte.cellIdentityLte.ci;
11964                 cellInfoLte.base.cellIdentityLte.base.pci =
11965                         rillCellInfo->CellInfo.lte.cellIdentityLte.pci;
11966                 cellInfoLte.base.cellIdentityLte.base.tac =
11967                         rillCellInfo->CellInfo.lte.cellIdentityLte.tac;
11968                 cellInfoLte.base.cellIdentityLte.base.earfcn =
11969                         rillCellInfo->CellInfo.lte.cellIdentityLte.earfcn;
11970                 cellInfoLte.base.signalStrengthLte.signalStrength =
11971                         rillCellInfo->CellInfo.lte.signalStrengthLte.signalStrength;
11972                 cellInfoLte.base.signalStrengthLte.rsrp =
11973                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrp;
11974                 cellInfoLte.base.signalStrengthLte.rsrq =
11975                         rillCellInfo->CellInfo.lte.signalStrengthLte.rsrq;
11976                 cellInfoLte.base.signalStrengthLte.rssnr =
11977                         rillCellInfo->CellInfo.lte.signalStrengthLte.rssnr;
11978                 cellInfoLte.base.signalStrengthLte.cqi =
11979                         rillCellInfo->CellInfo.lte.signalStrengthLte.cqi;
11980                 cellInfoLte.base.signalStrengthLte.timingAdvance =
11981                         rillCellInfo->CellInfo.lte.signalStrengthLte.timingAdvance;
11982                 records[i].info.lte(cellInfoLte);
11983                 break;
11984             }
11985 
11986             case RIL_CELL_INFO_TYPE_TD_SCDMA: {
11987                 V1_2::CellInfoTdscdma cellInfoTdscdma;
11988                 cellInfoTdscdma.cellIdentityTdscdma.base.mcc =
11989                         std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
11990                 cellInfoTdscdma.cellIdentityTdscdma.base.mnc =
11991                         ril::util::mnc::decode(
11992                                 rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
11993                 cellInfoTdscdma.cellIdentityTdscdma.base.lac =
11994                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.lac;
11995                 cellInfoTdscdma.cellIdentityTdscdma.base.cid =
11996                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cid;
11997                 cellInfoTdscdma.cellIdentityTdscdma.base.cpid =
11998                         rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.cpid;
11999                 cellInfoTdscdma.signalStrengthTdscdma.rscp =
12000                         rillCellInfo->CellInfo.tdscdma.signalStrengthTdscdma.rscp;
12001                 records[i].info.tdscdma(cellInfoTdscdma);
12002                 break;
12003             }
12004 
12005             case RIL_CELL_INFO_TYPE_NR: {
12006                 V1_4::CellInfoNr cellInfoNr;
12007                 cellInfoNr.cellidentity.mcc =
12008                         std::to_string(rillCellInfo->CellInfo.nr.cellidentity.mcc);
12009                 cellInfoNr.cellidentity.mnc =
12010                         ril::util::mnc::decode(
12011                                 rillCellInfo->CellInfo.nr.cellidentity.mnc);
12012                 cellInfoNr.cellidentity.nci =
12013                         rillCellInfo->CellInfo.nr.cellidentity.nci;
12014                 cellInfoNr.cellidentity.pci =
12015                         rillCellInfo->CellInfo.nr.cellidentity.pci;
12016                 cellInfoNr.cellidentity.tac =
12017                         rillCellInfo->CellInfo.nr.cellidentity.tac;
12018                 cellInfoNr.cellidentity.nrarfcn =
12019                         rillCellInfo->CellInfo.nr.cellidentity.nrarfcn;
12020                 cellInfoNr.cellidentity.operatorNames.alphaLong =
12021                         convertCharPtrToHidlString(rillCellInfo->CellInfo.nr.cellidentity.operatorNames.alphaLong);
12022                 cellInfoNr.cellidentity.operatorNames.alphaShort =
12023                         convertCharPtrToHidlString(rillCellInfo->CellInfo.nr.cellidentity.operatorNames.alphaShort);
12024 
12025                 cellInfoNr.signalStrength.ssRsrp =
12026                         rillCellInfo->CellInfo.nr.signalStrength.ssRsrp;
12027                 cellInfoNr.signalStrength.ssRsrq =
12028                         rillCellInfo->CellInfo.nr.signalStrength.ssRsrq;
12029                 cellInfoNr.signalStrength.ssSinr =
12030                         rillCellInfo->CellInfo.nr.signalStrength.ssSinr;
12031                 cellInfoNr.signalStrength.csiRsrp =
12032                         rillCellInfo->CellInfo.nr.signalStrength.csiRsrp;
12033                 cellInfoNr.signalStrength.csiRsrq =
12034                         rillCellInfo->CellInfo.nr.signalStrength.csiRsrq;
12035                 cellInfoNr.signalStrength.csiSinr =
12036                         rillCellInfo->CellInfo.nr.signalStrength.csiSinr;
12037                 records[i].info.nr(cellInfoNr);
12038                 break;
12039             }
12040             default: {
12041                 break;
12042             }
12043         }
12044         rillCellInfo += 1;
12045     }
12046 }
12047 
cellInfoListInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12048 int radio_1_6::cellInfoListInd(int slotId,
12049                            int indicationType, int token, RIL_Errno e, void *response,
12050                            size_t responseLen) {
12051     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12052         if ((response == NULL && responseLen != 0) || responseLen % sizeof(RIL_CellInfo_v12) != 0) {
12053             RLOGE("cellInfoListInd: invalid response");
12054             return 0;
12055         }
12056 
12057         hidl_vec<CellInfo> records;
12058         convertRilCellInfoListToHal(response, responseLen, records);
12059 
12060 #if VDBG
12061         RLOGD("cellInfoListInd");
12062 #endif
12063         Return<void> retStatus = radioService[slotId]->mRadioIndication->cellInfoList(
12064                 convertIntToRadioIndicationType(indicationType), records);
12065         radioService[slotId]->checkReturnStatus(retStatus);
12066     } else {
12067         RLOGE("cellInfoListInd: radioService[%d]->mRadioIndication == NULL", slotId);
12068     }
12069 
12070     return 0;
12071 }
12072 
imsNetworkStateChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12073 int radio_1_6::imsNetworkStateChangedInd(int slotId,
12074                                      int indicationType, int token, RIL_Errno e, void *response,
12075                                      size_t responseLen) {
12076     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12077 #if VDBG
12078         RLOGD("imsNetworkStateChangedInd");
12079 #endif
12080         Return<void> retStatus = radioService[slotId]->mRadioIndication->imsNetworkStateChanged(
12081                 convertIntToRadioIndicationType(indicationType));
12082         radioService[slotId]->checkReturnStatus(retStatus);
12083     } else {
12084         RLOGE("imsNetworkStateChangedInd: radioService[%d]->mRadioIndication == NULL",
12085                 slotId);
12086     }
12087 
12088     return 0;
12089 }
12090 
subscriptionStatusChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12091 int radio_1_6::subscriptionStatusChangedInd(int slotId,
12092                                         int indicationType, int token, RIL_Errno e, void *response,
12093                                         size_t responseLen) {
12094     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12095         if (response == NULL || responseLen != sizeof(int)) {
12096             RLOGE("subscriptionStatusChangedInd: invalid response");
12097             return 0;
12098         }
12099         bool activate = ((int32_t *) response)[0];
12100 #if VDBG
12101         RLOGD("subscriptionStatusChangedInd: activate %d", activate);
12102 #endif
12103         Return<void> retStatus = radioService[slotId]->mRadioIndication->subscriptionStatusChanged(
12104                 convertIntToRadioIndicationType(indicationType), activate);
12105         radioService[slotId]->checkReturnStatus(retStatus);
12106     } else {
12107         RLOGE("subscriptionStatusChangedInd: radioService[%d]->mRadioIndication == NULL",
12108                 slotId);
12109     }
12110 
12111     return 0;
12112 }
12113 
srvccStateNotifyInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12114 int radio_1_6::srvccStateNotifyInd(int slotId,
12115                                int indicationType, int token, RIL_Errno e, void *response,
12116                                size_t responseLen) {
12117     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12118         if (response == NULL || responseLen != sizeof(int)) {
12119             RLOGE("srvccStateNotifyInd: invalid response");
12120             return 0;
12121         }
12122         int32_t state = ((int32_t *) response)[0];
12123 #if VDBG
12124         RLOGD("srvccStateNotifyInd: rat %d", state);
12125 #endif
12126         Return<void> retStatus = radioService[slotId]->mRadioIndication->srvccStateNotify(
12127                 convertIntToRadioIndicationType(indicationType), (SrvccState) state);
12128         radioService[slotId]->checkReturnStatus(retStatus);
12129     } else {
12130         RLOGE("srvccStateNotifyInd: radioService[%d]->mRadioIndication == NULL", slotId);
12131     }
12132 
12133     return 0;
12134 }
12135 
convertRilHardwareConfigListToHal(void * response,size_t responseLen,hidl_vec<HardwareConfig> & records)12136 void convertRilHardwareConfigListToHal(void *response, size_t responseLen,
12137         hidl_vec<HardwareConfig>& records) {
12138     int num = responseLen / sizeof(RIL_HardwareConfig);
12139     records.resize(num);
12140 
12141     RIL_HardwareConfig *rilHardwareConfig = (RIL_HardwareConfig *) response;
12142     for (int i = 0; i < num; i++) {
12143         records[i].type = (HardwareConfigType) rilHardwareConfig[i].type;
12144         records[i].uuid = convertCharPtrToHidlString(rilHardwareConfig[i].uuid);
12145         records[i].state = (HardwareConfigState) rilHardwareConfig[i].state;
12146         switch (rilHardwareConfig[i].type) {
12147             case RIL_HARDWARE_CONFIG_MODEM: {
12148                 records[i].modem.resize(1);
12149                 records[i].sim.resize(0);
12150                 HardwareConfigModem *hwConfigModem = &records[i].modem[0];
12151                 hwConfigModem->rat = rilHardwareConfig[i].cfg.modem.rat;
12152                 hwConfigModem->maxVoice = rilHardwareConfig[i].cfg.modem.maxVoice;
12153                 hwConfigModem->maxData = rilHardwareConfig[i].cfg.modem.maxData;
12154                 hwConfigModem->maxStandby = rilHardwareConfig[i].cfg.modem.maxStandby;
12155                 break;
12156             }
12157 
12158             case RIL_HARDWARE_CONFIG_SIM: {
12159                 records[i].sim.resize(1);
12160                 records[i].modem.resize(0);
12161                 records[i].sim[0].modemUuid =
12162                         convertCharPtrToHidlString(rilHardwareConfig[i].cfg.sim.modemUuid);
12163                 break;
12164             }
12165         }
12166     }
12167 }
12168 
hardwareConfigChangedInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12169 int radio_1_6::hardwareConfigChangedInd(int slotId,
12170                                     int indicationType, int token, RIL_Errno e, void *response,
12171                                     size_t responseLen) {
12172     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12173         if ((response == NULL && responseLen != 0)
12174                 || responseLen % sizeof(RIL_HardwareConfig) != 0) {
12175             RLOGE("hardwareConfigChangedInd: invalid response");
12176             return 0;
12177         }
12178 
12179         hidl_vec<HardwareConfig> configs;
12180         convertRilHardwareConfigListToHal(response, responseLen, configs);
12181 
12182 #if VDBG
12183         RLOGD("hardwareConfigChangedInd");
12184 #endif
12185         Return<void> retStatus = radioService[slotId]->mRadioIndication->hardwareConfigChanged(
12186                 convertIntToRadioIndicationType(indicationType), configs);
12187         radioService[slotId]->checkReturnStatus(retStatus);
12188     } else {
12189         RLOGE("hardwareConfigChangedInd: radioService[%d]->mRadioIndication == NULL",
12190                 slotId);
12191     }
12192 
12193     return 0;
12194 }
12195 
convertRilRadioCapabilityToHal(void * response,size_t responseLen,RadioCapability & rc)12196 void convertRilRadioCapabilityToHal(void *response, size_t responseLen, RadioCapability& rc) {
12197     RIL_RadioCapability *rilRadioCapability = (RIL_RadioCapability *) response;
12198     rc.session = rilRadioCapability->session;
12199     rc.phase = (V1_0::RadioCapabilityPhase) rilRadioCapability->phase;
12200     rc.raf = rilRadioCapability->rat;
12201     rc.logicalModemUuid = convertCharPtrToHidlString(rilRadioCapability->logicalModemUuid);
12202     rc.status = (V1_0::RadioCapabilityStatus) rilRadioCapability->status;
12203 }
12204 
radioCapabilityIndicationInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12205 int radio_1_6::radioCapabilityIndicationInd(int slotId,
12206                                         int indicationType, int token, RIL_Errno e, void *response,
12207                                         size_t responseLen) {
12208     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12209         if (response == NULL || responseLen != sizeof(RIL_RadioCapability)) {
12210             RLOGE("radioCapabilityIndicationInd: invalid response");
12211             return 0;
12212         }
12213 
12214         RadioCapability rc = {};
12215         convertRilRadioCapabilityToHal(response, responseLen, rc);
12216 
12217 #if VDBG
12218         RLOGD("radioCapabilityIndicationInd");
12219 #endif
12220         Return<void> retStatus = radioService[slotId]->mRadioIndication->radioCapabilityIndication(
12221                 convertIntToRadioIndicationType(indicationType), rc);
12222         radioService[slotId]->checkReturnStatus(retStatus);
12223     } else {
12224         RLOGE("radioCapabilityIndicationInd: radioService[%d]->mRadioIndication == NULL",
12225                 slotId);
12226     }
12227 
12228     return 0;
12229 }
12230 
isServiceTypeCfQuery(RIL_SsServiceType serType,RIL_SsRequestType reqType)12231 bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
12232     if ((reqType == SS_INTERROGATION) &&
12233         (serType == SS_CFU ||
12234          serType == SS_CF_BUSY ||
12235          serType == SS_CF_NO_REPLY ||
12236          serType == SS_CF_NOT_REACHABLE ||
12237          serType == SS_CF_ALL ||
12238          serType == SS_CF_ALL_CONDITIONAL)) {
12239         return true;
12240     }
12241     return false;
12242 }
12243 
onSupplementaryServiceIndicationInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12244 int radio_1_6::onSupplementaryServiceIndicationInd(int slotId,
12245                                                int indicationType, int token, RIL_Errno e,
12246                                                void *response, size_t responseLen) {
12247     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12248         if (response == NULL || responseLen != sizeof(RIL_StkCcUnsolSsResponse)) {
12249             RLOGE("onSupplementaryServiceIndicationInd: invalid response");
12250             return 0;
12251         }
12252 
12253         RIL_StkCcUnsolSsResponse *rilSsResponse = (RIL_StkCcUnsolSsResponse *) response;
12254         StkCcUnsolSsResult ss = {};
12255         ss.serviceType = (SsServiceType) rilSsResponse->serviceType;
12256         ss.requestType = (SsRequestType) rilSsResponse->requestType;
12257         ss.teleserviceType = (SsTeleserviceType) rilSsResponse->teleserviceType;
12258         ss.serviceClass = rilSsResponse->serviceClass;
12259         ss.result = (RadioError) rilSsResponse->result;
12260 
12261         if (isServiceTypeCfQuery(rilSsResponse->serviceType, rilSsResponse->requestType)) {
12262 #if VDBG
12263             RLOGD("onSupplementaryServiceIndicationInd CF type, num of Cf elements %d",
12264                     rilSsResponse->cfData.numValidIndexes);
12265 #endif
12266             if (rilSsResponse->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
12267                 RLOGE("onSupplementaryServiceIndicationInd numValidIndexes is greater than "
12268                         "max value %d, truncating it to max value", NUM_SERVICE_CLASSES);
12269                 rilSsResponse->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
12270             }
12271 
12272             ss.cfData.resize(1);
12273             ss.ssInfo.resize(0);
12274 
12275             /* number of call info's */
12276             ss.cfData[0].cfInfo.resize(rilSsResponse->cfData.numValidIndexes);
12277 
12278             for (int i = 0; i < rilSsResponse->cfData.numValidIndexes; i++) {
12279                  RIL_CallForwardInfo cf = rilSsResponse->cfData.cfInfo[i];
12280                  CallForwardInfo *cfInfo = &ss.cfData[0].cfInfo[i];
12281 
12282                  cfInfo->status = (CallForwardInfoStatus) cf.status;
12283                  cfInfo->reason = cf.reason;
12284                  cfInfo->serviceClass = cf.serviceClass;
12285                  cfInfo->toa = cf.toa;
12286                  cfInfo->number = convertCharPtrToHidlString(cf.number);
12287                  cfInfo->timeSeconds = cf.timeSeconds;
12288 #if VDBG
12289                  RLOGD("onSupplementaryServiceIndicationInd: "
12290                         "Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
12291                         cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
12292 #endif
12293             }
12294         } else {
12295             ss.ssInfo.resize(1);
12296             ss.cfData.resize(0);
12297 
12298             /* each int */
12299             ss.ssInfo[0].ssInfo.resize(SS_INFO_MAX);
12300             for (int i = 0; i < SS_INFO_MAX; i++) {
12301 #if VDBG
12302                  RLOGD("onSupplementaryServiceIndicationInd: Data: %d",
12303                         rilSsResponse->ssInfo[i]);
12304 #endif
12305                  ss.ssInfo[0].ssInfo[i] = rilSsResponse->ssInfo[i];
12306             }
12307         }
12308 
12309 #if VDBG
12310         RLOGD("onSupplementaryServiceIndicationInd");
12311 #endif
12312         Return<void> retStatus = radioService[slotId]->mRadioIndication->
12313                 onSupplementaryServiceIndication(convertIntToRadioIndicationType(indicationType),
12314                 ss);
12315         radioService[slotId]->checkReturnStatus(retStatus);
12316     } else {
12317         RLOGE("onSupplementaryServiceIndicationInd: "
12318                 "radioService[%d]->mRadioIndication == NULL", slotId);
12319     }
12320 
12321     return 0;
12322 }
12323 
stkCallControlAlphaNotifyInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12324 int radio_1_6::stkCallControlAlphaNotifyInd(int slotId,
12325                                         int indicationType, int token, RIL_Errno e, void *response,
12326                                         size_t responseLen) {
12327     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12328         if (response == NULL || responseLen == 0) {
12329             RLOGE("stkCallControlAlphaNotifyInd: invalid response");
12330             return 0;
12331         }
12332 #if VDBG
12333         RLOGD("stkCallControlAlphaNotifyInd");
12334 #endif
12335         Return<void> retStatus = radioService[slotId]->mRadioIndication->stkCallControlAlphaNotify(
12336                 convertIntToRadioIndicationType(indicationType),
12337                 convertCharPtrToHidlString((char *) response));
12338         radioService[slotId]->checkReturnStatus(retStatus);
12339     } else {
12340         RLOGE("stkCallControlAlphaNotifyInd: radioService[%d]->mRadioIndication == NULL",
12341                 slotId);
12342     }
12343 
12344     return 0;
12345 }
12346 
convertRilLceDataInfoToHal(void * response,size_t responseLen,LceDataInfo & lce)12347 void convertRilLceDataInfoToHal(void *response, size_t responseLen, LceDataInfo& lce) {
12348     RIL_LceDataInfo *rilLceDataInfo = (RIL_LceDataInfo *)response;
12349     lce.lastHopCapacityKbps = rilLceDataInfo->last_hop_capacity_kbps;
12350     lce.confidenceLevel = rilLceDataInfo->confidence_level;
12351     lce.lceSuspended = rilLceDataInfo->lce_suspended;
12352 }
12353 
lceDataInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12354 int radio_1_6::lceDataInd(int slotId,
12355                       int indicationType, int token, RIL_Errno e, void *response,
12356                       size_t responseLen) {
12357     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12358         if (response == NULL || responseLen != sizeof(RIL_LceDataInfo)) {
12359             RLOGE("lceDataInd: invalid response");
12360             return 0;
12361         }
12362 
12363         LceDataInfo lce = {};
12364         convertRilLceDataInfoToHal(response, responseLen, lce);
12365 #if VDBG
12366         RLOGD("lceDataInd");
12367 #endif
12368         Return<void> retStatus = radioService[slotId]->mRadioIndication->lceData(
12369                 convertIntToRadioIndicationType(indicationType), lce);
12370         radioService[slotId]->checkReturnStatus(retStatus);
12371     } else {
12372         RLOGE("lceDataInd: radioService[%d]->mRadioIndication == NULL", slotId);
12373     }
12374 
12375     return 0;
12376 }
12377 
pcoDataInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12378 int radio_1_6::pcoDataInd(int slotId,
12379                       int indicationType, int token, RIL_Errno e, void *response,
12380                       size_t responseLen) {
12381     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12382         if (response == NULL || responseLen != sizeof(RIL_PCO_Data)) {
12383             RLOGE("pcoDataInd: invalid response");
12384             return 0;
12385         }
12386 
12387         PcoDataInfo pco = {};
12388         RIL_PCO_Data *rilPcoData = (RIL_PCO_Data *)response;
12389         pco.cid = rilPcoData->cid;
12390         pco.bearerProto = convertCharPtrToHidlString(rilPcoData->bearer_proto);
12391         pco.pcoId = rilPcoData->pco_id;
12392         pco.contents.setToExternal((uint8_t *) rilPcoData->contents, rilPcoData->contents_length);
12393 
12394 #if VDBG
12395         RLOGD("pcoDataInd");
12396 #endif
12397         Return<void> retStatus = radioService[slotId]->mRadioIndication->pcoData(
12398                 convertIntToRadioIndicationType(indicationType), pco);
12399         radioService[slotId]->checkReturnStatus(retStatus);
12400     } else {
12401         RLOGE("pcoDataInd: radioService[%d]->mRadioIndication == NULL", slotId);
12402     }
12403 
12404     return 0;
12405 }
12406 
modemResetInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12407 int radio_1_6::modemResetInd(int slotId,
12408                          int indicationType, int token, RIL_Errno e, void *response,
12409                          size_t responseLen) {
12410     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndication != NULL) {
12411         if (response == NULL || responseLen == 0) {
12412             RLOGE("modemResetInd: invalid response");
12413             return 0;
12414         }
12415 #if VDBG
12416         RLOGD("modemResetInd");
12417 #endif
12418         Return<void> retStatus = radioService[slotId]->mRadioIndication->modemReset(
12419                 convertIntToRadioIndicationType(indicationType),
12420                 convertCharPtrToHidlString((char *) response));
12421         radioService[slotId]->checkReturnStatus(retStatus);
12422     } else {
12423         RLOGE("modemResetInd: radioService[%d]->mRadioIndication == NULL", slotId);
12424     }
12425 
12426     return 0;
12427 }
12428 
networkScanResultInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12429 int radio_1_6::networkScanResultInd(int slotId,
12430                                 int indicationType, int token, RIL_Errno e, void *response,
12431                                 size_t responseLen) {
12432 #if VDBG
12433     RLOGD("networkScanResultInd");
12434 #endif
12435     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndicationV1_4 != NULL) {
12436         if (response == NULL || responseLen == 0) {
12437             RLOGE("networkScanResultInd: invalid response");
12438             return 0;
12439         }
12440         RLOGD("networkScanResultInd");
12441 
12442 #if VDBG
12443         RLOGD("networkScanResultInd");
12444 #endif
12445 
12446         RIL_NetworkScanResult *networkScanResult = (RIL_NetworkScanResult *) response;
12447 
12448         V1_1::NetworkScanResult result;
12449         result.status = (V1_1::ScanStatus) networkScanResult->status;
12450         result.error = (RadioError) networkScanResult->error;
12451         convertRilCellInfoListToHal(
12452                 networkScanResult->network_infos,
12453                 networkScanResult->network_infos_length * sizeof(RIL_CellInfo_v12),
12454                 result.networkInfos);
12455 
12456         Return<void> retStatus = radioService[slotId]->mRadioIndicationV1_4->networkScanResult(
12457                 convertIntToRadioIndicationType(indicationType), result);
12458         radioService[slotId]->checkReturnStatus(retStatus);
12459     } else {
12460         RLOGE("networkScanResultInd: radioService[%d]->mRadioIndicationV1_4 == NULL", slotId);
12461     }
12462     return 0;
12463 }
12464 
carrierInfoForImsiEncryption(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12465 int radio_1_6::carrierInfoForImsiEncryption(int slotId,
12466                                   int indicationType, int token, RIL_Errno e, void *response,
12467                                   size_t responseLen) {
12468     if (radioService[slotId] != NULL && radioService[slotId]->mRadioIndicationV1_4 != NULL) {
12469         if (response == NULL || responseLen == 0) {
12470             RLOGE("carrierInfoForImsiEncryption: invalid response");
12471             return 0;
12472         }
12473         RLOGD("carrierInfoForImsiEncryption");
12474         Return<void> retStatus = radioService[slotId]->mRadioIndicationV1_4->
12475                 carrierInfoForImsiEncryption(convertIntToRadioIndicationType(indicationType));
12476         radioService[slotId]->checkReturnStatus(retStatus);
12477     } else {
12478         RLOGE("carrierInfoForImsiEncryption: radioService[%d]->mRadioIndicationV1_4 == NULL",
12479                 slotId);
12480     }
12481 
12482     return 0;
12483 }
12484 
reportPhysicalChannelConfigs(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12485 int radio_1_6::reportPhysicalChannelConfigs(int slotId, int indicationType,
12486                                             int token, RIL_Errno e,
12487                                             void *response,
12488                                             size_t responseLen) {
12489     if (radioService[slotId] != NULL &&
12490         radioService[slotId]->mRadioIndicationV1_4 != NULL) {
12491       int *configs = (int *)response;
12492       ::android::hardware::hidl_vec<PhysicalChannelConfigV1_4> physChanConfig;
12493       physChanConfig.resize(1);
12494       physChanConfig[0].base.status =
12495           (::android::hardware::radio::V1_2::CellConnectionStatus)configs[0];
12496       physChanConfig[0].base.cellBandwidthDownlink = configs[1];
12497       physChanConfig[0].rat =
12498           (::android::hardware::radio::V1_4::RadioTechnology)configs[2];
12499       physChanConfig[0].rfInfo.range(
12500           (::android::hardware::radio::V1_4::FrequencyRange)configs[3]);
12501       physChanConfig[0].contextIds.resize(1);
12502       physChanConfig[0].contextIds[0] = configs[4];
12503       RLOGD("reportPhysicalChannelConfigs: %d %d %d %d %d", configs[0],
12504             configs[1], configs[2], configs[3], configs[4]);
12505       Return<void> retStatus = radioService[slotId]
12506           ->mRadioIndicationV1_4->currentPhysicalChannelConfigs_1_4(
12507               RadioIndicationType::UNSOLICITED, physChanConfig);
12508       radioService[slotId]->checkReturnStatus(retStatus);
12509       {
12510           // just send the link estimate along with physical channel
12511           // config, as it has at least the downlink bandwidth.
12512           // Note: the bandwidth is just some hardcoded
12513           // value, as there is not way to get that reliably on
12514           // virtual devices, as of now.
12515           V1_2::LinkCapacityEstimate lce = {
12516             .downlinkCapacityKbps = static_cast<uint32_t>(configs[1]),
12517             .uplinkCapacityKbps = static_cast<uint32_t>(configs[1])
12518           };
12519         RLOGD("reporting link capacity estimate download: %d upload: %d",
12520                         lce.downlinkCapacityKbps, lce.uplinkCapacityKbps );
12521         Return<void> retStatus = radioService[slotId]->mRadioIndicationV1_4->
12522             currentLinkCapacityEstimate(RadioIndicationType::UNSOLICITED, lce);
12523         radioService[slotId]->checkReturnStatus(retStatus);
12524       }
12525     } else {
12526       RLOGE(
12527           "reportPhysicalChannelConfigs: radioService[%d]->mRadioIndicationV1_4 "
12528           "== NULL",
12529           slotId);
12530       return -1;
12531     }
12532 
12533   return 0;
12534 }
12535 
keepaliveStatusInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12536 int radio_1_6::keepaliveStatusInd(int slotId,
12537                          int indicationType, int token, RIL_Errno e, void *response,
12538                          size_t responseLen) {
12539 #if VDBG
12540     RLOGD("%s(): token=%d", __FUNCTION__, token);
12541 #endif
12542     if (radioService[slotId] == NULL || radioService[slotId]->mRadioIndication == NULL) {
12543         RLOGE("%s: radioService[%d]->mRadioIndication == NULL", __FUNCTION__, slotId);
12544         return 0;
12545     }
12546 
12547     auto ret = V1_1::IRadioIndication::castFrom(
12548         radioService[slotId]->mRadioIndication);
12549     if (!ret.isOk()) {
12550         RLOGE("%s: ret.isOk() == false for radioService[%d]", __FUNCTION__, slotId);
12551         return 0;
12552     }
12553     sp<V1_1::IRadioIndication> radioIndicationV1_1 = ret;
12554 
12555     if (response == NULL || responseLen != sizeof(V1_1::KeepaliveStatus)) {
12556         RLOGE("%s: invalid response", __FUNCTION__);
12557         return 0;
12558     }
12559 
12560     V1_1::KeepaliveStatus ks;
12561     convertRilKeepaliveStatusToHal(static_cast<RIL_KeepaliveStatus*>(response), ks);
12562 
12563     Return<void> retStatus = radioIndicationV1_1->keepaliveStatus(
12564             convertIntToRadioIndicationType(indicationType), ks);
12565     radioService[slotId]->checkReturnStatus(retStatus);
12566     return 0;
12567 }
12568 
oemHookRawInd(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)12569 int radio_1_6::oemHookRawInd(int slotId,
12570                          int indicationType, int token, RIL_Errno e, void *response,
12571                          size_t responseLen) {
12572     if (!kOemHookEnabled) return 0;
12573 
12574     if (oemHookService[slotId] != NULL && oemHookService[slotId]->mOemHookIndication != NULL) {
12575         if (response == NULL || responseLen == 0) {
12576             RLOGE("oemHookRawInd: invalid response");
12577             return 0;
12578         }
12579 
12580         hidl_vec<uint8_t> data;
12581         data.setToExternal((uint8_t *) response, responseLen);
12582 #if VDBG
12583         RLOGD("oemHookRawInd");
12584 #endif
12585         Return<void> retStatus = oemHookService[slotId]->mOemHookIndication->oemHookRaw(
12586                 convertIntToRadioIndicationType(indicationType), data);
12587         checkReturnStatus(slotId, retStatus, false);
12588     } else {
12589         RLOGE("oemHookRawInd: oemHookService[%d]->mOemHookIndication == NULL", slotId);
12590     }
12591 
12592     return 0;
12593 }
12594 
registerService(RIL_RadioFunctions * callbacks,CommandInfo * commands)12595 void radio_1_6::registerService(RIL_RadioFunctions *callbacks, CommandInfo *commands) {
12596     using namespace android::hardware;
12597     int simCount = 1;
12598     const char *serviceNames[] = {
12599             android::RIL_getServiceName()
12600             #if (SIM_COUNT >= 2)
12601             , RIL2_SERVICE_NAME
12602             #if (SIM_COUNT >= 3)
12603             , RIL3_SERVICE_NAME
12604             #if (SIM_COUNT >= 4)
12605             , RIL4_SERVICE_NAME
12606             #endif
12607             #endif
12608             #endif
12609             };
12610 
12611     #if (SIM_COUNT >= 2)
12612     simCount = SIM_COUNT;
12613     #endif
12614 
12615     s_vendorFunctions = callbacks;
12616     s_commands = commands;
12617 
12618     configureRpcThreadpool(1, true /* callerWillJoin */);
12619     for (int i = 0; i < simCount; i++) {
12620         pthread_rwlock_t *radioServiceRwlockPtr = getRadioServiceRwlock(i);
12621         int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
12622         assert(ret == 0);
12623 
12624         RLOGD("sim i = %d registering ...", i);
12625 
12626         radioService[i] = new RadioImpl_1_6;
12627         radioService[i]->mSlotId = i;
12628         RLOGD("registerService: initializing power state to POWER_UP");
12629         radioService[i]->mSimCardPowerState = V1_1::CardPowerState::POWER_UP;
12630         RLOGD("registerService: starting android::hardware::radio::V1_6::IRadio %s for slot %d",
12631                 serviceNames[i], i);
12632         android::status_t status = radioService[i]->registerAsService(serviceNames[i]);
12633         LOG_ALWAYS_FATAL_IF(status != android::OK, "status %d", status);
12634 
12635         RLOGD("registerService: OemHook is enabled = %s", kOemHookEnabled ? "true" : "false");
12636         if (kOemHookEnabled) {
12637             oemHookService[i] = new OemHookImpl;
12638             oemHookService[i]->mSlotId = i;
12639             // status = oemHookService[i]->registerAsService(serviceNames[i]);
12640         }
12641 
12642         ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
12643         assert(ret == 0);
12644     }
12645 }
12646 
rilc_thread_pool()12647 void rilc_thread_pool() {
12648     joinRpcThreadpool();
12649 }
12650 
getRadioServiceRwlock(int slotId)12651 pthread_rwlock_t * radio_1_6::getRadioServiceRwlock(int slotId) {
12652     pthread_rwlock_t *radioServiceRwlockPtr = &radioServiceRwlock;
12653 
12654     #if (SIM_COUNT >= 2)
12655     if (slotId == 2) radioServiceRwlockPtr = &radioServiceRwlock2;
12656     #if (SIM_COUNT >= 3)
12657     if (slotId == 3) radioServiceRwlockPtr = &radioServiceRwlock3;
12658     #if (SIM_COUNT >= 4)
12659     if (slotId == 4) radioServiceRwlockPtr = &radioServiceRwlock4;
12660     #endif
12661     #endif
12662     #endif
12663 
12664     return radioServiceRwlockPtr;
12665 }
12666 
12667 // should acquire write lock for the corresponding service before calling this
setNitzTimeReceived(int slotId,long timeReceived)12668 void radio_1_6::setNitzTimeReceived(int slotId, long timeReceived) {
12669     nitzTimeReceived[slotId] = timeReceived;
12670 }
12671