mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2025-02-24 05:02:53 +00:00
Code View Modifications
Signed-off-by: erliangqi <zhangjiaxiang7@huawei.com>
This commit is contained in:
parent
bfde0f0dd3
commit
15f8e5287e
@ -12,18 +12,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "softbus_adapter_ble_gatt.h"
|
||||
|
||||
#include "adapter_bt_utils.h"
|
||||
#include "c_header/ohos_bt_def.h"
|
||||
#include "c_header/ohos_bt_gap.h"
|
||||
#include "c_header/ohos_bt_gatt.h"
|
||||
#include "disc_log.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_ble_gatt.h"
|
||||
#include "softbus_adapter_bt_common.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_adapter_thread.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_utils.h"
|
||||
|
||||
@ -52,12 +50,32 @@ typedef struct {
|
||||
int32_t scannerId;
|
||||
} ScanListener;
|
||||
|
||||
typedef struct {
|
||||
BleScanResultEvtType bleEvtType;
|
||||
SoftBusBleScanResultEvtType softBusEvtType;
|
||||
} OhosBleEvtToSoftBusEvt;
|
||||
|
||||
OhosBleEvtToSoftBusEvt g_bleEvtSoftBusEvt[] = {
|
||||
{OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE, SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE},
|
||||
{OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED, SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED},
|
||||
{OHOS_BLE_EVT_CONNECTABLE, SOFTBUS_BLE_EVT_CONNECTABLE},
|
||||
{OHOS_BLE_EVT_CONNECTABLE_DIRECTED, SOFTBUS_BLE_EVT_CONNECTABLE_DIRECTED},
|
||||
{OHOS_BLE_EVT_SCANNABLE, SOFTBUS_BLE_EVT_SCANNABLE},
|
||||
{OHOS_BLE_EVT_SCANNABLE_DIRECTED, SOFTBUS_BLE_EVT_SCANNABLE_DIRECTED},
|
||||
{OHOS_BLE_EVT_LEGACY_NON_CONNECTABLE, SOFTBUS_BLE_EVT_LEGACY_NON_CONNECTABLE},
|
||||
{OHOS_BLE_EVT_LEGACY_SCANNABLE, SOFTBUS_BLE_EVT_LEGACY_SCANNABLE},
|
||||
{OHOS_BLE_EVT_LEGACY_CONNECTABLE, SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE},
|
||||
{OHOS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED, SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED},
|
||||
{OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN, SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN},
|
||||
{OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV, SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV},
|
||||
};
|
||||
|
||||
static AdvChannel g_advChannel[ADV_MAX_NUM];
|
||||
static ScanListener g_scanListener[SCAN_MAX_NUM];
|
||||
|
||||
static volatile bool g_lockInit = false;
|
||||
static SoftBusMutex g_advLock = {0};
|
||||
static SoftBusMutex g_scanerLock = {0};
|
||||
static SoftBusMutex g_advLock;
|
||||
static SoftBusMutex g_scanerLock;
|
||||
|
||||
static volatile bool g_isRegCb = false;
|
||||
static volatile bool g_isLpDeviceRegCb = false;
|
||||
@ -70,24 +88,26 @@ static void OnBtStateChanged(int32_t listenerId, int32_t state)
|
||||
}
|
||||
|
||||
DISC_LOGI(DISC_BLE, "receive bt turn off event, start reset bt adapter state...");
|
||||
if (SoftBusMutexLock(&g_advLock) != 0) {
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "ATTENTION, try to get adv lock failed, something unexpected happened");
|
||||
return;
|
||||
}
|
||||
for (uint32_t index = 0; index < ADV_MAX_NUM; index++) {
|
||||
AdvChannel *advChannel = &g_advChannel[index];
|
||||
if (advChannel->isUsed && advChannel->advId != -1) {
|
||||
// ignore status code explicitedly, just to notify bt cleanup resources associated with this advertisement
|
||||
(void)BleStopAdv(advChannel->advId);
|
||||
advChannel->advId = -1;
|
||||
advChannel->isAdvertising = false;
|
||||
SoftBusCondBroadcast(&advChannel->cond);
|
||||
advChannel->advCallback->AdvDisableCallback(index, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
if (advChannel->isUsed && advChannel->advId == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// ignore status code explicitedly, just to notify bt cleanup resources associated with this advertisement
|
||||
(void)BleStopAdv(advChannel->advId);
|
||||
advChannel->advId = -1;
|
||||
advChannel->isAdvertising = false;
|
||||
SoftBusCondBroadcast(&advChannel->cond);
|
||||
advChannel->advCallback->AdvDisableCallback(index, SOFTBUS_BT_STATUS_SUCCESS);
|
||||
}
|
||||
(void)SoftBusMutexUnlock(&g_advLock);
|
||||
|
||||
if (SoftBusMutexLock(&g_scanerLock) != 0) {
|
||||
if (SoftBusMutexLock(&g_scanerLock) != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "ATTENTION, try to get scan lock failed, something unexpected happened");
|
||||
return;
|
||||
}
|
||||
@ -121,34 +141,18 @@ int BleGattLockInit(void)
|
||||
|
||||
static unsigned char ConvertScanEventType(unsigned char eventType)
|
||||
{
|
||||
switch (eventType) {
|
||||
case OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE:
|
||||
return SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE;
|
||||
case OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED:
|
||||
return SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED;
|
||||
case OHOS_BLE_EVT_CONNECTABLE:
|
||||
return SOFTBUS_BLE_EVT_CONNECTABLE;
|
||||
case OHOS_BLE_EVT_CONNECTABLE_DIRECTED:
|
||||
return SOFTBUS_BLE_EVT_CONNECTABLE_DIRECTED;
|
||||
case OHOS_BLE_EVT_SCANNABLE:
|
||||
return SOFTBUS_BLE_EVT_SCANNABLE;
|
||||
case OHOS_BLE_EVT_SCANNABLE_DIRECTED:
|
||||
return SOFTBUS_BLE_EVT_SCANNABLE_DIRECTED;
|
||||
case OHOS_BLE_EVT_LEGACY_NON_CONNECTABLE:
|
||||
return SOFTBUS_BLE_EVT_LEGACY_NON_CONNECTABLE;
|
||||
case OHOS_BLE_EVT_LEGACY_SCANNABLE:
|
||||
return SOFTBUS_BLE_EVT_LEGACY_SCANNABLE;
|
||||
case OHOS_BLE_EVT_LEGACY_CONNECTABLE:
|
||||
return SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE;
|
||||
case OHOS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED:
|
||||
return SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED;
|
||||
case OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN:
|
||||
return SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN;
|
||||
case OHOS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV:
|
||||
return SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV;
|
||||
default:
|
||||
return SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE;
|
||||
int32_t status = SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE;
|
||||
int len = sizeof(g_bleEvtSoftBusEvt) / sizeof(g_bleEvtSoftBusEvt[0]);
|
||||
OhosBleEvtToSoftBusEvt *ptr = g_bleEvtSoftBusEvt;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (eventType == (ptr + i)->bleEvtType) {
|
||||
status = (ptr + i)->softBusEvtType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static unsigned char ConvertScanPhyType(unsigned char phyType)
|
||||
@ -174,9 +178,7 @@ static unsigned char ConvertScanDataStatus(unsigned char dataStatus)
|
||||
return SOFTBUS_BLE_DATA_COMPLETE;
|
||||
case OHOS_BLE_DATA_INCOMPLETE_MORE_TO_COME:
|
||||
return SOFTBUS_BLE_DATA_INCOMPLETE_MORE_TO_COME;
|
||||
case OHOS_BLE_DATA_INCOMPLETE_TRUNCATED:
|
||||
return SOFTBUS_BLE_DATA_INCOMPLETE_TRUNCATED;
|
||||
default:
|
||||
default: // fall-through
|
||||
return SOFTBUS_BLE_DATA_INCOMPLETE_TRUNCATED;
|
||||
}
|
||||
}
|
||||
@ -194,9 +196,7 @@ static unsigned char ConvertScanAddrType(unsigned char addrType)
|
||||
return SOFTBUS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS;
|
||||
case OHOS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS:
|
||||
return SOFTBUS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS;
|
||||
case OHOS_BLE_NO_ADDRESS:
|
||||
return SOFTBUS_BLE_NO_ADDRESS;
|
||||
default:
|
||||
default: // fall-through
|
||||
return SOFTBUS_BLE_NO_ADDRESS;
|
||||
}
|
||||
}
|
||||
@ -256,7 +256,7 @@ static void DumpBleScanFilter(BleScanNativeFilter *nativeFilter, uint8_t filterS
|
||||
}
|
||||
(void)ConvertBytesToHexString(serviceData, hexLen, (nativeFilter + filterSize)->serviceData, len);
|
||||
(void)ConvertBytesToHexString(serviceDataMask, hexLen, (nativeFilter + filterSize)->serviceDataMask, len);
|
||||
DISC_LOGI(DISC_BLE, "BLE Scan Filter id:%d [serviceData:%s, serviceDataMask:%s]",
|
||||
DISC_LOGI(DISC_BLE, "BLE Scan Filter id:%u [serviceData:%s, serviceDataMask:%s]",
|
||||
filterSize, serviceData, serviceDataMask);
|
||||
SoftBusFree(serviceData);
|
||||
SoftBusFree(serviceDataMask);
|
||||
@ -286,20 +286,25 @@ static void GetAllNativeScanFilter(int thisListenerId, BleScanNativeFilter **nat
|
||||
}
|
||||
uint8_t size = g_scanListener[index].filterSize;
|
||||
const SoftBusBleScanFilter *filter = g_scanListener[index].filter;
|
||||
BleScanNativeFilter **nativeOffset = NULL;
|
||||
const SoftBusBleScanFilter *filterOffset = NULL;
|
||||
|
||||
while (size-- > 0) {
|
||||
nativeSize--;
|
||||
(*nativeFilter + nativeSize)->address = (filter + size)->address;
|
||||
(*nativeFilter + nativeSize)->deviceName = (filter + size)->deviceName;
|
||||
(*nativeFilter + nativeSize)->manufactureData = (filter + size)->manufactureData;
|
||||
(*nativeFilter + nativeSize)->manufactureDataLength = (filter + size)->manufactureDataLength;
|
||||
(*nativeFilter + nativeSize)->manufactureDataMask = (filter + size)->manufactureDataMask;
|
||||
(*nativeFilter + nativeSize)->manufactureId = (filter + size)->manufactureId;
|
||||
(*nativeFilter + nativeSize)->serviceData = (filter + size)->serviceData;
|
||||
(*nativeFilter + nativeSize)->serviceDataLength = (filter + size)->serviceDataLength;
|
||||
(*nativeFilter + nativeSize)->serviceDataMask = (filter + size)->serviceDataMask;
|
||||
(*nativeFilter + nativeSize)->serviceUuid = (filter + size)->serviceUuid;
|
||||
(*nativeFilter + nativeSize)->serviceUuidLength = (filter + size)->serviceUuidLength;
|
||||
(*nativeFilter + nativeSize)->serviceUuidMask = (filter + size)->serviceUuidMask;
|
||||
*nativeOffset = *nativeFilter + nativeSize;
|
||||
filterOffset = filter + size;
|
||||
(*nativeOffset)->address = (filterOffset)->address;
|
||||
(*nativeOffset)->deviceName = (filterOffset)->deviceName;
|
||||
(*nativeOffset)->manufactureData = (filterOffset)->manufactureData;
|
||||
(*nativeOffset)->manufactureDataLength = (filterOffset)->manufactureDataLength;
|
||||
(*nativeOffset)->manufactureDataMask = (filterOffset)->manufactureDataMask;
|
||||
(*nativeOffset)->manufactureId = (filterOffset)->manufactureId;
|
||||
(*nativeOffset)->serviceData = (filterOffset)->serviceData;
|
||||
(*nativeOffset)->serviceDataLength = (filterOffset)->serviceDataLength;
|
||||
(*nativeOffset)->serviceDataMask = (filterOffset)->serviceDataMask;
|
||||
(*nativeOffset)->serviceUuid = (filterOffset)->serviceUuid;
|
||||
(*nativeOffset)->serviceUuidLength = (filterOffset)->serviceUuidLength;
|
||||
(*nativeOffset)->serviceUuidMask = (filterOffset)->serviceUuidMask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -309,22 +314,28 @@ static void SoftBusGetBurstScanFilter(int thisListenerId, BleScanNativeFilter **
|
||||
uint8_t size = g_scanListener[thisListenerId].filterSize;
|
||||
*nativeFilter = (BleScanNativeFilter *)SoftBusCalloc(sizeof(BleScanNativeFilter) * size);
|
||||
if (*nativeFilter == NULL) {
|
||||
DISC_LOGE(DISC_BLE, "nativeFilter calloc addr fail");
|
||||
return;
|
||||
}
|
||||
const SoftBusBleScanFilter *filter = g_scanListener[thisListenerId].filter;
|
||||
BleScanNativeFilter **nativeOffset = NULL;
|
||||
const SoftBusBleScanFilter *filterOffset = NULL;
|
||||
|
||||
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;
|
||||
*nativeOffset = *nativeFilter + size;
|
||||
filterOffset = filter + size;
|
||||
(*nativeOffset)->address = (filterOffset)->address;
|
||||
(*nativeOffset)->deviceName = (filterOffset)->deviceName;
|
||||
(*nativeOffset)->manufactureData = (filterOffset)->manufactureData;
|
||||
(*nativeOffset)->manufactureDataLength = (filterOffset)->manufactureDataLength;
|
||||
(*nativeOffset)->manufactureDataMask = (filterOffset)->manufactureDataMask;
|
||||
(*nativeOffset)->manufactureId = (filterOffset)->manufactureId;
|
||||
(*nativeOffset)->serviceData = (filterOffset)->serviceData;
|
||||
(*nativeOffset)->serviceDataLength = (filterOffset)->serviceDataLength;
|
||||
(*nativeOffset)->serviceDataMask = (filterOffset)->serviceDataMask;
|
||||
(*nativeOffset)->serviceUuid = (filterOffset)->serviceUuid;
|
||||
(*nativeOffset)->serviceUuidLength = (filterOffset)->serviceUuidLength;
|
||||
(*nativeOffset)->serviceUuidMask = (filterOffset)->serviceUuidMask;
|
||||
}
|
||||
*filterSize = g_scanListener[thisListenerId].filterSize;
|
||||
}
|
||||
@ -423,8 +434,7 @@ static void WrapperAdvEnableCallback(int advId, int status)
|
||||
advChannel->advCallback->AdvEnableCallback == NULL) {
|
||||
continue;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE, "WrapperAdvEnableCallback, inner-advId: %d, bt-advId: %d, "
|
||||
"status: %d", index, advId, st);
|
||||
DISC_LOGI(DISC_BLE, "inner-advId: %u, bt-advId: %d, status: %u", index, advId, st);
|
||||
if (st == SOFTBUS_BT_STATUS_SUCCESS) {
|
||||
advChannel->isAdvertising = true;
|
||||
SoftBusCondSignal(&advChannel->cond);
|
||||
@ -445,8 +455,7 @@ static void WrapperAdvDisableCallback(int advId, int status)
|
||||
advChannel->advCallback->AdvDisableCallback == NULL) {
|
||||
continue;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE, "WrapperAdvDisableCallback, inner-advId: %d, bt-advId: %d, "
|
||||
"status: %d", index, advId, st);
|
||||
DISC_LOGI(DISC_BLE, "inner-advId: %u, bt-advId: %d, status: %d", index, advId, st);
|
||||
if (st == SOFTBUS_BT_STATUS_SUCCESS) {
|
||||
advChannel->advId = -1;
|
||||
advChannel->isAdvertising = false;
|
||||
@ -468,8 +477,7 @@ static void WrapperAdvDataCallback(int advId, int status)
|
||||
advChannel->advCallback->AdvDataCallback == NULL) {
|
||||
continue;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE, "WrapperAdvDataCallback, inner-advId: %d, bt-advId: %d, "
|
||||
"status: %d", index, advId, st);
|
||||
DISC_LOGI(DISC_BLE, "inner-advId: %u, bt-advId: %d, status: %d", index, advId, st);
|
||||
advChannel->advCallback->AdvDataCallback(index, st);
|
||||
break;
|
||||
}
|
||||
@ -486,8 +494,7 @@ static void WrapperAdvUpdateCallback(int advId, int status)
|
||||
advChannel->advCallback->AdvUpdateCallback == NULL) {
|
||||
continue;
|
||||
}
|
||||
DISC_LOGI(DISC_BLE, "WrapperAdvUpdateCallback, inner-advId: %d, bt-advId: %d, "
|
||||
"status: %d", index, advId, st);
|
||||
DISC_LOGI(DISC_BLE, "inner-advId: %u, bt-advId: %d, status: %d", index, advId, st);
|
||||
advChannel->advCallback->AdvUpdateCallback(index, st);
|
||||
break;
|
||||
}
|
||||
@ -504,10 +511,10 @@ static void WrapperScanResultCallback(BtScanResultData *scanResultdata)
|
||||
if (scanResultdata == NULL) {
|
||||
return;
|
||||
}
|
||||
int listenerId;
|
||||
|
||||
SoftBusBleScanResult sr;
|
||||
ConvertScanResult(scanResultdata, &sr);
|
||||
for (listenerId = 0; listenerId < SCAN_MAX_NUM; listenerId++) {
|
||||
for (int listenerId = 0; listenerId < SCAN_MAX_NUM; listenerId++) {
|
||||
SoftBusMutexLock(&g_scanerLock);
|
||||
ScanListener *scanListener = &g_scanListener[listenerId];
|
||||
if (!scanListener->isUsed || scanListener->listener == NULL || !scanListener->isScanning ||
|
||||
@ -535,8 +542,7 @@ static void WrapperLpDeviceInfoCallback(BtUuid *uuid, int32_t type, uint8_t *dat
|
||||
|
||||
static void WrapperScanStateChangeCallback(int32_t resultCode, bool isStartScan)
|
||||
{
|
||||
int32_t listenerId;
|
||||
for (listenerId = 0; listenerId < SCAN_MAX_NUM; listenerId++) {
|
||||
for (int32_t listenerId = 0; listenerId < SCAN_MAX_NUM; listenerId++) {
|
||||
SoftBusMutexLock(&g_scanerLock);
|
||||
ScanListener *scanListener = &g_scanListener[listenerId];
|
||||
if (!scanListener->isUsed || scanListener->listener == NULL || !scanListener->isScanning ||
|
||||
@ -595,7 +601,7 @@ static int RegisterBleGattCallback(int32_t *scannerId, bool isLpDeviceScan)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (BleRegisterScanCallbacks(&g_softbusBleScanCb, scannerId) != 0) {
|
||||
DISC_LOGE(DISC_BLE, "SH register sh scan callback failed");
|
||||
DISC_LOGE(DISC_BLE, "SH register ble scan callback failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_isLpDeviceRegCb = true;
|
||||
@ -639,12 +645,12 @@ static int SetAdvData(int advId, const SoftBusBleAdvData *data)
|
||||
if (data->advLength != 0) {
|
||||
g_advChannel[advId].advData.advData = SoftBusCalloc(data->advLength);
|
||||
if (g_advChannel[advId].advData.advData == NULL) {
|
||||
DISC_LOGE(DISC_BLE, "SetAdvData calloc advData failed");
|
||||
DISC_LOGE(DISC_BLE, "calloc advData failed");
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (memcpy_s(g_advChannel[advId].advData.advData, data->advLength,
|
||||
data->advData, data->advLength) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "SetAdvData memcpy advData failed");
|
||||
DISC_LOGE(DISC_BLE, "memcpy advData failed");
|
||||
SoftBusFree(g_advChannel[advId].advData.advData);
|
||||
g_advChannel[advId].advData.advData = NULL;
|
||||
return SOFTBUS_MEM_ERR;
|
||||
@ -653,14 +659,14 @@ static int SetAdvData(int advId, const SoftBusBleAdvData *data)
|
||||
if (data->scanRspLength != 0) {
|
||||
g_advChannel[advId].advData.scanRspData = SoftBusCalloc(data->scanRspLength);
|
||||
if (g_advChannel[advId].advData.scanRspData == NULL) {
|
||||
DISC_LOGE(DISC_BLE, "SetAdvData calloc scanRspData failed");
|
||||
DISC_LOGE(DISC_BLE, "calloc scanRspData failed");
|
||||
SoftBusFree(g_advChannel[advId].advData.advData);
|
||||
g_advChannel[advId].advData.advData = NULL;
|
||||
return SOFTBUS_MALLOC_ERR;
|
||||
}
|
||||
if (memcpy_s(g_advChannel[advId].advData.scanRspData, data->scanRspLength,
|
||||
data->scanRspData, data->scanRspLength) != EOK) {
|
||||
DISC_LOGE(DISC_BLE, "SetAdvData memcpy scanRspData failed");
|
||||
DISC_LOGE(DISC_BLE, "memcpy scanRspData failed");
|
||||
SoftBusFree(g_advChannel[advId].advData.advData);
|
||||
SoftBusFree(g_advChannel[advId].advData.scanRspData);
|
||||
g_advChannel[advId].advData.advData = NULL;
|
||||
@ -686,7 +692,7 @@ int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, boo
|
||||
if (callback == NULL) {
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (SoftBusMutexLock(&g_advLock) != 0) {
|
||||
if (SoftBusMutexLock(&g_advLock) != SOFTBUS_OK) {
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
if (RegisterBleGattCallback(scannerId, isLpDeviceScan) != SOFTBUS_OK) {
|
||||
@ -831,13 +837,12 @@ int SoftBusStopAdv(int advId)
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (!g_advChannel[advId].isAdvertising) {
|
||||
DISC_LOGI(DISC_BLE, "SoftBusStopAdv, adv %d is not advertising", advId);
|
||||
DISC_LOGI(DISC_BLE, "adv %d is not advertising", advId);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
int ret = BleStopAdv(g_advChannel[advId].advId);
|
||||
DISC_LOGI(DISC_BLE, "SoftBusStopAdv, inner-advId: %d, "
|
||||
"bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
|
||||
DISC_LOGI(DISC_BLE, "inner-advId: %d, bt-advId: %d, ret: %d", advId, g_advChannel[advId].advId, ret);
|
||||
if (ret != OHOS_BT_STATUS_SUCCESS) {
|
||||
g_advChannel[advId].advCallback->AdvDisableCallback(advId, SOFTBUS_BT_STATUS_FAIL);
|
||||
SoftBusMutexUnlock(&g_advLock);
|
||||
@ -852,14 +857,17 @@ int SoftBusStopAdv(int advId)
|
||||
int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data, const SoftBusBleAdvParams *param)
|
||||
{
|
||||
if (param == NULL || data == NULL) {
|
||||
DISC_LOGE(DISC_BLE, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int ret = SoftBusStopAdv(advId);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "SoftBusStopAdv return failed, ret = %d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = SetAdvData(advId, data);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
DISC_LOGE(DISC_BLE, "SetAdvData return failed, ret = %d", ret);
|
||||
return ret;
|
||||
}
|
||||
return SoftBusStartAdv(advId, param);
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "conn_log.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_type_def.h"
|
||||
|
||||
#include "c_header/ohos_bt_def.h"
|
||||
#include "c_header/ohos_bt_gatt_client.h"
|
||||
@ -36,7 +35,7 @@ static void GattcConnectionStateChangedCallback(int clientId, int connectionStat
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "StateChangedCallback id=%d, state=%d, status=%d", clientId, connectionState, status);
|
||||
if (connectionState != OHOS_STATE_CONNECTED && connectionState != OHOS_STATE_DISCONNECTED) {
|
||||
CONN_LOGI(CONN_BLE, "GattcConnectionStateChangedCallback ignore");
|
||||
CONN_LOGI(CONN_BLE, "connectionState = %d, ignore", connectionState);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -46,6 +45,11 @@ static void GattcConnectionStateChangedCallback(int clientId, int connectionStat
|
||||
|
||||
static void GattcConnectParaUpdateCallback(int clientId, int interval, int latency, int timeout, int status)
|
||||
{
|
||||
(void)clientId;
|
||||
(void)interval;
|
||||
(void)latency;
|
||||
(void)timeout;
|
||||
(void)status;
|
||||
CONN_LOGI(CONN_BLE, "ParaUpdateCallback");
|
||||
}
|
||||
|
||||
@ -57,22 +61,26 @@ static void GattcSearchServiceCompleteCallback(int clientId, int status)
|
||||
|
||||
static void GattcReadCharacteristicCallback(int clientId, BtGattReadData *readData, int status)
|
||||
{
|
||||
(void)readData;
|
||||
CONN_LOGI(CONN_BLE, "ReadCharacteristicCallback, id=%d, status=%d", clientId, status);
|
||||
}
|
||||
|
||||
|
||||
static void GattcWriteCharacteristicCallback(int clientId, BtGattCharacteristic *characteristic, int status)
|
||||
{
|
||||
(void)characteristic;
|
||||
CONN_LOGI(CONN_BLE, "WriteCharacteristicCallback, id=%d, status=%d", clientId, status);
|
||||
}
|
||||
|
||||
static void GattcReadDescriptorCallback(int clientId, BtGattReadData *readData, int status)
|
||||
{
|
||||
(void)readData;
|
||||
CONN_LOGI(CONN_BLE, "ReadDescriptorCallback, id=%d, status=%d", clientId, status);
|
||||
}
|
||||
|
||||
static void GattcWriteDescriptorCallback(int clientId, BtGattDescriptor *descriptor, int status)
|
||||
{
|
||||
(void)descriptor;
|
||||
CONN_LOGI(CONN_BLE, "WriteDescriptorCallback, id=%d, status=%d", clientId, status);
|
||||
}
|
||||
|
||||
@ -90,8 +98,8 @@ static void GattcRegisterNotificationCallback(int clientId, int status)
|
||||
|
||||
static void GattcNotificationCallback(int clientId, BtGattReadData *notifyData, int status)
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "GattcNotificationCallback, id=%d, status=%d", clientId, status);
|
||||
if (notifyData == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return;
|
||||
}
|
||||
SoftBusGattcNotify notify;
|
||||
@ -100,12 +108,16 @@ static void GattcNotificationCallback(int clientId, BtGattReadData *notifyData,
|
||||
notify.data = notifyData->data;
|
||||
notify.charaUuid.uuid = notifyData->attribute.characteristic.characteristicUuid.uuid;
|
||||
|
||||
CONN_LOGI(CONN_BLE, "GattcNotificationCallback, id=%d, status=%d", clientId, status);
|
||||
CONN_LOGI(CONN_BLE, "id=%d, status=%d", clientId, status);
|
||||
g_softBusGattcCallback->NotificationReceiveCallback(clientId, ¬ify, status);
|
||||
}
|
||||
|
||||
void SoftbusGattcRegisterCallback(SoftBusGattcCallback *cb)
|
||||
{
|
||||
if (cb == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return;
|
||||
}
|
||||
g_btGattClientCallbacks.ConnectionStateCb = GattcConnectionStateChangedCallback;
|
||||
g_btGattClientCallbacks.connectParaUpdateCb = GattcConnectParaUpdateCallback;
|
||||
g_btGattClientCallbacks.searchServiceCompleteCb = GattcSearchServiceCompleteCallback;
|
||||
@ -146,13 +158,13 @@ int32_t SoftbusGattcConnect(int32_t clientId, SoftBusBtAddr *addr)
|
||||
{
|
||||
BdAddr bdAddr;
|
||||
if (memcpy_s(bdAddr.addr, OHOS_BD_ADDR_LEN, addr->addr, BT_ADDR_LEN) != EOK) {
|
||||
CONN_LOGE(CONN_BLE, "SoftbusGattcConnect memcpy error");
|
||||
CONN_LOGE(CONN_BLE, "memcpy error");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
int32_t status = BleOhosStatusToSoftBus(
|
||||
BleGattcConnect(clientId, &g_btGattClientCallbacks, &bdAddr, false, OHOS_BT_TRANSPORT_TYPE_LE));
|
||||
if (status != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattcConnect error");
|
||||
CONN_LOGE(CONN_BLE, "BleGattcConnect error status = %d", status);
|
||||
return SOFTBUS_GATTC_INTERFACE_FAILED;
|
||||
}
|
||||
|
||||
@ -171,7 +183,7 @@ int32_t SoftbusBleGattcDisconnect(int32_t clientId, bool refreshGatt)
|
||||
|
||||
int32_t SoftbusGattcSearchServices(int32_t clientId)
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "SoftbusGattcSearchServices %d", clientId);
|
||||
CONN_LOGI(CONN_BLE, "input param %d", clientId);
|
||||
int32_t status = BleOhosStatusToSoftBus(BleGattcSearchServices(clientId));
|
||||
if (status != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattcSearchServices error, status = %d", status);
|
||||
@ -182,14 +194,14 @@ int32_t SoftbusGattcSearchServices(int32_t clientId)
|
||||
|
||||
int32_t SoftbusGattcRefreshServices(int32_t clientId)
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "SoftbusGattcRefreshServices %d", clientId);
|
||||
CONN_LOGI(CONN_BLE, "input param %d", clientId);
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftbusGattcGetService(int32_t clientId, SoftBusBtUuid *serverUuid)
|
||||
{
|
||||
if (clientId <= 0) {
|
||||
CONN_LOGE(CONN_BLE, "SoftbusGattcGetService invalid param");
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
BtUuid btUuid;
|
||||
@ -214,7 +226,7 @@ int32_t SoftbusGattcRegisterNotification(
|
||||
btCharaUuid.characteristicUuid.uuidLen = charaUuid->uuidLen;
|
||||
int32_t status = BleOhosStatusToSoftBus(BleGattcRegisterNotification(clientId, btCharaUuid, true));
|
||||
if (status != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattcRegisterNotification error");
|
||||
CONN_LOGE(CONN_BLE, "BleGattcRegisterNotification error status = %d", status);
|
||||
return SOFTBUS_GATTC_INTERFACE_FAILED;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -222,6 +234,11 @@ int32_t SoftbusGattcRegisterNotification(
|
||||
|
||||
int32_t SoftbusGattcConfigureMtuSize(int32_t clientId, int mtuSize)
|
||||
{
|
||||
if (clientId <= 0) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (BleGattcConfigureMtuSize(clientId, mtuSize) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattcConfigureMtuSize error");
|
||||
return SOFTBUS_GATTC_INTERFACE_FAILED;
|
||||
@ -232,10 +249,10 @@ int32_t SoftbusGattcConfigureMtuSize(int32_t clientId, int mtuSize)
|
||||
int32_t SoftbusGattcWriteCharacteristic(int32_t clientId, SoftBusGattcData *clientData)
|
||||
{
|
||||
if (clientId <= 0 || clientData == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "SoftbusGattcWriteCharacteristic invalid param");
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "SoftbusGattcRegisterNotification clientId = %d", clientId);
|
||||
CONN_LOGI(CONN_BLE, "clientId = %d", clientId);
|
||||
BtGattCharacteristic characteristic;
|
||||
characteristic.serviceUuid.uuid = clientData->serviceUuid.uuid;
|
||||
characteristic.serviceUuid.uuidLen = clientData->serviceUuid.uuidLen;
|
||||
@ -243,7 +260,7 @@ int32_t SoftbusGattcWriteCharacteristic(int32_t clientId, SoftBusGattcData *clie
|
||||
characteristic.characteristicUuid.uuidLen = clientData->characterUuid.uuidLen;
|
||||
if (BleGattcWriteCharacteristic(clientId, characteristic, OHOS_GATT_WRITE_NO_RSP, clientData->valueLen,
|
||||
(const char *)clientData->value) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "SoftbusGattcWriteCharacteristic error");
|
||||
CONN_LOGE(CONN_BLE, " error");
|
||||
return SOFTBUS_GATTC_INTERFACE_FAILED;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -266,7 +283,7 @@ int32_t SoftbusGattcSetFastestConn(int32_t clientId)
|
||||
int32_t SoftbusGattcSetPriority(int32_t clientId, SoftBusBtAddr *addr, SoftbusBleGattPriority priority)
|
||||
{
|
||||
if (clientId <= 0 || addr == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param, '%d'", clientId);
|
||||
CONN_LOGE(CONN_BLE, "invalid param, '%d'or addr is null", clientId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
BdAddr bdAddr = { 0 };
|
||||
|
@ -18,14 +18,12 @@
|
||||
|
||||
#include "conn_log.h"
|
||||
#include "softbus_adapter_timer.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_type_def.h"
|
||||
|
||||
#include "c_header/ohos_bt_def.h"
|
||||
#include "c_header/ohos_bt_gatt_server.h"
|
||||
|
||||
#define WAIT_HAL_REG_TIME 5 // ms
|
||||
#define WAIT_HAL_REG_TIME_MS 5 // ms
|
||||
#define WAIT_HAL_REG_RETRY 3
|
||||
|
||||
static const char SOFTBUS_APP_UUID[BT_UUID_LEN] = {
|
||||
@ -41,13 +39,14 @@ static volatile int g_halRegFlag = -1; // -1:not registered or register failed;
|
||||
int CheckGattsStatus(void)
|
||||
{
|
||||
if (g_gattsCallback == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "g_gattsCallback is NULL");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
while (g_halRegFlag == 0) {
|
||||
CONN_LOGE(CONN_BLE, "ble hal registerring");
|
||||
static int tryTimes = WAIT_HAL_REG_RETRY;
|
||||
if (tryTimes > 0) {
|
||||
SoftBusSleepMs(WAIT_HAL_REG_TIME);
|
||||
SoftBusSleepMs(WAIT_HAL_REG_TIME_MS);
|
||||
tryTimes--;
|
||||
} else {
|
||||
g_halRegFlag = -1;
|
||||
@ -63,9 +62,11 @@ int CheckGattsStatus(void)
|
||||
int SoftBusGattsAddService(SoftBusBtUuid srvcUuid, bool isPrimary, int number)
|
||||
{
|
||||
if ((srvcUuid.uuidLen == 0) || (srvcUuid.uuid == NULL) || (number <= 0)) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "CheckGattsStatus return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
BtUuid uuid = {
|
||||
@ -73,6 +74,7 @@ int SoftBusGattsAddService(SoftBusBtUuid srvcUuid, bool isPrimary, int number)
|
||||
.uuidLen = srvcUuid.uuidLen
|
||||
};
|
||||
if (BleGattsAddService(g_halServerId, uuid, isPrimary, number) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattsAddService return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -82,9 +84,11 @@ int SoftBusGattsAddCharacteristic(int srvcHandle, SoftBusBtUuid characUuid, int
|
||||
int permissions)
|
||||
{
|
||||
if ((characUuid.uuidLen == 0) || (characUuid.uuid == NULL)) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "CheckGattsStatus return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
BtUuid uuid = {
|
||||
@ -92,6 +96,7 @@ int SoftBusGattsAddCharacteristic(int srvcHandle, SoftBusBtUuid characUuid, int
|
||||
.uuidLen = characUuid.uuidLen
|
||||
};
|
||||
if (BleGattsAddCharacteristic(g_halServerId, srvcHandle, uuid, properties, permissions) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattsAddCharacteristic return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -100,9 +105,11 @@ int SoftBusGattsAddCharacteristic(int srvcHandle, SoftBusBtUuid characUuid, int
|
||||
int SoftBusGattsAddDescriptor(int srvcHandle, SoftBusBtUuid descUuid, int permissions)
|
||||
{
|
||||
if ((descUuid.uuidLen == 0) || (descUuid.uuid == NULL)) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "CheckGattsStatus return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
BtUuid uuid = {
|
||||
@ -110,6 +117,7 @@ int SoftBusGattsAddDescriptor(int srvcHandle, SoftBusBtUuid descUuid, int permis
|
||||
.uuidLen = descUuid.uuidLen
|
||||
};
|
||||
if (BleGattsAddDescriptor(g_halServerId, srvcHandle, uuid, permissions) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattsAddDescriptor return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -118,10 +126,12 @@ int SoftBusGattsAddDescriptor(int srvcHandle, SoftBusBtUuid descUuid, int permis
|
||||
int SoftBusGattsStartService(int srvcHandle)
|
||||
{
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "CheckGattsStatus return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleGattsStartService(%d, %d)", g_halServerId, srvcHandle);
|
||||
if (BleGattsStartService(g_halServerId, srvcHandle) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattsStartService return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -130,10 +140,12 @@ int SoftBusGattsStartService(int srvcHandle)
|
||||
int SoftBusGattsStopService(int srvcHandle)
|
||||
{
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "CheckGattsStatus return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:SoftBusGattsStopService(%d, %d)", g_halServerId, srvcHandle);
|
||||
if (BleGattsStopService(g_halServerId, srvcHandle) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattsStopService return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -142,9 +154,11 @@ int SoftBusGattsStopService(int srvcHandle)
|
||||
int SoftBusGattsDeleteService(int srvcHandle)
|
||||
{
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "CheckGattsStatus return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (BleGattsDeleteService(g_halServerId, srvcHandle) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "BleGattsDeleteService return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -153,6 +167,7 @@ int SoftBusGattsDeleteService(int srvcHandle)
|
||||
int SoftBusGattsConnect(SoftBusBtAddr btAddr)
|
||||
{
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "CheckGattsStatus return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
BdAddr addr;
|
||||
@ -170,6 +185,7 @@ int SoftBusGattsConnect(SoftBusBtAddr btAddr)
|
||||
int SoftBusGattsDisconnect(SoftBusBtAddr btAddr, int connId)
|
||||
{
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "CheckGattsStatus return error");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
BdAddr addr;
|
||||
@ -186,6 +202,11 @@ int SoftBusGattsDisconnect(SoftBusBtAddr btAddr, int connId)
|
||||
|
||||
int SoftBusGattsSendResponse(SoftBusGattsResponse *param)
|
||||
{
|
||||
if (param == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
@ -204,7 +225,11 @@ int SoftBusGattsSendResponse(SoftBusGattsResponse *param)
|
||||
|
||||
int SoftBusGattsSendNotify(SoftBusGattsNotify *param)
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "SoftBusGattsSendNotify enter");
|
||||
CONN_LOGI(CONN_BLE, "enter");
|
||||
if (param == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
if (CheckGattsStatus() != SOFTBUS_OK) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
@ -215,10 +240,10 @@ int SoftBusGattsSendNotify(SoftBusGattsNotify *param)
|
||||
.valueLen = param->valueLen,
|
||||
.value = param->value
|
||||
};
|
||||
CONN_LOGI(CONN_BLE, "SoftBusGattsSendNotify call BleGattsSendIndication halconnId:%d attrHandle:%d confirm:%d",
|
||||
CONN_LOGI(CONN_BLE, "call BleGattsSendIndication halconnId:%d attrHandle:%d confirm:%d",
|
||||
notify.connectId, notify.attrHandle, notify.confirm);
|
||||
if (BleGattsSendIndication(g_halServerId, ¬ify) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "SoftBusGattsSendNotify failed");
|
||||
CONN_LOGE(CONN_BLE, "BleGattsSendIndication return failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
@ -226,14 +251,14 @@ int SoftBusGattsSendNotify(SoftBusGattsNotify *param)
|
||||
|
||||
static void BleRegisterServerCallback(int status, int serverId, BtUuid *appUuid)
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "BleRegisterServerCallback status=%d severId=%d", status, serverId);
|
||||
CONN_LOGI(CONN_BLE, "status=%d severId=%d", status, serverId);
|
||||
if ((appUuid == NULL) || (appUuid->uuid == NULL)) {
|
||||
CONN_LOGE(CONN_BLE, "BleRegisterServerCallback appUuid is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (memcmp(appUuid->uuid, SOFTBUS_APP_UUID, appUuid->uuidLen) != 0) {
|
||||
CONN_LOGE(CONN_BLE, "BleRegisterServerCallback unknown uuid");
|
||||
CONN_LOGE(CONN_BLE, "unknown uuid");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -249,6 +274,10 @@ static void BleRegisterServerCallback(int status, int serverId, BtUuid *appUuid)
|
||||
|
||||
static void BleConnectServerCallback(int connId, int serverId, const BdAddr *bdAddr)
|
||||
{
|
||||
if (bdAddr == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "ConnectServerCallback is coming, connId=%d serverId=%d\n", connId, serverId);
|
||||
if (serverId != g_halServerId) {
|
||||
return;
|
||||
@ -258,6 +287,10 @@ static void BleConnectServerCallback(int connId, int serverId, const BdAddr *bdA
|
||||
|
||||
static void BleDisconnectServerCallback(int connId, int serverId, const BdAddr *bdAddr)
|
||||
{
|
||||
if (bdAddr == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "DisconnectServerCallback is coming, connId=%d severId=%d", connId, serverId);
|
||||
if (serverId != g_halServerId) {
|
||||
return;
|
||||
@ -267,12 +300,16 @@ static void BleDisconnectServerCallback(int connId, int serverId, const BdAddr *
|
||||
|
||||
static void BleServiceAddCallback(int status, int serverId, BtUuid *uuid, int srvcHandle)
|
||||
{
|
||||
if (uuid == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return;
|
||||
}
|
||||
(void)serverId;
|
||||
CONN_LOGI(CONN_BLE, "ServiceAddCallback srvcHandle=%d\n", srvcHandle);
|
||||
if (serverId != g_halServerId) {
|
||||
return;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleServiceAddCallback srvcHandle:%d)", srvcHandle);
|
||||
CONN_LOGI(CONN_BLE, "srvcHandle:%d", srvcHandle);
|
||||
g_gattsCallback->ServiceAddCallback(status, (SoftBusBtUuid *)uuid, srvcHandle);
|
||||
}
|
||||
|
||||
@ -293,28 +330,34 @@ static void BleCharacteristicAddCallback(int status, int serverId, BtUuid *uuid,
|
||||
CONN_LOGE(CONN_BLE, "bad server id");
|
||||
return;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleCharacteristicAddCallback characteristicHandle:%d)", characteristicHandle);
|
||||
CONN_LOGI(CONN_BLE, "characteristicHandle:%d", characteristicHandle);
|
||||
g_gattsCallback->CharacteristicAddCallback(status, (SoftBusBtUuid *)uuid, srvcHandle, characteristicHandle);
|
||||
}
|
||||
|
||||
static void BleDescriptorAddCallback(int status, int serverId, BtUuid *uuid,
|
||||
int srvcHandle, int descriptorHandle)
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "DescriptorAddCallback srvcHandle=%d,descriptorHandle=%d", srvcHandle, descriptorHandle);
|
||||
if (serverId != g_halServerId) {
|
||||
if (uuid == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleDescriptorAddCallback descriptorHandle:%d)", descriptorHandle);
|
||||
|
||||
CONN_LOGI(CONN_BLE, "DescriptorAddCallback srvcHandle=%d,descriptorHandle=%d", srvcHandle, descriptorHandle);
|
||||
if (serverId != g_halServerId) {
|
||||
CONN_LOGE(CONN_BLE, "serverId error");
|
||||
return;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "descriptorHandle:%d", descriptorHandle);
|
||||
g_gattsCallback->DescriptorAddCallback(status, (SoftBusBtUuid *)uuid, srvcHandle, descriptorHandle);
|
||||
}
|
||||
|
||||
static void BleServiceStartCallback(int status, int serverId, int srvcHandle)
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "ServiceStartCallback serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
|
||||
CONN_LOGI(CONN_BLE, "serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
|
||||
if (serverId != g_halServerId) {
|
||||
return;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "BLEINFOPRTINT:BleServiceStartCallback srvcHandle:%d)", srvcHandle);
|
||||
CONN_LOGI(CONN_BLE, "srvcHandle:%d", srvcHandle);
|
||||
g_gattsCallback->ServiceStartCallback(status, srvcHandle);
|
||||
}
|
||||
|
||||
@ -329,7 +372,7 @@ static void BleServiceStopCallback(int status, int serverId, int srvcHandle)
|
||||
|
||||
static void BleServiceDeleteCallback(int status, int serverId, int srvcHandle)
|
||||
{
|
||||
CONN_LOGI(CONN_BLE, "ServiceDeleteCallback serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
|
||||
CONN_LOGI(CONN_BLE, "serverId=%d,srvcHandle=%d\n", serverId, srvcHandle);
|
||||
if (serverId != g_halServerId) {
|
||||
return;
|
||||
}
|
||||
@ -409,17 +452,17 @@ static int GattsRegisterHalCallback(void)
|
||||
int SoftBusRegisterGattsCallbacks(SoftBusGattsCallback *callback)
|
||||
{
|
||||
if (callback == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "SoftBusRegisterGattsCallbacks fail:nullptr");
|
||||
CONN_LOGE(CONN_BLE, "fail:nullptr");
|
||||
return SOFTBUS_BLECONNECTION_REG_GATTS_CALLBACK_FAIL;
|
||||
}
|
||||
if (g_gattsCallback != NULL) {
|
||||
CONN_LOGW(CONN_BLE, "SoftBusRegisterGattsCallbacks register again");
|
||||
CONN_LOGW(CONN_BLE, "register again");
|
||||
} else {
|
||||
g_gattsCallback = callback;
|
||||
}
|
||||
int ret = GattsRegisterHalCallback();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "SoftBusRegisterGattsCallbacks GattsRegisterCallbacks failed:%d", ret);
|
||||
CONN_LOGE(CONN_BLE, "GattsRegisterCallbacks failed:%d", ret);
|
||||
return SOFTBUS_BLECONNECTION_REG_GATTS_CALLBACK_FAIL;
|
||||
}
|
||||
if (g_halRegFlag == -1) {
|
||||
|
@ -14,51 +14,31 @@
|
||||
*/
|
||||
|
||||
#include "adapter_bt_utils.h"
|
||||
#include "softbus_def.h"
|
||||
|
||||
OhosStatusToSoftBus BleStatus[] = {
|
||||
{OHOS_BT_STATUS_SUCCESS, SOFTBUS_BT_STATUS_SUCCESS},
|
||||
{OHOS_BT_STATUS_FAIL, SOFTBUS_BT_STATUS_FAIL},
|
||||
{OHOS_BT_STATUS_NOT_READY, SOFTBUS_BT_STATUS_NOT_READY},
|
||||
{OHOS_BT_STATUS_NOMEM, SOFTBUS_BT_STATUS_NOMEM},
|
||||
{OHOS_BT_STATUS_BUSY, SOFTBUS_BT_STATUS_BUSY},
|
||||
{OHOS_BT_STATUS_DONE, SOFTBUS_BT_STATUS_DONE},
|
||||
{OHOS_BT_STATUS_UNSUPPORTED, SOFTBUS_BT_STATUS_UNSUPPORTED},
|
||||
{OHOS_BT_STATUS_PARM_INVALID, SOFTBUS_BT_STATUS_PARM_INVALID},
|
||||
{OHOS_BT_STATUS_UNHANDLED, SOFTBUS_BT_STATUS_UNHANDLED},
|
||||
{OHOS_BT_STATUS_AUTH_FAILURE, SOFTBUS_BT_STATUS_AUTH_FAILURE},
|
||||
{OHOS_BT_STATUS_RMT_DEV_DOWN, SOFTBUS_BT_STATUS_RMT_DEV_DOWN},
|
||||
{OHOS_BT_STATUS_AUTH_REJECTED, SOFTBUS_BT_STATUS_AUTH_REJECTED},
|
||||
};
|
||||
|
||||
int32_t BleOhosStatusToSoftBus(BtStatus btStatus)
|
||||
{
|
||||
int32_t status;
|
||||
switch (btStatus) {
|
||||
case OHOS_BT_STATUS_SUCCESS:
|
||||
status = SOFTBUS_BT_STATUS_SUCCESS;
|
||||
break;
|
||||
case OHOS_BT_STATUS_FAIL:
|
||||
status = SOFTBUS_BT_STATUS_FAIL;
|
||||
break;
|
||||
case OHOS_BT_STATUS_NOT_READY:
|
||||
status = SOFTBUS_BT_STATUS_NOT_READY;
|
||||
break;
|
||||
case OHOS_BT_STATUS_NOMEM:
|
||||
status = SOFTBUS_BT_STATUS_NOMEM;
|
||||
break;
|
||||
case OHOS_BT_STATUS_BUSY:
|
||||
status = SOFTBUS_BT_STATUS_BUSY;
|
||||
break;
|
||||
case OHOS_BT_STATUS_DONE:
|
||||
status = SOFTBUS_BT_STATUS_DONE;
|
||||
break;
|
||||
case OHOS_BT_STATUS_UNSUPPORTED:
|
||||
status = SOFTBUS_BT_STATUS_UNSUPPORTED;
|
||||
break;
|
||||
case OHOS_BT_STATUS_PARM_INVALID:
|
||||
status = SOFTBUS_BT_STATUS_PARM_INVALID;
|
||||
break;
|
||||
case OHOS_BT_STATUS_UNHANDLED:
|
||||
status = SOFTBUS_BT_STATUS_UNHANDLED;
|
||||
break;
|
||||
case OHOS_BT_STATUS_AUTH_FAILURE:
|
||||
status = SOFTBUS_BT_STATUS_AUTH_FAILURE;
|
||||
break;
|
||||
case OHOS_BT_STATUS_RMT_DEV_DOWN:
|
||||
status = SOFTBUS_BT_STATUS_RMT_DEV_DOWN;
|
||||
break;
|
||||
case OHOS_BT_STATUS_AUTH_REJECTED:
|
||||
status = SOFTBUS_BT_STATUS_AUTH_REJECTED;
|
||||
break;
|
||||
default:
|
||||
status = SOFTBUS_BT_STATUS_FAIL;
|
||||
break;
|
||||
int32_t status = OHOS_BT_STATUS_FAIL;
|
||||
const int len = sizeof(BleStatus) / sizeof(BleStatus[0]);
|
||||
OhosStatusToSoftBus *ptr = BleStatus;
|
||||
|
||||
if (btStatus >= len) {
|
||||
return status;
|
||||
}
|
||||
return status;
|
||||
|
||||
return (ptr + btStatus)->softBusBtStatus;
|
||||
}
|
@ -19,10 +19,8 @@
|
||||
|
||||
#include "c_header/ohos_bt_def.h"
|
||||
#include "c_header/ohos_bt_gap.h"
|
||||
#include "c_header/ohos_bt_gatt.h"
|
||||
#include "comm_log.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_common.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
@ -46,7 +44,7 @@ static int ConvertBtState(int transport, int state)
|
||||
case OHOS_GAP_STATE_TURN_OFF:
|
||||
return (transport == BR_STATE_CB_TRANSPORT) ? SOFTBUS_BR_STATE_TURN_OFF : SOFTBUS_BT_STATE_TURN_OFF;
|
||||
default:
|
||||
return -1;
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +62,7 @@ static int ConvertAclState(GapAclState state)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
static SoftBusBtAddr ConvertBtAddr(const BdAddr *bdAddr)
|
||||
@ -240,6 +238,10 @@ int SoftBusGetBtName(unsigned char *name, unsigned int *len)
|
||||
|
||||
int SoftBusSetBtName(const char *name)
|
||||
{
|
||||
if (name == NULL) {
|
||||
COMM_LOGE(COMM_ADAPTER, "invalid parameter");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (SetLocalName((unsigned char *)name, strlen(name))) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
@ -32,9 +32,14 @@ extern "C" {
|
||||
|
||||
int32_t BleOhosStatusToSoftBus(BtStatus status);
|
||||
|
||||
typedef struct {
|
||||
BtStatus btStatus;
|
||||
SoftBusBtStatus softBusBtStatus;
|
||||
} OhosStatusToSoftBus;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
#endif /* ADAPTER_BT_UTILS_H */
|
@ -19,8 +19,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "softbus_error_code.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -40,10 +40,10 @@ extern "C" {
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00,
|
||||
SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04,
|
||||
SOFTBUS_BLE_EVT_CONNECTABLE = 0x01,
|
||||
SOFTBUS_BLE_EVT_CONNECTABLE_DIRECTED = 0x05,
|
||||
SOFTBUS_BLE_EVT_SCANNABLE = 0x02,
|
||||
SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04,
|
||||
SOFTBUS_BLE_EVT_CONNECTABLE_DIRECTED = 0x05,
|
||||
SOFTBUS_BLE_EVT_SCANNABLE_DIRECTED = 0x06,
|
||||
SOFTBUS_BLE_EVT_LEGACY_NON_CONNECTABLE = 0x10,
|
||||
SOFTBUS_BLE_EVT_LEGACY_SCANNABLE = 0x12,
|
||||
@ -226,4 +226,4 @@ int32_t SoftBusSetLpDeviceParam(int duration, int maxExtAdvEvents, int window,
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
#endif /* SOFTBUS_ADAPTER_BLE_GATT_H */
|
||||
|
@ -145,4 +145,4 @@ int SoftBusGattsSendNotify(SoftBusGattsNotify *param);
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
#endif /* SOFTBUS_ADAPTER_BLE_GATT_SERVER_H */
|
||||
|
@ -119,4 +119,4 @@ void SoftBusBtInit(void);
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
#endif /* SOFTBUS_ADAPTER_BT_COMMON_H */
|
@ -118,7 +118,7 @@ int32_t SoftBusRequestWlanChannelInfo(int32_t *channelId, uint32_t num)
|
||||
LNN_LOGI(LNN_STATE, "measuring channel");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
|
||||
g_channelList.buff = (int32_t *)SoftBusCalloc(sizeof(int32_t) * num);
|
||||
if (g_channelList.buff == NULL) {
|
||||
LNN_LOGE(LNN_STATE, " SoftBusCalloc channelId fail");
|
||||
|
@ -13,8 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_wlan_extend.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
|
@ -15,13 +15,11 @@
|
||||
|
||||
#include "softbus_wifi_api_adapter.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lnn_log.h"
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "wifi_device.h"
|
||||
#include "wifi_hid2d.h"
|
||||
@ -132,12 +130,11 @@ int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num
|
||||
|
||||
int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig)
|
||||
{
|
||||
WifiDeviceConfig wifiDevConfig;
|
||||
|
||||
if (wifiConfig == NULL) {
|
||||
LNN_LOGE(LNN_STATE, "para wifiConfig is NULL");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
WifiDeviceConfig wifiDevConfig;
|
||||
(void)memset_s(&wifiDevConfig, sizeof(WifiDeviceConfig), 0, sizeof(WifiDeviceConfig));
|
||||
if (ConvertWifiDevConfFromSoftBusWifiConf(wifiConfig, &wifiDevConfig) != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_STATE, "convert wifi config failed");
|
||||
@ -162,10 +159,7 @@ static bool g_registerFlag = true;
|
||||
|
||||
int32_t SoftBusStartWifiScan(void)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
ret = Scan();
|
||||
if (ret != WIFI_SUCCESS) {
|
||||
if (Scan() != WIFI_SUCCESS) {
|
||||
LNN_LOGE(LNN_STATE, "softbus start wifi scan failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
@ -202,7 +196,10 @@ static int32_t FindFreeCallbackIndex(void)
|
||||
|
||||
int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
int32_t ret;
|
||||
if (cb == NULL) {
|
||||
LNN_LOGE(LNN_STATE, "invalid para");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
int index = FindFreeCallbackIndex();
|
||||
if (index == MAX_CALLBACK_NUM) {
|
||||
@ -211,6 +208,7 @@ int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
}
|
||||
g_scanResultCb[index] = cb;
|
||||
|
||||
int32_t ret = 0;
|
||||
if (g_registerFlag) {
|
||||
ret = RegisterWifiEvent(&g_event);
|
||||
if (ret == WIFI_SUCCESS) {
|
||||
@ -223,7 +221,7 @@ int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ConvertSoftBusWifiScanInfoFromWifi(WifiScanInfo *info, SoftBusWifiScanInfo *result, uint32_t *size)
|
||||
static int32_t ConvertSoftBusWifiScanInfoFromWifi(WifiScanInfo *info, SoftBusWifiScanInfo *result, const uint32_t *size)
|
||||
{
|
||||
if (info == NULL || result == NULL || size == NULL) {
|
||||
LNN_LOGE(LNN_STATE, "invalid para");
|
||||
@ -302,7 +300,10 @@ static bool IsScanResultCbEmpty(void)
|
||||
|
||||
int32_t SoftBusUnRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
int32_t ret;
|
||||
if (cb == NULL) {
|
||||
LNN_LOGE(LNN_STATE, "invalid para");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] == cb) {
|
||||
@ -310,6 +311,7 @@ int32_t SoftBusUnRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if (IsScanResultCbEmpty()) {
|
||||
ret = UnRegisterWifiEvent(&g_event);
|
||||
if (ret == WIFI_SUCCESS) {
|
||||
@ -349,13 +351,17 @@ SoftBusBand SoftBusGetLinkBand(void)
|
||||
} else if (result.band == BAND_5G) {
|
||||
return BAND_5G;
|
||||
} else {
|
||||
LNN_LOGE(LNN_STATE, "get SoftBusGetLinkBand success");
|
||||
LNN_LOGE(LNN_STATE, "band unknown");
|
||||
return BAND_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SoftBusGetLinkedInfo(SoftBusWifiLinkedInfo *info)
|
||||
{
|
||||
if (info == NULL) {
|
||||
LNN_LOGE(LNN_STATE, "invalid para");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
WifiLinkedInfo result;
|
||||
if (GetLinkedInfo(&result) != WIFI_SUCCESS) {
|
||||
LNN_LOGE(LNN_STATE, "get SoftBusGetLinkedInfo failed");
|
||||
@ -372,6 +378,10 @@ int32_t SoftBusGetLinkedInfo(SoftBusWifiLinkedInfo *info)
|
||||
|
||||
int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo)
|
||||
{
|
||||
if (groupInfo == NULL) {
|
||||
LNN_LOGE(LNN_STATE, "invalid para");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
WifiP2pGroupInfo result;
|
||||
if (GetCurrentGroup(&result) != WIFI_SUCCESS) {
|
||||
LNN_LOGE(LNN_STATE, "get SoftBusGetCurrentGroup failed");
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_wifi_api_adapter.h"
|
||||
|
||||
|
@ -61,6 +61,10 @@ static EVP_CIPHER *GetCtrAlgorithmByKeyLen(uint32_t keyLen)
|
||||
|
||||
static int32_t OpensslEvpInit(EVP_CIPHER_CTX **ctx, const AesGcmCipherKey *cipherkey, bool mode)
|
||||
{
|
||||
if (cipherkey == NULL) {
|
||||
COMM_LOGE(COMM_ADAPTER, "Encrypt invalid para.");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
EVP_CIPHER *cipher = GetGcmAlgorithmByKeyLen(cipherkey->keyLen);
|
||||
if (cipher == NULL) {
|
||||
COMM_LOGE(COMM_ADAPTER, "get cipher fail.");
|
||||
@ -463,6 +467,7 @@ uint32_t SoftBusCryptoRand(void)
|
||||
int32_t len = SoftBusReadFile(fd, &value, sizeof(uint32_t));
|
||||
if (len < 0) {
|
||||
COMM_LOGE(COMM_ADAPTER, "CryptoRand read file fail");
|
||||
SoftBusCloseFile(fd);
|
||||
return 0;
|
||||
}
|
||||
SoftBusCloseFile(fd);
|
||||
|
@ -15,8 +15,6 @@
|
||||
|
||||
#include "softbus_adapter_perf.h"
|
||||
|
||||
#include "softbus_adapter_log.h"
|
||||
|
||||
|
||||
bool SoftBusIsRamTest(void)
|
||||
{
|
||||
|
@ -13,10 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_adapter_range.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "comm_log.h"
|
||||
#include "softbus_adapter_range.h"
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
#define MOCK_POWER (-17)
|
||||
#define DB_BASE (10.0)
|
||||
@ -26,19 +26,19 @@ int SoftBusBleRange(SoftBusRangeParam *param, int32_t *range)
|
||||
{
|
||||
if (param == NULL || range == NULL) {
|
||||
COMM_LOGE(COMM_ADAPTER, "SoftBusBleRange param is null.");
|
||||
return -1;
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
*range = (int32_t)pow(DB_BASE, param->rssi * -1 / DB_COEFFICIENT);
|
||||
return 0;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int SoftBusGetBlePower(int8_t *power)
|
||||
{
|
||||
if (power == NULL) {
|
||||
COMM_LOGE(COMM_ADAPTER, "SoftBusGetBlePower param is null.");
|
||||
return -1;
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
*power = MOCK_POWER;
|
||||
return 0;
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -18,6 +18,9 @@
|
||||
|
||||
void SoftbusConfigAdapterInit(const ConfigSetProc *sets)
|
||||
{
|
||||
if (sets == NULL) {
|
||||
return;
|
||||
}
|
||||
int32_t val = 0x1;
|
||||
sets->SetConfig(SOFTBUS_INT_AUTH_ABILITY_COLLECTION, (unsigned char *)&val, sizeof(val));
|
||||
}
|
@ -31,4 +31,4 @@ void SoftbusConfigAdapterInit(const ConfigSetProc *sets);
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
#endif /* SOFTBUS_CONFIG_ADAPT_H */
|
||||
|
@ -70,4 +70,4 @@ typedef struct {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
#endif /* SOFTBUS_CONFIG_TYPE_H */
|
@ -39,4 +39,4 @@ void SpungeDelEpInstFromFtSocket(struct FtSocket *sock, FILLP_INT epFd);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif // SPUNGE_APP_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user