1 /* 2 * Copyright (C) 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 TAG_NATIVE_IMPL_H 16 #define TAG_NATIVE_IMPL_H 17 #include "tag_host.h" 18 #include "inci_tag_interface.h" 19 20 namespace OHOS { 21 namespace NFC { 22 namespace NCI { 23 class TagNativeImpl final { 24 public: 25 static TagNativeImpl& GetInstance(); 26 27 /** 28 * @brief Set tag listener to receive tag status. 29 * @param listener The listener to receive tag status. 30 */ 31 void SetTagListener(std::weak_ptr<INciTagInterface::ITagListener> listener); 32 33 /** 34 * @brief Tag discovered, need to callback to nfc service. 35 * @param tagDiscId The tag discovered id given from nci stack. 36 * @param tagHost The TagHost instance created in TagNciAdapter when tag discorvered. 37 */ 38 void OnTagDiscovered(uint32_t tagDiscId, std::shared_ptr<TagHost> tagHost); 39 40 /** 41 * @brief Tag lost, need to callback to nfc service. 42 * @param tagDiscId The tag discovered id given from nci stack. 43 */ 44 void OnTagLost(uint32_t tagDiscId); 45 46 /** 47 * @brief Get the TagHost instance by the tag discovered id. 48 * @param tagDiscId The tag discovered id given from nci stack. 49 */ 50 std::weak_ptr<TagHost> GetTag(uint32_t tagDiscId); 51 52 /** 53 * @brief Check can make the ndef to be read only. 54 * @param ndefType The ndef type to check. 55 * @return True if can make read only, otherwise false. 56 */ 57 bool CanMakeReadOnly(uint32_t ndefType); 58 59 /** 60 * @brief Build the tech mask by all given technologies. 61 * @param discTech The given technology list. 62 * @return The technology mask. 63 */ 64 uint16_t GetTechMaskFromTechList(const std::vector<uint32_t> &discTech); 65 66 /** 67 * @brief Get the max transceive length of ISO-DEP technology. 68 * @return The max transceive length of ISO-DEP technology. 69 */ 70 uint32_t GetIsoDepMaxTransceiveLength(); 71 72 /** 73 * @brief Check if the nfc controller support extended APDU or not. 74 * @param length The max isodep length to check. 75 * @return True if the nfc controller support extended APDU, otherwise false. 76 */ 77 bool IsExtendedLengthApduSupported(uint32_t length); 78 private: 79 std::weak_ptr<INciTagInterface::ITagListener> tagListener_ {}; 80 std::map<uint32_t, std::shared_ptr<TagHost>> tagHostMap_ {}; 81 }; 82 } // namespace NCI 83 } // namespace NFC 84 } // namespace OHOS 85 #endif // TAG_NATIVE_IMPL_H 86