1 /****************************************************************************** 2 * 3 * Copyright 2018,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 ANDROID_HARDWARE_SECURE_ELEMENT_V1_0_SECUREELEMENT_H 19 #define ANDROID_HARDWARE_SECURE_ELEMENT_V1_0_SECUREELEMENT_H 20 21 #include <android/hardware/secure_element/1.0/ISecureElement.h> 22 #include <hidl/MQDescriptor.h> 23 #include <hidl/Status.h> 24 #include <string> 25 26 #include "phNxpEse_Api.h" 27 28 namespace android { 29 namespace hardware { 30 namespace secure_element { 31 namespace V1_0 { 32 namespace implementation { 33 34 using ::android::sp; 35 using ::android::hardware::hidl_vec; 36 using ::android::hardware::Return; 37 using ::android::hardware::Void; 38 using ::android::hardware::secure_element::V1_0::ISecureElementHalCallback; 39 using ::android::hidl::base::V1_0::IBase; 40 41 #ifndef MAX_LOGICAL_CHANNELS 42 #define MAX_LOGICAL_CHANNELS 0x04 43 #endif 44 #ifndef MIN_APDU_LENGTH 45 #define MIN_APDU_LENGTH 0x04 46 #endif 47 #ifndef DEFAULT_BASIC_CHANNEL 48 #define DEFAULT_BASIC_CHANNEL 0x00 49 #endif 50 #ifndef MAX_AID_LENGTH 51 #define MAX_AID_LENGTH 0x10 52 #endif 53 54 struct SecureElement : public ISecureElement, public hidl_death_recipient { 55 SecureElement(); 56 Return<void> init( 57 const sp<ISecureElementHalCallback>& clientCallback) override; 58 Return<void> getAtr(getAtr_cb _hidl_cb) override; 59 Return<bool> isCardPresent() override; 60 Return<void> transmit(const hidl_vec<uint8_t>& data, 61 transmit_cb _hidl_cb) override; 62 Return<void> openLogicalChannel(const hidl_vec<uint8_t>& aid, uint8_t p2, 63 openLogicalChannel_cb _hidl_cb) override; 64 Return<void> openBasicChannel(const hidl_vec<uint8_t>& aid, uint8_t p2, 65 openBasicChannel_cb _hidl_cb) override; 66 Return<::android::hardware::secure_element::V1_0::SecureElementStatus> 67 closeChannel(uint8_t channelNumber) override; 68 void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) override; 69 void onStateChange(bool result, std::string reason); 70 71 private: 72 uint8_t mOpenedchannelCount = 0; 73 bool mOpenedChannels[MAX_LOGICAL_CHANNELS]; 74 static sp<V1_0::ISecureElementHalCallback> mCallbackV1_0; 75 Return<::android::hardware::secure_element::V1_0::SecureElementStatus> 76 seHalDeInit(); 77 ESESTATUS seHalInit(); 78 bool isSeInitialized(); 79 }; 80 81 } // namespace implementation 82 } // namespace V1_0 83 } // namespace secure_element 84 } // namespace hardware 85 } // namespace android 86 87 #endif // ANDROID_HARDWARE_SECURE_ELEMENT_V1_0_SECUREELEMENT_H 88