1 /* 2 * Copyright (c) 2021 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 16 #ifndef LNN_NET_BUILDER_H 17 #define LNN_NET_BUILDER_H 18 19 #include "auth_interface.h" 20 #include "lnn_connId_callback_manager.h" 21 #include "lnn_event.h" 22 #include "lnn_sync_info_manager.h" 23 #include "softbus_bus_center.h" 24 #include "message_handler.h" 25 #include "lnn_net_builder_struct.h" 26 27 #define SPARK_GROUP_DELAY_TIME_MS 10000 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 int32_t LnnInitNetBuilder(void); 34 int32_t LnnInitNetBuilderDelay(void); 35 void LnnDeinitNetBuilder(void); 36 37 int32_t LnnSetReSyncDeviceName(void); 38 int32_t LnnNotifyDiscoveryDevice( 39 const ConnectionAddr *addr, const LnnDfxDeviceInfoReport *infoReport, bool isNeedConnect); 40 void LnnSyncOfflineComplete(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t len); 41 int32_t LnnRequestLeaveByAddrType(const bool *type, uint32_t typeLen); 42 int32_t LnnRequestLeaveSpecific(const char *networkId, ConnectionAddrType addrType); 43 void LnnRequestLeaveAllOnlineNodes(void); 44 int32_t LnnRequestLeaveInvalidConn(const char *oldNetworkId, ConnectionAddrType addrType, const char *newNetworkId); 45 int32_t LnnRequestCleanConnFsm(uint16_t connFsmId); 46 int32_t LnnNotifyNodeStateChanged(const ConnectionAddr *addr); 47 int32_t LnnNotifyMasterElect(const char *networkId, const char *masterUdid, int32_t masterWeight); 48 int32_t LnnNotifyAuthHandleLeaveLNN(AuthHandle authHandle); 49 int32_t LnnNotifyEmptySessionKey(int64_t authId); 50 int32_t LnnNotifyLeaveLnnByAuthHandle(AuthHandle *authHandle); 51 int32_t LnnUpdateNodeAddr(const char *addr); 52 NodeInfo *FindNodeInfoByRquestId(uint32_t requestId); 53 AuthVerifyCallback *LnnGetVerifyCallback(void); 54 AuthVerifyCallback *LnnGetReAuthVerifyCallback(void); 55 void SetWatchdogFlag(bool flag); 56 bool GetWatchdogFlag(void); 57 NetBuilder* LnnGetNetBuilder(void); 58 void AddNodeToLnnBleReportExtraMap(const char *udidHash, const LnnBleReportExtra *bleExtra); 59 int32_t GetNodeFromLnnBleReportExtraMap(const char *udidHash, LnnBleReportExtra *bleExtra); 60 bool IsExistLnnDfxNodeByUdidHash(const char *udidHash, LnnBleReportExtra *bleExtra); 61 void DeleteNodeFromLnnBleReportExtraMap(const char *udidHash); 62 void ClearLnnBleReportExtraMap(void); 63 void DfxRecordLnnServerjoinStart(const ConnectionAddr *addr, const char *packageName, bool needReportFailure); 64 bool TryPendingJoinRequest(const JoinLnnMsgPara *para, bool needReportFailure); 65 bool IsNeedWifiReauth(const char *networkId, const char *newAccountHash, int32_t len); 66 void DfxRecordLnnAuthStart(const AuthConnInfo *connInfo, const JoinLnnMsgPara *para, uint32_t requestId); 67 void TryRemovePendingJoinRequest(void); 68 void UpdateLocalMasterNode(bool isCurrentNode, const char *masterUdid, int32_t weight); 69 void SendElectMessageToAll(const char *skipNetworkId); 70 bool IsNodeOnline(const char *networkId); 71 void RemovePendingRequestByAddrType(const bool *addrType, uint32_t typeLen); 72 void UpdateLocalNetCapability(void); 73 void OnReceiveMasterElectMsg(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t len); 74 void OnReceiveNodeAddrChangedMsg(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t size); 75 int32_t ConfigLocalLedger(void); 76 int32_t SyncElectMessage(const char *networkId); 77 ConnectionAddrType GetCurrentConnectType(AuthLinkType linkType); 78 NodeInfo *DupNodeInfo(const NodeInfo *nodeInfo); 79 bool NeedPendingJoinRequest(void); 80 void PostVerifyResult(uint32_t requestId, int32_t retCode, AuthHandle authHandle, const NodeInfo *info); 81 int32_t TrySendJoinLNNRequest(const JoinLnnMsgPara *para, bool needReportFailure, bool isShort); 82 int32_t PostBuildMessageToHandler(int32_t msgType, void *para); 83 bool DeletePcNodeInfo(const char *peerUdid); 84 const char *SelectUseUdid(const char *peerUdid, const char *lowerUdid); 85 void LnnDeleteLinkFinderInfo(const char *peerUdid); 86 void LnnProcessCompleteNotTrustedMsg(LnnSyncInfoType syncType, const char *networkId, 87 const uint8_t *msg, uint32_t len); 88 void OnLnnProcessNotTrustedMsgDelay(void *para); 89 void LnnBlePcRestrictMapInit(void); 90 void AddNodeToPcRestrictMap(const char *udidHash); 91 void ClearPcRestrictMap(void); 92 void DeleteNodeFromPcRestrictMap(const char *udidHash); 93 int32_t GetNodeFromPcRestrictMap(const char *udidHash, uint32_t *count); 94 int32_t UpdateNodeFromPcRestrictMap(const char *udidHash); 95 int32_t JoinLnnWithNodeInfo(ConnectionAddr *addr, NodeInfo *info, bool isSession); 96 int32_t LnnServerJoinExt(ConnectionAddr *addr, LnnServerJoinExtCallBack *callback); 97 int32_t AuthFailNotifyProofInfo(int32_t errCode, const char *errorReturn, uint32_t errorReturnLen); 98 void NotifyForegroundUseridChange(char *networkId, uint32_t discoveryType, bool isChange); 99 int32_t LnnUpdateLocalUuidAndIrk(void); 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif