• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 typedef enum {
31     NODE_TYPE_C,
32     NODE_TYPE_L
33 } NodeType;
34 
35 #define JSON_KEY_NODE_CODE "NODE_CODE"
36 #define JSON_KEY_NODE_ADDR "NODE_ADDR"
37 #define JSON_KEY_NODE_PROXY_PORT "PROXY_PORT"
38 #define JSON_KEY_NODE_SESSION_PORT "SESSION_PORT"
39 
40 typedef enum {
41     MSG_TYPE_JOIN_LNN = 0,
42     MSG_TYPE_DISCOVERY_DEVICE,
43     MSG_TYPE_CLEAN_CONN_FSM,
44     MSG_TYPE_VERIFY_RESULT,
45     MSG_TYPE_DEVICE_VERIFY_PASS,
46     MSG_TYPE_DEVICE_DISCONNECT = 5,
47     MSG_TYPE_DEVICE_NOT_TRUSTED,
48     MSG_TYPE_LEAVE_LNN,
49     MSG_TYPE_SYNC_OFFLINE_FINISH,
50     MSG_TYPE_NODE_STATE_CHANGED,
51     MSG_TYPE_MASTER_ELECT = 10,
52     MSG_TYPE_LEAVE_INVALID_CONN,
53     MSG_TYPE_LEAVE_BY_ADDR_TYPE,
54     MSG_TYPE_LEAVE_SPECIFIC,
55     MSG_TYPE_LEAVE_BY_AUTH_ID,
56     MSG_TYPE_RE_SYNC_DEVICE_NAME = 15,
57     MSG_TYPE_BUILD_MAX,
58 } NetBuilderMessageType;
59 
60 typedef struct {
61     char nodeAddr[SHORT_ADDRESS_MAX_LEN];
62     int32_t code;
63     int32_t proxyPort;
64     int32_t sessionPort;
65     int32_t authPort;
66 } LnnNodeAddr;
67 
68 typedef struct {
69     char networkId[NETWORK_ID_BUF_LEN];
70     char pkgName[PKG_NAME_SIZE_MAX];
71     bool needReportFailure;
72     int32_t callingPid;
73     uint32_t requestId;
74     uint32_t flag;
75     ConnectionAddr addr;
76     int64_t authId;
77     ListNode node;
78 } MetaJoinRequestNode;
79 
80 typedef struct {
81     ListNode node;
82     ConnectionAddr addr;
83     bool needReportFailure;
84 } PendingJoinRequestNode;
85 
86 typedef struct {
87     NodeType nodeType;
88 
89     /* connection fsm list */
90     ListNode fsmList;
91     ListNode pendingList;
92     /* connection count */
93     int32_t connCount;
94 
95     SoftBusLooper *looper;
96     SoftBusHandler handler;
97 
98     int32_t maxConnCount;
99     int32_t maxConcurrentCount;
100     bool isInit;
101 } NetBuilder;
102 
103 typedef struct {
104     uint32_t requestId;
105     int32_t retCode;
106     NodeInfo *nodeInfo;
107     AuthHandle authHandle;
108 } VerifyResultMsgPara;
109 
110 typedef struct {
111     NodeInfo *nodeInfo;
112     AuthHandle authHandle;
113     ConnectionAddr addr;
114 } DeviceVerifyPassMsgPara;
115 
116 typedef struct {
117     char networkId[NETWORK_ID_BUF_LEN];
118     char masterUdid[UDID_BUF_LEN];
119     int32_t masterWeight;
120 } ElectMsgPara;
121 
122 typedef struct {
123     char oldNetworkId[NETWORK_ID_BUF_LEN];
124     char newNetworkId[NETWORK_ID_BUF_LEN];
125     ConnectionAddrType addrType;
126 } LeaveInvalidConnMsgPara;
127 
128 typedef struct {
129     char networkId[NETWORK_ID_BUF_LEN];
130     ConnectionAddrType addrType;
131 } SpecificLeaveMsgPara;
132 
133 typedef struct {
134     char pkgName[PKG_NAME_SIZE_MAX];
135     bool isNeedConnect;
136     bool isSession;
137     bool isForceJoin;
138     ConnectionAddr addr;
139     NodeInfo *dupInfo;
140     LnnDfxDeviceInfoReport infoReport;
141 } JoinLnnMsgPara;
142 
143 typedef struct {
144     char pkgName[PKG_NAME_SIZE_MAX];
145     char networkId[NETWORK_ID_BUF_LEN];
146 } LeaveLnnMsgPara;
147 
148 int32_t LnnInitNetBuilder(void);
149 int32_t LnnInitNetBuilderDelay(void);
150 void LnnDeinitNetBuilder(void);
151 
152 int32_t LnnSetReSyncDeviceName(void);
153 int32_t LnnNotifyDiscoveryDevice(
154     const ConnectionAddr *addr, const LnnDfxDeviceInfoReport *infoReport, bool isNeedConnect);
155 void LnnSyncOfflineComplete(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t len);
156 int32_t LnnRequestLeaveByAddrType(const bool *type, uint32_t typeLen);
157 int32_t LnnRequestLeaveSpecific(const char *networkId, ConnectionAddrType addrType);
158 void LnnRequestLeaveAllOnlineNodes(void);
159 int32_t LnnRequestLeaveInvalidConn(const char *oldNetworkId, ConnectionAddrType addrType, const char *newNetworkId);
160 int32_t LnnRequestCleanConnFsm(uint16_t connFsmId);
161 int32_t LnnNotifyNodeStateChanged(const ConnectionAddr *addr);
162 int32_t LnnNotifyMasterElect(const char *networkId, const char *masterUdid, int32_t masterWeight);
163 int32_t LnnNotifyAuthHandleLeaveLNN(AuthHandle authHandle);
164 int32_t LnnNotifyEmptySessionKey(int64_t authId);
165 int32_t LnnNotifyLeaveLnnByAuthHandle(AuthHandle *authHandle);
166 int32_t LnnUpdateNodeAddr(const char *addr);
167 NodeInfo *FindNodeInfoByRquestId(uint32_t requestId);
168 AuthVerifyCallback *LnnGetVerifyCallback(void);
169 AuthVerifyCallback *LnnGetReAuthVerifyCallback(void);
170 void SetWatchdogFlag(bool flag);
171 bool GetWatchdogFlag(void);
172 NetBuilder* LnnGetNetBuilder(void);
173 void AddNodeToLnnBleReportExtraMap(const char *udidHash, const LnnBleReportExtra *bleExtra);
174 int32_t GetNodeFromLnnBleReportExtraMap(const char *udidHash, LnnBleReportExtra *bleExtra);
175 bool IsExistLnnDfxNodeByUdidHash(const char *udidHash, LnnBleReportExtra *bleExtra);
176 void DeleteNodeFromLnnBleReportExtraMap(const char *udidHash);
177 void ClearLnnBleReportExtraMap(void);
178 void DfxRecordLnnServerjoinStart(const ConnectionAddr *addr, const char *packageName, bool needReportFailure);
179 bool TryPendingJoinRequest(const JoinLnnMsgPara *para, bool needReportFailure);
180 bool IsNeedWifiReauth(const char *networkId, const char *newAccountHash, int32_t len);
181 void DfxRecordLnnAuthStart(const AuthConnInfo *connInfo, const JoinLnnMsgPara *para, uint32_t requestId);
182 void TryRemovePendingJoinRequest(void);
183 void UpdateLocalMasterNode(bool isCurrentNode, const char *masterUdid, int32_t weight);
184 void SendElectMessageToAll(const char *skipNetworkId);
185 bool IsNodeOnline(const char *networkId);
186 void RemovePendingRequestByAddrType(const bool *addrType, uint32_t typeLen);
187 void UpdateLocalNetCapability(void);
188 void OnReceiveMasterElectMsg(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t len);
189 void OnReceiveNodeAddrChangedMsg(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t size);
190 int32_t ConfigLocalLedger(void);
191 int32_t SyncElectMessage(const char *networkId);
192 ConnectionAddrType GetCurrentConnectType(void);
193 NodeInfo *DupNodeInfo(const NodeInfo *nodeInfo);
194 bool NeedPendingJoinRequest(void);
195 void PostVerifyResult(uint32_t requestId, int32_t retCode, AuthHandle authHandle, const NodeInfo *info);
196 int32_t TrySendJoinLNNRequest(const JoinLnnMsgPara *para, bool needReportFailure, bool isShort);
197 int32_t PostBuildMessageToHandler(int32_t msgType, void *para);
198 bool DeletePcNodeInfo(const char *peerUdid);
199 const char *SelectUseUdid(const char *peerUdid, const char *lowerUdid);
200 void LnnDeleteLinkFinderInfo(const char *peerUdid);
201 void LnnProcessCompleteNotTrustedMsg(LnnSyncInfoType syncType, const char *networkId,
202     const uint8_t *msg, uint32_t len);
203 void OnLnnProcessNotTrustedMsgDelay(void *para);
204 void LnnBlePcRestrictMapInit(void);
205 void AddNodeToPcRestrictMap(const char *udidHash);
206 void ClearPcRestrictMap(void);
207 void DeleteNodeFromPcRestrictMap(const char *udidHash);
208 int32_t GetNodeFromPcRestrictMap(const char *udidHash, uint32_t *count);
209 int32_t UpdateNodeFromPcRestrictMap(const char *udidHash);
210 int32_t JoinLnnWithNodeInfo(ConnectionAddr *addr, NodeInfo *info, bool isSession);
211 int32_t LnnServerJoinExt(ConnectionAddr *addr, LnnServerJoinExtCallBack *callback);
212 int32_t AuthFailNotifyProofInfo(int32_t errCode, const char *errorReturn, uint32_t errorReturnLen);
213 void NotifyForegroundUseridChange(char *networkId, uint32_t discoveryType, bool isChange);
214 int32_t LnnUpdateLocalUuidAndIrk(void);
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif