Increase the demand for active disconnection of short distance servers

Signed-off-by: huobaobao <huobaobao@huawei.com>
This commit is contained in:
huobaobao 2023-10-23 19:40:10 +08:00
parent 3e91a8c8ec
commit a168d9ad8f
5 changed files with 35 additions and 6 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -159,6 +159,7 @@ uint8_t *ConnGattTransRecv(
DiscardBuffer(buffer, false);
SoftBusFree(packet);
SoftBusFree(copyData);
return NULL;
}
ListInit(&packet->node);
packet->header = header;