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