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_INTERFACE_H 17 #define SOFTBUS_CONN_INTERFACE_H 18 19 #include "softbus_common.h" 20 #include "softbus_def.h" 21 #include "softbus_protocol_def.h" 22 #include "softbus_conn_interface_struct.h" 23 24 #ifdef __cplusplus 25 #if __cplusplus 26 extern "C" { 27 #endif 28 #endif 29 30 /** 31 * @ingroup softbus_conn_manager 32 * @brief Get connection header size. 33 * @return <b>SOFTBUS_OK</b> if the header length get is successfully. 34 */ 35 uint32_t ConnGetHeadSize(void); 36 37 /** 38 * @brief The initialization of the connection server is mainly for the initialization of tcp, br, and ble. 39 * This interface is only called once when the soft bus service is created. 40 * @see {@link ConnServerDeinit} 41 * @return <b>SOFTBUS_OK</b> Successfully initialized connection server 42 * returns an error code less than zero otherwise. 43 */ 44 int32_t ConnServerInit(void); 45 46 /** 47 * @brief Deinitialize the connection server, the tcp, br, and ble connection servers will be deinitialized. 48 * This interface is only called once when the soft bus service is destroyed. 49 * @see {@link ConnServerInit} 50 */ 51 void ConnServerDeinit(void); 52 53 /** 54 * @ingroup Softbus_conn_manager 55 * @brief Register connection callback. 56 * @see {@link ConnUnSetConnectCallback} 57 * @param[in] moduleId Module ID. For details, see {@link ConnModule}. 58 * @param[in] callback Indicates a pointer to the connection callback. For details, see {@link ConnectCallback}. 59 * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null or invalid. 60 * @return <b>SOFTBUS_OK</b> if set the connection callback is successfully. 61 */ 62 int32_t ConnSetConnectCallback(ConnModule moduleId, const ConnectCallback *callback); 63 64 /** 65 * @ingroup Softbus_conn_manager 66 * @brief Unset the connection callback, clear the callback setting of ConnSetConnectCallback. 67 * @see {@link ConnSetConnectCallback} 68 * @param[in] moduleId Module ID.For details, see {@link ConnModule}. 69 */ 70 void ConnUnSetConnectCallback(ConnModule moduleId); 71 72 /** 73 * @ingroup Softbus_conn_manager 74 * @brief Send data to peer. 75 * @param[in] connectionId Connection ID. 76 * @param[in] data Connection message content. For details, see {@link ConnPostData}. 77 * @return <b>SOFTBUS_INVALID_PARAM</b> if any parameter is null. 78 * @return <b>SOFTBUS_CONN_MANAGER_PKT_LEN_INVALID</b> if the data parameter length is wrong. 79 * @return <b>SOFTBUS_CONN_MANAGER_TYPE_NOT_SUPPORT</b> if the type is null or invalid. 80 * @return <b>SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT</b> if the bytes result is null. 81 * @return <b>SOFTBUS_OK</b> if sending by byte is successfully. 82 */ 83 int32_t ConnPostBytes(uint32_t connectionId, ConnPostData *data); 84 85 /** 86 * @ingroup Softbus_conn_manager 87 * @brief Type checking of the connection module to check if this type is supported. 88 * @param[in] type Connection type. For details, see {@link ConnectType}. 89 * @return <b>SOFTBUS_OK</b> If checked the connection type is successfully. 90 */ 91 int32_t ConnTypeIsSupport(ConnectType type); 92 93 /** 94 * @ingroup Softbus_conn_manager 95 * @brief set keep alive by connectionId. 96 * @param[in] connectionId Connection Id. 97 * @param[in] needKeepalive tcp need keepalive. 98 * @return <b>SOFTBUS_OK</b> set keepalive success. 99 */ 100 int32_t ConnSetKeepaliveByConnectionId(uint32_t connectionId, bool needKeepalive); 101 102 /** 103 * @ingroup Softbus_conn_manager 104 * @brief Get inner object based on connection id. 105 * @param[in] connectionId Connection ID. 106 * @param[in] info Indicates a pointer to the connection information. For details, see {@link ConnectionInfo}. 107 * @return <b>SOFTBUS_CONN_MANAGER_TYPE_NOT_SUPPORT</b> if the type is null or invalid. 108 * @return <b>SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT</b> if the result is null. 109 * @return <b>SOFTBUS_OK</b> if the connection information get is successfully. 110 */ 111 int32_t ConnGetConnectionInfo(uint32_t connectionId, ConnectionInfo *info); 112 113 /** 114 * @ingroup Softbus_conn_manager 115 * @brief Request connection id. 116 * @param[in] moduleId ConnModule module ID. For details, see {@link ConnModule}. 117 * @return <b>SOFTBUS_OK</b> if get new request ID is successfully. 118 */ 119 uint32_t ConnGetNewRequestId(ConnModule moduleId); 120 121 /** 122 * @ingroup Softbus_conn_manager 123 * @brief Connect the device interface, call this interface to initiate a connection to the remote end. 124 * @see {@link ConnDisconnectDevice} 125 * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}. 126 * @param[in] requestId Request ID. 127 * @param[in] result Indicates a pointer to the connection request. For details, see {@link ConnectResult}. 128 * @return <b>SOFTBUS_OK</b> if the connection to the device is successfully 129 * returns an error code less than zero otherwise. 130 */ 131 int32_t ConnConnectDevice(const ConnectOption *option, uint32_t requestId, const ConnectResult *result); 132 133 /** 134 * @ingroup Softbus_conn_manager 135 * @brief Disconnect the device connection interface, disconnect the device logical connection, 136 * and disconnect the physical connection when the logical connection reference is zero. 137 * @see {@link ConnConnectDevice} 138 * @param[in] connectionId Connection ID. 139 * @return <b>SOFTBUS_CONN_MANAGER_TYPE_NOT_SUPPORT</b> if the type is null. 140 * @return <b>SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT</b> if the disconnection device function of type is null. 141 * @return <b>SOFTBUS_OK</b> if the device disconnected is successfully. 142 */ 143 int32_t ConnDisconnectDevice(uint32_t connectionId); 144 145 /** 146 * @ingroup Softbus_conn_manager 147 * @brief Disconnects all connected device interfaces, 148 * and disconnects the logical and physical connections on the specified device. 149 * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}. 150 * @return <b>SOFTBUS_INVALID_PARAM</b> if the option is null. 151 * @return <b>SOFTBUS_CONN_MANAGER_TYPE_NOT_SUPPORT</b> if the type is null. 152 * @return <b>SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT</b> 153 * if all connected devices all disconnected function of type is null. 154 * @return <b>SOFTBUS_OK</b> if all connected devices all disconnected are successfully. 155 */ 156 int32_t ConnDisconnectDeviceAllConn(const ConnectOption *option); 157 158 /** 159 * @ingroup Softbus_conn_manager 160 * @brief Stop the local monitoring service and stop monitoring the peer connection event. 161 * @see {@link ConnStartLocalListening} 162 * @param[in] info Indicates a pointer to local listener information. For details, see {@link LocalListenerInfo}. 163 * @return <b>SOFTBUS_INVALID_PARAM</b> if the info is null. 164 * @return <b>SOFTBUS_CONN_MANAGER_TYPE_NOT_SUPPORT</b> if the type is null. 165 * @return <b>SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT</b> if local listener stop function of type is null. 166 * @return <b>SOFTBUS_OK</b> if local listener stop successfully. 167 */ 168 int32_t ConnStopLocalListening(const LocalListenerInfo *info); 169 170 /** 171 * @ingroup Softbus_conn_manager 172 * @brief Start the local monitoring service and listen for the peer connection event. 173 * @see {@link ConnStopLocalListening} 174 * @param[in] info Indicates a pointer to local listener information. For details, see {@link LocalListenerInfo}. 175 * @return <b>SOFTBUS_INVALID_PARAM</b> if the info is null. 176 * @return <b>SOFTBUS_CONN_MANAGER_TYPE_NOT_SUPPORT</b> if the type is null. 177 * @return <b>SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT</b> if local listener start function of type is null. 178 * @return <b>SOFTBUS_OK</b> if local listeners start successfully. 179 */ 180 int32_t ConnStartLocalListening(const LocalListenerInfo *info); 181 182 /** 183 * @ingroup Softbus_conn_manager 184 * @brief call this interface to initiate a ble direct connection or sle direct connection to the remote end. 185 * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}. 186 * @param[in] requestId Request ID. 187 * @param[in] result Indicates a pointer to the connection request. For details, see {@link ConnectResult}. 188 * @return <b>SOFTBUS_OK</b> if the connection to the device is successfully 189 * returns an error code less than zero otherwise. 190 */ 191 int32_t ConnDirectConnectDevice(const ConnectOption *option, uint32_t requestId, const ConnectResult *result); 192 193 /** 194 * @ingroup Softbus_conn_manager. 195 * @brief call this interface to check ble direct connect support or not. 196 * @return <b>false</b> if not support. 197 * @return <b>true</b> if support. 198 */ 199 bool ConnBleDirectIsEnable(BleProtocolType protocol); 200 201 bool CheckActiveConnection(const ConnectOption *option, bool needOccupy); 202 203 /** 204 * @ingroup Softbus_conn_manager 205 * @brief update connection properties as need 206 * @param[in] connectionId connection id which should be update. 207 * @param[in] option the option will acts on connection 208 * @return <b>SOFTBUS_OK</b> if update connection properties successfully, others if failed. 209 */ 210 int32_t ConnUpdateConnection(uint32_t connectionId, UpdateOption *option); 211 212 /** 213 * @ingroup Softbus_conn_manager 214 * @brief Prevent connect other devices in specified time. 215 * @param[in] option Indicates a pointer to the connection option. For details, see {@link ConnectOption}. 216 * @param[in] time time in millisecond 217 * @return <b>SOFTBUS_OK</b> if prevent connect other devices successfully, others if failed. 218 */ 219 int32_t ConnPreventConnection(const ConnectOption *option, uint32_t time); 220 221 /** 222 * @ingroup Softbus_conn_manager 223 * @brief Obtain link type based on connection ID. 224 * @param[in] connectionId Connection ID. 225 * @param[out] type Indicates a pointer to the link type. For details, see {@link ConnectType}. 226 * @return <b>SOFTBUS_OK</b> if prevent connect other devices successfully, others if failed. 227 */ 228 int32_t ConnGetTypeByConnectionId(uint32_t connectionId, ConnectType *type); 229 230 /** 231 * @ingroup Softbus_conn_manager 232 * @param configuration flow control configuration of posting data 233 * @return <b>SOFTBUS_OK</b> if success, others if failed. 234 */ 235 int32_t ConnConfigPostLimit(const LimitConfiguration *configuration); 236 237 void ConnDeathCallback(const char *pkgName, int32_t pid); 238 239 #ifdef __cplusplus 240 #if __cplusplus 241 } 242 #endif /* __cplusplus */ 243 #endif /* __cplusplus */ 244 245 #endif 246