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 NCI_MANAGER_H 16 #define NCI_MANAGER_H 17 18 #include <memory> 19 #include <mutex> 20 21 #include "infc_nci.h" 22 #include "synchronize_event.h" 23 24 namespace OHOS { 25 namespace NFC { 26 namespace NCI { 27 class NfccNciAdapter final { 28 public: 29 static NfccNciAdapter& GetInstance(); 30 static int GetIsoDepMaxTransceiveLength(); 31 static void ClearT3tIdentifiersCache(); 32 static int GetLfT3tMax(); 33 static int GetLastError(); 34 static void Abort(); 35 static bool IsNfcActive(); 36 bool Initialize(); 37 bool Deinitialize(); 38 void EnableDiscovery(uint16_t techMask, bool enableReaderMode, bool enableHostRouting, bool restart); 39 void DisableDiscovery(); 40 bool SendRawFrame(std::string& rawData); 41 void SetScreenStatus(unsigned char screenStateMask) const; 42 int GetNciVersion() const; 43 bool RegisterT3tIdentifier(const std::string& t3tIdentifier) const; 44 void DeregisterT3tIdentifier(int handle) const; 45 bool CheckFirmware(); 46 void Dump(int fd) const; 47 void FactoryReset() const; 48 void Shutdown() const; 49 bool IsTagActive() const; 50 void SetNciAdaptation(std::shared_ptr<INfcNci> nciAdaptation); 51 void StartRfDiscovery(bool isStart) const; 52 bool IsRfEbabled(); 53 54 private: 55 static const tNFA_TECHNOLOGY_MASK DEFAULT_TECH_MASK = 56 (NFA_TECHNOLOGY_MASK_A | NFA_TECHNOLOGY_MASK_B | NFA_TECHNOLOGY_MASK_F | 57 NFA_TECHNOLOGY_MASK_V | NFA_TECHNOLOGY_MASK_A_ACTIVE); 58 static const int DEFAULT_DISCOVERY_DURATION = 500; 59 static const int DISCOVERY_DURATION = 200; 60 static const int NFA_SCREEN_POLLING_TAG_MASK = 0x10; 61 NfccNciAdapter(); 62 ~NfccNciAdapter(); 63 tNFA_STATUS StartPolling(tNFA_TECHNOLOGY_MASK techMask) const; 64 tNFA_STATUS StopPolling() const; 65 static void DoNfaActivatedEvt(tNFA_CONN_EVT_DATA* eventData); 66 static void DoNfaDeactivatedEvt(tNFA_CONN_EVT_DATA* eventData); 67 static void DoNfaDiscResultEvt(tNFA_CONN_EVT_DATA* eventData); 68 static void DoNfaPresenceEvt(tNFA_CONN_EVT_DATA* eventData); 69 static void NfcConnectionCallback(uint8_t connEvent, tNFA_CONN_EVT_DATA* eventData); 70 static void DoNfaDmEnableEvt(tNFA_DM_CBACK_DATA* eventData); 71 static void DoNfaDmDisableEvt(tNFA_DM_CBACK_DATA* eventData); 72 static void DoNfaDmRfFieldEvt(tNFA_DM_CBACK_DATA* eventData); 73 static void DoNfaDmNfccTimeoutEvt(tNFA_DM_CBACK_DATA* eventData); 74 static void NfcDeviceManagementCallback(uint8_t dmEvent, tNFA_DM_CBACK_DATA* eventData); 75 static uint8_t GetDiscovryParam(unsigned char screenState, unsigned char screenStateMask); 76 77 std::mutex mutex_ {}; 78 static OHOS::NFC::SynchronizeEvent nfcEnableEvent_; 79 static OHOS::NFC::SynchronizeEvent nfcDisableEvent_; 80 static bool isNfcEnabled_; 81 static bool rfEnabled_; 82 static bool discoveryEnabled_; // is polling or listening 83 static bool pollingEnabled_; // is polling for tag 84 static bool isDisabling_; 85 static bool readerModeEnabled_; 86 static unsigned long discoveryDuration_; 87 static bool isTagActive_; 88 static unsigned char curScreenState_; 89 static std::shared_ptr<INfcNci> nciAdaptation_; 90 }; 91 } // namespace NCI 92 } // namespace NFC 93 } // namespace OHOS 94 #endif // NCI_MANAGER_H 95