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