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