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