1 /* 2 * Copyright (C) 2025 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 #pragma once 18 #include <memory> 19 #include <mutex> 20 21 #include <aidl/android/hardware/radio/sim/BnRadioSim.h> 22 #include "AtChannel.h" 23 24 namespace aidl { 25 namespace android { 26 namespace hardware { 27 namespace radio { 28 namespace implementation { 29 using ::ndk::ScopedAStatus; 30 31 struct RadioSim : public sim::BnRadioSim { 32 RadioSim(std::shared_ptr<AtChannel> atChannel); 33 34 ScopedAStatus areUiccApplicationsEnabled(int32_t serial) override; 35 ScopedAStatus changeIccPin2ForApp(int32_t serial, const std::string& oldPin2, 36 const std::string& newPin2, 37 const std::string& aid) override; 38 ScopedAStatus changeIccPinForApp(int32_t serial, const std::string& oldPin, 39 const std::string& newPin, 40 const std::string& aid) override; 41 ScopedAStatus enableUiccApplications(int32_t serial, bool enable) override; 42 ScopedAStatus getAllowedCarriers(int32_t serial) override; 43 ScopedAStatus getCdmaSubscription(int32_t serial) override; 44 ScopedAStatus getCdmaSubscriptionSource(int32_t serial) override; 45 ScopedAStatus getFacilityLockForApp(int32_t serial, const std::string& facility, 46 const std::string& password, int32_t serviceClass, 47 const std::string& appId) override; 48 ScopedAStatus getIccCardStatus(int32_t serial) override; 49 ScopedAStatus getImsiForApp(int32_t serial, const std::string& aid) override; 50 ScopedAStatus getSimPhonebookCapacity(int32_t serial) override; 51 ScopedAStatus getSimPhonebookRecords(int32_t serial) override; 52 ScopedAStatus iccCloseLogicalChannel(int32_t serial, int32_t channelId) override; 53 ScopedAStatus iccCloseLogicalChannelWithSessionInfo(int32_t serial, 54 const sim::SessionInfo& recordInfo) override; 55 ScopedAStatus iccIoForApp(int32_t serial, const sim::IccIo& iccIo) override; 56 ScopedAStatus iccOpenLogicalChannel(int32_t serial, const std::string& aid, 57 int32_t p2) override; 58 ScopedAStatus iccTransmitApduBasicChannel( 59 int32_t serial, const sim::SimApdu& message) override; 60 ScopedAStatus iccTransmitApduLogicalChannel( 61 int32_t serial, const sim::SimApdu& message) override; 62 ScopedAStatus reportStkServiceIsRunning(int32_t serial) override; 63 ScopedAStatus requestIccSimAuthentication(int32_t serial, int32_t authContext, 64 const std::string& authData, 65 const std::string& aid) override; 66 ScopedAStatus sendEnvelope(int32_t serial, const std::string& command) override; 67 ScopedAStatus sendEnvelopeWithStatus(int32_t serial, 68 const std::string& contents) override; 69 ScopedAStatus sendTerminalResponseToSim(int32_t serial, 70 const std::string& commandResponse) override; 71 ScopedAStatus setAllowedCarriers( 72 int32_t serial, const sim::CarrierRestrictions& carriers, 73 sim::SimLockMultiSimPolicy multiSimPolicy) override; 74 ScopedAStatus setCarrierInfoForImsiEncryption( 75 int32_t serial, const sim::ImsiEncryptionInfo& imsiEncryptionInfo) 76 override; 77 ScopedAStatus setCdmaSubscriptionSource( 78 int32_t serial, sim::CdmaSubscriptionSource cdmaSub) override; 79 ScopedAStatus setFacilityLockForApp( 80 int32_t serial, const std::string& facility, 81 bool lockState, const std::string& passwd, 82 int32_t serviceClass, const std::string& appId) override; 83 ScopedAStatus setSimCardPower(int32_t serial, sim::CardPowerState powerUp) override; 84 ScopedAStatus setUiccSubscription( 85 int32_t serial, const sim::SelectUiccSub& uiccSub) override; 86 ScopedAStatus supplyIccPin2ForApp(int32_t serial, const std::string& pin2, 87 const std::string& aid) override; 88 ScopedAStatus supplyIccPinForApp(int32_t serial, const std::string& pin, 89 const std::string& aid) override; 90 ScopedAStatus supplyIccPuk2ForApp(int32_t serial, const std::string& puk2, 91 const std::string& pin2, 92 const std::string& aid) override; 93 ScopedAStatus supplyIccPukForApp(int32_t serial, const std::string& puk, 94 const std::string& pin, 95 const std::string& aid) override; 96 ScopedAStatus supplySimDepersonalization( 97 int32_t serial, sim::PersoSubstate persoType, const std::string& controlKey) override; 98 ScopedAStatus updateSimPhonebookRecords( 99 int32_t serial, const sim::PhonebookRecordInfo& recordInfo) override; 100 101 void atResponseSink(const AtResponsePtr& response); 102 void handleUnsolicited(const AtResponse::CFUN&); 103 void handleUnsolicited(const AtResponse::CUSATP&); 104 void handleUnsolicited(const AtResponse::CUSATEND&); handleUnsolicitedRadioSim105 template <class IGNORE> void handleUnsolicited(const IGNORE&) {} 106 107 ScopedAStatus responseAcknowledgement() override; 108 ScopedAStatus setResponseFunctions( 109 const std::shared_ptr<sim::IRadioSimResponse>& radioSimResponse, 110 const std::shared_ptr<sim::IRadioSimIndication>& radioSimIndication) override; 111 112 private: 113 std::shared_ptr<sim::IRadioSimResponse> mRadioSimResponse; 114 std::shared_ptr<sim::IRadioSimIndication> mRadioSimIndication; 115 116 const std::shared_ptr<AtChannel> mAtChannel; 117 AtChannel::Conversation mAtConversation; 118 119 std::mutex mMtx; 120 std::optional<AtResponse::CUSATP> mStkUnsolResponse; 121 modem::RadioState mRadioState = modem::RadioState::OFF; 122 bool mUiccApplicationsEnabled = true; 123 bool mStkServiceRunning = false; 124 }; 125 126 } // namespace implementation 127 } // namespace radio 128 } // namespace hardware 129 } // namespace android 130 } // namespace aidl 131