blob: 0f503c0d66031358528810c038a95de60a6b0424 [file] [log] [blame]
pdkd37a2162019-02-04 12:44:11 -08001/******************************************************************************
2 *
suryaprakash.konduru58183782023-03-01 10:24:08 +05303 * Copyright 2020,2022 NXP
pdkd37a2162019-02-04 12:44:11 -08004 *
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.hiranniah54728632021-03-27 10:45:31 +053018#ifndef ANDROID_HARDWARE_SECURE_ELEMENT_V1_2_SECUREELEMENT_H
19#define ANDROID_HARDWARE_SECURE_ELEMENT_V1_2_SECUREELEMENT_H
pdkd37a2162019-02-04 12:44:11 -080020
anil.hiranniah54728632021-03-27 10:45:31 +053021#include <SyncEvent.h>
22#include <android-base/stringprintf.h>
pdkd37a2162019-02-04 12:44:11 -080023#include <android/hardware/secure_element/1.0/types.h>
anil.hiranniah54728632021-03-27 10:45:31 +053024#include <android/hardware/secure_element/1.2/ISecureElement.h>
25#include <hardware/hardware.h>
pdkd37a2162019-02-04 12:44:11 -080026#include <hidl/MQDescriptor.h>
27#include <hidl/Status.h>
anil.hiranniah54728632021-03-27 10:45:31 +053028#include <pthread.h>
suryaprakash.konduru58183782023-03-01 10:24:08 +053029
30#include <vector>
31
anil.hiranniah54728632021-03-27 10:45:31 +053032#include "OsuHalExtn.h"
pdkd37a2162019-02-04 12:44:11 -080033#include "phNxpEse_Api.h"
34
anil.hiranniah54728632021-03-27 10:45:31 +053035class 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
47class 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
pdkd37a2162019-02-04 12:44:11 -080058namespace android {
59namespace hardware {
60namespace secure_element {
anil.hiranniah54728632021-03-27 10:45:31 +053061namespace V1_2 {
pdkd37a2162019-02-04 12:44:11 -080062namespace implementation {
63
64using ::android::sp;
anil.hiranniah54728632021-03-27 10:45:31 +053065using android::base::StringPrintf;
66using ::android::hardware::hidl_array;
67using ::android::hardware::hidl_memory;
68using ::android::hardware::hidl_string;
pdkd37a2162019-02-04 12:44:11 -080069using ::android::hardware::hidl_vec;
70using ::android::hardware::Return;
71using ::android::hardware::Void;
72using ::android::hardware::secure_element::V1_0::LogicalChannelResponse;
73using ::android::hardware::secure_element::V1_0::SecureElementStatus;
anil.hiranniah54728632021-03-27 10:45:31 +053074using ::android::hardware::secure_element::V1_2::ISecureElement;
pdkd37a2162019-02-04 12:44:11 -080075using ::android::hidl::base::V1_0::IBase;
76
pdkd37a2162019-02-04 12:44:11 -080077#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.hiranniah54728632021-03-27 10:45:31 +053084struct SecureElement : public V1_2::ISecureElement,
pdkd37a2162019-02-04 12:44:11 -080085 public hidl_death_recipient {
86 SecureElement();
suryaprakash.konduru58183782023-03-01 10:24:08 +053087 // 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
pdkd37a2162019-02-04 12:44:11 -080091 Return<void> init(
anil.hiranniah54728632021-03-27 10:45:31 +053092 const sp<
93 ::android::hardware::secure_element::V1_0::ISecureElementHalCallback>&
94 clientCallback) override;
pdkd37a2162019-02-04 12:44:11 -080095 Return<void> init_1_1(
anil.hiranniah54728632021-03-27 10:45:31 +053096 const sp<
97 ::android::hardware::secure_element::V1_1::ISecureElementHalCallback>&
98 clientCallback) override;
pdkd37a2162019-02-04 12:44:11 -080099 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.hiranniah54728632021-03-27 10:45:31 +0530108
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();
pdkd37a2162019-02-04 12:44:11 -0800114
115 private:
anil.hiranniah54728632021-03-27 10:45:31 +0530116 uint8_t mMaxChannelCount;
pdkd37a2162019-02-04 12:44:11 -0800117 uint8_t mOpenedchannelCount = 0;
anil.hiranniah54728632021-03-27 10:45:31 +0530118 Mutex seHalLock;
119 bool mIsEseInitialized = false;
120 static std::vector<bool> mOpenedChannels;
pdkd37a2162019-02-04 12:44:11 -0800121 static sp<V1_0::ISecureElementHalCallback> mCallbackV1_0;
suryaprakash.konduru58183782023-03-01 10:24:08 +0530122
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
pdkd37a2162019-02-04 12:44:11 -0800131 Return<SecureElementStatus> seHalDeInit();
132 ESESTATUS seHalInit();
anil.hiranniah54728632021-03-27 10:45:31 +0530133 Return<SecureElementStatus> internalCloseChannel(uint8_t channelNumber);
suryaprakash.konduru58183782023-03-01 10:24:08 +0530134 uint8_t getReserveChannelCnt(const hidl_vec<uint8_t>& aid);
135 uint8_t getMaxChannelCnt();
pdkd37a2162019-02-04 12:44:11 -0800136};
137
138} // namespace implementation
anil.hiranniah54728632021-03-27 10:45:31 +0530139} // namespace V1_2
pdkd37a2162019-02-04 12:44:11 -0800140} // namespace secure_element
141} // namespace hardware
142} // namespace android
143
144#endif // ANDROID_HARDWARE_SECURE_ELEMENT_V1_1_SECUREELEMENT_H