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 #include "nci_nfcc_proxy.h"
16 #include "nci_native_selector.h"
17
18 namespace OHOS {
19 namespace NFC {
20 namespace NCI {
NciNfccProxy()21 NciNfccProxy::NciNfccProxy()
22 {
23 nfccInterface_ = NciNativeSelector::GetInstance().GetNciNfccInterface();
24 }
25
26 /**
27 * @brief Initialize when turn on NFC
28 * @return True if success, otherwise false.
29 */
Initialize()30 bool NciNfccProxy::Initialize()
31 {
32 if (nfccInterface_) {
33 return nfccInterface_->Initialize();
34 }
35 return true;
36 }
37
38 /**
39 * @brief Deinitialize when turn off NFC
40 * @return True if success, otherwise false.
41 */
Deinitialize()42 bool NciNfccProxy::Deinitialize()
43 {
44 if (nfccInterface_) {
45 return nfccInterface_->Deinitialize();
46 }
47 return true;
48 }
49
50 /**
51 * @brief Start polling and listening
52 * @param techMask bitmask of the technologies
53 * @param enableReaderMode if enable tag polling
54 * @param enableHostRouting if enable host routing
55 * @param restart true if need restart, otherwise false.
56 */
EnableDiscovery(uint16_t techMask,bool enableReaderMode,bool enableHostRouting,bool restart)57 void NciNfccProxy::EnableDiscovery(uint16_t techMask, bool enableReaderMode, bool enableHostRouting, bool restart)
58 {
59 if (nfccInterface_) {
60 return nfccInterface_->EnableDiscovery(techMask, enableReaderMode, enableHostRouting, restart);
61 }
62 }
63
64 /**
65 * @brief Stop polling and listening
66 */
DisableDiscovery()67 void NciNfccProxy::DisableDiscovery()
68 {
69 if (nfccInterface_) {
70 return nfccInterface_->DisableDiscovery();
71 }
72 }
73
74 /**
75 * @brief Set the screen statue to nfc controller.
76 * @param screenStateMask the bitmask of the screen state
77 * @return True if success, otherwise false.
78 */
SetScreenStatus(uint8_t screenStateMask)79 bool NciNfccProxy::SetScreenStatus(uint8_t screenStateMask)
80 {
81 if (nfccInterface_) {
82 return nfccInterface_->SetScreenStatus(screenStateMask);
83 }
84 return true;
85 }
86
87 /**
88 * @brief Get Nci version supprted by nfc controller.
89 * @return 0x20 if it's NCI2.0, otherwise 0x10 if it's NCI1.0.
90 */
GetNciVersion()91 int NciNfccProxy::GetNciVersion()
92 {
93 if (nfccInterface_) {
94 return nfccInterface_->GetNciVersion();
95 }
96 return 0x10;
97 }
98
99 /**
100 * @brief Abort the nfc controller if NCI timeout.
101 */
Abort()102 void NciNfccProxy::Abort()
103 {
104 if (nfccInterface_) {
105 return nfccInterface_->Abort();
106 }
107 }
108
109 /**
110 * @brief Do factory reset for nfc controller.
111 */
FactoryReset()112 void NciNfccProxy::FactoryReset()
113 {
114 if (nfccInterface_) {
115 return nfccInterface_->FactoryReset();
116 }
117 }
118
119 /**
120 * @brief Shutdown the device. Enable the nfc functionality if support power off case.
121 */
Shutdown()122 void NciNfccProxy::Shutdown()
123 {
124 if (nfccInterface_) {
125 return nfccInterface_->Shutdown();
126 }
127 }
128
129 /**
130 * @brief Send a custom message to vendor
131 */
NotifyMessageToVendor(int key,const std::string & value)132 void NciNfccProxy::NotifyMessageToVendor(int key, const std::string& value)
133 {
134 if (nfccInterface_) {
135 return nfccInterface_->NotifyMessageToVendor(key, value);
136 }
137 }
138 } // namespace NCI
139 } // namespace NFC
140 } // namespace OHOS