Move CoC to enhance, and implement the ble factory pattern.

Signed-off-by: weiyuanxin <weiyuanxin3@huawei.com>
This commit is contained in:
weiyuanxin 2023-06-16 14:26:46 +08:00
parent 2c5a881559
commit 18e14c1f0a
10 changed files with 178 additions and 426 deletions

View File

@ -1,137 +0,0 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "softbus_adapter_coc.h"
#include "softbus_errcode.h"
static int32_t OpenCocServer(CocPsm *cocPsm)
{
(void)cocPsm;
return SOFTBUS_OK;
}
static void CloseCocServer(int32_t serverFd)
{
(void)serverFd;
}
static int32_t CreateCocClient(void)
{
return SOFTBUS_OK;
}
static void DestroyCocClient(int32_t clientFd)
{
(void)clientFd;
}
static int32_t Connect(int32_t clientFd, const BT_ADDR mac, int32_t psm)
{
(void)clientFd;
(void)mac;
(void)psm;
return SOFTBUS_OK;
}
static bool CancelConnect(int32_t clientFd)
{
(void)clientFd;
return true;
}
static int32_t DisConnect(int32_t fd)
{
(void)fd;
return SOFTBUS_OK;
}
static bool IsConnected(int32_t fd)
{
(void)fd;
return true;
}
static int32_t Accept(int32_t serverFd)
{
(void)serverFd;
return SOFTBUS_OK;
}
static int32_t Write(int32_t fd, const uint8_t *buf, const int32_t length)
{
(void)fd;
(void)buf;
(void)length;
return SOFTBUS_OK;
}
static int32_t Read(int32_t fd, uint8_t *buf, const int32_t length)
{
(void)fd;
(void)buf;
(void)length;
return SOFTBUS_OK;
}
static bool EnableFastCocConnection(int32_t clientFd)
{
(void)clientFd;
return true;
}
static bool SetCocPreferredPhy(int32_t clientFd, int32_t txPhy, int32_t rxPhy, int32_t phyOptions)
{
(void)clientFd;
(void)txPhy;
(void)rxPhy;
(void)phyOptions;
return true;
}
static bool UpdateCocConnectionParams(int32_t clientFd, int32_t priority)
{
(void)clientFd;
(void)priority;
return true;
}
static int32_t GetRemoteDeviceInfo(int32_t fd, BluetoothRemoteDevice *device)
{
(void)fd;
(void)device;
return SOFTBUS_OK;
}
CocSocketDriver *InitCocSocketDriver()
{
static CocSocketDriver g_cocSocketDriver = {
.OpenCocServer = OpenCocServer,
.CloseCocServer = CloseCocServer,
.CreateCocClient = CreateCocClient,
.DestroyCocClient = DestroyCocClient,
.Connect = Connect,
.CancelConnect = CancelConnect,
.DisConnect = DisConnect,
.IsConnected = IsConnected,
.Accept = Accept,
.Write = Write,
.Read = Read,
.EnableFastCocConnection = EnableFastCocConnection,
.SetCocPreferredPhy = SetCocPreferredPhy,
.UpdateCocConnectionParams = UpdateCocConnectionParams,
.GetRemoteDeviceInfo = GetRemoteDeviceInfo,
};
return &g_cocSocketDriver;
}

View File

