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 #ifndef NCI_TAG_PROXY_H
16 #define NCI_TAG_PROXY_H
17 #include "inci_tag_interface.h"
18 
19 namespace OHOS {
20 namespace NFC {
21 namespace NCI {
22 class NciTagProxy final : public INciTagInterface {
23 public:
24     NciTagProxy();
25 
26     /**
27      * @brief Set tag listener to receive tag status.
28      * @param listener The listener to receive tag status.
29      */
30     void SetTagListener(std::weak_ptr<ITagListener> listener) override;
31 
32     /**
33      * @brief Get the discovered technologies found.
34      * @param tagDiscId The tag discovered id given from nci stack.
35      * @return The technologies list.
36      */
37     std::vector<int> GetTechList(uint32_t tagDiscId) override;
38 
39     /**
40      * @brief Get the connected technology, the technology specific when call Connect(uint32_t technology).
41      * @param tagDiscId The tag discovered id given from nci stack.
42      * @return The connected technology.
43      */
44     uint32_t GetConnectedTech(uint32_t tagDiscId) override;
45 
46     /**
47      * @brief Get the extra data of all discovered technologies, Key and value.
48      * @param tagDiscId The tag discovered id given from nci stack.
49      * @return The extra data of all discovered technologies.
50      */
51     std::vector<AppExecFwk::PacMap> GetTechExtrasData(uint32_t tagDiscId) override;
52 
53     /**
54      * @brief Get the uid of discovered tag.
55      * @param tagDiscId The tag discovered id given from nci stack.
56      * @return The uid of discovered tag, such as DD236DEB.
57      */
58     std::string GetTagUid(uint32_t tagDiscId) override;
59 
60     /**
61      * @brief Connect the tag.
62      * @param tagDiscId The tag discovered id given from nci stack.
63      * @param technology The technology of the tag using to connect.
64      * @return True if success, otherwise false.
65      */
66     bool Connect(uint32_t tagDiscId, uint32_t technology) override;
67 
68     /**
69      * @brief Disconnect the tag
70      * @param tagDiscId The tag discovered id given from nci stack.
71      * @return True if success, otherwise false.
72      */
73     bool Disconnect(uint32_t tagDiscId) override;
74 
75     /**
76      * @brief Reconnect the tag
77      * @param tagDiscId The tag discovered id given from nci stack.
78      * @return True if success, otherwise false.
79      */
80     bool Reconnect(uint32_t tagDiscId) override;
81 
82     /**
83      * @brief Send command to tag and receive response.
84      * @param tagDiscId The tag discovered id given from nci stack.
85      * @param command The command to send.
86      * @param response The response from the tag.
87      * @return The status code to transceive the command.
88      */
89     int Transceive(uint32_t tagDiscId, const std::string& command, std::string& response) override;
90 
91     /**
92      * @brief Read the NDEF tag.
93      * @param tagDiscId The tag discovered id given from nci stack.
94      * @return The data read from NDEF tag.
95      */
96     std::string ReadNdef(uint32_t tagDiscId) override;
97 
98     /**
99      * @brief Find the NDEF tag technology from the NDEF tag data.
100      * @param tagDiscId The tag discovered id given from nci stack.
101      * @return The data read from NDEF tag.
102      */
103     std::string FindNdefTech(uint32_t tagDiscId) override;
104 
105     /**
106      * @brief Write command to NDEF tag.
107      * @param tagDiscId The tag discovered id given from nci stack.
108      * @param command The command to write to NDEF tag.
109      * @return True if success, otherwise false.
110      */
111     bool WriteNdef(uint32_t tagDiscId, std::string& command) override;
112 
113     /**
114      * @brief Format NDEF tag.
115      * @param tagDiscId The tag discovered id given from nci stack.
116      * @param key The key used to format the NDEF.
117      * @return True if success, otherwise false.
118      */
119     bool FormatNdef(uint32_t tagDiscId, const std::string& key) override;
120 
121     /**
122      * @brief Format NDEF tag.
123      * @param key The key used to format the NDEF.
124      * @return True if success, otherwise false.
125      */
126     bool CanMakeReadOnly(uint32_t ndefType) override;
127 
128     /**
129      * @brief Set the NDEF to be read only.
130      * @param tagDiscId The tag discovered id given from nci stack.
131      * @return True if success, otherwise false.
132      */
133     bool SetNdefReadOnly(uint32_t tagDiscId) override;
134 
135     /**
136      * @brief Detect the NDEF info, includes the max size and the mode.
137      * @param tagDiscId The tag discovered id given from nci stack.
138      * @param ndefInfo The output to save the detected result.
139      * @return True if success, otherwise false.
140      */
141     bool DetectNdefInfo(uint32_t tagDiscId, std::vector<int>& ndefInfo) override;
142 
143     /**
144      * @brief Check current tag is field on or not.
145      * @param tagDiscId The tag discovered id given from nci stack.
146      * @return True if current tag is field on, otherwise false.
147      */
148     bool IsTagFieldOn(uint32_t tagDiscId) override;
149 
150     /**
151      * @brief Start field on checking for tag. If tag lost, callback to notify.
152      * @param tagDiscId The tag discovered id given from nci stack.
153      * @param delayedMs The delayed time to check the tag lost.
154      */
155     void StartFieldOnChecking(uint32_t tagDiscId, uint32_t delayedMs) override;
156 
157     /**
158      * @brief Stop field on checking for tag if tag is connected.
159      */
160     void StopFieldChecking() override;
161 
162     /**
163      * @brief Config the timeout value to nfc controller when read or write tag.
164      * @param tagDiscId The tag discovered id given from nci stack.
165      * @param timeout The timeout value to config.
166      * @param technology The technology to config.
167      */
168     void SetTimeout(uint32_t tagDiscId, uint32_t timeout, uint32_t technology) override;
169 
170     /**
171      * @brief Get the timeout value to nfc controller when read or write tag.
172      * @param tagDiscId The tag discovered id given from nci stack.
173      * @param timeout The timeout value to config.
174      * @param technology The technology to config.
175      */
176     void GetTimeout(uint32_t tagDiscId, uint32_t &timeout, uint32_t technology) override;
177 
178     /**
179      * @brief Reset the timeout value to nfc controller when read or write tag.
180      * @param tagDiscId The tag discovered id given from nci stack.
181      */
182     void ResetTimeout(uint32_t tagDiscId) override;
183 
184     /**
185      * @brief Get the max transceive length of ISO-DEP technology.
186      * @return The max transceive length of ISO-DEP technology.
187      */
188     uint32_t GetIsoDepMaxTransceiveLength() override;
189 
190     /**
191      * @brief Check if the nfc controller support extended APDU or not.
192      * @return True if the nfc controller support extended APDU, otherwise false.
193      */
194     bool IsExtendedLengthApduSupported() override;
195 
196     /**
197      * @brief Build the tech mask by all given technologies.
198      * @param discTech The given technology list.
199      * @return The technology mask.
200      */
201     uint16_t GetTechMaskFromTechList(const std::vector<uint32_t> &discTech) override;
202 
203     /**
204      * @brief Try parse harPackage in vendor.
205      * @return True if vendor parsed harPackage, otherwise false.
206      */
207     bool VendorParseHarPackage(std::vector<std::string> &harPackages) override;
208 
209     /**
210      * @brief Get browser bundle name of the vendor.
211      * @return Browser bundle name of the vendor.
212      */
213     std::string GetVendorBrowserBundleName() override;
214 
215     /**
216      * @brief Get AppGallery bundle name of the vendor.
217      * @return AppGallery bundle name of the vendor.
218      */
219     std::string GetVendorAppGalleryBundleName() override;
220 #ifdef VENDOR_APPLICATIONS_ENABLED
221     /**
222      * @brief Check current ipc thread come from vendor process or not.
223      * @return Is Vendor Process.
224      */
225     bool IsVendorProcess() override;
226 #endif
227 private:
228     std::shared_ptr<INciTagInterface> nciTagInterface_;
229 };
230 }  // namespace NCI
231 }  // namespace NFC
232 }  // namespace OHOS
233 #endif  // NCI_TAG_PROXY_H