/****************************************************************************** * * Copyright 2020 NXP * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #ifndef ANDROID_HARDWARE_SECURE_ELEMENT_V1_2_SECUREELEMENT_H #define ANDROID_HARDWARE_SECURE_ELEMENT_V1_2_SECUREELEMENT_H #include #include #include #include #include #include #include #include #include "OsuHalExtn.h" #include "phNxpEse_Api.h" class ThreadMutex { public: ThreadMutex(); virtual ~ThreadMutex(); void lock(); void unlock(); operator pthread_mutex_t*() { return &mMutex; } private: pthread_mutex_t mMutex; }; class AutoThreadMutex { public: AutoThreadMutex(ThreadMutex& m); virtual ~AutoThreadMutex(); operator ThreadMutex&() { return mm; } operator pthread_mutex_t*() { return (pthread_mutex_t*)mm; } private: ThreadMutex& mm; }; namespace android { namespace hardware { namespace secure_element { namespace V1_2 { namespace implementation { using ::android::sp; using android::base::StringPrintf; using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::Void; using ::android::hardware::secure_element::V1_0::LogicalChannelResponse; using ::android::hardware::secure_element::V1_0::SecureElementStatus; using ::android::hardware::secure_element::V1_2::ISecureElement; using ::android::hidl::base::V1_0::IBase; #ifndef MIN_APDU_LENGTH #define MIN_APDU_LENGTH 0x04 #endif #ifndef DEFAULT_BASIC_CHANNEL #define DEFAULT_BASIC_CHANNEL 0x00 #endif struct SecureElement : public V1_2::ISecureElement, public hidl_death_recipient { SecureElement(); Return init( const sp< ::android::hardware::secure_element::V1_0::ISecureElementHalCallback>& clientCallback) override; Return init_1_1( const sp< ::android::hardware::secure_element::V1_1::ISecureElementHalCallback>& clientCallback) override; Return getAtr(getAtr_cb _hidl_cb) override; Return isCardPresent() override; Return transmit(const hidl_vec& data, transmit_cb _hidl_cb) override; Return openLogicalChannel(const hidl_vec& aid, uint8_t p2, openLogicalChannel_cb _hidl_cb) override; Return openBasicChannel(const hidl_vec& aid, uint8_t p2, openBasicChannel_cb _hidl_cb) override; Return closeChannel(uint8_t channelNumber) override; void serviceDied(uint64_t /*cookie*/, const wp& /*who*/); static void NotifySeWaitExtension(phNxpEse_wtxState state); Return<::android::hardware::secure_element::V1_0::SecureElementStatus> reset(); private: uint8_t mMaxChannelCount; uint8_t mOpenedchannelCount = 0; Mutex seHalLock; bool mIsEseInitialized = false; static std::vector mOpenedChannels; static sp mCallbackV1_0; static sp mCallbackV1_1; Return seHalDeInit(); ESESTATUS seHalInit(); Return internalCloseChannel(uint8_t channelNumber); }; } // namespace implementation } // namespace V1_2 } // namespace secure_element } // namespace hardware } // namespace android #endif // ANDROID_HARDWARE_SECURE_ELEMENT_V1_1_SECUREELEMENT_H