@ -1,72 +0,0 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOFTBUS_ADAPTER_COC_H
#define SOFTBUS_ADAPTER_COC_H
#include <stdbool.h>
#include <stdint.h>
#include "softbus_adapter_bt_common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef uint8_t BT_ADDR[BT_ADDR_LEN];
#define COC_READ_SOCKET_CLOSED 0
#define COC_READ_FAILED (-1)
typedef struct {
int32_t serverFd;
int32_t psm;
} CocPsm;
typedef struct {
int32_t psm;
BT_ADDR mac;
} BluetoothRemoteDevice;
typedef enum {
SOFTBUS_COC_PRIORITY_BALANCED = 0x0,
SOFTBUS_COC_PRIORITY_HIGH,
SOFTBUS_COC_PRIORITY_LOW_POWER,
} SoftbusBleCocPriority;
typedef struct {
int32_t (*OpenCocServer)(CocPsm *cocPsm);
void (*CloseCocServer)(int32_t serverFd);
int32_t (*CreateCocClient)();
void (*DestroyCocClient)(int32_t clientFd);
int32_t (*Connect)(int32_t clientFd, const BT_ADDR mac, int32_t psm);
bool (*CancelConnect)(int32_t clientFd);
int32_t (*DisConnect)(int32_t fd);
bool (*IsConnected)(int32_t fd);
int32_t (*Accept)(int32_t serverFd);
int32_t (*Write)(int32_t fd, const uint8_t *buf, const int32_t length);
int32_t (*Read)(int32_t fd, uint8_t *buf, const int32_t length);
bool (*EnableFastCocConnection)(int32_t clientFd);
bool (*SetCocPreferredPhy)(int32_t clientFd, int32_t txPhy, int32_t rxPhy, int32_t phyOptions);
bool (*UpdateCocConnectionParams)(int32_t clientFd, int32_t priority);
int32_t (*GetRemoteDeviceInfo)(int32_t fd, BluetoothRemoteDevice *device);
} CocSocketDriver;
CocSocketDriver *InitCocSocketDriver();
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* SOFTBUS_ADAPTER_COC_H */

View File

@ -26,7 +26,6 @@ adapter_ble_src = [
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_client.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/ble/softbus_adapter_coc_virtual.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/common/adapter_bt_utils.c",
"$dsoftbus_root_path/adapter/common/net/bluetooth/common/softbus_adapter_bt_common.c",
]

View File

