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