• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TAG_SESSION_H
16 #define TAG_SESSION_H
17 
18 #include "element_name.h"
19 #include "infcc_host.h"
20 #include "infc_service.h"
21 #include "itag_session.h"
22 #include "tag_dispatcher.h"
23 #include "tag_session_stub.h"
24 
25 namespace OHOS {
26 namespace NFC {
27 namespace TAG {
28 using OHOS::AppExecFwk::ElementName;
29 class TagSession final : public TagSessionStub {
30 public:
31     // Constructor/Destructor
32     explicit TagSession(std::shared_ptr<NFC::INfcService> service);
33     ~TagSession() override;
34     TagSession(const TagSession&) = delete;
35     TagSession& operator=(const TagSession&) = delete;
36 
37     /**
38      * @brief To connect the tagRfDiscId by technology.
39      * @param tagRfDiscId the rf disc id of tag
40      * @param technology the tag technology
41      * @return the result to connect the tag
42      */
43     int Connect(int tagRfDiscId, int technology) override;
44     /**
45      * @brief To reconnect the tagRfDiscId.
46      * @param tagRfDiscId the rf disc id of tag
47      * @return the result to reconnect the tag
48      */
49     int Reconnect(int tagRfDiscId) override;
50     /**
51      * @brief To disconnect the tagRfDiscId.
52      * @param tagRfDiscId the rf disc id of tag
53      */
54     void Disconnect(int tagRfDiscId) override;
55         /**
56      * @brief Set the Timeout for tag operations
57      *
58      * @param timeout the timeout value to set for tag operations
59      * @param technology the tag technology
60      * @return true success of setting timeout value
61      * @return false failure of setting timeout value
62      */
63     int SetTimeout(int timeout, int technology) override;
64     /**
65      * @brief Get the Timeout value of tag operations
66      *
67      * @param technology the tag technology
68      * @param timeout the output to read the timeout value.
69      * @return the status code of function calling.
70      */
71     int GetTimeout(int technology, int &timeout) override;
72     /**
73      * @brief Get the TechList of the tagRfDiscId.
74      * @param tagRfDiscId the rf disc id of tag
75      * @return TechList
76      */
77     std::vector<int> GetTechList(int tagRfDiscId) override;
78     /**
79      * @brief Checking the tagRfDiscId is present.
80      * @param tagRfDiscId the rf disc id of tag
81      * @return true - Presnet; the other - No Presnet
82      */
83     bool IsTagFieldOn(int tagRfDiscId) override;
84     /**
85      * @brief Checking the tagRfDiscId is a Ndef Tag.
86      * @param tagRfDiscId the rf disc id of tag
87      * @return true - Ndef Tag; the other - No Ndef Tag
88      */
89     bool IsNdef(int tagRfDiscId) override;
90 
91     int SendRawFrame(int tagRfDiscId, std::string hexCmdData, bool raw, std::string &hexRespData) override;
92     /**
93      * @brief Reading from the host tag
94      * @param tagRfDiscId the rf disc id of tag
95      * @return the read data
96      */
97     std::string NdefRead(int tagRfDiscId) override;
98     /**
99      * @brief Writing the data into the host tag.
100      * @param tagRfDiscId the rf disc id of tag
101      * @param msg the wrote data
102      * @return the Writing Result
103      */
104     int NdefWrite(int tagRfDiscId, std::string msg) override;
105     /**
106      * @brief Making the host tag to read only.
107      * @param tagRfDiscId the rf disc id of tag
108      * @return the making result
109      */
110     int NdefMakeReadOnly(int tagRfDiscId) override;
111     /**
112      * @brief format the tag by Ndef
113      * @param tagRfDiscId the rf disc id of tag
114      * @param key the format key
115      * @return the format result
116      */
117     int FormatNdef(int tagRfDiscId, const std::string& key) override;
118 
119     int CanMakeReadOnly(int ndefType, bool &canSetReadOnly) override;
120     int GetMaxTransceiveLength(int technology, int &maxSize) override;
121     int IsSupportedApdusExtended(bool &isSupported) override;
122 
123     /**
124      * @brief register foreground dispatch
125      *
126      * @param element the element name of the hap that request to register foreground dispatch.
127      * @param discTech the tag technologies in int array the the hap wants to discover.
128      * @param callback the callback to be registered
129      * @return The status code for register operation.
130      */
131     KITS::ErrorCode RegForegroundDispatch(ElementName element,
132         std::vector<uint32_t> &discTech, const sptr<KITS::IForegroundCallback> &callback) override;
133 
134     /**
135      * @brief unregister foreground dispatch
136      *
137      * @param element the element name of the hap that request to unregister foreground dispatch.
138      * @return The status code for unregister operation.
139      */
140     KITS::ErrorCode UnregForegroundDispatch(ElementName element) override;
141 
142     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
143 private:
144     std::string GetDumpInfo();
145     std::weak_ptr<NFC::INfcService> nfcService_ {};
146     std::weak_ptr<NCI::INfccHost> nfccHost_ {};
147     std::weak_ptr<TagDispatcher> tagDispatcher_ {};
148 };
149 }  // namespace TAG
150 }  // namespace NFC
151 }  // namespace OHOS
152 #endif  // TAG_SESSION_H
153