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