modify ble direct interface

Signed-off-by: liangliang_ma <maliangliang1@huawei.com>
This commit is contained in:
liangliang_ma 2023-11-14 08:37:15 +00:00
parent 8203e9aefd
commit e4fe0375dc
21 changed files with 123 additions and 123 deletions

View File

@ -754,9 +754,31 @@ int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data)
return ret;
}
static int OhosBleStartAdvEx(int *advId, const SoftBusBleAdvParams *param, const SoftBusBleAdvData *data)
{
int btAdvId = -1;
BleAdvParams dstParam;
StartAdvRawData advData;
ConvertAdvParam(param, &dstParam);
ConvertAdvData(data, &advData);
int ret = BleStartAdvEx(&btAdvId, advData, dstParam);
if (ret != OHOS_BT_STATUS_SUCCESS) {
CLOGE("BleStartAdvEx, bt-advId: %d, ret: %d", btAdvId, ret);
return SOFTBUS_ERR;
}
*advId = btAdvId;
return SOFTBUS_OK;
}
int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param)
{
if (param == NULL) {
return SoftBusStartAdvEx(advId, param, OhosBleStartAdvEx);
}
int SoftBusStartAdvEx(int advId, const SoftBusBleAdvParams *param,
int (*startAdvEx)(int *, const SoftBusBleAdvParams *, const SoftBusBleAdvData *))
{
if (param == NULL || startAdvEx == NULL) {
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_advLock) != 0) {
@ -782,19 +804,12 @@ int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param)
return SOFTBUS_ERR;
}
}
int btAdvId = -1;
BleAdvParams dstParam;
StartAdvRawData advData;
ConvertAdvParam(param, &dstParam);
ConvertAdvData(&g_advChannel[advId].advData, &advData);
int ret = BleStartAdvEx(&btAdvId, advData, dstParam);
g_advChannel[advId].advId = btAdvId;
CLOGI("BleStartAdvEx, inner-advId: %d, bt-advId: %d, "
"ret: %d", advId, btAdvId, ret);
if (ret != OHOS_BT_STATUS_SUCCESS) {
int ret = startAdvEx(&g_advChannel[advId].advId, param, &g_advChannel[advId].advData);
CLOGI("inner-advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
if (ret != SOFTBUS_OK) {
g_advChannel[advId].advCallback->AdvEnableCallback(advId, SOFTBUS_BT_STATUS_FAIL);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
return ret;
}
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_OK;

View File

@ -193,6 +193,9 @@ int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data);
int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param);
int SoftBusStartAdvEx(int advId, const SoftBusBleAdvParams *param,
int (*startAdvEx)(int *, const SoftBusBleAdvParams *, const SoftBusBleAdvData *));
int SoftBusStopAdv(int advId);
int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data, const SoftBusBleAdvParams *param);

View File

