diff --git a/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c b/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c index 45d1568bf..302a3fc87 100644 --- a/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c +++ b/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt_server.c @@ -150,9 +150,20 @@ int SoftBusGattsDeleteService(int srvcHandle) return SOFTBUS_OK; } -int SoftBusGattsConnect(int connId) +int SoftBusGattsConnect(SoftBusBtAddr btAddr) { - CLOGD("SoftBusGattsConnect stub is called, return success"); + if (CheckGattsStatus() != SOFTBUS_OK) { + return SOFTBUS_ERR; + } + BdAddr addr; + if (memcpy_s(addr.addr, BT_ADDR_LEN, btAddr.addr, BT_ADDR_LEN) != EOK) { + CLOGE("memcpy fail"); + return SOFTBUS_ERR; + } + CLOGI("BleGattsConnect start"); + if (BleGattsConnect(g_halServerId, addr) != SOFTBUS_OK) { + return SOFTBUS_ERR; + } return SOFTBUS_OK; } @@ -163,9 +174,10 @@ int SoftBusGattsDisconnect(SoftBusBtAddr btAddr, int connId) } BdAddr addr; if (memcpy_s(addr.addr, BT_ADDR_LEN, btAddr.addr, BT_ADDR_LEN) != EOK) { - CLOGE("SoftBusGattsDisconnect memcpy fail"); + CLOGE("memcpy fail"); return SOFTBUS_ERR; } + CLOGI("BleGattsDisconnect start"); if (BleGattsDisconnect(g_halServerId, addr, connId) != SOFTBUS_OK) { return SOFTBUS_ERR; } diff --git a/adapter/common/net/bluetooth/include/softbus_adapter_ble_gatt_server.h b/adapter/common/net/bluetooth/include/softbus_adapter_ble_gatt_server.h index 602d3e2c3..06148bc80 100644 --- a/adapter/common/net/bluetooth/include/softbus_adapter_ble_gatt_server.h +++ b/adapter/common/net/bluetooth/include/softbus_adapter_ble_gatt_server.h @@ -135,7 +135,7 @@ int SoftBusGattsAddDescriptor(int srvcHandle, SoftBusBtUuid descUuid, int permis int SoftBusGattsStartService(int srvcHandle); int SoftBusGattsStopService(int srvcHandle); int SoftBusGattsDeleteService(int srvcHandle); -int SoftBusGattsConnect(int connId); +int SoftBusGattsConnect(SoftBusBtAddr btAddr); int SoftBusGattsDisconnect(SoftBusBtAddr btAddr, int connId); int SoftBusGattsSendResponse(SoftBusGattsResponse *param); int SoftBusGattsSendNotify(SoftBusGattsNotify *param); diff --git a/core/connection/ble/src/softbus_conn_ble_manager.c b/core/connection/ble/src/softbus_conn_ble_manager.c index efbe8359c..2a630c3ea 100644 --- a/core/connection/ble/src/softbus_conn_ble_manager.c +++ b/core/connection/ble/src/softbus_conn_ble_manager.c @@ -721,13 +721,21 @@ static void BleServerAccepted(uint32_t connectionId) char anomizeAddress[BT_MAC_LEN] = { 0 }; ConvertAnonymizeMacAddress(anomizeAddress, BT_MAC_LEN, connection->addr, BT_MAC_LEN); - CLOGI("ble server accept a new connection, connId=%u, peer addr=%s", connectionId, anomizeAddress); ConnectionInfo info = { 0 }; int32_t status = BleConvert2ConnectionInfo(connection, &info); if (status != SOFTBUS_OK) { CLOGE("convert connection info failed, err=%d. It can not backoff now, just ahead.", status); } + char udidHashStr[HEXIFY_LEN(SHORT_UDID_HASH_LEN)] = { 0 }; + status = ConvertBytesToHexString(udidHashStr, HEXIFY_LEN(SHORT_UDID_HASH_LEN), + (unsigned char *)info.bleInfo.deviceIdHash, SHORT_UDID_HASH_LEN); + if (status != SOFTBUS_OK) { + CLOGE("convert peerUdidHash to string failed, connectionId=%u, err=%d.", connectionId, status); + } + char anomizeUdid[UDID_BUF_LEN] = { 0 }; + ConvertAnonymizeSensitiveString(anomizeUdid, UDID_BUF_LEN, udidHashStr); + CLOGI("ble server accept a new connection, connId=%u, peer addr=%s, peer udid=%s", connectionId, anomizeAddress, anomizeUdid); g_connectCallback.OnConnected(connectionId, &info); ConnBleDevice *connectingDevice = g_bleManager.connecting; @@ -924,6 +932,7 @@ static void ConflictOnConnectSuccessed(uint32_t requestId, uint32_t connectionId (void)connectionId; (void)info; ConnBleConnection *connection = ConnBleGetConnectionById(connectionId); + CONN_CHECK_AND_RETURN_LOG(connection != NULL, "conn not exist, connId=%u", connectionId); int32_t underlayHandle = connection->underlayerHandle; ConnBleReturnConnection(&connection); SoftbusBleConflictNotifyConnectResult(requestId, underlayHandle, true); diff --git a/core/connection/ble/src/softbus_conn_ble_server.c b/core/connection/ble/src/softbus_conn_ble_server.c index 1745c733e..accc95d32 100644 --- a/core/connection/ble/src/softbus_conn_ble_server.c +++ b/core/connection/ble/src/softbus_conn_ble_server.c @@ -896,7 +896,14 @@ int32_t ConnGattServerConnect(ConnBleConnection *connection) CLOGE("ble server connection %u connect failed, underlay handle is invalid", connection->connectionId); return SOFTBUS_ERR; } - status = SoftBusGattsConnect(underlayerHandle); + SoftBusBtAddr binaryAddr = { 0 }; + status = ConvertBtMacToBinary(connection->addr, BT_MAC_LEN, binaryAddr.addr, BT_ADDR_LEN); + if (status != SOFTBUS_OK) { + CLOGE("ble server connection %u connect failed: convert string mac to binary fail, err=%d", + connection->connectionId, status); + return status; + } + status = SoftBusGattsConnect(binaryAddr); CLOGI("ble server connection %u connect, underlayer handle=%d, status=%d", connection->connectionId, underlayerHandle, status); return status; diff --git a/core/connection/ble/src/softbus_conn_ble_trans.c b/core/connection/ble/src/softbus_conn_ble_trans.c index 45ac380f0..b1546a63b 100644 --- a/core/connection/ble/src/softbus_conn_ble_trans.c +++ b/core/connection/ble/src/softbus_conn_ble_trans.c @@ -159,6 +159,7 @@ uint8_t *ConnGattTransRecv( DiscardBuffer(buffer, false); SoftBusFree(packet); SoftBusFree(copyData); + return NULL; } ListInit(&packet->node); packet->header = header;