diff --git a/README_zh.md b/README_zh.md index 20ce0901d16a9471d3918717f3ae805f5a6b1b43..c3effb71ccb1516369e7ca0f841528c3faf9884d 100644 --- a/README_zh.md +++ b/README_zh.md @@ -12,7 +12,7 @@ ## 简介 -在OpenHarmony中,数据分级保护模块负责提供数据分级的保护策略。数据分级保护模块提供了数据分级相关的接口定义。(OpenHarmony当前不提供实际的功能实现。依赖设备厂商实现接口对应的功能,对搭载OpenHarmony的设备上的数据提供安全保护)。 +在OpenHarmony中,数据分级保护模块负责提供数据分级的保护策略。数据分级保护模块提供了数据分级相关的接口定义。 数据分级保护模块当前提供如下接口定义: @@ -66,7 +66,7 @@ base/security/dataclassification 1、编译依赖添加 ``` -external_deps += [ "datatransmitmgr:data_transit_mgr" ] +external_deps += [ "dataclassification:data_transit_mgr" ] ``` 2、头文件添加 diff --git a/frameworks/datatransmitmgr/dev_slinfo_adpt.c b/frameworks/datatransmitmgr/dev_slinfo_adpt.c index fe6ff67f9fcbefda18e650f38cf40bd8251356e0..48ff9646c329f8665c250f68ae13b8f63808a7fd 100644 --- a/frameworks/datatransmitmgr/dev_slinfo_adpt.c +++ b/frameworks/datatransmitmgr/dev_slinfo_adpt.c @@ -20,24 +20,27 @@ #include "dev_slinfo_log.h" #include "dev_slinfo_mgr.h" -void *g_deviceSecDlhandle = NULL; +void *g_deviceSecLevelHanle = NULL; DeviceSecEnv g_deviceSecEnv; static struct DATASLListParams *g_callback = NULL; static void DestroyDeviceSecEnv(void) { - if (g_deviceSecDlhandle != NULL) { + if (g_deviceSecLevelHanle != NULL) { (void)memset_s(&g_deviceSecEnv, sizeof(g_deviceSecEnv), 0, sizeof(g_deviceSecEnv)); - dlclose(g_deviceSecDlhandle); - g_deviceSecDlhandle = NULL; + dlclose(g_deviceSecLevelHanle); + g_deviceSecLevelHanle = NULL; + } + if (g_callback != NULL) { + ClearList(g_callback); } return; } static int32_t DlopenSDK(void) { - g_deviceSecDlhandle = dlopen("libdslm_sdk.z.so", RTLD_LAZY | RTLD_NODELETE); - if (!g_deviceSecDlhandle) { + g_deviceSecLevelHanle = dlopen("libdslm_sdk.z.so", RTLD_LAZY | RTLD_NODELETE); + if (g_deviceSecLevelHanle == NULL) { DATA_SEC_LOG_ERROR("failed to load libdevicesecmgrsdktmp: %s", dlerror()); return DEVSL_ERROR; } @@ -47,7 +50,7 @@ static int32_t DlopenSDK(void) static int32_t InitDeviceSecEnv(void) { - if (g_deviceSecDlhandle != NULL) { + if (g_deviceSecLevelHanle != NULL) { DATA_SEC_LOG_WARN("libdevicesecmgrsdk already loaded"); return SUCCESS; } @@ -56,34 +59,34 @@ static int32_t InitDeviceSecEnv(void) return ret; } RequestDeviceSecurityInfoFunction requestDeviceSecurityInfo = (RequestDeviceSecurityInfoFunction)dlsym( - g_deviceSecDlhandle, "RequestDeviceSecurityInfo"); - if (!requestDeviceSecurityInfo) { - dlclose(g_deviceSecDlhandle); - g_deviceSecDlhandle = NULL; + g_deviceSecLevelHanle, "RequestDeviceSecurityInfo"); + if (requestDeviceSecurityInfo == NULL) { + dlclose(g_deviceSecLevelHanle); + g_deviceSecLevelHanle = NULL; DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); return DEVSL_ERROR; } - FreeDeviceSecurityInfoFunction freeDeviceSecurityInfo = (FreeDeviceSecurityInfoFunction)dlsym(g_deviceSecDlhandle, + FreeDeviceSecurityInfoFunction freeDeviceSecurityInfo = (FreeDeviceSecurityInfoFunction)dlsym(g_deviceSecLevelHanle, "FreeDeviceSecurityInfo"); - if (!freeDeviceSecurityInfo) { - dlclose(g_deviceSecDlhandle); - g_deviceSecDlhandle = NULL; + if (freeDeviceSecurityInfo == NULL) { + dlclose(g_deviceSecLevelHanle); + g_deviceSecLevelHanle = NULL; DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); return DEVSL_ERROR; } GetDeviceSecurityLevelValueFunction getDeviceSecurityLevelValue = (GetDeviceSecurityLevelValueFunction)dlsym( - g_deviceSecDlhandle, "GetDeviceSecurityLevelValue"); - if (!getDeviceSecurityLevelValue) { - dlclose(g_deviceSecDlhandle); - g_deviceSecDlhandle = NULL; + g_deviceSecLevelHanle, "GetDeviceSecurityLevelValue"); + if (getDeviceSecurityLevelValue == NULL) { + dlclose(g_deviceSecLevelHanle); + g_deviceSecLevelHanle = NULL; DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); return DEVSL_ERROR; } RequestDeviceSecurityInfoAsyncFunction requestDeviceSecurityInfoAsync = - (RequestDeviceSecurityInfoAsyncFunction)dlsym(g_deviceSecDlhandle, "RequestDeviceSecurityInfoAsync"); - if (!requestDeviceSecurityInfoAsync) { - dlclose(g_deviceSecDlhandle); - g_deviceSecDlhandle = NULL; + (RequestDeviceSecurityInfoAsyncFunction)dlsym(g_deviceSecLevelHanle, "RequestDeviceSecurityInfoAsync"); + if (requestDeviceSecurityInfoAsync == NULL) { + dlclose(g_deviceSecLevelHanle); + g_deviceSecLevelHanle = NULL; DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); return DEVSL_ERROR; } @@ -103,12 +106,26 @@ int32_t StartDevslEnv() if (ret != SUCCESS) { return DEVSL_ERR_DEVICE_SEC_SDK_INIT; } + + if (g_callback == NULL) { + ret = InitPthreadMutex(); + g_callback = InitList(); + } + + if (ret != SUCCESS) { + return DEVSL_ERR_INIT_MUTEX_LOCK; + } + + if (g_callback == NULL) { + return DEVSL_ERR_MALLOC_FAIL; + } return SUCCESS; } void FinishDevslEnv(void) { DestroyDeviceSecEnv(); + DestroyPthreadMutex(); return; } @@ -116,17 +133,17 @@ int32_t GetDeviceSecLevelByUdid(uint8_t *udid, uint32_t udidLen, int32_t *devLev { DATA_SEC_LOG_INFO("Enter GetDeviceSecLevelByUdid!"); if (g_deviceSecEnv.requestDeviceSecurityInfo == NULL) { - DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid: requestDeviceSecurityInfo is incalid"); + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid: requestDeviceSecurityInfo is invalid"); return DEVSL_ERROR; } if (g_deviceSecEnv.freeDeviceSecurityInfo == NULL) { - DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid: freeDeviceSecurityInfo is incalid"); + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdid: freeDeviceSecurityInfo is invalid"); return DEVSL_ERROR; } if (g_deviceSecEnv.getDeviceSecurityLevelValue == NULL) { - DATA_SEC_LOG_ERROR("GetDeviceSecByUdid: getDeviceSecurityLevelValue is incalid"); + DATA_SEC_LOG_ERROR("GetDeviceSecByUdid: getDeviceSecurityLevelValue is invalid"); return DEVSL_ERROR; } @@ -164,62 +181,60 @@ int32_t GetDeviceSecLevelByUdid(uint8_t *udid, uint32_t udidLen, int32_t *devLev // Async void OnApiDeviceSecInfoCallback(const DeviceIdentify *identify, struct DeviceSecurityInfo *info) { - pthread_mutex_lock(&gMutex); DATA_SEC_LOG_INFO("Enter OnApiDeviceSecInfoCallback!"); - int32_t ret; + if (identify == NULL) { + DATA_SEC_LOG_INFO("OnApiDeviceSecInfoCallback: DeviceIdentify is null!"); + return; + } + int32_t ret = DEVSL_SUCCESS; + if (info == NULL) { + DATA_SEC_LOG_INFO("OnApiDeviceSecInfoCallback: DeviceSecurityInfo is null!"); + ret = DEVSL_ERROR; + } if (g_deviceSecEnv.getDeviceSecurityLevelValue == NULL) { - DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback: getDeviceSecValue is incalid"); + DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback: getDeviceSecValue is invalid"); ret = DEVSL_ERROR; } if (g_deviceSecEnv.freeDeviceSecurityInfo == NULL) { - DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback: freeDeviceSecurityInfo is incalid"); + DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback: freeDeviceSecurityInfo is invalid"); ret = DEVSL_ERROR; } int32_t devLevel = DEFAULT_DEV_SEC_LEVEL; - uint32_t levelInfo = DEFAULT_DEV_SEC_LEVEL; - ret = g_deviceSecEnv.getDeviceSecurityLevelValue(info, &devLevel); - if (ret != SUCCESS) { - DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback, get device security level value, %d", ret); - } else { - levelInfo = GetDataSecLevelByDevSecLevel(devLevel); + uint32_t levelInfo = DATA_SEC_LEVEL0; + + if (ret != DEVSL_ERROR) { + ret = g_deviceSecEnv.getDeviceSecurityLevelValue(info, &devLevel); + if (ret != SUCCESS) { + DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback, get device security level value, %d", ret); + } else { + levelInfo = GetDataSecLevelByDevSecLevel(devLevel); + } + g_deviceSecEnv.freeDeviceSecurityInfo(info); } - g_deviceSecEnv.freeDeviceSecurityInfo(info); DEVSLQueryParams queryParams; (void)memset_s(&queryParams, sizeof(queryParams), 0, sizeof(queryParams)); if (memcpy_s(queryParams.udid, DEVICE_ID_MAX_LEN, identify->identity, identify->length) != EOK) { DATA_SEC_LOG_ERROR("OnApiDeviceSecInfoCallback, udid memcpy failed"); - pthread_mutex_unlock(&gMutex); return; } queryParams.udidLen = identify->length; if (g_callback != NULL) { - struct DATASLListParams *tmpCallback = g_callback->next; - while (tmpCallback != NULL && tmpCallback != g_callback) { - struct DATASLListParams *nextCallback = tmpCallback->next; - int32_t result = UdidCmp(tmpCallback->callbackParams->queryParams, &queryParams); - if (result == SUCCESS) { - tmpCallback->callbackParams->callback(&queryParams, ret, levelInfo); - ListPop(g_callback, tmpCallback->callbackParams); - } - tmpCallback = nextCallback; - } + LookupCallback(g_callback, &queryParams, ret, levelInfo); } - DATA_SEC_LOG_INFO("OnApiDeviceSecInfoCallback done, ret %d!", ret); - pthread_mutex_unlock(&gMutex); } int32_t GetDeviceSecLevelByUdidAsync(uint8_t *udid, uint32_t udidLen) { DATA_SEC_LOG_INFO("Enter GetDeviceSecLevelByUdidAsync!"); if (g_deviceSecEnv.requestDeviceSecurityInfoAsync == NULL) { - DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdidAsync: requestDeviceSecurityInfoAsync is incalid"); + DATA_SEC_LOG_ERROR("GetDeviceSecLevelByUdidAsync: requestDeviceSecurityInfoAsync is invalid"); return DEVSL_ERROR; } @@ -242,9 +257,11 @@ int32_t GetDeviceSecLevelByUdidAsync(uint8_t *udid, uint32_t udidLen) return ret; } -int32_t UdidCmp(DEVSLQueryParams *queryParamsL, DEVSLQueryParams *queryParamsR) +int32_t CompareUdid(DEVSLQueryParams *queryParamsL, DEVSLQueryParams *queryParamsR) { + DATA_SEC_LOG_INFO("DATASL: Enter CompareUdid!"); uint32_t i; + if (queryParamsL->udidLen != queryParamsR->udidLen) { return DEVSL_ERROR; } @@ -283,28 +300,36 @@ int32_t GetDataSecLevelByDevSecLevel(int32_t devLevel) return DATA_SEC_LEVEL0; } -int32_t UpdateCallback(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback) +int32_t UpdateCallbackListParams(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback) { int32_t ret; int32_t result = DEVSL_ERR_SERVICES_TOO_MANY; int32_t levelInfo = DEFAULT_DEV_SEC_LEVEL; - if (g_callback == NULL) { - g_callback = ListInit(); - } - struct DATASLCallbackParams newList; - newList.queryParams = queryParams; - newList.callback = callback; + struct DATASLCallbackParams *newListNode = + (struct DATASLCallbackParams*)malloc(sizeof(struct DATASLCallbackParams)); + if (newListNode == NULL) { + return DEVSL_ERR_MALLOC_FAIL; + } + if (memcpy_s(newListNode->queryParams.udid, MAX_UDID_LENGTH, queryParams->udid, queryParams->udidLen) != EOK) { + DATA_SEC_LOG_ERROR("UpdateCallbackListParams, udid memcpy failed"); + return DEVSL_ERR_MEM_CPY; + } + newListNode->queryParams.udidLen = queryParams->udidLen; + newListNode->callback = callback; - ret = ListLength(g_callback); + ret = GetListLength(g_callback); if (ret == MAX_LIST_SUM) { g_callback->next->callbackParams->callback(queryParams, result, levelInfo); - ListPop(g_callback, g_callback->next->callbackParams); + PopList(g_callback, g_callback->next->callbackParams); } - ret = ListFind(g_callback, &newList); + ret = FindList(g_callback, newListNode); if (ret != SUCCESS) { - ListPush(g_callback, &newList); + ret = PushList(g_callback, newListNode); + if (ret != SUCCESS) { + return ret; + } } return SUCCESS; } \ No newline at end of file diff --git a/frameworks/datatransmitmgr/dev_slinfo_list.c b/frameworks/datatransmitmgr/dev_slinfo_list.c index e4fc7fa6f9ae600b84b78a7f00bc6af40979bf18..8d0e351bff23b355352796a410ae2e8f7064b775 100644 --- a/frameworks/datatransmitmgr/dev_slinfo_list.c +++ b/frameworks/datatransmitmgr/dev_slinfo_list.c @@ -14,21 +14,27 @@ */ #include "dev_slinfo_list.h" +#include #include "dev_slinfo_adpt.h" #include "dev_slinfo_log.h" -struct DATASLListParams* ListInit(void) +pthread_mutex_t gMutex; + +struct DATASLListParams* InitList(void) { pthread_mutex_lock(&gMutex); - struct DATASLListParams *list; - list = (struct DATASLListParams *)malloc(sizeof(struct DATASLListParams)); + struct DATASLListParams *list = (struct DATASLListParams *)malloc(sizeof(struct DATASLListParams)); + if (list == NULL) { + pthread_mutex_unlock(&gMutex); + return NULL; + } list->next = list; list->prev = list; pthread_mutex_unlock(&gMutex); return list; } -void Update(struct DATASLListParams *new, struct DATASLListParams *prev, struct DATASLListParams *next) +static void Update(struct DATASLListParams *new, struct DATASLListParams *prev, struct DATASLListParams *next) { next->prev = new; new->next = next; @@ -36,11 +42,15 @@ void Update(struct DATASLListParams *new, struct DATASLListParams *prev, struct prev->next = new; } -void ListPush(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) +int32_t PushList(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) { - DATA_SEC_LOG_INFO("ListPush, ret!"); + DATA_SEC_LOG_INFO("PushList, ret!"); pthread_mutex_lock(&gMutex); struct DATASLListParams *newList = (struct DATASLListParams*)malloc(sizeof(struct DATASLListParams)); + if (newList == NULL) { + pthread_mutex_unlock(&gMutex); + return DEVSL_ERR_MALLOC_FAIL; + } if (list->prev == NULL) { list->prev = newList; list->next = newList; @@ -51,41 +61,43 @@ void ListPush(struct DATASLListParams *list, struct DATASLCallbackParams *callba } newList->callbackParams = (struct DATASLCallbackParams*)callbackParams; pthread_mutex_unlock(&gMutex); - DATA_SEC_LOG_INFO("ListPush done, ret!"); + DATA_SEC_LOG_INFO("PushList done, ret!"); + return SUCCESS; } -void ListPop(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) +void PopList(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) { - DATA_SEC_LOG_INFO("ListPop, ret!"); + DATA_SEC_LOG_INFO("PopList, ret!"); pthread_mutex_lock(&gMutex); struct DATASLListParams *pList = list->next; while (pList != NULL && pList != list) { - if (UdidCmp(pList->callbackParams->queryParams, - ((struct DATASLCallbackParams*)callbackParams)->queryParams) == SUCCESS) { + if (CompareUdid(&(pList->callbackParams->queryParams), &(callbackParams->queryParams)) == SUCCESS) { pList->prev->next = pList->next; pList->next->prev = pList->prev; + free(pList->callbackParams); free(pList); break; } pList = pList->next; } pthread_mutex_unlock(&gMutex); - DATA_SEC_LOG_INFO("ListPop done, ret!"); + DATA_SEC_LOG_INFO("PopList done, ret!"); } -void ListClear(struct DATASLListParams *list) +void ClearList(struct DATASLListParams *list) { pthread_mutex_lock(&gMutex); struct DATASLListParams *pList = list->next; while (pList == NULL || pList != list) { struct DATASLListParams *delList = pList; pList = pList->next; + free(delList->callbackParams); free(delList); } pthread_mutex_unlock(&gMutex); } -int32_t ListLength(struct DATASLListParams *list) +int32_t GetListLength(struct DATASLListParams *list) { pthread_mutex_lock(&gMutex); struct DATASLListParams *pList = list->next; @@ -98,21 +110,53 @@ int32_t ListLength(struct DATASLListParams *list) return listLength; } -int32_t ListFind(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) +int32_t FindList(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams) { pthread_mutex_lock(&gMutex); - DATA_SEC_LOG_INFO("ListFind, ret!"); + DATA_SEC_LOG_INFO("DATASL: FindList, ret!"); struct DATASLListParams *pList = list->next; + DATA_SEC_LOG_INFO("DATASL: list is not NULL!"); while (pList != NULL && pList != list) { - if (UdidCmp(pList->callbackParams->queryParams, - ((struct DATASLCallbackParams*)callbackParams)->queryParams) == SUCCESS) { - DATA_SEC_LOG_INFO("ListFind fine done, ret!"); + DATA_SEC_LOG_INFO("DATASL: while is ok!"); + if (CompareUdid(&(pList->callbackParams->queryParams), &(callbackParams->queryParams)) == SUCCESS) { + DATA_SEC_LOG_INFO("FindList fine done, ret!"); pthread_mutex_unlock(&gMutex); return SUCCESS; } pList = pList->next; } - DATA_SEC_LOG_INFO("ListFind not find, ret!"); + DATA_SEC_LOG_INFO("FindList not find, ret!"); pthread_mutex_unlock(&gMutex); return DEVSL_ERROR; +} + +void LookupCallback(struct DATASLListParams *list, DEVSLQueryParams *queryParams, int32_t result, uint32_t levelInfo) +{ + pthread_mutex_lock(&gMutex); + struct DATASLListParams *tmpCallback = list->next; + while (tmpCallback != NULL && tmpCallback != list) { + struct DATASLListParams *nextCallback = tmpCallback->next; + int32_t result = CompareUdid(&(tmpCallback->callbackParams->queryParams), queryParams); + if (result == SUCCESS) { + tmpCallback->callbackParams->callback(&(tmpCallback->callbackParams->queryParams), result, levelInfo); + tmpCallback->prev->next = tmpCallback->next; + tmpCallback->next->prev = tmpCallback->prev; + free(tmpCallback->callbackParams); + free(tmpCallback); + } + tmpCallback = nextCallback; + } + pthread_mutex_unlock(&gMutex); +} + +int32_t InitPthreadMutex(void) +{ + int32_t ret; + ret = pthread_mutex_init(&gMutex, NULL); + return ret; +} + +void DestroyPthreadMutex(void) +{ + pthread_mutex_destroy(&gMutex); } \ No newline at end of file diff --git a/frameworks/datatransmitmgr/dev_slinfo_mgr.c b/frameworks/datatransmitmgr/dev_slinfo_mgr.c index bc38c7db5519017692b1240c3b2cb5d1283e23e3..664e6a1fc2727b0262322e0e5bd1aa6227ae739b 100644 --- a/frameworks/datatransmitmgr/dev_slinfo_mgr.c +++ b/frameworks/datatransmitmgr/dev_slinfo_mgr.c @@ -45,7 +45,7 @@ static int32_t GetHigestSecLevelByUdid(DEVSLQueryParams *queryParams, uint32_t * DEVSL_API int32_t DATASL_OnStart(void) { - int32_t ret = 0; + int32_t ret; DATA_SEC_LOG_INFO("Enter DATASL_Onstart"); ret = StartDevslEnv(); @@ -109,7 +109,11 @@ DEVSL_API int32_t DATASL_GetHighestSecLevelAsync(DEVSLQueryParams *queryParams, return ERR_INVALID_PARA; } - ret = UpdateCallback(queryParams, callback); + ret = UpdateCallbackListParams(queryParams, callback); + if (ret != SUCCESS) { + return ret; + } + ret = GetHighestSecLevelByUdidAsync(queryParams); DATA_SEC_LOG_INFO("DATASL_GetHighestSecLevelAsync done, ret %d!", ret); return ret; diff --git a/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_adpt.h b/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_adpt.h index 9f0a68bdf7d7f94f84b74744c082b5773daa8f2f..6a8bc10faad90bf34569c3c6c04b44358e2b56f2 100644 --- a/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_adpt.h +++ b/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_adpt.h @@ -56,13 +56,13 @@ void FinishDevslEnv(void); int32_t GetDeviceSecLevelByUdid(uint8_t *udid, uint32_t udidLen, int32_t *devLevel); -int32_t UdidCmp(DEVSLQueryParams *queryParamsL, DEVSLQueryParams *queryParamsR); +int32_t CompareUdid(DEVSLQueryParams *queryParamsL, DEVSLQueryParams *queryParamsR); int32_t GetDeviceSecLevelByUdidAsync(uint8_t *udid, uint32_t udidLen); int32_t GetDataSecLevelByDevSecLevel(int32_t devLevel); -int32_t UpdateCallback(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback); +int32_t UpdateCallbackListParams(DEVSLQueryParams *queryParams, HigestSecInfoCallback *callback); #ifdef __cplusplus } diff --git a/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_list.h b/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_list.h index 64523f758c1eb20cb1e2f8b435108e7bb8308d5e..f7997d032408ac22f478ce8c71af92c00ac3d5db 100644 --- a/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_list.h +++ b/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_list.h @@ -16,15 +16,11 @@ #ifndef DEV_SLINFO_LIST_H #define DEV_SLINFO_LIST_H -#include "dev_slinfo_mgr.h" - #include -#include - -static pthread_mutex_t gMutex = PTHREAD_MUTEX_INITIALIZER; +#include "dev_slinfo_mgr.h" struct DATASLCallbackParams { - DEVSLQueryParams *queryParams; + DEVSLQueryParams queryParams; HigestSecInfoCallback *callback; }; @@ -34,16 +30,22 @@ struct DATASLListParams { struct DATASLListParams *next; }; -struct DATASLListParams* ListInit(void); +struct DATASLListParams* InitList(void); + +int32_t PushList(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); + +void PopList(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); + +void ClearList(struct DATASLListParams *list); -void ListPush(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); +int GetListLength(struct DATASLListParams *list); -void ListPop(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); +int32_t FindList(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); -void ListClear(struct DATASLListParams *list); +int32_t InitPthreadMutex(void); -int ListLength(struct DATASLListParams *list); +void DestroyPthreadMutex(void); -int32_t ListFind(struct DATASLListParams *list, struct DATASLCallbackParams *callbackParams); +void LookupCallback(struct DATASLListParams *list, DEVSLQueryParams *queryParams, int32_t result, uint32_t levelInfo); #endif \ No newline at end of file diff --git a/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_mgr.h b/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_mgr.h index 033b6a7607c8e0bb9c26adfdac991482fad18f5f..612e4dff98a100256f22dfff50e046436edf5b3d 100644 --- a/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_mgr.h +++ b/interfaces/innerkits/datatransmitmgr/include/dev_slinfo_mgr.h @@ -44,6 +44,9 @@ enum { DEVSL_ERR_REPEATED_SERVICES = 103, DEVSL_ERR_MEM_CPY = 104, DEVSL_ERR_DEVICE_SEC_SDK_INIT = 105, + DEVSL_ERR_MALLOC_FAIL = 106, + DEVSL_MUTEX_UNLOCK = 107, + DEVSL_ERR_INIT_MUTEX_LOCK = 108, }; int32_t DATASL_GetHighestSecLevel(DEVSLQueryParams *queryParams, uint32_t *levelInfo); diff --git a/test/unittest/datatransmitmgr/DevSLMgrTest.cpp b/test/unittest/datatransmitmgr/DevSLMgrTest.cpp index 0ea7542b94ce5e6c1ee529bbaf0e6f2d71749525..d5132c80bc750121d5db44d78eff4d88e3488b3c 100644 --- a/test/unittest/datatransmitmgr/DevSLMgrTest.cpp +++ b/test/unittest/datatransmitmgr/DevSLMgrTest.cpp @@ -124,7 +124,6 @@ static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelAsync002, TestSize.Level1) static void tmpCallback(DEVSLQueryParams *queryParams, int32_t result, uint32_t levelInfo) { - printf("yes\n"); EXPECT_EQ(ERR_NOEXIST_DEVICE, result); EXPECT_EQ(DATA_SEC_LEVEL0, static_cast(levelInfo)); } @@ -136,5 +135,6 @@ static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelAsync003, TestSize.Level1) DATASL_GetUdidByOpp(&queryParams); ret = DATASL_GetHighestSecLevelAsync(&queryParams, &tmpCallback); + EXPECT_EQ(ERR_NOEXIST_DEVICE, ret); DATASL_OnStop(); } \ No newline at end of file