1 /*
2  * Copyright (C) 2022 - 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 I_TAG_SESSION_H
16 #define I_TAG_SESSION_H
17 #include "element_name.h"
18 #include "iforeground_callback.h"
19 #include "ireader_mode_callback.h"
20 #include "iremote_broker.h"
21 #include "nfc_sdk_common.h"
22 #include "parcel.h"
23 
24 namespace OHOS {
25 namespace NFC {
26 namespace TAG {
27 class ITagSession : public OHOS::IRemoteBroker {
28 public:
29     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.nfc.TAG.ITagSession");
30 
~ITagSession()31     virtual ~ITagSession() {}
32     /**
33      * @brief To connect the tagRfDiscId by technology.
34      * @param tagRfDiscId the rf disc id of tag
35      * @param technology the tag technology
36      * @return the result to connect the tag
37      */
38     virtual int Connect(int tagRfDiscId, int technology) = 0;
39     /**
40      * @brief To get connection status of tag.
41      * @param tagRfDiscId the rf disc id of tag
42      * @param isConnected the connection status of tag
43      * @return the status code for function calling
44      */
45     virtual int IsConnected(int tagRfDiscId, bool &isConnected) = 0;
46     /**
47      * @brief To reconnect the tagRfDiscId.
48      * @param tagRfDiscId the rf disc id of tag
49      * @return the result to reconnect the tag
50      */
51     virtual int Reconnect(int tagRfDiscId) = 0;
52     /**
53      * @brief To disconnect the tagRfDiscId.
54      * @param tagRfDiscId the rf disc id of tag
55      */
56     virtual void Disconnect(int tagRfDiscId) = 0;
57     /**
58      * @brief Set the Timeout for tag operations
59      *
60      * @param timeout the timeout value to set for tag operations
61      * @param technology the tag technology
62      * @return the tatus code for function calling.
63      */
64     virtual int SetTimeout(int tagRfDiscId, int timeout, int technology) = 0;
65     /**
66      * @brief Get the Timeout value of tag operations
67      * @param tagRfDiscId the rf disc id of tag
68      * @param technology the tag technology
69      * @param timeout the output argument to read the timeout.
70      * @return the tatus code for function calling.
71      */
72     virtual int GetTimeout(int tagRfDiscId, int technology, int &timeout) = 0;
73     /**
74      * @brief Reset the Timeout value of tag operations
75      *
76      * @param tagRfDiscId the rf disc id of tag
77      */
78     virtual void ResetTimeout(int tagRfDiscId) = 0;
79     /**
80      * @brief Get the TechList of the tagRfDiscId.
81      * @param tagRfDiscId the rf disc id of tag
82      * @return TechList
83      */
84     virtual std::vector<int> GetTechList(int tagRfDiscId) = 0;
85     /**
86      * @brief Checking the tagRfDiscId is field on.
87      * @param tagRfDiscId the rf disc id of tag
88      * @return true - Presnet; the other - No Presnet
89      */
90     virtual bool IsTagFieldOn(int tagRfDiscId) = 0;
91     /**
92      * @brief Checking the tagRfDiscId is a Ndef Tag.
93      * @param tagRfDiscId the rf disc id of tag
94      * @return true - Ndef Tag; the other - No Ndef Tag
95      */
96     virtual bool IsNdef(int tagRfDiscId) = 0;
97     /**
98      * @brief To send the data to the tagRfDiscId.
99      * @param tagRfDiscId the rf disc id of tag
100      * @param hexCmdData the sent data
101      * @param hexRespData the response hex data.
102      * @param raw to send whether original data or un-original data
103      * @return the error code of calling function.
104      */
105     virtual int SendRawFrame(const int tagRfDiscId, std::string hexCmdData, bool raw, std::string &hexRespData) = 0;
106     /**
107      * @brief Reading from the host tag
108      * @param tagRfDiscId the rf disc id of tag
109      * @return the read data
110      */
111     virtual int NdefRead(int tagRfDiscId, std::string &ndefMessage) = 0;
112     /**
113      * @brief Writing the data into the host tag.
114      * @param tagRfDiscId the rf disc id of tag
115      * @param msg the wrote data
116      * @return the Writing Result
117      */
118     virtual int NdefWrite(int tagRfDiscId, std::string msg) = 0;
119     /**
120      * @brief Making the host tag to read only.
121      * @param tagRfDiscId the rf disc id of tag
122      * @return the making result
123      */
124     virtual int NdefMakeReadOnly(int tagRfDiscId) = 0;
125     /**
126      * @brief format the tag by Ndef
127      * @param tagRfDiscId the rf disc id of tag
128      * @param key the format key
129      * @return the format result
130      */
131     virtual int FormatNdef(int tagRfDiscId, const std::string& key) = 0;
132     /**
133      * @brief Checking the host tag is Read only
134      * @param ndefType the ndef type.
135      * @param canSetReadOnly the output for read only or not.
136      * @return the error code of calling function.
137      */
138     virtual int CanMakeReadOnly(int ndefType, bool &canSetReadOnly) = 0;
139     /**
140      * @brief Get Max Transceive Length
141      * @param technology the tag technology
142      * @return Max Transceive Length
143      */
144     virtual int GetMaxTransceiveLength(int technology, int &maxSize) = 0;
145     /**
146      * @brief Checking the NFCC whether It supported the extended Apdus
147      * @param isSupported the output for checking supportting extended apdu or not.
148      * @return the error code of calling function.
149      */
150     virtual int IsSupportedApdusExtended(bool &isSupported) = 0;
151 
152     /**
153      * @brief register foreground dispatch
154      *
155      * @param element the element name of the hap that request to register foreground dispatch.
156      * @param discTech the tag technologies in int array the the hap wants to discover.
157      * @param callback the callback to be registered
158      * @return The status code for register operation.
159      */
160     virtual int RegForegroundDispatch(AppExecFwk::ElementName &element,
161         std::vector<uint32_t> &discTech, const sptr<KITS::IForegroundCallback> &callback) = 0;
162 
163     /**
164      * @brief unregister foreground dispatch
165      *
166      * @param element the element name of the hap that request to unregister foreground dispatch.
167      * @return The status code for unregister operation.
168      */
169     virtual int UnregForegroundDispatch(AppExecFwk::ElementName &element) = 0;
170 
171     /**
172      * @brief register reader mode
173      *
174      * @param element the element name of the hap that request to register reader mode.
175      * @param discTech the tag technologies in int array the the hap wants to discover.
176      * @param callback the callback to be registered
177      * @return The status code for register operation.
178      */
179     virtual int RegReaderMode(AppExecFwk::ElementName &element,
180         std::vector<uint32_t> &discTech, const sptr<KITS::IReaderModeCallback> &callback) = 0;
181 
182     /**
183      * @brief unregister reader mode
184      *
185      * @param element the element name of the hap that request to unregister reader mode.
186      * @return The status code for unregister operation.
187      */
188     virtual int UnregReaderMode(AppExecFwk::ElementName &element) = 0;
189 private:
190 };
191 }  // namespace TAG
192 }  // namespace NFC
193 }  // namespace OHOS
194 #endif  // I_TAG_SESSION_H
195