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