1 /****************************************************************************** 2 * 3 * Copyright 2018-2020,2022-2023 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 #ifndef VENDOR_NXP_VIRTUAL_ISO_V1_0_SECUREELEMENT_H 19 #define VENDOR_NXP_VIRTUAL_ISO_V1_0_SECUREELEMENT_H 20 21 #include <android-base/stringprintf.h> 22 #include <android/hardware/secure_element/1.0/types.h> 23 #include <android/hardware/secure_element/1.2/ISecureElement.h> 24 #include <android/binder_manager.h> 25 #include <android/binder_process.h> 26 #include <hardware/hardware.h> 27 #include <hidl/MQDescriptor.h> 28 #include <hidl/Status.h> 29 30 #include "phNxpEse_Api.h" 31 32 namespace vendor { 33 namespace nxp { 34 namespace virtual_iso { 35 namespace V1_0 { 36 namespace implementation { 37 38 using ::android::sp; 39 using ::android::wp; 40 using android::base::StringPrintf; 41 using ::android::hardware::hidl_array; 42 using ::android::hardware::hidl_death_recipient; 43 using ::android::hardware::hidl_handle; 44 using ::android::hardware::hidl_memory; 45 using ::android::hardware::hidl_string; 46 using ::android::hardware::hidl_vec; 47 using ::android::hardware::Return; 48 using ::android::hardware::Void; 49 using ::android::hardware::secure_element::V1_0::LogicalChannelResponse; 50 using ::android::hardware::secure_element::V1_0::SecureElementStatus; 51 using ::android::hardware::secure_element::V1_2::ISecureElement; 52 using ::android::hidl::base::V1_0::IBase; 53 #ifndef DEFAULT_BASIC_CHANNEL 54 #define DEFAULT_BASIC_CHANNEL 0x00 55 #endif 56 57 struct VirtualISO : public ISecureElement, public hidl_death_recipient { 58 VirtualISO(); 59 // Methods from ::android::hidl::base::V1_0::IBase follow. 60 Return<void> debug(const hidl_handle& handle, 61 const hidl_vec<hidl_string>& options) override; 62 63 Return<void> init( 64 const sp< 65 ::android::hardware::secure_element::V1_0::ISecureElementHalCallback>& 66 clientCallback) override; 67 Return<void> init_1_1( 68 const sp< 69 ::android::hardware::secure_element::V1_1::ISecureElementHalCallback>& 70 clientCallback) override; 71 Return<void> getAtr(getAtr_cb _hidl_cb) override; 72 Return<bool> isCardPresent() override; 73 Return<void> transmit(const hidl_vec<uint8_t>& data, 74 transmit_cb _hidl_cb) override; 75 Return<void> openLogicalChannel(const hidl_vec<uint8_t>& aid, uint8_t p2, 76 openLogicalChannel_cb _hidl_cb) override; 77 Return<void> openBasicChannel(const hidl_vec<uint8_t>& aid, uint8_t p2, 78 openBasicChannel_cb _hidl_cb) override; 79 Return<SecureElementStatus> closeChannel(uint8_t channelNumber) override; 80 Return<::android::hardware::secure_element::V1_0::SecureElementStatus> 81 reset(); serviceDiedVirtualISO82 virtual void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) { 83 // TODO: Implement graceful closure, to close ongoing tx-rx and deinit 84 // T=1 stack 85 // close(0); 86 } 87 private: 88 uint8_t mMaxChannelCount; 89 uint8_t mOpenedchannelCount = 0; 90 bool mIsEseInitialized = false; 91 static std::vector<bool> mOpenedChannels; 92 static sp< 93 ::android::hardware::secure_element::V1_0::ISecureElementHalCallback> 94 mCallbackV1_0; 95 static sp< 96 ::android::hardware::secure_element::V1_1::ISecureElementHalCallback> 97 mCallbackV1_1; 98 Return<SecureElementStatus> seHalDeInit(); 99 ESESTATUS seHalInit(); 100 Return<SecureElementStatus> internalCloseChannel(uint8_t channelNumber); 101 }; 102 103 } // namespace implementation 104 } // namespace V1_0 105 } // namespace virtual_iso 106 } // namespace nxp 107 } // namespace vendor 108 109 #endif // VENDOR_NXP_VIRTUAL_ISO_V1_0_SECUREELEMENT_H 110