• 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 NDEF_TAG_H
16 #define NDEF_TAG_H
17 
18 #include "basic_tag_session.h"
19 #include "ndef_message.h"
20 
21 namespace OHOS {
22 namespace NFC {
23 namespace KITS {
24 class NdefTag final : public BasicTagSession {
25 public:
26     enum EmNfcForumType {
27         NFC_FORUM_TYPE_UNKNOWN = 0,
28         NFC_FORUM_TYPE_1 = 1,
29         NFC_FORUM_TYPE_2 = 2,
30         NFC_FORUM_TYPE_3 = 3,
31         NFC_FORUM_TYPE_4 = 4,
32         MIFARE_CLASSIC = 101,
33         ICODE_SLI = 102
34     };
35 
36     const std::string STRING_NFC_FORUM_TYPE_1 = "org.nfcforum.ndef.type1";
37     const std::string STRING_NFC_FORUM_TYPE_2 = "org.nfcforum.ndef.type2";
38     const std::string STRING_NFC_FORUM_TYPE_3 = "org.nfcforum.ndef.type3";
39     const std::string STRING_NFC_FORUM_TYPE_4 = "org.nfcforum.ndef.type4";
40     const std::string STRING_MIFARE_CLASSIC = "com.nxp.ndef.mifareclassic";
41     const std::string STRING_ICODE_SLI = "com.nxp.ndef.icodesli";
42 
43     enum EmNdefTagMode { MODE_UNKNOW = 0, MODE_READ_ONLY, MODE_READ_WRITE };
44 
45 public:
46     explicit NdefTag(std::weak_ptr<TagInfo> tag);
~NdefTag()47     ~NdefTag() {}
48 
49     /**
50      * @Description Get an object of NdefTag for the given tag.
51      * @param tag compatible with all types of tag
52      * @return std::shared_ptr<NdefTag>
53      */
54     static std::shared_ptr<NdefTag> GetTag(std::weak_ptr<TagInfo> tag);
55     /**
56      * @Description Get the type of the Ndef tag in bytes.
57      * @param void
58      * @return type of Ndef tag.
59      */
60     EmNfcForumType GetNdefTagType() const;
61     /**
62      * @Description Get the mode of the Ndef tag in bytes.(readonly, read/write, unknown)
63      * @param void
64      * @return mode of Ndef tag.
65      */
66     EmNdefTagMode GetNdefTagMode() const;
67     /**
68      * @brief Get the Max Tag Size for this found ndef tag
69      *
70      * @return the max tag size when the tag is discoveried.
71      */
72     uint32_t GetMaxTagSize() const;
73     /**
74      * @Description Get the ndef message that was read from ndef tag when tag discovery.
75      * @param void
76      * @return ndef message.
77      */
78     std::shared_ptr<NdefMessage> GetCachedNdefMsg() const;
79     /**
80      * @Description Check ndef tag is writable
81      * @param void
82      * @return return true if the tag is writable, otherwise return false.
83      */
84     bool IsNdefWritable() const;
85     /**
86      * @Description Read ndef tag
87      * @param ndefMessage the NdefMessage instance read.
88      * @return the error code of calling function.
89      */
90     int ReadNdef(std::shared_ptr<NdefMessage> &ndefMessage);
91     /**
92      * @Description write ndef tag
93      * @param msg ndef message to write
94      * @return Errorcode of write. if return 0, means successful.
95      */
96     int WriteNdef(std::shared_ptr<NdefMessage> msg);
97     /**
98      * @Description check ndef tag can be set read-only
99      * @param canSetReadOnly the output for ndef tag can be set read-only or not.
100      * @return the error code of calling function.
101      */
102     int IsEnableReadOnly(bool &canSetReadOnly);
103     /**
104      * @Description set ndef tag read-only
105      * @param void
106      * @return Errorcode of write. if return 0, means successful.
107      */
108     int EnableReadOnly();
109     /**
110      * @Description convert the Nfc forum type into byte array defined in Nfc forum.
111      * @param emNfcForumType Nfc forum type of ndef tag
112      * @return Nfc forum type byte array
113      */
114     std::string GetNdefTagTypeString(EmNfcForumType emNfcForumType);
115 
116 private:
117     EmNfcForumType nfcForumType_ {};
118     EmNdefTagMode ndefTagMode_ {};
119     std::string ndefMsg_ {};
120     uint32_t maxTagSize_ {};
121 };
122 }  // namespace KITS
123 }  // namespace NFC
124 }  // namespace OHOS
125 #endif  // NDEF_TAG_H
126