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