@ -80,9 +80,7 @@ typedef struct {
typedef struct {
BleProtocolType protoType;
char nodeIdHash[NODEID_SHORT_HASH_LEN];
char localUdidHash[UDID_SHORT_HASH_LEN];
char peerUdidHash[SHA_256_HASH_LEN];
char networkId[NETWORK_ID_BUF_LEN];
} BleDirectConnInfo;
typedef struct {

View File

@ -66,10 +66,7 @@ typedef struct {
// 'GATT' and 'CoC' protocols under BLE use the same definitions
typedef struct {
BleProtocolType protoType;
int32_t psm; // mark--
char nodeIdHash[NODEID_SHORT_HASH_LEN];
char localUdidHash[UDID_SHORT_HASH_LEN];
char peerUdidHash[SHA_256_HASH_LEN];
char networkId[NETWORK_ID_BUF_LEN];
} BleDirectInfo;
typedef struct {

View File

@ -121,16 +121,8 @@ static int32_t Wlan5GInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connIn
static int32_t BleDirectInfoProc(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, LaneProfile *profile)
{
if (memcpy_s(connInfo->connInfo.bleDirect.nodeIdHash, NODEID_SHORT_HASH_LEN,
linkInfo->linkInfo.bleDirect.nodeIdHash, NODEID_SHORT_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
}
if (memcpy_s(connInfo->connInfo.bleDirect.localUdidHash, UDID_SHORT_HASH_LEN,
linkInfo->linkInfo.bleDirect.localUdidHash, UDID_SHORT_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
}
if (memcpy_s(connInfo->connInfo.bleDirect.peerUdidHash, SHA_256_HASH_LEN,
linkInfo->linkInfo.bleDirect.peerUdidHash, SHA_256_HASH_LEN) != EOK) {
if (strcpy_s(connInfo->connInfo.bleDirect.networkId, NETWORK_ID_BUF_LEN,
linkInfo->linkInfo.bleDirect.networkId) != EOK) {
return SOFTBUS_ERR;
}
connInfo->type = LANE_BLE_DIRECT;

View File

@ -92,8 +92,7 @@ static bool FindLaneResource(const LaneResource *resourceItem, LaneResource *ite
break;
case LANE_BLE_DIRECT:
case LANE_COC_DIRECT:
if (memcmp(resourceItem->linkInfo.bleDirect.peerUdidHash,
item->linkInfo.bleDirect.peerUdidHash, SHA_256_HASH_LEN) != 0) {
if (strcmp(resourceItem->linkInfo.bleDirect.networkId, item->linkInfo.bleDirect.networkId) != 0) {
return false;
}
break;
@ -664,52 +663,15 @@ static int32_t LaneLinkOfBle(uint32_t reqId, const LinkRequest *reqInfo, const L
return SOFTBUS_OK;
}
static int32_t LaneLinkOfBleDirectCommon(const LinkRequest *reqInfo, LaneLinkInfo *linkInfo)
{
unsigned char peerUdid[UDID_BUF_LEN] = {0};
unsigned char peerNetwordIdHash[SHA_256_HASH_LEN] = {0};
unsigned char localUdidHash[SHA_256_HASH_LEN] = {0};
if (SoftBusGenerateStrHash((const unsigned char*)reqInfo->peerNetworkId, strlen(reqInfo->peerNetworkId),
peerNetwordIdHash) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
const NodeInfo* nodeInfo = LnnGetLocalNodeInfo();
if (SoftBusGenerateStrHash((const unsigned char*)nodeInfo->deviceInfo.deviceUdid,
strlen(nodeInfo->deviceInfo.deviceUdid), localUdidHash) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
if (LnnGetRemoteStrInfo(reqInfo->peerNetworkId, STRING_KEY_DEV_UDID,
(char *)peerUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
if (SoftBusGenerateStrHash(peerUdid, strlen((char*)peerUdid),
(unsigned char *)linkInfo->linkInfo.bleDirect.peerUdidHash) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
if (memcpy_s(linkInfo->linkInfo.bleDirect.nodeIdHash, NODEID_SHORT_HASH_LEN, peerNetwordIdHash,
NODEID_SHORT_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
}
if (memcpy_s(linkInfo->linkInfo.bleDirect.localUdidHash, UDID_SHORT_HASH_LEN, localUdidHash, UDID_SHORT_HASH_LEN) !=
EOK) {
return SOFTBUS_ERR;
}
linkInfo->type = LANE_BLE_DIRECT;
return SOFTBUS_OK;
}
static int32_t LaneLinkOfGattDirect(uint32_t reqId, const LinkRequest *reqInfo, const LaneLinkCb *callback)
{
LaneLinkInfo linkInfo;
(void)memset_s(&linkInfo, sizeof(LaneLinkInfo), 0, sizeof(LaneLinkInfo));
if (LaneLinkOfBleDirectCommon(reqInfo, &linkInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "ble direct common failed");
return SOFTBUS_ERR;
if (strcpy_s(linkInfo.linkInfo.bleDirect.networkId, NETWORK_ID_BUF_LEN, reqInfo->peerNetworkId) != EOK) {
LNN_LOGE(LNN_LANE, "copy networkId fail");
return SOFTBUS_MEM_ERR;
}
linkInfo.type = LANE_BLE_DIRECT;
linkInfo.linkInfo.bleDirect.protoType = BLE_GATT;
callback->OnLaneLinkSuccess(reqId, &linkInfo);
return SOFTBUS_OK;
@ -925,9 +887,9 @@ static int32_t LaneLinkOfCocDirect(uint32_t reqId, const LinkRequest *reqInfo, c
{
LaneLinkInfo linkInfo;
(void)memset_s(&linkInfo, sizeof(LaneLinkInfo), 0, sizeof(LaneLinkInfo));
if (LaneLinkOfBleDirectCommon(reqInfo, &linkInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "ble direct common failed");
return SOFTBUS_ERR;
if (strcpy_s(linkInfo.linkInfo.bleDirect.networkId, NETWORK_ID_BUF_LEN, reqInfo->peerNetworkId) != EOK) {
LNN_LOGE(LNN_LANE, "copy networkId fail");
return SOFTBUS_MEM_ERR;
}
linkInfo.type = LANE_COC_DIRECT;
linkInfo.linkInfo.bleDirect.protoType = BLE_COC;

View File

@ -28,18 +28,22 @@ typedef enum {
CONN_COMMON,
CONN_WIFI_DIRECT,
CONN_NEARBY,
CONN_BLE_DIRECT,
CONN_BROADCAST,
CONN_TEST,
} ConnLogLabelEnum;
/* Keep consistent with labels 0xd005760 - 0xd00577f*/
static const SoftBusLogLabel CONN_LABELS[MODULE_DOMAIN_MAX_LEN] = {
{CONN_INIT, 0xd005760, "ConnInit" },
{ CONN_BLE, 0xd005761, "ConnBle" },
{ CONN_BR, 0xd005762, "ConnBr" },
{ CONN_COMMON, 0xd005763, "ConnCommon"},
{ CONN_WIFI_DIRECT, 0xd005764, "ConnWD" },
{ CONN_NEARBY, 0xd005765, "ConnNearby"},
{ CONN_TEST, DOMAIN_ID_TEST, "ConnTest" },
{CONN_INIT, 0xd005760, "ConnInit"},
{CONN_BLE, 0xd005761, "ConnBle"},
{CONN_BR, 0xd005762, "ConnBr"},
{CONN_COMMON, 0xd005763, "ConnCommon"},
{CONN_WIFI_DIRECT, 0xd005764, "ConnWD"},
{CONN_NEARBY, 0xd005765, "ConnNearby"},
{CONN_BLE_DIRECT, 0xd005766, "ConnBD"},
{CONN_BROADCAST, 0xd005767, "ConnBC"},
{CONN_TEST, DOMAIN_ID_TEST, "ConnTest"},
};
#define CONN_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_FATAL, CONN_LABELS[label], ##__VA_ARGS__)
@ -52,10 +56,19 @@ static const SoftBusLogLabel CONN_LABELS[MODULE_DOMAIN_MAX_LEN] = {
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGW, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGE, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_RET_LOGI(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGI, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_RET_LOGD(cond, ret, label, fmt, ...) \
CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, CONN_LOGD, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, CONN_LOGW, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, CONN_LOGE, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_LOGI(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, CONN_LOGI, label, fmt, ##__VA_ARGS__)
#define CONN_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \
CHECK_AND_RETURN_LOG_INNER(cond, CONN_LOGD, label, fmt, ##__VA_ARGS__)
#ifdef __cplusplus
}

View File

@ -15,7 +15,7 @@ import("../../../adapter/common/net/bluetooth/net_bluetooth.gni")
import("../../../dsoftbus.gni")
native_source_path = rebase_path("$dsoftbus_root_path")
conn_ble_dir = "dsoftbus_enhance/core/connection/ble/src"
conn_ble_dir = "dsoftbus_enhance/core/connection/ble_direct"
enhanced_conn_ble = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$native_source_path",
@ -73,9 +73,11 @@ if (!support_bluetooth) {
"$dsoftbus_root_path/core/common/include",
]
if (enhanced_conn_ble == true) {
ble_connection_src += [ "$dsoftbus_root_path/dsoftbus_enhance/core/connection/ble/src/softbus_conn_ble_direct_conn.c" ]
ble_connection_inc +=
[ "$dsoftbus_root_path/dsoftbus_enhance/core/connection/ble/include" ]
import(
"../../../dsoftbus_enhance/core/connection/ble_direct/ble_direct.gni")
ble_connection_src += ble_direct_connection_src
ble_connection_inc += ble_direct_connection_inc
} else {
ble_connection_src += [ "$dsoftbus_root_path/core/connection/ble/src/softbus_conn_ble_direct_virtual.c" ]
}

View File

@ -185,7 +185,7 @@ int32_t ConnBleStartServer(void);
int32_t ConnBleStopServer(void);
int32_t ConnBleConnect(ConnBleConnection *connection);
int32_t ConnBleDisconnectNow(ConnBleConnection *connection, enum ConnBleDisconnectReason reason);
int32_t ConnBleUpdateConnectionRc(ConnBleConnection *connection, int32_t delta);
int32_t ConnBleUpdateConnectionRc(ConnBleConnection *connection, uint16_t challengeCode, int32_t delta);
int32_t ConnBleOnReferenceRequest(ConnBleConnection *connection, const cJSON *json);
int32_t ConnBleUpdateConnectionPriority(ConnBleConnection *connection, ConnectBlePriority priority);
int32_t ConnBleSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module);

View File

@ -16,6 +16,15 @@
#ifndef SOFTBUS_CONN_BLE_DIRECT_H
#define SOFTBUS_CONN_BLE_DIRECT_H
int32_t ConnBleDirectInit();
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
int32_t ConnBleDirectInit(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -56,6 +56,7 @@ typedef struct {
// SHOULD diff requests by protocol type
BleProtocolType protocol;
uint32_t requestId;
uint16_t challengeCode; /* for ble direct */
ConnectResult result;
ConnectStatistics statistics;
} ConnBleRequest;
@ -67,6 +68,7 @@ typedef struct {
char udid[UDID_BUF_LEN];
bool fastestConnectEnable;
int32_t psm;
uint16_t challengeCode; /* for ble direct */
ConnectResult result;
ConnectStatistics statistics;
} ConnBleConnectRequestContext;
@ -121,7 +123,7 @@ ConnBleConnection *ConnBleGetConnectionByUdid(const char *addr, const char *udid
// get connection with same udid and client side
ConnBleConnection *ConnBleGetClientConnectionByUdid(const char *udid, BleProtocolType protocol);
void ConnBleReturnConnection(ConnBleConnection **connection);
void NotifyReusedConnected(uint32_t connectionId);
void NotifyReusedConnected(uint32_t connectionId, uint16_t challengeCode);
ConnectFuncInterface *ConnInitBle(const ConnectCallback *callback);

View File

@ -29,6 +29,7 @@ extern "C" {
#define CTRL_MSG_KEY_METHOD "KEY_METHOD"
#define CTRL_MSG_KEY_DELTA "KEY_DELTA"
#define CTRL_MSG_KEY_REF_NUM "KEY_REF_NUM"
#define CTRL_MSG_KEY_CHALLENGE "KEY_CHALLENGE"
#define CTRL_MSG_METHOD_NOTIFY_REQUEST 1
typedef struct {
@ -65,6 +66,7 @@ typedef struct {
int32_t referenceNumber;
} referenceRequest;
};
uint16_t challengeCode;
} BleCtlMessageSerializationContext;
typedef struct {

View File

@ -325,7 +325,7 @@ static void OnDisconnectedDataFinished(uint32_t connectionId, int32_t error)
}
int32_t ConnBleUpdateConnectionRc(ConnBleConnection *connection, int32_t delta)
int32_t ConnBleUpdateConnectionRc(ConnBleConnection *connection, uint16_t challengeCode, int32_t delta)
{
int32_t status = SoftBusMutexLock(&connection->lock);
if (status != SOFTBUS_OK) {
@ -339,8 +339,9 @@ int32_t ConnBleUpdateConnectionRc(ConnBleConnection *connection, int32_t delta)
connection->state = BLE_CONNECTION_STATE_NEGOTIATION_CLOSING;
}
(void)SoftBusMutexUnlock(&connection->lock);
CONN_LOGI(CONN_BLE, "ble notify refrence, connId=%u, handle=%d, side=%d, delta=%d, after update, localRc=%d,",
connection->connectionId, underlayerHandle, connection->side, delta, localRc);
CONN_LOGI(CONN_BLE, "ble notify refrence, connId=%u, handle=%d, side=%d, delta=%d, challenge=%u, "
"after update, localRc=%d,",
connection->connectionId, underlayerHandle, connection->side, delta, challengeCode, localRc);
if (localRc <= 0) {
if ((featureBitSet & (1 << BLE_FEATURE_SUPPORT_REMOTE_DISCONNECT)) == 0) {
@ -362,6 +363,7 @@ int32_t ConnBleUpdateConnectionRc(ConnBleConnection *connection, int32_t delta)
.delta = delta,
.referenceNumber = localRc,
},
.challengeCode = challengeCode,
};
uint8_t *data = NULL;
uint32_t dataLen = 0;
@ -384,12 +386,16 @@ int32_t ConnBleOnReferenceRequest(ConnBleConnection *connection, const cJSON *js
{
int32_t delta = 0;
int32_t peerRc = 0;
uint16_t challengeCode = 0;
if (!GetJsonObjectSignedNumberItem(json, CTRL_MSG_KEY_DELTA, &delta) ||
!GetJsonObjectSignedNumberItem(json, CTRL_MSG_KEY_REF_NUM, &peerRc)) {
CONN_LOGE(CONN_BLE, "connId=%u, parse delta or reference number fields failed, delta=%d, peer reference "
"count=%d", connection->connectionId, delta, peerRc);
return SOFTBUS_PARSE_JSON_ERR;
}
if (!GetJsonObjectNumber16Item(json, CTRL_MSG_KEY_CHALLENGE, &challengeCode)) {
CONN_LOGW(CONN_BLE, "connId=%u, old version NOT have KEY_CHALLENGE field", connection->connectionId);
}
int32_t status = SoftBusMutexLock(&connection->lock);
if (status != SOFTBUS_OK) {
@ -399,8 +405,8 @@ int32_t ConnBleOnReferenceRequest(ConnBleConnection *connection, const cJSON *js
connection->connectionRc += delta;
int32_t localRc = connection->connectionRc;
CONN_LOGI(CONN_BLE, "ble received reference request, connId=%u, delta=%d, peerRef=%d, localRc=%d",
connection->connectionId, delta, peerRc, localRc);
CONN_LOGI(CONN_BLE, "ble received reference request, connId=%u, delta=%d, peerRef=%d, localRc=%d, challenge=%u",
connection->connectionId, delta, peerRc, localRc, challengeCode);
if (peerRc > 0) {
if (connection->state == BLE_CONNECTION_STATE_NEGOTIATION_CLOSING) {
ConnRemoveMsgFromLooper(&g_bleConnectionAsyncHandler, MSG_CONNECTION_WAIT_NEGOTIATION_CLOSING_TIMEOUT,
@ -409,7 +415,7 @@ int32_t ConnBleOnReferenceRequest(ConnBleConnection *connection, const cJSON *js
g_connectionListener.onConnectionResume(connection->connectionId);
}
(void)SoftBusMutexUnlock(&connection->lock);
NotifyReusedConnected(connection->connectionId);
NotifyReusedConnected(connection->connectionId, challengeCode);
return SOFTBUS_OK;
}
if (localRc <= 0) {
@ -429,6 +435,7 @@ int32_t ConnBleOnReferenceRequest(ConnBleConnection *connection, const cJSON *js
.referenceNumber = localRc,
.delta = 0,
},
.challengeCode = challengeCode,
};
uint8_t *data = NULL;
uint32_t dataLen = 0;

View File

@ -29,7 +29,7 @@ bool ConnBleDirectIsEnable(BleProtocolType protocol)
return false;
}
int32_t ConnBleDirectInit()
int32_t ConnBleDirectInit(void)
{
return SOFTBUS_OK;
}

View File

@ -218,6 +218,7 @@ static int32_t NewRequest(ConnBleRequest **outRequest, const ConnBleConnectReque
}
ListInit(&request->node);
request->requestId = ctx->requestId;
request->challengeCode = ctx->challengeCode;
request->result = ctx->result;
request->protocol = ctx->protocol;
@ -329,11 +330,12 @@ static void BleNotifyDeviceConnectResult(const ConnBleDevice *device, ConnBleCon
CONN_LOGE(CONN_BLE, "convert ble connection info failed, err=%d. It cann't backoff now, just ahead.", status);
}
LIST_FOR_EACH_ENTRY(it, &device->requests, ConnBleRequest, node) {
ConnBleUpdateConnectionRc(connection, 1);
CONN_LOGI(CONN_BLE, "ble notify connect request %u success, addr=%s, connId=%u, protocol=%d", it->requestId,
anomizeAddress, connection->connectionId, device->protocol);
ConnBleUpdateConnectionRc(connection, it->challengeCode, 1);
CONN_LOGI(CONN_BLE, "ble notify connect request %u success, addr=%s, connId=%u, protocol=%d, challenge=%u",
it->requestId, anomizeAddress, connection->connectionId, device->protocol, it->challengeCode);
it->statistics.reqId = it->requestId;
DfxRecordBleConnectSuccess(DEFAULT_PID, connection, &it->statistics);
info.bleInfo.challengeCode = it->challengeCode;
it->result.OnConnectSuccessed(it->requestId, connection->connectionId, &info);
}
}
@ -613,7 +615,7 @@ static void BleClientConnected(uint32_t connectionId)
if (connectingDevice == NULL || StrCmpIgnoreCase(connectingDevice->addr, connection->addr) != 0) {
CONN_LOGE(CONN_BLE, "there is no connecting device, is it connected after timeout? connId=%u, addr=%d",
connectionId, anomizeAddress);
ConnBleUpdateConnectionRc(connection, -1);
ConnBleUpdateConnectionRc(connection, 0, -1);
ConnBleReturnConnection(&connection);
return;
}
@ -832,7 +834,7 @@ static void BleDisconnectRequest(uint32_t connectionId)
{
ConnBleConnection *connection = ConnBleGetConnectionById(connectionId);
CONN_CHECK_AND_RETURN_LOGW(connection != NULL, CONN_BLE, "connection is not exist, connId=%u", connectionId);
ConnBleUpdateConnectionRc(connection, -1);
ConnBleUpdateConnectionRc(connection, 0, -1);
ConnBleReturnConnection(&connection);
}
@ -922,7 +924,7 @@ static int32_t BleReuseConnectionCommon(const char *udid, const char *anomizeAdd
(void)SoftBusMutexUnlock(&connection->lock);
int32_t status = SOFTBUS_CONN_BLE_CONNECTION_NOT_READY_ERR;
if (state == BLE_CONNECTION_STATE_EXCHANGED_BASIC_INFO) {
status = ConnBleUpdateConnectionRc(connection, 1);
status = ConnBleUpdateConnectionRc(connection, 0, 1); /* no need challenge, set default value 0 */
}
CONN_LOGI(CONN_BLE, "reuse connection, connId=%u, state=%d, addr=%s, status=%d", connection->connectionId, state,
anomizeAddress, status);
@ -1289,7 +1291,7 @@ void ConnBleReturnConnection(ConnBleConnection **connection)
*connection = NULL;
}
void NotifyReusedConnected(uint32_t connectionId)
void NotifyReusedConnected(uint32_t connectionId, uint16_t challengeCode)
{
ConnBleConnection *connection = ConnBleGetConnectionById(connectionId);
CONN_CHECK_AND_RETURN_LOGW(connection != NULL, CONN_BLE, "connection not exist, connId=%u", connectionId);
@ -1299,6 +1301,7 @@ void NotifyReusedConnected(uint32_t connectionId)
if (status != SOFTBUS_OK) {
CONN_LOGE(CONN_BLE, "convert connection info failed, err=%d. It can not backoff now, just ahead.", status);
}
info.bleInfo.challengeCode = challengeCode;
g_connectCallback.OnReusedConnected(connectionId, &info);
}
@ -1548,6 +1551,7 @@ static int32_t BleConnectDevice(const ConnectOption *option, uint32_t requestId,
ctx->protocol = option->bleOption.protocol;
ctx->psm = option->bleOption.psm;
}
ctx->challengeCode = option->bleOption.challengeCode;
status = ConnPostMsgToLooper(&g_bleManagerSyncHandler, BLE_MGR_MSG_CONNECT_REQUEST, 0, 0, ctx, 0);
if (status != SOFTBUS_OK) {
CONN_LOGE(CONN_BLE, "post connect msg to manager looper failed, reqId=%u, addr=%s, udid=%s, err=%d",

View File

@ -372,7 +372,8 @@ static int32_t BleCtrlMsgSerializeByJson(BleCtlMessageSerializationContext ctx,
if (ctx.method == METHOD_NOTIFY_REQUEST) {
if (!AddNumberToJsonObject(json, CTRL_MSG_KEY_METHOD, CTRL_MSG_METHOD_NOTIFY_REQUEST) ||
!AddNumberToJsonObject(json, CTRL_MSG_KEY_DELTA, ctx.referenceRequest.delta) ||
!AddNumberToJsonObject(json, CTRL_MSG_KEY_REF_NUM, ctx.referenceRequest.referenceNumber)) {
!AddNumberToJsonObject(json, CTRL_MSG_KEY_REF_NUM, ctx.referenceRequest.referenceNumber) ||
!AddNumber16ToJsonObject(json, CTRL_MSG_KEY_CHALLENGE, ctx.challengeCode)) {
cJSON_Delete(json);
return SOFTBUS_CREATE_JSON_ERR;
}

View File

@ -92,6 +92,7 @@ struct BleInfo {
char deviceIdHash[UDID_HASH_LEN];
BleProtocolType protocol;
uint32_t psm;
uint16_t challengeCode;
};
struct ConnSocketInfo {
char addr[IP_LEN];
@ -157,14 +158,12 @@ struct BleOption {
char deviceIdHash[UDID_HASH_LEN];
bool fastestConnectEnable;
int32_t psm;
uint16_t challengeCode;
};
struct BleDirectOption {
BleProtocolType protoType;
int32_t psm;
char nodeIdHash[NODEID_SHORT_HASH_LEN];
char localUdidHash[UDID_SHORT_HASH_LEN];
char peerUdidHash[SHA_256_HASH_LEN];
char networkId[NETWORK_ID_BUF_LEN];
};
struct SocketOption {

View File

@ -373,7 +373,7 @@ static void RecordStartTime(const ConnectOption *info)
return;
}
conInfo.bleInfo.protocol = info->bleOption.protocol;
conInfo.bleInfo.psm = info->bleDirectOption.psm;
conInfo.bleInfo.psm = info->bleOption.psm;
break;
case CONNECT_TCP:
if (memcpy_s(&conInfo.socketInfo.addr, MAX_SOCKET_ADDR_LEN, info->socketOption.addr, MAX_SOCKET_ADDR_LEN) !=

View File

@ -581,21 +581,12 @@ static int32_t SetBleConnInfo(const BleConnInfo *bleInfo, ConnectOption *connOpt
return SOFTBUS_OK;
}
static int32_t SetBleDirectConnInfo(const BleDirectConnInfo* bleDirect, ConnectOption *connOpt)
static int32_t SetBleDirectConnInfo(const BleDirectConnInfo *bleDirect, ConnectOption *connOpt)
{
if (memcpy_s(connOpt->bleDirectOption.nodeIdHash, NODEID_SHORT_HASH_LEN,
bleDirect->nodeIdHash, NODEID_SHORT_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
if (strcpy_s(connOpt->bleDirectOption.networkId, NETWORK_ID_BUF_LEN, bleDirect->networkId) != EOK) {
TRANS_LOGW(TRANS_SVC, "set networkId err.");
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(connOpt->bleDirectOption.localUdidHash, UDID_SHORT_HASH_LEN,
bleDirect->localUdidHash, UDID_SHORT_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
}
if (memcpy_s(connOpt->bleDirectOption.peerUdidHash, SHA_256_HASH_LEN,
bleDirect->peerUdidHash, SHA_256_HASH_LEN) != EOK) {
return SOFTBUS_ERR;
}
connOpt->type = CONNECT_BLE_DIRECT;
connOpt->bleDirectOption.protoType = bleDirect->protoType;
return SOFTBUS_OK;

View File

@ -393,7 +393,7 @@ static bool CompareConnectOption(const ConnectOption *itemConnInfo, const Connec
}
return false;
} else if (connInfo->type == CONNECT_BLE_DIRECT) {
if ((strcmp(connInfo->bleDirectOption.nodeIdHash, itemConnInfo->bleDirectOption.nodeIdHash) == 0) &&
if ((strcmp(connInfo->bleDirectOption.networkId, itemConnInfo->bleDirectOption.networkId) == 0) &&
(connInfo->bleDirectOption.protoType == itemConnInfo->bleDirectOption.protoType)) {
return true;
}

View File

@ -350,6 +350,9 @@ enum SoftBusErrNo {
SOFTBUS_CONN_BLE_COC_UNDERLAY_SOCKET_CLOSED,
SOFTBUS_CONN_BLE_COC_UNDERLAY_READ_FAIL,
SOFTBUS_CONN_LINK_BROADCAST_START_ADV_FAIL,
SOFTBUS_CONN_LINK_BROADCAST_QUERY_RPA_FAIL,
SOFTBUS_BLECONNECTION_REG_GATTS_CALLBACK_FAIL,
SOFTBUS_GATTC_INTERFACE_FAILED,