1bc2ed2b3Sopenharmony_ci/*
2bc2ed2b3Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License.
5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at
6bc2ed2b3Sopenharmony_ci *
7bc2ed2b3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bc2ed2b3Sopenharmony_ci *
9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and
13bc2ed2b3Sopenharmony_ci * limitations under the License.
14bc2ed2b3Sopenharmony_ci */
15bc2ed2b3Sopenharmony_ci#include "nci_ce_proxy.h"
16bc2ed2b3Sopenharmony_ci#include "nci_native_selector.h"
17bc2ed2b3Sopenharmony_ci
18bc2ed2b3Sopenharmony_cinamespace OHOS {
19bc2ed2b3Sopenharmony_cinamespace NFC {
20bc2ed2b3Sopenharmony_cinamespace NCI {
21bc2ed2b3Sopenharmony_ciNciCeProxy::NciCeProxy()
22bc2ed2b3Sopenharmony_ci{
23bc2ed2b3Sopenharmony_ci    nciCeInterface_ = NciNativeSelector::GetInstance().GetNciCeInterface();
24bc2ed2b3Sopenharmony_ci}
25bc2ed2b3Sopenharmony_ci
26bc2ed2b3Sopenharmony_ci/**
27bc2ed2b3Sopenharmony_ci * @brief Set the listener to receive the card emulation notifications.
28bc2ed2b3Sopenharmony_ci * @param listener The listener to receive the card emulation notifications.
29bc2ed2b3Sopenharmony_ci */
30bc2ed2b3Sopenharmony_civoid NciCeProxy::SetCeHostListener(std::weak_ptr<ICeHostListener> listener)
31bc2ed2b3Sopenharmony_ci{
32bc2ed2b3Sopenharmony_ci    if (nciCeInterface_ && !listener.expired()) {
33bc2ed2b3Sopenharmony_ci        return nciCeInterface_->SetCeHostListener(listener);
34bc2ed2b3Sopenharmony_ci    }
35bc2ed2b3Sopenharmony_ci}
36bc2ed2b3Sopenharmony_ci
37bc2ed2b3Sopenharmony_ci/**
38bc2ed2b3Sopenharmony_ci * @brief compute the routing parameters based on the default payment app and
39bc2ed2b3Sopenharmony_ci * all installed app.
40bc2ed2b3Sopenharmony_ci * @return True if success, otherwise false.
41bc2ed2b3Sopenharmony_ci */
42bc2ed2b3Sopenharmony_cibool NciCeProxy::ComputeRoutingParams(int defaultPaymentType)
43bc2ed2b3Sopenharmony_ci{
44bc2ed2b3Sopenharmony_ci    if (nciCeInterface_) {
45bc2ed2b3Sopenharmony_ci        return nciCeInterface_->ComputeRoutingParams(defaultPaymentType);
46bc2ed2b3Sopenharmony_ci    }
47bc2ed2b3Sopenharmony_ci    return true;
48bc2ed2b3Sopenharmony_ci}
49bc2ed2b3Sopenharmony_ci
50bc2ed2b3Sopenharmony_ci/**
51bc2ed2b3Sopenharmony_ci * @brief Commit the routing parameters to nfc controller.
52bc2ed2b3Sopenharmony_ci * @return True if success, otherwise false.
53bc2ed2b3Sopenharmony_ci */
54bc2ed2b3Sopenharmony_cibool NciCeProxy::CommitRouting()
55bc2ed2b3Sopenharmony_ci{
56bc2ed2b3Sopenharmony_ci    if (nciCeInterface_) {
57bc2ed2b3Sopenharmony_ci        return nciCeInterface_->CommitRouting();
58bc2ed2b3Sopenharmony_ci    }
59bc2ed2b3Sopenharmony_ci    return true;
60bc2ed2b3Sopenharmony_ci}
61bc2ed2b3Sopenharmony_ci
62bc2ed2b3Sopenharmony_ci/**
63bc2ed2b3Sopenharmony_ci * @brief  send raw frame data
64bc2ed2b3Sopenharmony_ci * @param  hexCmdData the data to send
65bc2ed2b3Sopenharmony_ci * @return True if success, otherwise false.
66bc2ed2b3Sopenharmony_ci */
67bc2ed2b3Sopenharmony_cibool NciCeProxy::SendRawFrame(std::string &hexCmdData)
68bc2ed2b3Sopenharmony_ci{
69bc2ed2b3Sopenharmony_ci    if (nciCeInterface_) {
70bc2ed2b3Sopenharmony_ci        return nciCeInterface_->SendRawFrame(hexCmdData);
71bc2ed2b3Sopenharmony_ci    }
72bc2ed2b3Sopenharmony_ci    return false;
73bc2ed2b3Sopenharmony_ci}
74bc2ed2b3Sopenharmony_ci
75bc2ed2b3Sopenharmony_cibool NciCeProxy::AddAidRouting(const std::string &aidStr, int route, int aidInfo,
76bc2ed2b3Sopenharmony_ci                               int power)
77bc2ed2b3Sopenharmony_ci{
78bc2ed2b3Sopenharmony_ci    if (nciCeInterface_) {
79bc2ed2b3Sopenharmony_ci        return nciCeInterface_->AddAidRouting(aidStr, route, aidInfo, power);
80bc2ed2b3Sopenharmony_ci    }
81bc2ed2b3Sopenharmony_ci    return false;
82bc2ed2b3Sopenharmony_ci}
83bc2ed2b3Sopenharmony_ci
84bc2ed2b3Sopenharmony_cibool NciCeProxy::ClearAidTable()
85bc2ed2b3Sopenharmony_ci{
86bc2ed2b3Sopenharmony_ci    if (nciCeInterface_) {
87bc2ed2b3Sopenharmony_ci        return nciCeInterface_->ClearAidTable();
88bc2ed2b3Sopenharmony_ci    }
89bc2ed2b3Sopenharmony_ci    return false;
90bc2ed2b3Sopenharmony_ci}
91bc2ed2b3Sopenharmony_cistd::string NciCeProxy::GetSimVendorBundleName()
92bc2ed2b3Sopenharmony_ci{
93bc2ed2b3Sopenharmony_ci    if (nciCeInterface_) {
94bc2ed2b3Sopenharmony_ci        return nciCeInterface_->GetSimVendorBundleName();
95bc2ed2b3Sopenharmony_ci    }
96bc2ed2b3Sopenharmony_ci    return "";
97bc2ed2b3Sopenharmony_ci}
98bc2ed2b3Sopenharmony_ci
99bc2ed2b3Sopenharmony_civoid NciCeProxy::NotifyDefaultPaymentType(int paymentType)
100bc2ed2b3Sopenharmony_ci{
101bc2ed2b3Sopenharmony_ci    if (nciCeInterface_) {
102bc2ed2b3Sopenharmony_ci        nciCeInterface_->NotifyDefaultPaymentType(paymentType);
103bc2ed2b3Sopenharmony_ci    }
104bc2ed2b3Sopenharmony_ci}
105bc2ed2b3Sopenharmony_ci} // namespace NCI
106bc2ed2b3Sopenharmony_ci} // namespace NFC
107bc2ed2b3Sopenharmony_ci} // namespace OHOS