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