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 18 #include <memory> 19 #include <string> 20 21 #include "nfa_api.h" 22 #include "infc_nci.h" 23 #include "infcc_host.h" 24 #include "synchronize_event.h" 25 26 namespace OHOS { 27 namespace NFC { 28 namespace NCI { 29 class RoutingManager final { 30 public: 31 static RoutingManager& GetInstance(); 32 bool Initialize(); 33 void Deinitialize(); 34 bool CommitRouting(); 35 bool ComputeRoutingParams(); 36 37 private: 38 RoutingManager(); 39 ~RoutingManager(); 40 41 // update route settings 42 tNFA_TECHNOLOGY_MASK UpdateEeTechRouteSetting(); 43 void UpdateDefaultRoute(); 44 void UpdateDefaultProtoRoute(); 45 void SetOffHostNfceeTechMask(); 46 47 // routing entries 48 bool ClearRoutingEntry(int type); 49 bool SetRoutingEntry(int type, int value, int route, int power); 50 void RegisterProtoRoutingEntry(tNFA_HANDLE eeHandle, 51 tNFA_PROTOCOL_MASK protoSwitchOn, tNFA_PROTOCOL_MASK protoSwitchOff, 52 tNFA_PROTOCOL_MASK protoBatteryOn, tNFA_PROTOCOL_MASK protoScreenLock, 53 tNFA_PROTOCOL_MASK protoScreenOff, tNFA_PROTOCOL_MASK protoSwitchOffLock); 54 void RegisterTechRoutingEntry(tNFA_HANDLE eeHandle, 55 tNFA_PROTOCOL_MASK protoSwitchOn, tNFA_PROTOCOL_MASK protoSwitchOff, 56 tNFA_PROTOCOL_MASK protoBatteryOn, tNFA_PROTOCOL_MASK protoScreenLock, 57 tNFA_PROTOCOL_MASK protoScreenOff, tNFA_PROTOCOL_MASK protoSwitchOffLock); 58 bool IsTypeABSupportedInEe(tNFA_HANDLE eeHandle); 59 uint8_t GetProtoMaskFromTechMask(int& value); 60 61 // callbacks and event handlers 62 static void NfaCeStackCallback(uint8_t event, tNFA_CONN_EVT_DATA* eventData); 63 static void NfaEeCallback(tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData); 64 static void DoNfaEeRegisterEvent(); 65 static void DoNfaEeModeSetEvent(tNFA_EE_CBACK_DATA* eventData); 66 static void DoNfaEeDeregisterEvent(tNFA_EE_CBACK_DATA* eventData); 67 static void NotifyRoutingEvent(); 68 static void DoNfaEeDiscoverReqEvent(tNFA_EE_CBACK_DATA* eventData); 69 static void DoNfaEeAddOrRemoveAidEvent(tNFA_EE_CBACK_DATA* eventData); 70 static void DoNfaEeUpdateEvent(); 71 void ClearAllEvents(); 72 void OnNfcDeinit(); 73 74 private: 75 // default routes 76 int defaultOffHostRoute_; 77 int defaultFelicaRoute_; 78 int defaultIsoDepRoute_; 79 int defaultEe_; 80 81 // system code params 82 int defaultSysCode_; 83 tNFA_EE_PWR_STATE defaultSysCodePowerstate_; 84 tNFA_HANDLE defaultSysCodeRoute_; 85 86 std::vector<uint8_t> offHostRouteUicc_; 87 std::vector<uint8_t> offHostRouteEse_; 88 89 tNFA_TECHNOLOGY_MASK seTechMask_; 90 tNFA_EE_DISCOVER_REQ eeInfo_; 91 92 SynchronizeEvent eeUpdateEvent_; 93 SynchronizeEvent eeRegisterEvent_; 94 SynchronizeEvent eeInfoEvent_; 95 SynchronizeEvent routingEvent_; 96 SynchronizeEvent eeSetModeEvent_; 97 98 bool isEeInfoChanged_; 99 bool isEeInfoReceived_; 100 bool isSecureNfcEnabled_; 101 bool isDeinitializing_; 102 bool isAidRoutingConfigured_; 103 104 uint8_t hostListenTechMask_; 105 106 int offHostAidRoutingPowerState_; 107 }; 108 } 109 } 110 } 111 #endif // NCI_MANAGER_H