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