From ae4a7aa77a47ca45b688028062a5062a25476e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Sat, 25 May 2024 18:03:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=87=AD=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../native_cpp/src/mini/hichain_adapter.c | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/mini/hichain_adapter.c b/interfaces/inner_kits/native_cpp/src/mini/hichain_adapter.c index d57e61f6..0ed6afe9 100644 --- a/interfaces/inner_kits/native_cpp/src/mini/hichain_adapter.c +++ b/interfaces/inner_kits/native_cpp/src/mini/hichain_adapter.c @@ -42,15 +42,19 @@ static const int GROUP_TYPE_ACROSS_ACCOUNT_GROUP = 1282; static const int AUTH_FORM_IDENTICAL_ACCOUNT_GROUP = 1; static const int AUTH_FORM_PEER_TO_PEER_GROUP = 0; static const int AUTH_FORM_ACROSS_ACCOUNT_GROUP = 2; +static const int IMPORT_SELF_CREDENTIAL = 0; +static const int DELETE_SELF_CREDENTIAL = 1; static const DeviceGroupManager *g_deviceGroupManager = NULL; static const GroupAuthManager *g_groupAuthManager = NULL; static UINT32 g_createGroupSem = LOSCFG_BASE_IPC_SEM_LIMIT; +static UINT32 g_deleteGroupSem = LOSCFG_BASE_IPC_SEM_LIMIT; // It is only the id of a group operator request an has no security risk. static const int64_t CREATE_GROUP_REQUESTID = 159357462; static bool g_createGroupFlag = true; // strict operating timings do not require lock protection +static bool g_deleteGroupFlag = true; // maximum length of JSON character string input for credential operation static const UINT32 DM_MAX_REQUEST_JSON_LEN = 4096; @@ -102,6 +106,11 @@ int InitHichainModle(void) DMLOGE("failed to create group semaphore with ret: %d.", ret); retValue = ERR_DM_LITEOS_CREATE_MUTEX_OR_SEM; } + UINT32 osRet = LOS_BinarySemCreate(HICHAIN_SEM_INIT_COUNT, &g_deleteGroupSem); + if (osRet != LOS_OK) { + DMLOGE("failed to create group semaphore with ret: %d.", ret); + retValue = ERR_DM_LITEOS_CREATE_MUTEX_OR_SEM; + } if (retValue != DM_OK) { DMLOGE("failed to init hichain modle with retValue: %d.", retValue); UnInitHichainModle(); @@ -134,6 +143,13 @@ int UnInitHichainModle(void) } else { g_createGroupSem = LOSCFG_BASE_IPC_SEM_LIMIT; } + UINT32 osRet = LOS_SemDelete(g_deleteGroupSem); + if (osRet != LOS_OK && osRet != LOS_ERRNO_SEM_INVALID) { + DMLOGE("failed to delete group semaphore with ret: %d.", osRet); + retValue = ERR_DM_LITEOS_DELETE_MUTEX_OR_SEM; + } else { + g_deleteGroupSem = LOSCFG_BASE_IPC_SEM_LIMIT; + } if (retValue != DM_OK) { DMLOGE("failed to uninit hichain modle with retValue: %d.", retValue); return retValue; @@ -227,11 +243,20 @@ static void OnFinish(int64_t requestId, int operationCode, const char *returnDat #ifdef MINE_HARMONY_HICHAIN DMLOGI("start to notify the asynchronous operation group of the successful result."); if (requestId == CREATE_GROUP_REQUESTID) { - g_createGroupFlag = true; - UINT32 osRet = LOS_SemPost(g_createGroupSem); - if (osRet != LOS_OK) { - DMLOGE("failed to post create group semaphore with ret: %u.", osRet); - return; + if (operationCode == IMPORT_SELF_CREDENTIAL) { + g_createGroupFlag = true; + UINT32 osRet = LOS_SemPost(g_createGroupSem); + if (osRet != LOS_OK) { + DMLOGE("failed to post create group semaphore with ret: %u.", osRet); + return; + } + } else if (operationCode == DELETE_SELF_CREDENTIAL) { + g_deleteGroupFlag = true; + UINT32 osRet = LOS_SemPost(g_deleteGroupSem); + if (osRet != LOS_OK) { + DMLOGE("failed to post delete group semaphore with ret: %u.", osRet); + return; + } } } #endif @@ -243,11 +268,20 @@ static void OnError(int64_t requestId, int operationCode, int errorCode, const c (void)errorReturn; #ifdef MINE_HARMONY_HICHAIN if (requestId == CREATE_GROUP_REQUESTID) { - g_createGroupFlag = false; - UINT32 osRet = LOS_SemPost(g_createGroupSem); - if (osRet != LOS_OK) { - DMLOGE("failed to post create group semaphore with ret: %u.", osRet); - return; + if (operationCode == IMPORT_SELF_CREDENTIAL) { + g_createGroupFlag = false; + UINT32 osRet = LOS_SemPost(g_createGroupSem); + if (osRet != LOS_OK) { + DMLOGE("failed to post create group semaphore with ret: %u.", osRet); + return; + } + } else if (operationCode == DELETE_SELF_CREDENTIAL) { + g_deleteGroupFlag = false; + UINT32 osRet = LOS_SemPost(g_deleteGroupSem); + if (osRet != LOS_OK) { + DMLOGE("failed to post delete group semaphore with ret: %u.", osRet); + return; + } } } #endif @@ -460,6 +494,11 @@ static int DeleteCredentialAndGroup(void) DMLOGE("[hichian]failed to delete hichain credential and group with ret: %d.", retValue); return retValue; } + UINT32 osRet = LOS_SemPend(g_deleteGroupSem, HICHAIN_DELAY_TICK_COUNT); + if (osRet != LOS_OK || (osRet == LOS_OK && !g_deleteGroupFlag)) { + DMLOGE("failed to acquire semaphore or delete group with ret: %d or callback notify.", (int)osRet); + return retValue; + } return DM_OK; } -- Gitee From d132057e9292108b906bc0b1a037e0b0a3f9fa2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Mon, 27 May 2024 14:08:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=87=AD=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../inner_kits/native_cpp/src/mini/hichain_adapter.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/mini/hichain_adapter.c b/interfaces/inner_kits/native_cpp/src/mini/hichain_adapter.c index 0ed6afe9..41fbc1ef 100644 --- a/interfaces/inner_kits/native_cpp/src/mini/hichain_adapter.c +++ b/interfaces/inner_kits/native_cpp/src/mini/hichain_adapter.c @@ -106,7 +106,7 @@ int InitHichainModle(void) DMLOGE("failed to create group semaphore with ret: %d.", ret); retValue = ERR_DM_LITEOS_CREATE_MUTEX_OR_SEM; } - UINT32 osRet = LOS_BinarySemCreate(HICHAIN_SEM_INIT_COUNT, &g_deleteGroupSem); + osRet = LOS_BinarySemCreate(HICHAIN_SEM_INIT_COUNT, &g_deleteGroupSem); if (osRet != LOS_OK) { DMLOGE("failed to create group semaphore with ret: %d.", ret); retValue = ERR_DM_LITEOS_CREATE_MUTEX_OR_SEM; @@ -143,7 +143,7 @@ int UnInitHichainModle(void) } else { g_createGroupSem = LOSCFG_BASE_IPC_SEM_LIMIT; } - UINT32 osRet = LOS_SemDelete(g_deleteGroupSem); + osRet = LOS_SemDelete(g_deleteGroupSem); if (osRet != LOS_OK && osRet != LOS_ERRNO_SEM_INVALID) { DMLOGE("failed to delete group semaphore with ret: %d.", osRet); retValue = ERR_DM_LITEOS_DELETE_MUTEX_OR_SEM; @@ -245,6 +245,7 @@ static void OnFinish(int64_t requestId, int operationCode, const char *returnDat if (requestId == CREATE_GROUP_REQUESTID) { if (operationCode == IMPORT_SELF_CREDENTIAL) { g_createGroupFlag = true; + DMLOGI("create group successfully."); UINT32 osRet = LOS_SemPost(g_createGroupSem); if (osRet != LOS_OK) { DMLOGE("failed to post create group semaphore with ret: %u.", osRet); @@ -252,6 +253,7 @@ static void OnFinish(int64_t requestId, int operationCode, const char *returnDat } } else if (operationCode == DELETE_SELF_CREDENTIAL) { g_deleteGroupFlag = true; + DMLOGI("delete group successfully."); UINT32 osRet = LOS_SemPost(g_deleteGroupSem); if (osRet != LOS_OK) { DMLOGE("failed to post delete group semaphore with ret: %u.", osRet); @@ -270,6 +272,7 @@ static void OnError(int64_t requestId, int operationCode, int errorCode, const c if (requestId == CREATE_GROUP_REQUESTID) { if (operationCode == IMPORT_SELF_CREDENTIAL) { g_createGroupFlag = false; + DMLOGE("failed to create group."); UINT32 osRet = LOS_SemPost(g_createGroupSem); if (osRet != LOS_OK) { DMLOGE("failed to post create group semaphore with ret: %u.", osRet); @@ -277,6 +280,7 @@ static void OnError(int64_t requestId, int operationCode, int errorCode, const c } } else if (operationCode == DELETE_SELF_CREDENTIAL) { g_deleteGroupFlag = false; + DMLOGE("failed to delete group."); UINT32 osRet = LOS_SemPost(g_deleteGroupSem); if (osRet != LOS_OK) { DMLOGE("failed to post delete group semaphore with ret: %u.", osRet); -- Gitee