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 #include "se_impl.h"
17 #include <hdf_base.h>
18 #include <hdf_log.h>
19 #include <vector>
20 
21 #define HDF_LOG_TAG hdf_se
22 
23 #ifdef LOG_DOMAIN
24 #undef LOG_DOMAIN
25 #endif
26 
27 #define LOG_DOMAIN 0xD000305
28 
29 namespace OHOS {
30 namespace HDI {
31 namespace SecureElement {
32 
SecureElementInterfaceImplGetInstance(void)33 extern "C" ISecureElementInterface *SecureElementInterfaceImplGetInstance(void)
34 {
35     using OHOS::HDI::SecureElement::SeImpl;
36     SeImpl* service = new (std::nothrow) SeImpl();
37     if (service == nullptr) {
38         return nullptr;
39     }
40     return service;
41 }
42 
init(const sptr<ISecureElementCallback> & clientCallback,SecureElementStatus & status)43 int32_t SeImpl::init(const sptr<ISecureElementCallback>& clientCallback, SecureElementStatus& status)
44 {
45     return adaptor_.init(clientCallback, status);
46 }
47 
getAtr(std::vector<uint8_t> & response)48 int32_t SeImpl::getAtr(std::vector<uint8_t>& response)
49 {
50     return adaptor_.getAtr(response);
51 }
52 
isSecureElementPresent(bool & present)53 int32_t SeImpl::isSecureElementPresent(bool& present)
54 {
55     return adaptor_.isSecureElementPresent(present);
56 }
57 
openLogicalChannel(const std::vector<uint8_t> & aid,uint8_t p2,std::vector<uint8_t> & response,uint8_t & channelNumber,SecureElementStatus & status)58 int32_t SeImpl::openLogicalChannel(const std::vector<uint8_t>& aid, uint8_t p2, std::vector<uint8_t>& response,
59     uint8_t& channelNumber, SecureElementStatus& status)
60 {
61     return adaptor_.openLogicalChannel(aid, p2, response, channelNumber, status);
62 }
63 
openBasicChannel(const std::vector<uint8_t> & aid,uint8_t p2,std::vector<uint8_t> & response,SecureElementStatus & status)64 int32_t SeImpl::openBasicChannel(const std::vector<uint8_t>& aid, uint8_t p2, std::vector<uint8_t>& response,
65     SecureElementStatus& status)
66 {
67     return adaptor_.openBasicChannel(aid, p2, response, status);
68 }
69 
closeChannel(uint8_t channelNumber,SecureElementStatus & status)70 int32_t SeImpl::closeChannel(uint8_t channelNumber, SecureElementStatus& status)
71 {
72     return adaptor_.closeChannel(channelNumber, status);
73 }
74 
transmit(const std::vector<uint8_t> & command,std::vector<uint8_t> & response,SecureElementStatus & status)75 int32_t SeImpl::transmit(const std::vector<uint8_t>& command, std::vector<uint8_t>& response,
76     SecureElementStatus& status)
77 {
78     return adaptor_.transmit(command, response, status);
79 }
80 
reset(SecureElementStatus & status)81 int32_t SeImpl::reset(SecureElementStatus& status)
82 {
83     return adaptor_.reset(status);
84 }
85 } // SecureElement
86 } // HDI
87 } // OHOS
88