From ed8fb29856754c8aa1ef1474223346b3b6c1963a Mon Sep 17 00:00:00 2001 From: anyueling Date: Thu, 1 Jun 2023 11:48:30 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Request.FileTransferAgent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: anyueling --- include/codec_config/syscap_define.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 6ac6632..2eda1d3 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -285,6 +285,7 @@ typedef enum SystemCapabilityNum { WINDOW_WINDOW_MANAGER_LITE, DRIVER_DEVICEMANAGER_EXTENSION, FILEMANAGEMENT_DISTRIBUTEDFILESERVICE_CLOUDSYNC_CORE, + REQUEST_FILETRANSFERAGENT, // Add before here SYSCAP_BASIC_END = 500 } SyscapNum; @@ -552,6 +553,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Driver.DeviceManager.Extension", DRIVER_DEVICEMANAGER_EXTENSION}, {"SystemCapability.FileManagement.DistributedFileService.CloudSync.Core", FILEMANAGEMENT_DISTRIBUTEDFILESERVICE_CLOUDSYNC_CORE}, + {"SystemCapability.Request.FileTransferAgent", REQUEST_FILETRANSFERAGENT}, }; #ifdef __cplusplus From 8e48ffa929103d1f22c7e997b84c52920cd87396 Mon Sep 17 00:00:00 2001 From: yudechen Date: Fri, 2 Jun 2023 10:37:36 +0800 Subject: [PATCH 2/7] =?UTF-8?q?chore:=20=E5=91=8A=E8=AD=A6=E6=B8=85?= =?UTF-8?q?=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yudechen Change-Id: Ic49b6c5dbcc3744fe8dad80f52e9db0cbe994a88 --- tools/syscap_config_merge.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/syscap_config_merge.py b/tools/syscap_config_merge.py index 045d869..ea0cd33 100755 --- a/tools/syscap_config_merge.py +++ b/tools/syscap_config_merge.py @@ -70,6 +70,7 @@ after_struct = ''' #endif // SYSCAP_DEFINE_H ''' + def gen_define_enum(enum:list): header = 'typedef enum SystemCapabilityNum {\n' tail = '} SyscapNum;\n\n' From 1c50ccc32632d0203239672c4dacf8860958660f Mon Sep 17 00:00:00 2001 From: xuxiaoqing Date: Wed, 7 Jun 2023 06:29:51 +0000 Subject: [PATCH 3/7] fix: add syscap SystemCapability.Driver.HID.Extension and SystemCapability.Driver.USB.Extension Signed-off-by: xuxiaoqing --- include/codec_config/syscap_define.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 2eda1d3..46fe1f3 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -286,6 +286,8 @@ typedef enum SystemCapabilityNum { DRIVER_DEVICEMANAGER_EXTENSION, FILEMANAGEMENT_DISTRIBUTEDFILESERVICE_CLOUDSYNC_CORE, REQUEST_FILETRANSFERAGENT, + DRIVER_HID_EXTENSION, + DRIVER_USB_EXTENSION, // Add before here SYSCAP_BASIC_END = 500 } SyscapNum; @@ -554,6 +556,8 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.FileManagement.DistributedFileService.CloudSync.Core", FILEMANAGEMENT_DISTRIBUTEDFILESERVICE_CLOUDSYNC_CORE}, {"SystemCapability.Request.FileTransferAgent", REQUEST_FILETRANSFERAGENT}, + {"SystemCapability.Driver.HID.Extension", DRIVER_HID_EXTENSION}, + {"SystemCapability.Driver.USB.Extension", DRIVER_USB_EXTENSION}, }; #ifdef __cplusplus From 0e638ff9019870045be5d5888beb2f78a0e0636f Mon Sep 17 00:00:00 2001 From: BruceZong Date: Thu, 8 Jun 2023 21:09:58 +0800 Subject: [PATCH 4/7] add LogLibrary Capacity Signed-off-by: BruceZong --- include/codec_config/syscap_define.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 2eda1d3..42a5136 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -286,6 +286,7 @@ typedef enum SystemCapabilityNum { DRIVER_DEVICEMANAGER_EXTENSION, FILEMANAGEMENT_DISTRIBUTEDFILESERVICE_CLOUDSYNC_CORE, REQUEST_FILETRANSFERAGENT, + HIVIEWDFX_HIVIEW_LOGLIBRARY, // Add before here SYSCAP_BASIC_END = 500 } SyscapNum; @@ -356,6 +357,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.HiviewDFX.HiTrace", HIVIEWDFX_HITRACE}, {"SystemCapability.HiviewDFX.Hiview", HIVIEWDFX_HIVIEW}, {"SystemCapability.HiviewDFX.Hiview.FaultLogger", HIVIEWDFX_HIVIEW_FAULTLOGGER}, + {"SystemCapability.HiviewDFX.Hiview.LogLibrary", HIVIEWDFX_HIVIEW_LOGLIBRARY}, {"SystemCapability.HiviewDFX.HiviewLite", HIVIEWDFX_HIVIEWLITE}, {"SystemCapability.Global.I18n", GLOBAL_I18N}, {"SystemCapability.Kernel.Linux", KERNEL_LINUX}, From d58bb664c1df793e81f9ca5188484974e2d71b6b Mon Sep 17 00:00:00 2001 From: yudechen Date: Tue, 20 Jun 2023 15:03:41 +0800 Subject: [PATCH 5/7] chore: modify for standard python code style. Signed-off-by: yudechen Change-Id: I47e0ce78facb06830511ef744413327128989e47 --- include/codec_config/syscap_define.h | 2 +- tools/syscap_config_merge.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 6ac6632..c0b4e14 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -286,7 +286,7 @@ typedef enum SystemCapabilityNum { DRIVER_DEVICEMANAGER_EXTENSION, FILEMANAGEMENT_DISTRIBUTEDFILESERVICE_CLOUDSYNC_CORE, // Add before here - SYSCAP_BASIC_END = 500 + SYSCAP_BASIC_END = 500, } SyscapNum; diff --git a/tools/syscap_config_merge.py b/tools/syscap_config_merge.py index ea0cd33..df1c971 100755 --- a/tools/syscap_config_merge.py +++ b/tools/syscap_config_merge.py @@ -15,13 +15,11 @@ ''' 注意: -1. base 的枚举定义,须在末尾标记最大值。 -2. extern 的枚举定义,须在开始位置标记最大值。 -3. base 的 syscap 数组,必须以逗号(),)结尾。 +1. 扩展syscap头文件的枚举定义,须在开始位置标记最小值,且必须大于等于500。 ''' import argparse -licence = '''/* +LICENCE = '''/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +36,7 @@ licence = '''/* ''' -before_enum = '''#ifndef SYSCAP_DEFINE_H +BEFORE_ENUM = '''#ifndef SYSCAP_DEFINE_H #define SYSCAP_DEFINE_H #include @@ -61,7 +59,7 @@ typedef struct SystemCapabilityWithNum { */ ''' -after_struct = ''' +AFTER_STRUCT = ''' #ifdef __cplusplus #if __cplusplus } @@ -131,7 +129,7 @@ def assemble_header_file(fenum, fstru): enum, stru = merge_define(fenum, fstru) enum_def = gen_define_enum(enum) stru_def = gen_define_array(stru) - return licence + before_enum + enum_def + stru_def + after_struct + return LICENCE + BEFORE_ENUM + enum_def + stru_def + AFTER_STRUCT def parse_args(): From 1f03542c84ef01640306f72dff914308274e3e7c Mon Sep 17 00:00:00 2001 From: yudechen Date: Mon, 26 Jun 2023 11:30:18 +0800 Subject: [PATCH 6/7] refoctor: refoctor the code to reduce function complexity. Signed-off-by: yudechen Change-Id: I9abd347e414395c44300a8e927332f7101c05c38 --- interfaces/inner_api/syscap_interface.c | 44 +-- src/create_pcid.c | 489 +++++++++++++----------- src/main.c | 3 +- src/syscap_tool.c | 208 +++++----- 4 files changed, 398 insertions(+), 346 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 7ae22a3..e98c396 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -242,53 +242,52 @@ bool DecodeOsSyscap(const char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SY return true; } -bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt) +int32_t GetPriSyscapCount(char *input) { - char (*outputArray)[SINGLE_SYSCAP_LEN] = NULL; + int32_t syscapCnt = 0; + char *inputPos = input; - int bufferLen, ret; - int syscapCnt = 0; - - if (input == NULL) { - *output = outputArray; - *outputCnt = syscapCnt; - return false; - } - while (*inputPos != '\0') { if (*inputPos == ',') { syscapCnt++; } inputPos++; } + + return syscapCnt; +} + +bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt) +{ + char *inputPos = input; + char (*outputArray)[SINGLE_SYSCAP_LEN] = NULL; + + if (input == NULL) { + return false; + } + + int syscapCnt = GetPriSyscapCount(inputPos); + *outputCnt = syscapCnt; if (syscapCnt == 0) { - *output = outputArray; - *outputCnt = syscapCnt; return true; } - inputPos = input; - bufferLen = SINGLE_SYSCAP_LEN * syscapCnt; + int bufferLen = SINGLE_SYSCAP_LEN * syscapCnt; outputArray = (char (*)[SINGLE_SYSCAP_LEN])malloc(bufferLen); if (outputArray == NULL) { - PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", bufferLen, errno); - *outputCnt = 0; return false; } (void)memset_s(outputArray, bufferLen, 0, bufferLen); *output = outputArray; + inputPos = input; char buffer[SINGLE_FEAT_LEN] = {0}; char *bufferPos = buffer; while (*inputPos != '\0') { if (*inputPos == ',') { *bufferPos = '\0'; - ret = sprintf_s(*outputArray, SINGLE_SYSCAP_LEN, "SystemCapability.%s", buffer); - if (ret == -1) { - PRINT_ERR("sprintf_s failed\n"); - *outputCnt = 0; + if (sprintf_s(*outputArray, SINGLE_SYSCAP_LEN, "SystemCapability.%s", buffer) == -1) { free(outputArray); - outputArray = NULL; return false; } bufferPos = buffer; @@ -299,7 +298,6 @@ bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *o *bufferPos++ = *inputPos++; } - *outputCnt = syscapCnt; return true; } diff --git a/src/create_pcid.c b/src/create_pcid.c index ee66a22..744bc59 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -167,82 +167,171 @@ static cJSON *CreateWholeSyscapJsonObj(void) return root; } -int32_t CreatePCID(char *inputFile, char *outDirPath) +int32_t SetOsSyscap(PCIDMain *pcidBuffer, uint32_t osCapSize, + const cJSON *jsonOsSyscapObj, const cJSON *allOsSyscapObj) { - int32_t ret, sectorOfBits, posOfBits; - uint32_t i, privateCapSize, osCapSize; - size_t contextBufLen; - errno_t nRet = 0; - char *contextBuffer = NULL; - char *systemType = NULL; - cJSON *jsonRootObj = NULL; - cJSON *jsonSyscapObj = NULL; - cJSON *jsonOsSyscapObj = NULL; - cJSON *jsonPriSyscapObj = NULL; + int32_t sectorOfBits, posOfBits; cJSON *jsonArrayItem = NULL; cJSON *osCapIndex = NULL; - cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); - ret = GetFileContext(inputFile, &contextBuffer, &contextBufLen); - if (ret != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); + for (uint32_t i = 0; i < osCapSize; i++) { + jsonArrayItem = cJSON_GetArrayItem(jsonOsSyscapObj, (int)i); + osCapIndex = cJSON_GetObjectItem(allOsSyscapObj, jsonArrayItem->valuestring); + if (osCapIndex == NULL) { + PRINT_ERR("can't find the syscap: %s, please add it in syscap_define.h.\n", jsonArrayItem->valuestring); + return -1; + } + sectorOfBits = (osCapIndex->valueint) / UINT8_BIT; + posOfBits = (osCapIndex->valueint) % UINT8_BIT; + if (sectorOfBits >= OS_SYSCAP_BYTES) { + PRINT_ERR("num of \"os syscap\" is out of 960\n"); + return -1; + } + pcidBuffer->osSyscap[sectorOfBits] |= 1 << (posOfBits); + } + + return 0; +} + +int32_t SetPriSyscap(PCIDMain *pcidBuffer, cJSON *jsonPriSyscapObj, + uint32_t privateCapSize, uint16_t allPriSyscapStrLen) +{ + char *priSyscapHead = (char *)(pcidBuffer + 1); + char *priSyscapStr = NULL; + for (uint32_t i = 0; i < privateCapSize; i++) { + cJSON *jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, (int)i); + priSyscapStr = strchr(jsonArrayItem->valuestring, '.') + 1; + errno_t nRet = strcat_s(priSyscapHead, allPriSyscapStrLen + 1, priSyscapStr); + nRet += strcat_s(priSyscapHead, allPriSyscapStrLen + 1, ","); + if (nRet != EOK) { + PRINT_ERR("strcat_s \"pri\" string is failed\n"); + return -1; + } + } + return 0; +} + +int32_t SetPCIDHeader(PCIDMain *pcidBuffer, const cJSON *jsonRootObj) +{ + cJSON *jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "api_version"); + if (jsonSyscapObj == NULL || !cJSON_IsNumber(jsonSyscapObj)) { + PRINT_ERR("get \"api_version\" failed\n"); + return -1; + } + pcidBuffer->apiVersion = HtonsInter((uint16_t)jsonSyscapObj->valueint); + pcidBuffer->apiVersionType = 0; + + jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "system_type"); + if (jsonSyscapObj == NULL || !cJSON_IsString(jsonSyscapObj)) { + PRINT_ERR("get \"system_type\" failed\n"); + return -1; + } + char *systemType = jsonSyscapObj->valuestring; + pcidBuffer->systemType = !strcmp(systemType, "mini") ? 0b001 : + (!strcmp(systemType, "small") ? 0b010 : + (!strcmp(systemType, "standard") ? 0b100 : 0)); + if (pcidBuffer->systemType == 0) { + PRINT_ERR("\"system_type\" is invaild, systemType = \"%s\"\n", systemType); return -1; } - jsonRootObj = cJSON_ParseWithLength(contextBuffer, contextBufLen); + jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "manufacturer_id"); + if (jsonSyscapObj == NULL || !cJSON_IsNumber(jsonSyscapObj)) { + PRINT_ERR("get \"manufacturer_id\" failed\n"); + return -1; + } + pcidBuffer->manufacturerID = HtonlInter((uint32_t)jsonSyscapObj->valueint); + + return 0; +} + +int32_t GetOsAndPriSyscapSize(const cJSON *osSyscap, const cJSON *priSyscap, + uint32_t *osCapSize, uint32_t *privateCapSize) +{ + *osCapSize = 0; + *privateCapSize = 0; + + // get os syscap size + if (osSyscap == NULL || !cJSON_IsArray(osSyscap)) { + PRINT_ERR("get \"os\" array failed\n"); + return -1; + } + int32_t ret = cJSON_GetArraySize(osSyscap); + if (ret < 0) { + PRINT_ERR("get \"os\" array size failed\n"); + return -1; + } + *osCapSize = (uint32_t)ret; + + // get private syscap size + if (priSyscap != NULL && cJSON_IsArray(priSyscap)) { + ret = cJSON_GetArraySize(priSyscap); + if (ret < 0) { + PRINT_ERR("get \"private syscap\" array size failed\n"); + return -1; + } + *privateCapSize = (uint32_t)ret; + } else if (priSyscap == NULL) { + *privateCapSize = 0; + } else { + PRINT_ERR("get \"private\" array failed\n"); + return -1; + } + + return 0; +} + +int32_t GetPriSyscapLen(uint32_t privateCapSize, cJSON *jsonPriSyscapObj, uint16_t *len) +{ + for (uint32_t i = 0; i < privateCapSize; i++) { + cJSON *jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, (int)i); + *len += (uint16_t)strlen(strchr(jsonArrayItem->valuestring, '.') + 1); + (*len)++; // for separator ',' + } + if ((*len + 1) > PRIVATE_SYSCAP_SIZE) { + PRINT_ERR("context of \"pri\" array is too many.\n"); + return -1; + } + return 0; +} + +int32_t CreatePCID(char *inputFile, char *outDirPath) +{ + uint32_t privateCapSize, osCapSize; + size_t contextBufLen; + char *contextBuffer = NULL; + cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); + + int32_t ret = GetFileContext(inputFile, &contextBuffer, &contextBufLen); + if (ret != 0) { + PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); + goto FREE_CONVERT_OUT; + } + + cJSON *jsonRootObj = cJSON_ParseWithLength(contextBuffer, contextBufLen); if (jsonRootObj == NULL) { PRINT_ERR("cJSON_Parse failed, context buffer is:\n%s\n", contextBuffer); ret = -1; goto FREE_CONVERT_OUT; } - jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "syscap"); + cJSON *jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "syscap"); if (jsonSyscapObj == NULL || !cJSON_IsObject(jsonSyscapObj)) { PRINT_ERR("get \"syscap\" object failed\n"); ret = -1; goto FREE_CONVERT_OUT; } - jsonOsSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "os"); - if (jsonOsSyscapObj == NULL || !cJSON_IsArray(jsonOsSyscapObj)) { - PRINT_ERR("get \"os\" array failed\n"); - ret = -1; - goto FREE_CONVERT_OUT; - } - ret = cJSON_GetArraySize(jsonOsSyscapObj); - if (ret < 0) { - PRINT_ERR("get \"os\" array size failed\n"); - ret = -1; - goto FREE_CONVERT_OUT; - } - osCapSize = (uint32_t)ret; - - jsonPriSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "private"); - if (jsonPriSyscapObj != NULL && cJSON_IsArray(jsonPriSyscapObj)) { - ret = cJSON_GetArraySize(jsonPriSyscapObj); - if (ret < 0) { - PRINT_ERR("get \"private syscap\" array size failed\n"); - ret = -1; - goto FREE_CONVERT_OUT; - } - privateCapSize = (uint32_t)ret; - } else if (jsonPriSyscapObj == NULL) { - privateCapSize = 0; - } else { - PRINT_ERR("get \"private\" array failed\n"); - ret = -1; + cJSON *jsonOsSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "os"); + cJSON *jsonPriSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "private"); + ret = GetOsAndPriSyscapSize(jsonOsSyscapObj, jsonPriSyscapObj, &osCapSize, &privateCapSize); + if (ret != 0) { goto FREE_CONVERT_OUT; } uint16_t allPriSyscapStrLen = 0; - for (i = 0; i < privateCapSize; i++) { - jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, (int)i); - allPriSyscapStrLen += (uint16_t)strlen(strchr(jsonArrayItem->valuestring, '.') + 1); - allPriSyscapStrLen++; // for separator ',' - } - if ((allPriSyscapStrLen + 1) > PRIVATE_SYSCAP_SIZE) { - PRINT_ERR("context of \"pri\" array is too many.\n"); - ret = -1; + ret = GetPriSyscapLen(privateCapSize, jsonPriSyscapObj, &allPriSyscapStrLen); + if (ret != 0) { goto FREE_CONVERT_OUT; } @@ -254,98 +343,124 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) goto FREE_CONVERT_OUT; } (void)memset_s(pcidBuffer, pcidLength, 0, pcidLength); - - // process os syscap - for (i = 0; i < osCapSize; i++) { - jsonArrayItem = cJSON_GetArrayItem(jsonOsSyscapObj, (int)i); - osCapIndex = cJSON_GetObjectItem(allOsSyscapObj, jsonArrayItem->valuestring); - if (osCapIndex == NULL) { - PRINT_ERR("can't find the syscap: %s, please add it in syscap_define.h.\n", jsonArrayItem->valuestring); - ret = -1; - goto FREE_CONVERT_OUT; - } - sectorOfBits = (osCapIndex->valueint) / UINT8_BIT; - posOfBits = (osCapIndex->valueint) % UINT8_BIT; - if (sectorOfBits >= OS_SYSCAP_BYTES) { - PRINT_ERR("num of \"os syscap\" is out of 960\n"); - ret = -1; - goto FREE_PCID_BUFFER_OUT; - } - pcidBuffer->osSyscap[sectorOfBits] |= 1 << (posOfBits); - } - // process private syscap - char *priSyscapHead = (char *)(pcidBuffer + 1); - char *priSyscapStr = NULL; - for (i = 0; i < privateCapSize; i++) { - jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, (int)i); - priSyscapStr = strchr(jsonArrayItem->valuestring, '.') + 1; - nRet = strcat_s(priSyscapHead, allPriSyscapStrLen + 1, priSyscapStr); - nRet += strcat_s(priSyscapHead, allPriSyscapStrLen + 1, ","); - if (nRet != EOK) { - PRINT_ERR("strcat_s \"pri\" string is failed\n"); - ret = -1; - goto FREE_PCID_BUFFER_OUT; - } - } - - jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "api_version"); - if (jsonSyscapObj == NULL || !cJSON_IsNumber(jsonSyscapObj)) { - PRINT_ERR("get \"api_version\" failed\n"); - ret = -1; + ret = SetOsSyscap(pcidBuffer, osCapSize, jsonOsSyscapObj, allOsSyscapObj); + ret += SetPriSyscap(pcidBuffer, jsonPriSyscapObj, privateCapSize, allPriSyscapStrLen); + ret += SetPCIDHeader(pcidBuffer, jsonRootObj); + if (ret != 0) { goto FREE_PCID_BUFFER_OUT; } - pcidBuffer->apiVersion = HtonsInter((uint16_t)jsonSyscapObj->valueint); - pcidBuffer->apiVersionType = 0; - - jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "system_type"); - if (jsonSyscapObj == NULL || !cJSON_IsString(jsonSyscapObj)) { - PRINT_ERR("get \"system_type\" failed\n"); - ret = -1; - goto FREE_PCID_BUFFER_OUT; - } - systemType = jsonSyscapObj->valuestring; - pcidBuffer->systemType = !strcmp(systemType, "mini") ? 0b001 : - (!strcmp(systemType, "small") ? 0b010 : - (!strcmp(systemType, "standard") ? 0b100 : 0)); - if (pcidBuffer->systemType == 0) { - PRINT_ERR("\"system_type\" is invaild, systemType = \"%s\"\n", systemType); - ret = -1; - goto FREE_PCID_BUFFER_OUT; - } - - jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "manufacturer_id"); - if (jsonSyscapObj == NULL || !cJSON_IsNumber(jsonSyscapObj)) { - PRINT_ERR("get \"manufacturer_id\" failed\n"); - ret = -1; - goto FREE_PCID_BUFFER_OUT; - } - pcidBuffer->manufacturerID = HtonlInter((uint32_t)jsonSyscapObj->valueint); const char pcidFileName[] = "PCID.sc"; ret = ConvertedContextSaveAsFile(outDirPath, pcidFileName, (char *)pcidBuffer, pcidLength); if (ret != 0) { - PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, pcidFileName); - ret = -1; + PRINT_ERR("Save as file failed, outDirPath:%s, filename:%s\n", outDirPath, pcidFileName); goto FREE_PCID_BUFFER_OUT; } FREE_PCID_BUFFER_OUT: free(pcidBuffer); FREE_CONVERT_OUT: - free(allOsSyscapObj); + cJSON_Delete(allOsSyscapObj); FreeContextBuffer(contextBuffer); return ret; } -int32_t DecodePCID(char *inputFile, char *outDirPath) +int32_t GetOsSyscap(PCIDMain *pcidMain, cJSON *sysCapObject) { - int32_t ret; - errno_t nRet = 0; - char *contextBuffer = NULL; + uint32_t i, j, countOfSyscap = 0; uint8_t osSyscap[OS_SYSCAP_BYTES] = {0}; uint16_t indexOfSyscap[OS_SYSCAP_BYTES * UINT8_BIT] = {0}; - uint32_t i, j, countOfSyscap = 0; + + cJSON *capVectorPtr = cJSON_CreateArray(); + if (capVectorPtr == NULL) { + PRINT_ERR("cJSON_CreateArray failed\n"); + return -1; + } + + // 8, bytes of pcid header + errno_t nRet = memcpy_s(osSyscap, OS_SYSCAP_BYTES, (uint8_t *)pcidMain + 8, OS_SYSCAP_BYTES); + if (nRet != EOK) { + PRINT_ERR("memcpy_s failed."); + return -1; + } + + for (i = 0; i < OS_SYSCAP_BYTES; i++) { + for (j = 0; j < UINT8_BIT; j++) { + if (osSyscap[i] & (0x01 << j)) { + indexOfSyscap[countOfSyscap++] = i * UINT8_BIT + j; + } + } + } + for (i = 0; i < countOfSyscap; i++) { + for (j = 0; j < sizeof(g_arraySyscap) / sizeof(SyscapWithNum); j++) { + if (g_arraySyscap[j].num == indexOfSyscap[i]) { + if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(g_arraySyscap[j].str))) { + printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); + return -1; + } + } + } + } + + if (!cJSON_AddItemToObject(sysCapObject, "os", capVectorPtr)) { + PRINT_ERR("cJSON_AddItemToObject failed\n"); + return -1; + } + + return 0; +} + +int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufLen) +{ + cJSON *capVectorPtr = cJSON_CreateArray(); + if (capVectorPtr == NULL) { + PRINT_ERR("cJSON_CreateArray failed\n"); + return -1; + } + + int32_t privateSyscapLen = (int32_t)(contextBufLen - sizeof(PCIDMain) - 1); + if (privateSyscapLen < 0) { + PRINT_ERR("parse private syscap failed."); + return -1; + } else if (privateSyscapLen == 0) { + return 0; + } + + char fullCapStr[SINGLE_SYSCAP_LEN] = {0}; + char priSyscapStr[SINGLE_SYSCAP_LEN] = {0}; + char *tempPriSyscapStr = priSyscapStr; + char *ptrPrivateSyscap = (char *)(pcidMain + 1); + while (*ptrPrivateSyscap != '\0') { + if (*ptrPrivateSyscap == ',') { + *tempPriSyscapStr = '\0'; + int32_t ret = sprintf_s(fullCapStr, SINGLE_SYSCAP_LEN, "SystemCapability.%s", priSyscapStr); + if (ret == -1) { + printf("sprintf_s failed\n"); + return -1; + } + if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(fullCapStr))) { + printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); + return -1; + } + tempPriSyscapStr = priSyscapStr; + ptrPrivateSyscap++; + continue; + } + *tempPriSyscapStr++ = *ptrPrivateSyscap++; + } + if (!cJSON_AddItemToObject(sysCapObject, "private", capVectorPtr)) { + PRINT_ERR("cJSON_AddItemToObject failed\n"); + return -1; + } + + return 0; +} + +int32_t DecodePCID(char *inputFile, char *outDirPath) +{ + int32_t ret = 0; + char *contextBuffer = NULL; size_t contextBufLen; ret = GetFileContext(inputFile, &contextBuffer, &contextBufLen); @@ -355,7 +470,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) } PCIDMain *pcidMain = (PCIDMain *)contextBuffer; - + /* api version */ if (pcidMain->apiVersionType != 0) { PRINT_ERR("Prase file failed, apiVersionType is invaild, input file : %s\n", inputFile); @@ -373,97 +488,21 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) goto FREE_CONTEXT_OUT; } - cJSON *capVectorPtr = cJSON_CreateArray(); - if (capVectorPtr == NULL) { - PRINT_ERR("cJSON_CreateArray failed\n"); - ret = -1; - goto FREE_CONTEXT_OUT; - } - - nRet = memcpy_s(osSyscap, OS_SYSCAP_BYTES, (uint8_t *)pcidMain + 8, OS_SYSCAP_BYTES); // 8, bytes of pcid header - if (nRet != EOK) { - PRINT_ERR("memcpy_s failed."); - ret = -1; - goto FREE_VECTOR_OUT; - } - for (i = 0; i < OS_SYSCAP_BYTES; i++) { - for (j = 0; j < UINT8_BIT; j++) { - if (osSyscap[i] & (0x01 << j)) { - indexOfSyscap[countOfSyscap++] = i * UINT8_BIT + j; - } - } - } - for (i = 0; i < countOfSyscap; i++) { - for (j = 0; j < sizeof(g_arraySyscap) / sizeof(SyscapWithNum); j++) { - if (g_arraySyscap[j].num == indexOfSyscap[i]) { - if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(g_arraySyscap[j].str))) { - printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); - ret = -1; - goto FREE_VECTOR_OUT; - } - } - } - } - - cJSON *sysCapObjectPtr = cJSON_CreateObject(); - if (sysCapObjectPtr == NULL) { + /* syscap */ + cJSON *sysCapObj = cJSON_CreateObject(); + if (sysCapObj == NULL) { PRINT_ERR("cJSON_CreateObject failed\n"); ret = -1; goto FREE_CONTEXT_OUT; } - if (!cJSON_AddItemToObject(sysCapObjectPtr, "os", capVectorPtr)) { - PRINT_ERR("cJSON_AddItemToObject failed\n"); - ret = -1; - goto FREE_VECTOR_OUT; + + if (GetOsSyscap(pcidMain, sysCapObj) != 0) { + goto FREE_CONTEXT_OUT; } - // private syscap - capVectorPtr = cJSON_CreateArray(); - if (capVectorPtr == NULL) { - PRINT_ERR("cJSON_CreateArray failed\n"); - ret = -1; - goto FREE_SYSCAP_OUT; + if (GetPriSyscap(pcidMain, sysCapObj, contextBufLen) != 0) { + goto FREE_CONTEXT_OUT; } - char *ptrPrivateSyscap = (char *)(pcidMain + 1); - int privateSyscapLen = (int)(contextBufLen - sizeof(PCIDMain) - 1); - char priSyscapStr[SINGLE_SYSCAP_LEN] = {0}; - char *tempPriSyscapStr = priSyscapStr; - char fullPriSyscapStr[SINGLE_SYSCAP_LEN] = {0}; - if (privateSyscapLen < 0) { - PRINT_ERR("parse private syscap failed."); - ret = -1; - goto FREE_VECTOR_OUT; - } else if (privateSyscapLen == 0) { - goto SKIP_GET_PRIVATE; - } - - while (*ptrPrivateSyscap != '\0') { - if (*ptrPrivateSyscap == ',') { - *tempPriSyscapStr = '\0'; - ret = sprintf_s(fullPriSyscapStr, SINGLE_SYSCAP_LEN, "SystemCapability.%s", priSyscapStr); - if (ret == -1) { - printf("sprintf_s failed\n"); - goto FREE_VECTOR_OUT; - } - if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(fullPriSyscapStr))) { - printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); - ret = -1; - goto FREE_VECTOR_OUT; - } - tempPriSyscapStr = priSyscapStr; - ptrPrivateSyscap++; - continue; - } - *tempPriSyscapStr++ = *ptrPrivateSyscap++; - } - if (!cJSON_AddItemToObject(sysCapObjectPtr, "private", capVectorPtr)) { - PRINT_ERR("cJSON_AddItemToObject failed\n"); - ret = -1; - goto FREE_VECTOR_OUT; - } - -SKIP_GET_PRIVATE: - capVectorPtr = NULL; // create json root cJSON *jsonRootObj = cJSON_CreateObject(); if (jsonRootObj == NULL) { @@ -487,30 +526,27 @@ SKIP_GET_PRIVATE: ret = -1; goto FREE_ROOT_OUT; } - if (!cJSON_AddItemToObject(jsonRootObj, "syscap", sysCapObjectPtr)) { + if (!cJSON_AddItemToObject(jsonRootObj, "syscap", sysCapObj)) { PRINT_ERR("cJSON_AddItemToObject failed\n"); ret = -1; goto FREE_ROOT_OUT; } - sysCapObjectPtr = NULL; - - char *convertedBuffer = cJSON_Print(jsonRootObj); + sysCapObj = NULL; // avoid being released repeatedly. + char *strJson = cJSON_Print(jsonRootObj); const char outputFileName[] = "PCID.json"; - ret = ConvertedContextSaveAsFile(outDirPath, outputFileName, convertedBuffer, strlen(convertedBuffer)); + ret = ConvertedContextSaveAsFile(outDirPath, outputFileName, strJson, strlen(strJson)); if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, outputFileName); goto FREE_CONVERT_OUT; } FREE_CONVERT_OUT: - free(convertedBuffer); + free(strJson); FREE_ROOT_OUT: cJSON_Delete(jsonRootObj); FREE_SYSCAP_OUT: - cJSON_Delete(sysCapObjectPtr); -FREE_VECTOR_OUT: - cJSON_Delete(capVectorPtr); + cJSON_Delete(sysCapObj); FREE_CONTEXT_OUT: FreeContextBuffer(contextBuffer); return ret; @@ -675,22 +711,21 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) { int32_t ret = -1; - uint32_t osSyscapUintArray[OS_SYSCAP_NUM] = {0}; + uint32_t osSyscap[OS_SYSCAP_NUM] = {0}; uint32_t pcidHeader[PCID_HEADER]; size_t fileContextLen; - char *fileContext = NULL; + char *ctx = NULL; char *priSyscapStr = NULL; - if (GetFileContext(input, &fileContext, &fileContextLen) != 0) { + if (GetFileContext(input, &ctx, &fileContextLen) != 0) { PRINT_ERR("GetFileContext failed, input file : %s\n", input); goto PARSE_FAILED; } - if (ParseStringSyscap(fileContext, osSyscapUintArray, - OS_SYSCAP_NUM, pcidHeader, PCID_HEADER) != 0) { + if (ParseStringSyscap(ctx, osSyscap, OS_SYSCAP_NUM, pcidHeader, PCID_HEADER) != 0) { PRINT_ERR("Parse string syscap failed.\n"); goto PARSE_FAILED; } - priSyscapStr = fileContext; + priSyscapStr = ctx; // add to json object cJSON *sysCapObj = cJSON_CreateObject(); @@ -703,7 +738,7 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) PRINT_ERR("Add header to json object failed.\n"); goto ADD_JSON_FAILED; } - if (AddOsSyscapToJsonObj(osSyscapUintArray, OS_SYSCAP_NUM, sysCapObj) != 0) { + if (AddOsSyscapToJsonObj(osSyscap, OS_SYSCAP_NUM, sysCapObj) != 0) { PRINT_ERR("Add os syscap json object failed.\n"); goto ADD_JSON_FAILED; } @@ -726,7 +761,7 @@ SAVE_FAILED: ADD_JSON_FAILED: cJSON_Delete(rootObj); PARSE_FAILED: - free(fileContext); + free(ctx); return ret; } diff --git a/src/main.c b/src/main.c index 8726d43..c639b72 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include "securec.h" #include "syscap_tool.h" @@ -29,7 +28,7 @@ printf("ERROR: [%s: %d] -> ", __FILE__, __LINE__); \ printf(__VA_ARGS__); \ } while (0) -#define SYSCAP_VERSION "2.0.0" +#define SYSCAP_VERSION "2.0.1" #define OUTPUT_VERSION_LEN 200 #define ENCODE 0 #define DECODE 1 diff --git a/src/syscap_tool.c b/src/syscap_tool.c index d42d067..2b5a656 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -563,61 +563,37 @@ FREE_CONTEXT_OUT: return ret; } -int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uint32_t osArraySize, - char **priSyscap, uint32_t *priSyscapLen) +char *CopyInputString(const char *inputString) { - int32_t ret = 0; - uint32_t i; - - uint32_t count = 0; - char *temp = NULL; - char *tok = NULL; - char *private = NULL; - - if (osArraySize != PCID_OUT_BUFFER) { - return -1; - } - - // copy to temp string input - if (inputString == NULL) { - PRINT_ERR("inputString is null.\n"); - return -1; + if (inputString == NULL || *inputString == '\0') { + PRINT_ERR("inputString is null or empty.\n"); + return NULL; } size_t inputLen = strlen(inputString); if (inputLen > STRING_FORMAT_LEN_MAX) { PRINT_ERR("input string too long(%zu).\n", inputLen); - return -1; + return NULL; } char *input = (char *)malloc(inputLen + 1); if (input == NULL) { PRINT_ERR("malloc failed.\n"); - return -1; + return NULL; } - ret = strcpy_s(input, inputLen + 1, inputString); + int32_t ret = strcpy_s(input, inputLen + 1, inputString); if (ret != EOK) { PRINT_ERR("strcpy_s failed.\n"); free(input); - return -1; + return NULL; } input[inputLen] = '\0'; + return input; +} - // get os syscap data - for (i = 0; i < PCID_OUT_BUFFER; i++) { - ret = sscanf_s(input, "%u,%s", &osArray[i], input, inputLen); - if (ret == -1) { - PRINT_ERR("sscanf_s failed.\n"); - free(input); - return -1; - } - } - - // count private syscap - if (*input == '\0') { - *priSyscap = 0; - *priSyscapLen = 0; - goto SKIP_PRI_SYSCAP; - } - for (i = 0; *(input + i) != '\0'; i++) { +int32_t GetPriSyscapData(char *input, char **priSyscap, uint32_t *priSyscapLen) +{ + // count private syscaps + uint32_t count = 0; + for (uint32_t i = 0; *(input + i) != '\0'; i++) { if (*(input + i) == ',') { count++; } @@ -627,20 +603,19 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin char *priSysCapOut = (char *)malloc(SINGLE_SYSCAP_LEN * count); if (priSysCapOut == NULL) { PRINT_ERR("sscanf_s failed.\n"); - free(input); return -1; } (void)memset_s(priSysCapOut, SINGLE_SYSCAP_LEN * count, 0, SINGLE_SYSCAP_LEN * count); - private = priSysCapOut; + char *private = priSysCapOut; - temp = strtok_r(input, ",", &tok); + char *tok = NULL; + char *temp = strtok_r(input, ",", &tok); while (temp) { - ret = strncpy_s(private, SINGLE_SYSCAP_LEN, + int ret = strncpy_s(private, SINGLE_SYSCAP_LEN, temp, SINGLE_SYSCAP_LEN - 1); if (ret != EOK) { PRINT_ERR("strncpy_s failed.\n"); - free(input); - free(private); + free(priSysCapOut); return -1; } temp = strtok_r(NULL, ",", &tok); @@ -649,28 +624,112 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin *priSyscap = priSysCapOut; *priSyscapLen = count; + return 0; +} + +int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uint32_t osArraySize, + char **priSyscap, uint32_t *priSyscapLen) +{ + if (osArraySize != PCID_OUT_BUFFER) { + return -1; + } + + // copy origin string + char *input = CopyInputString(inputString); + if (input == NULL) { + return -1; + } + + // get os syscap data + for (uint32_t i = 0; i < PCID_OUT_BUFFER; i++) { + if (sscanf_s(input, "%u,%s", &osArray[i], input, strlen(input)) == -1) { + PRINT_ERR("sscanf_s failed.\n"); + free(input); + return -1; + } + } + + // get private syscap data + if (GetPriSyscapData(input, priSyscap, priSyscapLen) != 0) { + free(input); + return -1; + } -SKIP_PRI_SYSCAP: free(input); return 0; } +int32_t CompareOsSyscap(uint32_t pcidOsAarry[], uint32_t rpcidOsAarry[]) +{ + int32_t ossyscapFlag = 0; + const size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); + + for (uint32_t i = 2; i < PCID_OUT_BUFFER; i++) { // 2, header of pcid & rpcid + uint32_t blockBits = (pcidOsAarry[i] ^ rpcidOsAarry[i]) & rpcidOsAarry[i]; + if (!blockBits) { + continue; + } + for (uint8_t k = 0; k < INT_BIT; k++) { + if (!(blockBits & (1U << k))) { + continue; + } + // 2, header of pcid & rpcid + size_t pos = (size_t)((i - 2) * INT_BIT + k); + if (pos < allSyscapNum) { + printf("Missing: %s\n", g_arraySyscap[pos].str); + ossyscapFlag += 1; + } + } + } + return ossyscapFlag; +} + +int32_t ComparePriSyscap(char *pcid, char *rpcid, uint32_t pcidLen, uint32_t rpcidLen) +{ + uint32_t i, j; + bool priSysFound = false; + int32_t prisyscapFlag = 0; + + for (i = 0; i < rpcidLen; i++) { + for (j = 0; j < pcidLen; j++) { + if (strcmp(rpcid + SINGLE_SYSCAP_LEN * i, + pcid + SINGLE_SYSCAP_LEN * j) == 0) { + priSysFound = true; + break; + } + } + if (priSysFound != true) { + printf("Missing: %s\n", rpcid + SINGLE_SYSCAP_LEN * i); + prisyscapFlag += 1; + } + priSysFound = false; + } + + return prisyscapFlag; +} + +int32_t CompoareVersion(uint32_t *pcidOsAarry, uint32_t *rpcidOsAarry) +{ + int32_t versionFlag = 0; + uint16_t pcidVersion = NtohsInter(((PCIDMain *)pcidOsAarry)->apiVersion); + uint16_t rpcidVersion = NtohsInter(((RPCIDHead *)rpcidOsAarry)->apiVersion); + if (pcidVersion < rpcidVersion) { + printf("ERROR: Pcid version(%u) less than rpcid version(%u).\n", pcidVersion, rpcidVersion); + versionFlag = 1; + } + return versionFlag; +} + int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t type) { int32_t ret; - int32_t versionFlag = 0; - int32_t ossyscapFlag = 0; - int32_t prisyscapFlag = 0; char *pcidContent = NULL; char *rpcidContent = NULL; char *pcidPriSyscap = NULL; char *rpcidPriSyscap = NULL; uint32_t pcidContentLen, rpcidContentLen, pcidPriSyscapLen, rpcidPriSyscapLen; - uint32_t i, j, temp1, temp2; - bool priSysFound; uint32_t pcidOsAarry[PCID_OUT_BUFFER] = {0}; uint32_t rpcidOsAarry[PCID_OUT_BUFFER] = {0}; - const size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); if (type == TYPE_FILE) { if (GetFileContext(pcidFile, &pcidContent, &pcidContentLen)) { @@ -698,49 +757,10 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ PRINT_ERR("Separate syscap from string failed. ret = %d\n", ret); return -1; } - // compare version - uint16_t pcidVersion = NtohsInter(((PCIDMain *)pcidOsAarry)->apiVersion); - uint16_t rpcidVersion = NtohsInter(((RPCIDHead *)rpcidOsAarry)->apiVersion); - if (pcidVersion < rpcidVersion) { - printf("ERROR: Pcid version(%u) less than rpcid version(%u).\n", pcidVersion, rpcidVersion); - versionFlag = 1; - } - // compare os syscap - for (i = 2; i < PCID_OUT_BUFFER; i++) { // 2, header of pcid & rpcid - temp1 = pcidOsAarry[i] ^ rpcidOsAarry[i]; - temp2 = temp1 & rpcidOsAarry[i]; - if (!temp2) { - continue; - } - for (uint8_t k = 0; k < INT_BIT; k++) { - if (!(temp2 & (1U << k))) { - continue; - } - // 2, header of pcid & rpcid - size_t pos = (size_t)((i - 2) * INT_BIT + k); - if (pos < allSyscapNum) { - printf("Missing: %s\n", g_arraySyscap[pos].str); - ossyscapFlag += 1; - } - } - } - // compare pri syscap - priSysFound = false; - for (i = 0; i < rpcidPriSyscapLen; i++) { - for (j = 0; j < pcidPriSyscapLen; j++) { - if (strcmp(rpcidPriSyscap + SINGLE_SYSCAP_LEN * i, - pcidPriSyscap + SINGLE_SYSCAP_LEN * j) == 0) { - priSysFound = true; - break; - } - } - if (priSysFound != true) { - printf("Missing: %s\n", rpcidPriSyscap + SINGLE_SYSCAP_LEN * i); - prisyscapFlag += 1; - } - priSysFound = false; - } + int32_t versionFlag = CompoareVersion(pcidOsAarry, rpcidOsAarry); + int32_t ossyscapFlag = CompareOsSyscap(pcidOsAarry, rpcidOsAarry); + int32_t prisyscapFlag = ComparePriSyscap(pcidPriSyscap, rpcidPriSyscap, pcidPriSyscapLen, rpcidPriSyscapLen); if (!versionFlag && !ossyscapFlag && !prisyscapFlag) { printf("Succeed! The pcid meets the rpcid.\n"); } else { From 23627954070b9dbc3539c65871d5e651ef8714b0 Mon Sep 17 00:00:00 2001 From: yudechen Date: Wed, 28 Jun 2023 09:53:12 +0800 Subject: [PATCH 7/7] fix: modify python script shebang. Signed-off-by: yudechen Change-Id: I3afce1da174fa3c925883ed3b61594e48bfc1785 --- tools/syscap_config_merge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/syscap_config_merge.py b/tools/syscap_config_merge.py index df1c971..c3d676e 100755 --- a/tools/syscap_config_merge.py +++ b/tools/syscap_config_merge.py @@ -1,4 +1,4 @@ -#! /usr/bin/python3 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright (c) 2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License");