• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_1_SECUREELEMENT_H
20 #define ANDROID_HARDWARE_SECURE_ELEMENT_V1_1_SECUREELEMENT_H
21 
22 #include <android/hardware/secure_element/1.0/types.h>
23 #include <android/hardware/secure_element/1.2/ISecureElement.h>
24 #include <hidl/MQDescriptor.h>
25 #include <hidl/Status.h>
26 #include "../ese-spi-driver/StEseApi.h"
27 
28 namespace android {
29 namespace hardware {
30 namespace secure_element {
31 namespace V1_2 {
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 
39 using ::android::hardware::secure_element::V1_2::ISecureElement;
40 
41 using ::android::hardware::secure_element::V1_0::LogicalChannelResponse;
42 using ::android::hardware::secure_element::V1_0::SecureElementStatus;
43 using ::android::hidl::base::V1_0::IBase;
44 
45 #ifndef MAX_LOGICAL_CHANNELS
46 #define MAX_LOGICAL_CHANNELS 0x04
47 #endif
48 #ifndef MIN_APDU_LENGTH
49 #define MIN_APDU_LENGTH 0x04
50 #endif
51 #ifndef DEFAULT_BASIC_CHANNEL
52 #define DEFAULT_BASIC_CHANNEL 0x00
53 #endif
54 
55 struct SecureElement : public V1_2::ISecureElement,
56                        public hidl_death_recipient {
57   SecureElement();
58   Return<void> init(
59       const sp<V1_0::ISecureElementHalCallback>& clientCallback) override;
60   Return<void> init_1_1(
61       const sp<V1_1::ISecureElementHalCallback>& clientCallback) override;
62   Return<void> getAtr(getAtr_cb _hidl_cb) override;
63   Return<bool> isCardPresent() override;
64   Return<void> transmit(const hidl_vec<uint8_t>& data,
65                         transmit_cb _hidl_cb) override;
66   Return<void> openLogicalChannel(const hidl_vec<uint8_t>& aid, uint8_t p2,
67                                   openLogicalChannel_cb _hidl_cb) override;
68   Return<void> openBasicChannel(const hidl_vec<uint8_t>& aid, uint8_t p2,
69                                 openBasicChannel_cb _hidl_cb) override;
70   Return<::android::hardware::secure_element::V1_0::SecureElementStatus>
71           closeChannel(uint8_t channelNumber) override;
72   void serviceDied(uint64_t /*cookie*/, const wp<IBase>& /*who*/) override;
73   Return<::android::hardware::secure_element::V1_0::SecureElementStatus> reset();
74 
75  private:
76   uint8_t mOpenedchannelCount = 0;
77   bool mOpenedChannels[MAX_LOGICAL_CHANNELS];
78   static sp<V1_0::ISecureElementHalCallback> mCallbackV1_0;
79   static sp<V1_1::ISecureElementHalCallback> mCallbackV1_1;
80   Return<::android::hardware::secure_element::V1_0::SecureElementStatus> seHalDeInit();
81   ESESTATUS seHalInit();
82   bool isSeInitialized();
83   void seHalResetSe();
84 };
85 
86 }  // namespace implementation
87 }  // namespace V1_2
88 }  // namespace secure_element
89 }  // namespace hardware
90 }  // namespace android
91 
92 #endif  // ANDROID_HARDWARE_SECURE_ELEMENT_V1_2_SECUREELEMENT_H
93