@ -23,6 +23,13 @@ enhanced_conn_ble = exec_script("$dsoftbus_root_path/check_sub_module.py",
"$conn_ble_dir",
],
"value")
conn_coc_dir = "dsoftbus_enhance/core/connection/coc"
enhanced_conn_coc = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$native_source_path",
"$conn_coc_dir",
],
"value")
ble_connection_deps = []
if (dsoftbus_feature_conn_ble == false) {
ble_connection_src = [
@ -47,7 +54,6 @@ if (dsoftbus_feature_conn_ble == false) {
"$dsoftbus_root_path/core/connection/ble/src/softbus_conn_ble_send_queue.c",
"$dsoftbus_root_path/core/connection/ble/src/softbus_conn_ble_server.c",
"$dsoftbus_root_path/core/connection/ble/src/softbus_conn_ble_trans.c",
"$dsoftbus_root_path/core/connection/ble/src/softbus_conn_ble_coc_virtual.c",
]
ble_connection_inc = [
"$dsoftbus_root_path/core/connection/ble/include",
@ -59,6 +65,16 @@ if (dsoftbus_feature_conn_ble == false) {
} else {
ble_connection_src += [ "$dsoftbus_root_path/core/connection/ble/src/softbus_conn_ble_direct_virtual.c" ]
}
if (enhanced_conn_coc == true) {
ble_connection_src += [
"$dsoftbus_root_path/dsoftbus_enhance/core/connection/coc/src/ble_protocol_interface_factory.c",
"$dsoftbus_root_path/dsoftbus_enhance/core/connection/coc/src/softbus_adapter_coc.c",
"$dsoftbus_root_path/dsoftbus_enhance/core/connection/coc/src/softbus_conn_ble_coc.c",
]
ble_connection_inc += [ "$dsoftbus_root_path/dsoftbus_enhance/core/connection/coc/include" ]
} else {
ble_connection_src += [ "$dsoftbus_root_path/core/connection/ble/src/ble_protocol_interface_factory.c" ]
}
ble_connection_src += adapter_ble_src
ble_connection_inc += adapter_ble_inc
ble_connection_deps += adapter_ble_deps

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef COMMUNICATION_BLE_PROTOCOL_INTERFACE_FACTORY_H
#define COMMUNICATION_BLE_PROTOCOL_INTERFACE_FACTORY_H
#include "softbus_conn_ble_connection.h"
#ifdef__cplusplus
extern "C" {
#endif
const BleUnifyInterface *getBleUnifyInterface(BleProtocolType type);
#ifdef__cplusplus
}
#endif /* __cplusplus */
#endif //COMMUNICATION_BLE_PROTOCOL_INTERFACE_FACTORY_H

View File

@ -1,48 +0,0 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOFTBUS_CONN_BLE_COC_H
#define SOFTBUS_CONN_BLE_COC_H
#include "message_handler.h"
#include "softbus_conn_ble_connection.h"
#include "softbus_conn_interface.h"
#include "softbus_adapter_coc.h"
#include "softbus_error_code.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_COC_READ_BUFFER_CAPACITY (40 * 1000)
#define MAX_COC_MTU_SIZE (3 * 1024)
int32_t ConnCocClientConnect(ConnBleConnection *connection);
int32_t ConnCocClientDisconnect(ConnBleConnection *connection, bool ignore1, bool ignore2);
int32_t ConnCocClientSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module);
int32_t ConnCocClientUpdatePriority(ConnBleConnection *connection, ConnectBlePriority priority);
int32_t ConnCocServerStartService();
int32_t ConnCocServerStopService();
int32_t ConnCocServerSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module);
int32_t ConnCocServerDisconnect(ConnBleConnection *connection);
int32_t ConnCocServerConnect(ConnBleConnection *connection);
int32_t ConnCocGetServerPsm();
int32_t ConnCocInitModule(SoftBusLooper *looper, const ConnBleClientEventListener *cListener,
const ConnBleServerEventListener *sListener);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* SOFTBUS_CONN_BLE_COC_H */

View File

@ -158,6 +158,8 @@ typedef struct {
int32_t (*bleServerSend)(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module);
int32_t (*bleServerConnect)(ConnBleConnection *connection);
int32_t (*bleServerDisconnect)(ConnBleConnection *connection);
int32_t (*bleClientInitModule)(SoftBusLooper *looper, const ConnBleClientEventListener *listener);
int32_t (*bleServerInitModule)(SoftBusLooper *looper, const ConnBleServerEventListener *listener);
} BleUnifyInterface;
ConnBleConnection *ConnBleCreateConnection(

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ble_protocol_interface_factory.h"
#include "softbus_common.h"
#include "softbus_conn_ble_connection.h"
#include "softbus_conn_ble_client.h"
#include "softbus_conn_ble_server.h"
static BleUnifyInterface g_bleUnifyInterface[BLE_PROTOCOL_MAX] = {
[BLE_GATT] = {
.bleClientConnect = ConnGattClientConnect,
.bleClientDisconnect = ConnGattClientDisconnect,
.bleClientSend = ConnGattClientSend,
.bleClientUpdatePriority = ConnGattClientUpdatePriority,
.bleServerStartService = ConnGattServerStartService,
.bleServerStopService = ConnGattServerStopService,
.bleServerSend = ConnGattServerSend,
.bleServerDisconnect = ConnGattServerDisconnect,
.bleServerConnect = ConnGattServerConnect,
.bleClientInitModule = ConnGattInitClientModule,
.bleServerInitModule = ConnGattInitServerModule,
}
};
const BleUnifyInterface *getBleUnifyInterface(BleProtocolType type)
{
return &g_bleUnifyInterface[type];
}

View File

@ -1,101 +0,0 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "softbus_conn_ble_coc.h"
#include "securec.h"
#include "message_handler.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_coc.h"
#include "softbus_conn_ble_connection.h"
#include "softbus_conn_ble_manager.h"
#include "softbus_feature_config.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
#include "softbus_type_def.h"
#include "softbus_utils.h"
int32_t ConnCocClientConnect(ConnBleConnection *connection)
{
(void)connection;
return SOFTBUS_ERR;
}
int32_t ConnCocClientDisconnect(ConnBleConnection *connection, bool ignore1, bool ignore2)
{
(void)connection;
(void)ignore1;
(void)ignore2;
return SOFTBUS_ERR;
}
int32_t ConnCocClientSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module)
{
(void)connection;
(void)data;
(void)dataLen;
(void)module;
return SOFTBUS_ERR;
}
int32_t ConnCocClientUpdatePriority(ConnBleConnection *connection, ConnectBlePriority priority)
{
(void)connection;
(void)priority;
return SOFTBUS_ERR;
}
int32_t ConnCocGetServerPsm()
{
return SOFTBUS_ERR;
}
int32_t ConnCocServerStartService()
{
return SOFTBUS_OK;
}
int32_t ConnCocServerStopService(void)
{
return SOFTBUS_OK;
}
int32_t ConnCocServerSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module)
{
return SOFTBUS_ERR;
}
int32_t ConnCocServerDisconnect(ConnBleConnection *connection)
{
(void)connection;
return SOFTBUS_ERR;
}
int32_t ConnCocServerConnect(ConnBleConnection *connection)
{
(void)connection;
return SOFTBUS_ERR;
}
int32_t ConnCocInitModule(SoftBusLooper *looper, const ConnBleClientEventListener *cListener,
const ConnBleServerEventListener *sListener)
{
(void)looper;
(void)cListener;
(void)sListener;
return SOFTBUS_OK;
}

