• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 CONN_BR_MANAGER_STRUCT_H
17 #define CONN_BR_MANAGER_STRUCT_H
18 
19 #include <stdint.h>
20 
21 #include "common_list.h"
22 #include "softbus_common.h"
23 #include "softbus_conn_interface_struct.h"
24 #include "softbus_def.h"
25 #include "legacy/softbus_hisysevt_connreporter.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #define BR_CONNECT_TIMEOUT_MIN_MILLIS                    (10 * 1000)
32 #define BR_CONNECT_TIMEOUT_MAX_MILLIS                    (20 * 1000)
33 
34 #define BR_CONNECTION_PEND_TIMEOUT_MAX_MILLIS            (10 * 1000)
35 #define BR_CONNECTION_ACL_RETRY_CONNECT_COLLISION_MILLIS (3 * 1000)
36 #define BR_CONNECTION_ACL_CONNECT_COLLISION_MILLIS       (6 * 1000)
37 #define BR_WAIT_BLE_DISCONNECTED_PEND_MILLIS             (10 * 1000)
38 #define BR_NIP_SEQ                                       (0xeaddeaddeaddeadd)
39 
40 #define BR_CONNECT_WAIT_CALLBACK_TIMEOUT_MAX_MILLIS      (500)
41 
42 enum ConnBrDeviceState {
43     BR_DEVICE_STATE_INIT,
44     BR_DEVICE_STATE_WAIT_EVENT,
45     BR_DEVICE_STATE_PENDING,
46     BR_DEVICE_STATE_WAIT_SCHEDULE,
47     BR_DEVICE_STATE_SCHEDULING,
48 };
49 
50 typedef struct {
51     ListNode node;
52     char addr[BT_MAC_LEN];
53     enum ConnBrDeviceState state;
54     ListNode requests;
55     uint32_t connectionId;
56     uint32_t waitTimeoutDelay;
57     struct {
58         uint32_t keepAliveBleRequestId;
59         uint32_t keepAliveBleConnectionId;
60     } bleKeepAliveInfo;
61 } ConnBrDevice;
62 
63 typedef struct {
64     ListNode node;
65     ConnectResult result;
66     uint32_t requestId;
67     ConnectStatistics statistics;
68 } ConnBrRequest;
69 
70 typedef struct {
71     ConnectStatistics statistics;
72     char addr[BT_MAC_LEN];
73     uint32_t waitTimeoutDelay;
74     uint32_t requestId;
75     uint32_t connectionId;
76     ConnectResult result;
77 } ConnBrConnectRequestContext;
78 
79 typedef struct {
80     uint32_t connectionId;
81     uint32_t dataLen;
82     uint8_t *data;
83 } ConnBrDataReceivedContext;
84 
85 typedef struct {
86     char addr[BT_MAC_LEN];
87     uint32_t firstDuration;
88     uint32_t duration;
89     uint64_t firstStartTimestamp;
90     uint64_t startTimestamp;
91 } ConnBrPendInfo;
92 
93 typedef struct {
94     char *(*name)(void);
95     void (*enter)(void);
96     void (*exit)(void);
97     void (*connectRequest)(const ConnBrConnectRequestContext *ctx);
98     void (*handlePendingRequest)(void);
99     void (*serverAccepted)(uint32_t connectionId);
100     void (*clientConnected)(uint32_t connectionId);
101     void (*clientConnectFailed)(uint32_t connectionId, int32_t error);
102     void (*clientConnectTimeout)(uint32_t connectionId, const char *address);
103     void (*dataReceived)(ConnBrDataReceivedContext *ctx);
104     void (*connectionException)(uint32_t connectionId, int32_t error);
105     void (*connectionResume)(uint32_t connectionId);
106     void (*disconnectRequest)(uint32_t connectionId);
107     void (*unpend)(const char *addr);
108     void (*reset)(int32_t reason);
109 } ConnBrState;
110 
111 #ifdef __cplusplus
112 }
113 #endif /* __clpusplus */
114 #endif /* CONN_BR_MANAGER_STRUCT_H */
115