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