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