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 MIFARE_ULTRALIGHT_TAG_H
16 #define MIFARE_ULTRALIGHT_TAG_H
17 
18 #include "basic_tag_session.h"
19 
20 namespace OHOS {
21 namespace NFC {
22 namespace KITS {
23 class MifareUltralightTag final : public BasicTagSession {
24 public:
25     static const int NXP_MANUFACTURER_ID = 0x04;
26     static const int MU_MAX_PAGE_COUNT = 256;
27     static const int MU_PAGE_SIZE = 4;
28 
29     static const char MIFARE_ULTRALIGHT_READ = 0x30;
30     static const char MIFARE_ULTRALIGHT_WRITE = 0xA2;
31 
32     enum EmType { TYPE_UNKNOWN = 0, TYPE_ULTRALIGHT = 1, TYPE_ULTRALIGHT_C = 2 };
33 
34 public:
35     explicit MifareUltralightTag(std::weak_ptr<TagInfo> tag);
36     ~MifareUltralightTag() override;
37 
38     /**
39      * @Description Get an object of MifareUltralightTag for the given tag.
40      * @param tag compatible with all types of tag
41      * @return std::shared_ptr<MifareUltralightTag>
42      */
43     static std::shared_ptr<MifareUltralightTag> GetTag(std::weak_ptr<TagInfo> tag);
44     /**
45      * @Description Read 4 pages(16 bytes).
46      * @param pageIndex index of page to read
47      * @param hexRespData the hex response data for reading.
48      * @return the error code of calling function.
49      */
50     int ReadMultiplePages(uint32_t pageIndex, std::string &hexRespData);
51     /**
52      * @Description Write a page
53      * @param pageIndex index of page to write
54      * @param data page data to write
55      * @return Errorcode of write. if return 0, means successful.
56      */
57     int WriteSinglePage(uint32_t pageIndex, const std::string& data);
58     /**
59      * @Description Get the type of the MifareUltralight tag in bytes.
60      * @param void
61      * @return type of MifareUltralight tag.
62      */
63     EmType GetType() const;
64 
65 private:
66     EmType type_ {EmType::TYPE_UNKNOWN};
67 };
68 }  // namespace KITS
69 }  // namespace NFC
70 }  // namespace OHOS
71 #endif  // MIFARE_ULTRALIGHT_TAG_H
72