• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 - 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 ROUTING_MANAGER_H
16 #define ROUTING_MANAGER_H
17 #include <memory>
18 #include <string>
19 #include "ndef_utils.h"
20 #include "nfa_api.h"
21 #include "nfa_ce_api.h"
22 #include "nfa_ee_api.h"
23 #include "nfa_hci_api.h"
24 #include "nfa_rw_api.h"
25 #include "nfc_hal_api.h"
26 #include "synchronize_event.h"
27 #include "nfcc_nci_adapter.h"
28 
29 namespace OHOS {
30 namespace NFC {
31 namespace NCI {
32 class RoutingManager final {
33 public:
34     static RoutingManager& GetInstance();
35     bool Initialize();
36     void Deinitialize();
37     bool CommitRouting();
38     bool ComputeRoutingParams(int defaultPaymentType);
39     bool AddAidRouting(const std::string &aidStr, int route, int aidInfo, int power);
40     bool ClearAidTable();
41 
42 private:
43     RoutingManager();
44     ~RoutingManager();
45     uint32_t GetDefaultProtoRouteAndPower(int defaultPaymentType);
46 
47     // update route settings
48     tNFA_TECHNOLOGY_MASK UpdateEeTechRouteSetting();
49     void UpdateDefaultRoute();
50     void UpdateDefaultProtoRoute();
51     void SetOffHostNfceeTechMask();
52 
53     // routing entries
54     bool ClearRoutingEntry(uint32_t type);
55     bool SetRoutingEntry(uint32_t type, uint32_t value, uint32_t route, uint32_t power);
56     void SetDefaultAidRoute(int defaultPaymentType);
57     void RegisterProtoRoutingEntry(tNFA_HANDLE eeHandle, tNFA_PROTOCOL_MASK protoSwitchOn,
58                                    tNFA_PROTOCOL_MASK protoSwitchOff, tNFA_PROTOCOL_MASK protoBatteryOn,
59                                    tNFA_PROTOCOL_MASK protoScreenLock, tNFA_PROTOCOL_MASK protoScreenOff,
60                                    tNFA_PROTOCOL_MASK protoSwitchOffLock);
61     void RegisterTechRoutingEntry(tNFA_HANDLE eeHandle,
62         tNFA_PROTOCOL_MASK protoSwitchOn, tNFA_PROTOCOL_MASK protoSwitchOff,
63         tNFA_PROTOCOL_MASK protoBatteryOn, tNFA_PROTOCOL_MASK protoScreenLock,
64         tNFA_PROTOCOL_MASK protoScreenOff, tNFA_PROTOCOL_MASK protoSwitchOffLock);
65     bool IsTypeABSupportedInEe(tNFA_HANDLE eeHandle);
66     uint8_t GetProtoMaskFromTechMask(uint32_t& value);
67     tNFA_HANDLE GetEeHandle(uint32_t route);
68 
69     void DoNfaEeRegisterEvent();
70     void DoNfaEeModeSetEvent(tNFA_EE_CBACK_DATA* eventData);
71     void DoNfaEeDeregisterEvent(tNFA_EE_CBACK_DATA* eventData);
72     void NotifyRoutingEvent();
73     void DoNfaEeDiscoverReqEvent(tNFA_EE_CBACK_DATA* eventData);
74     void DoNfaEeAddOrRemoveAidEvent(tNFA_EE_CBACK_DATA* eventData);
75     void DoNfaEeUpdateEvent();
76     void ClearAllEvents();
77     void OnNfcDeinit();
78     void DoNfaEeRegisterEvt(); // NFA_EE_REGISTER_EVT
79 
80     // static callback functions regiter to nci stack.
81     static void NfaEeCallback(tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData);
82     static void NfaCeStackCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData);
83 
84     void DoNfaCeDataEvt(const tNFA_CE_DATA& ce_data);
85 
86 private:
87     // default routes
88     uint32_t defaultOffHostRoute_ = 0;
89     uint32_t defaultFelicaRoute_ = 0;
90     uint32_t defaultIsoDepRoute_ = 0;
91     int defaultEe_ = 0;
92 
93     // system code params
94     int defaultSysCode_ = 0;
95     tNFA_EE_PWR_STATE defaultSysCodePowerstate_;
96     tNFA_HANDLE defaultSysCodeRoute_;
97 
98     std::vector<uint8_t> offHostRouteUicc_ {};
99     std::vector<uint8_t> offHostRouteEse_ {};
100     std::vector<uint8_t> mRxDataBuffer;
101 
102     tNFA_TECHNOLOGY_MASK seTechMask_;
103     tNFA_EE_DISCOVER_REQ eeInfo_;
104 
105     SynchronizeEvent eeUpdateEvent_;
106     SynchronizeEvent eeRegisterEvent_;
107     SynchronizeEvent eeInfoEvent_;
108     SynchronizeEvent routingEvent_;
109     SynchronizeEvent eeSetModeEvent_;
110 
111     bool isEeInfoChanged_ = false;
112     bool isEeInfoReceived_ = false;
113     bool isSecureNfcEnabled_ = false;
114     bool isDeinitializing_ = false;
115     bool isAidRoutingConfigured_ = false;
116     uint8_t hostListenTechMask_ = 0;
117     uint32_t offHostAidRoutingPowerState_ = 0;
118 };
119 }
120 }
121 }
122 #endif  // NCI_MANAGER_H