Merge branch 'master' of gitee.com:openharmony/communication_dsoftbus into master

Signed-off-by: guowen <guowen31@huawei.com>
This commit is contained in:
guowen 2023-11-27 13:06:48 +00:00 committed by Gitee
commit ff5b12aa94
33 changed files with 796 additions and 220 deletions

View File

@ -18,7 +18,7 @@
#include <stdbool.h>
#include "adapter_bt_utils.h"
#include "disc_log.h"
#include "conn_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_type_def.h"
@ -34,9 +34,9 @@ static SoftBusGattcCallback *g_softBusGattcCallback = NULL;
static void GattcConnectionStateChangedCallback(int clientId, int connectionState, int status)
{
DISC_LOGI(DISC_BLE, "StateChangedCallback id=%d, state=%d, status=%d", clientId, connectionState, status);
CONN_LOGI(CONN_BLE, "StateChangedCallback id=%d, state=%d, status=%d", clientId, connectionState, status);
if (connectionState != OHOS_STATE_CONNECTED && connectionState != OHOS_STATE_DISCONNECTED) {
DISC_LOGI(DISC_BLE, "GattcConnectionStateChangedCallback ignore");
CONN_LOGI(CONN_BLE, "GattcConnectionStateChangedCallback ignore");
return;
}
@ -46,51 +46,51 @@ static void GattcConnectionStateChangedCallback(int clientId, int connectionStat
static void GattcConnectParaUpdateCallback(int clientId, int interval, int latency, int timeout, int status)
{
DISC_LOGI(DISC_BLE, "ParaUpdateCallback");
CONN_LOGI(CONN_BLE, "ParaUpdateCallback");
}
static void GattcSearchServiceCompleteCallback(int clientId, int status)
{
DISC_LOGI(DISC_BLE, "SearchServiceCompleteCallback, id=%d, status=%d", clientId, status);
CONN_LOGI(CONN_BLE, "SearchServiceCompleteCallback, id=%d, status=%d", clientId, status);
g_softBusGattcCallback->ServiceCompleteCallback(clientId, status);
}
static void GattcReadCharacteristicCallback(int clientId, BtGattReadData *readData, int status)
{
DISC_LOGI(DISC_BLE, "ReadCharacteristicCallback, id=%d, status=%d", clientId, status);
CONN_LOGI(CONN_BLE, "ReadCharacteristicCallback, id=%d, status=%d", clientId, status);
}
static void GattcWriteCharacteristicCallback(int clientId, BtGattCharacteristic *characteristic, int status)
{
DISC_LOGI(DISC_BLE, "WriteCharacteristicCallback, id=%d, status=%d", clientId, status);
CONN_LOGI(CONN_BLE, "WriteCharacteristicCallback, id=%d, status=%d", clientId, status);
}
static void GattcReadDescriptorCallback(int clientId, BtGattReadData *readData, int status)
{
DISC_LOGI(DISC_BLE, "ReadDescriptorCallback, id=%d, status=%d", clientId, status);
CONN_LOGI(CONN_BLE, "ReadDescriptorCallback, id=%d, status=%d", clientId, status);
}
static void GattcWriteDescriptorCallback(int clientId, BtGattDescriptor *descriptor, int status)
{
DISC_LOGI(DISC_BLE, "WriteDescriptorCallback, id=%d, status=%d", clientId, status);
CONN_LOGI(CONN_BLE, "WriteDescriptorCallback, id=%d, status=%d", clientId, status);
}
static void GattcConfigureMtuSizeCallback(int clientId, int mtuSize, int status)
{
DISC_LOGI(DISC_BLE, "ConfigureMtuSizeCallback, id=%d, mtusize=%d, status=%d", clientId, mtuSize, status);
CONN_LOGI(CONN_BLE, "ConfigureMtuSizeCallback, id=%d, mtusize=%d, status=%d", clientId, mtuSize, status);
g_softBusGattcCallback->ConfigureMtuSizeCallback(clientId, mtuSize, status);
}
static void GattcRegisterNotificationCallback(int clientId, int status)
{
DISC_LOGI(DISC_BLE, "RegisterNotificationCallback, id=%d, status=%d", clientId, status);
CONN_LOGI(CONN_BLE, "RegisterNotificationCallback, id=%d, status=%d", clientId, status);
g_softBusGattcCallback->RegistNotificationCallback(clientId, status);
}
static void GattcNotificationCallback(int clientId, BtGattReadData *notifyData, int status)
{
DISC_LOGI(DISC_BLE, "GattcNotificationCallback, id=%d, status=%d", clientId, status);
CONN_LOGI(CONN_BLE, "GattcNotificationCallback, id=%d, status=%d", clientId, status);
if (notifyData == NULL) {
return;
}
@ -100,7 +100,7 @@ static void GattcNotificationCallback(int clientId, BtGattReadData *notifyData,
notify.data = notifyData->data;
notify.charaUuid.uuid = notifyData->attribute.characteristic.characteristicUuid.uuid;
DISC_LOGI(DISC_BLE, "GattcNotificationCallback, id=%d, status=%d", clientId, status);
CONN_LOGI(CONN_BLE, "GattcNotificationCallback, id=%d, status=%d", clientId, status);
g_softBusGattcCallback->NotificationReceiveCallback(clientId, &notify, status);
}
@ -126,17 +126,17 @@ int32_t SoftbusGattcRegister(void)
appId.uuidLen = APP_UUID_LEN;
int32_t clientId = BleGattcRegister(appId);
if (clientId <= 0) {
DISC_LOGE(DISC_BLE, "BleGattcRegister error");
CONN_LOGE(CONN_BLE, "BleGattcRegister error");
return INVALID_ID;
}
DISC_LOGI(DISC_BLE, "BleGattcRegister %d", clientId);
CONN_LOGI(CONN_BLE, "BleGattcRegister %d", clientId);
return clientId;
}
int32_t SoftbusGattcUnRegister(int32_t clientId)
{
if (BleGattcUnRegister(clientId) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "BleGattcUnRegister error");
CONN_LOGE(CONN_BLE, "BleGattcUnRegister error");
return SOFTBUS_GATTC_INTERFACE_FAILED;
}
return SOFTBUS_OK;
@ -146,13 +146,13 @@ int32_t SoftbusGattcConnect(int32_t clientId, SoftBusBtAddr *addr)
{
BdAddr bdAddr;
if (memcpy_s(bdAddr.addr, OHOS_BD_ADDR_LEN, addr->addr, BT_ADDR_LEN) != EOK) {
DISC_LOGE(DISC_BLE, "SoftbusGattcConnect memcpy error");
CONN_LOGE(CONN_BLE, "SoftbusGattcConnect memcpy error");
return SOFTBUS_INVALID_PARAM;
}
int32_t status = BleOhosStatusToSoftBus(
BleGattcConnect(clientId, &g_btGattClientCallbacks, &bdAddr, false, OHOS_BT_TRANSPORT_TYPE_LE));
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "BleGattcConnect error");
CONN_LOGE(CONN_BLE, "BleGattcConnect error");
return SOFTBUS_GATTC_INTERFACE_FAILED;
}
@ -163,7 +163,7 @@ int32_t SoftbusBleGattcDisconnect(int32_t clientId, bool refreshGatt)
{
(void)refreshGatt;
if (BleGattcDisconnect(clientId) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "BleGattcDisconnect error");
CONN_LOGE(CONN_BLE, "BleGattcDisconnect error");
return SOFTBUS_GATTC_INTERFACE_FAILED;
}
return SOFTBUS_OK;
@ -171,10 +171,10 @@ int32_t SoftbusBleGattcDisconnect(int32_t clientId, bool refreshGatt)
int32_t SoftbusGattcSearchServices(int32_t clientId)
{
DISC_LOGI(DISC_BLE, "SoftbusGattcSearchServices %d", clientId);
CONN_LOGI(CONN_BLE, "SoftbusGattcSearchServices %d", clientId);
int32_t status = BleOhosStatusToSoftBus(BleGattcSearchServices(clientId));
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "BleGattcSearchServices error, status = %d", status);
CONN_LOGE(CONN_BLE, "BleGattcSearchServices error, status = %d", status);
return SOFTBUS_GATTC_INTERFACE_FAILED;
}
return SOFTBUS_OK;
@ -182,21 +182,21 @@ int32_t SoftbusGattcSearchServices(int32_t clientId)
int32_t SoftbusGattcRefreshServices(int32_t clientId)
{
DISC_LOGI(DISC_BLE, "SoftbusGattcRefreshServices %d", clientId);
CONN_LOGI(CONN_BLE, "SoftbusGattcRefreshServices %d", clientId);
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t SoftbusGattcGetService(int32_t clientId, SoftBusBtUuid *serverUuid)
{
if (clientId <= 0) {
DISC_LOGE(DISC_BLE, "SoftbusGattcGetService invalid param");
CONN_LOGE(CONN_BLE, "SoftbusGattcGetService invalid param");
return SOFTBUS_INVALID_PARAM;
}
BtUuid btUuid;
btUuid.uuid = serverUuid->uuid;
btUuid.uuidLen = serverUuid->uuidLen;
if (!BleGattcGetService(clientId, btUuid)) {
DISC_LOGE(DISC_BLE, "BleGattcGetService error");
CONN_LOGE(CONN_BLE, "BleGattcGetService error");
return SOFTBUS_GATTC_INTERFACE_FAILED;
}
return SOFTBUS_OK;
@ -214,7 +214,7 @@ int32_t SoftbusGattcRegisterNotification(
btCharaUuid.characteristicUuid.uuidLen = charaUuid->uuidLen;
int32_t status = BleOhosStatusToSoftBus(BleGattcRegisterNotification(clientId, btCharaUuid, true));
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "BleGattcRegisterNotification error");
CONN_LOGE(CONN_BLE, "BleGattcRegisterNotification error");
return SOFTBUS_GATTC_INTERFACE_FAILED;
}
return SOFTBUS_OK;
@ -223,7 +223,7 @@ int32_t SoftbusGattcRegisterNotification(
int32_t SoftbusGattcConfigureMtuSize(int32_t clientId, int mtuSize)
{
if (BleGattcConfigureMtuSize(clientId, mtuSize) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "BleGattcConfigureMtuSize error");
CONN_LOGE(CONN_BLE, "BleGattcConfigureMtuSize error");
return SOFTBUS_GATTC_INTERFACE_FAILED;
}
return SOFTBUS_OK;
@ -232,10 +232,10 @@ int32_t SoftbusGattcConfigureMtuSize(int32_t clientId, int mtuSize)
int32_t SoftbusGattcWriteCharacteristic(int32_t clientId, SoftBusGattcData *clientData)
{
if (clientId <= 0 || clientData == NULL) {
DISC_LOGE(DISC_BLE, "SoftbusGattcWriteCharacteristic invalid param");
CONN_LOGE(CONN_BLE, "SoftbusGattcWriteCharacteristic invalid param");
return SOFTBUS_INVALID_PARAM;
}
DISC_LOGI(DISC_BLE, "SoftbusGattcRegisterNotification clientId = %d", clientId);
CONN_LOGI(CONN_BLE, "SoftbusGattcRegisterNotification clientId = %d", clientId);
BtGattCharacteristic characteristic;
characteristic.serviceUuid.uuid = clientData->serviceUuid.uuid;
characteristic.serviceUuid.uuidLen = clientData->serviceUuid.uuidLen;
@ -243,7 +243,7 @@ int32_t SoftbusGattcWriteCharacteristic(int32_t clientId, SoftBusGattcData *clie
characteristic.characteristicUuid.uuidLen = clientData->characterUuid.uuidLen;
if (BleGattcWriteCharacteristic(clientId, characteristic, OHOS_GATT_WRITE_NO_RSP, clientData->valueLen,
(const char *)clientData->value) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "SoftbusGattcWriteCharacteristic error");
CONN_LOGE(CONN_BLE, "SoftbusGattcWriteCharacteristic error");
return SOFTBUS_GATTC_INTERFACE_FAILED;
}
return SOFTBUS_OK;
@ -252,12 +252,12 @@ int32_t SoftbusGattcWriteCharacteristic(int32_t clientId, SoftBusGattcData *clie
int32_t SoftbusGattcSetFastestConn(int32_t clientId)
{
if (clientId <= 0) {
DISC_LOGE(DISC_BLE, "invalid param, '%d'", clientId);
CONN_LOGE(CONN_BLE, "invalid param, '%d'", clientId);
return SOFTBUS_INVALID_PARAM;
}
int ret = BleGattcSetFastestConn(clientId, true);
if (ret != OHOS_BT_STATUS_SUCCESS) {
DISC_LOGE(DISC_BLE, "BleGattcSetFastestConn failed, return code '%d'", ret);
CONN_LOGE(CONN_BLE, "BleGattcSetFastestConn failed, return code '%d'", ret);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
@ -266,17 +266,17 @@ int32_t SoftbusGattcSetFastestConn(int32_t clientId)
int32_t SoftbusGattcSetPriority(int32_t clientId, SoftBusBtAddr *addr, SoftbusBleGattPriority priority)
{
if (clientId <= 0 || addr == NULL) {
DISC_LOGE(DISC_BLE, "invalid param, '%d'", clientId);
CONN_LOGE(CONN_BLE, "invalid param, '%d'", clientId);
return SOFTBUS_INVALID_PARAM;
}
BdAddr bdAddr = { 0 };
if (memcpy_s(bdAddr.addr, OHOS_BD_ADDR_LEN, addr->addr, BT_ADDR_LEN) != EOK) {
DISC_LOGE(DISC_BLE, "addr memory copy failed");
CONN_LOGE(CONN_BLE, "addr memory copy failed");
return SOFTBUS_INVALID_PARAM;
}
int ret = BleGattcSetPriority(clientId, &bdAddr, (BtGattPriority)priority);
if (ret != OHOS_BT_STATUS_SUCCESS) {
DISC_LOGE(DISC_BLE, "BleGattcSetPriority failed, return code '%d'", ret);
CONN_LOGE(CONN_BLE, "BleGattcSetPriority failed, return code '%d'", ret);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;

View File

@ -14,8 +14,9 @@
*/
#include "softbus_adapter_ble_gatt_server.h"
#include "disc_log.h"
#include "securec.h"
#include "conn_log.h"
#include "softbus_adapter_timer.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
@ -43,7 +44,7 @@ int CheckGattsStatus(void)
return SOFTBUS_ERR;
}
while (g_halRegFlag == 0) {
DISC_LOGE(DISC_BLE, "ble hal registerring");
CONN_LOGE(CONN_BLE, "ble hal registerring");
static int tryTimes = WAIT_HAL_REG_RETRY;
if (tryTimes > 0) {
SoftBusSleepMs(WAIT_HAL_REG_TIME);
@ -119,7 +120,7 @@ int SoftBusGattsStartService(int srvcHandle)
if (CheckGattsStatus() != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
DISC_LOGI(DISC_BLE, "BLEINFOPRTINT:BleGattsStartService(%d, %d)", g_halServerId, srvcHandle);
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleGattsStartService(%d, %d)", g_halServerId, srvcHandle);
if (BleGattsStartService(g_halServerId, srvcHandle) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
@ -131,7 +132,7 @@ int SoftBusGattsStopService(int srvcHandle)
if (CheckGattsStatus() != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
DISC_LOGI(DISC_BLE, "BLEINFOPRTINT:SoftBusGattsStopService(%d, %d)", g_halServerId, srvcHandle);
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:SoftBusGattsStopService(%d, %d)", g_halServerId, srvcHandle);
if (BleGattsStopService(g_halServerId, srvcHandle) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
@ -156,10 +157,10 @@ int SoftBusGattsConnect(SoftBusBtAddr btAddr)
}
BdAddr addr;
if (memcpy_s(addr.addr, BT_ADDR_LEN, btAddr.addr, BT_ADDR_LEN) != EOK) {
DISC_LOGE(DISC_BLE, "memcpy fail");
CONN_LOGE(CONN_BLE, "memcpy fail");
return SOFTBUS_ERR;
}
DISC_LOGI(DISC_BLE, "BleGattsConnect start");
CONN_LOGI(CONN_BLE, "BleGattsConnect start");
if (BleGattsConnect(g_halServerId, addr) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
@ -173,10 +174,10 @@ int SoftBusGattsDisconnect(SoftBusBtAddr btAddr, int connId)
}
BdAddr addr;
if (memcpy_s(addr.addr, BT_ADDR_LEN, btAddr.addr, BT_ADDR_LEN) != EOK) {
DISC_LOGE(DISC_BLE, "memcpy fail");
CONN_LOGE(CONN_BLE, "memcpy fail");
return SOFTBUS_ERR;
}
DISC_LOGI(DISC_BLE, "BleGattsDisconnect start");
CONN_LOGI(CONN_BLE, "BleGattsDisconnect start");
if (BleGattsDisconnect(g_halServerId, addr, connId) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
@ -203,7 +204,7 @@ int SoftBusGattsSendResponse(SoftBusGattsResponse *param)
int SoftBusGattsSendNotify(SoftBusGattsNotify *param)
{
DISC_LOGI(DISC_BLE, "SoftBusGattsSendNotify enter");
CONN_LOGI(CONN_BLE, "SoftBusGattsSendNotify enter");
if (CheckGattsStatus() != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
@ -214,10 +215,10 @@ int SoftBusGattsSendNotify(SoftBusGattsNotify *param)
.valueLen = param->valueLen,
.value = param->value
};
DISC_LOGI(DISC_BLE, "SoftBusGattsSendNotify call BleGattsSendIndication halconnId:%d attrHandle:%d confirm:%d",
CONN_LOGI(CONN_BLE, "SoftBusGattsSendNotify call BleGattsSendIndication halconnId:%d attrHandle:%d confirm:%d",
notify.connectId, notify.attrHandle, notify.confirm);
if (BleGattsSendIndication(g_halServerId, &notify) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "SoftBusGattsSendNotify failed");
CONN_LOGE(CONN_BLE, "SoftBusGattsSendNotify failed");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
@ -225,30 +226,30 @@ int SoftBusGattsSendNotify(SoftBusGattsNotify *param)
static void BleRegisterServerCallback(int status, int serverId, BtUuid *appUuid)
{
DISC_LOGI(DISC_BLE, "BleRegisterServerCallback status=%d severId=%d", status, serverId);
CONN_LOGI(CONN_BLE, "BleRegisterServerCallback status=%d severId=%d", status, serverId);
if ((appUuid == NULL) || (appUuid->uuid == NULL)) {
DISC_LOGE(DISC_BLE, "BleRegisterServerCallback appUuid is null");
CONN_LOGE(CONN_BLE, "BleRegisterServerCallback appUuid is null");
return;
}
if (memcmp(appUuid->uuid, SOFTBUS_APP_UUID, appUuid->uuidLen) != 0) {
DISC_LOGE(DISC_BLE, "BleRegisterServerCallback unknown uuid");
CONN_LOGE(CONN_BLE, "BleRegisterServerCallback unknown uuid");
return;
}
if (status != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "BleRegisterServerCallback failed, status=%d", status);
CONN_LOGE(CONN_BLE, "BleRegisterServerCallback failed, status=%d", status);
g_halRegFlag = -1;
} else {
g_halRegFlag = 1;
g_halServerId = serverId;
DISC_LOGI(DISC_BLE, "BLEINFOPRTINT:BleRegisterServerCallback g_halServerId:%d)", g_halServerId);
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleRegisterServerCallback g_halServerId:%d)", g_halServerId);
}
}
static void BleConnectServerCallback(int connId, int serverId, const BdAddr *bdAddr)
{
DISC_LOGI(DISC_BLE, "ConnectServerCallback is coming, connId=%d serverId=%d\n", connId, serverId);
CONN_LOGI(CONN_BLE, "ConnectServerCallback is coming, connId=%d serverId=%d\n", connId, serverId);
if (serverId != g_halServerId) {
return;
}
@ -257,7 +258,7 @@ static void BleConnectServerCallback(int connId, int serverId, const BdAddr *bdA
static void BleDisconnectServerCallback(int connId, int serverId, const BdAddr *bdAddr)
{
DISC_LOGI(DISC_BLE, "DisconnectServerCallback is coming, connId=%d severId=%d", connId, serverId);
CONN_LOGI(CONN_BLE, "DisconnectServerCallback is coming, connId=%d severId=%d", connId, serverId);
if (serverId != g_halServerId) {
return;
}
@ -267,11 +268,11 @@ static void BleDisconnectServerCallback(int connId, int serverId, const BdAddr *
static void BleServiceAddCallback(int status, int serverId, BtUuid *uuid, int srvcHandle)
{
(void)serverId;
DISC_LOGI(DISC_BLE, "ServiceAddCallback srvcHandle=%d\n", srvcHandle);
CONN_LOGI(CONN_BLE, "ServiceAddCallback srvcHandle=%d\n", srvcHandle);
if (serverId != g_halServerId) {
return;
}
DISC_LOGI(DISC_BLE, "BLEINFOPRTINT:BleServiceAddCallback srvcHandle:%d)", srvcHandle);
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleServiceAddCallback srvcHandle:%d)", srvcHandle);
g_gattsCallback->ServiceAddCallback(status, (SoftBusBtUuid *)uuid, srvcHandle);
}
@ -280,46 +281,46 @@ static void BleIncludeServiceAddCallback(int status, int serverId, int srvcHandl
{
(void)serverId;
(void)srvcHandle;
DISC_LOGI(DISC_BLE, "IncludeServiceAddCallback srvcHandle=%d,includeSrvcHandle=%d\n",
srvcHandle, includeSrvcHandle);
CONN_LOGI(CONN_BLE, "IncludeServiceAddCallback srvcHandle=%d,includeSrvcHandle=%d\n", srvcHandle,
includeSrvcHandle);
}
static void BleCharacteristicAddCallback(int status, int serverId, BtUuid *uuid, int srvcHandle,
int characteristicHandle)
{
DISC_LOGI(DISC_BLE, "CharacteristicAddCallback srvcHandle=%d,charHandle=%d\n", srvcHandle, characteristicHandle);
CONN_LOGI(CONN_BLE, "CharacteristicAddCallback srvcHandle=%d,charHandle=%d\n", srvcHandle, characteristicHandle);
if (serverId != g_halServerId) {
DISC_LOGE(DISC_BLE, "bad server id");
CONN_LOGE(CONN_BLE, "bad server id");
return;
}
DISC_LOGI(DISC_BLE, "BLEINFOPRTINT:BleCharacteristicAddCallback characteristicHandle:%d)", characteristicHandle);
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleCharacteristicAddCallback characteristicHandle:%d)", characteristicHandle);
g_gattsCallback->CharacteristicAddCallback(status, (SoftBusBtUuid *)uuid, srvcHandle, characteristicHandle);
}
static void BleDescriptorAddCallback(int status, int serverId, BtUuid *uuid,
int srvcHandle, int descriptorHandle)
{
DISC_LOGI(DISC_BLE, "DescriptorAddCallback srvcHandle=%d,descriptorHandle=%d", srvcHandle, descriptorHandle);
CONN_LOGI(CONN_BLE, "DescriptorAddCallback srvcHandle=%d,descriptorHandle=%d", srvcHandle, descriptorHandle);
if (serverId != g_halServerId) {
return;
}
DISC_LOGI(DISC_BLE, "BLEINFOPRTINT:BleDescriptorAddCallback descriptorHandle:%d)", descriptorHandle);
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleDescriptorAddCallback descriptorHandle:%d)", descriptorHandle);
g_gattsCallback->DescriptorAddCallback(status, (SoftBusBtUuid *)uuid, srvcHandle, descriptorHandle);
}
static void BleServiceStartCallback(int status, int serverId, int srvcHandle)
{
DISC_LOGI(DISC_BLE, "ServiceStartCallback serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
CONN_LOGI(CONN_BLE, "ServiceStartCallback serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
if (serverId != g_halServerId) {
return;
}
DISC_LOGI(DISC_BLE, "BLEINFOPRTINT:BleServiceStartCallback srvcHandle:%d)", srvcHandle);
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleServiceStartCallback srvcHandle:%d)", srvcHandle);
g_gattsCallback->ServiceStartCallback(status, srvcHandle);
}
static void BleServiceStopCallback(int status, int serverId, int srvcHandle)
{
DISC_LOGI(DISC_BLE, "ServiceStopCallback serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
CONN_LOGI(CONN_BLE, "ServiceStopCallback serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
if (serverId != g_halServerId) {
return;
}
@ -328,7 +329,7 @@ static void BleServiceStopCallback(int status, int serverId, int srvcHandle)
static void BleServiceDeleteCallback(int status, int serverId, int srvcHandle)
{
DISC_LOGI(DISC_BLE, "ServiceDeleteCallback serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
CONN_LOGI(CONN_BLE, "ServiceDeleteCallback serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
if (serverId != g_halServerId) {
return;
}
@ -337,7 +338,7 @@ static void BleServiceDeleteCallback(int status, int serverId, int srvcHandle)
static void BleRequestReadCallback(BtReqReadCbPara readCbPara)
{
DISC_LOGI(DISC_BLE, "RequestReadCallback transId=%d, attrHandle=%d\n", readCbPara.transId, readCbPara.attrHandle);
CONN_LOGI(CONN_BLE, "RequestReadCallback transId=%d, attrHandle=%d\n", readCbPara.transId, readCbPara.attrHandle);
SoftBusGattReadRequest req = {
.connId = readCbPara.connId,
.transId = readCbPara.transId,
@ -351,8 +352,8 @@ static void BleRequestReadCallback(BtReqReadCbPara readCbPara)
static void BleRequestWriteCallback(BtReqWriteCbPara writeCbPara)
{
DISC_LOGI(DISC_BLE, "RequestWriteCallback transId=%d, attrHandle=%d\n",
writeCbPara.transId, writeCbPara.attrHandle);
CONN_LOGI(CONN_BLE, "RequestWriteCallback transId=%d, attrHandle=%d\n", writeCbPara.transId,
writeCbPara.attrHandle);
SoftBusGattWriteRequest req = {
.connId = writeCbPara.connId,
.transId = writeCbPara.transId,
@ -369,19 +370,19 @@ static void BleRequestWriteCallback(BtReqWriteCbPara writeCbPara)
static void BleResponseConfirmationCallback(int status, int handle)
{
DISC_LOGI(DISC_BLE, "ResponseConfirmationCallback status=%d, handle=%d\n", status, handle);
CONN_LOGI(CONN_BLE, "ResponseConfirmationCallback status=%d, handle=%d\n", status, handle);
g_gattsCallback->ResponseConfirmationCallback(status, handle);
}
static void BleIndicationSentCallback(int connId, int status)
{
DISC_LOGI(DISC_BLE, "IndicationSentCallback status=%d, connId=%d\n", status, connId);
CONN_LOGI(CONN_BLE, "IndicationSentCallback status=%d, connId=%d\n", status, connId);
g_gattsCallback->NotifySentCallback(connId, status);
}
static void BleMtuChangeCallback(int connId, int mtu)
{
DISC_LOGI(DISC_BLE, "MtuChangeCallback connId=%d, mtu=%d\n", connId, mtu);
CONN_LOGI(CONN_BLE, "MtuChangeCallback connId=%d, mtu=%d\n", connId, mtu);
g_gattsCallback->MtuChangeCallback(connId, mtu);
}
@ -408,17 +409,17 @@ static int GattsRegisterHalCallback(void)
int SoftBusRegisterGattsCallbacks(SoftBusGattsCallback *callback)
{
if (callback == NULL) {
DISC_LOGE(DISC_BLE, "SoftBusRegisterGattsCallbacks fail:nullptr");
CONN_LOGE(CONN_BLE, "SoftBusRegisterGattsCallbacks fail:nullptr");
return SOFTBUS_BLECONNECTION_REG_GATTS_CALLBACK_FAIL;
}
if (g_gattsCallback != NULL) {
DISC_LOGW(DISC_BLE, "SoftBusRegisterGattsCallbacks register again");
CONN_LOGW(CONN_BLE, "SoftBusRegisterGattsCallbacks register again");
} else {
g_gattsCallback = callback;
}
int ret = GattsRegisterHalCallback();
if (ret != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "SoftBusRegisterGattsCallbacks GattsRegisterCallbacks failed:%d", ret);
CONN_LOGE(CONN_BLE, "SoftBusRegisterGattsCallbacks GattsRegisterCallbacks failed:%d", ret);
return SOFTBUS_BLECONNECTION_REG_GATTS_CALLBACK_FAIL;
}
if (g_halRegFlag == -1) {
@ -429,7 +430,7 @@ int SoftBusRegisterGattsCallbacks(SoftBusGattsCallback *callback)
ret = BleGattsRegister(uuid);
if (ret != SOFTBUS_OK) {
g_halRegFlag = -1;
DISC_LOGE(DISC_BLE, "BleGattsRegister failed%d", ret);
CONN_LOGE(CONN_BLE, "BleGattsRegister failed%d", ret);
return SOFTBUS_BLECONNECTION_REG_GATTS_CALLBACK_FAIL;
}
}
@ -439,15 +440,15 @@ int SoftBusRegisterGattsCallbacks(SoftBusGattsCallback *callback)
void SoftBusUnRegisterGattsCallbacks(void)
{
if (g_gattsCallback == NULL) {
DISC_LOGI(DISC_BLE, "no need to unregist gatts callback.");
CONN_LOGI(CONN_BLE, "no need to unregist gatts callback.");
return;
}
if (g_halRegFlag == -1) {
DISC_LOGI(DISC_BLE, "no need to unregist gatt server.");
CONN_LOGI(CONN_BLE, "no need to unregist gatt server.");
return;
}
if (BleGattsUnRegister(g_halServerId) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "BleGattsUnRegister error.");
CONN_LOGE(CONN_BLE, "BleGattsUnRegister error.");
return;
}
g_halServerId = -1;

View File

@ -25,8 +25,8 @@ extern "C" {
#endif
// max adv and scan limit
#define ADV_MAX_NUM 9
#define SCAN_MAX_NUM 9
#define ADV_MAX_NUM 16
#define SCAN_MAX_NUM 16
// Bluetooth scan duty cycle, unit: ms
#define SOFTBUS_BLE_SCAN_INTERVAL_P2 3000

View File

@ -132,6 +132,7 @@
"//foundation/communication/dsoftbus/tests/sdk/transmission:benchmarktest",
"//foundation/communication/dsoftbus/tests/sdk/transmission:integration_test",
"//foundation/communication/dsoftbus/tests/sdk/frame/common:unittest",
"//foundation/communication/dsoftbus/tests/sdk/frame/standard:unittest",
"//foundation/communication/dsoftbus/tests/sdk/frame:fuzztest"
]
}

View File

@ -470,9 +470,6 @@ void SignalingMsgPrint(const char *distinguish, unsigned char *data, unsigned ch
if (module == SOFTBUS_LOG_DISC) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "[signaling]:%s, len:%d, data:%s",
distinguish, dataLen, signalingMsgBuf);
} else if (module == SOFTBUS_LOG_CONN) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "[signaling]:%s, len:%d, data:%s",
distinguish, dataLen, signalingMsgBuf);
}
}

View File

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "conn_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_conn_ble_connection.h"
#include "softbus_conn_interface.h"
@ -23,7 +24,7 @@ ConnBleConnection *LegacyBleCreateConnection(const char *addr, ConnSideType side
{
if (g_connection == NULL) {
g_connection = (ConnBleConnection *)SoftBusCalloc(sizeof(ConnBleConnection));
CONN_CHECK_AND_RETURN_RET_LOG(g_connection != NULL, NULL, "ble connection calloc failed");
CONN_CHECK_AND_RETURN_RET_LOGE(g_connection != NULL, NULL, CONN_NEARBY, "ble connection calloc failed");
g_connection->side = side;
g_connection->underlayerHandle = underlayerHandle;
}

View File

@ -170,7 +170,7 @@ void ConnBleFreeConnection(ConnBleConnection *connection)
static GattService *CreateGattService(void)
{
GattService *gattService = SoftBusCalloc(sizeof(GattService));
CONN_CHECK_AND_RETURN_RET_LOG(gattService != NULL, NULL, "calloc gatt service failed");
CONN_CHECK_AND_RETURN_RET_LOGE(gattService != NULL, NULL, CONN_BLE, "calloc gatt service failed");
SoftBusBtUuid serviceUuid = {
.uuid = SOFTBUS_SERVICE_UUID,
.uuidLen = strlen(SOFTBUS_SERVICE_UUID),

View File

@ -454,6 +454,7 @@ static int32_t P2pShareLinkRemoveGroup(const char *interface)
static int32_t P2pRemoveGroup(const char *interface)
{
CONN_CHECK_AND_RETURN_RET_LOGW(interface != NULL, SOFTBUS_ERR, CONN_WIFI_DIRECT, "interface is null");
struct InterfaceInfo *info = GetResourceManager()->getInterfaceInfo(interface);
if (info == NULL) {
CONN_LOGE(CONN_WIFI_DIRECT, "can't find interface %s", interface);

View File

@ -220,8 +220,10 @@ int32_t OpenDefaultNegotiateChannel(const char *remoteIp, int32_t remotePort,
struct WifiDirectNegotiateChannel *srcChannel,
struct DefaultNegoChannelOpenCallback *callback)
{
CONN_CHECK_AND_RETURN_RET_LOGW(remoteIp != NULL, SOFTBUS_ERR, CONN_WIFI_DIRECT, "remoteIp is null");
CONN_CHECK_AND_RETURN_RET_LOGW(callback != NULL, SOFTBUS_ERR, CONN_WIFI_DIRECT, "callback is null");
bool isMeta = false;
if (srcChannel && srcChannel->isMetaChannel) {
if ((srcChannel != NULL) && (srcChannel->isMetaChannel != NULL)) {
isMeta = srcChannel->isMetaChannel(srcChannel);
}
CONN_LOGI(CONN_WIFI_DIRECT, "remoteIp=%s remotePort=%d isMeta=%d", WifiDirectAnonymizeIp(remoteIp), remotePort,
@ -249,6 +251,7 @@ int32_t OpenDefaultNegotiateChannel(const char *remoteIp, int32_t remotePort,
void CloseDefaultNegotiateChannel(struct DefaultNegotiateChannel *self)
{
CONN_CHECK_AND_RETURN_LOGW(self != NULL, CONN_WIFI_DIRECT, "self is null");
AuthCloseConn(self->authId);
}

View File

@ -512,6 +512,7 @@ static void Dump(struct InfoContainer *self, int32_t fd)
void InfoContainerConstructor(struct InfoContainer *self, struct InfoContainerKeyProperty *keyProperties, size_t max)
{
CONN_CHECK_AND_RETURN_LOGW(self != NULL, CONN_WIFI_DIRECT, "self is null");
self->dumpFilter = true;
for (size_t key = 0; key < max; key++) {
self->entries[key].data = NULL;
@ -547,6 +548,7 @@ void InfoContainerConstructor(struct InfoContainer *self, struct InfoContainerKe
void InfoContainerDestructor(struct InfoContainer *self, size_t max)
{
CONN_CHECK_AND_RETURN_LOGW(self != NULL, CONN_WIFI_DIRECT, "self is null");
for (size_t key = 0; key < max; key++) {
char *data = self->entries[key].data;
if (data) {

View File

@ -369,6 +369,7 @@ static size_t GetKeyFromKeyProperty(struct InfoContainerKeyProperty *keyProperty
static bool UnmarshallingPrimary(struct InnerLink *self, enum InnerLinkKey key, uint8_t *data, size_t size)
{
CONN_CHECK_AND_RETURN_RET_LOGW(self != NULL, false, CONN_WIFI_DIRECT, "self is null");
self->putRawData(self, key, data, ALIGN_SIZE_4(size));
return true;
}
@ -424,6 +425,7 @@ void InnerLinkDestructor(struct InnerLink *self)
struct InnerLink* InnerLinkNew(void)
{
struct InnerLink *self = SoftBusCalloc(sizeof(*self));
CONN_CHECK_AND_RETURN_RET_LOGE(self != NULL, NULL, CONN_WIFI_DIRECT, "self is null");
InnerLinkConstructor(self);
return self;
}
@ -437,10 +439,9 @@ void InnerLinkDelete(struct InnerLink *self)
struct InnerLink* InnerLinkNewArray(size_t size)
{
struct InnerLink *self = (struct InnerLink *)SoftBusCalloc(sizeof(*self) * size);
if (self) {
for (size_t i = 0; i < size; i++) {
InnerLinkConstructor(self + i);
}
CONN_CHECK_AND_RETURN_RET_LOGE(self != NULL, NULL, CONN_WIFI_DIRECT, "self is null");
for (size_t i = 0; i < size; i++) {
InnerLinkConstructor(self + i);
}
return self;

View File

@ -404,9 +404,8 @@ void InterfaceInfoDestructor(struct InterfaceInfo* self)
struct InterfaceInfo* InterfaceInfoNew(void)
{
struct InterfaceInfo *self = (struct InterfaceInfo *)SoftBusCalloc(sizeof(*self));
if (self) {
InterfaceInfoConstructor(self);
}
CONN_CHECK_AND_RETURN_RET_LOGE(self != NULL, NULL, CONN_WIFI_DIRECT, "self is null");
InterfaceInfoConstructor(self);
return self;
}
@ -420,10 +419,9 @@ void InterfaceInfoDelete(struct InterfaceInfo* self)
struct InterfaceInfo* InterfaceInfoNewArray(size_t size)
{
struct InterfaceInfo *self = (struct InterfaceInfo *)SoftBusCalloc(sizeof(*self) * size);
if (self) {
for (size_t i = 0; i < size; i++) {
InterfaceInfoConstructor(self + i);
}
CONN_CHECK_AND_RETURN_RET_LOGE(self != NULL, NULL, CONN_WIFI_DIRECT, "self is null");
for (size_t i = 0; i < size; i++) {
InterfaceInfoConstructor(self + i);
}
return self;

View File

@ -267,6 +267,7 @@ void LinkInfoConstructor(struct LinkInfo* self)
void LinkInfoDestructor(struct LinkInfo* self)
{
CONN_CHECK_AND_RETURN_LOGW(self != NULL, CONN_WIFI_DIRECT, "self is null");
InfoContainerDestructor((struct InfoContainer *)self, LI_KEY_MAX);
}
@ -284,9 +285,8 @@ void LinkInfoConstructorWithNameAndMode(struct LinkInfo* self, const char *local
struct LinkInfo* LinkInfoNew(void)
{
struct LinkInfo *self = (struct LinkInfo *)SoftBusCalloc(sizeof(*self));
if (self) {
LinkInfoConstructor(self);
}
CONN_CHECK_AND_RETURN_RET_LOGE(self != NULL, NULL, CONN_WIFI_DIRECT, "self is null");
LinkInfoConstructor(self);
return self;
}
@ -295,9 +295,8 @@ struct LinkInfo* LinkInfoNewWithNameAndMode(const char *localName, const char *r
uint32_t localMode, uint32_t remoteMod)
{
struct LinkInfo *self = (struct LinkInfo *)SoftBusCalloc(sizeof(*self));
if (self) {
LinkInfoConstructorWithNameAndMode(self, localName, remoteName, localMode, remoteMod);
}
CONN_CHECK_AND_RETURN_RET_LOGE(self != NULL, NULL, CONN_WIFI_DIRECT, "self is null");
LinkInfoConstructorWithNameAndMode(self, localName, remoteName, localMode, remoteMod);
return self;
}

View File

@ -43,7 +43,7 @@ static struct InnerLink* GetLinkByDevice(const char *macString)
struct InnerLink *target = NULL;
for (size_t type = 0; type < WIFI_DIRECT_LINK_TYPE_MAX; type++) {
target = self->getLinkByTypeAndDevice(type, macString);
if (target) {
if (target != NULL) {
return target;
}
}
@ -61,7 +61,7 @@ static struct InnerLink* GetLinkByTypeAndDevice(enum WifiDirectLinkType linkType
SoftBusMutexLock(&self->mutex);
LIST_FOR_EACH_ENTRY(target, &self->linkLists[linkType], struct InnerLink, node) {
char *mac = target->get(target, IL_KEY_REMOTE_BASE_MAC, NULL, NULL);
if (mac && !strcmp(mac, macString)) {
if ((mac != NULL) && (strcmp(mac, macString) == 0)) {
SoftBusMutexUnlock(&self->mutex);
return target;
}
@ -293,7 +293,7 @@ static int32_t GenerateLinkId(struct InnerLink *innerLink, int32_t requestId, in
enum WifiDirectLinkType type = innerLink->getInt(innerLink, IL_KEY_LINK_TYPE, WIFI_DIRECT_LINK_TYPE_INVALID);
char *remoteMac = innerLink->getString(innerLink, IL_KEY_REMOTE_BASE_MAC, "");
struct InnerLink *originInnerLink = self->getLinkByTypeAndDevice(type, remoteMac);
if (!originInnerLink) {
if (originInnerLink == NULL) {
CONN_LOGE(CONN_WIFI_DIRECT, "not find");
return LINK_ID_INVALID;
}
@ -320,7 +320,7 @@ static void RecycleLinkId(int32_t linkId, const char *remoteMac)
return;
}
struct InnerLink *originInnerLink = GetLinkManager()->getLinkById(linkId);
if (!originInnerLink) {
if (originInnerLink == NULL) {
CONN_LOGE(CONN_WIFI_DIRECT, "not find");
return;
}
@ -342,7 +342,7 @@ static void SetNegotiateChannelForLink(struct WifiDirectNegotiateChannel *channe
AnonymizeFree(anonymousUuid);
struct WifiDirectNegotiateChannel *channelOld = target->getPointer(target, IL_KEY_NEGO_CHANNEL, NULL);
if (channelOld) {
if (channelOld != NULL) {
channelOld->destructor(channelOld);
}
struct WifiDirectNegotiateChannel *channelNew = channel->duplicate(channel);
@ -366,7 +366,7 @@ static void ClearNegotiateChannelForLink(const char *uuid, bool destroy)
}
struct DefaultNegotiateChannel *channelOld = target->getPointer(target, IL_KEY_NEGO_CHANNEL, NULL);
if (channelOld) {
if (channelOld != NULL) {
DefaultNegotiateChannelDelete(channelOld);
}
target->remove(target, IL_KEY_NEGO_CHANNEL);
@ -479,7 +479,7 @@ static void RemoveLink(struct InnerLink *link)
struct LinkManager *self = GetLinkManager();
struct InnerLink *oldLink = self->getLinkByTypeAndDevice(linkType, mac);
if (oldLink) {
if (oldLink != NULL) {
SoftBusMutexLock(&self->mutex);
oldLink->setState(oldLink, INNER_LINK_STATE_DISCONNECTED);
OnInnerLinkChange(oldLink, true);
@ -493,11 +493,11 @@ static void RemoveLink(struct InnerLink *link)
static void UpdateLink(struct InnerLink *oldLink, struct InnerLink *newLink)
{
if (!oldLink) {
if (oldLink == NULL) {
AddLink(newLink);
return;
}
if (!newLink) {
if (newLink == NULL) {
RemoveLink(oldLink);
return;
}
@ -567,7 +567,7 @@ static void AdjustIfRemoteMacChange(struct InnerLink *innerLink)
innerLink->putString(innerLink, IL_KEY_LOCAL_BASE_MAC, targetLocalMac);
}
struct WifiDirectIpv4Info *targetRemoteIpv4 = target->getRawData(target, IL_KEY_REMOTE_IPV4, NULL, NULL);
if (targetRemoteIpv4) {
if (targetRemoteIpv4 != NULL) {
innerLink->putRawData(innerLink, IL_KEY_REMOTE_IPV4, targetRemoteIpv4, sizeof(*targetRemoteIpv4));
}
SoftBusFree(target);

View File

@ -141,7 +141,7 @@ static bool Marshalling(struct NegotiateMessage *self, struct WifiDirectProtocol
}
size_t size = 0;
uint8_t *value = self->get(self, key, &size, NULL);
if (!value || !size) {
if ((value == NULL) || (size == 0)) {
continue;
}
@ -389,9 +389,8 @@ void NegotiateMessageDestructor(struct NegotiateMessage* self)
struct NegotiateMessage* NegotiateMessageNew(void)
{
struct NegotiateMessage *self = (struct NegotiateMessage *)SoftBusCalloc(sizeof(*self));
if (self) {
NegotiateMessageConstructor(self);
}
CONN_CHECK_AND_RETURN_RET_LOGE(self != NULL, NULL, CONN_WIFI_DIRECT, "self is null");
NegotiateMessageConstructor(self);
return self;
}
@ -405,10 +404,9 @@ void NegotiateMessageDelete(struct NegotiateMessage* self)
struct NegotiateMessage* NegotiateMessageNewArray(size_t size)
{
struct NegotiateMessage *self = (struct NegotiateMessage *)SoftBusCalloc(sizeof(*self) * size);
if (self) {
for (size_t i = 0; i < size; i++) {
NegotiateMessageConstructor(self + i);
}
CONN_CHECK_AND_RETURN_RET_LOGE(self != NULL, NULL, CONN_WIFI_DIRECT, "self is null");
for (size_t i = 0; i < size; i++) {
NegotiateMessageConstructor(self + i);
}
return self;

View File

@ -85,7 +85,7 @@ static void NotifyInterfaceInfoChange(struct InterfaceInfo *info)
CONN_CHECK_AND_RETURN_LOGW(strlen(name) > 0, CONN_WIFI_DIRECT, "name is emtpy");
SoftBusMutexLock(&self->mutex);
struct InterfaceInfo *old = self->getInterfaceInfo(name);
if (!old) {
if (old == NULL) {
struct InterfaceInfo *newInfo = InterfaceInfoNew();
CONN_CHECK_AND_RETURN_LOGW(newInfo, CONN_WIFI_DIRECT, "new interface failed");
newInfo->deepCopy(newInfo, info);
@ -102,7 +102,7 @@ static void NotifyInterfaceInfoChange(struct InterfaceInfo *info)
size_t size = 0;
size_t count = 0;
void *data = info->get(info, key, &size, &count);
if (data) {
if (data != NULL) {
if (property->flag == CONTAINER_FLAG) {
old->putContainer(old, key, data, size);
} else if (property->flag == CONTAINER_ARRAY_FLAG) {
@ -126,7 +126,7 @@ static void NotifyInterfaceInfoChange(struct InterfaceInfo *info)
static void AddUsingInterfaceToList(ListNode *list, const char *interface)
{
struct CombinationEntry *entry = SoftBusCalloc(sizeof(*entry));
if (entry) {
if (entry != NULL) {
ListInit(&entry->node);
int32_t ret = strcpy_s(entry->interface, sizeof(entry->interface), interface);
if (ret != EOK) {
@ -153,7 +153,7 @@ static ListNode* GetUsingInterfaces(bool forShare)
}
struct InterfaceInfo *info = GetResourceManager()->getInterfaceInfo(IF_NAME_P2P);
if (info) {
if (info != NULL) {
enum WifiDirectApiRole myRole =
(enum WifiDirectApiRole)info->getInt(info, II_KEY_WIFI_DIRECT_ROLE, WIFI_DIRECT_API_ROLE_NONE);
if (myRole == WIFI_DIRECT_API_ROLE_GC || myRole == WIFI_DIRECT_API_ROLE_GO) {
@ -162,7 +162,7 @@ static ListNode* GetUsingInterfaces(bool forShare)
}
info = GetResourceManager()->getInterfaceInfo(IF_NAME_HML);
if (info) {
if (info != NULL) {
enum WifiDirectApiRole myRole =
(enum WifiDirectApiRole)info->getInt(info, II_KEY_WIFI_DIRECT_ROLE, WIFI_DIRECT_API_ROLE_NONE);
if (myRole == WIFI_DIRECT_API_ROLE_HML) {
@ -189,7 +189,7 @@ static bool IsStationAndHmlDBAC(void)
int32_t staFreq = GetWifiDirectP2pAdapter()->getStationFrequency();
int32_t hmlFreq = -1;
struct InterfaceInfo *hmlInfo = GetResourceManager()->getInterfaceInfo(IF_NAME_HML);
if (hmlInfo) {
if (hmlInfo != NULL) {
enum WifiDirectApiRole hmlRole = hmlInfo->getInt(hmlInfo, II_KEY_WIFI_DIRECT_ROLE, WIFI_DIRECT_API_ROLE_NONE);
if (hmlRole == WIFI_DIRECT_API_ROLE_HML) {
hmlFreq = hmlInfo->getInt(hmlInfo, II_KEY_CENTER_20M, -1);
@ -227,7 +227,7 @@ static bool IsInterfaceAvailable(const char *interface, bool forShare)
}
ListNode *usingInterfaces = GetUsingInterfaces(forShare);
if (usingInterfaces) {
if (usingInterfaces != NULL) {
AddUsingInterfaceToList(usingInterfaces, interface);
bool ret = GetWifiDirectCoexistRule()->isCombinationAvailable(usingInterfaces);
FreeUsingInterfaces(usingInterfaces);
@ -349,7 +349,7 @@ static int32_t InitInterfaceInfo(const char *interface)
info.putName(&info, interface);
CONN_LOGI(CONN_INIT, "interface %s", interface);
if (!strcmp(interface, IF_NAME_P2P)) {
if (strcmp(interface, IF_NAME_P2P) == 0) {
char macString[MAC_ADDR_STR_LEN];
int32_t ret = GetWifiDirectP2pAdapter()->getMacAddress(macString, sizeof(macString));
if (ret == SOFTBUS_OK) {
@ -375,7 +375,7 @@ static int32_t InitInterfaceInfo(const char *interface)
return SOFTBUS_OK;
}
if (!strcmp(interface, IF_NAME_HML)) {
if (strcmp(interface, IF_NAME_HML) == 0) {
info.putInt(&info, II_KEY_CONNECT_CAPABILITY, WIFI_DIRECT_API_ROLE_HML);
InterfaceInfoDestructor(&info);
return SOFTBUS_OK;

View File

@ -103,7 +103,7 @@ static bool Unmarshalling(struct WifiConfigInfo *self, struct WifiDirectProtocol
enum WifiConfigInfoKey key = GetKeyFromKeyProperty(&keyProperty);
CONN_CHECK_AND_RETURN_RET_LOGW(key < WC_KEY_MAX, false, CONN_WIFI_DIRECT, "key out of range, tag=%d",
keyProperty.tag);
if (!data || !size) {
if ((data == NULL) || (size == 0)) {
continue;
}
if (key == WC_KEY_IGNORE) {

View File

@ -306,13 +306,14 @@ static void OnClientJoinTimeout(void *data)
client = NULL;
struct WifiDirectConnectParams params;
strcpy_s(params.interface, sizeof(params.interface), IF_NAME_P2P);
int32_t ret = strcpy_s(params.interface, sizeof(params.interface), IF_NAME_P2P);
CONN_CHECK_AND_RETURN_LOGE(ret == EOK, CONN_WIFI_DIRECT, "copy interface failed");
int32_t ret = Disconnect(&params);
ret = Disconnect(&params);
CONN_CHECK_AND_RETURN_LOGW(ret == SOFTBUS_OK, CONN_WIFI_DIRECT, "disconnect failed");
struct InterfaceInfo *info = GetResourceManager()->getInterfaceInfo(IF_NAME_P2P);
if (info) {
if (info != NULL) {
info->decreaseRefCount(info);
}
}

View File

@ -1290,7 +1290,7 @@ static int32_t ProcessGetInterfaceInfoRequest(struct NegotiateMessage *msg)
CONN_CHECK_AND_RETURN_RET_LOGW(response, SOFTBUS_ERR, CONN_WIFI_DIRECT, "build interface info response failed");
ret = GetWifiDirectNegotiator()->postData(response);
NegotiateMessageDelete(response);
if (self->pendingRequestMsg) {
if (self->pendingRequestMsg != NULL) {
NegotiateMessageDelete(self->pendingRequestMsg);
self->pendingRequestMsg = NULL;
}
@ -1560,8 +1560,10 @@ static void InitBasicInnerLink(struct InnerLink *innerLink)
static void NotifyNewClient(const char *localInterface, const char *remoteMac)
{
struct WifiDirectConnectParams params;
(void)strcpy_s(params.interface, sizeof(params.interface), localInterface);
(void)strcpy_s(params.remoteMac, sizeof(params.remoteMac), remoteMac);
int32_t ret = strcpy_s(params.interface, sizeof(params.interface), localInterface);
CONN_CHECK_AND_RETURN_LOGE(ret == EOK, CONN_WIFI_DIRECT, "copy local interface failed");
ret = strcpy_s(params.remoteMac, sizeof(params.remoteMac), remoteMac);
CONN_CHECK_AND_RETURN_LOGE(ret == EOK, CONN_WIFI_DIRECT, "copy remote mac failed");
GetWifiDirectEntityFactory()->createEntity(ENTITY_TYPE_P2P)->notifyNewClientJoining(&params);
}
@ -1569,8 +1571,10 @@ static void NotifyNewClient(const char *localInterface, const char *remoteMac)
static void CancelNewClient(const char *localInterface, const char *remoteMac)
{
struct WifiDirectConnectParams params;
(void)strcpy_s(params.interface, sizeof(params.interface), localInterface);
(void)strcpy_s(params.remoteMac, sizeof(params.remoteMac), remoteMac);
int32_t ret = strcpy_s(params.interface, sizeof(params.interface), localInterface);
CONN_CHECK_AND_RETURN_LOGE(ret == EOK, CONN_WIFI_DIRECT, "copy local interface failed");
ret = strcpy_s(params.remoteMac, sizeof(params.remoteMac), remoteMac);
CONN_CHECK_AND_RETURN_LOGE(ret == EOK, CONN_WIFI_DIRECT, "copy remote mac failed");
GetWifiDirectEntityFactory()->createEntity(ENTITY_TYPE_P2P)->cancelNewClientJoining(&params);
}

View File

@ -83,6 +83,8 @@ static void ParseItemDataFromServiceData(char *serviceData, const char *key, cha
while (itemStr != NULL) {
valueStr = strchr(itemStr, ':');
if (valueStr == NULL) {
DISC_LOGW(DISC_COAP, "invalid service data item=%s", itemStr);
itemStr = strtok_s(NULL, itemDelimit, &saveItemPtr);
continue;
}
*valueStr = '\0';

View File

@ -245,7 +245,7 @@ int32_t TransTdcPostBytes(int32_t channelId, TdcPacketHead *packetHead, const ch
return SOFTBUS_INVALID_PARAM;
}
uint32_t bufferLen = AuthGetEncryptSize(packetHead->dataLen) + DC_MSG_PACKET_HEAD_SIZE;
char *buffer = (char *)SoftBusMalloc(bufferLen);
char *buffer = (char *)SoftBusCalloc(bufferLen);
if (buffer == NULL) {
TRANS_LOGE(TRANS_BYTES, "buffer malloc error.");
return SOFTBUS_MALLOC_ERR;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -32,11 +32,9 @@
#include "softbus_server_ipc_interface_code.h"
#include "softbus_server_proxy_standard.h"
using namespace OHOS;
namespace {
sptr<IRemoteObject> g_serverProxy = nullptr;
sptr<IRemoteObject::DeathRecipient> g_clientDeath = nullptr;
OHOS::sptr<OHOS::IRemoteObject> g_serverProxy = nullptr;
OHOS::sptr<OHOS::IRemoteObject::DeathRecipient> g_clientDeath = nullptr;
std::mutex g_mutex;
uint32_t g_waitServerInterval = 2;
uint32_t g_getSystemAbilityId = 2;
@ -49,7 +47,8 @@ static int InnerRegisterService(void)
COMM_LOGE(COMM_SDK, "g_serverProxy is nullptr!");
return SOFTBUS_INVALID_PARAM;
}
sptr<SoftBusServerProxyFrame> serverProxyFrame = new (std::nothrow) SoftBusServerProxyFrame(g_serverProxy);
OHOS::sptr<OHOS::SoftBusServerProxyFrame> serverProxyFrame =
new (std::nothrow) OHOS::SoftBusServerProxyFrame(g_serverProxy);
if (serverProxyFrame == nullptr) {
COMM_LOGE(COMM_SDK, "serverProxyFrame is nullptr!");
return SOFTBUS_INVALID_PARAM;
@ -75,18 +74,18 @@ static int InnerRegisterService(void)
return SOFTBUS_OK;
}
static sptr<IRemoteObject> GetSystemAbility()
static OHOS::sptr<OHOS::IRemoteObject> GetSystemAbility()
{
MessageParcel data;
OHOS::MessageParcel data;
if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) {
return nullptr;
}
data.WriteInt32(SOFTBUS_SERVER_SA_ID_INNER);
MessageParcel reply;
MessageOption option;
sptr<IRemoteObject> samgr = IPCSkeleton::GetContextObject();
OHOS::MessageParcel reply;
OHOS::MessageOption option;
OHOS::sptr<OHOS::IRemoteObject> samgr = OHOS::IPCSkeleton::GetContextObject();
if (samgr == nullptr) {
COMM_LOGE(COMM_EVENT, "Get samgr failed!");
return nullptr;
@ -108,7 +107,8 @@ static int32_t ServerProxyInit(void)
COMM_LOGE(COMM_SDK, "Get remote softbus object failed!\n");
return SOFTBUS_ERR;
}
g_clientDeath = sptr<IRemoteObject::DeathRecipient>(new (std::nothrow) SoftBusClientDeathRecipient());
g_clientDeath =
OHOS::sptr<OHOS::IRemoteObject::DeathRecipient>(new (std::nothrow) OHOS::SoftBusClientDeathRecipient());
if (g_clientDeath == nullptr) {
COMM_LOGE(COMM_SDK, "DeathRecipient object is nullptr\n");
return SOFTBUS_ERR;
@ -157,7 +157,8 @@ int ClientRegisterService(const char *pkgName)
COMM_LOGE(COMM_SDK, "g_serverProxy is nullptr!");
return SOFTBUS_INVALID_PARAM;
}
sptr<SoftBusServerProxyFrame> serverProxyFrame = new (std::nothrow) SoftBusServerProxyFrame(g_serverProxy);
OHOS::sptr<OHOS::SoftBusServerProxyFrame> serverProxyFrame =
new (std::nothrow) OHOS::SoftBusServerProxyFrame(g_serverProxy);
if (serverProxyFrame == nullptr) {
COMM_LOGE(COMM_SDK, "serverProxyFrame is nullptr!");
return SOFTBUS_INVALID_PARAM;

View File

@ -75,6 +75,18 @@ HWTEST_F(ConnLogTest, ConnLogTest001, TestSize.Level0)
EXPECT_EQ(++connDomainBase, label.domain);
EXPECT_STREQ("ConnNearby", label.tag);
EXPECT_EQ(++index, CONN_BLE_DIRECT);
label = CONN_LABELS[CONN_BLE_DIRECT];
EXPECT_EQ(CONN_BLE_DIRECT, label.label);
EXPECT_EQ(++connDomainBase, label.domain);
EXPECT_STREQ("ConnBD", label.tag);
EXPECT_EQ(++index, CONN_BROADCAST);
label = CONN_LABELS[CONN_BROADCAST];
EXPECT_EQ(CONN_BROADCAST, label.label);
EXPECT_EQ(++connDomainBase, label.domain);
EXPECT_STREQ("ConnBC", label.tag);
EXPECT_EQ(++index, CONN_TEST);
label = CONN_LABELS[CONN_TEST];
EXPECT_EQ(CONN_TEST, label.label);

View File

@ -20,12 +20,12 @@
#include <securec.h>
#include "common_list.h"
#include "conn_log.h"
#include "softbus_conn_interface.h"
#include "softbus_conn_manager.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_log_old.h"
static const uint32_t CONN_HEAD_SIZE = 24;
static const char *TEST_BLE_MAC = "11:22:33:44:55:66";
@ -722,7 +722,7 @@ HWTEST_F(ConnectionBleSwitchTest, testConnmanger0012, TestSize.Level1)
HWTEST_F(ConnectionBleSwitchTest, testConnmanger0013, TestSize.Level1)
{
int ret;
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "testConnmanger0013");
CONN_LOGI(CONN_WIFI_DIRECT, "testConnmanger0013");
ret = ConnTypeIsSupport(CONNECT_BLE);
EXPECT_EQ(ret, SOFTBUS_OK);
}
@ -735,7 +735,7 @@ HWTEST_F(ConnectionBleSwitchTest, testConnmanger0013, TestSize.Level1)
*/
HWTEST_F(ConnectionBleSwitchTest, testConnmanger0014, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "testConnmanger0014");
CONN_LOGI(CONN_WIFI_DIRECT, "testConnmanger0014");
int ret = ConnSetConnectCallback(static_cast<ConnModule>(0), nullptr);
ASSERT_TRUE(ret != SOFTBUS_OK);
ret = ConnConnectDevice(nullptr, 0, nullptr);
@ -758,7 +758,7 @@ HWTEST_F(ConnectionBleSwitchTest, testConnmanger0014, TestSize.Level1)
*/
HWTEST_F(ConnectionBleSwitchTest, testConnmanger0015, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "testConnmanger0015");
CONN_LOGI(CONN_WIFI_DIRECT, "testConnmanger0015");
ConnectCallback connCb;
connCb.OnConnected = ConnectedCB;
connCb.OnDisconnected = DisConnectCB;
@ -779,7 +779,7 @@ HWTEST_F(ConnectionBleSwitchTest, testConnmanger0015, TestSize.Level1)
*/
HWTEST_F(ConnectionBleSwitchTest, testConnmanger0016, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "testConnmanger0016");
CONN_LOGI(CONN_WIFI_DIRECT, "testConnmanger0016");
ConnectCallback connCb;
connCb.OnConnected = ConnectedCB;
connCb.OnDisconnected = DisConnectCB;
@ -807,7 +807,7 @@ HWTEST_F(ConnectionBleSwitchTest, testConnmanger0016, TestSize.Level1)
*/
HWTEST_F(ConnectionBleSwitchTest, testConnmanger0017, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "testConnmanger0017");
CONN_LOGI(CONN_WIFI_DIRECT, "testConnmanger0017");
int ret = ConnTypeIsSupport(CONNECT_P2P);
EXPECT_EQ(SOFTBUS_CONN_MANAGER_OP_NOT_SUPPORT, ret);
}
@ -822,7 +822,7 @@ HWTEST_F(ConnectionBleSwitchTest, testConnmanger0017, TestSize.Level1)
*/
HWTEST_F(ConnectionBleSwitchTest, testConnmanger0018, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "testConnmanger0018");
CONN_LOGI(CONN_WIFI_DIRECT, "testConnmanger0018");
int ret = ConnTypeIsSupport(CONNECT_BR);
EXPECT_EQ(SOFTBUS_OK, ret);
}
@ -837,7 +837,7 @@ HWTEST_F(ConnectionBleSwitchTest, testConnmanger0018, TestSize.Level1)
*/
HWTEST_F(ConnectionBleSwitchTest, testConnmanger0019, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "testConnmanger0019");
CONN_LOGI(CONN_WIFI_DIRECT, "testConnmanger0019");
int ret = ConnTypeIsSupport(CONNECT_TCP);
EXPECT_EQ(SOFTBUS_OK, ret);
}

View File

@ -16,7 +16,7 @@
#include <gtest/gtest.h>
#include <securec.h>
#include "softbus_log_old.h"
#include "conn_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_error_code.h"
#include "softbus_json_utils.h"
@ -58,7 +58,7 @@ void NegotiateStateTest::TearDown(void) {}
*/
HWTEST_F(NegotiateStateTest, NegotiateStateTest001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "NegotiateStateTest, NegotiateStateTest001, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "NegotiateStateTest, NegotiateStateTest001, Start");
struct WifiDirectNegotiator* negotiator = GetWifiDirectNegotiator();
struct ProcessingState* self = GetProcessingState(negotiator);
struct WifiDirectProcessor *processor =
@ -73,7 +73,7 @@ HWTEST_F(NegotiateStateTest, NegotiateStateTest001, TestSize.Level1)
EXPECT_EQ(ret, SOFTBUS_ERR);
ret = self->handleNegotiateMessageFromRemote(processor, CMD_CTRL_CHL_HANDSHAKE, msg);
EXPECT_NE(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "NegotiateStateTest, NegotiateStateTest001, End");
CONN_LOGI(CONN_WIFI_DIRECT, "NegotiateStateTest, NegotiateStateTest001, End");
};
/* waiting_connect_request_state.c */
@ -85,7 +85,7 @@ HWTEST_F(NegotiateStateTest, NegotiateStateTest001, TestSize.Level1)
*/
HWTEST_F(NegotiateStateTest, NegotiateStateTest002, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "NegotiateStateTest, NegotiateStateTest002, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "NegotiateStateTest, NegotiateStateTest002, Start");
struct WifiDirectNegotiator* negotiator = GetWifiDirectNegotiator();
struct WaitingConnectRequestState* self = GetWaitingConnectRequestState(negotiator);
struct WifiDirectProcessor *processor =
@ -98,7 +98,7 @@ HWTEST_F(NegotiateStateTest, NegotiateStateTest002, TestSize.Level1)
EXPECT_NE(ret, SOFTBUS_OK);
ret = self->handleNegotiateMessageFromRemote(processor, CMD_INVALID, msg);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "NegotiateStateTest, NegotiateStateTest002, End");
CONN_LOGI(CONN_WIFI_DIRECT, "NegotiateStateTest, NegotiateStateTest002, End");
};
/* waiting_connect_response_state.c */
@ -110,7 +110,7 @@ HWTEST_F(NegotiateStateTest, NegotiateStateTest002, TestSize.Level1)
*/
HWTEST_F(NegotiateStateTest, NegotiateStateTest003, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "NegotiateStateTest, NegotiateStateTest003, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "NegotiateStateTest, NegotiateStateTest003, Start");
struct WifiDirectNegotiator* negotiator = GetWifiDirectNegotiator();
struct WaitingConnectResponseState* self = GetWaitingConnectResponseState(negotiator);
struct WifiDirectProcessor *processor =
@ -123,7 +123,7 @@ HWTEST_F(NegotiateStateTest, NegotiateStateTest003, TestSize.Level1)
EXPECT_NE(ret, SOFTBUS_OK);
ret = self->handleNegotiateMessageFromRemote(processor, CMD_INVALID, msg);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "NegotiateStateTest, NegotiateStateTest003, End");
CONN_LOGI(CONN_WIFI_DIRECT, "NegotiateStateTest, NegotiateStateTest003, End");
};
/* available_state.c */
@ -135,7 +135,7 @@ HWTEST_F(NegotiateStateTest, NegotiateStateTest003, TestSize.Level1)
*/
HWTEST_F(NegotiateStateTest, NegotiateStateTest004, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "NegotiateStateTest, NegotiateStateTest004, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "NegotiateStateTest, NegotiateStateTest004, Start");
struct WifiDirectNegotiator* negotiator = GetWifiDirectNegotiator();
struct AvailableState* self = GetAvailableState(negotiator);
struct WifiDirectProcessor *processor =
@ -146,6 +146,6 @@ HWTEST_F(NegotiateStateTest, NegotiateStateTest004, TestSize.Level1)
EXPECT_NE(ret, SOFTBUS_OK);
ret = self->handleNegotiateMessageFromRemote(processor, CMD_INVALID, msg);
EXPECT_EQ(ret, SOFTBUS_OK);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "NegotiateStateTest, NegotiateStateTest004, End");
CONN_LOGI(CONN_WIFI_DIRECT, "NegotiateStateTest, NegotiateStateTest004, End");
};
} // namespace OHOS

View File

@ -15,9 +15,9 @@
#include "default_negotiate_channel_mock.h"
#include "securec.h"
#include "conn_log.h"
#include "softbus_error_code.h"
#include "softbus_adapter_mem.h"
#include "softbus_log_old.h"
static int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size)
{
@ -114,7 +114,7 @@ struct DefaultNegotiateChannel* DefaultNegotiateChannelNew(int64_t authId)
{
struct DefaultNegotiateChannel *self = (struct DefaultNegotiateChannel *)SoftBusCalloc(sizeof(*self));
if (!self) {
CLOGE("malloc failed");
CONN_LOGE(CONN_WIFI_DIRECT, "malloc failed");
return nullptr;
}
DefaultNegotiateChannelConstructor(self, authId);

View File

@ -16,9 +16,9 @@
#include <gtest/gtest.h>
#include <securec.h>
#include "conn_log.h"
#include "cJSON.h"
#include "json_protocol.h"
#include "softbus_log_old.h"
#include "softbus_adapter_mem.h"
#include "wifi_direct_protocol_factory.h"
#include "wifi_direct_protocol.h"
@ -64,7 +64,7 @@ static bool TrueMarShalling(InfoContainer *container, WifiDirectProtocol *base)
*/
HWTEST_F(WifiDirectProtocolTest, testWifiProtocol001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectProtocolTest, testWifiProtocol001, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectProtocolTest, testWifiProtocol001, Start");
WifiDirectMock wifiDirectMock;
struct WifiDirectProtocolFactory* factory = GetWifiDirectProtocolFactory();
struct WifiDirectProtocol *base = static_cast<struct WifiDirectProtocol*>(SoftBusCalloc(sizeof(*base)));
@ -102,7 +102,7 @@ HWTEST_F(WifiDirectProtocolTest, testWifiProtocol001, TestSize.Level1)
SoftBusFree(keyProperty);
SoftBusFree(data);
factory->destroyProtocol(protocol);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectProtocolTest, testWifiProtocol001, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectProtocolTest, testWifiProtocol001, End");
};
/* tlv_protocol.c */
@ -114,7 +114,7 @@ HWTEST_F(WifiDirectProtocolTest, testWifiProtocol001, TestSize.Level1)
*/
HWTEST_F(WifiDirectProtocolTest, testWifiProtocol002, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectProtocolTest, testWifiProtocol002, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectProtocolTest, testWifiProtocol002, Start");
struct WifiDirectProtocolFactory* factory = GetWifiDirectProtocolFactory();
struct WifiDirectProtocol *base = static_cast<struct WifiDirectProtocol*>(SoftBusCalloc(sizeof(*base)));
struct InfoContainer *container = static_cast<struct InfoContainer*>(SoftBusCalloc(sizeof(*container)));
@ -132,7 +132,7 @@ HWTEST_F(WifiDirectProtocolTest, testWifiProtocol002, TestSize.Level1)
SoftBusFree(base);
SoftBusFree(container);
SoftBusFree(outBuffer);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectProtocolTest, testWifiProtocol002, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectProtocolTest, testWifiProtocol002, End");
};
/*
@ -143,7 +143,7 @@ HWTEST_F(WifiDirectProtocolTest, testWifiProtocol002, TestSize.Level1)
*/
HWTEST_F(WifiDirectProtocolTest, testWifiProtocol003, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectProtocolTest, testWifiProtocol003, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectProtocolTest, testWifiProtocol003, Start");
struct WifiDirectProtocol *base = static_cast<struct WifiDirectProtocol*>(SoftBusCalloc(sizeof(*base)));
struct InfoContainerKeyProperty *keyProperty = static_cast<struct InfoContainerKeyProperty*>
(SoftBusCalloc(sizeof(*keyProperty)));
@ -169,6 +169,6 @@ HWTEST_F(WifiDirectProtocolTest, testWifiProtocol003, TestSize.Level1)
SoftBusFree(base);
SoftBusFree(keyProperty);
SoftBusFree(data);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectProtocolTest, testWifiProtocol003, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectProtocolTest, testWifiProtocol003, End");
};
} // namespace OHOS

View File

@ -16,8 +16,8 @@
#include <gtest/gtest.h>
#include <securec.h>
#include "conn_log.h"
#include "wifi_direct_ipv4_info.h"
#include "softbus_log_old.h"
#include "softbus_error_code.h"
#include "softbus_adapter_mem.h"
#include "wifi_direct_defines.h"
@ -89,7 +89,7 @@ void WifiDirectUtilsTest::TearDown(void) {}
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest001, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest001, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest001, Start");
struct WifiDirectPerfRecorder* self = GetWifiDirectPerfRecorder();
enum TimePointType type = TP_MAX;
self->calculate();
@ -116,7 +116,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest001, TestSize.Level1)
int32_t pid = PID;
self->setPid(PID);
EXPECT_EQ(self->getPid(), pid);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest001, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest001, End");
};
/* wifi_direct_utils.c */
@ -128,7 +128,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest001, TestSize.Level1)
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest002, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest002, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest002, Start");
struct WifiDirectUtils* self = GetWifiDirectUtils();
char banana = INVALID_CHAR;
@ -162,7 +162,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest002, TestSize.Level1)
ret = self->transferModeToRole(mode);
EXPECT_EQ(ret, WIFI_DIRECT_ROLE_INVALID);
SoftBusFree(data);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest002, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest002, End");
};
/*
@ -173,7 +173,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest002, TestSize.Level1)
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest003, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest003, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest003, Start");
struct WifiDirectUtils* self = GetWifiDirectUtils();
uint32_t data = TEST_DATA1;
@ -204,7 +204,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest003, TestSize.Level1)
role = WIFI_DIRECT_ROLE_INVALID;
ret = self->transferRoleToPreferLinkMode(role);
EXPECT_EQ(ret, WIFI_DIRECT_API_ROLE_GC | WIFI_DIRECT_API_ROLE_GO | WIFI_DIRECT_API_ROLE_HML);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest003, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest003, End");
};
/*
@ -215,7 +215,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest003, TestSize.Level1)
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest004, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest004, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest004, Start");
struct WifiDirectUtils* self = GetWifiDirectUtils();
char* string = static_cast<char *>(SoftBusCalloc(sizeof(*string)));
self->printLargeString(string);
@ -236,7 +236,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest004, TestSize.Level1)
SoftBusFree(string);
SoftBusFree(str1);
SoftBusFree(str2);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest004, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest004, End");
};
/* wifi_direct_network_utils.c */
@ -248,7 +248,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest004, TestSize.Level1)
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest005, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest005, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest005, Start");
struct WifiDirectNetWorkUtils* self = GetWifiDirectNetWorkUtils();
int32_t channel = CHANNEL_2G;
int32_t ret = self->channelToFrequency(channel);
@ -265,7 +265,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest005, TestSize.Level1)
ret = self->getLocalIpv4InfoArray(ipv4, &size);
EXPECT_TRUE(ret == SOFTBUS_OK);
SoftBusFree(ipv4);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest005, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest005, End");
};
/*
@ -276,7 +276,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest005, TestSize.Level1)
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest006, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest006, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest006, Start");
struct WifiDirectNetWorkUtils* self = GetWifiDirectNetWorkUtils();
int32_t array[ARRARY_COUNT] = {TEST_DATA1, TEST_DATA2};
int32_t *channelArray = array;
@ -286,7 +286,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest006, TestSize.Level1)
int32_t ret = self->channelListToString(channelArray, channelArraySize, channelListString, inSize);
EXPECT_TRUE(ret == SOFTBUS_ERR);
SoftBusFree(channelListString);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest006, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest006, End");
};
/*
@ -297,7 +297,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest006, TestSize.Level1)
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest007, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest007, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest007, Start");
struct WifiDirectNetWorkUtils* self = GetWifiDirectNetWorkUtils();
int32_t frequency = FREQUENCY_2G;
int32_t ret = self->frequencyToChannel(frequency);
@ -310,7 +310,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest007, TestSize.Level1)
frequency = FREQUENCY_INVALID_NUM;
ret = self->frequencyToChannel(frequency);
EXPECT_TRUE(ret == CHANNEL_INVALID);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest007, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest007, End");
};
/* wifi_direct_ipv4_info.c */
@ -322,7 +322,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest007, TestSize.Level1)
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest008, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest008, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest008, Start");
struct WifiDirectIpv4Info *ipv4 = static_cast<struct WifiDirectIpv4Info*>(SoftBusCalloc(sizeof(*ipv4)));
ipv4->address = TEST_DATA1;
ipv4->prefixLength = MIN_NUM;
@ -337,7 +337,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest008, TestSize.Level1)
uint8_t ipv4Bytes = MIN_NUM;
WifiDirectIpv4BytesToInfo(&ipv4Bytes, ipv4BytesLen, ipv4, &ipv4Count);
SoftBusFree(ipv4);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest008, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest008, End");
};
/*
@ -348,7 +348,7 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest008, TestSize.Level1)
*/
HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest009, TestSize.Level1)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest009, Start");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest009, Start");
struct WifiDirectIpv4Info *ipv4 = static_cast<struct WifiDirectIpv4Info*>(SoftBusCalloc(sizeof(*ipv4)));
ipv4->address = TEST_DATA1;
ipv4->prefixLength = MIN_NUM;
@ -364,6 +364,6 @@ HWTEST_F(WifiDirectUtilsTest, testDirectUtilsTest009, TestSize.Level1)
ipv4Count = MIN_NUM;
WifiDirectIpv4BytesToInfo(&ipv4Bytes, ipv4BytesLen, ipv4, &ipv4Count);
SoftBusFree(ipv4);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "WifiDirectUtilsTest, testDirectUtilsTest009, End");
CONN_LOGI(CONN_WIFI_DIRECT, "WifiDirectUtilsTest, testDirectUtilsTest009, End");
};
} //namespace OHOS

View File

@ -63,7 +63,6 @@ ohos_unittest("DiscBleTest") {
include_dirs += test_utils_inc
deps = [
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"$dsoftbus_root_path/adapter:softbus_adapter",
"$dsoftbus_root_path/core/common:softbus_utils",
"//third_party/googletest:gmock",

View File

@ -148,39 +148,42 @@ public:
static inline uint8_t btMacAddr[] = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
static inline uint8_t activeDiscoveryAdvData[] = {
0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04,
0x05, 0x90, 0x00, 0x01, 0x02, 0x00, 0x18, 0x64,
0x30, 0x31, 0x35, 0x35, 0x39, 0x62, 0x62, 0x21,
0x0E
0x02, 0x01, 0x02, 0x1B, 0x16, 0xEE, 0xFD, 0x04,
0x05, 0x90, 0x00, 0x01, 0x02, 0x00, 0x18, 0xE8,
0x31, 0xF7, 0x63, 0x0B, 0x76, 0x19, 0xAE, 0x21,
0x0E, 0x3A, 0x4D, 0x79, 0x20, 0x44, 0x65
};
static inline uint8_t activeDiscoveryAdvData2[] = {
0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04,
0x05, 0x90, 0x00, 0x01, 0x12, 0x00, 0x18, 0x64,
0x30, 0x31, 0x35, 0x35, 0x39, 0x62, 0x62, 0x21,
0x0E
0x02, 0x01, 0x02, 0x1B, 0x16, 0xEE, 0xFD, 0x04,
0x05, 0x90, 0x00, 0x01, 0x12, 0x00, 0x18, 0xE8,
0x31, 0xF7, 0x63, 0x0B, 0x76, 0x19, 0xAE, 0x21,
0x0E, 0x3A, 0x4D, 0x79, 0x20, 0x44, 0x65
};
static inline uint8_t activeDiscoveryRspData[] = {
0x03, 0xFF, 0x7D, 0x02
0x08, 0xFF, 0x7D, 0x02, 0x76, 0x69, 0x63, 0x65,
0x00
};
static inline uint8_t activePublishAdvData[] = {
0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04,
0x05, 0x10, 0x00, 0x01, 0x02, 0x00, 0x18, 0x64,
0x30, 0x31, 0x35, 0x35, 0x39, 0x62, 0x62, 0x21,
0x0E
0x02, 0x01, 0x02, 0x1B, 0x16, 0xEE, 0xFD, 0x04,
0x05, 0x10, 0x00, 0x01, 0x02, 0x00, 0x18, 0xE8,
0x31, 0xF7, 0x63, 0x0B, 0x76, 0x19, 0xAE, 0x21,
0x0E, 0x3A, 0x4D, 0x79, 0x20, 0x44, 0x65
};
static inline uint8_t activePublishRspData[] = {
0x03, 0xFF, 0x7D, 0x02
0x08, 0xFF, 0x7D, 0x02, 0x76, 0x69, 0x63, 0x65,
0x00
};
static inline uint8_t passivePublishAdvData[] = {
0x02, 0x01, 0x02, 0x1B, 0x16, 0xEE, 0xFD, 0x04,
0x05, 0x10, 0x00, 0x01, 0x02, 0x00, 0x18, 0x64,
0x30, 0x31, 0x35, 0x35, 0x39, 0x62, 0x62, 0x21,
0x0E, 0x56, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x05, 0x10, 0x00, 0x01, 0x02, 0x00, 0x18, 0xE8,
0x31, 0xF7, 0x63, 0x0B, 0x76, 0x19, 0xAE, 0x21,
0x0E, 0x56, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E
};
static inline uint8_t passivePublishRspData[] = {
0x04, 0xFF, 0x7D, 0x02, 0x0F
0x0F, 0xFF, 0x7D, 0x02, 0x0F, 0x3A, 0x4D, 0x79,
0x20, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x00
};
private:

View File

@ -52,7 +52,7 @@ public:
static inline std::string g_customCapData = "name=Bill";
static inline DeviceInfo g_foundDeviceInfo;
static constexpr char FOUND_DEVICE_ID[] = "d01559bb";
static constexpr char FOUND_DEVICE_ID[] = "e831f7630b7619ae";
};
static void OnDeviceFound(const DeviceInfo *device, const InnerDeviceInfoAddtions *addtions)
@ -454,8 +454,6 @@ HWTEST_F(DiscBleTest, ReceiveActiveDiscoveryPacket001, TestSize.Level1)
BleMock::InjectActiveConPacket();
EXPECT_EQ(bleMock.GetAsyncAdvertiseResult(), true);
BleMock::InjectActiveConPacket();
DISC_LOGI(DISC_TEST, "ReceiveActiveDiscoveryPacket001 end ----");
}

View File

@ -0,0 +1,66 @@
# 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.
import("//build/test.gni")
import("../../../../dsoftbus.gni")
import("../../../../sdk/frame/frame_sdk.gni")
module_output_path = "dsoftbus/transmission"
dsoftbus_root_path = "../../../../"
ohos_unittest("SoftBusFrameStandardTest") {
module_out_path = module_output_path
sources = [ "softbus_frame_standard_test.cpp" ]
include_dirs = [
"${dsoftbus_root_path}/core/frame/standard/init/include",
"${dsoftbus_root_path}/interfaces/kits/common",
"${dsoftbus_root_path}/interfaces/kits/discovery",
"${dsoftbus_root_path}/sdk/bus_center/manager/include",
"${dsoftbus_root_path}/sdk/discovery/manager/include",
"${dsoftbus_root_path}/sdk/frame/common/include",
"${dsoftbus_root_path}/sdk/frame/standard/include",
"${dsoftbus_root_path}/sdk/frame/standard/src",
"${dsoftbus_root_path}/sdk/transmission/session/include",
"${dsoftbus_root_path}/sdk/transmission/trans_channel/manager/include",
]
deps = [
"${dsoftbus_root_path}/core/common:softbus_utils",
"${dsoftbus_root_path}/core/frame:softbus_server",
"${dsoftbus_root_path}/sdk:softbus_client",
"//third_party/googletest:gtest",
"//third_party/googletest:gtest_main",
]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",
]
} else {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
}
}
group("unittest") {
testonly = true
deps = []
deps += [
# deps file
":SoftBusFrameStandardTest",
]
}

View File

@ -0,0 +1,488 @@
/*
* 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 <gtest/gtest.h>
#include <securec.h>
#include "softbus_client_death_recipient.cpp"
#include "softbus_client_frame_manager.h"
#define private public
#define protected public
#include "softbus_client_stub.cpp"
#include "softbus_client_stub.h"
#undef private
#undef protected
#include "softbus_server_proxy_frame.cpp"
#include "softbus_server_proxy_standard.h"
using namespace std;
using namespace testing::ext;
using namespace OHOS;
namespace OHOS {
class SoftBusServerProxyFrameTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
};
class SoftBusClientStubMock : public SoftBusClientStub {
public:
void OnDeviceFound([[maybe_unused]] const DeviceInfo *device) override { }
void OnDiscoverFailed([[maybe_unused]] int subscribeId, [[maybe_unused]] int failReason) override { }
void OnDiscoverySuccess([[maybe_unused]] int subscribeId) override { }
void OnPublishSuccess([[maybe_unused]] int publishId) override { }
void OnPublishFail([[maybe_unused]] int publishId, [[maybe_unused]] int reason) override { }
int32_t OnChannelOpenFailed([[maybe_unused]] int32_t channelId, [[maybe_unused]] int32_t channelType,
[[maybe_unused]] int32_t errCode) override
{
return SOFTBUS_OK;
}
int32_t OnChannelLinkDown([[maybe_unused]] const char *networkId, [[maybe_unused]] int32_t routeType) override
{
return SOFTBUS_OK;
}
int32_t OnChannelClosed([[maybe_unused]] int32_t channelId, [[maybe_unused]] int32_t channelType) override
{
return SOFTBUS_OK;
}
int32_t OnChannelMsgReceived([[maybe_unused]] int32_t channelId, [[maybe_unused]] int32_t channelType,
[[maybe_unused]] const void *data, [[maybe_unused]] uint32_t len, [[maybe_unused]] int32_t type) override
{
return SOFTBUS_OK;
}
};
namespace {
sptr<SoftBusClientStubMock> g_stub = nullptr;
}
void SoftBusServerProxyFrameTest::SetUpTestCase()
{
g_stub = new (std::nothrow) SoftBusClientStubMock();
}
void SoftBusServerProxyFrameTest::TearDownTestCase()
{
g_stub = nullptr;
}
/**
* @tc.name: InnerRegisterServiceTest
* @tc.desc: InnerRegisterServiceTest, Initialization failure
* @tc.desc: InnerRegisterServiceTest, Successful initialization
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, InnerRegisterServiceTest, TestSize.Level1)
{
EXPECT_EQ(InnerRegisterService(), SOFTBUS_INVALID_PARAM);
EXPECT_EQ(ServerProxyInit(), SOFTBUS_OK);
EXPECT_EQ(InitSoftBus("SoftBusServerProxyFrameTest"), SOFTBUS_OK);
EXPECT_EQ(InnerRegisterService(), SOFTBUS_OK);
}
/**
* @tc.name: GetSystemAbilityTest
* @tc.desc: GetSystemAbilityTest, Get interface return is not empty
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, GetSystemAbilityTest, TestSize.Level1)
{
EXPECT_TRUE(GetSystemAbility() != nullptr);
}
/**
* @tc.name: ClientRegisterServiceTest
* @tc.desc: ClientRegisterServiceTest, Initializing registration succeeded. Procedure
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, ClientRegisterServiceTest, TestSize.Level1)
{
EXPECT_EQ(ServerProxyInit(), SOFTBUS_OK);
EXPECT_EQ(ClientRegisterService("ClientRegisterServiceTest"), SOFTBUS_OK);
}
/**
* @tc.name: ClientStubInitTest
* @tc.desc: ClientStubInitTest, Successful initialization
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, ClientStubInitTest, TestSize.Level1)
{
EXPECT_EQ(ClientStubInit(), SOFTBUS_OK);
}
/**
* @tc.name: SoftbusRegisterServiceTest
* @tc.desc: SoftbusRegisterServiceTest, remote is nullptr return SOFTBUS_ERR
* @tc.desc: SoftbusRegisterServiceTest, SoftbusRegisterService success return SOFTBUS_OK
* @tc.desc: SoftbusRegisterServiceTest, clientPkgName is nullptr return SOFTBUS_ERR
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, SoftbusRegisterServiceTest, TestSize.Level1)
{
sptr<SoftBusServerProxyFrame> serverProxyFrame = new (std::nothrow) SoftBusServerProxyFrame(nullptr);
ASSERT_TRUE(serverProxyFrame != nullptr);
EXPECT_EQ(serverProxyFrame->SoftbusRegisterService("SoftbusRegisterServiceTest", nullptr), SOFTBUS_ERR);
sptr<IRemoteObject> serverProxy = GetSystemAbility();
ASSERT_TRUE(serverProxy != nullptr);
serverProxyFrame = new (std::nothrow) SoftBusServerProxyFrame(serverProxy);
ASSERT_TRUE(serverProxyFrame != nullptr);
EXPECT_EQ(serverProxyFrame->SoftbusRegisterService("SoftbusRegisterServiceTest", nullptr), SOFTBUS_OK);
EXPECT_EQ(serverProxyFrame->SoftbusRegisterService(nullptr, nullptr), SOFTBUS_ERR);
}
/**
* @tc.name: OnRemoteRequestTest
* @tc.desc: OnRemoteRequestTest, ReadInterfaceToken faild return SOFTBUS_ERR
* @tc.desc: OnRemoteRequestTest, OnRemoteRequest Call default return IPC_STUB_UNKNOW_TRANS_ERR
* @tc.desc: OnRemoteRequestTest, OnRemoteRequest Call CLIENT_ON_PERMISSION_CHANGE
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnRemoteRequestTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
uint32_t code = 0;
MessageParcel data;
MessageParcel reply;
MessageOption option;
EXPECT_EQ(g_stub->OnRemoteRequest(code, data, reply, option), SOFTBUS_ERR);
data.WriteInterfaceToken(g_stub->GetDescriptor());
EXPECT_EQ(g_stub->OnRemoteRequest(code, data, reply, option), IPC_STUB_UNKNOW_TRANS_ERR);
code = CLIENT_ON_PERMISSION_CHANGE;
data.WriteInterfaceToken(g_stub->GetDescriptor());
data.WriteInt32(0);
data.WriteCString("OnRemoteRequestTest");
EXPECT_EQ(g_stub->OnRemoteRequest(code, data, reply, option), SOFTBUS_OK);
}
/**
* @tc.name: OnClientPermissonChangeInnerTest
* @tc.desc: OnClientPermissonChangeInnerTest, ReadInt32 faild return SOFTBUS_ERR
* @tc.desc: OnClientPermissonChangeInnerTest, ReadCString faild return SOFTBUS_ERR
* @tc.desc: OnClientPermissonChangeInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnClientPermissonChangeInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
EXPECT_EQ(g_stub->OnClientPermissonChangeInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnClientPermissonChangeInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
data.WriteCString("OnClientPermissonChangeInnerTest");
EXPECT_EQ(g_stub->OnClientPermissonChangeInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnDeviceFoundInnerTest
* @tc.desc: OnDeviceFoundInnerTest, ReadBuffer faild return SOFTBUS_ERR
* @tc.desc: OnDeviceFoundInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnDeviceFoundInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
EXPECT_EQ(g_stub->OnDeviceFoundInner(data, reply), SOFTBUS_ERR);
DeviceInfo info;
data.WriteBuffer(&info, sizeof(DeviceInfo));
EXPECT_EQ(g_stub->OnDeviceFoundInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnDiscoverFailedInnerTest
* @tc.desc: OnDiscoverFailedInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnDiscoverFailedInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
data.WriteInt32(0);
data.WriteInt32(99);
EXPECT_EQ(g_stub->OnDiscoverFailedInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnDiscoverySuccessInnerTest
* @tc.desc: OnDiscoverySuccessInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnDiscoverySuccessInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnDiscoverySuccessInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnPublishSuccessInnerTest
* @tc.desc: OnPublishSuccessInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnPublishSuccessInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnPublishSuccessInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnPublishFailInnerTest
* @tc.desc: OnPublishFailInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnPublishFailInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
data.WriteInt32(0);
data.WriteInt32(99);
EXPECT_EQ(g_stub->OnPublishFailInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnChannelOpenedInnerTest001
* @tc.desc: OnChannelOpenedInnerTest001, MessageParcel read failed return SOFTBUS_ERR
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnChannelOpenedInnerTest001, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
MessageParcel tempData;
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelOpenedInnerTest");
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelOpenedInnerTest");
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelOpenedInnerTest");
data.WriteInt32(0);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelOpenedInnerTest");
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteBool(false);
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelOpenedInnerTest");
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteBool(false);
data.WriteBool(true);
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelOpenedInnerTest");
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteBool(false);
data.WriteBool(true);
data.WriteBool(false);
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
}
/**
* @tc.name: OnChannelOpenedInnerTest002
* @tc.desc: OnChannelOpenedInnerTest002, MessageParcel read failed return SOFTBUS_ERR
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnChannelOpenedInnerTest002, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
data.WriteCString("OnChannelOpenedInnerTest");
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteBool(false);
data.WriteBool(true);
data.WriteBool(false);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelOpenedInnerTest");
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteBool(false);
data.WriteBool(true);
data.WriteBool(false);
data.WriteInt32(0);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelOpenedInnerTest");
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteBool(false);
data.WriteBool(true);
data.WriteBool(false);
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteCString("OnChannelOpenedInnerTest");
EXPECT_EQ(g_stub->OnChannelOpenedInner(data, reply), SOFTBUS_ERR);
}
/**
* @tc.name: OnChannelOpenFailedInnerTest
* @tc.desc: OnChannelOpenFailedInnerTest, ReadInt32 failed return SOFTBUS_ERR
* @tc.desc: OnChannelOpenFailedInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnChannelOpenFailedInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
EXPECT_EQ(g_stub->OnChannelOpenFailedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelOpenFailedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
data.WriteInt32(99);
EXPECT_EQ(g_stub->OnChannelOpenFailedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelOpenFailedInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnChannelLinkDownInnerTest
* @tc.desc: OnChannelLinkDownInnerTest, ReadCString failed return SOFTBUS_ERR
* @tc.desc: OnChannelLinkDownInnerTest, ReadInt32 failed return SOFTBUS_ERR
* @tc.desc: OnChannelLinkDownInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnChannelLinkDownInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
EXPECT_EQ(g_stub->OnChannelLinkDownInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelLinkDownInnerTest");
EXPECT_EQ(g_stub->OnChannelLinkDownInner(data, reply), SOFTBUS_ERR);
data.WriteCString("OnChannelLinkDownInnerTest");
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelLinkDownInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnChannelClosedInnerTest
* @tc.desc: OnChannelClosedInnerTest, ReadInt32 failed return SOFTBUS_ERR
* @tc.desc: OnChannelClosedInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnChannelClosedInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
EXPECT_EQ(g_stub->OnChannelClosedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelClosedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelClosedInner(data, reply), SOFTBUS_OK);
}
/**
* @tc.name: OnChannelMsgReceivedInnerTest
* @tc.desc: OnChannelMsgReceivedInnerTest, MessageParcel failed return SOFTBUS_ERR
* @tc.desc: OnChannelMsgReceivedInnerTest, success return SOFTBUS_OK
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftBusServerProxyFrameTest, OnChannelMsgReceivedInnerTest, TestSize.Level1)
{
ASSERT_TRUE(g_stub != nullptr);
MessageParcel data;
MessageParcel reply;
EXPECT_EQ(g_stub->OnChannelMsgReceivedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelMsgReceivedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelMsgReceivedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteUint32(0);
EXPECT_EQ(g_stub->OnChannelMsgReceivedInner(data, reply), SOFTBUS_ERR);
std::string buffer = "OnChannelMsgReceivedInnerTest";
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteUint32(buffer.size());
data.WriteRawData(buffer.c_str(), buffer.size());
EXPECT_EQ(g_stub->OnChannelMsgReceivedInner(data, reply), SOFTBUS_ERR);
data.WriteInt32(0);
data.WriteInt32(0);
data.WriteUint32(buffer.size());
data.WriteRawData(buffer.c_str(), buffer.size());
data.WriteInt32(0);
EXPECT_EQ(g_stub->OnChannelMsgReceivedInner(data, reply), SOFTBUS_OK);
}
} // namespace OHOS