1 /*
2 * Copyright (C) 2022 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/Sap.h>
18
19 #include "commonStructs.h"
20 #include "debug.h"
21 #include "structs.h"
22
23 #include "collections.h"
24
25 #define RADIO_MODULE "Sap"
26
27 namespace android::hardware::radio::compat {
28
29 using ::ndk::ScopedAStatus;
30 namespace aidl = ::aidl::android::hardware::radio::sap;
31 constexpr auto ok = &ScopedAStatus::ok;
32
Sap(sp<V1_0::ISap> hidlHal)33 Sap::Sap(sp<V1_0::ISap> hidlHal) : mHal(hidlHal), mSapCallback(sp<SapCallback>::make()) {}
34
apduReq(int32_t serial,aidl::SapApduType type,const std::vector<uint8_t> & command)35 ScopedAStatus Sap::apduReq(int32_t serial, aidl::SapApduType type,
36 const std::vector<uint8_t>& command) {
37 LOG_CALL << serial;
38 mHal->apduReq(serial, toHidl(type), toHidl(command));
39 return ok();
40 }
41
connectReq(int32_t serial,int32_t maxMsgSize)42 ScopedAStatus Sap::connectReq(int32_t serial, int32_t maxMsgSize) {
43 LOG_CALL << serial;
44 mHal->connectReq(serial, maxMsgSize);
45 return ok();
46 }
47
disconnectReq(int32_t serial)48 ScopedAStatus Sap::disconnectReq(int32_t serial) {
49 LOG_CALL << serial;
50 mHal->disconnectReq(serial);
51 return ok();
52 }
53
powerReq(int32_t serial,bool state)54 ScopedAStatus Sap::powerReq(int32_t serial, bool state) {
55 LOG_CALL << serial;
56 mHal->powerReq(serial, state);
57 return ok();
58 }
59
resetSimReq(int32_t serial)60 ScopedAStatus Sap::resetSimReq(int32_t serial) {
61 LOG_CALL << serial;
62 mHal->resetSimReq(serial);
63 return ok();
64 }
65
setCallback(const std::shared_ptr<::aidl::android::hardware::radio::sap::ISapCallback> & sapCallback)66 ScopedAStatus Sap::setCallback(
67 const std::shared_ptr<::aidl::android::hardware::radio::sap::ISapCallback>& sapCallback) {
68 LOG_CALL << sapCallback;
69
70 CHECK(sapCallback);
71
72 mSapCallback->setResponseFunction(sapCallback);
73 mHal->setCallback(mSapCallback).assertOk();
74 return ok();
75 }
setTransferProtocolReq(int32_t serial,aidl::SapTransferProtocol transferProtocol)76 ScopedAStatus Sap::setTransferProtocolReq(int32_t serial,
77 aidl::SapTransferProtocol transferProtocol) {
78 LOG_CALL << serial;
79 mHal->setTransferProtocolReq(serial, toHidl(transferProtocol));
80 return ok();
81 }
82
transferAtrReq(int32_t serial)83 ScopedAStatus Sap::transferAtrReq(int32_t serial) {
84 LOG_CALL << serial;
85 mHal->transferAtrReq(serial);
86 return ok();
87 }
transferCardReaderStatusReq(int32_t serial)88 ScopedAStatus Sap::transferCardReaderStatusReq(int32_t serial) {
89 LOG_CALL << serial;
90 mHal->transferCardReaderStatusReq(serial);
91 return ok();
92 }
93
94 } // namespace android::hardware::radio::compat
95