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