1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef OHOS_HDI_SECURE_ELEMENT_V1_0_ISECUREELEMENTINTERFACE_H
17#define OHOS_HDI_SECURE_ELEMENT_V1_0_ISECUREELEMENTINTERFACE_H
18
19#include <stdint.h>
20#include <vector>
21#include <hdf_base.h>
22#include <hdi_base.h>
23#include "secure_element/v1_0/isecure_element_callback.h"
24#include "secure_element/v1_0/secure_element_types.h"
25
26#ifndef HDI_BUFF_MAX_SIZE
27#define HDI_BUFF_MAX_SIZE (1024 * 200)
28#endif
29
30#ifndef HDI_CHECK_VALUE_RETURN
31#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \
32    if ((lv) compare (rv)) { \
33        return ret; \
34    } \
35} while (false)
36#endif
37
38#ifndef HDI_CHECK_VALUE_RET_GOTO
39#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \
40    if ((lv) compare (rv)) { \
41        ret = value; \
42        goto table; \
43    } \
44} while (false)
45#endif
46
47namespace OHOS {
48namespace HDI {
49namespace SecureElement {
50namespace V1_0 {
51using namespace OHOS;
52using namespace OHOS::HDI;
53
54enum {
55    CMD_SECURE_ELEMENT_INTERFACE_GET_VERSION = 0,
56    CMD_SECURE_ELEMENT_INTERFACE_INIT = 1,
57    CMD_SECURE_ELEMENT_INTERFACE_GET_ATR = 2,
58    CMD_SECURE_ELEMENT_INTERFACE_IS_SECURE_ELEMENT_PRESENT = 3,
59    CMD_SECURE_ELEMENT_INTERFACE_OPEN_LOGICAL_CHANNEL = 4,
60    CMD_SECURE_ELEMENT_INTERFACE_OPEN_BASIC_CHANNEL = 5,
61    CMD_SECURE_ELEMENT_INTERFACE_CLOSE_CHANNEL = 6,
62    CMD_SECURE_ELEMENT_INTERFACE_TRANSMIT = 7,
63    CMD_SECURE_ELEMENT_INTERFACE_RESET = 8,
64};
65
66class ISecureElementInterface : public HdiBase {
67public:
68    DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.secure_element.v1_0.ISecureElementInterface");
69
70    virtual ~ISecureElementInterface() = default;
71
72    static sptr<OHOS::HDI::SecureElement::V1_0::ISecureElementInterface> Get(bool isStub = false);
73    static sptr<OHOS::HDI::SecureElement::V1_0::ISecureElementInterface> Get(const std::string &serviceName, bool isStub = false);
74
75    virtual int32_t init(const sptr<OHOS::HDI::SecureElement::V1_0::ISecureElementCallback>& clientCallback,
76         OHOS::HDI::SecureElement::V1_0::SecureElementStatus& status) = 0;
77
78    virtual int32_t getAtr(std::vector<uint8_t>& response) = 0;
79
80    virtual int32_t isSecureElementPresent(bool& present) = 0;
81
82    virtual int32_t openLogicalChannel(const std::vector<uint8_t>& aid, uint8_t p2, std::vector<uint8_t>& response,
83         uint8_t& channelNumber, OHOS::HDI::SecureElement::V1_0::SecureElementStatus& status) = 0;
84
85    virtual int32_t openBasicChannel(const std::vector<uint8_t>& aid, uint8_t p2, std::vector<uint8_t>& response,
86         OHOS::HDI::SecureElement::V1_0::SecureElementStatus& status) = 0;
87
88    virtual int32_t closeChannel(uint8_t channelNumber,
89         OHOS::HDI::SecureElement::V1_0::SecureElementStatus& status) = 0;
90
91    virtual int32_t transmit(const std::vector<uint8_t>& command, std::vector<uint8_t>& response,
92         OHOS::HDI::SecureElement::V1_0::SecureElementStatus& status) = 0;
93
94    virtual int32_t reset(OHOS::HDI::SecureElement::V1_0::SecureElementStatus& status) = 0;
95
96    virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer)
97    {
98        majorVer = 1;
99        minorVer = 0;
100        return HDF_SUCCESS;
101    }
102
103    virtual bool IsProxy()
104    {
105        return false;
106    }
107
108    virtual const std::u16string GetDesc()
109    {
110        return metaDescriptor_;
111    }
112};
113} // V1_0
114} // SecureElement
115} // HDI
116} // OHOS
117
118#endif // OHOS_HDI_SECURE_ELEMENT_V1_0_ISECUREELEMENTINTERFACE_H
119
120