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

Signed-off-by: xingchu <weiqian22@huawei.com>
This commit is contained in:
xingchu 2023-11-28 06:42:11 +00:00 committed by weiqian
commit 2a9c47140d
52 changed files with 879 additions and 682 deletions

View File

@ -36,6 +36,7 @@ if (defined(ohos_lite)) {
}
common_include = [
"$dsoftbus_root_path/core/common/dfx/interface/include",
"$dsoftbus_root_path/interfaces/kits",
"$dsoftbus_root_path/interfaces/kits/common",
"//base/startup/init/interfaces/innerkits/include/syspara",
@ -95,7 +96,10 @@ if (defined(ohos_lite)) {
]
}
deps = [ "$hilog_lite_deps_path" ]
deps = [
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"$hilog_lite_deps_path",
]
if (dsoftbus_feature_encrypt == 0) {
sources += [
@ -139,6 +143,7 @@ if (defined(ohos_lite)) {
"$softbus_adapter_config/spec_config/softbus_config_adapter.c",
]
deps = [
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"$hilog_lite_deps_path",
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//third_party/bounds_checking_function:libsec_shared",
@ -166,6 +171,7 @@ if (defined(ohos_lite)) {
"$softbus_adapter_common/include",
"$softbus_adapter_common/include/OS_adapter_define/linux",
"$dsoftbus_feature_product_config_path/spec_config",
"$dsoftbus_root_path/core/common/dfx/interface/include",
"$dsoftbus_root_path/core/common/include",
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include",
]
@ -180,6 +186,7 @@ if (defined(ohos_lite)) {
branch_protector_ret = "pac_ret"
include_dirs = [
"$dsoftbus_root_path/core/common/dfx/interface/include",
"$dsoftbus_root_path/interfaces/kits",
"$dsoftbus_root_path/interfaces/kits/common",
"//commonlibrary/c_utils/base/include",
@ -200,7 +207,10 @@ if (defined(ohos_lite)) {
"$softbus_adapter_common/log/softbus_adapter_log.c",
"$softbus_adapter_common/perf/softbus_adapter_perf.c",
]
public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
public_deps = [
"$dsoftbus_dfx_path/log:softbus_dfx_log",
"//third_party/bounds_checking_function:libsec_shared",
]
native_source_path = rebase_path("$dsoftbus_root_path")
ble_enhanced_impl =

View File

@ -92,8 +92,10 @@ if (defined(ohos_lite)) {
if (has_ces_part) {
bus_center_adapter_src +=
[ "$adapter_bus_center_path/common_event/lnn_common_event_monitor.cpp" ]
bus_center_adapter_external_deps +=
[ "common_event_service:cesfwk_innerkits" ]
bus_center_adapter_external_deps += [
"ability_base:want",
"common_event_service:cesfwk_innerkits",
]
} else {
bus_center_adapter_src += [ "$adapter_bus_center_path/common_event/lnn_common_event_monitor_virtual.cpp" ]
}
@ -109,7 +111,10 @@ if (defined(ohos_lite)) {
if (dsoftbus_feature_lnn_wifiservice_dependence && has_ces_part) {
bus_center_adapter_src +=
[ "$adapter_bus_center_path/wlan/lnn_wifiservice_monitor.cpp" ]
bus_center_adapter_external_deps += [ "wifi:wifi_sdk" ]
bus_center_adapter_external_deps += [
"ability_base:want",
"wifi:wifi_sdk",
]
} else {
bus_center_adapter_src += [
"$adapter_bus_center_path/wlan/lnn_wifiservice_monitor_virtual.cpp",

View File

@ -30,7 +30,7 @@ static int OnDevEventReceived(void* priv, unsigned int id, struct HdfSBuf* data)
{
(void)data;
if (id == IP_READY) {
LNN_LOGI(LNN_STATE, "envent %{public}s: dev event received: %{public}u", (char*)priv, id);
LNN_LOGI(LNN_STATE, "envent %s: dev event received: %u", (char*)priv, id);
LnnNotifyAddressChangedEvent(NULL);
}
return HDF_SUCCESS;
@ -45,7 +45,7 @@ int32_t LnnInitProductMonitorImpl(void)
{
g_serv = HdfIoServiceBind(HISYSLINK_SERVICE_NAME);
if (g_serv == NULL) {
LNN_LOGI(LNN_STATE, "fail to get service %{public}s", HISYSLINK_SERVICE_NAME);
LNN_LOGI(LNN_STATE, "fail to get service %s", HISYSLINK_SERVICE_NAME);
return SOFTBUS_OK;
}

View File

@ -17,9 +17,8 @@
#include <string>
#include <sstream>
#include <securec.h>
#include "comm_log.h"
#include "softbus_error_code.h"
#include "softbus_adapter_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_thread.h"
#include "message_handler.h"
@ -74,12 +73,12 @@ static int32_t ConvertEventParam(SoftBusEvtParam *srcParam, HiSysEventParam *dst
dstParam->t = HISYSEVENT_STRING;
dstParam->v.s = (char *)SoftBusCalloc(sizeof(char) * SOFTBUS_HISYSEVT_PARAM_LEN);
if (dstParam->v.s == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ConvertEventParam: SoftBusMalloc fail");
COMM_LOGE(COMM_ADAPTER, "ConvertEventParam: SoftBusMalloc fail");
return SOFTBUS_ERR;
}
if (strcpy_s(dstParam->v.s, SOFTBUS_HISYSEVT_PARAM_LEN, srcParam->paramValue.str) != EOK) {
SoftBusFree(dstParam->v.s);
HILOG_ERROR(SOFTBUS_HILOG_ID, "ConvertEventParam:copy string var fail");
COMM_LOGE(COMM_ADAPTER, "ConvertEventParam:copy string var fail");
return SOFTBUS_ERR;
}
break;
@ -87,12 +86,12 @@ static int32_t ConvertEventParam(SoftBusEvtParam *srcParam, HiSysEventParam *dst
dstParam->t = HISYSEVENT_UINT32_ARRAY;
dstParam->v.array = (uint32_t *)SoftBusCalloc(arraySize);
if (dstParam->v.array == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ConvertEventParam: SoftBusMalloc fail");
COMM_LOGE(COMM_ADAPTER, "ConvertEventParam: SoftBusMalloc fail");
return SOFTBUS_ERR;
}
if (memcpy_s(dstParam->v.array, arraySize, srcParam->paramValue.u32a, arraySize) != EOK) {
SoftBusFree(dstParam->v.array);
HILOG_ERROR(SOFTBUS_HILOG_ID, "ConvertEventParam:copy uint32 array var fail");
COMM_LOGE(COMM_ADAPTER, "ConvertEventParam:copy uint32 array var fail");
return SOFTBUS_ERR;
}
break;
@ -106,16 +105,16 @@ static int32_t ConvertMsgToHiSysEvent(SoftBusEvtReportMsg *msg)
{
if (memset_s(g_dstParam, sizeof(HiSysEventParam) * SOFTBUS_EVT_PARAM_BUTT, 0,
sizeof(HiSysEventParam) * SOFTBUS_EVT_PARAM_BUTT) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "init g_dstParam fail");
COMM_LOGE(COMM_ADAPTER, "init g_dstParam fail");
return SOFTBUS_ERR;
}
for (uint32_t i = 0; i < msg->paramNum; i++) {
if (strcpy_s(g_dstParam[i].name, SOFTBUS_HISYSEVT_NAME_LEN, msg->paramArray[i].paramName) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy param fail");
COMM_LOGE(COMM_ADAPTER, "copy param fail");
return SOFTBUS_ERR;
}
if (ConvertEventParam(&msg->paramArray[i], &g_dstParam[i]) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ConvertMsgToHiSysEvent:convert param fail");
COMM_LOGE(COMM_ADAPTER, "ConvertMsgToHiSysEvent:convert param fail");
return SOFTBUS_ERR;
}
}
@ -158,7 +157,7 @@ static HiSysEventEventType ConvertMsgType(SoftBusEvtType type)
static void InitHisEvtMutexLock()
{
if (SoftBusMutexInit(&g_dfx_lock, NULL) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "init HisEvtMutexLock fail");
COMM_LOGE(COMM_ADAPTER, "init HisEvtMutexLock fail");
return;
}
}
@ -179,7 +178,7 @@ int32_t SoftbusWriteHisEvt(SoftBusEvtReportMsg* reportMsg)
g_init_lock = true;
}
if (SoftBusMutexLock(&g_dfx_lock) != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%s:lock failed", __func__);
COMM_LOGE(COMM_ADAPTER, "lock failed");
return SOFTBUS_LOCK_ERR;
}
ConvertMsgToHiSysEvent(reportMsg);
@ -205,12 +204,12 @@ void SoftbusFreeEvtReporMsg(SoftBusEvtReportMsg* msg)
SoftBusEvtReportMsg* SoftbusCreateEvtReportMsg(int32_t paramNum)
{
if (paramNum <= SOFTBUS_EVT_PARAM_ZERO || paramNum >= SOFTBUS_EVT_PARAM_BUTT) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "param is invalid");
COMM_LOGE(COMM_ADAPTER, "param is invalid");
return nullptr;
}
SoftBusEvtReportMsg *msg = (SoftBusEvtReportMsg*)SoftBusMalloc(sizeof(SoftBusEvtReportMsg));
if (msg == nullptr) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "report msg is null");
COMM_LOGE(COMM_ADAPTER, "report msg is null");
return nullptr;
}
msg->paramArray = (SoftBusEvtParam*)SoftBusMalloc(sizeof(SoftBusEvtParam) * paramNum);

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "softbus_adapter_log.h"
#include "comm_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_hisysevent.h"
@ -39,13 +39,13 @@ void SoftbusFreeEvtReporMsg(SoftBusEvtReportMsg* msg)
SoftBusEvtReportMsg* SoftbusCreateEvtReportMsg(int32_t paramNum)
{
if (paramNum <= SOFTBUS_EVT_PARAM_ZERO || paramNum >= SOFTBUS_EVT_PARAM_BUTT) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "param is invalid");
COMM_LOGE(COMM_ADAPTER, "param is invalid");
return NULL;
}
SoftBusEvtReportMsg *msg = (SoftBusEvtReportMsg*)SoftBusMalloc(sizeof(SoftBusEvtReportMsg));
if (msg == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "report msg is null");
COMM_LOGE(COMM_ADAPTER, "report msg is null");
return NULL;
}

View File

@ -38,11 +38,11 @@ SoftBusLogSysType SoftBusGetLogSysType(void)
char value[PROP_USER_TYPE_VALUE_LEN] = {0};
int32_t ret = GetParameter(PROP_USER_TYPE, "", value, sizeof(value));
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "GetProp: [%{public}s] fail(ret=%{public}d)", PROP_USER_TYPE, ret);
COMM_LOGE(COMM_ADAPTER, "GetProp: [%s] fail(ret=%d)", PROP_USER_TYPE, ret);
return SOFTBUS_LOG_SYS_UNKNOWN;
}
isUserTypeObtained = true;
HILOG_INFO(SOFTBUS_HILOG_ID, "GetProp: [%{public}s]: [%{public}s]", PROP_USER_TYPE, value);
COMM_LOGI(COMM_ADAPTER, "GetProp: [%s]: [%s]", PROP_USER_TYPE, value);
// is beta or not: 1 china release, 3 china beta, 5 oversea beta, 6 oversea release
if (atoi(value) == PROP_USER_TYPE_CHANA_BETA) {
@ -56,17 +56,17 @@ SoftBusLogSysType SoftBusGetLogSysType(void)
void SoftBusGenHiviewHash(const char *deviceId, char *buf, uint32_t size)
{
if (deviceId == nullptr || buf == NULL || size < HiView::DEFAULT_TRUNCATED_LENGTH) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HiView::genTruncatedHash invalid param");
COMM_LOGE(COMM_ADAPTER, "HiView::genTruncatedHash invalid param");
return;
}
std::string input(deviceId);
std::string hash = HiView::GenTruncatedHash(input, HiView::ALGORITHM_SHA_256, HiView::DEFAULT_TRUNCATED_LENGTH);
if (hash.empty()) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HiView::genTruncatedHash return empty hash");
COMM_LOGE(COMM_ADAPTER, "HiView::genTruncatedHash return empty hash");
return;
}
if (strcpy_s(buf, size, hash.c_str()) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HiView::genTruncatedHash strcpy_s fail");
COMM_LOGE(COMM_ADAPTER, "HiView::genTruncatedHash strcpy_s fail");
return;
}
}

View File

@ -17,7 +17,7 @@
#include <cstdint>
#include "softbus_adapter_log.h"
#include "comm_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "xcollie/watchdog.h"
@ -26,7 +26,7 @@
int32_t SoftBusSetWatchdogTimer(const char *name, uint32_t timeout, void(*func)(void*), void *args)
{
if (name == NULL || func == NULL || args == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBus Set Watchdog Timer param is invalid.");
COMM_LOGE(COMM_ADAPTER, "SoftBus Set Watchdog Timer param is invalid.");
return SOFTBUS_INVALID_PARAM;
}
return OHOS::HiviewDFX::XCollie::GetInstance().SetTimer(name, timeout, func,
@ -41,7 +41,7 @@ void SoftBusCancelWatchdogTimer(int32_t id)
void SoftBusRunOneShotTask(const char *name, void(*task)(void), uint64_t delay)
{
if (name == NULL || task == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBus Run Shot Watchdog Task param is invalid.");
COMM_LOGE(COMM_ADAPTER, "SoftBus Run Shot Watchdog Task param is invalid.");
return;
}
OHOS::HiviewDFX::Watchdog::GetInstance().RunOneShotTask(name, task, delay);
@ -50,7 +50,7 @@ void SoftBusRunOneShotTask(const char *name, void(*task)(void), uint64_t delay)
void SoftBusRunPeriodicalTask(const char *name, void(*task)(void), uint64_t interval, uint64_t delay)
{
if (name == NULL || task == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBus Run Periodical Watchdog Task param is invalid");
COMM_LOGE(COMM_ADAPTER, "SoftBus Run Periodical Watchdog Task param is invalid");
return;
}
OHOS::HiviewDFX::Watchdog::GetInstance().RunPeriodicalTask(name, task, interval, delay);

View File

@ -15,12 +15,12 @@
#include "softbus_adapter_json.h"
#include "comm_log.h"
#include "nlohmann/json.hpp"
#include "securec.h"
#include "softbus_adapter_log.h"
#include "softbus_adapter_mem.h"
#define JSON_LOGE(fmt, ...) HILOG_ERROR(SOFTBUS_HILOG_ID, "[%{public}s] " fmt, __FUNCTION__, ##__VA_ARGS__)
#define JSON_LOGE(fmt, ...) COMM_LOGE(COMM_ADAPTER, "[%s] " fmt, __FUNCTION__, ##__VA_ARGS__)
JsonObj *JSON_CreateObject(void)
{
@ -142,7 +142,7 @@ bool JSON_GetBoolFromOject(const JsonObj *obj, const char *key, bool *value)
}
nlohmann::json item = (*json)[key];
if (!item.is_boolean()) {
JSON_LOGE("Cannot find or invalid [%{public}s]", key);
JSON_LOGE("Cannot find or invalid [%s]", key);
return false;
}
*value = item.get<bool>();
@ -179,7 +179,7 @@ static bool JSON_GetIntegerFromObject(const JsonObj *obj, const char *key, Integ
}
nlohmann::json item = (*json)[key];
if (!item.is_number()) {
JSON_LOGE("Cannot find or invalid [%{public}s]", key);
JSON_LOGE("Cannot find or invalid [%s]", key);
return false;
}
value = item.get<Integer>();
@ -256,12 +256,12 @@ bool JSON_GetStringFromOject(const JsonObj *obj, const char *key, char *value, u
}
nlohmann::json item = (*json)[key];
if (!item.is_string()) {
JSON_LOGE("cannot find or invalid [%{public}s]", key);
JSON_LOGE("cannot find or invalid [%s]", key);
return false;
}
std::string valueString = item.get<std::string>();
if (strcpy_s(value, size, valueString.c_str()) != EOK) {
JSON_LOGE("strcpy [%{public}s] value err, size=%{public}u, value=%{public}s",
JSON_LOGE("strcpy [%s] value err, size=%u, value=%s",
key, size, valueString.c_str());
return false;
}
@ -300,7 +300,7 @@ bool JSON_GetStringArrayFromOject(const JsonObj *obj, const char * const key, ch
}
nlohmann::json item = (*json)[key];
if (!item.is_array()) {
JSON_LOGE("cannot find or invalid [%{public}s]", key);
JSON_LOGE("cannot find or invalid [%s]", key);
return false;
}
if ((unsigned long)(*len) < (unsigned long)item.size()) {
@ -317,7 +317,7 @@ bool JSON_GetStringArrayFromOject(const JsonObj *obj, const char * const key, ch
return false;
}
if (strcpy_s(value[i], len, valueString) != EOK) {
JSON_LOGE("strcpy [%{public}s] value err, value=%{public}s", key, valueString);
JSON_LOGE("strcpy [%s] value err, value=%s", key, valueString);
return false;
}
i++;

View File

@ -15,13 +15,14 @@
#include "lnn_ip_utils_adapter.h"
#include "comm_log.h"
#include "lwip/netif.h"
#include "softbus_adapter_mem.h"
int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32_t len)
{
if (ifName == NULL || ip == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ifName or ip buffer is NULL!");
COMM_LOGE(COMM_ADAPTER, "ifName or ip buffer is NULL!");
return SOFTBUS_INVALID_PARAM;
}
@ -33,7 +34,7 @@ int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32
netif = netif_find(ifName);
if (netif == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "netif is NULL!");
COMM_LOGE(COMM_ADAPTER, "netif is NULL!");
return SOFTBUS_ERR;
}
#ifdef HISPARK_PEGASUS_USE_NETIF_GET_ADDR
@ -44,13 +45,13 @@ int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32
#endif
ipStr = ip4addr_ntoa(ipAddr);
if (strncpy_s(ip, len, ipStr, strlen(ipStr)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy ip failed!");
COMM_LOGE(COMM_ADAPTER, "copy ip failed!");
return SOFTBUS_ERR;
}
if (netmask != NULL) {
netMaskStr = ip4addr_ntoa(netMask);
if (strncpy_s(netmask, len, netMaskStr, strlen(netMaskStr)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy netmask failed!");
COMM_LOGE(COMM_ADAPTER, "copy netmask failed!");
return SOFTBUS_ERR;
}
}

View File

@ -16,8 +16,8 @@
#include "softbus_adapter_file.h"
#include "cmsis_os2.h"
#include "comm_log.h"
#include "softbus_adapter_errcode.h"
#include "softbus_adapter_log.h"
#include "softbus_errcode.h"
#include "utils_file.h"
@ -37,7 +37,7 @@ int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen
uint32_t fileLen = 0;
int32_t fd = UtilsFileOpen(fileName, O_RDONLY_FS, 0);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Read UtilsFileOpen fail");
COMM_LOGE(COMM_ADAPTER, "Read UtilsFileOpen fail");
return SOFTBUS_FILE_ERR;
}
int32_t ret = UtilsFileStat(fileName, &fileLen);
@ -47,18 +47,18 @@ int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen
}
ret = UtilsFileSeek(fd, 0, SEEK_SET_FS);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Read UtilsFileSeek fail");
COMM_LOGE(COMM_ADAPTER, "Read UtilsFileSeek fail");
UtilsFileClose(fd);
return SOFTBUS_FILE_ERR;
}
if (fileLen > maxLen) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Read file len not legal, clear buf");
COMM_LOGE(COMM_ADAPTER, "Read file len not legal, clear buf");
UtilsFileClose(fd);
return SOFTBUS_FILE_ERR;
}
ret = UtilsFileRead(fd, readBuf, maxLen);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Read UtilsFileRead, ret=%{public}d", ret);
COMM_LOGE(COMM_ADAPTER, "Read UtilsFileRead, ret=%d", ret);
UtilsFileClose(fd);
return SOFTBUS_FILE_ERR;
}
@ -72,12 +72,12 @@ int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t le
int32_t fd;
fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "UtilsFileOpen fail");
COMM_LOGE(COMM_ADAPTER, "UtilsFileOpen fail");
return SOFTBUS_FILE_ERR;
}
ret = UtilsFileWrite(fd, writeBuf, len);
if (ret != (int32_t)len) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "UtilsFileOpen UtilsFileWrite fail");
COMM_LOGE(COMM_ADAPTER, "UtilsFileOpen UtilsFileWrite fail");
UtilsFileClose(fd);
return SOFTBUS_FILE_ERR;
}

View File

@ -17,7 +17,7 @@
#include <sys/time.h>
#include "cmsis_os2.h"
#include "softbus_adapter_log.h"
#include "comm_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
@ -43,39 +43,39 @@ void *SoftBusCreateTimer(void **timerId, unsigned int type)
void *id = osTimerNew((osTimerFunc_t)HandleTimeoutAdapterFun, (osTimerType_t)type, NULL, NULL);
if (id != NULL) {
HILOG_INFO(SOFTBUS_HILOG_ID, "create timer success");
COMM_LOGI(COMM_ADAPTER, "create timer success");
return id;
}
HILOG_ERROR(SOFTBUS_HILOG_ID, "create timer failed");
COMM_LOGE(COMM_ADAPTER, "create timer failed");
return NULL;
}
int SoftBusStartTimer(void *timerId, unsigned int ms)
{
if (timerId == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "timerId is NULL");
COMM_LOGE(COMM_ADAPTER, "timerId is NULL");
return SOFTBUS_ERR;
}
if (osTimerStart(timerId, ms * osKernelGetTickFreq() / MS_PER_SECOND) != osOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "start timer failed");
COMM_LOGE(COMM_ADAPTER, "start timer failed");
(void)osTimerDelete(timerId);
return SOFTBUS_ERR;
}
HILOG_INFO(SOFTBUS_HILOG_ID, "start timer success");
COMM_LOGI(COMM_ADAPTER, "start timer success");
return SOFTBUS_OK;
}
int SoftBusDeleteTimer(void *timerId)
{
if (timerId == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "timerId is NULL");
COMM_LOGE(COMM_ADAPTER, "timerId is NULL");
return SOFTBUS_ERR;
}
if (osTimerDelete(timerId) != osOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "delete timer failed");
COMM_LOGE(COMM_ADAPTER, "delete timer failed");
return SOFTBUS_ERR;
}
HILOG_INFO(SOFTBUS_HILOG_ID, "delete timer success");
COMM_LOGI(COMM_ADAPTER, "delete timer success");
return SOFTBUS_OK;
}
@ -88,7 +88,7 @@ int SoftBusSleepMs(unsigned int ms)
int32_t SoftBusGetTime(SoftBusSysTime *sysTime)
{
if (sysTime == NULL) {
HILOG_INFO(SOFTBUS_HILOG_ID, "sysTime is null");
COMM_LOGI(COMM_ADAPTER, "sysTime is null");
return SOFTBUS_INVALID_PARAM;
}
struct timeval time = {0};

View File

@ -21,38 +21,39 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "comm_log.h"
static int32_t GetNetworkIfIp(int32_t fd, struct ifreq *req, char *ip, char *netmask, uint32_t len)
{
if (ioctl(fd, SIOCGIFFLAGS, (char*)req) < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ioctl SIOCGIFFLAGS fail, errno = %{public}d", errno);
COMM_LOGE(COMM_ADAPTER, "ioctl SIOCGIFFLAGS fail, errno = %d", errno);
return SOFTBUS_ERR;
}
if (!((uint16_t)req->ifr_flags & IFF_UP)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "interface is not up");
COMM_LOGE(COMM_ADAPTER, "interface is not up");
return SOFTBUS_ERR;
}
/* get IP of this interface */
if (ioctl(fd, SIOCGIFADDR, (char*)req) < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ioctl SIOCGIFADDR fail, errno = %{public}d", errno);
COMM_LOGE(COMM_ADAPTER, "ioctl SIOCGIFADDR fail, errno = %d", errno);
return SOFTBUS_ERR;
}
struct sockaddr_in *sockAddr = (struct sockaddr_in *)&(req->ifr_addr);
if (inet_ntop(sockAddr->sin_family, &sockAddr->sin_addr, ip, len) == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "convert ip addr to string failed");
COMM_LOGE(COMM_ADAPTER, "convert ip addr to string failed");
return SOFTBUS_ERR;
}
/* get netmask of this interface */
if (netmask != NULL) {
if (ioctl(fd, SIOCGIFNETMASK, (char*)req) < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ioctl SIOCGIFNETMASK fail, errno = %{public}d", errno);
COMM_LOGE(COMM_ADAPTER, "ioctl SIOCGIFNETMASK fail, errno = %d", errno);
return SOFTBUS_ERR;
}
sockAddr = (struct sockaddr_in *)&(req->ifr_netmask);
if (inet_ntop(sockAddr->sin_family, &sockAddr->sin_addr, netmask, len) == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "convert netmask addr to string failed");
COMM_LOGE(COMM_ADAPTER, "convert netmask addr to string failed");
return SOFTBUS_ERR;
}
}
@ -62,22 +63,22 @@ static int32_t GetNetworkIfIp(int32_t fd, struct ifreq *req, char *ip, char *net
int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32_t len)
{
if (ifName == NULL || ip == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ifName or ip buffer is NULL!");
COMM_LOGE(COMM_ADAPTER, "ifName or ip buffer is NULL!");
return SOFTBUS_INVALID_PARAM;
}
int32_t fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "open socket failed");
COMM_LOGE(COMM_ADAPTER, "open socket failed");
return SOFTBUS_ERR;
}
struct ifreq ifr;
if (strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), ifName, strlen(ifName)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy netIfName:%{public}s fail", ifName);
COMM_LOGE(COMM_ADAPTER, "copy netIfName:%s fail", ifName);
close(fd);
return SOFTBUS_ERR;
}
if (GetNetworkIfIp(fd, &ifr, ip, netmask, len) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "GetNetworkIfIp ifName:%{public}s fail", ifName);
COMM_LOGE(COMM_ADAPTER, "GetNetworkIfIp ifName:%s fail", ifName);
close(fd);
return SOFTBUS_ERR;
}

