• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **
3 ** Copyright 2020, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #define LOG_TAG "RILC"
19 
20 #include "RefRadioConfig.h"
21 
22 #include <android-base/logging.h>
23 #include <android/binder_manager.h>
24 #include <android/binder_process.h>
25 
26 #pragma clang diagnostic push
27 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
28 #include <android/hardware/radio/config/1.1/IRadioConfig.h>
29 #include <android/hardware/radio/config/1.2/IRadioConfigIndication.h>
30 #include <android/hardware/radio/config/1.2/IRadioConfigResponse.h>
31 #include <android/hardware/radio/config/1.3/IRadioConfig.h>
32 #include <android/hardware/radio/config/1.3/IRadioConfigResponse.h>
33 #include <libradiocompat/RadioConfig.h>
34 #pragma clang diagnostic pop
35 
36 #include <ril.h>
37 #include <guest/hals/ril/reference-libril/ril_service.h>
38 #include <hidl/HidlTransportSupport.h>
39 
40 using namespace android::hardware::radio::V1_0;
41 using namespace android::hardware::radio::config;
42 using namespace android::hardware::radio::config::V1_0;
43 using namespace android::hardware::radio::config::V1_3;
44 using ::android::hardware::Return;
45 using ::android::hardware::hidl_string;
46 using ::android::hardware::hidl_vec;
47 using ::android::hardware::Void;
48 using android::CommandInfo;
49 using android::RequestInfo;
50 using android::requestToString;
51 using android::sp;
52 
53 RIL_RadioFunctions *s_vendorFunctions_config = NULL;
54 static CommandInfo *s_configCommands;
55 struct RadioConfigImpl;
56 sp<RadioConfigImpl> radioConfigService;
57 std::atomic_int32_t mCounterRadioConfig;
58 
59 #if defined (ANDROID_MULTI_SIM)
60 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
61 #define CALL_ONREQUEST(a, b, c, d, e) s_vendorFunctions_config->onRequest((a), (b), (c), (d), (e))
62 #define CALL_ONSTATEREQUEST(a) s_vendorFunctions_config->onStateRequest(a)
63 #else
64 #define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
65 #define CALL_ONREQUEST(a, b, c, d, e) s_vendorFunctions_config->onRequest((a), (b), (c), (d))
66 #define CALL_ONSTATEREQUEST(a) s_vendorFunctions_config->onStateRequest()
67 #endif
68 
69 extern void populateResponseInfo(RadioResponseInfo& responseInfo, int serial, int responseType,
70                 RIL_Errno e);
71 
72 extern void populateResponseInfo_1_6(
73     ::android::hardware::radio::V1_6::RadioResponseInfo &responseInfo,
74     int serial, int responseType, RIL_Errno e);
75 
76 extern bool dispatchVoid(int serial, int slotId, int request);
77 extern bool dispatchString(int serial, int slotId, int request, const char * str);
78 extern bool dispatchStrings(int serial, int slotId, int request, bool allowEmpty,
79                 int countStrings, ...);
80 extern bool dispatchInts(int serial, int slotId, int request, int countInts, ...);
81 extern hidl_string convertCharPtrToHidlString(const char *ptr);
82 extern void sendErrorResponse(android::RequestInfo *pRI, RIL_Errno err);
83 extern RadioIndicationType convertIntToRadioIndicationType(int indicationType);
84 
85 extern bool isChangeSlotId(int serviceId, int slotId);
86 
87 struct RadioConfigImpl : public V1_3::IRadioConfig {
88     int32_t mSlotId;
89     sp<V1_0::IRadioConfigResponse> mRadioConfigResponse;
90     sp<V1_0::IRadioConfigIndication> mRadioConfigIndication;
91     sp<V1_1::IRadioConfigResponse> mRadioConfigResponseV1_1;
92     sp<V1_2::IRadioConfigResponse> mRadioConfigResponseV1_2;
93     sp<V1_2::IRadioConfigIndication> mRadioConfigIndicationV1_2;
94     sp<V1_3::IRadioConfigResponse> mRadioConfigResponseV1_3;
95 
96     Return<void> setResponseFunctions(
97             const ::android::sp<V1_0::IRadioConfigResponse>& radioConfigResponse,
98             const ::android::sp<V1_0::IRadioConfigIndication>& radioConfigIndication);
99 
100     Return<void> getSimSlotsStatus(int32_t serial);
101 
102     Return<void> setSimSlotsMapping(int32_t serial, const hidl_vec<uint32_t>& slotMap);
103 
104     Return<void> getPhoneCapability(int32_t serial);
105 
106     Return<void> setPreferredDataModem(int32_t serial, uint8_t modemId);
107 
108     Return<void> setModemsConfig(int32_t serial, const V1_1::ModemsConfig& modemsConfig);
109 
110     Return<void> getModemsConfig(int32_t serial);
111 
112     Return<void> getHalDeviceCapabilities(int32_t serial);
113 
114     void checkReturnStatus_config(Return<void>& ret);
115 };
setResponseFunctions(const::android::sp<V1_0::IRadioConfigResponse> & radioConfigResponse,const::android::sp<V1_0::IRadioConfigIndication> & radioConfigIndication)116 Return<void> RadioConfigImpl::setResponseFunctions(
117         const ::android::sp<V1_0::IRadioConfigResponse>& radioConfigResponse,
118         const ::android::sp<V1_0::IRadioConfigIndication>& radioConfigIndication) {
119     pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(RIL_SOCKET_1);
120     int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
121     CHECK_EQ(ret, 0);
122 
123     mRadioConfigResponse = radioConfigResponse;
124     mRadioConfigIndication = radioConfigIndication;
125 
126 
127     mRadioConfigResponseV1_1 =
128         V1_1::IRadioConfigResponse::castFrom(mRadioConfigResponse).withDefault(nullptr);
129     if (mRadioConfigResponseV1_1 == nullptr) {
130         mRadioConfigResponseV1_1 = nullptr;
131     }
132 
133     mRadioConfigResponseV1_2 =
134         V1_2::IRadioConfigResponse::castFrom(mRadioConfigResponse).withDefault(nullptr);
135     mRadioConfigIndicationV1_2 =
136         V1_2::IRadioConfigIndication::castFrom(mRadioConfigIndication).withDefault(nullptr);
137     if (mRadioConfigResponseV1_2 == nullptr || mRadioConfigIndicationV1_2 == nullptr) {
138         mRadioConfigResponseV1_2 = nullptr;
139         mRadioConfigIndicationV1_2 = nullptr;
140     }
141 
142     mRadioConfigResponseV1_3 =
143         V1_3::IRadioConfigResponse::castFrom(mRadioConfigResponse).withDefault(nullptr);
144     if (mRadioConfigResponseV1_3 == nullptr || mRadioConfigResponseV1_3 == nullptr) {
145         mRadioConfigResponseV1_3 = nullptr;
146     }
147 
148     mCounterRadioConfig++;
149 
150     ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
151     CHECK_EQ(ret, 0);
152 
153     return Void();
154 }
155 
getSimSlotsStatus(int32_t serial)156 Return<void> RadioConfigImpl::getSimSlotsStatus(int32_t serial) {
157 #if VDBG
158     RLOGD("getSimSlotsStatus: serial %d", serial);
159 #endif
160     dispatchVoid(serial, mSlotId, RIL_REQUEST_CONFIG_GET_SLOT_STATUS);
161 
162     return Void();
163 }
164 
setSimSlotsMapping(int32_t serial,const hidl_vec<uint32_t> & slotMap)165 Return<void> RadioConfigImpl::setSimSlotsMapping(int32_t serial, const hidl_vec<uint32_t>& slotMap) {
166 #if VDBG
167     RLOGD("setSimSlotsMapping: serial %d", serial);
168 #endif
169     RequestInfo *pRI = android::addRequestToList(serial, RIL_SOCKET_1,
170         RIL_REQUEST_CONFIG_SET_SLOT_MAPPING);
171     if (pRI == NULL) {
172         return Void();
173     }
174     size_t slotNum = slotMap.size();
175 
176     if (slotNum > MAX_LOGICAL_MODEM_NUM) {
177         RLOGE("setSimSlotsMapping: invalid parameter");
178         sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
179         return Void();
180     }
181 
182     for (size_t socket_id = 0; socket_id < slotNum; socket_id++) {
183         if (slotMap[socket_id] >= MAX_LOGICAL_MODEM_NUM) {
184             RLOGE("setSimSlotsMapping: invalid parameter[%zu]", socket_id);
185             sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
186             return Void();
187         }
188         // confirm logical id is not duplicate
189         for (size_t nextId = socket_id + 1; nextId < slotNum; nextId++) {
190             if (slotMap[socket_id] == slotMap[nextId]) {
191                 RLOGE("setSimSlotsMapping: slot parameter is the same:[%zu] and [%zu]",
192                     socket_id, nextId);
193                 sendErrorResponse(pRI, RIL_E_INVALID_ARGUMENTS);
194                 return Void();
195             }
196         }
197     }
198     int *pSlotMap = (int *)calloc(slotNum, sizeof(int));
199 
200     for (size_t socket_id = 0; socket_id < slotNum; socket_id++) {
201         pSlotMap[socket_id] = slotMap[socket_id];
202     }
203 
204     CALL_ONREQUEST(RIL_REQUEST_CONFIG_SET_SLOT_MAPPING, pSlotMap,
205         slotNum * sizeof(int), pRI, pRI->socket_id);
206     if (pSlotMap != NULL) {
207         free(pSlotMap);
208     }
209 
210     return Void();
211 }
212 
getPhoneCapability(int32_t serial)213 Return<void> RadioConfigImpl::getPhoneCapability(int32_t serial) {
214 #if VDBG
215     RLOGD("getPhoneCapability: serial %d", serial);
216 #endif
217     dispatchVoid(serial, mSlotId, RIL_REQUEST_CONFIG_GET_PHONE_CAPABILITY);
218     return Void();
219 }
220 
setPreferredDataModem(int32_t serial,uint8_t modemId)221 Return<void> RadioConfigImpl::setPreferredDataModem(int32_t serial, uint8_t modemId) {
222 #if VDBG
223     RLOGD("setPreferredDataModem: serial %d", serial);
224 #endif
225     dispatchInts(serial, mSlotId, RIL_REQUEST_CONFIG_SET_PREFER_DATA_MODEM, 1, modemId);
226     return Void();
227 }
228 
setModemsConfig(int32_t serial,const V1_1::ModemsConfig & modemsConfig)229 Return<void> RadioConfigImpl::setModemsConfig(int32_t serial, const V1_1::ModemsConfig& modemsConfig) {
230 #if VDBG
231     RLOGD("setModemsConfig: serial %d", serial);
232 #endif
233     RequestInfo *pRI = android::addRequestToList(serial, mSlotId,
234         RIL_REQUEST_CONFIG_SET_MODEM_CONFIG);
235     if (pRI == NULL) {
236         return Void();
237     }
238 
239     RIL_ModemConfig mdConfig = {};
240 
241     mdConfig.numOfLiveModems = modemsConfig.numOfLiveModems;
242 
243 
244     CALL_ONREQUEST(RIL_REQUEST_CONFIG_SET_MODEM_CONFIG, &mdConfig,
245         sizeof(RIL_ModemConfig), pRI, pRI->socket_id);
246 
247     return Void();
248 }
249 
getModemsConfig(int32_t serial)250 Return<void> RadioConfigImpl::getModemsConfig(int32_t serial) {
251 #if VDBG
252     RLOGD("getModemsConfig: serial %d", serial);
253 #endif
254     dispatchVoid(serial, mSlotId, RIL_REQUEST_CONFIG_GET_MODEM_CONFIG);
255     return Void();
256 }
257 
getHalDeviceCapabilities(int32_t serial)258 Return<void> RadioConfigImpl::getHalDeviceCapabilities(int32_t serial) {
259 #if VDBG
260     RLOGD("getHalDeviceCapabilities: serial %d", serial);
261 #endif
262     dispatchVoid(serial, mSlotId, RIL_REQUEST_CONFIG_GET_HAL_DEVICE_CAPABILITIES);
263     return Void();
264 }
265 
registerConfigService(RIL_RadioFunctions * callbacks,CommandInfo * commands)266 void radio_1_6::registerConfigService(RIL_RadioFunctions *callbacks, CommandInfo *commands) {
267     using namespace android::hardware;
268     using namespace std::string_literals;
269     namespace compat = android::hardware::radio::compat;
270 
271     RLOGD("Entry %s", __FUNCTION__);
272     const char *serviceNames = "default";
273 
274     s_vendorFunctions_config = callbacks;
275     s_configCommands = commands;
276 
277     int slotId = RIL_SOCKET_1;
278 
279     pthread_rwlock_t *radioServiceRwlockPtr = getRadioServiceRwlock(0);
280     int ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
281     CHECK_EQ(ret, 0);
282     RLOGD("registerConfigService: starting V1_2::IConfigRadio %s", serviceNames);
283     radioConfigService = new RadioConfigImpl;
284 
285     radioConfigService->mSlotId = slotId;
286     radioConfigService->mRadioConfigResponse = NULL;
287     radioConfigService->mRadioConfigIndication = NULL;
288     radioConfigService->mRadioConfigResponseV1_1 = NULL;
289     radioConfigService->mRadioConfigResponseV1_2 = NULL;
290     radioConfigService->mRadioConfigResponseV1_3 = NULL;
291     radioConfigService->mRadioConfigIndicationV1_2 = NULL;
292 
293     // use a compat shim to convert HIDL interface to AIDL and publish it
294     // TODO(bug 220004469): replace with a full AIDL implementation
295     static auto aidlHal = ndk::SharedRefBase::make<cf::ril::RefRadioConfig>(radioConfigService);
296     const auto instance = compat::RadioConfig::descriptor + "/"s + std::string(serviceNames);
297     const auto status = AServiceManager_addService(aidlHal->asBinder().get(), instance.c_str());
298     RLOGD("registerConfigService addService: status %d", status);
299     CHECK_EQ(status, STATUS_OK);
300 
301     ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
302     CHECK_EQ(ret, 0);
303 }
304 
checkReturnStatus(Return<void> & ret)305 void checkReturnStatus(Return<void>& ret) {
306     if (ret.isOk() == false) {
307         RLOGE("checkReturnStatus_config: unable to call response/indication callback");
308         // Remote process hosting the callbacks must be dead. Reset the callback objects;
309         // there's no other recovery to be done here. When the client process is back up, it will
310         // call setResponseFunctions()
311 
312         // Caller should already hold rdlock, release that first
313         // note the current counter to avoid overwriting updates made by another thread before
314         // write lock is acquired.
315         int32_t counter = mCounterRadioConfig.load();
316         pthread_rwlock_t *radioServiceRwlockPtr = radio_1_6::getRadioServiceRwlock(0);
317         int ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
318         CHECK_EQ(ret, 0);
319 
320         // acquire wrlock
321         ret = pthread_rwlock_wrlock(radioServiceRwlockPtr);
322         CHECK_EQ(ret, 0);
323 
324         // make sure the counter value has not changed
325         if (counter == mCounterRadioConfig) {
326             radioConfigService->mRadioConfigResponse = NULL;
327             radioConfigService->mRadioConfigIndication = NULL;
328             radioConfigService->mRadioConfigResponseV1_1 = NULL;
329             radioConfigService->mRadioConfigResponseV1_2 = NULL;
330             radioConfigService->mRadioConfigResponseV1_3 = NULL;
331             radioConfigService->mRadioConfigIndicationV1_2 = NULL;
332             mCounterRadioConfig++;
333         } else {
334             RLOGE("checkReturnStatus_config: not resetting responseFunctions as they likely "
335                   "got updated on another thread");
336         }
337 
338         // release wrlock
339         ret = pthread_rwlock_unlock(radioServiceRwlockPtr);
340         CHECK_EQ(ret, 0);
341 
342         // Reacquire rdlock
343         ret = pthread_rwlock_rdlock(radioServiceRwlockPtr);
344         CHECK_EQ(ret, 0);
345     }
346 }
347 
checkReturnStatus_config(Return<void> & ret)348 void RadioConfigImpl::checkReturnStatus_config(Return<void>& ret) {
349     ::checkReturnStatus(ret);
350 }
351 
getSimSlotsStatusResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)352 int radio_1_6::getSimSlotsStatusResponse(int slotId, int responseType, int serial,
353                                      RIL_Errno e, void *response, size_t responseLen) {
354 #if VDBG
355     RLOGD("getSimSlotsResponse: serial %d", serial);
356 #endif
357 
358     if (radioConfigService->mRadioConfigResponse != NULL) {
359         RadioResponseInfo responseInfo = {};
360         populateResponseInfo(responseInfo, serial, responseType, e);
361         hidl_vec<SimSlotStatus> simSlotStatus = {};
362 
363         if ((response == NULL) || (responseLen % sizeof(RIL_SimSlotStatus_V1_2) != 0)) {
364             RLOGE("getSimSlotsStatusResponse: Invalid response");
365             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
366         } else {
367             RIL_SimSlotStatus_V1_2 *psimSlotStatus = ((RIL_SimSlotStatus_V1_2 *) response);
368             int num = responseLen / sizeof(RIL_SimSlotStatus_V1_2);
369             simSlotStatus.resize(num);
370             for (int i = 0; i < num; i++) {
371                 simSlotStatus[i].cardState = (CardState)psimSlotStatus->base.cardState;
372                 simSlotStatus[i].slotState = (SlotState)psimSlotStatus->base.slotState;
373                 simSlotStatus[i].atr = convertCharPtrToHidlString(psimSlotStatus->base.atr);
374                 simSlotStatus[i].logicalSlotId = psimSlotStatus->base.logicalSlotId;
375                 simSlotStatus[i].iccid = convertCharPtrToHidlString(psimSlotStatus->base.iccid);
376                 psimSlotStatus += 1;
377             }
378         }
379         Return<void> retStatus = radioConfigService->mRadioConfigResponse->getSimSlotsStatusResponse(
380                 responseInfo, simSlotStatus);
381         radioConfigService->checkReturnStatus_config(retStatus);
382     } else {
383         RLOGE("getSimSlotsResponse: radioConfigService->mRadioConfigResponse == NULL");
384     }
385 
386     return 0;
387 }
388 
setSimSlotsMappingResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)389 int radio_1_6::setSimSlotsMappingResponse(int slotId, int responseType, int serial,
390                                       RIL_Errno e, void *response, size_t responseLen) {
391 #if VDBG
392     RLOGD("setSimSlotsMappingResponse: serial %d", serial);
393 #endif
394 
395     if (radioConfigService->mRadioConfigResponse != NULL) {
396         RadioResponseInfo responseInfo = {};
397         populateResponseInfo(responseInfo, serial, responseType, e);
398         Return<void> retStatus = radioConfigService->mRadioConfigResponse->setSimSlotsMappingResponse(
399                 responseInfo);
400         radioConfigService->checkReturnStatus_config(retStatus);
401     } else {
402         RLOGE("setSimSlotsMappingResponse: radioConfigService->mRadioConfigResponse == NULL");
403     }
404 
405     return 0;
406 }
407 
getPhoneCapabilityResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)408 int radio_1_6::getPhoneCapabilityResponse(int slotId, int responseType, int serial,
409                                       RIL_Errno e, void *response, size_t responseLen) {
410 #if VDBG
411     RLOGD("getPhoneCapabilityResponse: serial %d", serial);
412 #endif
413 
414     if (radioConfigService->mRadioConfigResponseV1_1 != NULL) {
415         RadioResponseInfo responseInfo = {};
416         populateResponseInfo(responseInfo, serial, responseType, e);
417         V1_1::PhoneCapability phoneCapability = {};
418         if ((response == NULL) || (responseLen % sizeof(RIL_PhoneCapability) != 0)) {
419             RLOGE("getPhoneCapabilityResponse Invalid response: NULL");
420             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
421         } else {
422             RIL_PhoneCapability *pCapability = (RIL_PhoneCapability *)response;
423             phoneCapability.maxActiveData = pCapability->maxActiveData;
424             phoneCapability.maxActiveInternetData = pCapability->maxActiveInternetData;
425             phoneCapability.isInternetLingeringSupported = pCapability->isInternetLingeringSupported;
426             phoneCapability.logicalModemList.resize(SIM_COUNT);
427             for (int i = 0 ; i < SIM_COUNT; i++) {
428                 RIL_ModemInfo logicalModemInfo = pCapability->logicalModemList[i];
429                 phoneCapability.logicalModemList[i].modemId = logicalModemInfo.modemId;
430             }
431         }
432         Return<void> retStatus = radioConfigService->mRadioConfigResponseV1_1->getPhoneCapabilityResponse(
433                 responseInfo, phoneCapability);
434         radioConfigService->checkReturnStatus_config(retStatus);
435     } else {
436         RLOGE("getPhoneCapabilityResponse: radioConfigService->mRadioConfigResponseV1_1 == NULL");
437     }
438 
439     return 0;
440 }
441 
setPreferredDataModemResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)442 int radio_1_6::setPreferredDataModemResponse(int slotId, int responseType, int serial,
443                                          RIL_Errno e, void *response, size_t responseLen) {
444 #if VDBG
445     RLOGD("setPreferredDataModemResponse: serial %d", serial);
446 #endif
447 
448     if (radioConfigService->mRadioConfigResponseV1_1 != NULL) {
449         RadioResponseInfo responseInfo = {};
450         populateResponseInfo(responseInfo, serial, responseType, e);
451         Return<void> retStatus = radioConfigService->mRadioConfigResponseV1_1->setPreferredDataModemResponse(
452                 responseInfo);
453         radioConfigService->checkReturnStatus_config(retStatus);
454     } else {
455         RLOGE("setPreferredDataModemResponse: radioConfigService->mRadioConfigResponseV1_1 == NULL");
456     }
457 
458     return 0;
459 }
460 
setModemsConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)461 int radio_1_6::setModemsConfigResponse(int slotId, int responseType, int serial,
462                                    RIL_Errno e, void *response, size_t responseLen) {
463 #if VDBG
464     RLOGD("setModemsConfigResponse: serial %d", serial);
465 #endif
466 
467     if (radioConfigService->mRadioConfigResponseV1_1 != NULL) {
468         RadioResponseInfo responseInfo = {};
469         populateResponseInfo(responseInfo, serial, responseType, e);
470         Return<void> retStatus = radioConfigService->mRadioConfigResponseV1_1->setModemsConfigResponse(
471                 responseInfo);
472         radioConfigService->checkReturnStatus_config(retStatus);
473     } else {
474         RLOGE("setModemsConfigResponse: radioConfigService->mRadioConfigResponseV1_1 == NULL");
475     }
476 
477     return 0;
478 }
479 
getModemsConfigResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)480 int radio_1_6::getModemsConfigResponse(int slotId, int responseType, int serial,
481                                    RIL_Errno e, void *response, size_t responseLen) {
482 #if VDBG
483     RLOGD("getModemsConfigResponse: serial %d", serial);
484 #endif
485 
486     if (radioConfigService->mRadioConfigResponseV1_1 != NULL) {
487         RadioResponseInfo responseInfo = {};
488         populateResponseInfo(responseInfo, serial, responseType, e);
489         V1_1::ModemsConfig mdCfg = {};
490         RIL_ModemConfig *pMdCfg = (RIL_ModemConfig *)response;
491         if ((response == NULL) || (responseLen != sizeof(RIL_ModemConfig))) {
492             RLOGE("getModemsConfigResponse Invalid response: NULL");
493             if (e == RIL_E_SUCCESS) responseInfo.error = RadioError::INVALID_RESPONSE;
494         } else {
495             mdCfg.numOfLiveModems = pMdCfg->numOfLiveModems;
496         }
497         Return<void> retStatus = radioConfigService->mRadioConfigResponseV1_1->getModemsConfigResponse(
498                 responseInfo, mdCfg);
499         radioConfigService->checkReturnStatus_config(retStatus);
500     } else {
501         RLOGE("getModemsConfigResponse: radioConfigService->mRadioConfigResponseV1_1 == NULL");
502     }
503 
504     return 0;
505 }
506 
getHalDeviceCapabilitiesResponse(int slotId,int responseType,int serial,RIL_Errno e,void * response,size_t responseLen)507 int radio_1_6::getHalDeviceCapabilitiesResponse(int slotId, int responseType, int serial,
508                                    RIL_Errno e, void *response, size_t responseLen) {
509 #if VDBG
510     RLOGD("getHalDeviceCapabilitiesResponse: serial %d", serial);
511 #endif
512 
513     if (radioConfigService->mRadioConfigResponseV1_3 != NULL) {
514         ::android::hardware::radio::V1_6::RadioResponseInfo responseInfo = {};
515         populateResponseInfo_1_6(responseInfo, serial, responseType, e);
516 
517         bool modemReducedFeatureSet1 = false;
518         if (response == NULL || responseLen != sizeof(bool)) {
519             RLOGE("getHalDeviceCapabilitiesResponse Invalid response.");
520         } else {
521             modemReducedFeatureSet1 = (*((bool *) response));
522         }
523 
524         Return<void> retStatus = radioConfigService->mRadioConfigResponseV1_3->getHalDeviceCapabilitiesResponse(
525                 responseInfo, modemReducedFeatureSet1);
526         radioConfigService->checkReturnStatus_config(retStatus);
527     } else {
528         RLOGE("getHalDeviceCapabilitiesResponse: radioConfigService->getHalDeviceCapabilities == NULL");
529     }
530 
531     return 0;
532 }
533 
simSlotsStatusChanged(int slotId,int indicationType,int token,RIL_Errno e,void * response,size_t responseLen)534 int radio_1_6::simSlotsStatusChanged(int slotId, int indicationType, int token, RIL_Errno e,
535                                  void *response, size_t responseLen) {
536     if (radioConfigService != NULL &&
537         (radioConfigService->mRadioConfigIndication != NULL ||
538          radioConfigService->mRadioConfigIndicationV1_2 != NULL)) {
539         if ((response == NULL) || (responseLen % sizeof(RIL_SimSlotStatus_V1_2) != 0)) {
540             RLOGE("simSlotsStatusChanged: invalid response");
541             return 0;
542         }
543 
544         RIL_SimSlotStatus_V1_2 *psimSlotStatus = ((RIL_SimSlotStatus_V1_2 *)response);
545         int num = responseLen / sizeof(RIL_SimSlotStatus_V1_2);
546         if (radioConfigService->mRadioConfigIndication != NULL) {
547             hidl_vec<SimSlotStatus> simSlotStatus = {};
548             simSlotStatus.resize(num);
549             for (int i = 0; i < num; i++) {
550                 simSlotStatus[i].cardState = (CardState) psimSlotStatus->base.cardState;
551                 simSlotStatus[i].slotState = (SlotState) psimSlotStatus->base.slotState;
552                 simSlotStatus[i].atr = convertCharPtrToHidlString(psimSlotStatus->base.atr);
553                 simSlotStatus[i].logicalSlotId = psimSlotStatus->base.logicalSlotId;
554                 simSlotStatus[i].iccid = convertCharPtrToHidlString(psimSlotStatus->base.iccid);
555 #if VDBG
556                 RLOGD("simSlotsStatusChanged: cardState %d slotState %d", simSlotStatus[i].cardState,
557                         simSlotStatus[i].slotState);
558 #endif
559                 psimSlotStatus += 1;
560             }
561 
562             Return<void> retStatus = radioConfigService->mRadioConfigIndication->simSlotsStatusChanged(
563                     convertIntToRadioIndicationType(indicationType), simSlotStatus);
564             radioConfigService->checkReturnStatus_config(retStatus);
565         } else if (radioConfigService->mRadioConfigIndicationV1_2) {
566             hidl_vec<V1_2::SimSlotStatus> simSlotStatus;
567             simSlotStatus.resize(num);
568             for (int i = 0; i < num; i++) {
569                 simSlotStatus[i].base.cardState = (CardState)(psimSlotStatus->base.cardState);
570                 simSlotStatus[i].base.slotState = (SlotState) psimSlotStatus->base.slotState;
571                 simSlotStatus[i].base.atr = convertCharPtrToHidlString(psimSlotStatus->base.atr);
572                 simSlotStatus[i].base.logicalSlotId = psimSlotStatus->base.logicalSlotId;
573                 simSlotStatus[i].base.iccid = convertCharPtrToHidlString(psimSlotStatus->base.iccid);
574                 simSlotStatus[i].eid = convertCharPtrToHidlString(psimSlotStatus->eid);
575                 psimSlotStatus += 1;
576 #if VDBG
577             RLOGD("simSlotsStatusChanged_1_2: cardState %d slotState %d",
578                     simSlotStatus[i].base.cardState, simSlotStatus[i].base.slotState);
579 #endif
580             }
581 
582             Return<void> retStatus = radioConfigService->mRadioConfigIndicationV1_2->simSlotsStatusChanged_1_2(
583                     convertIntToRadioIndicationType(indicationType), simSlotStatus);
584             radioConfigService->checkReturnStatus_config(retStatus);
585         }
586     } else {
587         RLOGE("simSlotsStatusChanged: radioService->mRadioIndication == NULL");
588     }
589 
590     return 0;
591 }
592