feat: broadcast mgr error code

Signed-off-by: JanierVan <fanjingya1@huawei.com>
This commit is contained in:
JanierVan 2024-04-11 14:41:07 +08:00
parent 916f8eaa1f
commit 219db9bfaf
4 changed files with 196 additions and 103 deletions

View File

@ -175,9 +175,10 @@ int32_t InitBroadcastMgr(void)
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "lock init fail!");
SoftbusBleAdapterInit();
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->Init != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
ret = g_interface[g_interfaceId]->Init();
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "call from adapter fail!");
@ -205,7 +206,7 @@ int32_t DeInitBroadcastMgr(void)
DISC_LOGI(DISC_BLE, "enter.");
DISC_CHECK_AND_RETURN_RET_LOGW(g_interface[g_interfaceId] != NULL, SOFTBUS_OK, DISC_BLE, "already deinit!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->DeInit != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
if (CheckLockIsInit(&g_bcLock)) {
(void)SoftBusMutexDestroy(&g_bcLock);
@ -513,7 +514,8 @@ static int32_t BuildBroadcastPacket(const SoftbusBroadcastData *softbusBcData, B
int32_t maxPayloadLen = (softbusBcData->isSupportFlag) ? BC_DATA_MAX_LEN : (BC_DATA_MAX_LEN + BC_FLAG_LEN);
int32_t ret = BuildBcPayload(maxPayloadLen, &(softbusBcData->bcData), &(packet->bcData));
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "build broadcast payload failed!");
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_BC_MGR_BUILD_ADV_PACKT_FAIL,
DISC_BLE, "build broadcast payload failed!");
DumpSoftbusData("scan result bcData", softbusBcData->bcData.payloadLen, softbusBcData->bcData.payload);
@ -527,7 +529,7 @@ static int32_t BuildBroadcastPacket(const SoftbusBroadcastData *softbusBcData, B
if (ret != SOFTBUS_OK) {
SoftBusFree(packet->bcData.payload);
DISC_LOGE(DISC_BLE, "build broadcast rsp payload failed!");
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_BUILD_RSP_PACKT_FAIL;
}
DumpSoftbusData("scan result rspData", softbusBcData->rspData.payloadLen, softbusBcData->rspData.payload);
}
@ -660,19 +662,24 @@ static SoftbusScanCallback g_softbusBcBleScanCb = {
.OnLpDeviceInfoCallback = BcLpDeviceInfoCallback,
};
static bool IsSrvTypeValid(BaseServiceType srvType)
{
return srvType >= 0 && srvType < SRV_TYPE_BUTT;
}
int32_t RegisterBroadcaster(BaseServiceType srvType, int32_t *bcId, const BroadcastCallback *cb)
{
static uint32_t callCount = 0;
DISC_LOGI(DISC_BLE, "enter. callCount=%{public}u", callCount++);
int32_t ret = SOFTBUS_OK;
int32_t adapterBcId = -1;
DISC_CHECK_AND_RETURN_RET_LOGE(srvType >= 0 && srvType < SRV_TYPE_BUTT, SOFTBUS_INVALID_PARAM, DISC_BLE,
"srvType is invalid!");
DISC_CHECK_AND_RETURN_RET_LOGE(IsSrvTypeValid(srvType), SOFTBUS_BC_MGR_INVALID_SRV, DISC_BLE, "srvType invalid!");
DISC_CHECK_AND_RETURN_RET_LOGE(bcId != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "invalid param bcId!");
DISC_CHECK_AND_RETURN_RET_LOGE(cb != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "invalid param cb!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->RegisterBroadcaster != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
ret = SoftBusMutexLock(&g_bcLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
ret = g_interface[g_interfaceId]->RegisterBroadcaster(&adapterBcId, &g_softbusBcBleCb);
@ -691,7 +698,7 @@ int32_t RegisterBroadcaster(BaseServiceType srvType, int32_t *bcId, const Broadc
if (managerId == BC_NUM_MAX) {
DISC_LOGE(DISC_BLE, "no available adv manager");
SoftBusMutexUnlock(&g_bcLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_REG_NO_AVAILABLE_BC_ID;
}
DISC_LOGD(DISC_BLE,
"srvType=%{public}s, bcId=%{public}d, adapterBcId=%{public}d", GetSrvType(srvType), managerId, adapterBcId);
@ -725,9 +732,10 @@ static bool CheckBcIdIsValid(int32_t bcId)
int32_t UnRegisterBroadcaster(int32_t bcId)
{
DISC_LOGI(DISC_BLE, "enter.");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->UnRegisterBroadcaster != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = SoftBusMutexLock(&g_bcLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
@ -813,15 +821,15 @@ int32_t RegisterScanListener(BaseServiceType srvType, int32_t *listenerId, const
DISC_LOGI(DISC_BLE, "enter. callCount=%{public}u", callCount++);
int32_t ret = SOFTBUS_OK;
int32_t adapterScanId = -1;
DISC_CHECK_AND_RETURN_RET_LOGE(srvType >= 0 && srvType < SRV_TYPE_BUTT, SOFTBUS_INVALID_PARAM, DISC_BLE,
"srvType is invalid!");
DISC_CHECK_AND_RETURN_RET_LOGE(IsSrvTypeValid(srvType), SOFTBUS_BC_MGR_INVALID_SRV, DISC_BLE, "srvType invalid!");
DISC_CHECK_AND_RETURN_RET_LOGE(listenerId != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "invalid param listenerId!");
DISC_CHECK_AND_RETURN_RET_LOGE(cb != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "invalid param cb!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->RegisterScanListener != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(!CheckSrvRegistered(srvType), SOFTBUS_ERR, DISC_BLE, "already registered!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(!CheckSrvRegistered(srvType), SOFTBUS_BC_MGR_REG_DUP,
DISC_BLE, "already registered!");
ret = SoftBusMutexLock(&g_scanLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
@ -841,7 +849,7 @@ int32_t RegisterScanListener(BaseServiceType srvType, int32_t *listenerId, const
if (managerId == SCAN_NUM_MAX) {
DISC_LOGE(DISC_BLE, "no available scanner");
SoftBusMutexUnlock(&g_scanLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_REG_NO_AVAILABLE_LISN_ID;
}
DISC_LOGD(DISC_BLE, "srvType=%{public}s, listenerId=%{public}d, adapterScanId=%{public}d",
GetSrvType(srvType), managerId, adapterScanId);
@ -1117,9 +1125,10 @@ static int32_t CheckAndStopScan(int32_t listenerId)
int32_t UnRegisterScanListener(int32_t listenerId)
{
DISC_LOGI(DISC_BLE, "enter. listenerId=%{public}d", listenerId);
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->UnRegisterScanListener != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = SoftBusMutexLock(&g_scanLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
if (!CheckScanIdIsValid(listenerId)) {
@ -1160,7 +1169,6 @@ int32_t UnRegisterScanListener(int32_t listenerId)
g_scanManager[listenerId].freq = SCAN_FREQ_LOW_POWER;
g_scanManager[listenerId].scanCallback = NULL;
g_scanManager[listenerId].isScanning = false;
SoftBusMutexUnlock(&g_scanLock);
return SOFTBUS_OK;
}
@ -1201,10 +1209,8 @@ static void DumpBroadcastPacket(const BroadcastPayload *bcData, const BroadcastP
static int32_t SoftBusCondWaitTwoSec(int32_t bcId, SoftBusMutex *mutex)
{
SoftBusSysTime absTime = {0};
if (SoftBusGetTime(&absTime) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "softbus get time failed");
return SOFTBUS_ERR;
}
int32_t ret = SoftBusGetTime(&absTime);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "softbus get time failed");
absTime.sec += BC_WAIT_TIME_SEC;
if (SoftBusCondWait(&g_bcManager[bcId].cond, mutex, &absTime) != SOFTBUS_OK) {
@ -1285,22 +1291,22 @@ int32_t StartBroadcasting(int32_t bcId, const BroadcastParam *param, const Broad
DISC_CHECK_AND_RETURN_RET_LOGE(packet != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "invalid param packet!");
DISC_CHECK_AND_RETURN_RET_LOGE(packet->bcData.payload != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE,
"invalid param payload!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->StartBroadcasting != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = SoftBusMutexLock(&g_bcLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
if (!CheckBcIdIsValid(bcId)) {
SoftBusMutexUnlock(&g_bcLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_INVALID_BC_ID;
}
if (g_bcManager[bcId].isAdvertising) {
DISC_LOGW(DISC_BLE, "wait condition managerId=%{public}d", bcId);
if (SoftBusCondWaitTwoSec(bcId, &g_bcLock) != SOFTBUS_OK) {
DISC_LOGE(DISC_BLE, "SoftBusCondWaitTwoSec failed");
SoftBusMutexUnlock(&g_bcLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_WAIT_COND_FAIL;
}
}
@ -1346,22 +1352,23 @@ int32_t SetBroadcastingData(int32_t bcId, const BroadcastPacket *packet)
static uint32_t callCount = 0;
DISC_LOGI(DISC_BLE, "enter. bcId=%{public}d, callCount=%{public}u", bcId, callCount++);
DISC_CHECK_AND_RETURN_RET_LOGE(packet != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "invalid param packet!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->SetBroadcastingData != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = SoftBusMutexLock(&g_bcLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
if (!CheckBcIdIsValid(bcId)) {
SoftBusMutexUnlock(&g_bcLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_INVALID_BC_ID;
}
if (!g_bcManager[bcId].isAdvertising) {
DISC_LOGW(DISC_BLE, "bcId=%{public}d is not advertising", bcId);
SoftBusMutexUnlock(&g_bcLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_NOT_BROADCASTING;
}
DISC_LOGI(DISC_BLE, "replace BroadcastPacket srvType=%{public}s, bcId=%{public}d, adapterId=%{public}d",
@ -1390,10 +1397,11 @@ int32_t StopBroadcasting(int32_t bcId)
{
static uint32_t callCount = 0;
DISC_LOGI(DISC_BLE, "enter. bcId=%{public}d, callCount=%{public}u", bcId, callCount++);
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->StopBroadcasting != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(CheckBcIdIsValid(bcId), SOFTBUS_ERR, DISC_BLE, "invalid bcId");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(CheckBcIdIsValid(bcId), SOFTBUS_BC_MGR_INVALID_BC_ID, DISC_BLE, "invalid bcId");
int64_t time = MgrGetSysTime();
if (time - g_bcManager[bcId].time < BC_WAIT_TIME_MICROSEC) {
@ -1444,9 +1452,10 @@ static int32_t GetScanFreq(uint16_t scanInterval, uint16_t scanWindow)
static bool NeedUpdateScan(int32_t listenerId)
{
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->StopScan != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
bool isNeedReset = false;
bool isScanning = false;
int32_t adapterScanId = g_scanManager[listenerId].adapterScanId;
@ -1493,7 +1502,7 @@ static int32_t StartScanSub(int32_t listenerId)
}
DISC_LOGD(DISC_BLE, "need update scan");
GetBcScanFilters(listenerId, &adapterFilter, &filterSize);
DISC_CHECK_AND_RETURN_RET_LOGE(filterSize > 0, SOFTBUS_ERR, DISC_BLE, "fitersize is 0!");
DISC_CHECK_AND_RETURN_RET_LOGE(filterSize > 0, SOFTBUS_BC_MGR_START_SCAN_NO_FILTER, DISC_BLE, "fitersize is 0!");
DumpBcScanFilter(adapterFilter, filterSize);
DISC_LOGI(DISC_BLE, "start service srvType=%{public}s, listenerId=%{public}d, adapterId=%{public}d",
@ -1515,9 +1524,10 @@ int32_t StartScan(int32_t listenerId, const BcScanParams *param)
static uint32_t callCount = 0;
DISC_LOGI(DISC_BLE, "enter. listenerId=%{public}d, callCount=%{public}u", listenerId, callCount++);
DISC_CHECK_AND_RETURN_RET_LOGE(param != NULL, SOFTBUS_INVALID_PARAM, DISC_BLE, "invalid param!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->StartScan != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = SoftBusMutexLock(&g_scanLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
@ -1525,7 +1535,7 @@ int32_t StartScan(int32_t listenerId, const BcScanParams *param)
if (!CheckScanIdIsValid(listenerId)) {
DISC_LOGE(DISC_BLE, "invalid param listenerId. listenerId=%{public}d", listenerId);
SoftBusMutexUnlock(&g_scanLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_INVALID_LISN_ID;
}
g_scanManager[listenerId].param = *param;
@ -1548,9 +1558,10 @@ int32_t StopScan(int32_t listenerId)
{
static uint32_t callCount = 0;
DISC_LOGI(DISC_BLE, "enter. listenerId=%{public}d, callCount=%{public}u", listenerId, callCount++);
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->StopScan != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = SoftBusMutexLock(&g_scanLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
@ -1558,7 +1569,7 @@ int32_t StopScan(int32_t listenerId)
if (!CheckScanIdIsValid(listenerId)) {
DISC_LOGE(DISC_BLE, "invalid param listenerId. listenerId=%{public}d", listenerId);
SoftBusMutexUnlock(&g_scanLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_INVALID_LISN_ID;
}
if (!g_scanManager[listenerId].isScanning) {
DISC_LOGI(DISC_BLE, "listenerId is not scanning. listenerId=%{public}d", listenerId);
@ -1590,7 +1601,7 @@ int32_t SetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_
if (!CheckScanIdIsValid(listenerId)) {
DISC_LOGE(DISC_BLE, "invalid param listenerId. listenerId=%{public}d", listenerId);
SoftBusMutexUnlock(&g_scanLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_INVALID_LISN_ID;
}
ReleaseBcScanFilter(listenerId);
@ -1615,7 +1626,7 @@ int32_t GetScanFilter(int32_t listenerId, BcScanFilter **scanFilter, uint8_t *fi
if (!CheckScanIdIsValid(listenerId)) {
DISC_LOGE(DISC_BLE, "invalid param listenerId. listenerId=%{public}d", listenerId);
SoftBusMutexUnlock(&g_scanLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_INVALID_LISN_ID;
}
*scanFilter = g_scanManager[listenerId].filter;
@ -1692,9 +1703,10 @@ bool BroadcastSetAdvDeviceParam(const LpBroadcastParam *bcParam, const LpScanPar
int32_t BroadcastGetBroadcastHandle(int32_t bcId, int32_t *bcHandle)
{
DISC_LOGI(DISC_BLE, "enter.");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->GetBroadcastHandle != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = g_interface[g_interfaceId]->GetBroadcastHandle(g_bcManager[bcId].adapterBcId, bcHandle);
if (ret != SOFTBUS_OK) {
@ -1707,9 +1719,10 @@ int32_t BroadcastGetBroadcastHandle(int32_t bcId, int32_t *bcHandle)
int32_t BroadcastEnableSyncDataToLpDevice(void)
{
DISC_LOGI(DISC_BLE, "enter.");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->EnableSyncDataToLpDevice != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = g_interface[g_interfaceId]->EnableSyncDataToLpDevice();
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "call from adapter fail!");
@ -1719,9 +1732,10 @@ int32_t BroadcastEnableSyncDataToLpDevice(void)
int32_t BroadcastDisableSyncDataToLpDevice(void)
{
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->DisableSyncDataToLpDevice != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = g_interface[g_interfaceId]->DisableSyncDataToLpDevice();
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "call from adapter fail!");
@ -1731,9 +1745,10 @@ int32_t BroadcastDisableSyncDataToLpDevice(void)
int32_t BroadcastSetScanReportChannelToLpDevice(int32_t listenerId, bool enable)
{
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->SetScanReportChannelToLpDevice != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = SoftBusMutexLock(&g_scanLock);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, SOFTBUS_LOCK_ERR, DISC_BLE, "mutex err!");
@ -1741,7 +1756,7 @@ int32_t BroadcastSetScanReportChannelToLpDevice(int32_t listenerId, bool enable)
if (!CheckScanIdIsValid(listenerId)) {
DISC_LOGE(DISC_BLE, "invalid param listenerId. listenerId=%{public}d", listenerId);
SoftBusMutexUnlock(&g_scanLock);
return SOFTBUS_ERR;
return SOFTBUS_BC_MGR_INVALID_LISN_ID;
}
ret = g_interface[g_interfaceId]->SetScanReportChannelToLpDevice(g_scanManager[listenerId].adapterScanId, enable);
@ -1758,9 +1773,10 @@ int32_t BroadcastSetLpAdvParam(int32_t duration, int32_t maxExtAdvEvents, int32_
int32_t interval, int32_t bcHandle)
{
DISC_LOGI(DISC_BLE, "enter.");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_ERR, DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId] != NULL, SOFTBUS_BC_MGR_NO_FUNC_REGISTERED,
DISC_BLE, "interface is null!");
DISC_CHECK_AND_RETURN_RET_LOGE(g_interface[g_interfaceId]->SetLpDeviceParam != NULL,
SOFTBUS_ERR, DISC_BLE, "function is null!");
SOFTBUS_BC_MGR_FUNC_NULL, DISC_BLE, "function is null!");
int32_t ret = g_interface[g_interfaceId]->SetLpDeviceParam(duration, maxExtAdvEvents, window, interval, bcHandle);
DISC_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, DISC_BLE, "call from adapter fail!");

View File

@ -901,7 +901,7 @@ static int32_t StartAdvertiser(int32_t adv)
DfxRecordAdevertiserEnd(adv, ret);
DestroyBleConfigAdvData(&packet);
DISC_LOGE(DISC_BLE, "start adv failed, adv=%{public}d", adv);
return SOFTBUS_DISCOVER_START_BROADCAST_FAIL;
return SOFTBUS_DISCOVER_BLE_START_BROADCAST_FAIL;
}
DfxRecordAdevertiserEnd(adv, SOFTBUS_OK);
UpdateInfoManager(adv, false);
@ -953,7 +953,7 @@ static int32_t UpdateAdvertiser(int32_t adv)
if (UpdateBroadcasting(advertiser->channel, &advParam, &packet) != SOFTBUS_OK) {
DestroyBleConfigAdvData(&packet);
DISC_LOGE(DISC_BLE, "UpdateAdv failed");
return SOFTBUS_DISCOVER_START_BROADCAST_FAIL;
return SOFTBUS_DISCOVER_BLE_START_BROADCAST_FAIL;
}
UpdateInfoManager(adv, false);
DestroyBleConfigAdvData(&packet);
@ -1020,7 +1020,7 @@ static int32_t StopScaner(void)
}
if (StopScan(g_bleListener.scanListenerId) != SOFTBUS_OK) {
DISC_LOGI(DISC_BLE, "StopScaner failed");
return SOFTBUS_DISCOVER_END_SCAN_FAIL;
return SOFTBUS_DISCOVER_BLE_END_SCAN_FAIL;
}
DISC_LOGI(DISC_BLE, "success");
return SOFTBUS_OK;

View File

@ -47,6 +47,7 @@ extern "C" {
#define SOFTBUS_SUB_SYSTEM 203
#define SOFTBUS_ERRNO(module) (-(((SOFTBUS_SUB_SYSTEM) << 21) | ((module) << 16) | (0xFFFF)))
#define SOFTBUS_SUB_ERRNO(module, sub) (-(((SOFTBUS_SUB_SYSTEM) << 21) | ((module) << 16) | ((sub) << 12) | (0x0FFF)))
enum SoftBusSubModule {
DISC_SUB_MODULE_CODE = 1,
@ -58,6 +59,14 @@ enum SoftBusSubModule {
PUBLIC_SUB_MODULE_CODE = 10,
};
enum DisSubModule {
DISC_SERVICE_SUB_MODULE_CODE = 1,
DISC_MANAGER_SUB_MODULE_CODE = 2,
DISC_BLE_SUB_MODULE_CODE = 3,
DISC_COAP_SUB_MODULE_CODE = 4,
DISC_BC_MGR_SUB_MODULE_CODE = 5,
};
enum SoftBusErrNo {
/* errno begin: -((203 << 21) | (10 << 16) | 0xFFFF) */
SOFTBUS_PUBLIC_ERR_BASE = SOFTBUS_ERRNO(PUBLIC_SUB_MODULE_CODE),
@ -401,7 +410,12 @@ enum SoftBusErrNo {
/* errno begin: -((203 << 21) | (1 << 16) | 0xFFFF) */
SOFTBUS_DISCOVER_ERR_BASE = SOFTBUS_ERRNO(DISC_SUB_MODULE_CODE),
/* errno begin: -((203 << 21) | (1 << 16) | (1 << 12) | 0x0FFF) */
SOFTBUS_DISCOVER_SERVICE_ERR_BASE = SOFTBUS_SUB_ERRNO(DISC_SUB_MODULE_CODE, DISC_SERVICE_SUB_MODULE_CODE),
SOFTBUS_DISCOVER_NOT_INIT,
SOFTBUS_DISC_SERVER_INIT_FAILED,
/* errno begin: -((203 << 21) | (1 << 16) | (2 << 12) | 0x0FFF) */
SOFTBUS_DISCOVER_MANAGER_ERR_BASE = SOFTBUS_SUB_ERRNO(DISC_SUB_MODULE_CODE, DISC_MANAGER_SUB_MODULE_CODE),
SOFTBUS_DISCOVER_MANAGER_NOT_INIT,
SOFTBUS_DISCOVER_MANAGER_INIT_FAIL,
SOFTBUS_DISCOVER_MANAGER_ITEM_NOT_CREATE,
@ -411,10 +425,18 @@ enum SoftBusErrNo {
SOFTBUS_DISCOVER_MANAGER_CAPABILITY_INVALID,
SOFTBUS_DISCOVER_MANAGER_DUPLICATE_PARAM,
SOFTBUS_DISCOVER_MANAGER_INVALID_MEDIUM,
/* errno begin: -((203 << 21) | (1 << 16) | (3 << 12) | 0x0FFF) */
SOFTBUS_DISCOVER_BLE_ERR_BASE = SOFTBUS_SUB_ERRNO(DISC_SUB_MODULE_CODE, DISC_BLE_SUB_MODULE_CODE),
SOFTBUS_DISCOVER_BLE_DISPATCHER_FAIL,
SOFTBUS_DISCOVER_BLE_GET_BROADCAST_DATA_FAIL,
SOFTBUS_DISCOVER_BLE_BUILD_CONFIG_ADV_DATA_FAIL,
SOFTBUS_DISCOVER_BLE_REGISTER_CAP_FAIL,
SOFTBUS_DISCOVER_BLE_START_BROADCAST_FAIL,
SOFTBUS_DISCOVER_BLE_END_BROADCAST_FAIL,
SOFTBUS_DISCOVER_BLE_START_SCAN_FAIL,
SOFTBUS_DISCOVER_BLE_END_SCAN_FAIL,
/* errno begin: -((203 << 21) | (1 << 16) | (4 << 12) | 0x0FFF) */
SOFTBUS_DISCOVER_COAP_ERR_BASE = SOFTBUS_SUB_ERRNO(DISC_SUB_MODULE_CODE, DISC_COAP_SUB_MODULE_CODE),
SOFTBUS_DISCOVER_COAP_NOT_INIT,
SOFTBUS_DISCOVER_COAP_INIT_FAIL,
SOFTBUS_DISCOVER_COAP_MERGE_CAP_FAIL,
@ -425,22 +447,21 @@ enum SoftBusErrNo {
SOFTBUS_DISCOVER_COAP_STOP_PUBLISH_FAIL,
SOFTBUS_DISCOVER_COAP_START_DISCOVER_FAIL,
SOFTBUS_DISCOVER_COAP_STOP_DISCOVER_FAIL,
SOFTBUS_DISCOVER_START_BROADCAST_FAIL,
SOFTBUS_DISCOVER_END_BROADCAST_FAIL,
SOFTBUS_DISCOVER_START_SCAN_FAIL,
SOFTBUS_DISCOVER_END_SCAN_FAIL,
SOFTBUS_DISC_SERVER_INIT_FAILED,
/* errno begin: -((203 << 21) | (1 << 16) | (5 << 12) | 0x0FFF) */
SOFTBUS_DISCOVER_BC_MGR_ERR_BASE = SOFTBUS_SUB_ERRNO(DISC_SUB_MODULE_CODE, DISC_BC_MGR_SUB_MODULE_CODE),
SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, // no medium has registered
SOFTBUS_BC_MGR_FUNC_NULL, // the function registered is null
SOFTBUS_BC_MGR_BUILD_ADV_PACKT_FAIL, // build broadcast adv packet fail
SOFTBUS_BC_MGR_BUILD_RSP_PACKT_FAIL, // build broadcast rsp packet fail
SOFTBUS_BC_MGR_INVALID_BC_ID, // invalid broadcast id
SOFTBUS_BC_MGR_INVALID_LISN_ID, // invalid listener id
SOFTBUS_BC_MGR_INVALID_SRV, // invalid service type
SOFTBUS_BC_MGR_NOT_BROADCASTING, // not broadcasting
SOFTBUS_BC_MGR_START_SCAN_NO_FILTER, // start scan without setting filter
SOFTBUS_BC_MGR_REG_NO_AVAILABLE_BC_ID, // no available broadcast id
SOFTBUS_BC_MGR_REG_NO_AVAILABLE_LISN_ID, // no available listener id
SOFTBUS_BC_MGR_REG_DUP, // duplicate registration
SOFTBUS_BC_MGR_WAIT_COND_FAIL, // wait signal fail
/* softbus ok */
SOFTBUS_OK = 0,

View File

@ -55,6 +55,15 @@ public:
static inline uint8_t RSP_DATA_PAYLOAD[] = {0x61, 0x72, 0x6D, 0x6F, 0x6E, 0x79, 0x20, 0x33, 0x2E, 0x32, 0x00};
};
static void ActionOfSoftbusBleAdapterInitNull()
{
DISC_LOGI(DISC_TEST, "enter");
static SoftbusBroadcastMediumInterface interface = {};
if (RegisterBroadcastMediumFunction(BROADCAST_MEDIUM_TYPE_BLE, &interface) != 0) {
DISC_LOGE(DISC_TEST, "Register gatt interface failed.");
}
}
static void BuildBroadcastParam(BroadcastParam *bcParam)
{
bcParam->minInterval = BC_INTERNAL;
@ -94,7 +103,7 @@ static BcScanFilter *GetBcScanFilter(void)
BcScanFilter *filter = static_cast<BcScanFilter *>(SoftBusCalloc(sizeof(BcScanFilter)));
DISC_CHECK_AND_RETURN_RET_LOGW(filter != nullptr, nullptr, DISC_TEST, "malloc filter failed");
unsigned char *data = static_cast<unsigned char *>(SoftBusCalloc(serviceDataLength));
unsigned char *mask = static_cast<unsigned char *>(SoftBusCalloc(serviceDataLength));
if (data == nullptr || mask == nullptr) {
@ -261,10 +270,10 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastInterface001, TestSize.Level1)
int32_t bcId = -1;
int32_t listenerId = -1;
EXPECT_EQ(SOFTBUS_ERR, RegisterBroadcaster(SRV_TYPE_DIS, &bcId, GetBroadcastCallback()));
EXPECT_EQ(SOFTBUS_ERR, UnRegisterBroadcaster(bcId));
EXPECT_EQ(SOFTBUS_ERR, RegisterScanListener(SRV_TYPE_DIS, &listenerId, GetScanCallback()));
EXPECT_EQ(SOFTBUS_ERR, UnRegisterScanListener(listenerId));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, RegisterBroadcaster(SRV_TYPE_DIS, &bcId, GetBroadcastCallback()));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, UnRegisterBroadcaster(bcId));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, RegisterScanListener(SRV_TYPE_DIS, &listenerId, GetScanCallback()));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, UnRegisterScanListener(listenerId));
BroadcastParam bcParam = {};
BroadcastPacket packet = {};
@ -276,20 +285,66 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastInterface001, TestSize.Level1)
packet.rspData.payloadLen = sizeof(RSP_DATA_PAYLOAD);
packet.rspData.payload = RSP_DATA_PAYLOAD;
EXPECT_EQ(SOFTBUS_ERR, StartBroadcasting(bcId, &bcParam, &packet));
EXPECT_EQ(SOFTBUS_ERR, SetBroadcastingData(bcId, &packet));
EXPECT_EQ(SOFTBUS_ERR, StopBroadcasting(bcId));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, StartBroadcasting(bcId, &bcParam, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, SetBroadcastingData(bcId, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, StopBroadcasting(bcId));
BcScanParams scanParam = {};
BuildScanParam(&scanParam);
EXPECT_EQ(SOFTBUS_ERR, StartScan(listenerId, &scanParam));
EXPECT_EQ(SOFTBUS_ERR, StopScan(listenerId));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, StartScan(listenerId, &scanParam));
EXPECT_EQ(SOFTBUS_BC_MGR_NO_FUNC_REGISTERED, StopScan(listenerId));
EXPECT_FALSE(BroadcastIsLpDeviceAvailable());
DISC_LOGI(DISC_TEST, "SoftbusBroadcastInterface001 end ----");
}
/*
* @tc.name: SoftbusBroadcastInterface002
* @tc.desc: Calls the interface when the function registered is null.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastInterface002, TestSize.Level1)
{
DISC_LOGI(DISC_TEST, "SoftbusBroadcastInterface002 begin ----");
ManagerMock managerMock;
EXPECT_CALL(managerMock, SoftbusBleAdapterInit).WillRepeatedly(ActionOfSoftbusBleAdapterInitNull);
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, InitBroadcastMgr());
int32_t bcId = -1;
int32_t listenerId = -1;
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, RegisterBroadcaster(SRV_TYPE_DIS, &bcId, GetBroadcastCallback()));
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, UnRegisterBroadcaster(bcId));
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, RegisterScanListener(SRV_TYPE_DIS, &listenerId, GetScanCallback()));
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, UnRegisterScanListener(listenerId));
BroadcastParam bcParam = {};
BroadcastPacket packet = {};
BuildBroadcastParam(&bcParam);
BuildBroadcastPacketExceptPayload(&packet);
packet.bcData.payloadLen = sizeof(BC_DATA_PAYLOAD);
packet.bcData.payload = BC_DATA_PAYLOAD;
packet.rspData.payloadLen = sizeof(RSP_DATA_PAYLOAD);
packet.rspData.payload = RSP_DATA_PAYLOAD;
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, StartBroadcasting(bcId, &bcParam, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, SetBroadcastingData(bcId, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, StopBroadcasting(bcId));
BcScanParams scanParam = {};
BuildScanParam(&scanParam);
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, StartScan(listenerId, &scanParam));
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, StopScan(listenerId));
EXPECT_FALSE(BroadcastIsLpDeviceAvailable());
EXPECT_EQ(SOFTBUS_BC_MGR_FUNC_NULL, DeInitBroadcastMgr());
DISC_LOGI(DISC_TEST, "SoftbusBroadcastInterface002 end ----");
}
/*
* @tc.name: SoftbusBroadcastRegisterBroadcaster001
* @tc.desc: Invalid parameter, register broadcaster fail.
@ -303,7 +358,7 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastRegisterBroadcaster001, TestSi
EXPECT_EQ(SOFTBUS_OK, InitBroadcastMgr());
int32_t bcId = -1;
EXPECT_EQ(SOFTBUS_INVALID_PARAM, RegisterBroadcaster(static_cast<BaseServiceType>(SRV_TYPE_INVALID), &bcId,
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_SRV, RegisterBroadcaster(static_cast<BaseServiceType>(SRV_TYPE_INVALID), &bcId,
GetBroadcastCallback()));
EXPECT_EQ(SOFTBUS_INVALID_PARAM, RegisterBroadcaster(SRV_TYPE_DIS, nullptr, GetBroadcastCallback()));
EXPECT_EQ(SOFTBUS_INVALID_PARAM, RegisterBroadcaster(SRV_TYPE_DIS, &bcId, nullptr));
@ -353,8 +408,9 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastRegisterBroadcaster003, TestSi
EXPECT_TRUE(bcId[i] >= 0);
}
EXPECT_EQ(SOFTBUS_ERR, RegisterBroadcaster(SRV_TYPE_DIS, &bcId[BC_NUM_MAX], GetBroadcastCallback()));
EXPECT_EQ(SOFTBUS_BC_MGR_REG_NO_AVAILABLE_BC_ID, RegisterBroadcaster(SRV_TYPE_DIS, &bcId[BC_NUM_MAX],
GetBroadcastCallback()));
for (int32_t i = 0; i < BC_NUM_MAX; i++) {
EXPECT_EQ(SOFTBUS_OK, UnRegisterBroadcaster(bcId[i]));
}
@ -435,8 +491,8 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastRegisterScanListener001, TestS
EXPECT_EQ(SOFTBUS_OK, InitBroadcastMgr());
int32_t listenerId = -1;
EXPECT_EQ(SOFTBUS_INVALID_PARAM, RegisterScanListener(static_cast<BaseServiceType>(SRV_TYPE_INVALID), &listenerId,
GetScanCallback()));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_SRV, RegisterScanListener(static_cast<BaseServiceType>(SRV_TYPE_INVALID),
&listenerId, GetScanCallback()));
EXPECT_EQ(SOFTBUS_INVALID_PARAM, RegisterScanListener(SRV_TYPE_DIS, nullptr, GetScanCallback()));
EXPECT_EQ(SOFTBUS_INVALID_PARAM, RegisterScanListener(SRV_TYPE_DIS, &listenerId, nullptr));
@ -482,12 +538,12 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastRegisterScanListener003, TestS
int32_t listenerId = -1;
EXPECT_EQ(SOFTBUS_OK, RegisterScanListener(SRV_TYPE_DIS, &listenerId, GetScanCallback()));
EXPECT_TRUE(listenerId >= 0);
EXPECT_EQ(SOFTBUS_ERR, RegisterScanListener(SRV_TYPE_DIS, &listenerId, GetScanCallback()));
EXPECT_EQ(SOFTBUS_BC_MGR_REG_DUP, RegisterScanListener(SRV_TYPE_DIS, &listenerId, GetScanCallback()));
EXPECT_EQ(SOFTBUS_OK, UnRegisterScanListener(listenerId));
EXPECT_EQ(SOFTBUS_OK, RegisterScanListener(SRV_TYPE_SH, &listenerId, GetScanCallback()));
EXPECT_TRUE(listenerId >= 0);
EXPECT_EQ(SOFTBUS_ERR, RegisterScanListener(SRV_TYPE_SH, &listenerId, GetScanCallback()));
EXPECT_EQ(SOFTBUS_BC_MGR_REG_DUP, RegisterScanListener(SRV_TYPE_SH, &listenerId, GetScanCallback()));
EXPECT_EQ(SOFTBUS_OK, UnRegisterScanListener(listenerId));
EXPECT_EQ(SOFTBUS_OK, DeInitBroadcastMgr());
@ -580,7 +636,7 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastStartBroadcasting001, TestSize
packet.rspData.payloadLen = sizeof(RSP_DATA_PAYLOAD);
packet.rspData.payload = RSP_DATA_PAYLOAD;
int32_t invalidBcId = -1;
EXPECT_EQ(SOFTBUS_ERR, StartBroadcasting(invalidBcId, &bcParam, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_BC_ID, StartBroadcasting(invalidBcId, &bcParam, &packet));
EXPECT_EQ(SOFTBUS_OK, UnRegisterBroadcaster(bcId));
@ -653,7 +709,7 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastStartBroadcasting003, TestSize
packet.rspData.payload = RSP_DATA_PAYLOAD;
EXPECT_EQ(SOFTBUS_OK, StartBroadcasting(bcId, &bcParam, &packet));
EXPECT_EQ(SOFTBUS_ERR, StartBroadcasting(bcId, &bcParam, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_WAIT_COND_FAIL, StartBroadcasting(bcId, &bcParam, &packet));
EXPECT_EQ(SOFTBUS_OK, StopBroadcasting(bcId));
EXPECT_EQ(SOFTBUS_OK, UnRegisterBroadcaster(bcId));
@ -738,10 +794,10 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastSetBroadcastingData001, TestSi
int32_t invalidId = -1;
BroadcastPacket packet = {};
EXPECT_EQ(SOFTBUS_INVALID_PARAM, SetBroadcastingData(invalidId, nullptr));
EXPECT_EQ(SOFTBUS_ERR, SetBroadcastingData(invalidId, &packet));
EXPECT_EQ(SOFTBUS_ERR, SetBroadcastingData(BC_NUM_MAX, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_BC_ID, SetBroadcastingData(invalidId, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_BC_ID, SetBroadcastingData(BC_NUM_MAX, &packet));
invalidId = 0;
EXPECT_EQ(SOFTBUS_ERR, SetBroadcastingData(invalidId, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_BC_ID, SetBroadcastingData(invalidId, &packet));
EXPECT_EQ(SOFTBUS_OK, DeInitBroadcastMgr());
@ -766,7 +822,7 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastSetBroadcastingData002, TestSi
EXPECT_TRUE(bcId >= 0);
BroadcastPacket packet = {};
EXPECT_EQ(SOFTBUS_ERR, SetBroadcastingData(bcId, &packet));
EXPECT_EQ(SOFTBUS_BC_MGR_NOT_BROADCASTING, SetBroadcastingData(bcId, &packet));
EXPECT_EQ(SOFTBUS_OK, UnRegisterBroadcaster(bcId));
EXPECT_EQ(SOFTBUS_OK, DeInitBroadcastMgr());
@ -825,10 +881,10 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastStopBroadcasting001, TestSize.
EXPECT_EQ(SOFTBUS_OK, InitBroadcastMgr());
int32_t invalidId = -1;
EXPECT_EQ(SOFTBUS_ERR, StopBroadcasting(invalidId));
EXPECT_EQ(SOFTBUS_ERR, StopBroadcasting(BC_NUM_MAX));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_BC_ID, StopBroadcasting(invalidId));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_BC_ID, StopBroadcasting(BC_NUM_MAX));
invalidId = 0;
EXPECT_EQ(SOFTBUS_ERR, StopBroadcasting(invalidId));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_BC_ID, StopBroadcasting(invalidId));
EXPECT_EQ(SOFTBUS_OK, DeInitBroadcastMgr());
@ -878,10 +934,10 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastSetScanFilter001, TestSize.Lev
filterNum = 1;
EXPECT_EQ(SOFTBUS_INVALID_PARAM, SetScanFilter(listenerId, nullptr, filterNum));
EXPECT_EQ(SOFTBUS_ERR, SetScanFilter(listenerId, &filter, filterNum));
EXPECT_EQ(SOFTBUS_ERR, SetScanFilter(SCAN_NUM_MAX, &filter, filterNum));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_LISN_ID, SetScanFilter(listenerId, &filter, filterNum));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_LISN_ID, SetScanFilter(SCAN_NUM_MAX, &filter, filterNum));
listenerId = 0;
EXPECT_EQ(SOFTBUS_ERR, SetScanFilter(listenerId, &filter, filterNum));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_LISN_ID, SetScanFilter(listenerId, &filter, filterNum));
EXPECT_EQ(SOFTBUS_OK, DeInitBroadcastMgr());
@ -930,7 +986,7 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastStartScan001, TestSize.Level1)
int32_t listenerId = -1;
BcScanParams scanParam = {};
BuildScanParam(&scanParam);
EXPECT_EQ(SOFTBUS_ERR, StartScan(listenerId, &scanParam));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_LISN_ID, StartScan(listenerId, &scanParam));
EXPECT_EQ(SOFTBUS_OK, RegisterScanListener(SRV_TYPE_DIS, &listenerId, GetScanCallback()));
EXPECT_TRUE(listenerId >= 0);
@ -960,7 +1016,7 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastStartScan002, TestSize.Level1)
EXPECT_EQ(SOFTBUS_OK, RegisterScanListener(SRV_TYPE_DIS, &listenerId, GetScanCallback()));
EXPECT_TRUE(listenerId >= 0);
EXPECT_EQ(SOFTBUS_ERR, StartScan(listenerId, &scanParam));
EXPECT_EQ(SOFTBUS_BC_MGR_START_SCAN_NO_FILTER, StartScan(listenerId, &scanParam));
EXPECT_EQ(SOFTBUS_OK, UnRegisterScanListener(listenerId));
EXPECT_EQ(SOFTBUS_OK, DeInitBroadcastMgr());
@ -1044,10 +1100,10 @@ HWTEST_F(SoftbusBroadcastMgrTest, SoftbusBroadcastStopScan001, TestSize.Level1)
EXPECT_EQ(SOFTBUS_OK, InitBroadcastMgr());
int32_t invalidId = -1;
EXPECT_EQ(SOFTBUS_ERR, StopScan(invalidId));
EXPECT_EQ(SOFTBUS_ERR, StopScan(SCAN_NUM_MAX));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_LISN_ID, StopScan(invalidId));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_LISN_ID, StopScan(SCAN_NUM_MAX));
invalidId = 0;
EXPECT_EQ(SOFTBUS_ERR, StopScan(invalidId));
EXPECT_EQ(SOFTBUS_BC_MGR_INVALID_LISN_ID, StopScan(invalidId));
EXPECT_EQ(SOFTBUS_OK, DeInitBroadcastMgr());