From 4ed8bd7f051f3141b3abac0b6d801650d14900dd Mon Sep 17 00:00:00 2001 From: lcaidm Date: Thu, 20 Mar 2025 18:06:27 +0800 Subject: [PATCH 01/16] bugfix Signed-off-by:lcaidm Signed-off-by: lcaidm --- 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 be54e82..9b793a6 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -379,6 +379,7 @@ typedef enum SystemCapabilityNum { DISTRIBUTEDSCHED_APPCOLLABORATION, MULTIMEDIA_AVSESSION_AVINPUTCAST, GAME_GAMECONTROLLER, + DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -742,6 +743,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.MultimodalAwarness.Motion", MULTIMODALAWARENESS_MOTION}, {"SystemCapability.DistributedSched.AppCollaboration", DISTRIBUTEDSCHED_APPCOLLABORATION}, {"SystemCapability.Game.GameController", GAME_GAMECONTROLLER}, + {"SystemCapability.DistributedDataManager.DataIntelligence.Core", DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE}, }; #ifdef __cplusplus -- Gitee From 4e42a7d999e63e85cf64f6d95350a54a16405c04 Mon Sep 17 00:00:00 2001 From: zhaohang Date: Mon, 24 Mar 2025 16:16:21 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaohang --- src/create_pcid.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/create_pcid.c b/src/create_pcid.c index da299fe..c5e5bed 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -379,6 +379,11 @@ static int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, int32_t con char *tempPriSyscapStr = priSyscapStr; char *ptrPrivateSyscap = (char *)(pcidMain + 1); while (*ptrPrivateSyscap != '\0') { + size_t currentLen = tempPriSyscapStr - priSyscapStr; + if (currentLen >= SINGLE_SYSCAP_LEN - 1) { + PRINT_ERR("Syscap name exceeds maximum length\n"); + return GetPriSyscapResult(capVectorPtr, -1); + } if (*ptrPrivateSyscap == ',') { *tempPriSyscapStr = '\0'; int32_t ret = sprintf_s(fullCapStr, SINGLE_SYSCAP_LEN, "SystemCapability.%s", priSyscapStr); -- Gitee From 2363cf20f328eae70a474acd542fa3ddf23639ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E6=98=AF=E9=93=B8=E5=B8=81=E6=8D=8F?= Date: Wed, 26 Mar 2025 08:03:37 +0000 Subject: [PATCH 03/16] add syscap for device_status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 就是铸币捏 --- 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 9b793a6..aa8026a 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -380,6 +380,7 @@ typedef enum SystemCapabilityNum { MULTIMEDIA_AVSESSION_AVINPUTCAST, GAME_GAMECONTROLLER, DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE, + MULTIMODALAWARENESS_DEVICESTATUS, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -744,6 +745,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.DistributedSched.AppCollaboration", DISTRIBUTEDSCHED_APPCOLLABORATION}, {"SystemCapability.Game.GameController", GAME_GAMECONTROLLER}, {"SystemCapability.DistributedDataManager.DataIntelligence.Core", DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE}, + {"SystemCapability.MultimodalAwareness.DeviceStatus", MULTIMODALAWARENESS_DEVICESTATUS}, }; #ifdef __cplusplus -- Gitee From a0e8b56b22ee06771097a035325bdf0bd57a35fa Mon Sep 17 00:00:00 2001 From: zhaohang Date: Thu, 27 Mar 2025 15:01:50 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaohang --- src/create_pcid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index c5e5bed..1b08215 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -381,7 +381,7 @@ static int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, int32_t con while (*ptrPrivateSyscap != '\0') { size_t currentLen = tempPriSyscapStr - priSyscapStr; if (currentLen >= SINGLE_SYSCAP_LEN - 1) { - PRINT_ERR("Syscap name exceeds maximum length\n"); + printf("Syscap name exceeds maximum length\n"); return GetPriSyscapResult(capVectorPtr, -1); } if (*ptrPrivateSyscap == ',') { -- Gitee From 732b317ca81152ba3debe34ed6110e641de3018c Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Mon, 31 Mar 2025 10:14:42 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9module=5Foutput=5Fpath?= =?UTF-8?q?=E4=B8=BA=E9=83=A8=E4=BB=B6/=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- test/unittest/common/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/common/BUILD.gn b/test/unittest/common/BUILD.gn index 2621342..ea89fb0 100644 --- a/test/unittest/common/BUILD.gn +++ b/test/unittest/common/BUILD.gn @@ -64,7 +64,7 @@ if (defined(ohos_lite)) { import("//build/ohos.gni") import("//build/test.gni") - module_output_path = "developtools/syscap_codec" + module_output_path = "syscap_codec/syscap_codec" ohos_unittest("syscap_codec_test") { module_out_path = module_output_path -- Gitee From 77efbdb97e07dfc6ee3c5791a31e6e4e915ba9e2 Mon Sep 17 00:00:00 2001 From: dairan Date: Tue, 8 Apr 2025 02:24:23 +0000 Subject: [PATCH 06/16] update include/codec_config/syscap_define.h. Signed-off-by: dairan --- 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 aa8026a..0b98731 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -174,6 +174,7 @@ typedef enum SystemCapabilityNum { UPDATER_RAW, UPDATE_UPDATESERVICE, USB_USBMANAGER, + USB_USBMANAGER_SERIAL, USERIAM_USERAUTH_CORE, USERIAM_USERAUTH_FACEAUTH, USERIAM_USERAUTH_FINGERPRINTAUTH, @@ -548,6 +549,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Updater.Raw", UPDATER_RAW}, {"SystemCapability.Update.UpdateService", UPDATE_UPDATESERVICE}, {"SystemCapability.USB.USBManager", USB_USBMANAGER}, + {"SystemCapability.USB.USBManager.Serial", USB_USBMANAGER_SERIAL}, {"SystemCapability.UserIAM.UserAuth.Core", USERIAM_USERAUTH_CORE}, {"SystemCapability.UserIAM.UserAuth.FaceAuth", USERIAM_USERAUTH_FACEAUTH}, {"SystemCapability.UserIAM.UserAuth.FingerprintAuth", USERIAM_USERAUTH_FINGERPRINTAUTH}, -- Gitee From 3cc35c82509827f7023cc581c811d0c2dcb1d21d Mon Sep 17 00:00:00 2001 From: dairan Date: Tue, 8 Apr 2025 08:08:15 +0000 Subject: [PATCH 07/16] update include/codec_config/syscap_define.h. Signed-off-by: dairan --- include/codec_config/syscap_define.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 0b98731..8d92488 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -174,7 +174,6 @@ typedef enum SystemCapabilityNum { UPDATER_RAW, UPDATE_UPDATESERVICE, USB_USBMANAGER, - USB_USBMANAGER_SERIAL, USERIAM_USERAUTH_CORE, USERIAM_USERAUTH_FACEAUTH, USERIAM_USERAUTH_FINGERPRINTAUTH, @@ -382,6 +381,7 @@ typedef enum SystemCapabilityNum { GAME_GAMECONTROLLER, DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE, MULTIMODALAWARENESS_DEVICESTATUS, + USB_USBMANAGER_SERIAL, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; -- Gitee From 23c3428a4d495b7a54349391d6393122e48d541c Mon Sep 17 00:00:00 2001 From: dairan Date: Tue, 8 Apr 2025 08:19:34 +0000 Subject: [PATCH 08/16] update include/codec_config/syscap_define.h. Signed-off-by: dairan --- include/codec_config/syscap_define.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 8d92488..89fbe28 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -381,7 +381,7 @@ typedef enum SystemCapabilityNum { GAME_GAMECONTROLLER, DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE, MULTIMODALAWARENESS_DEVICESTATUS, - USB_USBMANAGER_SERIAL, + USB_USBMANAGER_SERIAL, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; -- Gitee From 1473b910d907a283898dbd9d0944c5db3aeda96b Mon Sep 17 00:00:00 2001 From: lixing Date: Wed, 16 Apr 2025 02:10:04 +0000 Subject: [PATCH 09/16] hidumper add abandoned Signed-off-by: lixing --- include/codec_config/syscap_define.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 89fbe28..5526c41 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -86,7 +86,7 @@ typedef enum SystemCapabilityNum { GRAPHIC_WMS, HIVIEWDFX_HIAPPEVENT, HIVIEWDFX_HICHECKER, - HIVIEWDFX_HIDUMPER, + HIVIEWDFX_HIDUMPER, // abandoned HIEVENTKLITE, HIVIEWDFX_HILOG, HIVIEWDFX_HILOGLITE, -- Gitee From 8812baf746f09082aeafacb411073551be167684 Mon Sep 17 00:00:00 2001 From: lixing Date: Wed, 16 Apr 2025 02:15:43 +0000 Subject: [PATCH 10/16] hidumper add abandoned Signed-off-by: lixing --- include/codec_config/syscap_define.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 5526c41..8eed0f2 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -452,7 +452,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Graphic.Wms", GRAPHIC_WMS}, {"SystemCapability.HiviewDFX.HiAppEvent", HIVIEWDFX_HIAPPEVENT}, {"SystemCapability.HiviewDFX.HiChecker", HIVIEWDFX_HICHECKER}, - {"SystemCapability.HiviewDFX.HiDumper", HIVIEWDFX_HIDUMPER}, + {"SystemCapability.HiviewDFX.HiDumper", HIVIEWDFX_HIDUMPER}, // abandoned {"SystemCapability.HiviewDFX.HiEventLite", HIEVENTKLITE}, {"SystemCapability.HiviewDFX.HiLog", HIVIEWDFX_HILOG}, {"SystemCapability.HiviewDFX.HiLogLite", HIVIEWDFX_HILOGLITE}, -- Gitee From b897c4b34ad065d69e06972833d778678d637548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=B8=BF=E7=9D=BF?= Date: Tue, 29 Apr 2025 11:44:47 +0800 Subject: [PATCH 11/16] =?UTF-8?q?syscap=E4=B8=AD=E5=88=A0=E9=99=A4Cellular?= =?UTF-8?q?Call=E2=80=9C--signoff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git commit -msyscap中删除CellularCall“ Signed-off-by: 王鸿睿 --- include/codec_config/syscap_define.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 8eed0f2..609cfbc 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -161,7 +161,6 @@ typedef enum SystemCapabilityNum { SENSORS_SENSOR, SENSORS_SENSOR_LITE, TELEPHONY_CALLMANAGER, - TELEPHONY_CELLULARCALL, TELEPHONY_CELLULARDATA, TELEPHONY_CORESERVICE, TELEPHONY_DATASTORAGE, @@ -535,7 +534,6 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Sensors.Sensor", SENSORS_SENSOR}, {"SystemCapability.Sensors.Sensor.Lite", SENSORS_SENSOR_LITE}, {"SystemCapability.Telephony.CallManager", TELEPHONY_CALLMANAGER}, - {"SystemCapability.Telephony.CellularCall", TELEPHONY_CELLULARCALL}, {"SystemCapability.Telephony.CellularData", TELEPHONY_CELLULARDATA}, {"SystemCapability.Telephony.CoreService", TELEPHONY_CORESERVICE}, {"SystemCapability.Telephony.DataStorage", TELEPHONY_DATASTORAGE}, -- Gitee From 946f92a98a6dcee4b7a0ab478497a3db1b87381f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=B8=BF=E7=9D=BF?= Date: Wed, 30 Apr 2025 09:35:45 +0000 Subject: [PATCH 12/16] update include/codec_config/syscap_define.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王鸿睿 --- include/codec_config/syscap_define.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 609cfbc..b4b6ccc 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -160,7 +160,8 @@ typedef enum SystemCapabilityNum { SENSORS_MISCDEVICE, SENSORS_SENSOR, SENSORS_SENSOR_LITE, - TELEPHONY_CALLMANAGER, + TELEPHONY_CALLMANAGER, // abandoned + TELEPHONY_CELLULARCALL, TELEPHONY_CELLULARDATA, TELEPHONY_CORESERVICE, TELEPHONY_DATASTORAGE, @@ -534,6 +535,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Sensors.Sensor", SENSORS_SENSOR}, {"SystemCapability.Sensors.Sensor.Lite", SENSORS_SENSOR_LITE}, {"SystemCapability.Telephony.CallManager", TELEPHONY_CALLMANAGER}, + {"SystemCapability.Telephony.CellularCall", TELEPHONY_CELLULARCALL}, {"SystemCapability.Telephony.CellularData", TELEPHONY_CELLULARDATA}, {"SystemCapability.Telephony.CoreService", TELEPHONY_CORESERVICE}, {"SystemCapability.Telephony.DataStorage", TELEPHONY_DATASTORAGE}, -- Gitee From cfb3124c4f355e9aaf3ee15f014bb71a64a5c9e9 Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Wed, 7 May 2025 17:11:31 +0800 Subject: [PATCH 13/16] Modify to the correct path. Signed-off-by: liutuantuan --- tools/syscap_check.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/syscap_check.py b/tools/syscap_check.py index c404369..3799b79 100644 --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -285,7 +285,8 @@ def main(): project_path = args.project_path check_target = args.check_target bundles = args.bundles - syscap_define_path = os.path.join(project_path, "developtools", "syscap_codec", "include", "syscap_define.h") + syscap_define_path = os.path.join(project_path, "developtools", "syscap_codec", "include", + "codec_config", "syscap_define.h") ts_path = os.path.join(project_path, "interface", "sdk-js", "api") component_black_dirs = ("out",) bundle_syscap_heirarchy = ("component", "syscap") -- Gitee From d5a60bf49ffe7d0bbd1051adce723255bdf938fe Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Thu, 8 May 2025 09:30:07 +0800 Subject: [PATCH 14/16] gl4 Signed-off-by: zhangqiang --- 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 b4b6ccc..e4309d0 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -76,6 +76,7 @@ typedef enum SystemCapabilityNum { GLOBAL_RESOURCEMANAGER, GRAPHIC_GRAPHIC2D_EGL, GRAPHIC_GRAPHIC2D_GLES3, + GRAPHIC_GRAPHIC2D_GL4, GRAPHIC_GRAPHIC2D_NATIVEDRAWING, GRAPHIC_GRAPHIC2D_NATIVEWINDOW, GRAPHIC_GRAPHIC2D_WEBGL, @@ -438,6 +439,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Graphic.Graphic2D.EGL", GRAPHIC_GRAPHIC2D_EGL}, {"SystemCapability.Graphic.Graphic2D.GLES2", GRAPHIC_GRAPHIC2D_GLES2}, {"SystemCapability.Graphic.Graphic2D.GLES3", GRAPHIC_GRAPHIC2D_GLES3}, + {"SystemCapability.Graphic.Graphic2D.GL4", GRAPHIC_GRAPHIC2D_GL4}, {"SystemCapability.Graphic.Graphic2D.HyperGraphicManager", GRAPHIC_GRAPHIC2D_HYPERGRAPHICMANAGER}, {"SystemCapability.Graphic.Graphic2D.NativeBuffer", GRAPHIC_GRAPHIC2D_NATIVEBUFFER}, {"SystemCapability.Graphic.Graphic2D.NativeImage", GRAPHIC_GRAPHIC2D_NATIVEIMAGE}, -- Gitee From ddd61a6f02f2323db03c3e7e06bbb002c53b4fb2 Mon Sep 17 00:00:00 2001 From: zhangqiang Date: Tue, 13 May 2025 09:26:03 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=8FGRAPHIC=5FGRAP?= =?UTF-8?q?HIC2D=5FGL4=20=E6=B7=BB=E5=8A=A0=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangqiang --- include/codec_config/syscap_define.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index e4309d0..5326479 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -76,7 +76,6 @@ typedef enum SystemCapabilityNum { GLOBAL_RESOURCEMANAGER, GRAPHIC_GRAPHIC2D_EGL, GRAPHIC_GRAPHIC2D_GLES3, - GRAPHIC_GRAPHIC2D_GL4, GRAPHIC_GRAPHIC2D_NATIVEDRAWING, GRAPHIC_GRAPHIC2D_NATIVEWINDOW, GRAPHIC_GRAPHIC2D_WEBGL, @@ -383,6 +382,7 @@ typedef enum SystemCapabilityNum { DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE, MULTIMODALAWARENESS_DEVICESTATUS, USB_USBMANAGER_SERIAL, + GRAPHIC_GRAPHIC2D_GL4, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; -- Gitee From 39c5b0d4eb87cc3120a71cfc06a32aae1f006493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=B8=BF=E7=9D=BF?= Date: Mon, 19 May 2025 02:18:54 +0000 Subject: [PATCH 16/16] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20sr?= =?UTF-8?q?c/create=5Fpcid.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/create_pcid.c | 926 ---------------------------------------------- 1 file changed, 926 deletions(-) delete mode 100644 src/create_pcid.c diff --git a/src/create_pcid.c b/src/create_pcid.c deleted file mode 100644 index 1b08215..0000000 --- a/src/create_pcid.c +++ /dev/null @@ -1,926 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "securec.h" -#include "cJSON.h" -#include "endian_internal.h" -#include "create_pcid.h" -#include "context_tool.h" -#include "common_method.h" - -#ifdef SYSCAP_DEFINE_EXTERN_ENABLE -#include "syscap_define_custom.h" -#else -#include "syscap_define.h" -#endif - -#define SYSCAP_PREFIX_LEN 17 -#define SINGLE_FEAT_LEN (SINGLE_SYSCAP_LEN - SYSCAP_PREFIX_LEN) -#define PCID_OUT_BUFFER 32 -#define PRIVATE_SYSCAP_SIZE 1000 -#define UINT8_BIT 8 - -#define U32_TO_STR_MAX_LEN 11 -#define FREE_CREATE_PCID_BUFFER_OUT 1 - -#define FREE_DECODE_PCID_CONVERT_OUT 1 -#define FREE_DECODE_PCID_ROOT_OUT 2 -#define FREE_DECODE_PCID_SYSCAP_OUT 3 -#define FREE_DECODE_PCID_CONTEXT_OUT 4 - -#define ENCODE_PCID_OUTPUT 1 -#define FREE_ENCODE_PCID_OUT 2 -#define FREE_ENCODE_PCID_PRISYSCAP_FULL_OUT 3 -#define FREE_ENCODE_PCID_CONTEXT_OUT 4 - -struct FreeEncodePcidInfo { - char *output; - char *priSyscapFull; - char *contextBuffer; - char *outDirPathFinal; -}; - -struct FreeDecodePcidJsonInfo { - char *strJson; - char *contextBuffer; - cJSON *jsonRootObj; - cJSON *sysCapObj; - int32_t flag; -}; - -int32_t SetOsSyscap(PCIDMain *pcidBuffer, uint32_t osCapSize, - const cJSON *jsonOsSyscapObj, const cJSON *allOsSyscapObj) -{ - int32_t sectorOfBits, posOfBits; - cJSON *jsonArrayItem = NULL; - cJSON *osCapIndex = NULL; - - for (uint32_t i = 0; i < osCapSize; i++) { - jsonArrayItem = cJSON_GetArrayItem(jsonOsSyscapObj, (int)i); - if (jsonArrayItem == NULL || !cJSON_IsString(jsonArrayItem)) { - PRINT_ERR("Get jsonArrayItem failed."); - return -1; - } - 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; - } - if (!cJSON_IsNumber(osCapIndex)) { - PRINT_ERR("Get osCapIndex failed."); - 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); - if (jsonArrayItem == NULL || !cJSON_IsString(jsonArrayItem)) { - PRINT_ERR("get jsonArrayItem failed!"); - return -1; - } - priSyscapStr = strchr(jsonArrayItem->valuestring, '.'); - if (priSyscapStr == NULL) { - PRINT_ERR("get priSyscapStr failed!"); - return -1; - } - priSyscapStr += 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; - } - - 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); - if (jsonArrayItem == NULL || !cJSON_IsString(jsonArrayItem)) { - PRINT_ERR("Get jsonArrayItem failed."); - return -1; - } - *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; -} - -static int32_t CheckConvertedContextSaveAsFile(char *outDirPath, PCIDMain *pcidBuffer, uint16_t pcidLength, int32_t ret) -{ - const char pcidFileName[] = "pcid.sc"; - ret = ConvertedContextSaveAsFile(outDirPath, pcidFileName, (char *)pcidBuffer, pcidLength); - if (ret != 0) { - PRINT_ERR("Save as file failed, outDirPath:%s, filename:%s\n", outDirPath, pcidFileName); - } - return ret; -} - -static int32_t FreeAfterCreatePCID(PCIDMain *pcidBuffer, cJSON *allOsSyscapObj, char *contextBuffer, - int32_t type, int32_t ret) -{ - if (type == FREE_CREATE_PCID_BUFFER_OUT) { - free(pcidBuffer); - } - cJSON_Delete(allOsSyscapObj); - FreeContextBuffer(contextBuffer); - return ret; -} - -static int32_t PreFreeAfterCreatePCID(PCIDMain *pcidBuffer, cJSON *allOsSyscapObj, cJSON *jsonRootObj, - char *contextBuffer, int32_t type) -{ - cJSON_Delete(jsonRootObj); - return FreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, contextBuffer, type, -1); -} - -int32_t CreatePCID(char *inputFile, char *outDirPath) -{ - uint32_t privateCapSize, osCapSize; - uint32_t contextBufLen; - char *contextBuffer = NULL; - - cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); - int32_t ret = CheckFileAndGetFileContext(inputFile, &contextBuffer, (uint32_t *)&contextBufLen); - if (ret != 0) { - return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, -1); - } - - cJSON *jsonRootObj = cJSON_ParseWithLength(contextBuffer, contextBufLen); - if (jsonRootObj == NULL) { - PRINT_ERR("cJSON_Parse failed, context buffer is:\n%s\n", contextBuffer); - return PreFreeAfterCreatePCID(NULL, allOsSyscapObj, jsonRootObj, contextBuffer, 0); - } - - cJSON *jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "syscap"); - if (jsonSyscapObj == NULL || !cJSON_IsObject(jsonSyscapObj)) { - PRINT_ERR("get \"syscap\" object failed\n"); - return PreFreeAfterCreatePCID(NULL, allOsSyscapObj, jsonRootObj, contextBuffer, 0); - } - - cJSON *jsonOsSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "os"); - cJSON *jsonPriSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "private"); - - ret = GetOsAndPriSyscapSize(jsonOsSyscapObj, jsonPriSyscapObj, &osCapSize, &privateCapSize); - if (ret != 0) { - return PreFreeAfterCreatePCID(NULL, allOsSyscapObj, jsonRootObj, contextBuffer, 0); - } - - uint16_t allPriSyscapStrLen = 0; - ret = GetPriSyscapLen(privateCapSize, jsonPriSyscapObj, &allPriSyscapStrLen); - if (ret != 0) { - return PreFreeAfterCreatePCID(NULL, allOsSyscapObj, jsonRootObj, contextBuffer, 0); - } - - uint16_t pcidLength = sizeof(PCIDMain) + allPriSyscapStrLen + 1; - PCIDMain *pcidBuffer = (PCIDMain *)malloc(pcidLength); - if (pcidBuffer == NULL) { - PRINT_ERR("malloc for pcid buffer failed\n"); - return PreFreeAfterCreatePCID(NULL, allOsSyscapObj, jsonRootObj, contextBuffer, 0); - } - (void)memset_s(pcidBuffer, pcidLength, 0, pcidLength); - - ret = SetOsSyscap(pcidBuffer, osCapSize, jsonOsSyscapObj, allOsSyscapObj); - ret += SetPriSyscap(pcidBuffer, jsonPriSyscapObj, privateCapSize, allPriSyscapStrLen); - ret += SetPCIDHeader(pcidBuffer, jsonRootObj); - if (ret != 0) { - return PreFreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, jsonRootObj, contextBuffer, - FREE_CREATE_PCID_BUFFER_OUT); - } - - ret = CheckConvertedContextSaveAsFile(outDirPath, pcidBuffer, pcidLength, ret); - cJSON_Delete(jsonRootObj); - return FreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, contextBuffer, FREE_CREATE_PCID_BUFFER_OUT, ret); -} - -int32_t GetOsSyscap(PCIDMain *pcidMain, cJSON *sysCapObject) -{ - uint32_t i, j, countOfSyscap = 0; - uint8_t osSyscap[OS_SYSCAP_BYTES] = {0}; - uint16_t indexOfSyscap[OS_SYSCAP_BYTES * UINT8_BIT] = {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."); - cJSON_Delete(capVectorPtr); - 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]) { - continue; - } - if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(g_arraySyscap[j].str))) { - printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); - cJSON_Delete(capVectorPtr); - return -1; - } - } - } - - if (!cJSON_AddItemToObject(sysCapObject, "os", capVectorPtr)) { - PRINT_ERR("cJSON_AddItemToObject failed\n"); - cJSON_Delete(capVectorPtr); - return -1; - } - - return 0; -} - -static int32_t GetPriSyscapResult(cJSON *capVectorPtr, int32_t ret) -{ - cJSON_Delete(capVectorPtr); - return ret; -} - -static int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, int32_t contextBufLen) -{ - cJSON *capVectorPtr = cJSON_CreateArray(); - if (capVectorPtr == NULL) { - PRINT_ERR("cJSON_CreateArray failed\n"); - return -1; - } - - int32_t privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1; - if (privateSyscapLen < 0 || privateSyscapLen > INT32_MAX) { - PRINT_ERR("parse private syscap failed."); - return GetPriSyscapResult(capVectorPtr, -1); - } else if (privateSyscapLen == 0) { - return GetPriSyscapResult(capVectorPtr, 0); - } - - char fullCapStr[SINGLE_SYSCAP_LEN] = {0}; - char priSyscapStr[SINGLE_SYSCAP_LEN] = {0}; - char *tempPriSyscapStr = priSyscapStr; - char *ptrPrivateSyscap = (char *)(pcidMain + 1); - while (*ptrPrivateSyscap != '\0') { - size_t currentLen = tempPriSyscapStr - priSyscapStr; - if (currentLen >= SINGLE_SYSCAP_LEN - 1) { - printf("Syscap name exceeds maximum length\n"); - return GetPriSyscapResult(capVectorPtr, -1); - } - 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 GetPriSyscapResult(capVectorPtr, -1); - } - if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(fullCapStr))) { - printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); - return GetPriSyscapResult(capVectorPtr, -1); - } - tempPriSyscapStr = priSyscapStr; - ptrPrivateSyscap++; - continue; - } - *tempPriSyscapStr++ = *ptrPrivateSyscap++; - } - if (!cJSON_AddItemToObject(sysCapObject, "private", capVectorPtr)) { - PRINT_ERR("cJSON_AddItemToObject failed\n"); - return GetPriSyscapResult(capVectorPtr, -1); - } - return 0; -} - -static int32_t CheckSysCapObj(struct FreeDecodePcidJsonInfo freePcidJsonInfo, PCIDMain *pcidMain, - uint32_t contextBufLen, int32_t ret) -{ - if (freePcidJsonInfo.sysCapObj == NULL) { - PRINT_ERR("cJSON_CreateObject failed\n"); - freePcidJsonInfo.flag = -1; - return -1; - } - if (GetOsSyscap(pcidMain, freePcidJsonInfo.sysCapObj) != 0) { - freePcidJsonInfo.flag = -1; - return ret; - } - if (GetPriSyscap(pcidMain, freePcidJsonInfo.sysCapObj, contextBufLen) != 0) { - freePcidJsonInfo.flag = -1; - } - return ret; -} - -static int32_t CheckJsonRootObj(struct FreeDecodePcidJsonInfo freePcidJsonInfo, PCIDMain *pcidMain, char *systemType) -{ - if (!cJSON_AddNumberToObject(freePcidJsonInfo.jsonRootObj, "api_version", NtohsInter(pcidMain->apiVersion))) { - PRINT_ERR("cJSON_AddNumberToObject failed\n"); - return -1; - } - if (!cJSON_AddNumberToObject(freePcidJsonInfo.jsonRootObj, "manufacturer_id", - NtohlInter(pcidMain->manufacturerID))) { - PRINT_ERR("cJSON_AddNumberToObject failed\n"); - return -1; - } - if (!cJSON_AddStringToObject(freePcidJsonInfo.jsonRootObj, "system_type", systemType)) { - PRINT_ERR("cJSON_AddStringToObject failed\n"); - return -1; - } - if (!cJSON_AddItemToObject(freePcidJsonInfo.jsonRootObj, "syscap", freePcidJsonInfo.sysCapObj)) { - PRINT_ERR("cJSON_AddItemToObject failed\n"); - return -1; - } - return 0; -} - -static int32_t FreeAfterDecodePCID(struct FreeDecodePcidJsonInfo freePcidJsonInfo, int32_t type, int32_t ret) -{ - switch (type) { - case FREE_DECODE_PCID_CONVERT_OUT: - cJSON_free(freePcidJsonInfo.strJson); - cJSON_Delete(freePcidJsonInfo.jsonRootObj); - FreeContextBuffer(freePcidJsonInfo.contextBuffer); - break; - case FREE_DECODE_PCID_ROOT_OUT: - cJSON_Delete(freePcidJsonInfo.jsonRootObj); - cJSON_Delete(freePcidJsonInfo.sysCapObj); - FreeContextBuffer(freePcidJsonInfo.contextBuffer); - break; - case FREE_DECODE_PCID_SYSCAP_OUT: - cJSON_Delete(freePcidJsonInfo.sysCapObj); - FreeContextBuffer(freePcidJsonInfo.contextBuffer); - break; - case FREE_DECODE_PCID_CONTEXT_OUT: - cJSON_Delete(freePcidJsonInfo.sysCapObj); - FreeContextBuffer(freePcidJsonInfo.contextBuffer); - break; - default: - FreeContextBuffer(freePcidJsonInfo.contextBuffer); - } - return ret; -} - -int32_t DecodePCID(char *inputFile, char *outDirPath) -{ - int32_t ret = 0; - uint32_t contextBufLen; - struct FreeDecodePcidJsonInfo freePcidJsonInfo; - freePcidJsonInfo.strJson = NULL; - freePcidJsonInfo.contextBuffer = NULL; - freePcidJsonInfo.jsonRootObj = NULL; - freePcidJsonInfo.sysCapObj = NULL; - freePcidJsonInfo.flag = 0; - - ret = CheckFileAndGetFileContext(inputFile, &freePcidJsonInfo.contextBuffer, (uint32_t *)&contextBufLen); - if (ret != 0) { - return -1; - } - - PCIDMain *pcidMain = (PCIDMain *)freePcidJsonInfo.contextBuffer; - - /* api version */ - if (pcidMain->apiVersionType != 0) { - PRINT_ERR("Prase file failed, apiVersionType is invaild, input file : %s\n", inputFile); - return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_CONTEXT_OUT, -1); - } - - /* system type */ - char *systemType = pcidMain->systemType == 0b001 ? "mini" :(pcidMain->systemType == 0b010 ? "small" : - (pcidMain->systemType == 0b100 ? "standard" : NULL)); - if (systemType == NULL) { - PRINT_ERR("prase file failed, systemType is invaild, %u\n", pcidMain->systemType); - return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_CONTEXT_OUT, -1); - } - - /* syscap */ - freePcidJsonInfo.sysCapObj = cJSON_CreateObject(); - ret = CheckSysCapObj(freePcidJsonInfo, pcidMain, contextBufLen, ret); - if (freePcidJsonInfo.flag == -1) { - return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_CONTEXT_OUT, ret); - } - - // create json root - freePcidJsonInfo.jsonRootObj = cJSON_CreateObject(); - if (freePcidJsonInfo.jsonRootObj == NULL) { - PRINT_ERR("cJSON_CreateObject failed\n"); - return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_SYSCAP_OUT, -1); - } - - ret = CheckJsonRootObj(freePcidJsonInfo, pcidMain, systemType); - if (ret == -1) { - return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_ROOT_OUT, ret); - } - - freePcidJsonInfo.strJson = cJSON_Print(freePcidJsonInfo.jsonRootObj); - if (freePcidJsonInfo.strJson == NULL) { - return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_ROOT_OUT, -1); - } - - const char outputFileName[] = "pcid.json"; - ret = ConvertedContextSaveAsFile(outDirPath, outputFileName, freePcidJsonInfo.strJson, - strlen(freePcidJsonInfo.strJson)); - if (ret != 0) { - PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, outputFileName); - } - return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_CONVERT_OUT, ret); -} - -#define U32_TO_STR_MAX_LEN 11 -#define OS_SYSCAP_NUM 30 -#define PCID_HEADER 2 -static int32_t ParseStringSyscap(char *input, uint32_t *osSyscap, uint32_t osSyscapNum, - uint32_t *header, uint32_t headerLen) -{ - int32_t ret; - uint32_t tempNum; - uint32_t i = 0; - size_t inputLen = strlen(input); - - if (osSyscapNum != OS_SYSCAP_NUM || headerLen != PCID_HEADER) { - PRINT_ERR("Input osSyscapNum(%u) or headerLen(%u) error.\n", osSyscapNum, headerLen); - return -1; - } - - if (sscanf_s(input, "%u,%u,%s", &header[0], &header[1], input, inputLen) != 3) { // 3, return val of "%u,%u,%s" - PRINT_ERR("Get pcid header failed.\n"); - return -1; - } - - while ((ret = sscanf_s(input, "%u,%s", &tempNum, input, inputLen)) > 0) { - osSyscap[i++] = tempNum; - if (i >= OS_SYSCAP_NUM) { - break; - } - } - if (ret == -1) { - PRINT_ERR("sscanf_s failed, i = %u.\n", i); - return -1; - } - - if (strlen(input) <= 1) { - *input = '\0'; - } - - return 0; -} - -static int32_t AddHeaderToJsonObj(uint32_t *pcidHeader, uint32_t pcidHeaderLen, cJSON *rootObj) -{ - if (pcidHeaderLen != PCID_HEADER) { - PRINT_ERR("input pcidHeader(%u) error.\n", pcidHeaderLen); - return -1; - } - - PCIDHeader *header = (PCIDHeader *)pcidHeader; - // trans system type to string - char *systemType = header->systemType == 0b001 ? "mini" : - (header->systemType == 0b010 ? "small" : - (header->systemType == 0b100 ? "standard" : NULL)); - if (systemType == NULL) { - PRINT_ERR("prase system type failed.\n"); - return -1; - } - - // add to json - if (!cJSON_AddNumberToObject(rootObj, "api_version", NtohsInter(header->apiVersion))) { - PRINT_ERR("add api_version(%u) to json object failed.\n", NtohsInter(header->apiVersion)); - return -1; - } - if (!cJSON_AddNumberToObject(rootObj, "manufacturer_id", NtohlInter(header->manufacturerID))) { - PRINT_ERR("add manufacturer_id(%u) to json object failed\n", NtohlInter(header->manufacturerID)); - return -1; - } - if (!cJSON_AddStringToObject(rootObj, "system_type", systemType)) { - PRINT_ERR("add system_type(%s) to json object failed\n", systemType); - return -1; - } - return 0; -} - -static int32_t AddOsSyscapToJsonObj(uint32_t *osSyscapArray, uint32_t osSyscapArrayLen, cJSON *sysCapObj) -{ - cJSON *sysCapArray = cJSON_CreateArray(); - if (sysCapArray == NULL) { - PRINT_ERR("Create cJSON array failed.\n"); - return -1; - } - - if (osSyscapArrayLen != OS_SYSCAP_NUM) { - PRINT_ERR("Input os syscap array len error.\n"); - cJSON_Delete(sysCapArray); - return -1; - } - uint8_t *osSysCapArrayUint8 = (uint8_t *)osSyscapArray; - - uint32_t i, j; - uint32_t osSyscapCount = 0; - uint16_t index[OS_SYSCAP_BYTES * UINT8_BIT] = {0}; - for (i = 0; i < OS_SYSCAP_BYTES; i++) { - for (j = 0; j < UINT8_BIT; j++) { - if (osSysCapArrayUint8[i] & (0x01 << j)) { - index[osSyscapCount++] = i * UINT8_BIT + j; - } - } - } - - for (i = 0; i < osSyscapCount; i++) { - for (j = 0; j < sizeof(g_arraySyscap) / sizeof(SyscapWithNum); j++) { - if (index[i] != g_arraySyscap[j].num) { - continue; - } - if (!cJSON_AddItemToArray(sysCapArray, cJSON_CreateString(g_arraySyscap[j].str))) { - PRINT_ERR("Add os syscap string to json failed.\n"); - cJSON_Delete(sysCapArray); - return -1; - } - break; - } - } - - if (!cJSON_AddItemToObject(sysCapObj, "os", sysCapArray)) { - PRINT_ERR("Add os syscap item to json object failed.\n"); - cJSON_Delete(sysCapArray); - return -1; - } - return 0; -} - -static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapStringLen, cJSON *sysCapObj) -{ - char *token = NULL; - - cJSON *sysCapArray = cJSON_CreateArray(); - if (sysCapArray == NULL) { - PRINT_ERR("Create cJSON array failed.\n"); - return -1; - } - if (priSyscapStringLen == 0) { - if (!cJSON_AddItemToObject(sysCapObj, "private", sysCapArray)) { - PRINT_ERR("Add private syscap array to json failed.\n"); - cJSON_Delete(sysCapArray); - return -1; - } - cJSON_Delete(sysCapArray); - return 0; - } - - token = strtok(priSyscapString, ","); - while (token != NULL) { - if (!cJSON_AddItemToArray(sysCapArray, cJSON_CreateString(token))) { - PRINT_ERR("Add private syscap string to json failed.\n"); - cJSON_Delete(sysCapArray); - return -1; - } - token = strtok(NULL, ","); - } - if (!cJSON_AddItemToObject(sysCapObj, "private", sysCapArray)) { - PRINT_ERR("Add private syscap array to json failed.\n"); - cJSON_Delete(sysCapArray); - return -1; - } - return 0; -} - -static int32_t GetSyscapStr(char *input, char const *priSyscapStr, uint32_t* osSyscap, uint32_t *pcidHeader) -{ - if (input == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - char *ctx = NULL; - uint32_t fileContextLen; - if (GetFileContext(input, &ctx, (uint32_t *)&fileContextLen) != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", input); - return -1; - } - if (ParseStringSyscap(ctx, osSyscap, OS_SYSCAP_NUM, pcidHeader, PCID_HEADER) != 0) { - PRINT_ERR("Parse string syscap failed.\n"); - free(ctx); - return -1; - } - priSyscapStr = ctx; - return 0; -} - -int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) -{ - int32_t ret = -1; - uint32_t osSyscap[OS_SYSCAP_NUM] = {0}; - uint32_t pcidHeader[PCID_HEADER]; - char *priSyscapStr = NULL; - char *jsonBuffer = NULL; - - ret = GetSyscapStr(input, priSyscapStr, osSyscap, pcidHeader); - if (ret == -1) { - return ret; - } - - // add to json object - cJSON *sysCapObj = cJSON_CreateObject(); - cJSON *rootObj = cJSON_CreateObject(); - if (sysCapObj == NULL || rootObj == NULL) { - PRINT_ERR("Failed to create cJSON objects.\n"); - goto FAILED; - } - - if (!cJSON_AddItemToObject(rootObj, "syscap", sysCapObj)) { - PRINT_ERR("Add syscap to json failed.\n"); - goto FAILED; - } - if (AddHeaderToJsonObj(pcidHeader, PCID_HEADER, rootObj) != 0) { - PRINT_ERR("Add header to json object failed.\n"); - goto FAILED; - } - if (AddOsSyscapToJsonObj(osSyscap, OS_SYSCAP_NUM, sysCapObj) != 0) { - PRINT_ERR("Add os syscap json object failed.\n"); - goto FAILED; - } - - if (AddPriSyscapToJsonObj(priSyscapStr, (uint32_t) strlen(priSyscapStr), sysCapObj) != 0) { - PRINT_ERR("Add private syscap json object failed.\n"); - goto FAILED; - } - // save as json file - jsonBuffer = cJSON_Print(rootObj); - if (jsonBuffer == NULL) { - PRINT_ERR("json buffer is null.\n"); - goto FAILED; - } - const char outputFileName[] = "pcid.json"; - if (ConvertedContextSaveAsFile(outDirPath, outputFileName, jsonBuffer, strlen(jsonBuffer)) != 0) { - PRINT_ERR("Save as json file failed.\n"); - goto FAILED; - } - ret = 0; - -FAILED: - cJSON_free(jsonBuffer); - SafeFree(priSyscapStr); - cJSON_Delete(sysCapObj); - cJSON_Delete(rootObj); - return ret; -} - -static int32_t FreeAfterEncodePCID(struct FreeEncodePcidInfo freePcidInfo, int32_t type, int32_t ret) -{ - switch (type) { - case FREE_ENCODE_PCID_OUT: - free(freePcidInfo.output); - free(freePcidInfo.priSyscapFull); - free(freePcidInfo.contextBuffer); - break; - case FREE_ENCODE_PCID_PRISYSCAP_FULL_OUT: - free(freePcidInfo.priSyscapFull); - free(freePcidInfo.contextBuffer); - break; - case FREE_ENCODE_PCID_CONTEXT_OUT: - default: - free(freePcidInfo.contextBuffer); - } - return ret; -} - -static int32_t GetEncodePCIDOut(uint16_t priSyscapCount, uint32_t privateSyscapLen, uint32_t *mainSyscap, - struct FreeEncodePcidInfo freePcidInfo, int32_t ret) -{ - // 17, size of "SystemCapability." - uint32_t outputLen = U32_TO_STR_MAX_LEN * PCID_OUT_BUFFER + 17 * priSyscapCount + privateSyscapLen + 1; - char *output = NULL; - uint32_t i; - output = (char *)malloc(outputLen); - if (output == NULL) { - PRINT_ERR("malloc failed\n"); - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_PRISYSCAP_FULL_OUT, ret); - } - (void)memset_s(output, outputLen, 0, outputLen); - ret = sprintf_s(output, outputLen, "%u", mainSyscap[0]); - if (ret == -1) { - PRINT_ERR("sprintf_s failed\n"); - free(output); - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); - } - for (i = 1; i < PCID_OUT_BUFFER; i++) { - ret = sprintf_s(output, outputLen, "%s,%u", output, mainSyscap[i]); - if (ret == -1) { - PRINT_ERR("sprintf_s failed\n"); - free(output); - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); - } - } - for (i = 0; i < priSyscapCount; i++) { - ret = sprintf_s(output, outputLen, "%s,%s", output, freePcidInfo.priSyscapFull + i * SINGLE_SYSCAP_LEN); - if (ret == -1) { - PRINT_ERR("sprintf_s failed\n"); - free(output); - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); - } - } - // save as file - const char outputFileName[] = "pcid.txt"; - ret = ConvertedContextSaveAsFile(freePcidInfo.outDirPathFinal, outputFileName, output, strlen(output)); - if (ret != 0) { - PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", - freePcidInfo.outDirPathFinal, outputFileName); - } - free(output); - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); -} - -static int32_t CheckPrivateSyCap(struct FreeEncodePcidInfo freePcidInfo, uint32_t privateSyscapLen, - char *privateSyscap, int32_t ret) -{ - uint32_t i, j; - char tempSyscap[SINGLE_SYSCAP_LEN] = {0}; - char *temp = tempSyscap; - for (i = 0, j = 0; i < privateSyscapLen; i++) { - if (*privateSyscap == ',') { - *temp = '\0'; - ret = sprintf_s(freePcidInfo.priSyscapFull + j * SINGLE_SYSCAP_LEN, SINGLE_SYSCAP_LEN, - "SystemCapability.%s", tempSyscap); - if (ret == -1) { - PRINT_ERR("sprintf_s failed\n"); - return ret; - } - temp = tempSyscap; - privateSyscap++; - j++; - continue; - } - *temp++ = *privateSyscap++; - } - return ret; -} - -int32_t EncodePcidscToString(char *inputFile, char *outDirPath) -{ - int32_t ret = 0; - uint32_t bufferLen, privateSyscapLen; - uint32_t i; - uint32_t *mainSyscap = NULL; - uint16_t priSyscapCount = 0; - - char *privateSyscap = NULL; - struct FreeEncodePcidInfo freePcidInfo; - freePcidInfo.contextBuffer = NULL; - freePcidInfo.priSyscapFull = NULL; - freePcidInfo.output = NULL; - freePcidInfo.outDirPathFinal = outDirPath; - PCIDMain *pcidMain = NULL; - - ret = CheckFileAndGetFileContext(inputFile, &freePcidInfo.contextBuffer, (uint32_t *)&bufferLen); - if (ret != 0) { - return -1; - } - - if (bufferLen > 1128) { // 1128, max size of pcid.sc - PRINT_ERR("Input pcid file too large, pcid file size: %u\n", bufferLen); - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_CONTEXT_OUT, ret); - } - - pcidMain = (PCIDMain *)freePcidInfo.contextBuffer; - privateSyscap = (char *)(pcidMain + 1); - privateSyscapLen = strlen(privateSyscap); - - // process os syscap - mainSyscap = (uint32_t *)pcidMain; - - // process private syscap - for (i = 0; i < privateSyscapLen; i++) { - if (privateSyscap[i] == ',') { - priSyscapCount++; - } - } - if (priSyscapCount == 0) { - return GetEncodePCIDOut(priSyscapCount, privateSyscapLen, mainSyscap, freePcidInfo, ret); - } - freePcidInfo.priSyscapFull = (char *)malloc(priSyscapCount * SINGLE_SYSCAP_LEN); - if (freePcidInfo.priSyscapFull == NULL) { - PRINT_ERR("malloc failed\n"); - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_CONTEXT_OUT, ret); - } - (void)memset_s(freePcidInfo.priSyscapFull, priSyscapCount * SINGLE_SYSCAP_LEN, - 0, priSyscapCount * SINGLE_SYSCAP_LEN); - - ret = CheckPrivateSyCap(freePcidInfo, privateSyscapLen, privateSyscap, ret); - if (ret == -1) { - return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_PRISYSCAP_FULL_OUT, ret); - } - - // output - return GetEncodePCIDOut(priSyscapCount, privateSyscapLen, mainSyscap, freePcidInfo, ret); -} \ No newline at end of file -- Gitee