pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
suryaprakash.konduru | 5818378 | 2023-03-01 10:24:08 +0530 | [diff] [blame] | 3 | * Copyright 2020,2022 NXP |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 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 | ******************************************************************************/ |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 18 | #ifndef ANDROID_HARDWARE_SECURE_ELEMENT_V1_2_SECUREELEMENT_H |
| 19 | #define ANDROID_HARDWARE_SECURE_ELEMENT_V1_2_SECUREELEMENT_H |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 20 | |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 21 | #include <SyncEvent.h> |
| 22 | #include <android-base/stringprintf.h> |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 23 | #include <android/hardware/secure_element/1.0/types.h> |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 24 | #include <android/hardware/secure_element/1.2/ISecureElement.h> |
| 25 | #include <hardware/hardware.h> |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 26 | #include <hidl/MQDescriptor.h> |
| 27 | #include <hidl/Status.h> |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 28 | #include <pthread.h> |
suryaprakash.konduru | 5818378 | 2023-03-01 10:24:08 +0530 | [diff] [blame] | 29 | |
| 30 | #include <vector> |
| 31 | |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 32 | #include "OsuHalExtn.h" |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 33 | #include "phNxpEse_Api.h" |
| 34 | |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 35 | class ThreadMutex { |
| 36 | public: |
| 37 | ThreadMutex(); |
| 38 | virtual ~ThreadMutex(); |
| 39 | void lock(); |
| 40 | void unlock(); |
| 41 | operator pthread_mutex_t*() { return &mMutex; } |
| 42 | |
| 43 | private: |
| 44 | pthread_mutex_t mMutex; |
| 45 | }; |
| 46 | |
| 47 | class AutoThreadMutex { |
| 48 | public: |
| 49 | AutoThreadMutex(ThreadMutex& m); |
| 50 | virtual ~AutoThreadMutex(); |
| 51 | operator ThreadMutex&() { return mm; } |
| 52 | operator pthread_mutex_t*() { return (pthread_mutex_t*)mm; } |
| 53 | |
| 54 | private: |
| 55 | ThreadMutex& mm; |
| 56 | }; |
| 57 | |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 58 | namespace android { |
| 59 | namespace hardware { |
| 60 | namespace secure_element { |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 61 | namespace V1_2 { |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 62 | namespace implementation { |
| 63 | |
| 64 | using ::android::sp; |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 65 | using android::base::StringPrintf; |
| 66 | using ::android::hardware::hidl_array; |
| 67 | using ::android::hardware::hidl_memory; |
| 68 | using ::android::hardware::hidl_string; |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 69 | using ::android::hardware::hidl_vec; |
| 70 | using ::android::hardware::Return; |
| 71 | using ::android::hardware::Void; |
| 72 | using ::android::hardware::secure_element::V1_0::LogicalChannelResponse; |
| 73 | using ::android::hardware::secure_element::V1_0::SecureElementStatus; |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 74 | using ::android::hardware::secure_element::V1_2::ISecureElement; |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 75 | using ::android::hidl::base::V1_0::IBase; |
| 76 | |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 77 | #ifndef MIN_APDU_LENGTH |
| 78 | #define MIN_APDU_LENGTH 0x04 |
| 79 | #endif |
| 80 | #ifndef DEFAULT_BASIC_CHANNEL |
| 81 | #define DEFAULT_BASIC_CHANNEL 0x00 |
| 82 | #endif |
| 83 | |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 84 | struct SecureElement : public V1_2::ISecureElement, |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 85 | public hidl_death_recipient { |
| 86 | SecureElement(); |
suryaprakash.konduru | 5818378 | 2023-03-01 10:24:08 +0530 | [diff] [blame] | 87 | // Methods from ::android::hidl::base::V1_0::IBase follow. |
| 88 | Return<void> debug(const hidl_handle& handle, |
| 89 | const hidl_vec<hidl_string>& options) override; |
| 90 | |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 91 | Return<void> init( |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 92 | const sp< |
| 93 | ::android::hardware::secure_element::V1_0::ISecureElementHalCallback>& |
| 94 | clientCallback) override; |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 95 | Return<void> init_1_1( |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 96 | const sp< |
| 97 | ::android::hardware::secure_element::V1_1::ISecureElementHalCallback>& |
| 98 | clientCallback) override; |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 99 | Return<void> getAtr(getAtr_cb _hidl_cb) override; |
| 100 | Return<bool> isCardPresent() override; |
| 101 | Return<void> transmit(const hidl_vec<uint8_t>& data, |
| 102 | transmit_cb _hidl_cb) override; |
| 103 | Return<void> openLogicalChannel(const hidl_vec<uint8_t>& aid, uint8_t p2, |
| 104 | openLogicalChannel_cb _hidl_cb) override; |
| 105 | Return<void> openBasicChannel(const hidl_vec<uint8_t>& aid, uint8_t p2, |
| 106 | openBasicChannel_cb _hidl_cb) override; |
| 107 | Return<SecureElementStatus> closeChannel(uint8_t channelNumber) override; |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 108 | |
| 109 | void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/); |
| 110 | |
| 111 | static void NotifySeWaitExtension(phNxpEse_wtxState state); |
| 112 | Return<::android::hardware::secure_element::V1_0::SecureElementStatus> |
| 113 | reset(); |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 114 | |
| 115 | private: |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 116 | uint8_t mMaxChannelCount; |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 117 | uint8_t mOpenedchannelCount = 0; |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 118 | Mutex seHalLock; |
| 119 | bool mIsEseInitialized = false; |
| 120 | static std::vector<bool> mOpenedChannels; |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 121 | static sp<V1_0::ISecureElementHalCallback> mCallbackV1_0; |
suryaprakash.konduru | 5818378 | 2023-03-01 10:24:08 +0530 | [diff] [blame] | 122 | |
| 123 | std::vector<sp<V1_1::ISecureElementHalCallback>> mCallbacks; |
| 124 | bool mHasPriorityAccess = false; |
| 125 | |
| 126 | void notifyClients(bool connected, std::string reason); |
| 127 | |
| 128 | void registerCallback(const sp<V1_1::ISecureElementHalCallback>& callback); |
| 129 | void unregisterCallback(const sp<IBase>& callback); |
| 130 | |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 131 | Return<SecureElementStatus> seHalDeInit(); |
| 132 | ESESTATUS seHalInit(); |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 133 | Return<SecureElementStatus> internalCloseChannel(uint8_t channelNumber); |
suryaprakash.konduru | 5818378 | 2023-03-01 10:24:08 +0530 | [diff] [blame] | 134 | uint8_t getReserveChannelCnt(const hidl_vec<uint8_t>& aid); |
| 135 | uint8_t getMaxChannelCnt(); |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | } // namespace implementation |
anil.hiranniah | 5472863 | 2021-03-27 10:45:31 +0530 | [diff] [blame] | 139 | } // namespace V1_2 |
pdk | d37a216 | 2019-02-04 12:44:11 -0800 | [diff] [blame] | 140 | } // namespace secure_element |
| 141 | } // namespace hardware |
| 142 | } // namespace android |
| 143 | |
| 144 | #endif // ANDROID_HARDWARE_SECURE_ELEMENT_V1_1_SECUREELEMENT_H |