View File

@ -24,8 +24,8 @@
#include <sys/types.h>
#include <unistd.h>
#include "comm_log.h"
#include "softbus_adapter_errcode.h"
#include "softbus_adapter_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
@ -45,14 +45,14 @@ static int32_t SoftBusCreateFile(const char *fileName)
continue;
}
if (memcpy_s(dirPath, sizeof(dirPath), fileName, len) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "memory copy dir name failed");
COMM_LOGE(COMM_ADAPTER, "memory copy dir name failed");
return SOFTBUS_ERR;
}
dirPath[len] = 0;
if (access(dirPath, F_OK) != 0) {
int32_t ret = mkdir(dirPath, S_IRWXU);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "make dir failed, err code %{public}d", ret);
COMM_LOGE(COMM_ADAPTER, "make dir failed, err code %d", ret);
return SOFTBUS_ERR;
}
}
@ -60,7 +60,7 @@ static int32_t SoftBusCreateFile(const char *fileName)
}
int32_t fd = open(fileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "crate file failed, errno = %{public}d", errno);
COMM_LOGE(COMM_ADAPTER, "crate file failed, errno = %d", errno);
return SOFTBUS_ERR;
}
close(fd);
@ -70,12 +70,12 @@ static int32_t SoftBusCreateFile(const char *fileName)
int32_t SoftBusReadFile(int32_t fd, void *readBuf, uint32_t maxLen)
{
if (readBuf == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus read file [buff is null]");
COMM_LOGE(COMM_ADAPTER, "softbus read file [buff is null]");
return SOFTBUS_INVALID_PARAM;
}
int64_t len = read(fd, readBuf, maxLen);
if (len < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus read file fail : %s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "softbus read file fail : %s", strerror(errno));
}
return len;
}
@ -88,24 +88,24 @@ static int32_t ReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen
int32_t fd = open(fileName, O_RDONLY, S_IRUSR | S_IWUSR);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ReadFile open file fail");
COMM_LOGE(COMM_ADAPTER, "ReadFile open file fail");
return SOFTBUS_FILE_ERR;
}
int32_t fileLen = lseek(fd, 0, SEEK_END);
if (fileLen <= 0 || fileLen > (int32_t)maxLen) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ReadFile maxLen failed or over maxLen");
COMM_LOGE(COMM_ADAPTER, "ReadFile maxLen failed or over maxLen");
close(fd);
return SOFTBUS_FILE_ERR;
}
int32_t ret = lseek(fd, 0, SEEK_SET);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ReadFile lseek file fail");
COMM_LOGE(COMM_ADAPTER, "ReadFile lseek file fail");
close(fd);
return SOFTBUS_FILE_ERR;
}
ret = read(fd, readBuf, fileLen);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ReadFile read fail, ret=%{public}d", ret);
COMM_LOGE(COMM_ADAPTER, "ReadFile read fail, ret=%d", ret);
close(fd);
return SOFTBUS_FILE_ERR;
}
@ -131,17 +131,17 @@ int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t le
return SOFTBUS_FILE_ERR;
}
if (access(fileName, F_OK) != 0 && SoftBusCreateFile(fileName) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "create file fail");
COMM_LOGE(COMM_ADAPTER, "create file fail");
return SOFTBUS_FILE_ERR;
}
int32_t fd = open(fileName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "WriteFile open file fail");
COMM_LOGE(COMM_ADAPTER, "WriteFile open file fail");
return SOFTBUS_FILE_ERR;
}
int32_t ret = write(fd, writeBuf, len);
if (len > INT32_MAX || ret != (int32_t)len) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "WriteFile write fail");
COMM_LOGE(COMM_ADAPTER, "WriteFile write fail");
close(fd);
return SOFTBUS_FILE_ERR;
}
@ -157,7 +157,7 @@ int32_t SoftBusWriteFileFd(int32_t fd, const char *writeBuf, uint32_t len)
}
int32_t ret = write(fd, writeBuf, len);
if (ret != (int32_t)len) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "WriteFileFd write fail");
COMM_LOGE(COMM_ADAPTER, "WriteFileFd write fail");
}
return ret;
}
@ -165,12 +165,12 @@ int32_t SoftBusWriteFileFd(int32_t fd, const char *writeBuf, uint32_t len)
int32_t SoftBusOpenFile(const char *fileName, int32_t flags)
{
if (fileName == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus open file [fileName is null]");
COMM_LOGE(COMM_ADAPTER, "softbus open file [fileName is null]");
return SOFTBUS_INVALID_FD;
}
int32_t fd = open(fileName, flags);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus open file [open fail], %s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "softbus open file [open fail], %s", strerror(errno));
return SOFTBUS_INVALID_FD;
}
return fd;
@ -179,12 +179,12 @@ int32_t SoftBusOpenFile(const char *fileName, int32_t flags)
int32_t SoftBusOpenFileWithPerms(const char *fileName, int32_t flags, int32_t perms)
{
if (fileName == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus open with perms file [fileName is null]");
COMM_LOGE(COMM_ADAPTER, "softbus open with perms file [fileName is null]");
return SOFTBUS_INVALID_FD;
}
int32_t fd = open(fileName, flags, perms);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus open with perms file [open fail], %s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "softbus open with perms file [open fail], %s", strerror(errno));
return SOFTBUS_INVALID_FD;
}
return fd;
@ -193,11 +193,11 @@ int32_t SoftBusOpenFileWithPerms(const char *fileName, int32_t flags, int32_t pe
void SoftBusRemoveFile(const char *fileName)
{
if (fileName == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus remove file [fileName is null]");
COMM_LOGE(COMM_ADAPTER, "softbus remove file [fileName is null]");
return;
}
if (remove(fileName) != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus remove file fail : %s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "softbus remove file fail : %s", strerror(errno));
return;
}
}
@ -205,11 +205,11 @@ void SoftBusRemoveFile(const char *fileName)
void SoftBusCloseFile(int32_t fd)
{
if (fd <= SOFTBUS_INVALID_FD) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus close file [fd is invalid]");
COMM_LOGE(COMM_ADAPTER, "softbus close file [fd is invalid]");
return;
}
if (close(fd) != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus remove file fail : %s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "softbus remove file fail : %s", strerror(errno));
return;
}
}
@ -217,12 +217,12 @@ void SoftBusCloseFile(int32_t fd)
int64_t SoftBusPreadFile(int32_t fd, void *buf, uint64_t readBytes, uint64_t offset)
{
if (buf == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus pread file [buff is null]");
COMM_LOGE(COMM_ADAPTER, "softbus pread file [buff is null]");
return SOFTBUS_ERR;
}
int64_t len = pread(fd, buf, readBytes, offset);
if (len < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus pread file fail : %s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "softbus pread file fail : %s", strerror(errno));
}
return len;
}
@ -230,12 +230,12 @@ int64_t SoftBusPreadFile(int32_t fd, void *buf, uint64_t readBytes, uint64_t off
int64_t SoftBusPwriteFile(int32_t fd, const void *buf, uint64_t writeBytes, uint64_t offset)
{
if (buf == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus pwrite file [buff is null]");
COMM_LOGE(COMM_ADAPTER, "softbus pwrite file [buff is null]");
return SOFTBUS_ERR;
}
int64_t len = pwrite(fd, buf, writeBytes, offset);
if (len < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus pwrite file fail : %s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "softbus pwrite file fail : %s", strerror(errno));
}
return len;
}
@ -243,13 +243,13 @@ int64_t SoftBusPwriteFile(int32_t fd, const void *buf, uint64_t writeBytes, uint
int32_t SoftBusAccessFile(const char *pathName, int32_t mode)
{
if (pathName == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus access path [pathName is null]");
COMM_LOGE(COMM_ADAPTER, "softbus access path [pathName is null]");
return SOFTBUS_ERR;
}
int32_t ret = access(pathName, mode);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus access path fail : %s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "softbus access path fail : %s", strerror(errno));
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
@ -258,7 +258,7 @@ int32_t SoftBusAccessFile(const char *pathName, int32_t mode)
int32_t SoftBusMakeDir(const char *pathName, int32_t mode)
{
if (pathName == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus mkdir file [pathName is null]");
COMM_LOGE(COMM_ADAPTER, "softbus mkdir file [pathName is null]");
return SOFTBUS_ERR;
}
@ -274,13 +274,13 @@ int32_t SoftBusMakeDir(const char *pathName, int32_t mode)
int32_t SoftBusGetFileSize(const char *fileName, uint64_t *fileSize)
{
if ((fileName == NULL) || (fileSize == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus mkdir file [fileName or fileSize is null]");
COMM_LOGE(COMM_ADAPTER, "softbus mkdir file [fileName or fileSize is null]");
return SOFTBUS_ERR;
}
struct stat statbuff;
if (stat(fileName, &statbuff) < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "stat file fail");
COMM_LOGE(COMM_ADAPTER, "stat file fail");
return SOFTBUS_ERR;
} else {
*fileSize = statbuff.st_size;
@ -292,13 +292,13 @@ int32_t SoftBusGetFileSize(const char *fileName, uint64_t *fileSize)
char *SoftBusRealPath(const char *path, char *absPath)
{
if ((path == NULL) || (absPath == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "softbus realpath [path or absPath is null]");
COMM_LOGE(COMM_ADAPTER, "softbus realpath [path or absPath is null]");
return NULL;
}
char *realPath = NULL;
if (realpath(path, absPath) == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "realpath failed, err[%s]", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "realpath failed, err[%s]", strerror(errno));
return NULL;
} else {
realPath = absPath;

View File

@ -26,9 +26,9 @@
#include <sys/socket.h>
#include <unistd.h>
#include "comm_log.h"
#include "endian.h" /* liteos_m htons */
#include "softbus_adapter_errcode.h"
#include "softbus_adapter_log.h"
#include "softbus_def.h"
static void ShiftByte(uint8_t *in, int8_t inSize)
@ -76,13 +76,13 @@ static int32_t GetErrorCode(void)
int32_t SoftBusSocketCreate(int32_t domain, int32_t type, int32_t protocol, int32_t *socketFd)
{
if (socketFd == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "socketFd is null");
COMM_LOGE(COMM_ADAPTER, "socketFd is null");
return SOFTBUS_ADAPTER_INVALID_PARAM;
}
int32_t ret;
ret = socket(domain, type, protocol);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "socket %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "socket %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
} else {
*socketFd = ret;
@ -94,7 +94,7 @@ int32_t SoftBusSocketSetOpt(int32_t socketFd, int32_t level, int32_t optName, co
{
int32_t ret = setsockopt(socketFd, level, optName, optVal, (socklen_t)optLen);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "setsockopt : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "setsockopt : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
@ -105,7 +105,7 @@ int32_t SoftBusSocketGetOpt(int32_t socketFd, int32_t level, int32_t optName, vo
{
int32_t ret = getsockopt(socketFd, level, optName, optVal, (socklen_t *)optLen);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "getsockopt : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "getsockopt : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
return SOFTBUS_ADAPTER_OK;
@ -117,11 +117,11 @@ int32_t SoftBusSocketGetError(int32_t socketFd)
socklen_t errSize = sizeof(err);
int32_t ret = getsockopt(socketFd, SOL_SOCKET, SO_ERROR, &err, &errSize);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "getsockopt fd=%{public}d, ret=%{public}d", socketFd, ret);
COMM_LOGE(COMM_ADAPTER, "getsockopt fd=%d, ret=%d", socketFd, ret);
return ret;
}
if (err != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "getsockopt fd=%{public}d, err=%{public}d", socketFd, err);
COMM_LOGE(COMM_ADAPTER, "getsockopt fd=%d, err=%d", socketFd, err);
return err;
}
return err;
@ -130,21 +130,21 @@ int32_t SoftBusSocketGetError(int32_t socketFd)
static int32_t SoftBusAddrToSysAddr(const SoftBusSockAddr *softbusAddr, struct sockaddr *sysAddr, uint32_t len)
{
if (len < sizeof(softbusAddr->saFamily)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%s:invalid len", __func__);
COMM_LOGE(COMM_ADAPTER, "invalid len");
return SOFTBUS_ADAPTER_ERR;
}
if ((softbusAddr == NULL) || (sysAddr == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%s:invalid input", __func__);
COMM_LOGE(COMM_ADAPTER, "invalid input");
return SOFTBUS_ADAPTER_ERR;
}
if (memset_s(sysAddr, sizeof(struct sockaddr), 0, sizeof(struct sockaddr)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%s:memset fail", __func__);
COMM_LOGE(COMM_ADAPTER, "memset fail");
return SOFTBUS_ADAPTER_ERR;
}
sysAddr->sa_family = softbusAddr->saFamily;
if (memcpy_s(sysAddr->sa_data, sizeof(sysAddr->sa_data), softbusAddr->saData,
len - sizeof(softbusAddr->saFamily)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%s:memcpy fail", __func__);
COMM_LOGE(COMM_ADAPTER, "memcpy fail");
return SOFTBUS_ADAPTER_ERR;
}
return SOFTBUS_ADAPTER_OK;
@ -153,13 +153,13 @@ static int32_t SoftBusAddrToSysAddr(const SoftBusSockAddr *softbusAddr, struct s
static int32_t SysAddrToSoftBusAddr(const struct sockaddr *sysAddr, SoftBusSockAddr *softbusAddr)
{
if (memset_s(softbusAddr, sizeof(SoftBusSockAddr), 0, sizeof(SoftBusSockAddr)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%s:memset fail", __func__);
COMM_LOGE(COMM_ADAPTER, "memset fail");
return SOFTBUS_ADAPTER_ERR;
}
softbusAddr->saFamily = sysAddr->sa_family;
if (memcpy_s(softbusAddr->saData, sizeof(softbusAddr->saData), sysAddr->sa_data, sizeof(sysAddr->sa_data))
!= EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%s:memcpy fail", __func__);
COMM_LOGE(COMM_ADAPTER, "memcpy fail");
return SOFTBUS_ADAPTER_ERR;
}
return SOFTBUS_ADAPTER_OK;
@ -168,22 +168,22 @@ static int32_t SysAddrToSoftBusAddr(const struct sockaddr *sysAddr, SoftBusSockA
int32_t SoftBusSocketGetLocalName(int32_t socketFd, SoftBusSockAddr *addr)
{
if (addr == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "get local name invalid input");
COMM_LOGE(COMM_ADAPTER, "get local name invalid input");
return SOFTBUS_ADAPTER_ERR;
}
struct sockaddr sysAddr;
uint32_t len = sizeof(struct sockaddr);
if (memset_s(&sysAddr, sizeof(struct sockaddr), 0, sizeof(struct sockaddr)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "get local name memset fail");
COMM_LOGE(COMM_ADAPTER, "get local name memset fail");
return SOFTBUS_ADAPTER_ERR;
}
int32_t ret = getsockname(socketFd, &sysAddr, (socklen_t *)&len);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "getsockname : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "getsockname : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
if (SysAddrToSoftBusAddr(&sysAddr, addr) != SOFTBUS_ADAPTER_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "get local name sys addr to softbus addr failed");
COMM_LOGE(COMM_ADAPTER, "get local name sys addr to softbus addr failed");
return SOFTBUS_ADAPTER_ERR;
}
return SOFTBUS_ADAPTER_OK;
@ -192,22 +192,22 @@ int32_t SoftBusSocketGetLocalName(int32_t socketFd, SoftBusSockAddr *addr)
int32_t SoftBusSocketGetPeerName(int32_t socketFd, SoftBusSockAddr *addr)
{
if (addr == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "get peer name invalid input");
COMM_LOGE(COMM_ADAPTER, "get peer name invalid input");
return SOFTBUS_ADAPTER_ERR;
}
struct sockaddr sysAddr;
if (memset_s(&sysAddr, sizeof(struct sockaddr), 0, sizeof(struct sockaddr)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "get peer name memset fail");
COMM_LOGE(COMM_ADAPTER, "get peer name memset fail");
return SOFTBUS_ADAPTER_ERR;
}
uint32_t len = sizeof(sysAddr);
int32_t ret = getpeername(socketFd, &sysAddr, (socklen_t *)&len);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "getpeername : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "getpeername : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
if (SysAddrToSoftBusAddr(&sysAddr, addr) != SOFTBUS_ADAPTER_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "get peer name sys addr to softbus addr failed");
COMM_LOGE(COMM_ADAPTER, "get peer name sys addr to softbus addr failed");
return SOFTBUS_ADAPTER_ERR;
}
return SOFTBUS_ADAPTER_OK;
@ -221,12 +221,12 @@ int32_t SoftBusSocketBind(int32_t socketFd, SoftBusSockAddr *addr, int32_t addrL
struct sockaddr sysAddr;
uint32_t len = ((uint32_t)addrLen >= sizeof(SoftBusSockAddr)) ? sizeof(SoftBusSockAddr) : (uint32_t)addrLen;
if (SoftBusAddrToSysAddr(addr, &sysAddr, len) != SOFTBUS_ADAPTER_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "socket bind sys addr to softbus addr failed");
COMM_LOGE(COMM_ADAPTER, "socket bind sys addr to softbus addr failed");
return SOFTBUS_ADAPTER_ERR;
}
int32_t ret = bind(socketFd, &sysAddr, (socklen_t)addrLen);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "bind : %{public}s, %d", strerror(errno), errno);
COMM_LOGE(COMM_ADAPTER, "bind : %s, %d", strerror(errno), errno);
return GetErrorCode();
}
@ -237,7 +237,7 @@ int32_t SoftBusSocketListen(int32_t socketFd, int32_t backLog)
{
int32_t ret = listen(socketFd, backLog);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "listen : %{public}s, %d", strerror(errno), errno);
COMM_LOGE(COMM_ADAPTER, "listen : %s, %d", strerror(errno), errno);
return SOFTBUS_ADAPTER_ERR;
}
@ -247,22 +247,22 @@ int32_t SoftBusSocketListen(int32_t socketFd, int32_t backLog)
int32_t SoftBusSocketAccept(int32_t socketFd, SoftBusSockAddr *addr, int32_t *acceptFd)
{
if (addr == NULL || acceptFd == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "socket accept invalid input");
COMM_LOGE(COMM_ADAPTER, "socket accept invalid input");
return SOFTBUS_ADAPTER_INVALID_PARAM;
}
struct sockaddr sysAddr;
uint32_t len = sizeof(sysAddr);
if (memset_s(&sysAddr, len, 0, len) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "memset failed");
COMM_LOGE(COMM_ADAPTER, "memset failed");
return SOFTBUS_ADAPTER_ERR;
}
int32_t ret = accept(socketFd, &sysAddr, (socklen_t *)&len);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "accept : %{public}s, %d", strerror(errno), errno);
COMM_LOGE(COMM_ADAPTER, "accept : %s, %d", strerror(errno), errno);
return GetErrorCode();
}
if (SysAddrToSoftBusAddr(&sysAddr, addr) != SOFTBUS_ADAPTER_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "socket accept sys addr to softbus addr failed");
COMM_LOGE(COMM_ADAPTER, "socket accept sys addr to softbus addr failed");
return SOFTBUS_ADAPTER_ERR;
}
*acceptFd = ret;
@ -273,13 +273,13 @@ int32_t SoftBusSocketConnect(int32_t socketFd, const SoftBusSockAddr *addr)
{
struct sockaddr sysAddr;
if (SoftBusAddrToSysAddr(addr, &sysAddr, sizeof(SoftBusSockAddr)) != SOFTBUS_ADAPTER_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "socket connect sys addr to softbus addr failed");
COMM_LOGE(COMM_ADAPTER, "socket connect sys addr to softbus addr failed");
return SOFTBUS_ADAPTER_ERR;
}
uint32_t len = sizeof(sysAddr);
int32_t ret = connect(socketFd, &sysAddr, (socklen_t)len);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "connect :%{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "connect :%s", strerror(errno));
return GetErrorCode();
}
return SOFTBUS_ADAPTER_OK;
@ -288,7 +288,7 @@ int32_t SoftBusSocketConnect(int32_t socketFd, const SoftBusSockAddr *addr)
void SoftBusSocketFdZero(SoftBusFdSet *set)
{
if (set == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "set is null");
COMM_LOGE(COMM_ADAPTER, "set is null");
return;
}
@ -298,7 +298,7 @@ void SoftBusSocketFdZero(SoftBusFdSet *set)
void SoftBusSocketFdSet(int32_t socketFd, SoftBusFdSet *set)
{
if (set == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "set is null");
COMM_LOGE(COMM_ADAPTER, "set is null");
return;
}
@ -308,7 +308,7 @@ void SoftBusSocketFdSet(int32_t socketFd, SoftBusFdSet *set)
void SoftBusSocketFdClr(int32_t socketFd, SoftBusFdSet *set)
{
if (set == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "set is null");
COMM_LOGE(COMM_ADAPTER, "set is null");
return;
}
@ -318,7 +318,7 @@ void SoftBusSocketFdClr(int32_t socketFd, SoftBusFdSet *set)
int32_t SoftBusSocketFdIsset(int32_t socketFd, SoftBusFdSet *set)
{
if (set == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "set is null");
COMM_LOGE(COMM_ADAPTER, "set is null");
return 0;
}
@ -361,7 +361,7 @@ int32_t SoftBusSocketSelect(
#endif
int32_t ret = select(nfds, tempReadSet, tempWriteSet, tempExceptSet, timeoutPtr);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "select : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "select : %s", strerror(errno));
return GetErrorCode();
}
@ -372,7 +372,7 @@ int32_t SoftBusSocketIoctl(int32_t socketFd, long cmd, void *argp)
{
int32_t ret = ioctl(socketFd, cmd, argp);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "ioctl : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "ioctl : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
@ -383,7 +383,7 @@ int32_t SoftBusSocketFcntl(int32_t socketFd, long cmd, long flag)
{
int32_t ret = fcntl(socketFd, cmd, flag);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "fcntl : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "fcntl : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
@ -395,7 +395,7 @@ int32_t SoftBusSocketSend(int32_t socketFd, const void *buf, uint32_t len, int32
int32_t wrapperFlag = flags | MSG_NOSIGNAL;
int32_t ret = send(socketFd, buf, len, wrapperFlag);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "send : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "send : %s", strerror(errno));
return GetErrorCode();
}
@ -406,17 +406,17 @@ int32_t SoftBusSocketSendTo(int32_t socketFd, const void *buf, uint32_t len, int
const SoftBusSockAddr *toAddr, int32_t toAddrLen)
{
if ((toAddr == NULL) || (toAddrLen <= 0)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "toAddr is null or toAddrLen <= 0");
COMM_LOGE(COMM_ADAPTER, "toAddr is null or toAddrLen <= 0");
return SOFTBUS_ADAPTER_ERR;
}
struct sockaddr sysAddr;
if (SoftBusAddrToSysAddr(toAddr, &sysAddr, sizeof(SoftBusSockAddr)) != SOFTBUS_ADAPTER_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "socket sendto sys addr to softbus addr failed");
COMM_LOGE(COMM_ADAPTER, "socket sendto sys addr to softbus addr failed");
return SOFTBUS_ADAPTER_ERR;
}
int32_t ret = sendto(socketFd, buf, len, flags, &sysAddr, toAddrLen);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "sendto : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "sendto : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
@ -427,7 +427,7 @@ int32_t SoftBusSocketRecv(int32_t socketFd, void *buf, uint32_t len, int32_t fla
{
int32_t ret = recv(socketFd, buf, len, flags);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "recv : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "recv : %s", strerror(errno));
return GetErrorCode();
}
@ -438,17 +438,17 @@ int32_t SoftBusSocketRecvFrom(int32_t socketFd, void *buf, uint32_t len, int32_t
int32_t *fromAddrLen)
{
if ((fromAddr == NULL) || (fromAddrLen == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "fromAddr or fromAddrLen is null");
COMM_LOGE(COMM_ADAPTER, "fromAddr or fromAddrLen is null");
return SOFTBUS_ADAPTER_ERR;
}
struct sockaddr sysAddr;
if (SoftBusAddrToSysAddr(fromAddr, &sysAddr, sizeof(SoftBusSockAddr)) != SOFTBUS_ADAPTER_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "socket recvfrom sys addr to softbus addr failed");
COMM_LOGE(COMM_ADAPTER, "socket recvfrom sys addr to softbus addr failed");
return SOFTBUS_ADAPTER_ERR;
}
int32_t ret = recvfrom(socketFd, buf, len, flags, &sysAddr, (socklen_t *)fromAddrLen);
if (ret < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "recvfrom : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "recvfrom : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
@ -459,7 +459,7 @@ int32_t SoftBusSocketShutDown(int32_t socketFd, int32_t how)
{
int32_t ret = shutdown(socketFd, how);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "shutdown :%{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "shutdown :%s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
@ -470,7 +470,7 @@ int32_t SoftBusSocketClose(int32_t socketFd)
{
int32_t ret = close(socketFd);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "close : %{public}s", strerror(errno));
COMM_LOGE(COMM_ADAPTER, "close : %s", strerror(errno));
return SOFTBUS_ADAPTER_ERR;
}
@ -483,10 +483,10 @@ int32_t SoftBusInetPtoN(int32_t af, const char *src, void *dst)
if (ret == 1) {
return SOFTBUS_ADAPTER_OK;
} else if (ret == 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "invalid str input fromat");
COMM_LOGE(COMM_ADAPTER, "invalid str input fromat");
return SOFTBUS_ADAPTER_INVALID_PARAM;
} else {
HILOG_ERROR(SOFTBUS_HILOG_ID, "inet_pton failed");
COMM_LOGE(COMM_ADAPTER, "inet_pton failed");
return SOFTBUS_ADAPTER_ERR;
}
}

View File

@ -24,7 +24,7 @@
#include <stdio.h>
#include <string.h>
#include "softbus_adapter_log.h"
#include "comm_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
@ -34,7 +34,7 @@ static pthread_mutex_t g_adapterStaticLock = PTHREAD_MUTEX_INITIALIZER;
int32_t SoftBusMutexAttrInit(SoftBusMutexAttr *mutexAttr)
{
if (mutexAttr == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "mutexAttr is null");
COMM_LOGE(COMM_ADAPTER, "mutexAttr is null");
return SOFTBUS_INVALID_PARAM;
}
@ -45,11 +45,11 @@ int32_t SoftBusMutexAttrInit(SoftBusMutexAttr *mutexAttr)
int32_t SoftBusMutexInit(SoftBusMutex *mutex, SoftBusMutexAttr *mutexAttr)
{
if (pthread_mutex_lock(&g_adapterStaticLock) != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "mutex init : g_adapterStaticLock lock failed");
COMM_LOGE(COMM_ADAPTER, "mutex init : g_adapterStaticLock lock failed");
return SOFTBUS_ERR;
}
if (mutex == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "mutex is null");
COMM_LOGE(COMM_ADAPTER, "mutex is null");
(void)pthread_mutex_unlock(&g_adapterStaticLock);
return SOFTBUS_INVALID_PARAM;
}
@ -60,7 +60,7 @@ int32_t SoftBusMutexInit(SoftBusMutex *mutex, SoftBusMutexAttr *mutexAttr)
pthread_mutex_t *tempMutex;
tempMutex = (pthread_mutex_t *)SoftBusCalloc(sizeof(pthread_mutex_t));
if (tempMutex == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "tempMutex is null");
COMM_LOGE(COMM_ADAPTER, "tempMutex is null");
(void)pthread_mutex_unlock(&g_adapterStaticLock);
return SOFTBUS_INVALID_PARAM;
}
@ -82,7 +82,7 @@ int32_t SoftBusMutexInit(SoftBusMutex *mutex, SoftBusMutexAttr *mutexAttr)
ret = pthread_mutex_init(tempMutex, &attr);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusMutexInit failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusMutexInit failed, ret[%d]", ret);
SoftBusFree(tempMutex);
tempMutex = NULL;
(void)pthread_mutex_unlock(&g_adapterStaticLock);
@ -97,14 +97,14 @@ int32_t SoftBusMutexInit(SoftBusMutex *mutex, SoftBusMutexAttr *mutexAttr)
int32_t SoftBusMutexLock(SoftBusMutex *mutex)
{
if ((mutex == NULL) || ((void *)(*mutex) == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "mutex is null");
COMM_LOGE(COMM_ADAPTER, "mutex is null");
return SOFTBUS_INVALID_PARAM;
}
int ret;
ret = pthread_mutex_lock((pthread_mutex_t *)*mutex);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusMutexLock failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusMutexLock failed, ret[%d]", ret);
return SOFTBUS_LOCK_ERR;
}
return SOFTBUS_OK;
@ -113,14 +113,14 @@ int32_t SoftBusMutexLock(SoftBusMutex *mutex)
int32_t SoftBusMutexUnlock(SoftBusMutex *mutex)
{
if ((mutex == NULL) || ((void *)(*mutex) == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "mutex is null");
COMM_LOGE(COMM_ADAPTER, "mutex is null");
return SOFTBUS_INVALID_PARAM;
}
int ret;
ret = pthread_mutex_unlock((pthread_mutex_t *)*mutex);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusMutexUnlock failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusMutexUnlock failed, ret[%d]", ret);
return SOFTBUS_LOCK_ERR;
}
@ -130,14 +130,14 @@ int32_t SoftBusMutexUnlock(SoftBusMutex *mutex)
int32_t SoftBusMutexDestroy(SoftBusMutex *mutex)
{
if ((mutex == NULL) || ((void *)(*mutex) == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "mutex is null");
COMM_LOGE(COMM_ADAPTER, "mutex is null");
return SOFTBUS_INVALID_PARAM;
}
int ret;
ret = pthread_mutex_destroy((pthread_mutex_t *)*mutex);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusMutexDestroy failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusMutexDestroy failed, ret[%d]", ret);
SoftBusFree((void *)*mutex);
*mutex = (SoftBusMutex)NULL;
return SOFTBUS_ERR;
@ -152,7 +152,7 @@ int32_t SoftBusMutexDestroy(SoftBusMutex *mutex)
int32_t SoftBusThreadAttrInit(SoftBusThreadAttr *threadAttr)
{
if (threadAttr == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "threadAttr is null");
COMM_LOGE(COMM_ADAPTER, "threadAttr is null");
return SOFTBUS_INVALID_PARAM;
}
@ -176,7 +176,7 @@ static int32_t SoftbusSetThreadPolicy(SoftBusThreadAttr *threadAttr, pthread_att
} else if (threadAttr->policy == SOFTBUS_SCHED_RR) {
pthread_attr_setschedpolicy(attr, SCHED_RR);
} else {
HILOG_ERROR(SOFTBUS_HILOG_ID, "set policy error");
COMM_LOGE(COMM_ADAPTER, "set policy error");
return SOFTBUS_INVALID_PARAM;
}
@ -190,7 +190,7 @@ static int32_t SoftbusSetThreadDetachState(SoftBusThreadAttr *threadAttr, pthrea
} else if (threadAttr->detachState == SOFTBUS_THREAD_DETACH) {
pthread_attr_setdetachstate(attr, PTHREAD_CREATE_DETACHED);
} else {
HILOG_ERROR(SOFTBUS_HILOG_ID, "set detachState error");
COMM_LOGE(COMM_ADAPTER, "set detachState error");
return SOFTBUS_INVALID_PARAM;
}
@ -246,25 +246,25 @@ static int32_t SoftBusConfTransPthreadAttr(SoftBusThreadAttr *threadAttr, pthrea
{
int ret;
if ((threadAttr == NULL) || (attr == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "threadAttr or attr is null");
COMM_LOGE(COMM_ADAPTER, "threadAttr or attr is null");
return SOFTBUS_INVALID_PARAM;
}
ret = SoftbusSetThreadPolicy(threadAttr, attr);
if (ret != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftbusSetThreadPolicy failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftbusSetThreadPolicy failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
ret = SoftbusSetThreadDetachState(threadAttr, attr);
if (ret != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftbusSetThreadDetachState failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftbusSetThreadDetachState failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
ret = SoftbusSetThreadPeriority(threadAttr, attr);
if (ret != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftbusSetThreadPeriority failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftbusSetThreadPeriority failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
@ -272,7 +272,7 @@ static int32_t SoftBusConfTransPthreadAttr(SoftBusThreadAttr *threadAttr, pthrea
if (stackSize != 0) {
ret = pthread_attr_setstacksize(attr, stackSize);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "pthread_attr_setstacksize failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "pthread_attr_setstacksize failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
}
@ -284,12 +284,12 @@ int32_t SoftBusThreadCreate(SoftBusThread *thread, SoftBusThreadAttr *threadAttr
void *(*threadEntry) (void *), void *arg)
{
if (thread == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "thread is null");
COMM_LOGE(COMM_ADAPTER, "thread is null");
return SOFTBUS_INVALID_PARAM;
}
if (threadEntry == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "threadEntry is null");
COMM_LOGE(COMM_ADAPTER, "threadEntry is null");
return SOFTBUS_INVALID_PARAM;
}
@ -297,31 +297,31 @@ int32_t SoftBusThreadCreate(SoftBusThread *thread, SoftBusThreadAttr *threadAttr
if (threadAttr == NULL) {
ret = pthread_create((pthread_t *)thread, NULL, threadEntry, arg);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Thread create failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "Thread create failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
} else {
pthread_attr_t attr;
ret = pthread_attr_init(&attr);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "pthread_attr_init failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "pthread_attr_init failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
ret = SoftBusConfTransPthreadAttr(threadAttr, &attr);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusConfTransPthreadAttr failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusConfTransPthreadAttr failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
ret = pthread_create((pthread_t *)thread, &attr, threadEntry, arg);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Thread create failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "Thread create failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
if (threadAttr->taskName != NULL) {
ret = SoftBusThreadSetName(*thread, threadAttr->taskName);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Thread set name failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "Thread set name failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
}
@ -333,13 +333,13 @@ int32_t SoftBusThreadCreate(SoftBusThread *thread, SoftBusThreadAttr *threadAttr
int32_t SoftBusThreadJoin(SoftBusThread thread, void **value)
{
if (thread <= 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "thread is invalid");
COMM_LOGE(COMM_ADAPTER, "thread is invalid");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = pthread_join((pthread_t)thread, value);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Thread join failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "Thread join failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
@ -349,22 +349,22 @@ int32_t SoftBusThreadJoin(SoftBusThread thread, void **value)
int32_t SoftBusThreadSetName(SoftBusThread thread, const char *name)
{
if (thread <= 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "thread is invalid");
COMM_LOGE(COMM_ADAPTER, "thread is invalid");
return SOFTBUS_INVALID_PARAM;
}
if (name == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "name is null");
COMM_LOGE(COMM_ADAPTER, "name is null");
return SOFTBUS_INVALID_PARAM;
}
if (strlen(name) >= TASK_NAME_MAX_LEN) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "set thread name length >= TASK_NAME_MAX_LEN");
COMM_LOGE(COMM_ADAPTER, "set thread name length >= TASK_NAME_MAX_LEN");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = pthread_setname_np((pthread_t)thread, name);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Thread set name failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "Thread set name failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
@ -380,29 +380,29 @@ SoftBusThread SoftBusThreadGetSelf(void)
int32_t SoftBusCondInit(SoftBusCond *cond)
{
if (cond == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "cond is null");
COMM_LOGE(COMM_ADAPTER, "cond is null");
return SOFTBUS_INVALID_PARAM;
}
pthread_condattr_t attr = {0};
int ret = pthread_condattr_init(&attr);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "pthread_condattr_init failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "pthread_condattr_init failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
ret = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "set clock failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "set clock failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
pthread_cond_t *tempCond = (pthread_cond_t *)SoftBusCalloc(sizeof(pthread_cond_t));
if (tempCond == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "tempCond is null");
COMM_LOGE(COMM_ADAPTER, "tempCond is null");
return SOFTBUS_ERR;
}
ret = pthread_cond_init(tempCond, &attr);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusCondInit failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusCondInit failed, ret[%d]", ret);
SoftBusFree(tempCond);
tempCond = NULL;
return SOFTBUS_ERR;
@ -415,14 +415,14 @@ int32_t SoftBusCondInit(SoftBusCond *cond)
int32_t SoftBusCondSignal(SoftBusCond *cond)
{
if ((cond == NULL) || ((void *)(*cond) == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "cond is null");
COMM_LOGE(COMM_ADAPTER, "cond is null");
return SOFTBUS_INVALID_PARAM;
}
int ret;
ret = pthread_cond_signal((pthread_cond_t *)*cond);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusCondSignal failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusCondSignal failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
@ -432,14 +432,14 @@ int32_t SoftBusCondSignal(SoftBusCond *cond)
int32_t SoftBusCondBroadcast(SoftBusCond *cond)
{
if ((cond == NULL) || ((void *)(*cond) == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "cond is null");
COMM_LOGE(COMM_ADAPTER, "cond is null");
return SOFTBUS_INVALID_PARAM;
}
int ret;
ret = pthread_cond_broadcast((pthread_cond_t *)*cond);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusCondBroadcast failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusCondBroadcast failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
@ -450,12 +450,12 @@ int32_t SoftBusCondWait(SoftBusCond *cond, SoftBusMutex *mutex, SoftBusSysTime *
{
#define USECTONSEC 1000
if ((cond == NULL) || ((void *)(*cond) == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "cond is null");
COMM_LOGE(COMM_ADAPTER, "cond is null");
return SOFTBUS_INVALID_PARAM;
}
if ((mutex == NULL) || ((void *)(*mutex) == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "mutex is null");
COMM_LOGE(COMM_ADAPTER, "mutex is null");
return SOFTBUS_INVALID_PARAM;
}
@ -463,7 +463,7 @@ int32_t SoftBusCondWait(SoftBusCond *cond, SoftBusMutex *mutex, SoftBusSysTime *
if (time == NULL) {
ret = pthread_cond_wait((pthread_cond_t *)*cond, (pthread_mutex_t *)*mutex);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusCondWait failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusCondWait failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
} else {
@ -472,12 +472,12 @@ int32_t SoftBusCondWait(SoftBusCond *cond, SoftBusMutex *mutex, SoftBusSysTime *
tv.tv_nsec = time->usec * USECTONSEC;
ret = pthread_cond_timedwait((pthread_cond_t *)*cond, (pthread_mutex_t *)*mutex, &tv);
if (ret == ETIMEDOUT) {
HILOG_DEBUG(SOFTBUS_HILOG_ID, "SoftBusCondTimedWait timeout, ret[%{public}d]", ret);
COMM_LOGD(COMM_ADAPTER, "SoftBusCondTimedWait timeout, ret[%d]", ret);
return SOFTBUS_TIMOUT;
}
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusCondTimedWait failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusCondTimedWait failed, ret[%d]", ret);
return SOFTBUS_ERR;
}
}
@ -488,14 +488,14 @@ int32_t SoftBusCondWait(SoftBusCond *cond, SoftBusMutex *mutex, SoftBusSysTime *
int32_t SoftBusCondDestroy(SoftBusCond *cond)
{
if ((cond == NULL) || ((void *)(*cond) == NULL)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "cond is null");
COMM_LOGE(COMM_ADAPTER, "cond is null");
return SOFTBUS_INVALID_PARAM;
}
int ret;
ret = pthread_cond_destroy((pthread_cond_t *)*cond);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusCondDestroy failed, ret[%{public}d]", ret);
COMM_LOGE(COMM_ADAPTER, "SoftBusCondDestroy failed, ret[%d]", ret);
SoftBusFree((void *)*cond);
*cond = (SoftBusCond)NULL;
return SOFTBUS_ERR;

View File

@ -24,8 +24,8 @@
#include <time.h>
#include <unistd.h>
#include "comm_log.h"
#include "securec.h"
#include "softbus_adapter_log.h"
#include "softbus_adapter_socket.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
@ -54,7 +54,7 @@ void SetTimerFunc(TimerFunc func)
void *SoftBusCreateTimer(void **timerId, unsigned int type)
{
if (timerId == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "timerId is null");
COMM_LOGE(COMM_ADAPTER, "timerId is null");
return NULL;
}
struct sigevent envent;
@ -65,7 +65,7 @@ void *SoftBusCreateTimer(void **timerId, unsigned int type)
g_timerType = type;
if (timer_create(CLOCK_REALTIME, &envent, timerId) != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "timer create error, errno code: [%{public}d]", errno);
COMM_LOGE(COMM_ADAPTER, "timer create error, errno code: [%d]", errno);
return NULL;
}
@ -75,7 +75,7 @@ void *SoftBusCreateTimer(void **timerId, unsigned int type)
int SoftBusStartTimer(void *timerId, unsigned int tickets)
{
if (timerId == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "timerId is null");
COMM_LOGE(COMM_ADAPTER, "timerId is null");
return SOFTBUS_ERR;
}
struct itimerspec value;
@ -91,7 +91,7 @@ int SoftBusStartTimer(void *timerId, unsigned int tickets)
}
if (timer_settime(timerId, 0, &value, NULL) != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "timer start error, errno code: [%{public}d]", errno);
COMM_LOGE(COMM_ADAPTER, "timer start error, errno code: [%d]", errno);
return SOFTBUS_ERR;
}
@ -101,12 +101,12 @@ int SoftBusStartTimer(void *timerId, unsigned int tickets)
int SoftBusDeleteTimer(void *timerId)
{
if (timerId == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "timerId is null");
COMM_LOGE(COMM_ADAPTER, "timerId is null");
return SOFTBUS_ERR;
}
if (timer_delete(timerId) != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "timer delete err, errno code: [%{public}d]", errno);
COMM_LOGE(COMM_ADAPTER, "timer delete err, errno code: [%d]", errno);
return SOFTBUS_ERR;
}
@ -130,7 +130,7 @@ int SoftBusSleepMs(unsigned int ms)
int32_t SoftBusGetTime(SoftBusSysTime *sysTime)
{
if (sysTime == NULL) {
HILOG_INFO(SOFTBUS_HILOG_ID, "sysTime is null");
COMM_LOGI(COMM_ADAPTER, "sysTime is null");
return SOFTBUS_INVALID_PARAM;
}
struct timespec time = {0};
@ -147,7 +147,7 @@ uint64_t SoftBusGetSysTimeMs(void)
time.tv_sec = 0;
time.tv_usec = 0;
if (gettimeofday(&time, NULL) != 0) {
HILOG_INFO(SOFTBUS_HILOG_ID, "get sys time fail");
COMM_LOGI(COMM_ADAPTER, "get sys time fail");
return 0;
}
uint64_t ms = (uint64_t)time.tv_sec * MS_PER_SECOND + (uint64_t)time.tv_usec / US_PER_MSECOND;

View File

@ -17,6 +17,7 @@
#include <securec.h>
#include "comm_log.h"
#include "mbedtls/base64.h"
#include "mbedtls/cipher.h"
#include "mbedtls/ctr_drbg.h"
@ -25,7 +26,6 @@
#include "mbedtls/md.h"
#include "mbedtls/platform.h"
#include "softbus_adapter_file.h"
#include "softbus_adapter_log.h"
#include "softbus_errcode.h"
#ifndef MBEDTLS_CTR_DRBG_C
@ -79,7 +79,7 @@ static int32_t MbedAesGcmEncrypt(const AesGcmCipherKey *cipherkey, const unsigne
{
if ((cipherkey == NULL) || (plainText == NULL) || (plainTextSize == 0) || cipherText == NULL ||
(cipherTextLen < plainTextSize + OVERHEAD_LEN)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Encrypt invalid para\n");
COMM_LOGE(COMM_ADAPTER, "Encrypt invalid para\n");
return SOFTBUS_INVALID_PARAM;
}
@ -121,7 +121,7 @@ static int32_t MbedAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigne
{
if ((cipherkey == NULL) || (cipherText == NULL) || (cipherTextSize <= OVERHEAD_LEN) || plain == NULL ||
(plainLen < cipherTextSize - OVERHEAD_LEN)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Decrypt invalid para\n");
COMM_LOGE(COMM_ADAPTER, "Decrypt invalid para\n");
return SOFTBUS_INVALID_PARAM;
}
@ -130,7 +130,7 @@ static int32_t MbedAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigne
int32_t ret = mbedtls_gcm_setkey(&aesContext, MBEDTLS_CIPHER_ID_AES, cipherkey->key,
cipherkey->keyLen * KEY_BITS_UNIT);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Decrypt mbedtls_gcm_setkey fail\n");
COMM_LOGE(COMM_ADAPTER, "Decrypt mbedtls_gcm_setkey fail\n");
mbedtls_gcm_free(&aesContext);
return SOFTBUS_DECRYPT_ERR;
}
@ -139,7 +139,7 @@ static int32_t MbedAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigne
ret = mbedtls_gcm_auth_decrypt(&aesContext, cipherTextSize - OVERHEAD_LEN, cipherkey->iv,
GCM_IV_LEN, NULL, 0, cipherText + actualPlainLen + GCM_IV_LEN, TAG_LEN, cipherText + GCM_IV_LEN, plain);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] Decrypt mbedtls_gcm_auth_decrypt fail.[%d]\n", ret);
COMM_LOGE(COMM_ADAPTER, "[TRANS] Decrypt mbedtls_gcm_auth_decrypt fail.[%d]\n", ret);
mbedtls_gcm_free(&aesContext);
return SOFTBUS_DECRYPT_ERR;
}
@ -151,7 +151,7 @@ static int32_t MbedAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigne
static int32_t HandleError(mbedtls_cipher_context_t *ctx, const char *buf)
{
if (buf != NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%{public}s", buf);
COMM_LOGE(COMM_ADAPTER, "%s", buf);
}
if (ctx != NULL) {
mbedtls_cipher_free(ctx);
@ -222,7 +222,7 @@ int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
if (initFlag == false) {
if (SoftBusMutexInit(&g_randomLock, NULL) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusGenerateRandomArray init lock fail");
COMM_LOGE(COMM_ADAPTER, "SoftBusGenerateRandomArray init lock fail");
return SOFTBUS_LOCK_ERR;
}
mbedtls_ctr_drbg_init(&ctrDrbg);
@ -230,21 +230,21 @@ int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
ret = mbedtls_ctr_drbg_seed(&ctrDrbg, mbedtls_entropy_func, &entropy, NULL, 0);
if (ret != 0) {
SoftBusMutexUnlock(&g_randomLock);
HILOG_ERROR(SOFTBUS_HILOG_ID, "gen random seed error, ret[%d]", ret);
COMM_LOGE(COMM_ADAPTER, "gen random seed error, ret[%d]", ret);
return SOFTBUS_ERR;
}
initFlag = true;
}
if (SoftBusMutexLock(&g_randomLock) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusGenerateRandomArray lock fail");
COMM_LOGE(COMM_ADAPTER, "SoftBusGenerateRandomArray lock fail");
return SOFTBUS_LOCK_ERR;
}
ret = mbedtls_ctr_drbg_random(&ctrDrbg, randStr, len);
SoftBusMutexUnlock(&g_randomLock);
if (ret != 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "gen random error, ret[%d]", ret);
COMM_LOGE(COMM_ADAPTER, "gen random error, ret[%d]", ret);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
@ -253,7 +253,7 @@ int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
int32_t SoftBusGenerateSessionKey(char *key, uint32_t len)
{
if (SoftBusGenerateRandomArray((unsigned char *)key, len) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate sessionKey error.");
COMM_LOGE(COMM_ADAPTER, "generate sessionKey error.");
return SOFTBUS_ENCRYPT_ERR;
}
return SOFTBUS_OK;
@ -267,7 +267,7 @@ int32_t SoftBusEncryptData(AesGcmCipherKey *cipherKey, const unsigned char *inpu
}
if (SoftBusGenerateRandomArray(cipherKey->iv, sizeof(cipherKey->iv)) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate random iv error.");
COMM_LOGE(COMM_ADAPTER, "generate random iv error.");
return SOFTBUS_ENCRYPT_ERR;
}
uint32_t outLen = inLen + OVERHEAD_LEN;
@ -286,7 +286,7 @@ int32_t SoftBusEncryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned cha
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusGenerateRandomArray(cipherKey->iv, sizeof(cipherKey->iv)) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate random iv error.");
COMM_LOGE(COMM_ADAPTER, "generate random iv error.");
return SOFTBUS_ENCRYPT_ERR;
}
if (memcpy_s(cipherKey->iv, sizeof(int32_t), &seqNum, sizeof(int32_t)) != EOK) {
@ -309,7 +309,7 @@ int32_t SoftBusDecryptData(AesGcmCipherKey *cipherKey, const unsigned char *inpu
}
if (memcpy_s(cipherKey->iv, sizeof(cipherKey->iv), input, GCM_IV_LEN) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy iv failed.");
COMM_LOGE(COMM_ADAPTER, "copy iv failed.");
return SOFTBUS_ENCRYPT_ERR;
}
uint32_t outLen = inLen - OVERHEAD_LEN;
@ -332,13 +332,13 @@ uint32_t SoftBusCryptoRand(void)
{
int32_t fd = SoftBusOpenFile("/dev/urandom", SOFTBUS_O_RDONLY);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "CryptoRand open file fail");
COMM_LOGE(COMM_ADAPTER, "CryptoRand open file fail");
return 0;
}
uint32_t value = 0;
int32_t len = SoftBusReadFile(fd, &value, sizeof(uint32_t));
if (len < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "CryptoRand read file fail");
COMM_LOGE(COMM_ADAPTER, "CryptoRand read file fail");
SoftBusCloseFile(fd);
return 0;
}

View File

@ -18,13 +18,13 @@
#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_bt_common.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_thread.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_log_old.h"
#include "softbus_utils.h"
#define BT_UUID "43d4a49f-604d-45b5-9302-4ddbbfd538fd"
@ -69,9 +69,9 @@ static void OnBtStateChanged(int32_t listenerId, int32_t state)
return;
}
CLOGI("receive bt turn off event, start reset bt adapter state...");
DISC_LOGI(DISC_BLE, "receive bt turn off event, start reset bt adapter state...");
if (SoftBusMutexLock(&g_advLock) != 0) {
CLOGE("ATTENTION, try to get adv lock failed, something unexpected happened");
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++) {
@ -88,7 +88,7 @@ static void OnBtStateChanged(int32_t listenerId, int32_t state)
(void)SoftBusMutexUnlock(&g_advLock);
if (SoftBusMutexLock(&g_scanerLock) != 0) {
CLOGE("ATTENTION, try to get scan lock failed, something unexpected happened");
DISC_LOGE(DISC_BLE, "ATTENTION, try to get scan lock failed, something unexpected happened");
return;
}
for (int index = 0; index < SCAN_MAX_NUM; index++) {
@ -108,11 +108,11 @@ int BleGattLockInit(void)
return SOFTBUS_OK;
}
if (SoftBusMutexInit(&g_advLock, NULL) != SOFTBUS_OK) {
CLOGE("g_advLock init failed");
DISC_LOGE(DISC_BLE, "g_advLock init failed");
return SOFTBUS_ERR;
}
if (SoftBusMutexInit(&g_scanerLock, NULL) != SOFTBUS_OK) {
CLOGE("g_scanerLock init failed");
DISC_LOGE(DISC_BLE, "g_scanerLock init failed");
return SOFTBUS_ERR;
}
g_lockInit = true;
@ -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);
CLOGI("BLE Scan Filter id:%d [serviceData:%s, serviceDataMask:%s]",
DISC_LOGI(DISC_BLE, "BLE Scan Filter id:%d [serviceData:%s, serviceDataMask:%s]",
filterSize, serviceData, serviceDataMask);
SoftBusFree(serviceData);
SoftBusFree(serviceDataMask);
@ -335,7 +335,7 @@ static void ConvertScanResult(const BtScanResultData *src, SoftBusBleScanResult
dst->dataStatus = ConvertScanDataStatus(src->dataStatus);
dst->addrType = ConvertScanAddrType(src->addrType);
if (memcpy_s(dst->addr.addr, BT_ADDR_LEN, src->addr.addr, BT_ADDR_LEN) != EOK) {
CLOGE("ConvertScanResult memcpy addr fail");
DISC_LOGE(DISC_BLE, "ConvertScanResult memcpy addr fail");
return;
}
dst->primaryPhy = ConvertScanPhyType(src->primaryPhy);
@ -346,7 +346,7 @@ static void ConvertScanResult(const BtScanResultData *src, SoftBusBleScanResult
dst->periodicAdvInterval = src->periodicAdvInterval;
dst->directAddrType = ConvertScanAddrType(src->directAddrType);
if (memcpy_s(dst->directAddr.addr, BT_ADDR_LEN, src->directAddr.addr, BT_ADDR_LEN) != EOK) {
CLOGE("ConvertScanResult memcpy directAddr fail");
DISC_LOGE(DISC_BLE, "ConvertScanResult memcpy directAddr fail");
return;
}
dst->advLen = src->advLen;
@ -403,7 +403,7 @@ static void ConvertAdvParam(const SoftBusBleAdvParams *src, BleAdvParams *dst)
dst->ownAddrType = 0x00;
dst->peerAddrType = 0x00;
if (memcpy_s(dst->peerAddr.addr, BT_ADDR_LEN, src->peerAddr.addr, BT_ADDR_LEN) != EOK) {
CLOGE("ConvertAdvParam memcpy directAddr fail");
DISC_LOGE(DISC_BLE, "ConvertAdvParam memcpy directAddr fail");
return;
}
dst->channelMap = src->channelMap;
@ -423,7 +423,7 @@ static void WrapperAdvEnableCallback(int advId, int status)
advChannel->advCallback->AdvEnableCallback == NULL) {
continue;
}
CLOGI("WrapperAdvEnableCallback, inner-advId: %d, bt-advId: %d, "
DISC_LOGI(DISC_BLE, "WrapperAdvEnableCallback, inner-advId: %d, bt-advId: %d, "
"status: %d", index, advId, st);
if (st == SOFTBUS_BT_STATUS_SUCCESS) {
advChannel->isAdvertising = true;
@ -445,7 +445,7 @@ static void WrapperAdvDisableCallback(int advId, int status)
advChannel->advCallback->AdvDisableCallback == NULL) {
continue;
}
CLOGI("WrapperAdvDisableCallback, inner-advId: %d, bt-advId: %d, "
DISC_LOGI(DISC_BLE, "WrapperAdvDisableCallback, inner-advId: %d, bt-advId: %d, "
"status: %d", index, advId, st);
if (st == SOFTBUS_BT_STATUS_SUCCESS) {
advChannel->advId = -1;
@ -468,7 +468,7 @@ static void WrapperAdvDataCallback(int advId, int status)
advChannel->advCallback->AdvDataCallback == NULL) {
continue;
}
CLOGI("WrapperAdvDataCallback, inner-advId: %d, bt-advId: %d, "
DISC_LOGI(DISC_BLE, "WrapperAdvDataCallback, inner-advId: %d, bt-advId: %d, "
"status: %d", index, advId, st);
advChannel->advCallback->AdvDataCallback(index, st);
break;
@ -486,7 +486,7 @@ static void WrapperAdvUpdateCallback(int advId, int status)
advChannel->advCallback->AdvUpdateCallback == NULL) {
continue;
}
CLOGI("WrapperAdvUpdateCallback, inner-advId: %d, bt-advId: %d, "
DISC_LOGI(DISC_BLE, "WrapperAdvUpdateCallback, inner-advId: %d, bt-advId: %d, "
"status: %d", index, advId, st);
advChannel->advCallback->AdvUpdateCallback(index, st);
break;
@ -496,7 +496,7 @@ static void WrapperAdvUpdateCallback(int advId, int status)
static void WrapperSecurityRespondCallback(const BdAddr *bdAddr)
{
(void)bdAddr;
CLOGI("WrapperSecurityRespondCallback");
DISC_LOGI(DISC_BLE, "WrapperSecurityRespondCallback");
}
static void WrapperScanResultCallback(BtScanResultData *scanResultdata)
@ -584,7 +584,7 @@ static int RegisterBleGattCallback(int32_t *scannerId, bool isLpDeviceScan)
return SOFTBUS_OK;
}
if (BleRegisterScanCallbacks(&g_softbusBleScanCb, scannerId) != 0) {
CLOGE("SH register ble scan callback failed");
DISC_LOGE(DISC_BLE, "SH register ble scan callback failed");
return SOFTBUS_ERR;
}
g_scannerId = *scannerId;
@ -595,7 +595,7 @@ static int RegisterBleGattCallback(int32_t *scannerId, bool isLpDeviceScan)
return SOFTBUS_OK;
}
if (BleRegisterScanCallbacks(&g_softbusBleScanCb, scannerId) != 0) {
CLOGE("SH register sh scan callback failed");
DISC_LOGE(DISC_BLE, "SH register sh scan callback failed");
return SOFTBUS_ERR;
}
g_isLpDeviceRegCb = true;
@ -609,7 +609,7 @@ static bool CheckAdvChannelInUsed(int advId)
return false;
}
if (!g_advChannel[advId].isUsed) {
CLOGE("advId %d is ready released", advId);
DISC_LOGE(DISC_BLE, "advId %d is ready released", advId);
return false;
}
return true;
@ -621,7 +621,7 @@ static bool CheckScanChannelInUsed(int listenerId)
return false;
}
if (!g_scanListener[listenerId].isUsed) {
CLOGE("listenerId %d is ready released", listenerId);
DISC_LOGE(DISC_BLE, "listenerId %d is ready released", listenerId);
return false;
}
return true;
@ -639,12 +639,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) {
CLOGE("SetAdvData calloc advData failed");
DISC_LOGE(DISC_BLE, "SetAdvData calloc advData failed");
return SOFTBUS_MALLOC_ERR;
}
if (memcpy_s(g_advChannel[advId].advData.advData, data->advLength,
data->advData, data->advLength) != EOK) {
CLOGE("SetAdvData memcpy advData failed");
DISC_LOGE(DISC_BLE, "SetAdvData memcpy advData failed");
SoftBusFree(g_advChannel[advId].advData.advData);
g_advChannel[advId].advData.advData = NULL;
return SOFTBUS_MEM_ERR;
@ -653,14 +653,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) {
CLOGE("SetAdvData calloc scanRspData failed");
DISC_LOGE(DISC_BLE, "SetAdvData 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) {
CLOGE("SetAdvData memcpy scanRspData failed");
DISC_LOGE(DISC_BLE, "SetAdvData memcpy scanRspData failed");
SoftBusFree(g_advChannel[advId].advData.advData);
SoftBusFree(g_advChannel[advId].advData.scanRspData);
g_advChannel[advId].advData.advData = NULL;
@ -700,7 +700,7 @@ int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, boo
}
}
if (freeAdvId == ADV_MAX_NUM) {
CLOGE("no available adv channel");
DISC_LOGE(DISC_BLE, "no available adv channel");
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
@ -763,7 +763,7 @@ static int OhosBleStartAdvEx(int *advId, const SoftBusBleAdvParams *param, const
ConvertAdvData(data, &advData);
int ret = BleStartAdvEx(&btAdvId, advData, dstParam);
if (ret != OHOS_BT_STATUS_SUCCESS) {
CLOGE("BleStartAdvEx, bt-advId: %d, ret: %d", btAdvId, ret);
DISC_LOGE(DISC_BLE, "BleStartAdvEx, bt-advId: %d, ret: %d", btAdvId, ret);
return SOFTBUS_ERR;
}
*advId = btAdvId;
@ -789,29 +789,29 @@ int SoftBusStartAdvEx(int advId, const SoftBusBleAdvParams *param,
return SOFTBUS_ERR;
}
if (g_advChannel[advId].isAdvertising) {
CLOGW("SoftBusStartAdv, wait condition inner-advId: %d", advId);
DISC_LOGW(DISC_BLE, "SoftBusStartAdv, wait condition inner-advId: %d", advId);
SoftBusSysTime absTime = {0};
if (SoftBusGetTime(&absTime) != SOFTBUS_OK) {
CLOGE("Softbus get time failed");
DISC_LOGE(DISC_BLE, "Softbus get time failed");
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
absTime.sec += ADV_WAIT_TIME_SEC;
if (SoftBusCondWait(&g_advChannel[advId].cond, &g_advLock, &absTime) != SOFTBUS_OK) {
CLOGE("SoftBusStartAdv, wait timeout");
DISC_LOGE(DISC_BLE, "SoftBusStartAdv, wait timeout");
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
}
if (g_advChannel[advId].advId != -1) {
CLOGE("already assigned an advId %d", g_advChannel[advId].advId);
DISC_LOGE(DISC_BLE, "already assigned an advId %d", g_advChannel[advId].advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_ERR;
}
int ret = startAdvEx(&g_advChannel[advId].advId, param, &g_advChannel[advId].advData);
CLOGI("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 != SOFTBUS_OK) {
g_advChannel[advId].advCallback->AdvEnableCallback(advId, SOFTBUS_BT_STATUS_FAIL);
SoftBusMutexUnlock(&g_advLock);
@ -831,12 +831,12 @@ int SoftBusStopAdv(int advId)
return SOFTBUS_ERR;
}
if (!g_advChannel[advId].isAdvertising) {
CLOGI("SoftBusStopAdv, adv %d is not advertising", advId);
DISC_LOGI(DISC_BLE, "SoftBusStopAdv, adv %d is not advertising", advId);
SoftBusMutexUnlock(&g_advLock);
return SOFTBUS_OK;
}
int ret = BleStopAdv(g_advChannel[advId].advId);
CLOGI("SoftBusStopAdv, inner-advId: %d, "
DISC_LOGI(DISC_BLE, "SoftBusStopAdv, 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);
@ -943,7 +943,7 @@ static bool CheckNeedReStartScan(int scannerId)
}
if (isNeedReset && isScanning) {
if (BleOhosStatusToSoftBus(BleStopScan(scannerId)) != SOFTBUS_BT_STATUS_SUCCESS) {
CLOGE("ble stop scan failed");
DISC_LOGE(DISC_BLE, "ble stop scan failed");
return false;
}
return true;
@ -976,7 +976,7 @@ int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter *filter, uint8_t f
return SOFTBUS_LOCK_ERR;
}
if (!CheckScanChannelInUsed(listenerId)) {
CLOGE("ScanListener id:%d is not in use", listenerId);
DISC_LOGE(DISC_BLE, "ScanListener id:%d is not in use", listenerId);
SoftBusMutexUnlock(&g_scanerLock);
return SOFTBUS_ERR;
}
@ -997,7 +997,7 @@ int SoftBusStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *
return SOFTBUS_LOCK_ERR;
}
if (!CheckScanChannelInUsed(listenerId)) {
CLOGE("ScanListener id:%d is not in use", listenerId);
DISC_LOGE(DISC_BLE, "ScanListener id:%d is not in use", listenerId);
SoftBusMutexUnlock(&g_scanerLock);
return SOFTBUS_ERR;
}
@ -1079,17 +1079,17 @@ int SoftBusReplaceAdvertisingAdv(int advId, const SoftBusBleAdvData *data)
}
if (!g_advChannel[advId].isAdvertising) {
SoftBusMutexUnlock(&g_advLock);
CLOGE("adv %d is not advertising", advId);
DISC_LOGE(DISC_BLE, "adv %d is not advertising", advId);
return SOFTBUS_ERR;
}
int btAdvId = g_advChannel[advId].advId;
int ret = SetAdvData(advId, data);
SoftBusMutexUnlock(&g_advLock);
if (ret != SOFTBUS_OK) {
CLOGE("SetAdvData failed, advId: %d, btadvId: %d", advId, btAdvId);
DISC_LOGE(DISC_BLE, "SetAdvData failed, advId: %d, btadvId: %d", advId, btAdvId);
return SOFTBUS_ERR;
}
CLOGI("BleSetAdvData, advId: %d, btadvId: %d", advId, btAdvId);
DISC_LOGI(DISC_BLE, "BleSetAdvData, advId: %d, btadvId: %d", advId, btAdvId);
StartAdvRawData advData = {0};
ConvertAdvData(data, &advData);
ret = BleOhosStatusToSoftBus(BleSetAdvData(btAdvId, advData));
@ -1130,7 +1130,7 @@ bool SoftBusSetAdvFilterParam(int advHandle, int advId, SoftBusBleAdvParams *adv
btLpDeviceParam.advHandle = advHandle;
btLpDeviceParam.duration = ADV_DURATION_MS;
if (SetLpDeviceParam(&btLpDeviceParam) != SOFTBUS_OK) {
CLOGE("SH SetLpDeviceParam failed");
DISC_LOGE(DISC_BLE, "SH SetLpDeviceParam failed");
return false;
}
SoftBusFree(filter);

View File

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

View File

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

View File

@ -17,14 +17,15 @@
* @file softbus_ble_gatt.h
* @brief ble stack adapter
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
#ifndef SOFTBUS_BLE_GATT_H
#define SOFTBUS_BLE_GATT_H
#include "softbus_broadcast_adapter.h"
#include "softbus_broadcast_adapter_interface.h"
#include "softbus_broadcast_adapter_type.h"
#ifdef __cplusplus
extern "C"{

View File

@ -17,7 +17,7 @@
* @file softbus_broadcast_adapter_interface.h
* @brief Different broadcast protocol stacks adapt layer interfaces
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
@ -30,10 +30,12 @@
extern "C"{
#endif
#define MEDIUM_MAX_NUM 2
/**
* @brief Defines the broadcast callback function.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -46,56 +48,51 @@ typedef struct {
/**
* @brief Defines the broadcast scan callback function.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
void (*OnStartScanCallback)(int32_t scanId, int32_t status);
void (*OnStopScanCallback)(int32_t scanId, int32_t status);
void (*OnReportScanDataCallback)(int32_t scanId, const SoftBusBleScanResult *reportData);
void (*OnReportScanDataCallback)(const SoftBusBcScanResult *reportData);
} SoftbusScanCallback;
/**
* @brief Defines Different broadcast protocol stacks adapt layer interfaces
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
struct SoftbusBroadcastMediumInterface {
int32_t (*InitBroadcast)(void);
int32_t (*DeInitBroadcast)(void);
typedef struct{
int32_t (*Init)(void);
int32_t (*DeInit)(void);
int32_t (*RegisterBroadcaster)(int32_t *advId, const SoftbusBroadcastCallback *cb);
int32_t (*UnRegisterBroadcaster)(int32_t advId);
int32_t (*RegisterScanListener)(int32_t *scanerId, const SoftbusScanCallback *cb);
int32_t (*UnRegisterScanListener)(int32_t scanerId);
int32_t (*RegisterScanListener)(int32_t *scannerId, const SoftbusScanCallback *cb);
int32_t (*UnRegisterScanListener)(int32_t scannerId);
int32_t (*StartBroadcasting)(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *bcData,
const SoftbusBroadcastData *rspData);
int32_t (*UpdateBroadcasting)(int32_t advId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *bcData,
const SoftbusBroadcastData *rspData);
int32_t (*StopBroadcasting)(int32_t advId);
int32_t (*StartScan)(int32_t scanerId, const SoftBusBcScanParams *param);
int32_t (*StopScan)(int32_t scanerId);
int32_t (*SetScanFilter)(int32_t scanerId, const SoftBusBcScanFilter *scanFilter, uint8_t filterSize);
int32_t (*GetScanFilter)(int32_t scanerId, const SoftBusBcScanFilter *scanFilter, uint8_t *filterSize);
int32_t (*QueryBroadcastStatus)(int32_t advId, int32_t *status);
};
int32_t (*StartScan)(int32_t scannerId, const SoftBusBcScanParams *param, const SoftBusBcScanFilter *scanFilter,
uint8_t filterSize);
int32_t (*StopScan)(int32_t scannerId);
} SoftbusBroadcastMediumInterface;
/**
* @brief Defines interface functions for registering different media
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t RegisterBroadcastMediumFunction(SoftbusMediumType type, const SoftbusBroadcastMediumInterface *interface);
int32_t RegisterBroadcastMediumFunction(enum SoftbusMediumType type,
const struct SoftbusBroadcastMediumInterface *interface);
/**
* @brief Defines interface functions for unregistering different media
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t UnRegisterBroadcastMediumFunction(enum SoftbusMediumType type);
int32_t UnRegisterBroadcastMediumFunction(SoftbusMediumType type);
#ifdef __cplusplus
}

View File

@ -17,7 +17,7 @@
* @file softbus_broadcast_adapter_type.h
* @brief Declare functions and constants for the soft bus broadcast adaptation
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
@ -33,7 +33,7 @@ extern "C"{
/**
* @brief Defines mac address length
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
#define SOFTBUS_ADDR_MAC_LEN 6
@ -41,37 +41,30 @@ extern "C"{
/**
* @brief Defines different broadcast media protocol stacks
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
enum SoftbusMediumType {
typedef enum {
BROADCAST_MEDIUM_TYPE_BLE,
BROADCAST_MEDIUM_TYPE_SLE,
BROADCAST_MEDIUM_TYPE_BUTT,
};
} SoftbusMediumType;
/**
* @brief Defines the broadcast data information
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
uint16_t uuidLen;
uint16_t serviceLen;
uint8_t *uuid;
uint8_t *serviceData;
uint16_t companyId;
uint16_t manufacturerDataLen;
uint8_t *manufacturerData;
uint8_t flag;
uint8_t rsv[3]; // Reserved
uint16_t rawDataLen;
uint8_t *rawData;
} SoftbusBroadcastData;
/**
* @brief Defines mac address information
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -81,7 +74,7 @@ typedef struct {
/**
* @brief Defines the device information returned by <b>SoftbusBroadcastCallback</b>.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -95,12 +88,12 @@ typedef struct {
uint8_t addrType;
SoftbusMacAddr addr;
SoftbusBroadcastData data;
} SoftBusBleScanResult;
} SoftBusBcScanResult;
/**
* @brief Defines the broadcast parameters
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -119,7 +112,7 @@ typedef struct {
/**
* @brief Defines broadcast scan filters
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -140,7 +133,7 @@ typedef struct {
/**
* @brief Defines broadcast scan parameters
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {

View File

@ -17,7 +17,7 @@
* @file softbus_broadcast_manager.h
* @brief
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
@ -33,7 +33,7 @@ extern "C"{
/**
* @brief Defines the broadcast callback function.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -46,7 +46,7 @@ typedef struct {
/**
* @brief Defines the broadcast scan callback function.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -60,7 +60,7 @@ typedef struct {
*
* @return Returns <b>0</b> If the broadcast management initialization fails;
* returns any other value if the request fails.
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t InitBroadcastMgr(void);
@ -70,7 +70,7 @@ int32_t InitBroadcastMgr(void);
*
* @return Returns <b>SOFTBUS_OK</b> If the broadcast management deinitialization fails;
* returns any other value if the request fails.
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t DeInitBroadcastMgr(void);
@ -85,10 +85,10 @@ int32_t DeInitBroadcastMgr(void);
* @return Returns <b>SOFTBUS_OK</b> if the service register is successful.
* returns any other value if the register fails.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t RegisterBroadcaster(enum BaseServiceType type, int32_t *bcId, const BroadcastCallback *cb);
int32_t RegisterBroadcaster(BaseServiceType type, int32_t *bcId, const BroadcastCallback *cb);
/**
* @brief UnRegister the service to the broadcast manager.
@ -98,7 +98,7 @@ int32_t RegisterBroadcaster(enum BaseServiceType type, int32_t *bcId, const Broa
* @return Returns <b>SOFTBUS_OK</b> if the service unregister is successful.
* returns any other value if the unregister fails.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t UnRegisterBroadcaster(int32_t bcId);
@ -113,10 +113,10 @@ int32_t UnRegisterBroadcaster(int32_t bcId);
* @return Returns <b>SOFTBUS_OK</b> if the service register is successful.
* returns any other value if the register fails.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t RegisterScanListener(enum BaseServiceType type, int32_t *listenerId, const ScanCallback *cb);
int32_t RegisterScanListener(BaseServiceType type, int32_t *listenerId, const ScanCallback *cb);
/**
* @brief UnRegister the service listener to the broadcast manager.
@ -126,7 +126,7 @@ int32_t RegisterScanListener(enum BaseServiceType type, int32_t *listenerId, con
* @return Returns <b>SOFTBUS_OK</b> if the service unregister is successful.
* returns any other value if the unregister fails.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t UnRegisterScanListener(int32_t listenerId);
@ -142,11 +142,11 @@ int32_t UnRegisterScanListener(int32_t listenerId);
* @return Returns <b>SOFTBUS_OK</b> if the service starts the broadcast successfully.
* returns any other value if the unregister fails.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t StartBroadcasting(int32_t bcId, const BroadcastParam *param, const BroadcastData *bcData,
const BroadcastData *rspData);
int32_t StartBroadcasting(int32_t bcId, const BroadcastParam *param, const BroadcastPayload *bcData,
const BroadcastPayload *rspData);
/**
* @brief The service update broadcast data and parameters.
@ -159,11 +159,11 @@ int32_t StartBroadcasting(int32_t bcId, const BroadcastParam *param, const Broad
* @return Returns <b>SOFTBUS_OK</b> if the service updates the broadcast successfully.
* returns any other value if the service fails to update the broadcast.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t UpdateBroadcasting(int32_t bcId, const BroadcastParam *param, const BroadcastData *bcData,
const BroadcastData *rspData);
int32_t UpdateBroadcasting(int32_t bcId, const BroadcastParam *param, const BroadcastPayload *bcData,
const BroadcastPayload *rspData);
/**
* @brief The service stop broadcast
@ -173,7 +173,7 @@ int32_t UpdateBroadcasting(int32_t bcId, const BroadcastParam *param, const Broa
* @return Returns <b>SOFTBUS_OK</b> if the service stop the broadcast successfully.
* returns any other value if the service fails to stop the broadcast.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t StopBroadcasting(int32_t bcId);
@ -187,7 +187,7 @@ int32_t StopBroadcasting(int32_t bcId);
* @return Returns <b>SOFTBUS_OK</b> if the service start to scan the broadcast successfully.
* returns any other value if the service fails to scan the broadcast.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t StartScan(int32_t listenerId, const BcScanParams *param);
@ -200,7 +200,7 @@ int32_t StartScan(int32_t listenerId, const BcScanParams *param);
* @return Returns <b>SOFTBUS_OK</b> if the service stop to scan the broadcast successfully.
* returns any other value if the service fails to stop scanning the broadcast.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t StopScan(int32_t listenerId);
@ -215,7 +215,7 @@ int32_t StopScan(int32_t listenerId);
* @return Returns <b>SOFTBUS_OK</b> if the service set the Scan Filter successfully.
* returns any other value if the service fails to set the Scan Filter.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t SetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t filterNum);
@ -230,7 +230,7 @@ int32_t SetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_
* @return Returns <b>SOFTBUS_OK</b> if the service get the Scan Filter successfully.
* returns any other value if the service fails to get the Scan Filter.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_t *filterNum);
@ -244,11 +244,15 @@ int32_t GetScanFilter(int32_t listenerId, const BcScanFilter *scanFilter, uint8_
* @return Returns <b>SOFTBUS_OK</b> if the service query status successfully.
* returns any other value if the service fails to query status.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t QueryBroadcastStatus(int32_t bcId, int32_t *status);
void SetBroadcastAdvFlag();
uint8_t GetBroadcastFlag();
#ifdef __cplusplus
}
#endif

View File

@ -17,7 +17,7 @@
* @file softbus_broadcast_type.h
* @brief Declare constants for the softbus broadcast.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
@ -33,18 +33,27 @@ extern "C"{
/**
* @brief Defines mac address length
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
#define BC_ADDR_MAC_LEN 6
// Bluetooth scan duty cycle, unit: ms
#define SOFTBUS_BC_SCAN_INTERVAL_P2 3000
#define SOFTBUS_BC_SCAN_INTERVAL_P10 600
#define SOFTBUS_BC_SCAN_INTERVAL_P25 240
#define SOFTBUS_BC_SCAN_INTERVAL_P100 1000
#define SOFTBUS_BC_SCAN_WINDOW_P2 60
#define SOFTBUS_BC_SCAN_WINDOW_P10 60
#define SOFTBUS_BC_SCAN_WINDOW_P25 60
#define SOFTBUS_BC_SCAN_WINDOW_P100 1000
/**
* @brief Defines the broadcast service type.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
enum BaseServiceType {
typedef enum {
SRV_TYPE_HB, // The service type is heart beat.
SRV_TYPE_CONN, // The service type is connection.
SRV_TYPE_TRANS_MSG, // The service type is transmission message.
@ -52,30 +61,114 @@ enum BaseServiceType {
SRV_TYPE_SHARE, // The service type is share discovery.
SRV_TYPE_APPROACH, // The service type is approach discovery.
SRV_TYPE_BUTT,
};
} BaseServiceType;
typedef enum {
SOFTBUS_BC_STATUS_SUCCESS = 0x00,
SOFTBUS_BC_STATUS_FAIL,
SOFTBUS_BC_STATUS_NOT_READY,
SOFTBUS_BC_STATUS_NOMEM,
SOFTBUS_BC_STATUS_BUSY,
SOFTBUS_BC_STATUS_DONE,
SOFTBUS_BC_STATUS_UNSUPPORTED,
SOFTBUS_BC_STATUS_PARM_INVALID,
SOFTBUS_BC_STATUS_UNHANDLED,
SOFTBUS_BC_STATUS_AUTH_FAILURE,
SOFTBUS_BC_STATUS_RMT_DEV_DOWN,
SOFTBUS_BC_STATUS_AUTH_REJECTED
} SoftBusBcStatus;
typedef enum {
SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00,
SOFTBUS_BC_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04,
SOFTBUS_BC_EVT_CONNECTABLE = 0x01,
SOFTBUS_BC_EVT_CONNECTABLE_DIRECTED = 0x05,
SOFTBUS_BC_EVT_SCANNABLE = 0x02,
SOFTBUS_BC_EVT_SCANNABLE_DIRECTED = 0x06,
SOFTBUS_BC_EVT_LEGACY_NON_CONNECTABLE = 0x10,
SOFTBUS_BC_EVT_LEGACY_SCANNABLE = 0x12,
SOFTBUS_BC_EVT_LEGACY_CONNECTABLE = 0x13,
SOFTBUS_BC_EVT_LEGACY_CONNECTABLE_DIRECTED = 0x15,
SOFTBUS_BC_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN = 0x1A,
SOFTBUS_BC_EVT_LEGACY_SCAN_RSP_TO_ADV = 0x1B
} SoftBusBcScanResultEvtType;
typedef enum {
SOFTBUS_BC_PUBLIC_DEVICE_ADDRESS = 0x00,
SOFTBUS_BC_RANDOM_DEVICE_ADDRESS = 0x01,
SOFTBUS_BC_PUBLIC_IDENTITY_ADDRESS = 0x02,
SOFTBUS_BC_RANDOM_STATIC_IDENTITY_ADDRESS = 0x03,
SOFTBUS_BC_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS = 0xFE,
SOFTBUS_BC_NO_ADDRESS = 0xFF,
} SoftBusBcScanResultAddrType;
typedef enum {
SOFTBUS_BC_SCAN_TYPE_PASSIVE = 0x00,
SOFTBUS_BC_SCAN_TYPE_ACTIVE,
} SoftBusBcScanType;
typedef enum {
SOFTBUS_BC_SCAN_PHY_NO_PACKET = 0x00,
SOFTBUS_BC_SCAN_PHY_1M = 0x01,
SOFTBUS_BC_SCAN_PHY_2M = 0x02,
SOFTBUS_BC_SCAN_PHY_CODED = 0x03
} SoftBusBcScanResultPhyType;
typedef enum {
SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL = 0x00,
SOFTBUS_BC_SCAN_FILTER_POLICY_ONLY_WHITE_LIST,
SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL_AND_RPA,
SOFTBUS_BC_SCAN_FILTER_POLICY_ONLY_WHITE_LIST_AND_RPA
} SoftBusBcScanFilterPolicy;
typedef enum {
SOFTBUS_BC_ADV_IND = 0x00,
SOFTBUS_BC_ADV_DIRECT_IND_HIGH = 0x01,
SOFTBUS_BC_ADV_SCAN_IND = 0x02,
SOFTBUS_BC_ADV_NONCONN_IND = 0x03,
SOFTBUS_BC_ADV_DIRECT_IND_LOW = 0x04,
} SoftBusBcAdvType;
typedef enum {
SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00,
SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY = 0x01,
SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST = 0x02,
SOFTBUS_BC_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST = 0x03,
} SoftBusBcAdvFilter;
typedef enum {
SOFTBUS_BC_DATA_COMPLETE = 0x00,
SOFTBUS_BC_DATA_INCOMPLETE_MORE_TO_COME = 0x01,
SOFTBUS_BC_DATA_INCOMPLETE_TRUNCATED = 0x02,
} SoftBusScanResultDataStatus;
typedef enum {
SOFTBUS_BC_BT_STATE_TURNING_ON = 0x0,
SOFTBUS_BC_BT_STATE_TURN_ON,
SOFTBUS_BC_BT_STATE_TURNING_OFF,
SOFTBUS_BC_BT_STATE_TURN_OFF,
SOFTBUS_BC_BR_STATE_TURNING_ON,
SOFTBUS_BC_BR_STATE_TURN_ON,
SOFTBUS_BC_BR_STATE_TURNING_OFF,
SOFTBUS_BC_BR_STATE_TURN_OFF
} SoftBusBcStackState;
/**
* @brief Defines the broadcast data information
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
uint16_t uuidLen;
uint16_t serviceLen;
uint8_t *uuid;
uint8_t *serviceData;
uint16_t uuid;
uint16_t companyId;
uint16_t manufacturerDataLen;
uint8_t *manufacturerData;
uint8_t flag;
uint8_t rsv[3]; // Reserved
} BroadcastData;
uint16_t payloadLen;
uint8_t *payload; // if pointer defines rsp payload, pointer may be null
} BroadcastPayload;
/**
* @brief Defines mac address information
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -85,7 +178,7 @@ typedef struct {
/**
* @brief Defines the device information returned by <b>SoftbusBroadcastCallback</b>.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -98,13 +191,14 @@ typedef struct {
int8_t rssi;
uint8_t addrType;
BcMacAddr addr;
BroadcastData data;
BroadcastPayload bcData;
BroadcastPayload rspData;
} BroadcastReportInfo;
/**
* @brief Defines the broadcast parameters
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -123,15 +217,15 @@ typedef struct {
/**
* @brief Defines broadcast scan filters
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
int8_t *address;
int8_t *deviceName;
uint32_t serviceUuidLength;
uint8_t *serviceUuid;
uint8_t *serviceUuidMask;
uint32_t serviceUuidLength; // reserve
uint8_t *serviceUuid; // reserve
uint8_t *serviceUuidMask; // reserve
uint32_t serviceDataLength;
uint8_t *serviceData;
uint8_t *serviceDataMask;
@ -144,7 +238,7 @@ typedef struct {
/**
* @brief Defines broadcast scan parameters
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {

View File

@ -17,7 +17,7 @@
* @file softbus_broadcast_utils.h
* @brief Declare functions and constants for the softbus broadcast or scan data fill or parse common functions.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
@ -30,13 +30,54 @@
extern "C"{
#endif
#define MEDIUM_NUM_MAX 2
// max broadcasting and scan limit
#define BC_NUM_MAX 9
#define SCAN_NUM_MAX 9
#define BC_DATA_MAX_LEN 24
#define RSP_DATA_MAX_LEN 27
#define BC_BYTE_MASK 0xFF
#define BC_SHIFT_BIT 8
// adv broadcast head
#define BC_HEAD_LEN 7
#define IDX_BC_FLAG_BYTE_LEN 0
#define IDX_BC_FLAG_AD_TYPE 1
#define IDX_BC_FLAG_AD_DATA 2
#define IDX_PACKET_LEN 3
#define IDX_BC_TYPE 4
#define IDX_BC_UUID 5
#define BC_UUID_LEN 2
#define BC_FLAG_BYTE_LEN 0x2
#define BC_FLAG_AD_TYPE 0x1
#define BC_FLAG_AD_DATA 0x2
// broadcast type
#define SERVICE_BC_TYPE 0x16
#define MANUFACTURE_BC_TYPE 0xFF
// scan rsp head
#define RSP_HEAD_LEN 4
#define IDX_RSP_PACKET_LEN 0
#define IDX_RSP_TYPE 1
#define IDX_RSP_UUID 2
#define RSP_UUID_LEN 2
#define RSP_FLAG_BYTE_LEN 0x2
#define RSP_FLAG_AD_TYPE 0x1
#define RSP_FLAG_AD_DATA 0x2
/**
* @brief Defines the format of broadcast TLV data
*
* DATA_FORMAT_TL_1BYTE indicates BcTlvDataFormatThe TLV format is 4 bits for T and 4 bits for L
* DATA_FORMAT_TL_2BYTE indicates BcTlvDataFormatThe TLV format is 1 byte for T and 1 byte for L
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
enum BcTlvDataFormat {
@ -47,7 +88,7 @@ enum BcTlvDataFormat {
/**
* @brief Defines the broadcast TLV data
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
typedef struct {
@ -68,7 +109,7 @@ typedef struct {
* @return Returns <b>SOFTBUS_OK</b> if the service gets service data successful.
* returns any other value if the service fails to get service data.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetServiceAdvData(uint16_t uuid, uint8_t **advPosPtr, uint32_t *advLen,
@ -86,7 +127,7 @@ int32_t GetServiceAdvData(uint16_t uuid, uint8_t **advPosPtr, uint32_t *advLen,
* @return Returns <b>SOFTBUS_OK</b> if the service gets respond service data successful.
* returns any other value if the service fails to get respond service data.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetServiceRspData(uint16_t uuid, uint8_t **rspPosPtr, uint32_t *rspLen,
@ -104,7 +145,7 @@ int32_t GetServiceRspData(uint16_t uuid, uint8_t **rspPosPtr, uint32_t *rspLen,
* @return Returns <b>SOFTBUS_OK</b> if the service gets manufacturer data successful.
* returns any other value if the service fails to get manufacturer data.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetManufacturerAdvData(uint16_t companyId, uint8_t **advPosPtr, uint32_t *advLen, const uint8_t *rawData,
@ -122,7 +163,7 @@ int32_t GetManufacturerAdvData(uint16_t companyId, uint8_t **advPosPtr, uint32_t
* @return Returns <b>SOFTBUS_OK</b> if the service gets respond manufacturer data successful.
* returns any other value if the service fails to get respond manufacturer data.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetManufacturerRspData(uint16_t companyId, uint8_t **rspPosPtr, uint32_t *rspLen, const uint8_t *rawData,
@ -139,7 +180,7 @@ int32_t GetManufacturerRspData(uint16_t companyId, uint8_t **rspPosPtr, uint32_t
* @return Returns <b>SOFTBUS_OK</b> if the service gets local name successful.
* returns any other value if the service fails to get local name.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetLocalNameData(uint8_t *localName, uint32_t *len, const uint8_t *rawData, uint32_t dataLen);
@ -154,7 +195,7 @@ int32_t GetLocalNameData(uint8_t *localName, uint32_t *len, const uint8_t *rawDa
* @return Returns <b>SOFTBUS_OK</b> if the service gets flag successful.
* returns any other value if the service fails to get flag.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetBcFlag(uint8_t *flag, const uint8_t *rawData, uint32_t dataLen);
@ -169,7 +210,7 @@ int32_t GetBcFlag(uint8_t *flag, const uint8_t *rawData, uint32_t dataLen);
* @return Returns <b>SOFTBUS_OK</b> if the service gets uuid successful.
* returns any other value if the service fails to get uuid.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetServiceUuid(uint16_t *uuid, const uint8_t *rawData, uint32_t dataLen);
@ -184,7 +225,7 @@ int32_t GetServiceUuid(uint16_t *uuid, const uint8_t *rawData, uint32_t dataLen)
* @return Returns <b>SOFTBUS_OK</b> if the service gets companyId successful.
* returns any other value if the service fails to get companyId.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t GetManufacturerId(uint16_t *companyId, const uint8_t *rawData, uint32_t dataLen);
@ -198,7 +239,7 @@ int32_t GetManufacturerId(uint16_t *companyId, const uint8_t *rawData, uint32_t
* @return true
* @return false
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
bool IsServiceData(const uint8_t *rawData, uint32_t dataLen);
@ -213,7 +254,7 @@ bool IsServiceData(const uint8_t *rawData, uint32_t dataLen);
* @return Returns <b>SOFTBUS_OK</b> if the TLV packet assemble successful.
* returns any other value if the TLV packet fails to assemble.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t AssembleTlvPkg(enum BcTlvDataFormat, uint8_t *bcData, uint32_t dataLen, const BcTlv *tlv);
@ -228,7 +269,7 @@ int32_t AssembleTlvPkg(enum BcTlvDataFormat, uint8_t *bcData, uint32_t dataLen,
* @return Returns <b>SOFTBUS_OK</b> if the TLV packet parse successful.
* returns any other value if the TLV packet fails to parse.
*
* @since 1.0
* @since 4.1
* @version 1.0
*/
int32_t ParseTlvPkg(enum BcTlvDataFormat, const uint8_t *bcData, uint32_t dataLen, BcTlv *tlv);

View File

@ -20,11 +20,11 @@
#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"
#include "softbus_log_old.h"
#define STATE_LISTENER_MAX_NUM 18
#define BR_STATE_CB_TRANSPORT 1
@ -71,7 +71,7 @@ static SoftBusBtAddr ConvertBtAddr(const BdAddr *bdAddr)
{
SoftBusBtAddr btAddr = {0};
if (memcpy_s(btAddr.addr, sizeof(btAddr.addr), bdAddr->addr, sizeof(bdAddr->addr)) != EOK) {
CLOGE("copy bdAddr fail");
COMM_LOGE(COMM_ADAPTER, "copy bdAddr fail");
}
return btAddr;
}
@ -92,7 +92,7 @@ static void SoftBusOnBtSateChanged(int32_t status)
static void WrapperStateChangeCallback(const int transport, const int status)
{
CLOGI("WrapperStateChangeCallback, transport=%d, status=%d", transport, status);
COMM_LOGI(COMM_ADAPTER, "WrapperStateChangeCallback, transport=%d, status=%d", transport, status);
int st = ConvertBtState(transport, status);
SoftBusOnBtSateChanged(st);
}
@ -100,11 +100,11 @@ static void WrapperStateChangeCallback(const int transport, const int status)
static void WrapperAclStateChangedCallback(const BdAddr *bdAddr, GapAclState state, unsigned int reason)
{
if (bdAddr == NULL) {
CLOGE("WrapperAclStateChangedCallback addr is null");
COMM_LOGE(COMM_ADAPTER, "WrapperAclStateChangedCallback addr is null");
return;
}
CLOGI("WrapperAclStateChangedCallback, addr:%02X:%02X:***%02X, state=%d, reason=%u",
COMM_LOGI(COMM_ADAPTER, "WrapperAclStateChangedCallback, addr:%02X:%02X:***%02X, state=%d, reason=%u",
bdAddr->addr[MAC_FIRST_INDEX], bdAddr->addr[MAC_ONE_INDEX], bdAddr->addr[MAC_FIVE_INDEX], state, reason);
int listenerId;
int aclState = ConvertAclState(state);
@ -121,14 +121,14 @@ static void WrapperAclStateChangedCallback(const BdAddr *bdAddr, GapAclState sta
static void WrapperPairRequestedCallback(const BdAddr *bdAddr, int transport)
{
if (bdAddr == NULL) {
CLOGE("WrapperPairRequestedCallback addr is null");
COMM_LOGE(COMM_ADAPTER, "WrapperPairRequestedCallback addr is null");
return;
}
CLOGI("WrapperPairRequestedCallback, addr:%02X:%02X:***%02X, transport=%d",
COMM_LOGI(COMM_ADAPTER, "WrapperPairRequestedCallback, addr:%02X:%02X:***%02X, transport=%d",
bdAddr->addr[MAC_FIRST_INDEX], bdAddr->addr[MAC_ONE_INDEX], bdAddr->addr[MAC_FIVE_INDEX], transport);
if (!PairRequestReply(bdAddr, transport, true)) {
CLOGE("PairRequestReply error");
COMM_LOGE(COMM_ADAPTER, "PairRequestReply error");
}
}
@ -136,15 +136,15 @@ static void WrapperPairConfiremedCallback(const BdAddr *bdAddr, int transport, i
int number)
{
if (bdAddr == NULL) {
CLOGE("WrapperPairConfirmedCallback addr is null");
COMM_LOGE(COMM_ADAPTER, "WrapperPairConfirmedCallback addr is null");
return;
}
CLOGI("WrapperPairConfirmedCallback, addr=%02X:%02X:***%02X, transport=%d, reqType:%d, number:%d",
COMM_LOGI(COMM_ADAPTER, "WrapperPairConfirmedCallback, addr=%02X:%02X:***%02X, transport=%d, reqType:%d, number:%d",
bdAddr->addr[MAC_FIRST_INDEX], bdAddr->addr[MAC_ONE_INDEX], bdAddr->addr[MAC_FIVE_INDEX],
transport, reqType, number);
if (!SetDevicePairingConfirmation(bdAddr, transport, true)) {
CLOGE("SetDevicePairingConfirmation error");
COMM_LOGE(COMM_ADAPTER, "SetDevicePairingConfirmation error");
}
}

View File

@ -20,8 +20,8 @@
#include <openssl/evp.h>
#include <openssl/rand.h>
#include "comm_log.h"
#include "softbus_adapter_file.h"
#include "softbus_adapter_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
@ -63,7 +63,7 @@ static int32_t OpensslEvpInit(EVP_CIPHER_CTX **ctx, const AesGcmCipherKey *ciphe
{
EVP_CIPHER *cipher = GetGcmAlgorithmByKeyLen(cipherkey->keyLen);
if (cipher == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "get cipher fail.");
COMM_LOGE(COMM_ADAPTER, "get cipher fail.");
return SOFTBUS_DECRYPT_ERR;
}
int32_t ret;
@ -75,21 +75,21 @@ static int32_t OpensslEvpInit(EVP_CIPHER_CTX **ctx, const AesGcmCipherKey *ciphe
if (mode == true) {
ret = EVP_EncryptInit_ex(*ctx, cipher, NULL, NULL, NULL);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptInit_ex fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptInit_ex fail.");
EVP_CIPHER_CTX_free(*ctx);
return SOFTBUS_DECRYPT_ERR;
}
} else {
ret = EVP_DecryptInit_ex(*ctx, cipher, NULL, NULL, NULL);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_DecryptInit_ex fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_DecryptInit_ex fail.");
EVP_CIPHER_CTX_free(*ctx);
return SOFTBUS_DECRYPT_ERR;
}
}
ret = EVP_CIPHER_CTX_ctrl(*ctx, EVP_CTRL_GCM_SET_IVLEN, GCM_IV_LEN, NULL);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Set iv len fail.");
COMM_LOGE(COMM_ADAPTER, "Set iv len fail.");
EVP_CIPHER_CTX_free(*ctx);
return SOFTBUS_DECRYPT_ERR;
}
@ -100,21 +100,21 @@ static int32_t PackIvAndTag(EVP_CIPHER_CTX *ctx, const AesGcmCipherKey *cipherke
unsigned char *cipherText, uint32_t cipherTextLen)
{
if ((dataLen + OVERHEAD_LEN) > cipherTextLen) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Encrypt invalid para.");
COMM_LOGE(COMM_ADAPTER, "Encrypt invalid para.");
return SOFTBUS_ENCRYPT_ERR;
}
if (memcpy_s(cipherText, cipherTextLen - dataLen, cipherkey->iv, GCM_IV_LEN) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP memcpy iv fail.");
COMM_LOGE(COMM_ADAPTER, "EVP memcpy iv fail.");
return SOFTBUS_ENCRYPT_ERR;
}
char tagbuf[TAG_LEN];
int ret = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, TAG_LEN, (void *)tagbuf);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_CIPHER_CTX_ctrl fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_CIPHER_CTX_ctrl fail.");
return SOFTBUS_DECRYPT_ERR;
}
if (memcpy_s(cipherText + dataLen + GCM_IV_LEN, cipherTextLen - dataLen - GCM_IV_LEN, tagbuf, TAG_LEN) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP memcpy tag fail.");
COMM_LOGE(COMM_ADAPTER, "EVP memcpy tag fail.");
return SOFTBUS_ENCRYPT_ERR;
}
return SOFTBUS_OK;
@ -125,7 +125,7 @@ static int32_t SslAesGcmEncrypt(const AesGcmCipherKey *cipherkey, const unsigned
{
if ((cipherkey == NULL) || (plainText == NULL) || (plainTextSize == 0) || cipherText == NULL ||
(cipherTextLen < plainTextSize + OVERHEAD_LEN)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Encrypt invalid para.");
COMM_LOGE(COMM_ADAPTER, "Encrypt invalid para.");
return SOFTBUS_INVALID_PARAM;
}
@ -134,32 +134,32 @@ static int32_t SslAesGcmEncrypt(const AesGcmCipherKey *cipherkey, const unsigned
EVP_CIPHER_CTX *ctx = NULL;
int32_t ret = OpensslEvpInit(&ctx, cipherkey, true);
if (ret != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "OpensslEvpInit fail.");
COMM_LOGE(COMM_ADAPTER, "OpensslEvpInit fail.");
return SOFTBUS_DECRYPT_ERR;
}
ret = EVP_EncryptInit_ex(ctx, NULL, NULL, cipherkey->key, cipherkey->iv);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptInit_ex fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptInit_ex fail.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_DECRYPT_ERR;
}
ret = EVP_EncryptUpdate(ctx, cipherText + GCM_IV_LEN, (int32_t *)&outbufLen, plainText, plainTextSize);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptUpdate fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptUpdate fail.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_DECRYPT_ERR;
}
outlen += outbufLen;
ret = EVP_EncryptFinal_ex(ctx, cipherText + GCM_IV_LEN + outbufLen, (int32_t *)&outbufLen);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptFinal_ex fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptFinal_ex fail.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_DECRYPT_ERR;
}
outlen += outbufLen;
ret = PackIvAndTag(ctx, cipherkey, outlen, cipherText, cipherTextLen);
if (ret != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "pack iv and tag fail.");
COMM_LOGE(COMM_ADAPTER, "pack iv and tag fail.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_DECRYPT_ERR;
}
@ -172,7 +172,7 @@ static int32_t SslAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigned
{
if ((cipherkey == NULL) || (cipherText == NULL) || (cipherTextSize <= OVERHEAD_LEN) || plain == NULL ||
(plainLen < cipherTextSize - OVERHEAD_LEN)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Decrypt invalid para.");
COMM_LOGE(COMM_ADAPTER, "Decrypt invalid para.");
return SOFTBUS_INVALID_PARAM;
}
@ -180,31 +180,31 @@ static int32_t SslAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigned
EVP_CIPHER_CTX *ctx = NULL;
int32_t ret = OpensslEvpInit(&ctx, cipherkey, false);
if (ret != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "OpensslEvpInit fail.");
COMM_LOGE(COMM_ADAPTER, "OpensslEvpInit fail.");
return SOFTBUS_DECRYPT_ERR;
}
ret = EVP_DecryptInit_ex(ctx, NULL, NULL, cipherkey->key, cipherkey->iv);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptInit_ex fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptInit_ex fail.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_DECRYPT_ERR;
}
ret = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, TAG_LEN, (void *)(cipherText + (cipherTextSize - TAG_LEN)));
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_DecryptUpdate fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_DecryptUpdate fail.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_DECRYPT_ERR;
}
ret = EVP_DecryptUpdate(ctx, plain, (int32_t *)&plainLen, cipherText + GCM_IV_LEN, cipherTextSize - OVERHEAD_LEN);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_DecryptUpdate fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_DecryptUpdate fail.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_DECRYPT_ERR;
}
outlen += plainLen;
ret = EVP_DecryptFinal_ex(ctx, plain + plainLen, (int32_t *)&plainLen);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_DecryptFinal_ex fail.");
COMM_LOGE(COMM_ADAPTER, "EVP_DecryptFinal_ex fail.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_DECRYPT_ERR;
}
@ -216,7 +216,7 @@ static int32_t SslAesGcmDecrypt(const AesGcmCipherKey *cipherkey, const unsigned
static int32_t HandleError(EVP_CIPHER_CTX *ctx, const char *buf)
{
if (buf != NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "%{public}s", buf);
COMM_LOGE(COMM_ADAPTER, "%s", buf);
}
if (ctx != NULL) {
EVP_CIPHER_CTX_free(ctx);
@ -237,14 +237,14 @@ int32_t SoftBusBase64Encode(unsigned char *dst, size_t dlen, size_t *olen, const
}
unsigned char *dstTmp = SoftBusCalloc(EVP_ENCODE_LENGTH(slen));
if (dstTmp == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] %{public}s SoftBusCalloc fail.", __func__);
COMM_LOGE(COMM_ADAPTER, "[TRANS] SoftBusCalloc fail.");
EVP_ENCODE_CTX_free(ctx);
return SOFTBUS_MEM_ERR;
}
EVP_EncodeInit(ctx);
int32_t ret = EVP_EncodeUpdate(ctx, dstTmp, &outlen, src, slen);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] EVP_EncodeUpdate fail.");
COMM_LOGE(COMM_ADAPTER, "[TRANS] EVP_EncodeUpdate fail.");
EVP_ENCODE_CTX_free(ctx);
SoftBusFree(dstTmp);
return SOFTBUS_DECRYPT_ERR;
@ -254,8 +254,7 @@ int32_t SoftBusBase64Encode(unsigned char *dst, size_t dlen, size_t *olen, const
*olen += outlen;
if (*olen > dlen) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] %{public}s invalid dlen: %{public}zu, olen:%{public}zu.", __func__,
dlen, *olen);
COMM_LOGE(COMM_ADAPTER, "[TRANS] invalid dlen: %zu, olen:%zu.", dlen, *olen);
EVP_ENCODE_CTX_free(ctx);
SoftBusFree(dstTmp);
return SOFTBUS_INVALID_PARAM;
@ -263,7 +262,7 @@ int32_t SoftBusBase64Encode(unsigned char *dst, size_t dlen, size_t *olen, const
ret = memcpy_s(dst, dlen, dstTmp, *olen);
if (ret != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] %{public}s memcpy_s failed.", __func__);
COMM_LOGE(COMM_ADAPTER, "[TRANS] memcpy_s failed.");
EVP_ENCODE_CTX_free(ctx);
SoftBusFree(dstTmp);
return SOFTBUS_MEM_ERR;
@ -291,35 +290,34 @@ int32_t SoftBusBase64Decode(unsigned char *dst, size_t dlen, size_t *olen, const
}
unsigned char *dstTmp = SoftBusCalloc(EVP_DECODE_LENGTH(slen));
if (dstTmp == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] %{public}s SoftBusCalloc fail.", __func__);
COMM_LOGE(COMM_ADAPTER, "[TRANS] SoftBusCalloc fail.");
EVP_ENCODE_CTX_free(ctx);
return SOFTBUS_MEM_ERR;
}
EVP_DecodeInit(ctx);
int32_t ret = EVP_DecodeUpdate(ctx, dstTmp, &outlen, src, slen);
if (ret == -1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] EVP_DecodeUpdate fail.");
COMM_LOGE(COMM_ADAPTER, "[TRANS] EVP_DecodeUpdate fail.");
ret = SOFTBUS_DECRYPT_ERR;
goto FINISHED;
}
*olen += outlen;
ret = EVP_DecodeFinal(ctx, dstTmp + outlen, &outlen);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] EVP_DecodeFinal fail.");
COMM_LOGE(COMM_ADAPTER, "[TRANS] EVP_DecodeFinal fail.");
ret = SOFTBUS_DECRYPT_ERR;
goto FINISHED;
}
*olen += outlen;
if (*olen > dlen) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] %{public}s invalid dlen: %{public}zu, olen:%{public}zu.", __func__,
dlen, *olen);
COMM_LOGE(COMM_ADAPTER, "[TRANS] invalid dlen: %zu, olen:%zu.", dlen, *olen);
ret = SOFTBUS_INVALID_PARAM;
goto FINISHED;
}
ret = memcpy_s(dst, dlen, dstTmp, *olen);
if (ret != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] %{public}s memcpy_s failed.", __func__);
COMM_LOGE(COMM_ADAPTER, "[TRANS] memcpy_s failed.");
ret = SOFTBUS_MEM_ERR;
goto FINISHED;
}
@ -338,7 +336,7 @@ int32_t SoftBusGenerateStrHash(const unsigned char *str, uint32_t len, unsigned
uint32_t olen;
int32_t ret = EVP_Digest(str, len, hash, &olen, EVP_sha256(), NULL);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "[TRANS] Get Openssl Hash fail.");
COMM_LOGE(COMM_ADAPTER, "[TRANS] Get Openssl Hash fail.");
return SOFTBUS_DECRYPT_ERR;
}
return SOFTBUS_OK;
@ -354,12 +352,12 @@ int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
int32_t ret;
if (SoftBusMutexInit(&g_randomLock, NULL) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "init mutex failed.");
COMM_LOGE(COMM_ADAPTER, "init mutex failed.");
return SOFTBUS_ERR;
}
if (SoftBusMutexLock(&g_randomLock) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "lock mutex failed");
COMM_LOGE(COMM_ADAPTER, "lock mutex failed");
return SOFTBUS_ERR;
}
if (initFlag == false) {
@ -370,7 +368,7 @@ int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
ret = RAND_bytes(randStr, (int32_t)len);
SoftBusMutexUnlock(&g_randomLock);
if (ret != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "gen random error, ret[%d]", ret);
COMM_LOGE(COMM_ADAPTER, "gen random error, ret[%d]", ret);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
@ -379,7 +377,7 @@ int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
int32_t SoftBusGenerateSessionKey(char *key, uint32_t len)
{
if (SoftBusGenerateRandomArray((unsigned char *)key, len) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate sessionKey error.");
COMM_LOGE(COMM_ADAPTER, "generate sessionKey error.");
return SOFTBUS_ENCRYPT_ERR;
}
return SOFTBUS_OK;
@ -393,7 +391,7 @@ int32_t SoftBusEncryptData(AesGcmCipherKey *cipherKey, const unsigned char *inpu
}
if (SoftBusGenerateRandomArray(cipherKey->iv, sizeof(cipherKey->iv)) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate random iv error.");
COMM_LOGE(COMM_ADAPTER, "generate random iv error.");
return SOFTBUS_ENCRYPT_ERR;
}
uint32_t outLen = inLen + OVERHEAD_LEN;
@ -412,7 +410,7 @@ int32_t SoftBusEncryptDataWithSeq(AesGcmCipherKey *cipherKey, const unsigned cha
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusGenerateRandomArray(cipherKey->iv, sizeof(cipherKey->iv)) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "generate random iv error.");
COMM_LOGE(COMM_ADAPTER, "generate random iv error.");
return SOFTBUS_ENCRYPT_ERR;
}
if (memcpy_s(cipherKey->iv, sizeof(int32_t), &seqNum, sizeof(int32_t)) != EOK) {
@ -435,7 +433,7 @@ int32_t SoftBusDecryptData(AesGcmCipherKey *cipherKey, const unsigned char *inpu
}
if (memcpy_s(cipherKey->iv, sizeof(cipherKey->iv), input, GCM_IV_LEN) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "copy iv failed.");
COMM_LOGE(COMM_ADAPTER, "copy iv failed.");
return SOFTBUS_ENCRYPT_ERR;
}
uint32_t outLen = inLen - OVERHEAD_LEN;
@ -458,13 +456,13 @@ uint32_t SoftBusCryptoRand(void)
{
int32_t fd = SoftBusOpenFile("/dev/urandom", SOFTBUS_O_RDONLY);
if (fd < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "CryptoRand open file fail");
COMM_LOGE(COMM_ADAPTER, "CryptoRand open file fail");
return 0;
}
uint32_t value = 0;
int32_t len = SoftBusReadFile(fd, &value, sizeof(uint32_t));
if (len < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "CryptoRand read file fail");
COMM_LOGE(COMM_ADAPTER, "CryptoRand read file fail");
return 0;
}
SoftBusCloseFile(fd);

View File

@ -22,8 +22,8 @@
#include "openssl/aes.h"
#include "comm_log.h"
#include "softbus_adapter_crypto.h"
#include "softbus_adapter_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
@ -43,44 +43,45 @@ int32_t SoftBusGenerateHmacHash(
uint8_t tempOutputData[EVP_MAX_MD_SIZE];
if (randomKey == NULL || rootKey == NULL || rootKeyLen == 0 || hash == NULL || hashLen == 0) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
HMAC_CTX *ctx = HMAC_CTX_new();
if (ctx == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HMAC_CTX_new failed.");
COMM_LOGE(COMM_ADAPTER, "HMAC_CTX_new failed.");
return SOFTBUS_ERR;
}
if (HMAC_CTX_reset(ctx) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HMAC_CTX_reset failed.");
COMM_LOGE(COMM_ADAPTER, "HMAC_CTX_reset failed.");
HMAC_CTX_free(ctx);
return SOFTBUS_ERR;
}
if (HMAC_Init_ex(ctx, rootKey, rootKeyLen, EVP_sha256(), NULL) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HMAC_Init_ex failed.");
COMM_LOGE(COMM_ADAPTER, "HMAC_Init_ex failed.");
HMAC_CTX_free(ctx);
return SOFTBUS_ERR;
}
if (HMAC_Update(ctx, randomKey->key, (size_t)randomKey->len) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HMAC_Update failed.");
COMM_LOGE(COMM_ADAPTER, "HMAC_Update failed.");
HMAC_CTX_free(ctx);
return SOFTBUS_ERR;
}
if (HMAC_Final(ctx, tempOutputData, &outBufLen) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "HMAC_Final failed.");
COMM_LOGE(COMM_ADAPTER, "HMAC_Final failed.");
HMAC_CTX_free(ctx);
return SOFTBUS_ERR;
}
HMAC_CTX_free(ctx);
if (hashLen < outBufLen) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "hash is invalid param.");
COMM_LOGE(COMM_ADAPTER, "hash is invalid param.");
return SOFTBUS_INVALID_PARAM;
}
if (outBufLen != SHA256_MAC_LEN) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "outBufLen is invalid length for hash.");
COMM_LOGE(COMM_ADAPTER, "outBufLen is invalid length for hash.");
return SOFTBUS_ERR;
}
if (memcpy_s(hash, hashLen, tempOutputData, outBufLen) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "hash result memcpy_s failed.");
COMM_LOGE(COMM_ADAPTER, "hash result memcpy_s failed.");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
@ -94,6 +95,7 @@ static int32_t OpensslAesCfbEncrypt(
if (cipherKey == NULL || cipherKey->ivLen != AES_IV_LENGTH || inData == NULL || inData->data == NULL ||
outData == NULL || (encMode != ENCRYPT_MODE && encMode != DECRYPT_MODE)) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
int32_t bits = 0;
@ -105,11 +107,11 @@ static int32_t OpensslAesCfbEncrypt(
bits = AES_256_CFB_BITS_LEN;
break;
default:
HILOG_ERROR(SOFTBUS_HILOG_ID, "cipherKey->keyLen unable to get encryption bits.");
COMM_LOGE(COMM_ADAPTER, "cipherKey->keyLen unable to get encryption bits.");
return SOFTBUS_INVALID_PARAM;
}
if (AES_set_encrypt_key(cipherKey->key, bits, &aes) < 0) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftbusAesCfbEncrypt unable to set encryption key in AES.");
COMM_LOGE(COMM_ADAPTER, "SoftbusAesCfbEncrypt unable to set encryption key in AES.");
return SOFTBUS_ERR;
}
if (encMode == ENCRYPT_MODE) {
@ -125,16 +127,16 @@ static int32_t RootKeyGenerateIvAndSessionKey(const EncryptKey *randomKey, Encry
{
uint8_t result[SHA256_MAC_LEN] = { 0 };
if (SoftBusGenerateHmacHash(randomKey, rootKey->key, rootKey->len, result, sizeof(result)) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SslHmacSha256 failed.");
COMM_LOGE(COMM_ADAPTER, "SslHmacSha256 failed.");
return SOFTBUS_ERR;
}
if (memcpy_s(cipherKey->key, cipherKey->keyLen, result, AES_SESSION_KEY_LENGTH) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "RootKeyGenerateIvAndSessionKey fill sessionKey failed!");
COMM_LOGE(COMM_ADAPTER, "RootKeyGenerateIvAndSessionKey fill sessionKey failed!");
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(cipherKey->iv, cipherKey->ivLen, result + AES_SESSION_KEY_LENGTH,
SHA256_MAC_LEN - AES_SESSION_KEY_LENGTH) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "RootKeyGenerateIvAndSessionKey fill iv failed!");
COMM_LOGE(COMM_ADAPTER, "RootKeyGenerateIvAndSessionKey fill iv failed!");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
@ -143,6 +145,7 @@ static int32_t RootKeyGenerateIvAndSessionKey(const EncryptKey *randomKey, Encry
static int32_t GenerateIvAndSessionKey(const EncryptKey *randomKey, EncryptKey *rootKey, AesCipherKey *cipherKey)
{
if (cipherKey == NULL) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
cipherKey->keyLen = AES_SESSION_KEY_LENGTH;
@ -157,7 +160,7 @@ static int32_t GenerateIvAndSessionKey(const EncryptKey *randomKey, EncryptKey *
return SOFTBUS_MEM_ERR;
}
if (RootKeyGenerateIvAndSessionKey(randomKey, rootKey, cipherKey) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "RootKeyGenerateIvAndSessionKey failed!");
COMM_LOGE(COMM_ADAPTER, "RootKeyGenerateIvAndSessionKey failed!");
SoftBusFree(cipherKey->key);
SoftBusFree(cipherKey->iv);
return SOFTBUS_ERR;
@ -170,28 +173,28 @@ int32_t SoftBusAesCfbRootEncrypt(const AesInputData *inData, const EncryptKey *r
{
if (inData == NULL || inData->data == NULL || randomKey == NULL || randomKey->key == NULL || rootKey == NULL ||
rootKey->key == NULL || outData == NULL || (encMode != ENCRYPT_MODE && encMode != DECRYPT_MODE)) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
AesCipherKey cipherKey = { 0 };
AesOutputData encryptData = { .data = (uint8_t *)SoftBusCalloc(inData->len), .len = inData->len };
if (encryptData.data == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "encryptData calloc failed.");
COMM_LOGE(COMM_ADAPTER, "encryptData calloc failed.");
return SOFTBUS_MEM_ERR;
}
if (GenerateIvAndSessionKey(randomKey, rootKey, &cipherKey) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "GenerateIvAndSessionKey failed!");
COMM_LOGE(COMM_ADAPTER, "GenerateIvAndSessionKey failed!");
SoftBusFree(encryptData.data);
return SOFTBUS_ERR;
}
if (OpensslAesCfbEncrypt(&cipherKey, inData, encMode, &encryptData) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "OpensslAesCfb encrypt or decrypt by root key failed.");
COMM_LOGE(COMM_ADAPTER, "OpensslAesCfb encrypt or decrypt by root key failed.");
SoftBusFree(cipherKey.key);
SoftBusFree(cipherKey.iv);
SoftBusFree(encryptData.data);
encryptData.data = NULL;
return SOFTBUS_ENCRYPT_ERR;
}
(void)memset_s(cipherKey.key, cipherKey.keyLen, 0, cipherKey.keyLen);
(void)memset_s(cipherKey.iv, cipherKey.ivLen, 0, cipherKey.ivLen);
SoftBusFree(cipherKey.key);
@ -209,32 +212,33 @@ int32_t SoftBusAesCfbEncrypt(
if (inData == NULL || inData->data == NULL || cipherKey == NULL || cipherKey->ivLen < RANDOM_LENGTH ||
outData == NULL || (encMode != ENCRYPT_MODE && encMode != DECRYPT_MODE)) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
AesOutputData encryptData = { .data = (uint8_t *)SoftBusCalloc(inData->len), .len = inData->len };
if (encryptData.data == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "encryptData calloc failed.");
COMM_LOGE(COMM_ADAPTER, "encryptData calloc failed.");
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(random, sizeof(random), cipherKey->iv, sizeof(random)) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "random memcpy_s failed!");
COMM_LOGE(COMM_ADAPTER, "random memcpy_s failed!");
SoftBusFree(encryptData.data);
return SOFTBUS_MEM_ERR;
}
EncryptKey key = { cipherKey->key, cipherKey->keyLen };
(void)memset_s(cipherKey->key, cipherKey->keyLen, 0, cipherKey->keyLen);
if (SoftBusGenerateHmacHash(&key, random, sizeof(random), result, SHA256_MAC_LEN) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SslHmacSha256 failed.");
COMM_LOGE(COMM_ADAPTER, "SslHmacSha256 failed.");
SoftBusFree(encryptData.data);
return SOFTBUS_ERR;
}
if (memcpy_s(cipherKey->key, cipherKey->keyLen, result, SHA256_MAC_LEN) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "fill cipherKey->key failed!");
COMM_LOGE(COMM_ADAPTER, "fill cipherKey->key failed!");
SoftBusFree(encryptData.data);
return SOFTBUS_MEM_ERR;
}
if (OpensslAesCfbEncrypt(cipherKey, inData, encMode, &encryptData) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "OpensslAesCfbEncrypt failed.");
COMM_LOGE(COMM_ADAPTER, "OpensslAesCfbEncrypt failed.");
SoftBusFree(encryptData.data);
encryptData.data = NULL;
return SOFTBUS_ENCRYPT_ERR;
@ -253,7 +257,7 @@ static EVP_CIPHER *GetSslGcmAlgorithmByKeyLen(uint32_t keyLen)
case AES_256_GCM_KEYLEN:
return (EVP_CIPHER *)EVP_aes_256_gcm();
default:
HILOG_ERROR(SOFTBUS_HILOG_ID, "Get SslGcmAlgorithm ByKeyLen failed.");
COMM_LOGE(COMM_ADAPTER, "Get SslGcmAlgorithm ByKeyLen failed.");
return NULL;
}
return NULL;
@ -262,34 +266,35 @@ static EVP_CIPHER *GetSslGcmAlgorithmByKeyLen(uint32_t keyLen)
static int32_t GcmOpensslEvpInit(EVP_CIPHER_CTX **ctx, uint32_t keyLen, int32_t encMode)
{
if (ctx == NULL || keyLen == 0 || (encMode != ENCRYPT_MODE && encMode != DECRYPT_MODE)) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
EVP_CIPHER *cipher = GetSslGcmAlgorithmByKeyLen(keyLen);
if (cipher == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "GetSslGcmAlgorithmByKeyLen failed.");
COMM_LOGE(COMM_ADAPTER, "GetSslGcmAlgorithmByKeyLen failed.");
return SOFTBUS_ERR;
}
*ctx = EVP_CIPHER_CTX_new();
if (*ctx == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_CIPHER_CTX_new failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_CIPHER_CTX_new failed.");
return SOFTBUS_MEM_ERR;
}
EVP_CIPHER_CTX_set_padding(*ctx, OPENSSL_EVP_PADDING_FUNC_CLOSE);
if (encMode == ENCRYPT_MODE) {
if (EVP_EncryptInit_ex(*ctx, cipher, NULL, NULL, NULL) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptInit_ex failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptInit_ex failed.");
EVP_CIPHER_CTX_free(*ctx);
return SOFTBUS_ERR;
}
} else {
if (EVP_DecryptInit_ex(*ctx, cipher, NULL, NULL, NULL) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_DecryptInit_ex failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_DecryptInit_ex failed.");
EVP_CIPHER_CTX_free(*ctx);
return SOFTBUS_ERR;
}
}
if (EVP_CIPHER_CTX_ctrl(*ctx, EVP_CTRL_GCM_SET_IVLEN, AES_IV_LENGTH, NULL) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_CIPHER_CTX_ctrl failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_CIPHER_CTX_ctrl failed.");
EVP_CIPHER_CTX_free(*ctx);
return SOFTBUS_ERR;
}
@ -301,45 +306,46 @@ static int32_t OpensslAesGcmEncrypt(
{
if (srcData == NULL || srcDataLen == 0 || cipherKey == NULL || outData == NULL || outDataLen == NULL ||
*outDataLen < (srcDataLen + AES_GCM_TAG_LEN)) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
EVP_CIPHER_CTX *ctx = NULL;
if (GcmOpensslEvpInit(&ctx, cipherKey->keyLen, ENCRYPT_MODE) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "GcmOpensslEvpInit failed.");
COMM_LOGE(COMM_ADAPTER, "GcmOpensslEvpInit failed.");
return SOFTBUS_ERR;
}
if (EVP_EncryptInit_ex(ctx, NULL, NULL, cipherKey->key, cipherKey->iv) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptInit_ex failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptInit_ex failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_ERR;
}
int32_t outLen = 0;
int32_t outBufLen = 0;
if (EVP_EncryptUpdate(ctx, outData, &outBufLen, srcData, srcDataLen) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptUpdate failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptUpdate failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_ERR;
}
outLen += outBufLen;
if (EVP_EncryptFinal_ex(ctx, outData + outBufLen, &outBufLen) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_EncryptFinal_ex failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_EncryptFinal_ex failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_ERR;
}
outLen += outBufLen;
if (*outDataLen < ((uint32_t)outLen + AES_GCM_TAG_LEN)) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "Encrypt invalid param.");
COMM_LOGE(COMM_ADAPTER, "Encrypt invalid param.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_INVALID_PARAM;
}
uint8_t tagbuf[AES_GCM_TAG_LEN]; // outData has two part: EncryptedData & AES-GCM-TAG
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, AES_GCM_TAG_LEN, (void *)tagbuf) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_CTRL_GCM_GET_TAG failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_CTRL_GCM_GET_TAG failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_ERR;
}
if (memcpy_s(outData + outLen, AES_GCM_TAG_LEN, tagbuf, AES_GCM_TAG_LEN) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "tag memcpy_s failed.");
COMM_LOGE(COMM_ADAPTER, "tag memcpy_s failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_MEM_ERR;
}
@ -353,15 +359,16 @@ static int32_t OpensslAesGcmDecrypt(
{
if (srcData == NULL || srcDataLen <= AES_GCM_TAG_LEN || cipherKey == NULL || outData == NULL ||
outDataLen == NULL || *outDataLen < (srcDataLen - AES_GCM_TAG_LEN)) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
EVP_CIPHER_CTX *ctx = NULL;
if (GcmOpensslEvpInit(&ctx, cipherKey->keyLen, DECRYPT_MODE) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "GcmOpensslEvpInit failed.");
COMM_LOGE(COMM_ADAPTER, "GcmOpensslEvpInit failed.");
return SOFTBUS_ERR;
}
if (EVP_DecryptInit_ex(ctx, NULL, NULL, cipherKey->key, cipherKey->iv) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_DecryptInit_ex failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_DecryptInit_ex failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_ERR;
}
@ -369,24 +376,24 @@ static int32_t OpensslAesGcmDecrypt(
int32_t outBufLen = 0;
uint8_t trueEncryptedData[srcDataLen - AES_GCM_TAG_LEN];
if (memcpy_s(trueEncryptedData, srcDataLen - AES_GCM_TAG_LEN, srcData, srcDataLen - AES_GCM_TAG_LEN) != EOK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "trueEncryptedData memcpy_s failed.");
COMM_LOGE(COMM_ADAPTER, "trueEncryptedData memcpy_s failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_MEM_ERR;
}
if (EVP_CIPHER_CTX_ctrl(
ctx, EVP_CTRL_GCM_SET_TAG, AES_GCM_TAG_LEN, (void *)(srcData + (srcDataLen - AES_GCM_TAG_LEN))) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_CTRL_GCM_SET_TAG failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_CTRL_GCM_SET_TAG failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_ERR;
}
if (EVP_DecryptUpdate(ctx, outData, &outBufLen, trueEncryptedData, srcDataLen - AES_GCM_TAG_LEN) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_DecryptUpdate failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_DecryptUpdate failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_ERR;
}
outLen += outBufLen;
if (EVP_DecryptFinal_ex(ctx, outData + outBufLen, &outBufLen) != 1) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "EVP_DecryptFinal_ex failed.");
COMM_LOGE(COMM_ADAPTER, "EVP_DecryptFinal_ex failed.");
EVP_CIPHER_CTX_free(ctx);
return SOFTBUS_ERR;
}
@ -401,24 +408,25 @@ int32_t SoftBusAesGcmEncrypt(
{
if (inData == NULL || inData->data == NULL || cipherKey == NULL || cipherKey->key == NULL ||
cipherKey->iv == NULL || outData == NULL || (encMode != ENCRYPT_MODE && encMode != DECRYPT_MODE)) {
COMM_LOGE(COMM_ADAPTER, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
uint32_t encryptDataLen = inData->len + AES_GCM_TAG_LEN;
uint8_t *encryptData = (uint8_t *)SoftBusCalloc(encryptDataLen);
if (encryptData == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "encryptdata calloc failed.");
COMM_LOGE(COMM_ADAPTER, "encrypt data calloc fail.");
return SOFTBUS_MEM_ERR;
}
if (encMode == ENCRYPT_MODE) {
if (OpensslAesGcmEncrypt(inData->data, inData->len, cipherKey, encryptData, &encryptDataLen) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "OpensslAesGcmEncrypt failed.");
COMM_LOGE(COMM_ADAPTER, "OpensslAesGcmEncrypt failed.");
SoftBusFree(encryptData);
encryptData = NULL;
return SOFTBUS_ENCRYPT_ERR;
}
} else {
if (OpensslAesGcmDecrypt(inData->data, inData->len, cipherKey, encryptData, &encryptDataLen) != SOFTBUS_OK) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "OpensslAesGcmDecrypt failed.");
COMM_LOGE(COMM_ADAPTER, "OpensslAesGcmDecrypt failed.");
SoftBusFree(encryptData);
encryptData = NULL;
return SOFTBUS_DECRYPT_ERR;

View File

@ -16,7 +16,7 @@
#include "softbus_adapter_range.h"
#include <math.h>
#include <stdlib.h>
#include "softbus_adapter_log.h"
#include "comm_log.h"
#define MOCK_POWER (-17)
#define DB_BASE (10.0)
@ -25,7 +25,7 @@
int SoftBusBleRange(SoftBusRangeParam *param, int32_t *range)
{
if (param == NULL || range == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusBleRange param is null.");
COMM_LOGE(COMM_ADAPTER, "SoftBusBleRange param is null.");
return -1;
}
@ -36,7 +36,7 @@ int SoftBusBleRange(SoftBusRangeParam *param, int32_t *range)
int SoftBusGetBlePower(int8_t *power)
{
if (power == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "SoftBusGetBlePower param is null.");
COMM_LOGE(COMM_ADAPTER, "SoftBusGetBlePower param is null.");
return -1;
}
*power = MOCK_POWER;

View File

@ -20,7 +20,6 @@
#include <securec.h>
#include "bus_center_adapter.h"
#include "softbus_adapter_log.h"
#include "softbus_errcode.h"
#define DEFAULT_DEVICE_NAME "UNKNOWN"
@ -29,7 +28,6 @@
int32_t __attribute__ ((weak)) GetCommonDevInfo(const CommonDeviceKey key, char *value, uint32_t len)
{
if (value == NULL) {
HILOG_ERROR(SOFTBUS_HILOG_ID, "fail: para error!");
return SOFTBUS_INVALID_PARAM;
}
switch (key) {

View File

@ -59,7 +59,7 @@ if (defined(ohos_lite)) {
bus_center_core_adapter_external_deps += [ "huks:libhukssdk" ]
}
} else {
if (dsoftbus_get_devicename == false) {
if (!dsoftbus_get_devicename) {
bus_center_core_adapter_src += [ "$dsoftbus_root_path/core/adapter/bus_center/src/lnn_settingdata_event_monitor_virtual.cpp" ]
bus_center_core_adapter_inc +=
[ "$dsoftbus_root_path/core/adapter/bus_center/include" ]
@ -82,7 +82,7 @@ if (defined(ohos_lite)) {
"relational_store:native_rdb",
]
}
if (softbus_os_account == true) {
if (softbus_os_account) {
bus_center_core_adapter_src += [
"$dsoftbus_root_path/core/adapter/bus_center/src/lnn_ohos_account.cpp",
"$dsoftbus_root_path/core/adapter/bus_center/src/lnn_ohos_account_adapter.cpp",

View File

@ -99,6 +99,7 @@ static int32_t GenerateRsaKeyPair(void)
int32_t SoftBusGetPublicKey(uint8_t *publicKey, uint32_t publicKeyLen)
{
if (publicKey == NULL || publicKeyLen == 0) {
COMM_LOGE(COMM_UTILS, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
if (!IsRsaKeyPairExist(g_rsaKeyAlias)) {
@ -124,6 +125,7 @@ int32_t SoftBusGetPublicKey(uint8_t *publicKey, uint32_t publicKeyLen)
static BN_CTX *GetRsaBigNum(const BIGNUM *modNum, BIGNUM **base, BIGNUM **result, uint8_t **buf, int32_t *bufNum)
{
if (modNum == NULL || base == NULL || result == NULL || buf == NULL || bufNum == NULL) {
COMM_LOGE(COMM_UTILS, "invalid param.");
return NULL;
}
BN_CTX *ctx = BN_CTX_new();
@ -157,6 +159,7 @@ static BN_CTX *GetRsaBigNum(const BIGNUM *modNum, BIGNUM **base, BIGNUM **result
static int32_t EncryptByPublicKey(const uint8_t *src, uint32_t srcLen, const RSA *rsa, uint8_t *out, uint32_t outLen)
{
if (src == NULL || srcLen == 0 || rsa == NULL || out == NULL || outLen < SOFTBUS_RSA_ENCRYPT_LEN) {
COMM_LOGE(COMM_UTILS, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = SOFTBUS_ERR;
@ -201,6 +204,7 @@ static int32_t DataToPublicKey(const uint8_t *bufKey, int32_t bufKeyLen, RSA **p
BIO *pBio = NULL;
if (bufKey == NULL || bufKeyLen < 0 || pubKey == NULL) {
COMM_LOGE(COMM_UTILS, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
pBio = BIO_new(BIO_s_mem());
@ -229,6 +233,7 @@ int32_t SoftBusRsaEncrypt(const uint8_t *srcData, uint32_t srcDataLen, PublicKey
{
if (srcData == NULL || srcDataLen == 0 || publicKey == NULL || publicKey->key == NULL || publicKey->len == 0 ||
encryptedData == NULL || encryptedDataLen == NULL) {
COMM_LOGE(COMM_UTILS, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
RSA *peerPubKey = NULL;
@ -272,6 +277,7 @@ int32_t SoftBusRsaDecrypt(
const uint8_t *srcData, uint32_t srcDataLen, uint8_t **decryptedData, uint32_t *decryptedDataLen)
{
if (srcData == NULL || srcDataLen == 0 || decryptedData == NULL || decryptedDataLen == NULL) {
COMM_LOGE(COMM_UTILS, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
struct HksBlob encryptedBlob = { srcDataLen, (uint8_t *)srcData };

View File

@ -30,20 +30,22 @@ typedef enum {
COMM_VERIFY,
COMM_PERM,
COMM_UTILS,
COMM_ADAPTER,
COMM_TEST,
} CommLogLabelEnum;
/* Keep consistent with labels */
static const SoftBusLogLabel COMM_LABELS[MODULE_DOMAIN_MAX_LEN] = {
{COMM_SDK, 0xd005700, "CommSdk" },
{ COMM_SVC, 0xd005701, "CommSvc" },
{ COMM_INIT, 0xd005702, "CommInit" },
{ COMM_DFX, 0xd005703, "CommDfx" },
{ COMM_EVENT, 0xd005704, "CommEvent" },
{ COMM_VERIFY, 0xd005705, "CommVerify"},
{ COMM_PERM, 0xd005706, "CommPerm" },
{ COMM_UTILS, 0xd005707, "CommUtils" },
{ COMM_TEST, DOMAIN_ID_TEST, "CommTest" },
{ COMM_SDK, 0xd005700, "CommSdk" },
{ COMM_SVC, 0xd005701, "CommSvc" },
{ COMM_INIT, 0xd005702, "CommInit" },
{ COMM_DFX, 0xd005703, "CommDfx" },
{ COMM_EVENT, 0xd005704, "CommEvent" },
{ COMM_VERIFY, 0xd005705, "CommVerify" },
{ COMM_PERM, 0xd005706, "CommPerm" },
{ COMM_UTILS, 0xd005707, "CommUtils" },
{ COMM_ADAPTER, 0xd005708, "CommAdapter"},
{ COMM_TEST, DOMAIN_ID_TEST, "CommTest" },
};
#define COMM_LOGF(label, ...) (void)SOFTBUS_LOG_INNER(SOFTBUS_DFX_LOG_FATAL, COMM_LABELS[label], ##__VA_ARGS__)

View File

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

View File

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

View File

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

View File

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

View File

@ -94,10 +94,7 @@ void InitSoftBusServer(void)
COMM_LOGE(COMM_SVC, "softbus buscenter server init failed.");
goto ERR_EXIT;
}
if (ConnBleDirectInit() == SOFTBUS_ERR) {
COMM_LOGE(COMM_SVC, "softbus ble direct init failed.");
goto ERR_EXIT;
}
if (TransServerInit() == SOFTBUS_ERR) {
COMM_LOGE(COMM_SVC, "softbus trans server init failed.");
goto ERR_EXIT;
@ -108,6 +105,11 @@ void InitSoftBusServer(void)
goto ERR_EXIT;
}
if (ConnBleDirectInit() == SOFTBUS_ERR) {
COMM_LOGE(COMM_SVC, "softbus ble direct init failed.");
goto ERR_EXIT;
}
if (InitSoftbusSysEvt() != SOFTBUS_OK || SoftBusHiDumperInit() != SOFTBUS_OK) {
COMM_LOGE(COMM_SVC, "softbus dfx init failed.");
goto ERR_EXIT;

View File

@ -113,3 +113,12 @@ int32_t ServerIpcRippleStats(int32_t channelId, int32_t channelType, const Traff
(void)data;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t ServerIpcEvaluateQos(const char *peerNetworkId, TransDataType dataType, const QosTV *qos, uint32_t qosCount)
{
(void)peerNetworkId;
(void)dataType;
(void)qos;
(void)qosCount;
return SOFTBUS_NOT_IMPLEMENT;
}

View File

@ -374,3 +374,12 @@ int32_t ServerIpcRippleStats(int32_t channelId, int32_t channelType, const Traff
(void)data;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t ServerIpcEvaluateQos(const char *peerNetworkId, TransDataType dataType, const QosTV *qos, uint32_t qosCount)
{
(void)peerNetworkId;
(void)dataType;
(void)qos;
(void)qosCount;
return SOFTBUS_NOT_IMPLEMENT;
}

View File

@ -87,6 +87,12 @@ HWTEST_F(CommLogTest, CommLogTest001, TestSize.Level0)
EXPECT_EQ(++authDomainBase, label.domain);
EXPECT_STREQ("CommUtils", label.tag);
EXPECT_EQ(++index, COMM_ADAPTER);
label = COMM_LABELS[COMM_ADAPTER];
EXPECT_EQ(COMM_ADAPTER, label.label);
EXPECT_EQ(++authDomainBase, label.domain);
EXPECT_STREQ("CommAdapter", label.tag);
EXPECT_EQ(++index, COMM_TEST);
label = COMM_LABELS[COMM_TEST];
EXPECT_EQ(COMM_TEST, label.label);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@ -17,6 +17,7 @@
#include "accesstoken_kit.h"
#include "discovery_service.h"
#include "nativetoken_kit.h"
#include "softbus_bus_center.h"
#include "token_setproc.h"
namespace OHOS {
@ -114,118 +115,116 @@ static PublishInfo g_pInfo = {
static void TestDeviceFound(const DeviceInfo *device)
{}
static void TestDiscoverFailed(int subscribeId, DiscoveryFailReason failReason)
static void TestDiscoverResult(int32_t refreshId, RefreshResult reason)
{}
static void TestDiscoverySuccess(int subscribeId)
static void TestPublishResult(int publishId, PublishResult reason)
{}
static void TestPublishSuccess(int publishId)
{}
static void TestPublishFail(int publishId, PublishFailReason reason)
{}
static IDiscoveryCallback g_subscribeCb = {
static IRefreshCallback g_refreshCb = {
.OnDeviceFound = TestDeviceFound,
.OnDiscoverFailed = TestDiscoverFailed,
.OnDiscoverySuccess = TestDiscoverySuccess
.OnDiscoverResult = TestDiscoverResult
};
static IPublishCallback g_publishCb = {
.OnPublishSuccess = TestPublishSuccess,
.OnPublishFail = TestPublishFail
static IPublishCb g_publishCb = {
.OnPublishResult = TestPublishResult
};
/**
* @tc.name: PublishServiceTestCase
* @tc.name: PublishLNNTestCase
* @tc.desc: PublishService Performance Testing
* @tc.type: FUNC
* @tc.require: PublishService normal operation
*/
BENCHMARK_F(DiscoveryTest, PublishServiceTestCase)(benchmark::State &state)
BENCHMARK_F(DiscoveryTest, PublishLNNTestCase)(benchmark::State &state)
{
while (state.KeepRunning()) {
g_pInfo.publishId = GetPublishId();
state.ResumeTiming();
int ret = PublishService(g_pkgName, &g_pInfo, &g_publishCb);
int ret = PublishLNN(g_pkgName, &g_pInfo, &g_publishCb);
if (ret != 0) {
state.SkipWithError("PublishServiceTestCase failed.");
state.SkipWithError("PublishLNNTestCase failed.");
}
state.PauseTiming();
ret = UnPublishService(g_pkgName, g_pInfo.publishId);
ret = StopPublishLNN(g_pkgName, g_pInfo.publishId);
if (ret != 0) {
state.SkipWithError("StopPublishLNNTestCase failed.");
}
}
}
BENCHMARK_REGISTER_F(DiscoveryTest, PublishServiceTestCase);
BENCHMARK_REGISTER_F(DiscoveryTest, PublishLNNTestCase);
/**
* @tc.name: UnPublishServiceTestCase
* @tc.name: StopPublishLNNTestCase
* @tc.desc: UnPublishService Performance Testing
* @tc.type: FUNC
* @tc.require: UnPublishService normal operation
*/
BENCHMARK_F(DiscoveryTest, UnPublishServiceTestCase)(benchmark::State &state)
BENCHMARK_F(DiscoveryTest, StopPublishLNNTestCase)(benchmark::State &state)
{
while (state.KeepRunning()) {
g_pInfo.publishId = GetPublishId();
state.PauseTiming();
int ret = PublishService(g_pkgName, &g_pInfo, &g_publishCb);
int ret = PublishLNN(g_pkgName, &g_pInfo, &g_publishCb);
if (ret != 0) {
state.SkipWithError("UnPublishServiceTestCase failed.");
state.SkipWithError("PublishLNNTestCase failed.");
}
state.ResumeTiming();
ret = UnPublishService(g_pkgName, g_pInfo.publishId);
ret = StopPublishLNN(g_pkgName, g_pInfo.publishId);
if (ret != 0) {
state.SkipWithError("UnPublishServiceTestCase failed.");
state.SkipWithError("StopPublishLNNTestCase failed.");
}
}
}
BENCHMARK_REGISTER_F(DiscoveryTest, UnPublishServiceTestCase);
BENCHMARK_REGISTER_F(DiscoveryTest, StopPublishLNNTestCase);
/**
* @tc.name: StartDiscoveryTestCase
* @tc.name: RefreshLNNTestCase
* @tc.desc: StartDiscovery Performance Testing
* @tc.type: FUNC
* @tc.require: StartDiscovery normal operation
*/
BENCHMARK_F(DiscoveryTest, StartDiscoveryTestCase)(benchmark::State &state)
BENCHMARK_F(DiscoveryTest, RefreshLNNTestCase)(benchmark::State &state)
{
while (state.KeepRunning()) {
g_sInfo.subscribeId = GetSubscribeId();
state.ResumeTiming();
int ret = StartDiscovery(g_pkgName, &g_sInfo, &g_subscribeCb);
int ret = RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb);
if (ret != 0) {
state.SkipWithError("StartDiscoveryTestCase failed.");
state.SkipWithError("RefreshLNNTestCase failed.");
}
state.PauseTiming();
ret = StopDiscovery(g_pkgName, g_sInfo.subscribeId);
ret = StopRefreshLNN(g_pkgName, g_sInfo.subscribeId);
if (ret != 0) {
state.SkipWithError("StoptRefreshLNNTestCase failed.");
}
}
}
BENCHMARK_REGISTER_F(DiscoveryTest, StartDiscoveryTestCase);
BENCHMARK_REGISTER_F(DiscoveryTest, RefreshLNNTestCase);
/**
* @tc.name: StopDiscoveryTestCase
* @tc.name: StoptRefreshLNNTestCase
* @tc.desc: StoptDiscovery Performance Testing
* @tc.type: FUNC
* @tc.require: StoptDiscovery normal operation
*/
BENCHMARK_F(DiscoveryTest, StoptDiscoveryTestCase)(benchmark::State &state)
BENCHMARK_F(DiscoveryTest, StoptRefreshLNNTestCase)(benchmark::State &state)
{
while (state.KeepRunning()) {
g_sInfo.subscribeId = GetSubscribeId();
state.PauseTiming();
int ret = StartDiscovery(g_pkgName, &g_sInfo, &g_subscribeCb);
int ret = RefreshLNN(g_pkgName, &g_sInfo, &g_refreshCb);
if (ret != 0) {
state.SkipWithError("StoptDiscoveryTestCase failed.");
state.SkipWithError("RefreshLNNTestCase failed.");
}
state.ResumeTiming();
ret = StopDiscovery(g_pkgName, g_sInfo.subscribeId);
ret = StopRefreshLNN(g_pkgName, g_sInfo.subscribeId);
if (ret != 0) {
state.SkipWithError("StoptDiscoveryTestCase failed.");
state.SkipWithError("StoptRefreshLNNTestCase failed.");
}
}
}
BENCHMARK_REGISTER_F(DiscoveryTest, StoptDiscoveryTestCase);
BENCHMARK_REGISTER_F(DiscoveryTest, StoptRefreshLNNTestCase);
}
// Run the benchmark