• 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 
17 #ifndef LNN_CONNECTION_FSM_H
18 #define LNN_CONNECTION_FSM_H
19 
20 #include <stdint.h>
21 
22 #include "auth_interface.h"
23 #include "common_list.h"
24 #include "lnn_node_info.h"
25 #include "lnn_state_machine.h"
26 #include "softbus_bus_center.h"
27 #include "softbus_hisysevt_bus_center.h"
28 #include "lnn_net_builder.h"
29 
30 #ifdef __cplusplus
31 #if __cplusplus
32 extern "C" {
33 #endif
34 #endif
35 
36 #define LNN_CONNECTION_FSM_NAME_LEN 32
37 
38 #define LNN_CONN_INFO_FLAG_JOIN_REQUEST 0x01
39 #define LNN_CONN_INFO_FLAG_JOIN_AUTO 0x02
40 #define LNN_CONN_INFO_FLAG_JOIN_PASSIVE 0x04
41 #define LNN_CONN_INFO_FLAG_LEAVE_REQUEST 0x08
42 #define LNN_CONN_INFO_FLAG_LEAVE_AUTO 0x10
43 #define LNN_CONN_INFO_FLAG_LEAVE_PASSIVE 0x20
44 #define LNN_CONN_INFO_FLAG_INITIATE_ONLINE 0x40
45 #define LNN_CONN_INFO_FLAG_ONLINE 0x80
46 
47 #define LNN_CONN_INFO_FLAG_JOIN_ACTIVE (LNN_CONN_INFO_FLAG_JOIN_REQUEST | LNN_CONN_INFO_FLAG_JOIN_AUTO)
48 #define LNN_CONN_INFO_FLAG_JOIN (LNN_CONN_INFO_FLAG_JOIN_ACTIVE | LNN_CONN_INFO_FLAG_JOIN_PASSIVE)
49 
50 #define LNN_CONN_INFO_FLAG_LEAVE_ACTIVE (LNN_CONN_INFO_FLAG_LEAVE_REQUEST | LNN_CONN_INFO_FLAG_LEAVE_AUTO)
51 #define LNN_CONN_INFO_FLAG_LEAVE (LNN_CONN_INFO_FLAG_LEAVE_ACTIVE | LNN_CONN_INFO_FLAG_LEAVE_PASSIVE)
52 
53 typedef struct {
54     /* clean invalid addr type */
55     ConnectionAddrType addrType;
56     /* record newer connection networkId */
57     char networkId[NETWORK_ID_BUF_LEN];
58 } LnnInvalidCleanInfo;
59 
60 typedef struct {
61     ConnectionAddr addr;
62     NodeInfo *nodeInfo;
63     char peerNetworkId[NETWORK_ID_BUF_LEN];
64     LnnInvalidCleanInfo *cleanInfo;
65     int64_t authId;
66     uint32_t requestId;
67     uint32_t flag;
68     SoftBusVersion version;
69 } LnnConntionInfo;
70 
71 struct tagLnnConnectionFsm;
72 
73 typedef void (*LnnConnectionFsmStopCallback)(struct tagLnnConnectionFsm *connFsm);
74 
75 typedef struct tagLnnConnectionFsm {
76     ListNode node;
77     uint16_t id;
78 
79     char fsmName[LNN_CONNECTION_FSM_NAME_LEN];
80     char pkgName[PKG_NAME_SIZE_MAX];
81     FsmStateMachine fsm;
82     LnnConntionInfo connInfo;
83     LnnConnectionFsmStopCallback stopCallback;
84     bool isDead;
85     bool isNeedConnect;
86     LnnStatisticData statisticData;
87 } LnnConnectionFsm;
88 
89 LnnConnectionFsm *LnnCreateConnectionFsm(const ConnectionAddr *target, const char *pkgName, bool isNeedConnect);
90 void LnnDestroyConnectionFsm(LnnConnectionFsm *connFsm);
91 
92 int32_t LnnStartConnectionFsm(LnnConnectionFsm *connFsm);
93 int32_t LnnStopConnectionFsm(LnnConnectionFsm *connFsm, LnnConnectionFsmStopCallback callback);
94 
95 int32_t LnnSendJoinRequestToConnFsm(LnnConnectionFsm *connFsm);
96 int32_t LnnSendAuthResultMsgToConnFsm(LnnConnectionFsm *connFsm, int32_t retCode);
97 int32_t LnnSendNotTrustedToConnFsm(LnnConnectionFsm *connFsm);
98 int32_t LnnSendDisconnectMsgToConnFsm(LnnConnectionFsm *connFsm);
99 int32_t LnnSendLeaveRequestToConnFsm(LnnConnectionFsm *connFsm);
100 int32_t LnnSendSyncOfflineFinishToConnFsm(LnnConnectionFsm *connFsm);
101 int32_t LnnSendNewNetworkOnlineToConnFsm(LnnConnectionFsm *connFsm);
102 int32_t OnJoinMetaNode(MetaJoinRequestNode *mateJoinNode, CustomData *customData);
103 
104 #ifdef __cplusplus
105 #if __cplusplus
106 }
107 #endif /* __cplusplus */
108 #endif /* __cplusplus */
109 
110 #endif /* LNN_CONNECTION_FSM_H */