mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-27 02:40:40 +00:00
SensorHub Low Power
Signed-off-by: zhangjie_rennes <zhangjie79@hisilicon.com>
This commit is contained in:
parent
0e84e5bb1f
commit
5f56277495
@ -186,6 +186,17 @@ if (defined(ohos_lite)) {
|
||||
"$ble_enhanced_impl",
|
||||
],
|
||||
"value")
|
||||
if (enhanced_range) {
|
||||
include_dirs += [
|
||||
"$dsoftbus_root_path/dsoftbus_enhance/adapter/common/mlps/include",
|
||||
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/mlps/include",
|
||||
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/mlps/interface",
|
||||
]
|
||||
sources += [
|
||||
"$dsoftbus_root_path/dsoftbus_enhance/adapter/common/mlps/src/softbus_adapter_mlps.cpp",
|
||||
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/mlps/src/mlps.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
if (enhanced_range && defined(global_parts_info.msdp_algorithm)) {
|
||||
include_dirs += [ "//base/msdp/algorithm/ble_range/include" ]
|
||||
|
@ -27,6 +27,10 @@
|
||||
#include "softbus_log.h"
|
||||
#include "softbus_utils.h"
|
||||
|
||||
#define BT_UUID "43d4a49f-604d-45b5-9302-4ddbbfd538fd"
|
||||
#define DELIVERY_MODE_REPLY 0xF0 // Lpdevice delivery mode: reply adv when filter matched
|
||||
#define ADV_DURATION_MS 0
|
||||
static int32_t g_scannerId = -1;
|
||||
typedef struct {
|
||||
int advId;
|
||||
bool isUsed;
|
||||
@ -44,6 +48,7 @@ typedef struct {
|
||||
SoftBusBleScanFilter *filter;
|
||||
uint8_t filterSize;
|
||||
SoftBusScanListener *listener;
|
||||
int32_t scannerId;
|
||||
} ScanListener;
|
||||
|
||||
static AdvChannel g_advChannel[ADV_MAX_NUM];
|
||||
@ -54,6 +59,7 @@ static SoftBusMutex g_advLock = {0};
|
||||
static SoftBusMutex g_scanerLock = {0};
|
||||
|
||||
static volatile bool g_isRegCb = false;
|
||||
static volatile bool g_isLpDeviceRegCb = false;
|
||||
|
||||
NO_SANITIZE("cfi") static void OnBtStateChanged(int32_t listenerId, int32_t state)
|
||||
{
|
||||
@ -84,19 +90,14 @@ NO_SANITIZE("cfi") static void OnBtStateChanged(int32_t listenerId, int32_t stat
|
||||
CLOGE("ATTENTION, try to get scan lock failed, something unexpected happened");
|
||||
return;
|
||||
}
|
||||
bool needStopScan = false;
|
||||
for (int index = 0; index < SCAN_MAX_NUM; index++) {
|
||||
ScanListener *scanListener = &g_scanListener[index];
|
||||
if (scanListener->isUsed && scanListener->isScanning) {
|
||||
scanListener->isScanning = false;
|
||||
scanListener->listener->OnScanStop(index, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
needStopScan = true;
|
||||
(void)BleStopScan(scanListener->scannerId);
|
||||
}
|
||||
}
|
||||
if (needStopScan) {
|
||||
// ignore status code explicitedly, just to notify bt cleanup resources associated with this scan
|
||||
(void)BleStopScan();
|
||||
}
|
||||
(void)SoftBusMutexUnlock(&g_scanerLock);
|
||||
}
|
||||
|
||||
@ -265,7 +266,8 @@ static void GetAllNativeScanFilter(int thisListenerId, BleScanNativeFilter **nat
|
||||
{
|
||||
uint8_t nativeSize = 0;
|
||||
for (int index = 0; index < SCAN_MAX_NUM; index++) {
|
||||
if (!g_scanListener[index].isUsed || (!g_scanListener[index].isScanning && index != thisListenerId)) {
|
||||
if (!g_scanListener[index].isUsed || (!g_scanListener[index].isScanning && index != thisListenerId) ||
|
||||
g_scanListener[index].scannerId != g_scannerId) {
|
||||
g_scanListener[index].isNeedReset = false;
|
||||
continue;
|
||||
}
|
||||
@ -301,6 +303,31 @@ static void GetAllNativeScanFilter(int thisListenerId, BleScanNativeFilter **nat
|
||||
}
|
||||
}
|
||||
|
||||
static void SoftBusGetBurstScanFilter(int thisListenerId, BleScanNativeFilter **nativeFilter, uint8_t *filterSize)
|
||||
{
|
||||
uint8_t size = g_scanListener[thisListenerId].filterSize;
|
||||
*nativeFilter = (BleScanNativeFilter *)SoftBusCalloc(sizeof(BleScanNativeFilter) * size);
|
||||
if (*nativeFilter == NULL) {
|
||||
return;
|
||||
}
|
||||
const SoftBusBleScanFilter *filter = g_scanListener[thisListenerId].filter;
|
||||
while (size-- > 0) {
|
||||
(*nativeFilter + size)->address = (filter + size)->address;
|
||||
(*nativeFilter + size)->deviceName = (filter + size)->deviceName;
|
||||
(*nativeFilter + size)->manufactureData = (filter + size)->manufactureData;
|
||||
(*nativeFilter + size)->manufactureDataLength = (filter + size)->manufactureDataLength;
|
||||
(*nativeFilter + size)->manufactureDataMask = (filter + size)->manufactureDataMask;
|
||||
(*nativeFilter + size)->manufactureId = (filter + size)->manufactureId;
|
||||
(*nativeFilter + size)->serviceData = (filter + size)->serviceData;
|
||||
(*nativeFilter + size)->serviceDataLength = (filter + size)->serviceDataLength;
|
||||
(*nativeFilter + size)->serviceDataMask = (filter + size)->serviceDataMask;
|
||||
(*nativeFilter + size)->serviceUuid = (filter + size)->serviceUuid;
|
||||
(*nativeFilter + size)->serviceUuidLength = (filter + size)->serviceUuidLength;
|
||||
(*nativeFilter + size)->serviceUuidMask = (filter + size)->serviceUuidMask;
|
||||
}
|
||||
*filterSize = g_scanListener[thisListenerId].filterSize;
|
||||
}
|
||||
|
||||
static void ConvertScanResult(const BtScanResultData *src, SoftBusBleScanResult *dst)
|
||||
{
|
||||
dst->eventType = ConvertScanEventType(src->eventType);
|
||||
@ -492,11 +519,33 @@ NO_SANITIZE("cfi") static void WrapperScanResultCallback(BtScanResultData *scanR
|
||||
}
|
||||
}
|
||||
|
||||
static void WrapperScanParameterSetCompletedCallback(int clientId, int status)
|
||||
static void WrapperLpDeviceInfoCallback(BtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize)
|
||||
{
|
||||
(void)clientId;
|
||||
(void)status;
|
||||
CLOGI("WrapperScanParameterSetCompletedCallback");
|
||||
for (uint32_t index = 0; index < ADV_MAX_NUM; index++) {
|
||||
AdvChannel *advChannel = &g_advChannel[index];
|
||||
if (advChannel->isUsed == false || advChannel->advCallback == NULL ||
|
||||
advChannel->advCallback->LpDeviceInfoCallback == NULL) {
|
||||
continue;
|
||||
}
|
||||
advChannel->advCallback->LpDeviceInfoCallback((SoftBusBtUuid *)uuid, type, data, dataSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void WrapperScanStateChangeCallback(int32_t resultCode, bool isStartScan)
|
||||
{
|
||||
int32_t listenerId;
|
||||
for (listenerId = 0; listenerId < SCAN_MAX_NUM; listenerId++) {
|
||||
SoftBusMutexLock(&g_scanerLock);
|
||||
ScanListener *scanListener = &g_scanListener[listenerId];
|
||||
if (!scanListener->isUsed || scanListener->listener == NULL || !scanListener->isScanning ||
|
||||
scanListener->listener->OnScanStateChanged == NULL) {
|
||||
SoftBusMutexUnlock(&g_scanerLock);
|
||||
continue;
|
||||
}
|
||||
SoftBusMutexUnlock(&g_scanerLock);
|
||||
scanListener->listener->OnScanStateChanged(resultCode, isStartScan);
|
||||
}
|
||||
}
|
||||
|
||||
static BtGattCallbacks g_softbusGattCb = {
|
||||
@ -505,8 +554,12 @@ static BtGattCallbacks g_softbusGattCb = {
|
||||
.advDataCb = WrapperAdvDataCallback,
|
||||
.advUpdateCb = WrapperAdvUpdateCallback,
|
||||
.securityRespondCb = WrapperSecurityRespondCallback,
|
||||
};
|
||||
|
||||
static BleScanCallbacks g_softbusBleScanCb = {
|
||||
.scanResultCb = WrapperScanResultCallback,
|
||||
.scanParamSetCb = WrapperScanParameterSetCompletedCallback
|
||||
.scanStateChangeCb = WrapperScanStateChangeCallback,
|
||||
.lpDeviceInfoCb = WrapperLpDeviceInfoCallback,
|
||||
};
|
||||
|
||||
static SoftBusBtStateListener g_btStateLister = {
|
||||
@ -514,19 +567,39 @@ static SoftBusBtStateListener g_btStateLister = {
|
||||
.OnBtAclStateChanged = NULL,
|
||||
};
|
||||
|
||||
static int RegisterBleGattCallback(void)
|
||||
static int RegisterBleGattCallback(int32_t *scannerId, bool isLpDeviceScan)
|
||||
{
|
||||
if (g_isRegCb) {
|
||||
if (!g_isRegCb && !g_isLpDeviceRegCb) {
|
||||
if (BleGattRegisterCallbacks(&g_softbusGattCb) != 0) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (SoftBusAddBtStateListener(&g_btStateLister) < 0) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
if (!isLpDeviceScan) {
|
||||
if (g_isRegCb) {
|
||||
*scannerId = g_scannerId;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (BleRegisterScanCallbacks(&g_softbusBleScanCb, scannerId) != 0) {
|
||||
CLOGE("SH register ble scan callback failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_scannerId = *scannerId;
|
||||
g_isRegCb = true;
|
||||
return SOFTBUS_OK;
|
||||
} else {
|
||||
if (g_isLpDeviceRegCb) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (BleRegisterScanCallbacks(&g_softbusBleScanCb, scannerId) != 0) {
|
||||
CLOGE("SH register sh scan callback failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_isLpDeviceRegCb = true;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (BleGattRegisterCallbacks(&g_softbusGattCb) != 0) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (SoftBusAddBtStateListener(&g_btStateLister) < 0) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_isRegCb = true;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static bool CheckAdvChannelInUsed(int advId)
|
||||
@ -607,7 +680,7 @@ static void ClearAdvData(int advId)
|
||||
g_advChannel[advId].advData.scanRspData = NULL;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback)
|
||||
NO_SANITIZE("cfi") int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan)
|
||||
{
|
||||
if (callback == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
@ -615,7 +688,7 @@ NO_SANITIZE("cfi") int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback)
|
||||
if (SoftBusMutexLock(&g_advLock) != 0) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (RegisterBleGattCallback() != SOFTBUS_OK) {
|
||||
if (RegisterBleGattCallback(scannerId, isLpDeviceScan) != SOFTBUS_OK) {
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
@ -710,7 +783,6 @@ NO_SANITIZE("cfi") int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *par
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_advChannel[advId].advCallback->AdvEnableCallback(advId, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
@ -759,7 +831,7 @@ NO_SANITIZE("cfi") int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data
|
||||
return SoftBusStartAdv(advId, param);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int SoftBusAddScanListener(const SoftBusScanListener *listener)
|
||||
NO_SANITIZE("cfi") int SoftBusAddScanListener(const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan)
|
||||
{
|
||||
if (listener == NULL) {
|
||||
return SOFTBUS_ERR;
|
||||
@ -767,7 +839,7 @@ NO_SANITIZE("cfi") int SoftBusAddScanListener(const SoftBusScanListener *listene
|
||||
if (SoftBusMutexLock(&g_scanerLock) != 0) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (RegisterBleGattCallback() != SOFTBUS_OK) {
|
||||
if (RegisterBleGattCallback(scannerId, isLpDeviceScan) != SOFTBUS_OK) {
|
||||
SoftBusMutexUnlock(&g_scanerLock);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
@ -777,6 +849,7 @@ NO_SANITIZE("cfi") int SoftBusAddScanListener(const SoftBusScanListener *listene
|
||||
g_scanListener[index].isUsed = true;
|
||||
g_scanListener[index].isNeedReset = true;
|
||||
g_scanListener[index].isScanning = false;
|
||||
g_scanListener[index].scannerId = *scannerId;
|
||||
g_scanListener[index].listener = (SoftBusScanListener *)listener;
|
||||
SoftBusMutexUnlock(&g_scanerLock);
|
||||
return index;
|
||||
@ -822,7 +895,7 @@ NO_SANITIZE("cfi") int SoftBusRemoveScanListener(int listenerId)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static bool CheckNeedReStartScan(void)
|
||||
static bool CheckNeedReStartScan(int scannerId)
|
||||
{
|
||||
bool isNeedReset = false;
|
||||
bool isScanning = false;
|
||||
@ -835,7 +908,7 @@ static bool CheckNeedReStartScan(void)
|
||||
}
|
||||
}
|
||||
if (isNeedReset && isScanning) {
|
||||
if (BleOhosStatusToSoftBus(BleStopScan()) != SOFTBUS_BT_STATUS_SUCCESS) {
|
||||
if (BleOhosStatusToSoftBus(BleStopScan(scannerId)) != SOFTBUS_BT_STATUS_SUCCESS) {
|
||||
CLOGE("ble stop scan failed");
|
||||
return false;
|
||||
}
|
||||
@ -881,7 +954,7 @@ NO_SANITIZE("cfi") int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int SoftBusStartScan(int listenerId, const SoftBusBleScanParams *param)
|
||||
NO_SANITIZE("cfi") int SoftBusStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *param)
|
||||
{
|
||||
if (param == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
@ -897,12 +970,16 @@ NO_SANITIZE("cfi") int SoftBusStartScan(int listenerId, const SoftBusBleScanPara
|
||||
BleScanConfigs scanConfig;
|
||||
SetAndGetSuitableScanConfig(listenerId, param, &scanConfig);
|
||||
int32_t status = SOFTBUS_BT_STATUS_SUCCESS;
|
||||
if (CheckNeedReStartScan()) {
|
||||
if (CheckNeedReStartScan(scannerId)) {
|
||||
uint8_t filterSize = 0;
|
||||
BleScanNativeFilter *nativeFilter = NULL;
|
||||
GetAllNativeScanFilter(listenerId, &nativeFilter, &filterSize);
|
||||
if (scannerId == g_scannerId) {
|
||||
GetAllNativeScanFilter(listenerId, &nativeFilter, &filterSize);
|
||||
} else {
|
||||
SoftBusGetBurstScanFilter(listenerId, &nativeFilter, &filterSize);
|
||||
}
|
||||
DumpBleScanFilter(nativeFilter, filterSize);
|
||||
status = BleOhosStatusToSoftBus(BleStartScanEx(&scanConfig, nativeFilter, filterSize));
|
||||
status = BleOhosStatusToSoftBus(BleStartScanEx(scannerId, &scanConfig, nativeFilter, filterSize));
|
||||
SoftBusFree(nativeFilter);
|
||||
}
|
||||
if (status != SOFTBUS_BT_STATUS_SUCCESS) {
|
||||
@ -921,7 +998,7 @@ NO_SANITIZE("cfi") int SoftBusStartScan(int listenerId, const SoftBusBleScanPara
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int SoftBusStopScan(int listenerId)
|
||||
NO_SANITIZE("cfi") int SoftBusStopScan(int listenerId, int scannerId)
|
||||
{
|
||||
if (SoftBusMutexLock(&g_scanerLock) != 0) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
@ -936,7 +1013,7 @@ NO_SANITIZE("cfi") int SoftBusStopScan(int listenerId)
|
||||
}
|
||||
int32_t status = SOFTBUS_BT_STATUS_SUCCESS;
|
||||
if (CheckNeedStopScan(listenerId)) {
|
||||
status = BleOhosStatusToSoftBus(BleStopScan());
|
||||
status = BleOhosStatusToSoftBus(BleStopScan(scannerId));
|
||||
}
|
||||
if (status != SOFTBUS_BT_STATUS_SUCCESS) {
|
||||
SoftBusMutexUnlock(&g_scanerLock);
|
||||
@ -983,3 +1060,75 @@ int SoftBusReplaceAdvertisingAdv(int advId, const SoftBusBleAdvData *data)
|
||||
ret = BleOhosStatusToSoftBus(BleSetAdvData(btAdvId, advData));
|
||||
return ret;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") bool SoftBusIsLpDeviceAvailable(void)
|
||||
{
|
||||
return IsLpDeviceAvailable();
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") bool SoftBusSetAdvFilterParam(int advHandle, int advId, SoftBusBleAdvParams *advParam,
|
||||
int listenerId, SoftBusBleScanParams *scanParam)
|
||||
{
|
||||
BleScanConfigs scanConfig;
|
||||
SetAndGetSuitableScanConfig(listenerId, scanParam, &scanConfig);
|
||||
BleScanNativeFilter *filter = NULL;
|
||||
uint8_t filterSize = 0;
|
||||
SoftBusGetBurstScanFilter(listenerId, &filter, &filterSize);
|
||||
DumpBleScanFilter(filter, filterSize);
|
||||
BleAdvParams btAdvParam;
|
||||
StartAdvRawData rawData;
|
||||
ConvertAdvParam(advParam, &btAdvParam);
|
||||
ConvertAdvData(&g_advChannel[advId].advData, &rawData);
|
||||
BtUuid btUuid;
|
||||
btUuid.uuid = BT_UUID;
|
||||
btUuid.uuidLen = strlen(BT_UUID);
|
||||
BtLpDeviceParam btLpDeviceParam;
|
||||
btLpDeviceParam.scanConfig = &scanConfig;
|
||||
btLpDeviceParam.filter = filter;
|
||||
btLpDeviceParam.filterSize = filterSize;
|
||||
btLpDeviceParam.advParam = btAdvParam;
|
||||
btLpDeviceParam.rawData = rawData;
|
||||
btLpDeviceParam.uuid = btUuid;
|
||||
btLpDeviceParam.activeDeviceInfo = NULL;
|
||||
btLpDeviceParam.activeDeviceSize = 0;
|
||||
btLpDeviceParam.deliveryMode = DELIVERY_MODE_REPLY;
|
||||
btLpDeviceParam.advHandle = advHandle;
|
||||
btLpDeviceParam.duration = ADV_DURATION_MS;
|
||||
if (SetLpDeviceParam(&btLpDeviceParam) != SOFTBUS_OK) {
|
||||
CLOGE("SH SetLpDeviceParam failed");
|
||||
return false;
|
||||
}
|
||||
SoftBusFree(filter);
|
||||
return true;
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int32_t SoftBusGetAdvHandle(int32_t advId, int32_t *advHandle)
|
||||
{
|
||||
return GetAdvHandle(g_advChannel[advId].advId, advHandle);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int32_t SoftBusEnableSyncDataToLpDevice(void)
|
||||
{
|
||||
return EnableSyncDataToLpDevice();
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int32_t SoftBusDisableSyncDataToLpDevice(void)
|
||||
{
|
||||
return DisableSyncDataToLpDevice();
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int32_t SoftBusDeregisterScanCallbacks(int32_t scannerId)
|
||||
{
|
||||
return BleDeregisterScanCallbacks(scannerId);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int32_t SoftBusSetScanReportChannelToLpDevice(int scannerId, bool enable)
|
||||
{
|
||||
return SetScanReportChannelToLpDevice(scannerId, enable);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi") int32_t SoftBusSetLpDeviceParam(int duration, int maxExtAdvEvents, int window,
|
||||
int interval, int advHandle)
|
||||
{
|
||||
return SetLpDeviceAdvParam(duration, maxExtAdvEvents, window, interval, advHandle);
|
||||
}
|
@ -149,8 +149,7 @@ typedef struct {
|
||||
void (*OnScanStart)(int listenerId, int status);
|
||||
void (*OnScanStop)(int listenerId, int status);
|
||||
void (*OnScanResult)(int listenerId, const SoftBusBleScanResult *scanResultdata);
|
||||
void (*OnScanFailed)(int resultCode, bool isStartScan);
|
||||
void (*OnScanStateChanged)(int callbackCode);
|
||||
void (*OnScanStateChanged)(int32_t resultCode, bool isStartScan);
|
||||
} SoftBusScanListener;
|
||||
|
||||
typedef struct {
|
||||
@ -162,7 +161,7 @@ typedef struct {
|
||||
SoftBusBtAddr peerAddr;
|
||||
int channelMap;
|
||||
unsigned char advFilterPolicy;
|
||||
int txPower;
|
||||
int8_t txPower;
|
||||
int duration;
|
||||
} SoftBusBleAdvParams;
|
||||
|
||||
@ -171,22 +170,22 @@ typedef struct {
|
||||
void (*AdvDisableCallback)(int advId, int status);
|
||||
void (*AdvDataCallback)(int advId, int status);
|
||||
void (*AdvUpdateCallback)(int advId, int status);
|
||||
void (*SensorhubCallback)(SoftBusBtUuid *uuid, int type, unsigned char *data, int dataSize);
|
||||
void (*LpDeviceInfoCallback)(SoftBusBtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize);
|
||||
} SoftBusAdvCallback;
|
||||
|
||||
int BleGattLockInit(void);
|
||||
|
||||
int SoftBusAddScanListener(const SoftBusScanListener *listener);
|
||||
int SoftBusAddScanListener(const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan);
|
||||
|
||||
int SoftBusRemoveScanListener(int listenerId);
|
||||
|
||||
int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter *filter, uint8_t filterSize);
|
||||
|
||||
int SoftBusStartScan(int listenerId, const SoftBusBleScanParams *param);
|
||||
int SoftBusStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *param);
|
||||
|
||||
int SoftBusStopScan(int listenerId);
|
||||
int SoftBusStopScan(int listenerId, int scannerId);
|
||||
|
||||
int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback);
|
||||
int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan);
|
||||
|
||||
int SoftBusReleaseAdvChannel(int advId);
|
||||
|
||||
@ -200,6 +199,23 @@ int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data, const SoftBusBleA
|
||||
|
||||
int SoftBusReplaceAdvertisingAdv(int advId, const SoftBusBleAdvData *data);
|
||||
|
||||
bool SoftBusIsLpDeviceAvailable(void);
|
||||
|
||||
bool SoftBusSetAdvFilterParam(int advHandle, int advId, SoftBusBleAdvParams *advParam,
|
||||
int listenerId, SoftBusBleScanParams *scanParam);
|
||||
|
||||
int32_t SoftBusGetAdvHandle(int32_t advId, int32_t *advHandle);
|
||||
|
||||
int32_t SoftBusEnableSyncDataToLpDevice(void);
|
||||
|
||||
int32_t SoftBusDisableSyncDataToLpDevice(void);
|
||||
|
||||
int32_t SoftBusDeregisterScanCallbacks(int32_t scannerId);
|
||||
|
||||
int32_t SoftBusSetScanReportChannelToLpDevice(int32_t scannerId, bool enable);
|
||||
|
||||
int32_t SoftBusSetLpDeviceParam(int duration, int maxExtAdvEvents, int window,
|
||||
int interval, int advHandle);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
@ -24,7 +24,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t LnnRegistBleHeartbeatMediumMgr(void);
|
||||
|
||||
int32_t HbUpdateBleScanFilter(int32_t listenerId);
|
||||
void SetBleTypeIsSupportLpDevice(int32_t type);
|
||||
int32_t HbGenerateBitPosition(int32_t min, int32_t max, int64_t seed, int32_t *randPos, int32_t num);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef LNN_BLE_LPDEVICE_H
|
||||
#define LNN_BLE_LPDEVICE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t LnnRegisterBleLpDeviceMediumMgr(void);
|
||||
void SendInfoToMlpsBleOnlineProcess(void *para);
|
||||
void SendInfoToMlpsBleOfflineProcess(void *para);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*LNN_BLE_LPDEVICE_H*/
|
@ -92,6 +92,8 @@ typedef enum {
|
||||
UPDATE_HB_ACCOUNT_INFO,
|
||||
UPDATE_HB_NETWORK_INFO,
|
||||
UPDATE_SCREEN_STATE_INFO,
|
||||
UPDATE_BT_STATE_OPEN_INFO,
|
||||
UPDATE_BT_STATE_CLOSE_INFO,
|
||||
UPDATE_HB_MAX_INFO,
|
||||
} LnnHeartbeatUpdateInfoType;
|
||||
|
||||
|
@ -86,3 +86,16 @@ int32_t LnnRegistBleHeartbeatMediumMgr(void)
|
||||
{
|
||||
return LnnRegistHeartbeatMediumMgr(&g_bleMgr);
|
||||
}
|
||||
|
||||
int32_t HbUpdateBleScanFilter(int32_t listenerId)
|
||||
{
|
||||
(void)listenerId;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void SetBleTypeIsSupportLpDevice(int32_t type)
|
||||
{
|
||||
(void)type;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 "lnn_ble_lpdevice.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
int32_t LnnRegisterBleLpDeviceMediumMgr(void)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
void SendInfoToMlpsBleOnlineProcess(void *para)
|
||||
{
|
||||
(void)para;
|
||||
return;
|
||||
}
|
||||
|
||||
void SendInfoToMlpsBleOfflineProcess(void *para)
|
||||
{
|
||||
(void)para;
|
||||
return;
|
||||
}
|
@ -313,10 +313,12 @@ static void HbBtStateChangeEventHandler(const LnnEventBasicInfo *info)
|
||||
switch (btState) {
|
||||
case SOFTBUS_BLE_TURN_ON:
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "HB handle SOFTBUS_BLE_TURN_ON");
|
||||
LnnUpdateHeartbeatInfo(UPDATE_BT_STATE_OPEN_INFO);
|
||||
HbConditionChanged(false);
|
||||
break;
|
||||
case SOFTBUS_BLE_TURN_OFF:
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "HB handle SOFTBUS_BLE_TURN_OFF");
|
||||
LnnUpdateHeartbeatInfo(UPDATE_BT_STATE_CLOSE_INFO);
|
||||
HbProcOfflineNodeWithoutSoftbus();
|
||||
HbConditionChanged(false);
|
||||
break;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "bus_center_manager.h"
|
||||
#include "common_list.h"
|
||||
#include "lnn_ble_heartbeat.h"
|
||||
#include "lnn_ble_lpdevice.h"
|
||||
#include "lnn_connection_addr_utils.h"
|
||||
#include "lnn_device_info.h"
|
||||
#include "lnn_distributed_net_ledger.h"
|
||||
@ -501,7 +502,10 @@ NO_SANITIZE("cfi") int32_t LnnHbMediumMgrInit(void)
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB regist ble heartbeat manager fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
// mark-- LnnRegistBleSensorHubMediumMgr
|
||||
if (LnnRegisterBleLpDeviceMediumMgr() != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "SH regist LpDevice manager fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return HbInitRecvList();
|
||||
}
|
||||
|
||||
@ -563,6 +567,10 @@ NO_SANITIZE("cfi") static bool VisitHbMediumMgrSendEnd(LnnHeartbeatType *typeSet
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB manager send once end get invalid param");
|
||||
return false;
|
||||
}
|
||||
if (eachType == HEARTBEAT_TYPE_BLE_V3) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "V3 don't stop");
|
||||
return true;
|
||||
}
|
||||
custData = (LnnHeartbeatSendEndData *)data;
|
||||
custData->hbType = eachType;
|
||||
id = LnnConvertHbTypeToId(eachType);
|
||||
@ -574,10 +582,6 @@ NO_SANITIZE("cfi") static bool VisitHbMediumMgrSendEnd(LnnHeartbeatType *typeSet
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "HB not support heartbeat type(%d)", eachType);
|
||||
return true;
|
||||
}
|
||||
if (eachType == HEARTBEAT_TYPE_BLE_V3) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "V3 don't stop");
|
||||
return true;
|
||||
}
|
||||
if (g_hbMeidumMgr[id]->onSendOneHbEnd == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "HB manager send once end cb is NULL, type(%d)", eachType);
|
||||
return true;
|
||||
|
@ -790,7 +790,8 @@ NO_SANITIZE("cfi") int32_t LnnStopHeartbeatByType(LnnHeartbeatType type)
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
LnnHbClearRecvList();
|
||||
if (type == (HEARTBEAT_TYPE_UDP | HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V1 | HEARTBEAT_TYPE_TCP_FLUSH)) {
|
||||
if (type == (HEARTBEAT_TYPE_UDP | HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V1 | HEARTBEAT_TYPE_BLE_V3 |
|
||||
HEARTBEAT_TYPE_TCP_FLUSH)) {
|
||||
return LnnPostTransStateMsgToHbFsm(g_hbFsm, EVENT_HB_IN_NONE_STATE);
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -883,7 +884,7 @@ NO_SANITIZE("cfi") void LnnHbStrategyDeinit(void)
|
||||
if (g_hbFsm != NULL) {
|
||||
(void)LnnStopHeartbeatFsm(g_hbFsm);
|
||||
}
|
||||
LnnUnRegistParamMgrByType(HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V1);
|
||||
LnnUnRegistParamMgrByType(HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V1 | HEARTBEAT_TYPE_BLE_V3);
|
||||
LnnUnRegistParamMgrByType(HEARTBEAT_TYPE_TCP_FLUSH);
|
||||
(void)SoftBusMutexDestroy(&g_hbStrategyMutex);
|
||||
}
|
||||
|
@ -81,8 +81,10 @@ if (dsoftbus_feature_lnn_net) {
|
||||
"$core_lane_hub_path/heartbeat/src/lnn_heartbeat_utils.c",
|
||||
]
|
||||
if (!enhanced) {
|
||||
bus_center_hub_src +=
|
||||
[ "$core_lane_hub_path/heartbeat/src/lnn_ble_heartbeat_virtual.c" ]
|
||||
bus_center_hub_src += [
|
||||
"$core_lane_hub_path/heartbeat/src/lnn_ble_heartbeat_virtual.c",
|
||||
"$core_lane_hub_path/heartbeat/src/lnn_ble_lpdevice_virtual.c",
|
||||
]
|
||||
}
|
||||
} else {
|
||||
bus_center_hub_src +=
|
||||
@ -104,7 +106,10 @@ if (dsoftbus_feature_lnn_net && dsoftbus_feature_lnn_time_sync && enhanced) {
|
||||
bus_center_hub_deps += [ "$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/time_sync:dsoftbus_time_sync_impl" ]
|
||||
}
|
||||
if (dsoftbus_feature_lnn_net && dsoftbus_feature_lnn_heartbeat && enhanced) {
|
||||
bus_center_hub_deps += [ "$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/heartbeat:dsoftbus_ble_heartbeat" ]
|
||||
bus_center_hub_deps += [
|
||||
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/heartbeat:dsoftbus_ble_heartbeat",
|
||||
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/heartbeat:dsoftbus_ble_lpdevice",
|
||||
]
|
||||
}
|
||||
if (dsoftbus_feature_lnn_net && dsoftbus_feature_qos && enhanced) {
|
||||
bus_center_hub_deps += [ "$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/lane_statistics:dsoftbus_lane_statistics" ]
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "auth_hichain.h"
|
||||
#include "bus_center_event.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "lnn_ble_lpdevice.h"
|
||||
#include "lnn_connection_addr_utils.h"
|
||||
#include "lnn_decision_db.h"
|
||||
#include "lnn_device_info.h"
|
||||
@ -331,16 +332,34 @@ static void PostPcOnlineUniquely(NodeInfo *info)
|
||||
static void DeviceStateChangeProcess(char *udid, ConnectionAddrType type, bool isOnline)
|
||||
{
|
||||
if (type != CONNECTION_ADDR_BLE) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "send mlps only support ble");
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "send mlps only support ble");
|
||||
return;
|
||||
}
|
||||
if (isOnline) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "ap online, ready to mlps");
|
||||
// mark--SendInfoToMlpsBleOnlineProcess
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "ap offline, ready to mlps");
|
||||
// mark-- SendInfoToMlpsBleOfflineProcess
|
||||
char *outUdid = (char *)SoftBusCalloc(UDID_BUF_LEN);
|
||||
if (outUdid == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "calloc outUdid fail");
|
||||
return;
|
||||
}
|
||||
if (strcpy_s(outUdid, UDID_BUF_LEN, udid) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy outUdid fail");
|
||||
SoftBusFree(outUdid);
|
||||
return;
|
||||
}
|
||||
SoftBusLooper *looper = GetLooper(LOOP_TYPE_DEFAULT);
|
||||
if (isOnline) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "SH ap online");
|
||||
if (LnnAsyncCallbackDelayHelper(looper, SendInfoToMlpsBleOnlineProcess, (void *)outUdid, 0) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "async call online process fail");
|
||||
SoftBusFree(outUdid);
|
||||
}
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "SH ap offline");
|
||||
if (LnnAsyncCallbackDelayHelper(looper, SendInfoToMlpsBleOfflineProcess, (void *)outUdid, 0) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "async call online process fail");
|
||||
SoftBusFree(outUdid);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void CompleteJoinLNN(LnnConnectionFsm *connFsm, const char *networkId, int32_t retCode)
|
||||
@ -604,8 +623,8 @@ static int32_t OnAuthDone(LnnConnectionFsm *connFsm, int32_t *retCode)
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "[id=%u]auth done, authId=%" PRId64 ", result=%d",
|
||||
connFsm->id, connInfo->authId, *retCode);
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "[id=%u]auth done, authId=%" PRId64 ", result=%d, connType=%d",
|
||||
connFsm->id, connInfo->authId, *retCode, connFsm->connInfo.addr.type);
|
||||
if (*retCode == SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO,
|
||||
"[id=%u]auth passed, authId=%" PRId64, connFsm->id, connInfo->authId);
|
||||
@ -614,8 +633,8 @@ static int32_t OnAuthDone(LnnConnectionFsm *connFsm, int32_t *retCode)
|
||||
LnnFsmPostMessage(&connFsm->fsm, FSM_MSG_TYPE_LEAVE_INVALID_CONN, NULL);
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO,
|
||||
"[id=%u]auth failed, authId=%" PRId64 ", requestId=%u, reason=%d", connFsm->id, connInfo->authId,
|
||||
connInfo->requestId, *retCode);
|
||||
"[id=%u]auth failed, authId=%" PRId64 ", requestId=%u, reason=%d, connType=%d", connFsm->id, connInfo->authId,
|
||||
connInfo->requestId, *retCode, connFsm->connInfo.addr.type);
|
||||
CompleteJoinLNN(connFsm, NULL, *retCode);
|
||||
}
|
||||
SoftBusFree(retCode);
|
||||
|
@ -77,6 +77,7 @@
|
||||
#define BlE_ADVERTISER "bleAdvertiser"
|
||||
#define RECV_MESSAGE_INFO "recvMessageInfo"
|
||||
|
||||
static int32_t g_bleScannerId = -1;
|
||||
typedef enum {
|
||||
PUBLISH_ACTIVE_SERVICE,
|
||||
PUBLISH_PASSIVE_SERVICE,
|
||||
@ -574,13 +575,15 @@ static SoftBusAdvCallback g_advCallback = {
|
||||
.AdvEnableCallback = BleAdvEnableCallback,
|
||||
.AdvDisableCallback = BleAdvDisableCallback,
|
||||
.AdvDataCallback = BleAdvDataCallback,
|
||||
.AdvUpdateCallback = BleAdvUpdateCallback
|
||||
.AdvUpdateCallback = BleAdvUpdateCallback,
|
||||
.LpDeviceInfoCallback = NULL
|
||||
};
|
||||
|
||||
static SoftBusScanListener g_scanListener = {
|
||||
.OnScanStart = BleOnScanStart,
|
||||
.OnScanStop = BleOnScanStop,
|
||||
.OnScanResult = BleScanResultCallback
|
||||
.OnScanResult = BleScanResultCallback,
|
||||
.OnScanStateChanged = NULL
|
||||
};
|
||||
|
||||
static SoftBusBtStateListener g_stateChangedListener = {
|
||||
@ -930,7 +933,7 @@ static void StartScaner(void)
|
||||
DLOGE("GetScannerParam failed");
|
||||
return;
|
||||
}
|
||||
if (SoftBusStartScan(g_bleListener.scanListenerId, &scanParam) != SOFTBUS_OK) {
|
||||
if (SoftBusStartScan(g_bleListener.scanListenerId, g_bleScannerId, &scanParam) != SOFTBUS_OK) {
|
||||
DLOGE("start scan failed");
|
||||
return;
|
||||
}
|
||||
@ -943,7 +946,7 @@ static int32_t StopScaner(void)
|
||||
DLOGI("already stop scanning");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (SoftBusStopScan(g_bleListener.scanListenerId) != SOFTBUS_OK) {
|
||||
if (SoftBusStopScan(g_bleListener.scanListenerId, g_bleScannerId) != SOFTBUS_OK) {
|
||||
DLOGI("StopScaner failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
@ -1222,8 +1225,8 @@ static DiscoveryBleDispatcherInterface g_discBleDispatcherInterface = {
|
||||
|
||||
static int32_t InitAdvertiser(void)
|
||||
{
|
||||
int32_t conChannel = SoftBusGetAdvChannel(&g_advCallback);
|
||||
int32_t nonChannel = SoftBusGetAdvChannel(&g_advCallback);
|
||||
int32_t conChannel = SoftBusGetAdvChannel(&g_advCallback, &g_bleScannerId, false);
|
||||
int32_t nonChannel = SoftBusGetAdvChannel(&g_advCallback, &g_bleScannerId, false);
|
||||
if (conChannel < 0 || nonChannel < 0) {
|
||||
DLOGE("get adv channel failed");
|
||||
(void)SoftBusReleaseAdvChannel(conChannel);
|
||||
@ -1599,7 +1602,7 @@ static void DiscBleSetScanFilter(int32_t listenerId)
|
||||
|
||||
static int32_t InitBleListener(void)
|
||||
{
|
||||
g_bleListener.scanListenerId = SoftBusAddScanListener(&g_scanListener);
|
||||
g_bleListener.scanListenerId = SoftBusAddScanListener(&g_scanListener, &g_bleScannerId, false);
|
||||
g_bleListener.stateListenerId = SoftBusAddBtStateListener(&g_stateChangedListener);
|
||||
if (g_bleListener.stateListenerId < 0 || g_bleListener.scanListenerId < 0) {
|
||||
return SOFTBUS_ERR;
|
||||
@ -1674,6 +1677,7 @@ static void BleListenerDeinit(void)
|
||||
{
|
||||
(void)SoftBusRemoveBtStateListener(g_bleListener.stateListenerId);
|
||||
(void)SoftBusRemoveScanListener(g_bleListener.scanListenerId);
|
||||
(void)SoftBusDeregisterScanCallbacks(g_bleScannerId);
|
||||
}
|
||||
|
||||
static void DiscBleInfoDeinit(void)
|
||||
|
@ -25,6 +25,7 @@
|
||||
MockBluetooth *MockBluetooth::targetMocker = nullptr;
|
||||
BtGapCallBacks *MockBluetooth::btGapCallback = nullptr;
|
||||
BtGattCallbacks *MockBluetooth::btGattCallback = nullptr;
|
||||
BleScanCallbacks *MockBluetooth::bleScanCallback = nullptr;
|
||||
|
||||
static int ActionGapRegisterCallbacks(BtGapCallBacks *func)
|
||||
{
|
||||
@ -101,14 +102,14 @@ int BleGattRegisterCallbacks(BtGattCallbacks *func)
|
||||
return MockBluetooth::GetMocker()->BleGattRegisterCallbacks(func);
|
||||
}
|
||||
|
||||
int BleStartScanEx(BleScanConfigs *configs, BleScanNativeFilter *filter, unsigned int filterSize)
|
||||
int BleStartScanEx(int scannerId, BleScanConfigs *configs, BleScanNativeFilter *filter, unsigned int filterSize)
|
||||
{
|
||||
return MockBluetooth::GetMocker()->BleStartScanEx(configs, filter, filterSize);
|
||||
return MockBluetooth::GetMocker()->BleStartScanEx(scannerId, configs, filter, filterSize);
|
||||
}
|
||||
|
||||
int BleStopScan(void)
|
||||
int BleStopScan(int scannerId)
|
||||
{
|
||||
return MockBluetooth::GetMocker()->BleStopScan();
|
||||
return MockBluetooth::GetMocker()->BleStopScan(scannerId);
|
||||
}
|
||||
|
||||
int BleStartAdvEx(int *advId, const StartAdvRawData rawData, BleAdvParams advParam)
|
||||
|
@ -40,8 +40,8 @@ public:
|
||||
|
||||
// BLE广播相关
|
||||
virtual int BleGattRegisterCallbacks(BtGattCallbacks *func) = 0;
|
||||
virtual int BleStartScanEx(BleScanConfigs *configs, BleScanNativeFilter *filter, unsigned int filterSize) = 0;
|
||||
virtual int BleStopScan(void) = 0;
|
||||
virtual int BleStartScanEx(int scannerId, BleScanConfigs *configs, BleScanNativeFilter *filter, unsigned int filterSize) = 0;
|
||||
virtual int BleStopScan(int scannerId) = 0;
|
||||
virtual int BleStartAdvEx(int *advId, const StartAdvRawData rawData, BleAdvParams advParam) = 0;
|
||||
virtual int BleStopAdv(int advId) = 0;
|
||||
|
||||
@ -91,9 +91,9 @@ public:
|
||||
MOCK_METHOD(bool, SetDevicePairingConfirmation, (const BdAddr *bdAddr, int transport, bool accept), (override));
|
||||
|
||||
MOCK_METHOD(int, BleGattRegisterCallbacks, (BtGattCallbacks *func), (override));
|
||||
MOCK_METHOD(int, BleStartScanEx, (BleScanConfigs * configs, BleScanNativeFilter *filter, unsigned int filterSize),
|
||||
MOCK_METHOD(int, BleStartScanEx, (int scannerId, BleScanConfigs * configs, BleScanNativeFilter *filter, unsigned int filterSize),
|
||||
(override));
|
||||
MOCK_METHOD(int, BleStopScan, (), (override));
|
||||
MOCK_METHOD(int, BleStopScan, (int scannerId), (override));
|
||||
MOCK_METHOD(int, BleStartAdvEx, (int *advId, const StartAdvRawData rawData, BleAdvParams advParam), (override));
|
||||
MOCK_METHOD(int, BleStopAdv, (int advId), (override));
|
||||
|
||||
@ -134,6 +134,7 @@ public:
|
||||
|
||||
static BtGapCallBacks *btGapCallback;
|
||||
static BtGattCallbacks *btGattCallback;
|
||||
static BleScanCallbacks *bleScanCallback;
|
||||
|
||||
private:
|
||||
static MockBluetooth *targetMocker;
|
||||
|
@ -93,6 +93,7 @@ SoftBusScanListener *GetStubScanListener()
|
||||
.OnScanStart = StubOnScanStart,
|
||||
.OnScanStop = StubOnScanStop,
|
||||
.OnScanResult = StubOnScanResult,
|
||||
.OnScanStateChanged = NULL
|
||||
};
|
||||
return &listener;
|
||||
}
|
||||
@ -138,13 +139,14 @@ SoftBusAdvCallback *GetStubAdvCallback()
|
||||
static SoftBusAdvCallback callback = {.AdvEnableCallback = StubAdvEnableCallback,
|
||||
.AdvDisableCallback = StubAdvDisableCallback,
|
||||
.AdvDataCallback = StubAdvDataCallback,
|
||||
.AdvUpdateCallback = StubAdvUpdateCallback};
|
||||
.AdvUpdateCallback = StubAdvUpdateCallback,
|
||||
.LpDeviceInfoCallback = NULL};
|
||||
return &callback;
|
||||
}
|
||||
|
||||
static testing::AssertionResult PrepareScanListener(MockBluetooth &mocker, int *outId)
|
||||
static testing::AssertionResult PrepareScanListener(MockBluetooth &mocker, int *outId, int *scannerId)
|
||||
{
|
||||
auto id = SoftBusAddScanListener(GetStubScanListener());
|
||||
auto id = SoftBusAddScanListener(GetStubScanListener(), scannerId, false);
|
||||
if (id == SOFTBUS_ERR) {
|
||||
return testing::AssertionFailure() << "SoftBusAddScanListener failed";
|
||||
}
|
||||
@ -155,11 +157,11 @@ static testing::AssertionResult PrepareScanListener(MockBluetooth &mocker, int *
|
||||
return testing::AssertionSuccess();
|
||||
}
|
||||
|
||||
static testing::AssertionResult PrepareAdvCallback(MockBluetooth &mocker, int *outId)
|
||||
static testing::AssertionResult PrepareAdvCallback(MockBluetooth &mocker, int *outId, int *scannerId)
|
||||
{
|
||||
EXPECT_CALL(mocker, BleStartAdvEx).WillRepeatedly(ActionSuccessBleStartAdvEx);
|
||||
EXPECT_CALL(mocker, BleStopAdv).WillRepeatedly(ActionSuccessBleStopAdv);
|
||||
auto id = SoftBusGetAdvChannel(GetStubAdvCallback());
|
||||
auto id = SoftBusGetAdvChannel(GetStubAdvCallback(), scannerId, false);
|
||||
if (id == SOFTBUS_ERR) {
|
||||
return testing::AssertionFailure() << "GetStubAdvCallback failed";
|
||||
}
|
||||
@ -207,16 +209,16 @@ EXIT:
|
||||
HWTEST_F(AdapterBleGattTest, SoftBusAddScanListener, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
|
||||
ASSERT_EQ(SoftBusAddScanListener(nullptr), SOFTBUS_ERR);
|
||||
int scannerId = -1;
|
||||
ASSERT_EQ(SoftBusAddScanListener(nullptr, &scannerId, false), SOFTBUS_ERR);
|
||||
|
||||
int scanListerIds[SCAN_MAX_NUM];
|
||||
for (size_t i = 0; i < SCAN_MAX_NUM; i++) {
|
||||
scanListerIds[i] = SoftBusAddScanListener(GetStubScanListener());
|
||||
scanListerIds[i] = SoftBusAddScanListener(GetStubScanListener(), &scannerId, false);
|
||||
ASSERT_NE(scanListerIds[i], SOFTBUS_ERR);
|
||||
}
|
||||
|
||||
ASSERT_EQ(SoftBusAddScanListener(GetStubScanListener()), SOFTBUS_ERR);
|
||||
ASSERT_EQ(SoftBusAddScanListener(GetStubScanListener(), &scannerId, false), SOFTBUS_ERR);
|
||||
|
||||
for (size_t i = 0; i < SCAN_MAX_NUM; i++) {
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(scanListerIds[i]), SOFTBUS_OK);
|
||||
@ -233,7 +235,8 @@ HWTEST_F(AdapterBleGattTest, SoftBusRemoveScanListener, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId);
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
ASSERT_EQ(SoftBusRemoveScanListener(-1), SOFTBUS_INVALID_PARAM);
|
||||
@ -251,7 +254,8 @@ HWTEST_F(AdapterBleGattTest, SoftBusSetScanFilter, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId);
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
auto filter = CreateScanFilter();
|
||||
@ -276,7 +280,8 @@ HWTEST_F(AdapterBleGattTest, ScanLifecycle, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId);
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
auto filter = CreateScanFilter();
|
||||
@ -293,7 +298,7 @@ HWTEST_F(AdapterBleGattTest, ScanLifecycle, TestSize.Level3)
|
||||
};
|
||||
|
||||
EXPECT_CALL(mocker, BleStartScanEx).Times(1).WillOnce(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
ret = SoftBusStartScan(listenerId, &scanParam);
|
||||
ret = SoftBusStartScan(listenerId, scannerId, &scanParam);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
ASSERT_TRUE(scanStartCtx.Expect(listenerId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
@ -303,7 +308,7 @@ HWTEST_F(AdapterBleGattTest, ScanLifecycle, TestSize.Level3)
|
||||
BtScanResultData mockScanResult = {0};
|
||||
mockScanResult.advLen = sizeof(scanDataExample);
|
||||
mockScanResult.advData = (unsigned char *)scanDataExample;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
|
||||
SoftBusBleScanResult expectScanResult = {0};
|
||||
expectScanResult.advLen = sizeof(scanDataExample);
|
||||
@ -311,7 +316,7 @@ HWTEST_F(AdapterBleGattTest, ScanLifecycle, TestSize.Level3)
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
EXPECT_CALL(mocker, BleStopScan).Times(1).WillOnce(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
ret = SoftBusStopScan(listenerId);
|
||||
ret = SoftBusStopScan(listenerId, scannerId);
|
||||
ASSERT_EQ(ret, SOFTBUS_OK);
|
||||
ASSERT_TRUE(scanStopCtx.Expect(listenerId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
@ -328,7 +333,8 @@ HWTEST_F(AdapterBleGattTest, ScanResultCb, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int listenerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId);
|
||||
int scannerId = -1;
|
||||
auto result = PrepareScanListener(mocker, &listenerId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
auto filter = CreateScanFilter();
|
||||
@ -344,8 +350,8 @@ HWTEST_F(AdapterBleGattTest, ScanResultCb, TestSize.Level3)
|
||||
.scanFilterPolicy = 0,
|
||||
};
|
||||
EXPECT_CALL(mocker, BleStartScanEx).Times(1).WillOnce(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
ASSERT_EQ(SoftBusStartScan(listenerId, nullptr), SOFTBUS_INVALID_PARAM);
|
||||
ASSERT_EQ(SoftBusStartScan(listenerId, &scanParam), SOFTBUS_OK);
|
||||
ASSERT_EQ(SoftBusStartScan(listenerId, scannerId, nullptr), SOFTBUS_INVALID_PARAM);
|
||||
ASSERT_EQ(SoftBusStartScan(listenerId, scannerId, &scanParam), SOFTBUS_OK);
|
||||
ASSERT_TRUE(scanStartCtx.Expect(listenerId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
const unsigned char scanDataExample[] = {0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04, 0x05, 0x90, 0x00, 0x00,
|
||||
@ -364,7 +370,7 @@ HWTEST_F(AdapterBleGattTest, ScanResultCb, TestSize.Level3)
|
||||
mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_NO_PACKET;
|
||||
mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_NO_PACKET;
|
||||
mockScanResult.directAddrType = OHOS_BLE_PUBLIC_DEVICE_ADDRESS;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED;
|
||||
@ -373,7 +379,7 @@ HWTEST_F(AdapterBleGattTest, ScanResultCb, TestSize.Level3)
|
||||
mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_1M;
|
||||
mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_1M;
|
||||
mockScanResult.directAddrType = OHOS_BLE_RANDOM_DEVICE_ADDRESS;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_CONNECTABLE;
|
||||
@ -382,7 +388,7 @@ HWTEST_F(AdapterBleGattTest, ScanResultCb, TestSize.Level3)
|
||||
mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_2M;
|
||||
mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_2M;
|
||||
mockScanResult.directAddrType = OHOS_BLE_PUBLIC_IDENTITY_ADDRESS;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_CONNECTABLE_DIRECTED;
|
||||
@ -391,7 +397,7 @@ HWTEST_F(AdapterBleGattTest, ScanResultCb, TestSize.Level3)
|
||||
mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_CODED;
|
||||
mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_CODED;
|
||||
mockScanResult.directAddrType = OHOS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_SCANNABLE;
|
||||
@ -399,43 +405,43 @@ HWTEST_F(AdapterBleGattTest, ScanResultCb, TestSize.Level3)
|
||||
mockScanResult.primaryPhy = UINT8_MAX;
|
||||
mockScanResult.secondaryPhy = UINT8_MAX;
|
||||
mockScanResult.directAddrType = OHOS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_SCANNABLE_DIRECTED;
|
||||
mockScanResult.addrType = OHOS_BLE_NO_ADDRESS;
|
||||
mockScanResult.directAddrType = OHOS_BLE_NO_ADDRESS;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_NON_CONNECTABLE;
|
||||
mockScanResult.addrType = UINT8_MAX;
|
||||
mockScanResult.directAddrType = UINT8_MAX;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_SCANNABLE;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_CONNECTABLE;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
|
||||
mockScanResult.eventType = UINT8_MAX;
|
||||
MockBluetooth::btGattCallback->scanResultCb(&mockScanResult);
|
||||
MockBluetooth::bleScanCallback->scanResultCb(&mockScanResult);
|
||||
ASSERT_TRUE(scanResultCtx.Expect(listenerId, &expectScanResult));
|
||||
}
|
||||
|
||||
@ -449,7 +455,8 @@ HWTEST_F(AdapterBleGattTest, AdvertiseLifecycle, TestSize.Level3)
|
||||
{
|
||||
MockBluetooth mocker;
|
||||
int advId = -1;
|
||||
auto result = PrepareAdvCallback(mocker, &advId);
|
||||
int scannerId = -1;
|
||||
auto result = PrepareAdvCallback(mocker, &advId, &scannerId);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
const char advDataExample[] = {0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04, 0x05, 0x90, 0x00, 0x00, 0x04, 0x00,
|
||||
@ -485,7 +492,6 @@ HWTEST_F(AdapterBleGattTest, AdvertiseLifecycle, TestSize.Level3)
|
||||
ASSERT_TRUE(advUpdateCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
|
||||
MockBluetooth::btGattCallback->securityRespondCb(nullptr);
|
||||
MockBluetooth::btGattCallback->scanParamSetCb(btInnerAdvId, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
|
||||
ASSERT_EQ(SoftBusStopAdv(advId), SOFTBUS_OK);
|
||||
ASSERT_TRUE(advDisableCtx.Expect(advId, SOFTBUS_BT_STATUS_SUCCESS));
|
||||
@ -504,14 +510,15 @@ HWTEST_F(AdapterBleGattTest, AdvertiseLifecycle, TestSize.Level3)
|
||||
*/
|
||||
HWTEST_F(AdapterBleGattTest, SoftBusGetAdvChannel, TestSize.Level3)
|
||||
{
|
||||
ASSERT_EQ(SoftBusGetAdvChannel(nullptr), SOFTBUS_INVALID_PARAM);
|
||||
int scannerId = -1;
|
||||
ASSERT_EQ(SoftBusGetAdvChannel(nullptr, &scannerId, false), SOFTBUS_INVALID_PARAM);
|
||||
MockBluetooth mocker;
|
||||
int advIds[ADV_MAX_NUM];
|
||||
for (size_t i = 0; i < ADV_MAX_NUM; i++) {
|
||||
advIds[i] = SoftBusGetAdvChannel(GetStubAdvCallback());
|
||||
advIds[i] = SoftBusGetAdvChannel(GetStubAdvCallback(), &scannerId, false);
|
||||
ASSERT_NE(advIds[i], SOFTBUS_ERR);
|
||||
}
|
||||
ASSERT_EQ(SoftBusGetAdvChannel(GetStubAdvCallback()), SOFTBUS_ERR);
|
||||
ASSERT_EQ(SoftBusGetAdvChannel(GetStubAdvCallback(), &scannerId, false), SOFTBUS_ERR);
|
||||
for (size_t i = 0; i < ADV_MAX_NUM; i++) {
|
||||
ASSERT_EQ(SoftBusReleaseAdvChannel(advIds[i]), SOFTBUS_OK);
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener)
|
||||
return BleMock::GetMock()->SoftBusAddBtStateListener(listener);
|
||||
}
|
||||
|
||||
int SoftBusAddScanListener(const SoftBusScanListener *listener)
|
||||
int SoftBusAddScanListener(const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan)
|
||||
{
|
||||
return BleMock::GetMock()->SoftBusAddScanListener(listener);
|
||||
return BleMock::GetMock()->SoftBusAddScanListener(listener, scannerId, isLpDeviceScan);
|
||||
}
|
||||
|
||||
int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter *filter, uint8_t filterSize)
|
||||
@ -45,9 +45,9 @@ int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter *filter, uint8_t f
|
||||
return BleMock::GetMock()->SoftBusSetScanFilter(listenerId, filter, filterSize);
|
||||
}
|
||||
|
||||
int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback)
|
||||
int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan)
|
||||
{
|
||||
return BleMock::GetMock()->SoftBusGetAdvChannel(callback);
|
||||
return BleMock::GetMock()->SoftBusGetAdvChannel(callback, scannerId, isLpDeviceScan);
|
||||
}
|
||||
|
||||
int SoftBusReleaseAdvChannel(int channel)
|
||||
@ -55,9 +55,9 @@ int SoftBusReleaseAdvChannel(int channel)
|
||||
return BleMock::GetMock()->SoftBusReleaseAdvChannel(channel);
|
||||
}
|
||||
|
||||
int SoftBusStopScan(int listenerId)
|
||||
int SoftBusStopScan(int listenerId, int scannerId)
|
||||
{
|
||||
return BleMock::GetMock()->SoftBusStopScan(listenerId);
|
||||
return BleMock::GetMock()->SoftBusStopScan(listenerId, scannerId);
|
||||
}
|
||||
|
||||
int SoftBusRemoveBtStateListener(int listenerId)
|
||||
@ -70,6 +70,11 @@ int SoftBusRemoveScanListener(int listenerId)
|
||||
return BleMock::GetMock()->SoftBusRemoveScanListener(listenerId);
|
||||
}
|
||||
|
||||
int32_t SoftBusDeregisterScanCallbacks(int32_t scannerId)
|
||||
{
|
||||
return BleMock::GetMock()->SoftBusDeregisterScanCallbacks(scannerId);
|
||||
}
|
||||
|
||||
int SoftBusStopAdv(int channel)
|
||||
{
|
||||
return BleMock::GetMock()->SoftBusStopAdv(channel);
|
||||
@ -80,9 +85,9 @@ int SoftBusUpdateAdv(int channel, const SoftBusBleAdvData *data, const SoftBusBl
|
||||
return BleMock::GetMock()->SoftBusUpdateAdv(channel, data, param);
|
||||
}
|
||||
|
||||
int SoftBusStartScan(int listenerId, const SoftBusBleScanParams *param)
|
||||
int SoftBusStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *param)
|
||||
{
|
||||
return BleMock::GetMock()->SoftBusStartScan(listenerId, param);
|
||||
return BleMock::GetMock()->SoftBusStartScan(listenerId, scannerId, param);
|
||||
}
|
||||
|
||||
int SoftBusSetAdvData(int channel, const SoftBusBleAdvData *data)
|
||||
@ -134,7 +139,7 @@ int32_t BleMock::ActionOfRemoveBtStateListener(int listenerId)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t BleMock::ActionOfAddScanListener(const SoftBusScanListener *listener)
|
||||
int32_t BleMock::ActionOfAddScanListener(const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan)
|
||||
{
|
||||
scanListener = listener;
|
||||
return SCAN_LISTENER_ID;
|
||||
@ -146,13 +151,18 @@ int32_t BleMock::ActionOfRemoveScanListener(int listenerId)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t BleMock::ActionOfDeregisterScanCallbacks(int scannerId)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t BleMock::ActionOfSetScanFilter(int listenerId, const SoftBusBleScanFilter *filter, uint8_t filterSize)
|
||||
{
|
||||
DLOGI("listenerId=%d filterSize=%d", listenerId, filterSize);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t BleMock::ActionOfGetAdvChannel(const SoftBusAdvCallback *callback)
|
||||
int32_t BleMock::ActionOfGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan)
|
||||
{
|
||||
static int32_t advChannel = 0;
|
||||
advCallback = callback;
|
||||
@ -165,7 +175,7 @@ int32_t BleMock::ActionOfReleaseAdvChannel(int channel)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t BleMock::ActionOfStartScan(int listenerId, const SoftBusBleScanParams *param)
|
||||
int32_t BleMock::ActionOfStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *param)
|
||||
{
|
||||
if (listenerId != SCAN_LISTENER_ID) {
|
||||
return SOFTBUS_ERR;
|
||||
@ -179,7 +189,7 @@ int32_t BleMock::ActionOfStartScan(int listenerId, const SoftBusBleScanParams *p
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t BleMock::ActionOfStopScan(int listenerId)
|
||||
int32_t BleMock::ActionOfStopScan(int listenerId, int scannerId)
|
||||
{
|
||||
if (listenerId != SCAN_LISTENER_ID) {
|
||||
return SOFTBUS_ERR;
|
||||
@ -464,11 +474,12 @@ void BleMock::SetupSuccessStub()
|
||||
EXPECT_CALL(*this, SoftBusRemoveBtStateListener).WillRepeatedly(BleMock::ActionOfRemoveBtStateListener);
|
||||
EXPECT_CALL(*this, BleGattLockInit).WillRepeatedly(BleMock::ActionOfBleGattLockInit);
|
||||
EXPECT_CALL(*this, SoftBusAddBtStateListener(NotNull())).WillRepeatedly(BleMock::ActionOfAddBtStateListener);
|
||||
EXPECT_CALL(*this, SoftBusAddScanListener(NotNull())).WillRepeatedly(BleMock::ActionOfAddScanListener);
|
||||
EXPECT_CALL(*this, SoftBusAddScanListener).WillRepeatedly(BleMock::ActionOfAddScanListener);
|
||||
EXPECT_CALL(*this, SoftBusGetAdvChannel).WillRepeatedly(BleMock::ActionOfGetAdvChannel);
|
||||
EXPECT_CALL(*this, SoftBusSetScanFilter).WillRepeatedly(BleMock::ActionOfSetScanFilter);
|
||||
EXPECT_CALL(*this, SoftBusRemoveScanListener).WillRepeatedly(BleMock::ActionOfRemoveScanListener);
|
||||
EXPECT_CALL(*this, SoftBusReleaseAdvChannel).WillRepeatedly(BleMock::ActionOfReleaseAdvChannel);
|
||||
EXPECT_CALL(*this, SoftBusDeregisterScanCallbacks).WillRepeatedly(BleMock::ActionOfDeregisterScanCallbacks);
|
||||
}
|
||||
|
||||
void BleMock::AsyncAdvertiseDone()
|
||||
|
@ -32,16 +32,16 @@ public:
|
||||
virtual int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener) = 0;
|
||||
virtual int SoftBusRemoveBtStateListener(int listenerId) = 0;
|
||||
|
||||
virtual int SoftBusAddScanListener(const SoftBusScanListener *listener) = 0;
|
||||
virtual int SoftBusAddScanListener(const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan) = 0;
|
||||
virtual int SoftBusRemoveScanListener(int listenerId) = 0;
|
||||
|
||||
virtual int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter *filter, uint8_t filterSize) = 0;
|
||||
|
||||
virtual int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback) = 0;
|
||||
virtual int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan) = 0;
|
||||
virtual int SoftBusReleaseAdvChannel(int channel) = 0;
|
||||
|
||||
virtual int SoftBusStartScan(int listenerId, const SoftBusBleScanParams *param) = 0;
|
||||
virtual int SoftBusStopScan(int listenerId) = 0;
|
||||
virtual int SoftBusStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *param) = 0;
|
||||
virtual int SoftBusStopScan(int listenerId, int scannerId) = 0;
|
||||
|
||||
virtual int SoftBusStartAdv(int channel, const SoftBusBleAdvParams *param) = 0;
|
||||
virtual int SoftBusStopAdv(int channel) = 0;
|
||||
@ -51,6 +51,8 @@ public:
|
||||
|
||||
virtual int SoftBusGetBtMacAddr(SoftBusBtAddr *mac) = 0;
|
||||
virtual int SoftBusGetBtState() = 0;
|
||||
|
||||
virtual int32_t SoftBusDeregisterScanCallbacks(int32_t scannerId) = 0;
|
||||
};
|
||||
|
||||
class BleMock : public BleInterface {
|
||||
@ -68,17 +70,19 @@ public:
|
||||
MOCK_METHOD(int, SoftBusAddBtStateListener, (const SoftBusBtStateListener *listener), (override));
|
||||
MOCK_METHOD(int, SoftBusRemoveBtStateListener, (int listenerId), (override));
|
||||
|
||||
MOCK_METHOD(int, SoftBusAddScanListener, (const SoftBusScanListener *listener), (override));
|
||||
MOCK_METHOD(int, SoftBusAddScanListener, (const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan), (override));
|
||||
MOCK_METHOD(int, SoftBusRemoveScanListener, (int listenerId), (override));
|
||||
|
||||
MOCK_METHOD(int, SoftBusDeregisterScanCallbacks, (int32_t scannerId), (override));
|
||||
|
||||
MOCK_METHOD(int, SoftBusSetScanFilter, (int listenerId, SoftBusBleScanFilter *filter, uint8_t filterSize),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(int, SoftBusGetAdvChannel, (const SoftBusAdvCallback *callback), (override));
|
||||
MOCK_METHOD(int, SoftBusGetAdvChannel, (const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan), (override));
|
||||
MOCK_METHOD(int, SoftBusReleaseAdvChannel, (int channel), (override));
|
||||
|
||||
MOCK_METHOD(int, SoftBusStartScan, (int listenerId, const SoftBusBleScanParams *param), (override));
|
||||
MOCK_METHOD(int, SoftBusStopScan, (int listenerId), (override));
|
||||
MOCK_METHOD(int, SoftBusStartScan, (int listenerId, int scannerId, const SoftBusBleScanParams *param), (override));
|
||||
MOCK_METHOD(int, SoftBusStopScan, (int listenerId, int scannerId), (override));
|
||||
|
||||
MOCK_METHOD(int, SoftBusStartAdv, (int channel, const SoftBusBleAdvParams *param), (override));
|
||||
MOCK_METHOD(int, SoftBusStopAdv, (int channel), (override));
|
||||
@ -99,13 +103,14 @@ public:
|
||||
static int32_t ActionOfBleGattLockInit();
|
||||
static int32_t ActionOfAddBtStateListener(const SoftBusBtStateListener *listener);
|
||||
static int32_t ActionOfRemoveBtStateListener(int listenerId);
|
||||
static int32_t ActionOfAddScanListener(const SoftBusScanListener *listener);
|
||||
static int32_t ActionOfAddScanListener(const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan);
|
||||
static int32_t ActionOfRemoveScanListener(int listenerId);
|
||||
static int32_t ActionOfDeregisterScanCallbacks(int scannerId);
|
||||
static int32_t ActionOfSetScanFilter(int listenerId, const SoftBusBleScanFilter *filter, uint8_t filterSize);
|
||||
static int32_t ActionOfGetAdvChannel(const SoftBusAdvCallback *callback);
|
||||
static int32_t ActionOfGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan);
|
||||
static int32_t ActionOfReleaseAdvChannel(int channel);
|
||||
static int32_t ActionOfStartScan(int listenerId, const SoftBusBleScanParams *param);
|
||||
static int32_t ActionOfStopScan(int listenerId);
|
||||
static int32_t ActionOfStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *param);
|
||||
static int32_t ActionOfStopScan(int listenerId, int scannerId);
|
||||
static int32_t ActionOfStartAdv(int channel, const SoftBusBleAdvParams *param);
|
||||
static int32_t ActionOfStopAdv(int channel);
|
||||
static int32_t ActionOfSetAdvDataForActiveDiscovery(int channel, const SoftBusBleAdvData *data);
|
||||
|
Loading…
Reference in New Issue
Block a user