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