View File

@ -20,7 +20,6 @@
#include "bus_center_manager.h"
#include "softbus_adapter_mem.h"
#include "softbus_conn_ble_client.h"
#include "softbus_conn_ble_coc.h"
#include "softbus_conn_ble_manager.h"
#include "softbus_conn_ble_server.h"
#include "softbus_conn_ble_trans.h"
@ -28,6 +27,7 @@
#include "softbus_datahead_transform.h"
#include "softbus_json_utils.h"
#include "softbus_log.h"
#include "ble_protocol_interface_factory.h"
// basic info json key definition
#define BASIC_INFO_KEY_DEVID "devid"
@ -78,31 +78,6 @@ static BleServerCoordination g_serverCoordination = {
// compatible with old devices, old device not support remote disconnect
static const ConnBleFeatureBitSet g_featureBitSet = (1 << BLE_FEATURE_SUPPORT_REMOTE_DISCONNECT);
static BleUnifyInterface g_bleUnifyInterface[BLE_PROTOCOL_MAX] = {
[BLE_GATT] = {
.bleClientConnect = ConnGattClientConnect,
.bleClientDisconnect = ConnGattClientDisconnect,
.bleClientSend = ConnGattClientSend,
.bleClientUpdatePriority = ConnGattClientUpdatePriority,
.bleServerStartService = ConnGattServerStartService,
.bleServerStopService = ConnGattServerStopService,
.bleServerSend = ConnGattServerSend,
.bleServerDisconnect = ConnGattServerDisconnect,
.bleServerConnect = ConnGattServerConnect,
},
[BLE_COC] = {
.bleClientConnect = ConnCocClientConnect,
.bleClientDisconnect = ConnCocClientDisconnect,
.bleClientSend = ConnCocClientSend,
.bleClientUpdatePriority = ConnCocClientUpdatePriority,
.bleServerStartService = ConnCocServerStartService,
.bleServerStopService = ConnCocServerStopService,
.bleServerSend = ConnCocServerSend,
.bleServerDisconnect = ConnCocServerDisconnect,
.bleServerConnect = ConnCocServerConnect,
}
};
ConnBleConnection *ConnBleCreateConnection(
const char *addr, BleProtocolType protocol, ConnSideType side, int32_t underlayerHandle, bool fastestConnectEnable)
{
@ -169,12 +144,17 @@ int32_t ConnBleStartServer()
if (actual == BLE_SERVER_STATE_STARTING || actual == BLE_SERVER_STATE_STARTED) {
return SOFTBUS_OK;
}
g_serverCoordination.status[BLE_GATT] = g_bleUnifyInterface[BLE_GATT].bleServerStartService();
g_serverCoordination.status[BLE_COC] = g_bleUnifyInterface[BLE_COC].bleServerStartService();
if (g_serverCoordination.status[BLE_GATT] != SOFTBUS_OK || g_serverCoordination.status[BLE_COC] != SOFTBUS_OK) {
ConnPostMsgToLooper(&g_bleConnectionAsyncHandler, MSG_CONNECTION_RETRY_SERVER_STATE_CONSISTENT, 0, 0, NULL,
RETRY_SERVER_STATE_CONSISTENT_MILLIS);
return SOFTBUS_OK;
for (int i = BLE_GATT; i < BLE_PROTOCOL_MAX; i++) {
BleUnifyInterface *interface = getBleUnifyInterface(i);
if (interface == NULL) {
continue;
}
g_serverCoordination.status[i] = interface->bleServerStartService();
if (g_serverCoordination.status[i] != SOFTBUS_OK) {
ConnPostMsgToLooper(&g_bleConnectionAsyncHandler, MSG_CONNECTION_RETRY_SERVER_STATE_CONSISTENT, 0, 0, NULL,
RETRY_SERVER_STATE_CONSISTENT_MILLIS);
return SOFTBUS_OK;
}
}
CONN_CHECK_AND_RETURN_RET_LOG(SoftBusMutexLock(&g_serverCoordination.lock) == SOFTBUS_OK, SOFTBUS_LOCK_ERR,
"ATTENTION UNEXPECTED EXCEPTION: ble start server failed, try to lock failed");
@ -193,13 +173,17 @@ int32_t ConnBleStopServer()
if (actual == BLE_SERVER_STATE_STOPPING || actual == BLE_SERVER_STATE_STOPPED) {
return SOFTBUS_OK;
}
g_serverCoordination.status[BLE_GATT] = g_bleUnifyInterface[BLE_GATT].bleServerStopService();
g_serverCoordination.status[BLE_COC] = g_bleUnifyInterface[BLE_COC].bleServerStopService();
if (g_serverCoordination.status[BLE_GATT] != SOFTBUS_OK || g_serverCoordination.status[BLE_COC] != SOFTBUS_OK) {
ConnPostMsgToLooper(&g_bleConnectionAsyncHandler, MSG_CONNECTION_RETRY_SERVER_STATE_CONSISTENT, 0, 0, NULL,
RETRY_SERVER_STATE_CONSISTENT_MILLIS);
return SOFTBUS_OK;
for (int i = BLE_GATT; i < BLE_PROTOCOL_MAX; i++) {
BleUnifyInterface *interface = getBleUnifyInterface(i);
if (interface == NULL) {
continue;
}
g_serverCoordination.status[i] = interface->bleServerStopService();
if (g_serverCoordination.status[i] != SOFTBUS_OK) {
ConnPostMsgToLooper(&g_bleConnectionAsyncHandler, MSG_CONNECTION_RETRY_SERVER_STATE_CONSISTENT, 0, 0, NULL,
RETRY_SERVER_STATE_CONSISTENT_MILLIS);
return SOFTBUS_OK;
}
}
CONN_CHECK_AND_RETURN_RET_LOG(SoftBusMutexLock(&g_serverCoordination.lock) == SOFTBUS_OK, SOFTBUS_LOCK_ERR,
"ATTENTION UNEXPECTED EXCEPTION: ble close server failed, try to lock failed");
@ -210,7 +194,11 @@ int32_t ConnBleStopServer()
int32_t ConnBleConnect(ConnBleConnection *connection)
{
return g_bleUnifyInterface[connection->protocol].bleClientConnect(connection);
BleUnifyInterface *interface = getBleUnifyInterface(connection->protocol);
if (interface == NULL) {
return SOFTBUS_ERR;
}
return interface->bleClientConnect(connection);
}
static bool ShouldGrace(enum ConnBleDisconnectReason reason)
@ -238,6 +226,10 @@ static bool ShoudRefreshGatt(enum ConnBleDisconnectReason reason)
int32_t ConnBleDisconnectNow(ConnBleConnection *connection, enum ConnBleDisconnectReason reason)
{
BleUnifyInterface *interface = getBleUnifyInterface(connection->protocol);
if (interface ==NULL) {
return SOFTBUS_ERR;
}
CLOGW("receive ble disconnect now, connection id=%u, side=%d, reason=%d", connection->connectionId,
connection->side, reason);
ConnRemoveMsgFromLooper(
@ -245,9 +237,9 @@ int32_t ConnBleDisconnectNow(ConnBleConnection *connection, enum ConnBleDisconne
if (connection->side == CONN_SIDE_CLIENT) {
bool grace = ShouldGrace(reason);
bool refreshGatt = ShoudRefreshGatt(reason);
return g_bleUnifyInterface[connection->protocol].bleClientDisconnect(connection, grace, refreshGatt);
return interface->bleClientDisconnect(connection, grace, refreshGatt);
}
return g_bleUnifyInterface[connection->protocol].bleServerDisconnect(connection);
return interface->bleServerDisconnect(connection);
}
int32_t ConnBleUpdateConnectionRc(ConnBleConnection *connection, int32_t delta)
@ -371,7 +363,11 @@ int32_t ConnBleUpdateConnectionPriority(ConnBleConnection *connection, ConnectBl
if (connection->side == CONN_SIDE_SERVER) {
return SOFTBUS_FUNC_NOT_SUPPORT;
}
return g_bleUnifyInterface[connection->protocol].bleClientUpdatePriority(connection, priority);
BleUnifyInterface *interface = getBleUnifyInterface(connection->protocol);
if (interface == NULL) {
return SOFTBUS_ERR;
}
return interface->bleClientUpdatePriority(connection, priority);
}
int32_t ConnBleSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module)
@ -383,9 +379,13 @@ int32_t ConnBleSend(ConnBleConnection *connection, const uint8_t *data, uint32_t
CONN_CHECK_AND_RETURN_RET_LOG(
dataLen != 0, SOFTBUS_INVALID_PARAM, "ble connection send data failed, invalid param, data len is 0");
BleUnifyInterface *interface = getBleUnifyInterface(connection->protocol);
if (interface == NULL) {
return SOFTBUS_ERR;
}
return connection->side == CONN_SIDE_SERVER ?
g_bleUnifyInterface[connection->protocol].bleServerSend(connection, data, dataLen, module) :
g_bleUnifyInterface[connection->protocol].bleClientSend(connection, data, dataLen, module);
interface->bleServerSend(connection, data, dataLen, module) :
interface->bleClientSend(connection, data, dataLen, module);
}
void ConnBleRefreshIdleTimeout(ConnBleConnection *connection)
@ -493,7 +493,7 @@ static int32_t SendBasicInfo(ConnBleConnection *connection)
int32_t *netCtrlMsgHeader = (int32_t *)(buf + offset);
netCtrlMsgHeader[0] = NET_CTRL_MSG_TYPE_BASIC_INFO;
offset += NET_CTRL_MSG_TYPE_HEADER_SIZE;
if (memcpy_s(buf + offset, bufLen - offset, payload, payloadLen)) {
if (memcpy_s(buf + offset, bufLen - offset, payload, payloadLen) != EOK) {
CLOGE("ble send basic info failed: memcpy_s buf failed, connection id=%u, buf len=%u, paylaod len=%u",
connection->connectionId, bufLen, payloadLen);
status = SOFTBUS_MEM_ERR;
@ -688,7 +688,10 @@ void BleOnDataReceived(uint32_t connectionId, bool isConnCharacteristic, uint8_t
if (connection->side == CONN_SIDE_CLIENT) {
g_connectionListener.onConnectFailed(connection->connectionId, status);
} else {
g_bleUnifyInterface[connection->protocol].bleServerDisconnect(connection);
BleUnifyInterface *interface = getBleUnifyInterface(connection->protocol);
if (interface != NULL) {
interface->bleServerDisconnect(connection);
}
}
break;
}
@ -696,14 +699,19 @@ void BleOnDataReceived(uint32_t connectionId, bool isConnCharacteristic, uint8_t
&g_bleConnectionAsyncHandler, MSG_CONNECTION_EXCHANGE_BASIC_INFO_TIMEOUT, connectionId, 0, NULL);
if (connection->side == CONN_SIDE_SERVER) {
status = SendBasicInfo(connection);
BleUnifyInterface *interface = getBleUnifyInterface(connection->protocol);
if (status != SOFTBUS_OK) {
CLOGE("ble connection data received failed, send server side basic info failed, connection id=%u, "
"underlayer handle=%d, error=%d",
connectionId, underlayerHandle, status);
g_bleUnifyInterface[connection->protocol].bleServerDisconnect(connection);
if (interface != NULL) {
interface->bleServerDisconnect(connection);
}
break;
}
status = g_bleUnifyInterface[connection->protocol].bleServerConnect(connection);
if (interface != NULL) {
status = interface->bleServerConnect(connection);
}
CLOGI("ble connection data received, server side finish exchange basic info, connection id=%u, "
"underlayer handle=%d, server connect status=%d",
connectionId, underlayerHandle, status);
@ -790,7 +798,10 @@ void BleOnServerAccepted(uint32_t connectionId)
}
} while (false);
if (status != SOFTBUS_OK) {
g_bleUnifyInterface[connection->protocol].bleServerDisconnect(connection);
BleUnifyInterface *interface = getBleUnifyInterface(connection->protocol);
if (interface != NULL) {
interface->bleServerDisconnect(connection);
}
}
ConnBleReturnConnection(&connection);
}
@ -800,13 +811,19 @@ static int32_t DoRetryAction(enum BleServerState expect)
int32_t statusGatt = SOFTBUS_OK;
int32_t statusCoc = SOFTBUS_OK;
if (g_serverCoordination.status[BLE_GATT] != SOFTBUS_OK) {
statusGatt = (expect == BLE_SERVER_STATE_STARTED) ? g_bleUnifyInterface[BLE_GATT].bleServerStartService() :
g_bleUnifyInterface[BLE_GATT].bleServerStopService();
BleUnifyInterface *interface = getBleUnifyInterface(BLE_GATT);
if (interface != NULL) {
statusGatt = (expect == BLE_SERVER_STATE_STARTED) ? interface->bleServerStartService() :
interface->bleServerStopService();
}
}
if (g_serverCoordination.status[BLE_COC] != SOFTBUS_OK) {
statusCoc = (expect == BLE_SERVER_STATE_STARTED) ? g_bleUnifyInterface[BLE_COC].bleServerStartService() :
g_bleUnifyInterface[BLE_COC].bleServerStopService();
BleUnifyInterface *interface = getBleUnifyInterface(BLE_COC);
if (interface != NULL) {
statusCoc = (expect == BLE_SERVER_STATE_STARTED) ? interface->bleServerStartService() :
interface->bleServerStopService();
}
}
return (statusGatt != SOFTBUS_OK || statusCoc != SOFTBUS_OK) ? SOFTBUS_ERR : SOFTBUS_OK;
@ -852,7 +869,10 @@ static void BasicInfoExchangeTimeoutHandler(uint32_t connectionId)
if (connection->side == CONN_SIDE_CLIENT) {
g_connectionListener.onConnectFailed(connectionId, SOFTBUS_CONN_BLE_EXCHANGE_BASIC_INFO_TIMEOUT_ERR);
} else {
g_bleUnifyInterface[connection->protocol].bleServerDisconnect(connection);
BleUnifyInterface *interface = getBleUnifyInterface(connection->protocol);
if (interface != NULL) {
interface->bleServerDisconnect(connection);
}
}
ConnBleReturnConnection(&connection);
}
@ -965,11 +985,6 @@ int32_t ConnBleInitConnectionMudule(SoftBusLooper *looper, ConnBleConnectionEven
.onClientDataReceived = BleOnDataReceived,
.onClientConnectionClosed = BleOnConnectionClosed,
};
int32_t status = ConnGattInitClientModule(looper, &clientEventListener);
CONN_CHECK_AND_RETURN_RET_LOG(
status == SOFTBUS_OK, status, "init ble connection failed: init ble client failed, error=%d", status);
ConnBleServerEventListener serverEventLisener = {
.onServerStarted = BleOnServerStarted,
.onServerClosed = BleOnServerClosed,
@ -977,12 +992,19 @@ int32_t ConnBleInitConnectionMudule(SoftBusLooper *looper, ConnBleConnectionEven
.onServerDataReceived = BleOnDataReceived,
.onServerConnectionClosed = BleOnConnectionClosed,
};
status = ConnGattInitServerModule(looper, &serverEventLisener);
CONN_CHECK_AND_RETURN_RET_LOG(
status == SOFTBUS_OK, status, "init ble connection failed: init ble server failed, error=%d", status);
status = ConnCocInitModule(looper, &clientEventListener, &serverEventLisener);
CONN_CHECK_AND_RETURN_RET_LOG(
status == SOFTBUS_OK, status, "init ble connection failed: init ble coc failed, error=%d", status);
int32_t status = SOFTBUS_ERR;
for (int i = BLE_GATT; i < BLE_PROTOCOL_MAX; i++) {
BleUnifyInterface *interface = getBleUnifyInterface(i);
if (interface == NULL) {
continue;
}
status = interface->bleClientInitModule(looper, &clientEventListener);
CONN_CHECK_AND_RETURN_RET_LOG(status == SOFTBUS_OK, status,
"init ble connection failed: init ble %d client failed, error=%d", i, status);
status = interface->bleServerInitModule(looper, &serverEventListener);
CONN_CHECK_AND_RETURN_RET_LOG(status == SOFTBUS_OK, status,
"init ble connection failed: init ble %d server failed, error=%d", i, status);
}
status = SoftBusMutexInit(&g_serverCoordination.lock, NULL);
CONN_CHECK_AND_RETURN_RET_LOG(status == SOFTBUS_OK, status,