• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     ~NfccNciAdapter();
31 
32     static int GetIsoDepMaxTransceiveLength();
33     static void ClearT3tIdentifiersCache();
34     static int GetLfT3tMax();
35     static int GetLastError();
36     static void Abort();
37     static bool IsNfcActive();
38     bool Initialize();
39     bool Deinitialize();
40     void EnableDiscovery(uint16_t techMask, bool enableReaderMode, bool enableHostRouting, bool restart);
41     void DisableDiscovery();
42     bool SendRawFrame(std::string& rawData);
43     void SetScreenStatus(unsigned char screenStateMask) const;
44     int GetNciVersion() const;
45     bool RegisterT3tIdentifier(const std::string& t3tIdentifier) const;
46     void DeregisterT3tIdentifier(int handle) const;
47     bool CheckFirmware();
48     void Dump(int fd) const;
49     void FactoryReset() const;
50     void Shutdown() const;
51     bool IsTagActive() const;
52     void SetNciAdaptation(std::shared_ptr<INfcNci> nciAdaptation);
53     void StartRfDiscovery(bool isStart) const;
54     bool IsRfEbabled();
55     bool CommitRouting();
56     bool ComputeRoutingParams();
57 
58 private:
59     static const tNFA_TECHNOLOGY_MASK DEFAULT_TECH_MASK =
60         (NFA_TECHNOLOGY_MASK_A | NFA_TECHNOLOGY_MASK_B | NFA_TECHNOLOGY_MASK_F |
61          NFA_TECHNOLOGY_MASK_V);
62     static const int DEFAULT_DISCOVERY_DURATION = 500;
63     static const int DISCOVERY_DURATION = 200;
64     static const int NFA_SCREEN_POLLING_TAG_MASK = 0x10;
65     NfccNciAdapter();
66 
67     tNFA_STATUS StartPolling(tNFA_TECHNOLOGY_MASK techMask) const;
68     tNFA_STATUS StopPolling() const;
69     static void DoNfaPollEnabledDisabledEvt();
70     static void DoNfaActivatedEvt(tNFA_CONN_EVT_DATA* eventData);
71     static void DoNfaDeactivatedEvt(tNFA_CONN_EVT_DATA* eventData);
72     static void DoNfaDiscResultEvt(tNFA_CONN_EVT_DATA* eventData);
73     static void DoNfaPresenceEvt(tNFA_CONN_EVT_DATA* eventData);
74     static void NfcConnectionCallback(uint8_t connEvent, tNFA_CONN_EVT_DATA* eventData);
75     static void DoNfaDmEnableEvt(tNFA_DM_CBACK_DATA* eventData);
76     static void DoNfaDmDisableEvt(tNFA_DM_CBACK_DATA* eventData);
77     static void DoNfaDmRfFieldEvt(tNFA_DM_CBACK_DATA* eventData);
78     static void DoNfaDmNfccTimeoutEvt(tNFA_DM_CBACK_DATA* eventData);
79     static void NfcDeviceManagementCallback(uint8_t dmEvent, tNFA_DM_CBACK_DATA* eventData);
80     static uint8_t GetDiscovryParam(unsigned char screenState, unsigned char screenStateMask);
81 
82     static OHOS::NFC::SynchronizeEvent nfcEnableEvent_;
83     static OHOS::NFC::SynchronizeEvent nfcDisableEvent_;
84     static OHOS::NFC::SynchronizeEvent nfcStartStopPollingEvent_;
85     static bool isNfcEnabled_;
86     static bool isRoutingInited_;
87     static bool rfEnabled_;
88     static bool discoveryEnabled_;  // is polling or listening
89     static bool pollingEnabled_;    // is polling for tag
90     static bool isDisabling_;
91     static bool readerModeEnabled_;
92     static unsigned long discoveryDuration_;
93     static bool isTagActive_;
94     static unsigned char curScreenState_;
95     static std::shared_ptr<INfcNci> nciAdaptation_;
96 };
97 }  // namespace NCI
98 }  // namespace NFC
99 }  // namespace OHOS
100 #endif  // NCI_MANAGER_H
101