Tomasz Wasilczyk | fb10e00 | 2021-10-28 13:22:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 | #include <libradiocompat/RadioSim.h> |
| 18 | |
| 19 | #include "commonStructs.h" |
| 20 | #include "debug.h" |
| 21 | #include "structs.h" |
| 22 | |
| 23 | #include "collections.h" |
| 24 | |
| 25 | #define RADIO_MODULE "Sim" |
| 26 | |
| 27 | namespace android::hardware::radio::compat { |
| 28 | |
| 29 | using ::ndk::ScopedAStatus; |
| 30 | namespace aidl = ::aidl::android::hardware::radio::sim; |
| 31 | constexpr auto ok = &ScopedAStatus::ok; |
| 32 | |
Tomasz Wasilczyk | 6902a75 | 2021-12-13 17:13:48 -0800 | [diff] [blame] | 33 | std::shared_ptr<aidl::IRadioSimResponse> RadioSim::respond() { |
Tomasz Wasilczyk | 8579f1d | 2021-12-16 12:19:09 -0800 | [diff] [blame] | 34 | return mCallbackManager->response().simCb(); |
Tomasz Wasilczyk | 6902a75 | 2021-12-13 17:13:48 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Tomasz Wasilczyk | fb10e00 | 2021-10-28 13:22:47 -0700 | [diff] [blame] | 37 | ScopedAStatus RadioSim::areUiccApplicationsEnabled(int32_t serial) { |
| 38 | LOG_CALL << serial; |
| 39 | mHal1_5->areUiccApplicationsEnabled(serial); |
| 40 | return ok(); |
| 41 | } |
| 42 | |
| 43 | ScopedAStatus RadioSim::changeIccPin2ForApp(int32_t serial, const std::string& oldPin2, |
| 44 | const std::string& newPin2, const std::string& aid) { |
| 45 | LOG_CALL << serial; |
| 46 | mHal1_5->changeIccPin2ForApp(serial, oldPin2, newPin2, aid); |
| 47 | return ok(); |
| 48 | } |
| 49 | |
| 50 | ScopedAStatus RadioSim::changeIccPinForApp(int32_t serial, const std::string& oldPin, |
| 51 | const std::string& newPin, const std::string& aid) { |
| 52 | LOG_CALL << serial; |
| 53 | mHal1_5->changeIccPinForApp(serial, oldPin, newPin, aid); |
| 54 | return ok(); |
| 55 | } |
| 56 | |
| 57 | ScopedAStatus RadioSim::enableUiccApplications(int32_t serial, bool enable) { |
| 58 | LOG_CALL << serial; |
| 59 | mHal1_5->enableUiccApplications(serial, enable); |
| 60 | return ok(); |
| 61 | } |
| 62 | |
| 63 | ScopedAStatus RadioSim::getAllowedCarriers(int32_t serial) { |
| 64 | LOG_CALL << serial; |
Tomasz Wasilczyk | 31f6fab | 2021-12-15 16:15:45 -0800 | [diff] [blame] | 65 | mHal1_5->getAllowedCarriers_1_4(serial); |
Tomasz Wasilczyk | fb10e00 | 2021-10-28 13:22:47 -0700 | [diff] [blame] | 66 | return ok(); |
| 67 | } |
| 68 | |
| 69 | ScopedAStatus RadioSim::getCdmaSubscription(int32_t serial) { |
| 70 | LOG_CALL << serial; |
| 71 | mHal1_5->getCDMASubscription(serial); |
| 72 | return ok(); |
| 73 | } |
| 74 | |
| 75 | ScopedAStatus RadioSim::getCdmaSubscriptionSource(int32_t serial) { |
| 76 | LOG_CALL << serial; |
| 77 | mHal1_5->getCdmaSubscriptionSource(serial); |
| 78 | return ok(); |
| 79 | } |
| 80 | |
| 81 | ScopedAStatus RadioSim::getFacilityLockForApp( // |
| 82 | int32_t serial, const std::string& facility, const std::string& password, |
| 83 | int32_t serviceClass, const std::string& appId) { |
| 84 | LOG_CALL << serial; |
| 85 | mHal1_5->getFacilityLockForApp(serial, facility, password, serviceClass, appId); |
| 86 | return ok(); |
| 87 | } |
| 88 | |
| 89 | ScopedAStatus RadioSim::getIccCardStatus(int32_t serial) { |
| 90 | LOG_CALL << serial; |
| 91 | mHal1_5->getIccCardStatus(serial); |
| 92 | return ok(); |
| 93 | } |
| 94 | |
| 95 | ScopedAStatus RadioSim::getImsiForApp(int32_t serial, const std::string& aid) { |
| 96 | LOG_CALL << serial; |
| 97 | mHal1_5->getImsiForApp(serial, aid); |
| 98 | return ok(); |
| 99 | } |
| 100 | |
| 101 | ScopedAStatus RadioSim::getSimPhonebookCapacity(int32_t serial) { |
| 102 | LOG_CALL << serial; |
| 103 | if (mHal1_6) { |
| 104 | mHal1_6->getSimPhonebookCapacity(serial); |
| 105 | } else { |
Tomasz Wasilczyk | 6902a75 | 2021-12-13 17:13:48 -0800 | [diff] [blame] | 106 | respond()->getSimPhonebookCapacityResponse(notSupported(serial), {}); |
Tomasz Wasilczyk | fb10e00 | 2021-10-28 13:22:47 -0700 | [diff] [blame] | 107 | } |
| 108 | return ok(); |
| 109 | } |
| 110 | |
| 111 | ScopedAStatus RadioSim::getSimPhonebookRecords(int32_t serial) { |
| 112 | LOG_CALL << serial; |
| 113 | if (mHal1_6) { |
| 114 | mHal1_6->getSimPhonebookRecords(serial); |
| 115 | } else { |
Tomasz Wasilczyk | 6902a75 | 2021-12-13 17:13:48 -0800 | [diff] [blame] | 116 | respond()->getSimPhonebookRecordsResponse(notSupported(serial)); |
Tomasz Wasilczyk | fb10e00 | 2021-10-28 13:22:47 -0700 | [diff] [blame] | 117 | } |
| 118 | return ok(); |
| 119 | } |
| 120 | |
| 121 | ScopedAStatus RadioSim::iccCloseLogicalChannel(int32_t serial, int32_t channelId) { |
| 122 | LOG_CALL << serial; |
| 123 | mHal1_5->iccCloseLogicalChannel(serial, channelId); |
| 124 | return ok(); |
| 125 | } |
| 126 | |
| 127 | ScopedAStatus RadioSim::iccIoForApp(int32_t serial, const aidl::IccIo& iccIo) { |
| 128 | LOG_CALL << serial; |
| 129 | mHal1_5->iccIOForApp(serial, toHidl(iccIo)); |
| 130 | return ok(); |
| 131 | } |
| 132 | |
| 133 | ScopedAStatus RadioSim::iccOpenLogicalChannel(int32_t serial, const std::string& aid, int32_t p2) { |
| 134 | LOG_CALL << serial; |
| 135 | mHal1_5->iccOpenLogicalChannel(serial, aid, p2); |
| 136 | return ok(); |
| 137 | } |
| 138 | |
| 139 | ScopedAStatus RadioSim::iccTransmitApduBasicChannel(int32_t serial, const aidl::SimApdu& message) { |
| 140 | LOG_CALL << serial; |
| 141 | mHal1_5->iccTransmitApduBasicChannel(serial, toHidl(message)); |
| 142 | return ok(); |
| 143 | } |
| 144 | |
| 145 | ScopedAStatus RadioSim::iccTransmitApduLogicalChannel(int32_t serial, |
| 146 | const aidl::SimApdu& message) { |
| 147 | LOG_CALL << serial; |
| 148 | mHal1_5->iccTransmitApduLogicalChannel(serial, toHidl(message)); |
| 149 | return ok(); |
| 150 | } |
| 151 | |
| 152 | ScopedAStatus RadioSim::reportStkServiceIsRunning(int32_t serial) { |
| 153 | LOG_CALL << serial; |
| 154 | mHal1_5->reportStkServiceIsRunning(serial); |
| 155 | return ok(); |
| 156 | } |
| 157 | |
| 158 | ScopedAStatus RadioSim::requestIccSimAuthentication( // |
| 159 | int32_t serial, int32_t authContext, const std::string& authData, const std::string& aid) { |
| 160 | LOG_CALL << serial; |
| 161 | mHal1_5->requestIccSimAuthentication(serial, authContext, authData, aid); |
| 162 | return ok(); |
| 163 | } |
| 164 | |
| 165 | ScopedAStatus RadioSim::responseAcknowledgement() { |
| 166 | LOG_CALL; |
| 167 | mHal1_5->responseAcknowledgement(); |
| 168 | return ok(); |
| 169 | } |
| 170 | |
| 171 | ScopedAStatus RadioSim::sendEnvelope(int32_t serial, const std::string& command) { |
| 172 | LOG_CALL << serial; |
| 173 | mHal1_5->sendEnvelope(serial, command); |
| 174 | return ok(); |
| 175 | } |
| 176 | |
| 177 | ScopedAStatus RadioSim::sendEnvelopeWithStatus(int32_t serial, const std::string& contents) { |
| 178 | LOG_CALL << serial; |
| 179 | mHal1_5->sendEnvelopeWithStatus(serial, contents); |
| 180 | return ok(); |
| 181 | } |
| 182 | |
| 183 | ScopedAStatus RadioSim::sendTerminalResponseToSim(int32_t serial, |
| 184 | const std::string& commandResponse) { |
| 185 | LOG_CALL << serial; |
| 186 | mHal1_5->sendTerminalResponseToSim(serial, commandResponse); |
| 187 | return ok(); |
| 188 | } |
| 189 | |
| 190 | ScopedAStatus RadioSim::setAllowedCarriers( // |
| 191 | int32_t serial, const aidl::CarrierRestrictions& carriers, aidl::SimLockMultiSimPolicy mp) { |
| 192 | LOG_CALL << serial; |
| 193 | mHal1_5->setAllowedCarriers_1_4(serial, toHidl(carriers), V1_4::SimLockMultiSimPolicy(mp)); |
| 194 | return ok(); |
| 195 | } |
| 196 | |
| 197 | ScopedAStatus RadioSim::setCarrierInfoForImsiEncryption( |
| 198 | int32_t serial, const aidl::ImsiEncryptionInfo& imsiEncryptionInfo) { |
| 199 | LOG_CALL << serial; |
| 200 | if (mHal1_6) { |
| 201 | mHal1_6->setCarrierInfoForImsiEncryption_1_6(serial, toHidl_1_6(imsiEncryptionInfo)); |
| 202 | } else { |
| 203 | mHal1_5->setCarrierInfoForImsiEncryption(serial, toHidl(imsiEncryptionInfo)); |
| 204 | } |
| 205 | return ok(); |
| 206 | } |
| 207 | |
| 208 | ScopedAStatus RadioSim::setCdmaSubscriptionSource(int32_t serial, |
| 209 | aidl::CdmaSubscriptionSource cdmaSub) { |
| 210 | LOG_CALL << serial; |
| 211 | mHal1_5->setCdmaSubscriptionSource(serial, V1_0::CdmaSubscriptionSource(cdmaSub)); |
| 212 | return ok(); |
| 213 | } |
| 214 | |
| 215 | ScopedAStatus RadioSim::setFacilityLockForApp( // |
| 216 | int32_t serial, const std::string& facility, bool lockState, const std::string& password, |
| 217 | int32_t serviceClass, const std::string& appId) { |
| 218 | LOG_CALL << serial; |
| 219 | mHal1_5->setFacilityLockForApp(serial, facility, lockState, password, serviceClass, appId); |
| 220 | return ok(); |
| 221 | } |
| 222 | |
| 223 | ScopedAStatus RadioSim::setResponseFunctions( |
Tomasz Wasilczyk | 8579f1d | 2021-12-16 12:19:09 -0800 | [diff] [blame] | 224 | const std::shared_ptr<aidl::IRadioSimResponse>& response, |
| 225 | const std::shared_ptr<aidl::IRadioSimIndication>& indication) { |
| 226 | LOG_CALL << response << ' ' << indication; |
| 227 | mCallbackManager->setResponseFunctions(response, indication); |
Tomasz Wasilczyk | fb10e00 | 2021-10-28 13:22:47 -0700 | [diff] [blame] | 228 | return ok(); |
| 229 | } |
| 230 | |
| 231 | ScopedAStatus RadioSim::setSimCardPower(int32_t serial, aidl::CardPowerState powerUp) { |
| 232 | LOG_CALL << serial; |
| 233 | if (mHal1_6) { |
| 234 | mHal1_6->setSimCardPower_1_6(serial, V1_1::CardPowerState(powerUp)); |
| 235 | } else { |
| 236 | mHal1_5->setSimCardPower_1_1(serial, V1_1::CardPowerState(powerUp)); |
| 237 | } |
| 238 | return ok(); |
| 239 | } |
| 240 | |
| 241 | ScopedAStatus RadioSim::setUiccSubscription(int32_t serial, const aidl::SelectUiccSub& uiccSub) { |
| 242 | LOG_CALL << serial; |
| 243 | mHal1_5->setUiccSubscription(serial, toHidl(uiccSub)); |
| 244 | return ok(); |
| 245 | } |
| 246 | |
| 247 | ScopedAStatus RadioSim::supplyIccPin2ForApp(int32_t serial, const std::string& pin2, |
| 248 | const std::string& aid) { |
| 249 | LOG_CALL << serial; |
| 250 | mHal1_5->supplyIccPin2ForApp(serial, pin2, aid); |
| 251 | return ok(); |
| 252 | } |
| 253 | |
| 254 | ScopedAStatus RadioSim::supplyIccPinForApp(int32_t serial, const std::string& pin, |
| 255 | const std::string& aid) { |
| 256 | LOG_CALL << serial; |
| 257 | mHal1_5->supplyIccPinForApp(serial, pin, aid); |
| 258 | return ok(); |
| 259 | } |
| 260 | |
| 261 | ScopedAStatus RadioSim::supplyIccPuk2ForApp(int32_t serial, const std::string& puk2, |
| 262 | const std::string& pin2, const std::string& aid) { |
| 263 | LOG_CALL << serial; |
| 264 | mHal1_5->supplyIccPuk2ForApp(serial, puk2, pin2, aid); |
| 265 | return ok(); |
| 266 | } |
| 267 | |
| 268 | ScopedAStatus RadioSim::supplyIccPukForApp(int32_t serial, const std::string& puk, |
| 269 | const std::string& pin, const std::string& aid) { |
| 270 | LOG_CALL << serial; |
| 271 | mHal1_5->supplyIccPukForApp(serial, puk, pin, aid); |
| 272 | return ok(); |
| 273 | } |
| 274 | |
| 275 | ScopedAStatus RadioSim::supplySimDepersonalization(int32_t serial, aidl::PersoSubstate pss, |
| 276 | const std::string& controlKey) { |
| 277 | LOG_CALL << serial; |
| 278 | mHal1_5->supplySimDepersonalization(serial, V1_5::PersoSubstate(pss), controlKey); |
| 279 | return ok(); |
| 280 | } |
| 281 | |
| 282 | ScopedAStatus RadioSim::updateSimPhonebookRecords(int32_t serial, |
| 283 | const aidl::PhonebookRecordInfo& recordInfo) { |
| 284 | LOG_CALL << serial; |
| 285 | if (mHal1_6) { |
| 286 | mHal1_6->updateSimPhonebookRecords(serial, toHidl(recordInfo)); |
| 287 | } else { |
Tomasz Wasilczyk | 6902a75 | 2021-12-13 17:13:48 -0800 | [diff] [blame] | 288 | respond()->updateSimPhonebookRecordsResponse(notSupported(serial), 0); |
Tomasz Wasilczyk | fb10e00 | 2021-10-28 13:22:47 -0700 | [diff] [blame] | 289 | } |
| 290 | return ok(); |
| 291 | } |
| 292 | |
| 293 | } // namespace android::hardware::radio::compat |