1bc2ed2b3Sopenharmony_ci/* 2bc2ed2b3Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 3bc2ed2b3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bc2ed2b3Sopenharmony_ci * you may not use this file except in compliance with the License. 5bc2ed2b3Sopenharmony_ci * You may obtain a copy of the License at 6bc2ed2b3Sopenharmony_ci * 7bc2ed2b3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc2ed2b3Sopenharmony_ci * 9bc2ed2b3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc2ed2b3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bc2ed2b3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc2ed2b3Sopenharmony_ci * See the License for the specific language governing permissions and 13bc2ed2b3Sopenharmony_ci * limitations under the License. 14bc2ed2b3Sopenharmony_ci */ 15bc2ed2b3Sopenharmony_ci#include "nci_nfcc_proxy.h" 16bc2ed2b3Sopenharmony_ci#include "nci_native_selector.h" 17bc2ed2b3Sopenharmony_ci 18bc2ed2b3Sopenharmony_cinamespace OHOS { 19bc2ed2b3Sopenharmony_cinamespace NFC { 20bc2ed2b3Sopenharmony_cinamespace NCI { 21bc2ed2b3Sopenharmony_ciNciNfccProxy::NciNfccProxy() 22bc2ed2b3Sopenharmony_ci{ 23bc2ed2b3Sopenharmony_ci nfccInterface_ = NciNativeSelector::GetInstance().GetNciNfccInterface(); 24bc2ed2b3Sopenharmony_ci} 25bc2ed2b3Sopenharmony_ci 26bc2ed2b3Sopenharmony_ci/** 27bc2ed2b3Sopenharmony_ci * @brief Initialize when turn on NFC 28bc2ed2b3Sopenharmony_ci * @return True if success, otherwise false. 29bc2ed2b3Sopenharmony_ci */ 30bc2ed2b3Sopenharmony_cibool NciNfccProxy::Initialize() 31bc2ed2b3Sopenharmony_ci{ 32bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 33bc2ed2b3Sopenharmony_ci return nfccInterface_->Initialize(); 34bc2ed2b3Sopenharmony_ci } 35bc2ed2b3Sopenharmony_ci return true; 36bc2ed2b3Sopenharmony_ci} 37bc2ed2b3Sopenharmony_ci 38bc2ed2b3Sopenharmony_ci/** 39bc2ed2b3Sopenharmony_ci * @brief Deinitialize when turn off NFC 40bc2ed2b3Sopenharmony_ci * @return True if success, otherwise false. 41bc2ed2b3Sopenharmony_ci */ 42bc2ed2b3Sopenharmony_cibool NciNfccProxy::Deinitialize() 43bc2ed2b3Sopenharmony_ci{ 44bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 45bc2ed2b3Sopenharmony_ci return nfccInterface_->Deinitialize(); 46bc2ed2b3Sopenharmony_ci } 47bc2ed2b3Sopenharmony_ci return true; 48bc2ed2b3Sopenharmony_ci} 49bc2ed2b3Sopenharmony_ci 50bc2ed2b3Sopenharmony_ci/** 51bc2ed2b3Sopenharmony_ci * @brief Start polling and listening 52bc2ed2b3Sopenharmony_ci * @param techMask bitmask of the technologies 53bc2ed2b3Sopenharmony_ci * @param enableReaderMode if enable tag polling 54bc2ed2b3Sopenharmony_ci * @param enableHostRouting if enable host routing 55bc2ed2b3Sopenharmony_ci * @param restart true if need restart, otherwise false. 56bc2ed2b3Sopenharmony_ci */ 57bc2ed2b3Sopenharmony_civoid NciNfccProxy::EnableDiscovery(uint16_t techMask, bool enableReaderMode, bool enableHostRouting, bool restart) 58bc2ed2b3Sopenharmony_ci{ 59bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 60bc2ed2b3Sopenharmony_ci return nfccInterface_->EnableDiscovery(techMask, enableReaderMode, enableHostRouting, restart); 61bc2ed2b3Sopenharmony_ci } 62bc2ed2b3Sopenharmony_ci} 63bc2ed2b3Sopenharmony_ci 64bc2ed2b3Sopenharmony_ci/** 65bc2ed2b3Sopenharmony_ci * @brief Stop polling and listening 66bc2ed2b3Sopenharmony_ci */ 67bc2ed2b3Sopenharmony_civoid NciNfccProxy::DisableDiscovery() 68bc2ed2b3Sopenharmony_ci{ 69bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 70bc2ed2b3Sopenharmony_ci return nfccInterface_->DisableDiscovery(); 71bc2ed2b3Sopenharmony_ci } 72bc2ed2b3Sopenharmony_ci} 73bc2ed2b3Sopenharmony_ci 74bc2ed2b3Sopenharmony_ci/** 75bc2ed2b3Sopenharmony_ci * @brief Set the screen statue to nfc controller. 76bc2ed2b3Sopenharmony_ci * @param screenStateMask the bitmask of the screen state 77bc2ed2b3Sopenharmony_ci * @return True if success, otherwise false. 78bc2ed2b3Sopenharmony_ci */ 79bc2ed2b3Sopenharmony_cibool NciNfccProxy::SetScreenStatus(uint8_t screenStateMask) 80bc2ed2b3Sopenharmony_ci{ 81bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 82bc2ed2b3Sopenharmony_ci return nfccInterface_->SetScreenStatus(screenStateMask); 83bc2ed2b3Sopenharmony_ci } 84bc2ed2b3Sopenharmony_ci return true; 85bc2ed2b3Sopenharmony_ci} 86bc2ed2b3Sopenharmony_ci 87bc2ed2b3Sopenharmony_ci/** 88bc2ed2b3Sopenharmony_ci * @brief Get Nci version supprted by nfc controller. 89bc2ed2b3Sopenharmony_ci * @return 0x20 if it's NCI2.0, otherwise 0x10 if it's NCI1.0. 90bc2ed2b3Sopenharmony_ci */ 91bc2ed2b3Sopenharmony_ciint NciNfccProxy::GetNciVersion() 92bc2ed2b3Sopenharmony_ci{ 93bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 94bc2ed2b3Sopenharmony_ci return nfccInterface_->GetNciVersion(); 95bc2ed2b3Sopenharmony_ci } 96bc2ed2b3Sopenharmony_ci return 0x10; 97bc2ed2b3Sopenharmony_ci} 98bc2ed2b3Sopenharmony_ci 99bc2ed2b3Sopenharmony_ci/** 100bc2ed2b3Sopenharmony_ci * @brief Abort the nfc controller if NCI timeout. 101bc2ed2b3Sopenharmony_ci */ 102bc2ed2b3Sopenharmony_civoid NciNfccProxy::Abort() 103bc2ed2b3Sopenharmony_ci{ 104bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 105bc2ed2b3Sopenharmony_ci return nfccInterface_->Abort(); 106bc2ed2b3Sopenharmony_ci } 107bc2ed2b3Sopenharmony_ci} 108bc2ed2b3Sopenharmony_ci 109bc2ed2b3Sopenharmony_ci/** 110bc2ed2b3Sopenharmony_ci * @brief Do factory reset for nfc controller. 111bc2ed2b3Sopenharmony_ci */ 112bc2ed2b3Sopenharmony_civoid NciNfccProxy::FactoryReset() 113bc2ed2b3Sopenharmony_ci{ 114bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 115bc2ed2b3Sopenharmony_ci return nfccInterface_->FactoryReset(); 116bc2ed2b3Sopenharmony_ci } 117bc2ed2b3Sopenharmony_ci} 118bc2ed2b3Sopenharmony_ci 119bc2ed2b3Sopenharmony_ci/** 120bc2ed2b3Sopenharmony_ci * @brief Shutdown the device. Enable the nfc functionality if support power off case. 121bc2ed2b3Sopenharmony_ci */ 122bc2ed2b3Sopenharmony_civoid NciNfccProxy::Shutdown() 123bc2ed2b3Sopenharmony_ci{ 124bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 125bc2ed2b3Sopenharmony_ci return nfccInterface_->Shutdown(); 126bc2ed2b3Sopenharmony_ci } 127bc2ed2b3Sopenharmony_ci} 128bc2ed2b3Sopenharmony_ci 129bc2ed2b3Sopenharmony_ci/** 130bc2ed2b3Sopenharmony_ci * @brief Send a custom message to vendor 131bc2ed2b3Sopenharmony_ci*/ 132bc2ed2b3Sopenharmony_civoid NciNfccProxy::NotifyMessageToVendor(const std::string& key, const std::string& value) 133bc2ed2b3Sopenharmony_ci{ 134bc2ed2b3Sopenharmony_ci if (nfccInterface_) { 135bc2ed2b3Sopenharmony_ci return nfccInterface_->NotifyMessageToVendor(key, value); 136bc2ed2b3Sopenharmony_ci } 137bc2ed2b3Sopenharmony_ci} 138bc2ed2b3Sopenharmony_ci} // namespace NCI 139bc2ed2b3Sopenharmony_ci} // namespace NFC 140bc2ed2b3Sopenharmony_ci} // namespace OHOS