1 /*
2 * Copyright (C) 2024 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 "RadioSim.h"
18
19 #include <libminradio/debug.h>
20 #include <libminradio/response.h>
21 #include <libminradio/sim/IccUtils.h>
22
23 #define RADIO_MODULE "SimImpl"
24
25 namespace android::hardware::radio::service {
26
27 using ::android::hardware::radio::minimal::noError;
28 using ::ndk::ScopedAStatus;
29 namespace aidl = ::aidl::android::hardware::radio::sim;
30 namespace aidlConfig = ::aidl::android::hardware::radio::config;
31 constexpr auto ok = &ScopedAStatus::ok;
32
RadioSim(std::shared_ptr<minimal::SlotContext> context)33 RadioSim::RadioSim(std::shared_ptr<minimal::SlotContext> context) : minimal::RadioSim(context) {
34 addCtsCertificate(); // do NOT call on real device's production build
35 setIccid("98683081462002318379");
36 mFilesystem->write(minimal::sim::paths::msisdn, minimal::sim::encodeMsisdn("+16500000000"));
37 }
38
getIccCardStatus(int32_t serial)39 ScopedAStatus RadioSim::getIccCardStatus(int32_t serial) {
40 LOG_CALL;
41
42 aidl::CardStatus cardStatus{
43 .cardState = aidl::CardStatus::STATE_PRESENT,
44 .universalPinState = aidl::PinState::DISABLED,
45 .gsmUmtsSubscriptionAppIndex = 0,
46 .imsSubscriptionAppIndex = -1,
47 .applications =
48 {
49 aidl::AppStatus{
50 .appType = aidl::AppStatus::APP_TYPE_USIM,
51 .appState = aidl::AppStatus::APP_STATE_READY,
52 .persoSubstate = aidl::PersoSubstate::READY,
53 },
54 },
55 .atr = "",
56 .iccid = getIccid().value_or(""),
57 .eid = "eUICC-simslot1",
58 .slotMap =
59 {
60 .physicalSlotId = 0,
61 .portId = 0,
62 },
63 .supportedMepMode = aidlConfig::MultipleEnabledProfilesMode::NONE,
64 };
65 respond()->getIccCardStatusResponse(noError(serial), cardStatus);
66 return ok();
67 }
68
getImsiForApp(int32_t serial,const std::string & aid)69 ScopedAStatus RadioSim::getImsiForApp(int32_t serial, const std::string& aid) {
70 LOG_CALL << aid;
71 // 6-digit IMSI prefix has to be a valid mccmnc
72 respond()->getImsiForAppResponse(noError(serial), "311740123456789");
73 return ok();
74 }
75
76 } // namespace android::hardware::radio::service
77