• 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 SOFTBUS_CONN_MANAGER_STRUCT_H
17 #define SOFTBUS_CONN_MANAGER_STRUCT_H
18 
19 #include "softbus_conn_interface_struct.h"
20 
21 #define CONNECT_TYPE_SHIFT 16
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef struct {
28     /**
29      * @brief To connect the device, you can use the br/ble/tcp type to initiate a connection to the remote end.
30      * The existing connection can be reused. If there is no physical connection, the logical connection will be made.
31      * @see {@link TcpConnectDevice} or {@link ConnectDevice} or {@link BleConnectDevice}.
32      * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}.
33      * @param[in] requestId Request ID.
34      * @param[in] result Indicates a pointer to the connection request. For details, see {@link ConnectResult}.
35      * @return <b>SOFTBUS_OK</b> if the connection to the device is successfully.
36      */
37     int32_t (*ConnectDevice)(const ConnectOption *option, uint32_t requestId, const ConnectResult *result);
38 
39     /**
40      * @brief Send data to the peer. Enable br/ble/tcp to send data.
41      * @see {@link TcpPostBytes} or {@link PostBytes} or {@link BlePostBytes}.
42      * @param[in] connectionId Connection ID.
43      * @param[in] data Connection message content.
44      * @param[in] len Data length.
45      * @param[in] pid Identification ID.
46      * @param[in] flag Message send flag.
47      * @param[in] module Message source module.
48      * @param[in] seq Message sequence.
49      * @return <b>SOFTBUS_OK</b> if sending by byte is successfully.
50      */
51     int32_t (*PostBytes)(
52         uint32_t connectionId, uint8_t *data, uint32_t len, int32_t pid, int32_t flag, int32_t module, int64_t seq);
53 
54     /**
55      * @brief To disconnect the device, use the br/ble/tcp type of disconnect device logically to disconnect
56      * the physical connection when the logical connection reference is zero.
57      * @see {@link TcpDisconnectDevice} or {@link DisconnectDevice} or {@link BleDisconnectDevice}.
58      * @param[in] connectionId Connection ID.
59      * @return <b>SOFTBUS_OK</b> if the device disconnected is successfully.
60      */
61     int32_t (*DisconnectDevice)(uint32_t connectionId);
62 
63     /**
64      * @brief Disconnects all connected devices, and disconnects logical and physical connections on
65      * specified devices of type br/ble/tcp.
66      * @see {@link TcpDisconnectDeviceNow} or {@link DisconnectDeviceNow} or {@link BleDisconnectDeviceNow}.
67      * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}.
68      * @return <b>SOFTBUS_OK</b> If the device is successfully disconnected through the address.
69      */
70     int32_t (*DisconnectDeviceNow)(const ConnectOption *option);
71 
72     /**
73      * @brief Get an internal object of type br/ble/tcp based on the connection id.
74      * @see {@link TcpGetConnectionInfo} or {@link GetConnectionInfo} or {@link BleGetConnectionInfo}.
75      * @param[in] connectionId Connection ID.
76      * @param[out] info Indicates a pointer to the connection information. For details, see {@link ConnectionInfo}.
77      * @return <b>SOFTBUS_OK</b> if get the connection information is successfully.
78      */
79     int32_t (*GetConnectionInfo)(uint32_t connectionId, ConnectionInfo *info);
80 
81     /**
82      * @brief Start the local monitoring service and listen for br/ble/tcp peer connection events.
83      * @see {@link TcpStartLocalListening} or {@link StartLocalListening} or {@link BleStartLocalListening}.
84      * @param[in] info Indicates a pointer to local listener information.
85      * For details, see {@link LocalListenerInfo}.
86      * @return <b>SOFTBUS_OK</b> if local listeners start successfully.
87      */
88     int32_t (*StartLocalListening)(const LocalListenerInfo *info);
89 
90     /**
91      * @brief Stop the local monitoring service and stop monitoring br/ble/tcp peer connection events.
92      * @see {@link TcpStopLocalListening} or {@link StopLocalListening} or {@link BleStopLocalListening}.
93      * @param[in] info Indicates a pointer to local listener information. For details, see {@link LocalListenerInfo}.
94      * @return <b>SOFTBUS_OK</b> if local listeners start successfully.
95      */
96     int32_t (*StopLocalListening)(const LocalListenerInfo *info);
97     bool (*CheckActiveConnection)(const ConnectOption *info, bool needOccupy);
98     int32_t (*UpdateConnection)(uint32_t connectionId, UpdateOption *option);
99 
100     /**
101      * @brief Prevent connect other devices in specified time.
102      * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}.
103      * @param[in] time time in millisecond
104      * @return <b>SOFTBUS_OK</b> if prevent connect other devices successfully, others if failed.
105      */
106     int32_t (*PreventConnection)(const ConnectOption *option, uint32_t time);
107 
108     /**
109      * @brief Config flow control of posting data
110      * @param configuration flow control configuration of posting data
111      */
112     int32_t (*ConfigPostLimit)(const LimitConfiguration *configuration);
113 } ConnectFuncInterface;
114 
115 #define MAGIC_NUMBER  0xBABEFACE
116 
117 #define CONN_FEATURE_SUPPORT_NETWORKID_EXCAHNGE 0
118 #define CONN_FEATURE_SUPPORT_ACTION_ENCODE 1
119 
120 typedef struct {
121     int32_t magic;
122     int32_t module;
123     int64_t seq;
124     int32_t flag;
125     uint32_t len;
126 } __attribute__((packed))ConnPktHead;
127 
128 #ifdef __cplusplus
129 #if __cplusplus
130 }
131 #endif /* __cplusplus */
132 #endif /* __cplusplus */
133 
134 #endif