diff --git a/0006-feat-auto-generated-udid-and-add-new-interfaces.patch b/0006-feat-auto-generated-udid-and-add-new-interfaces.patch new file mode 100644 index 0000000000000000000000000000000000000000..342228c4bd030991ab43ec481398d91fc79ce331 --- /dev/null +++ b/0006-feat-auto-generated-udid-and-add-new-interfaces.patch @@ -0,0 +1,367 @@ +From 75f7f930e9bb433a486d401ceb7fb3371b7676d7 Mon Sep 17 00:00:00 2001 +From: peng_langyuan +Date: Tue, 7 May 2024 16:03:58 +0800 +Subject: [PATCH] feat-auto-generated-udid-and-add-new-interfaces + +--- + bundle.json | 1 + + etc/BUILD.gn | 28 +++++ + etc/default.para | 18 +++ + interfaces/innerkits/BUILD.gn | 5 + + .../innerkits/include/syspara/parameter.h | 2 + + interfaces/innerkits/syspara/param_comm.c | 108 ++++++++++++++++-- + interfaces/innerkits/syspara/param_comm.h | 2 + + interfaces/innerkits/syspara/parameter.c | 64 +++-------- + 8 files changed, 169 insertions(+), 59 deletions(-) + create mode 100644 etc/BUILD.gn + create mode 100644 etc/default.para + +diff --git a/bundle.json b/bundle.json +index 7d22547..ed9d605 100755 +--- a/bundle.json ++++ b/bundle.json +@@ -42,6 +42,7 @@ + ] + }, + "sub_component": [ ++ "//base/startup/init/etc:startup_etc", + "//base/startup/init/services/param_service:param_service" + ], + "inner_kits": [ +diff --git a/etc/BUILD.gn b/etc/BUILD.gn +new file mode 100644 +index 0000000..8b663dc +--- /dev/null ++++ b/etc/BUILD.gn +@@ -0,0 +1,28 @@ ++# Copyright (c) 2023 HopeRun 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. ++ ++import("//build/ohos.gni") ++ ++group("startup_etc") { ++ deps = [ ++ ":default.para", ++ ] ++} ++ ++ohos_prebuilt_etc("default.para") { ++ source = "default.para" ++ relative_install_dir = "param" ++ part_name = "init" ++ subsystem_name = "startup" ++} ++ +diff --git a/etc/default.para b/etc/default.para +new file mode 100644 +index 0000000..680ef43 +--- /dev/null ++++ b/etc/default.para +@@ -0,0 +1,18 @@ ++# Copyright (c) 2024 HopeRun 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. ++ ++const.product.devicetype=default ++const.product.manufacturer=default ++const.product.model=oeos ++const.default.account=0 ++const.device.name=OpenEuler +diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn +index a68eaee..65be6f2 100755 +--- a/interfaces/innerkits/BUILD.gn ++++ b/interfaces/innerkits/BUILD.gn +@@ -50,6 +50,11 @@ ohos_shared_library("libbegetutil") { + "//base/startup/init/services/utils:libinit_utils", + ] + deps += [ "//base/startup/init/services/param/base:param_base" ] ++ ++ libs = [ ++ "/usr/lib64/libcrypto.so" ++ ] ++ + external_deps = [ + "c_utils:utils", + ] +diff --git a/interfaces/innerkits/include/syspara/parameter.h b/interfaces/innerkits/include/syspara/parameter.h +index 36dc05e..e688ffd 100755 +--- a/interfaces/innerkits/include/syspara/parameter.h ++++ b/interfaces/innerkits/include/syspara/parameter.h +@@ -119,6 +119,8 @@ int RemoveParameterWatcher(const char *keyPrefix, ParameterChgPtr callback, void + + const char *GetDeviceType(void); + int GetDevUdid(char *udid, int size); ++int GetOsAccount(int *id); ++int GetDeviceName(char* deviceName, int size); + int32_t GetIntParameter(const char *key, int32_t def); + uint32_t GetUintParameter(const char *key, uint32_t def); + +diff --git a/interfaces/innerkits/syspara/param_comm.c b/interfaces/innerkits/syspara/param_comm.c +index a05c2ab..c139f4b 100644 +--- a/interfaces/innerkits/syspara/param_comm.c ++++ b/interfaces/innerkits/syspara/param_comm.c +@@ -17,6 +17,7 @@ + + #include + #include ++#include + + #include "init_param.h" + #ifdef LITEOS_SUPPORT +@@ -28,6 +29,30 @@ + #include "securec.h" + #include "beget_ext.h" + ++static int GetSha256Value(const char *input, char *udid, int udidSize) ++{ ++ if (input == NULL) { ++ return EC_FAILURE; ++ } ++ ++ unsigned char hash[SHA256_DIGEST_LENGTH]; ++ SHA256_CTX ctx; ++ SHA256_Init(&ctx); ++ SHA256_Update(&ctx, input, strlen(input)); ++ SHA256_Final(hash, &ctx); ++ ++ char buf[DEV_BUF_LENGTH] = { 0 }; ++ for (size_t i = 0; i < SHA256_DIGEST_LENGTH; i++) { ++ unsigned char value = hash[i]; ++ memset_s(buf, DEV_BUF_LENGTH, 0, DEV_BUF_LENGTH); ++ int len = sprintf_s(buf, sizeof(buf), "%02X", value); ++ if (len > 0 && strcat_s(udid, udidSize, buf) != 0) { ++ return EC_FAILURE; ++ } ++ } ++ return EC_SUCCESS; ++} ++ + BEGET_LOCAL_API int GetSystemError(int err) + { + switch (err) { +@@ -124,18 +149,24 @@ BEGET_LOCAL_API const char *GetManufacture_(void) + + BEGET_LOCAL_API const char *GetSerial_(void) + { +-#ifdef LITEOS_SUPPORT +- return HalGetSerial(); +-#else ++ // A-Z, 0-9随机生成 ++ char ch[36]; + static char *ohosSerial = NULL; ++ for (int i = 0; i < 26; ++i) { ++ ch[i] = i + 'A'; ++ } ++ for (int i = 26; i < 36; ++i) { ++ ch[i] = '0' + i - 26; ++ } + if (ohosSerial == NULL) { +- BEGET_CHECK((ohosSerial = (char *)calloc(1, PARAM_VALUE_LEN_MAX)) != NULL, return NULL); ++ ohosSerial = (char *)calloc(1, PARAM_VALUE_LEN_MAX); ++ } ++ srand(time(0)); ++ for (int i = 0; i < 7; ++i) { ++ *(ohosSerial+i) = ch[rand()%36]; + } +- uint32_t len = PARAM_VALUE_LEN_MAX; +- int ret = SystemGetParameter("ohos.boot.sn", ohosSerial, &len); +- BEGET_CHECK(ret == 0, return NULL); + return ohosSerial; +-#endif ++ + } + + BEGET_LOCAL_API int GetDevUdid_(char *udid, int size) +@@ -145,8 +176,65 @@ BEGET_LOCAL_API int GetDevUdid_(char *udid, int size) + } + + uint32_t len = (uint32_t)size; +- int ret = SystemGetParameter("const.product.udid", udid, &len); ++ int ret = SystemGetParameter("persist.product.udid", udid, &len); + BEGET_CHECK(ret != 0, return ret); + ++ const char *manufacture = GetManufacture_(); ++ const char *model = GetProductModel_(); ++ const char *sn = GetSerial_(); ++ if (manufacture == NULL || model == NULL || sn == NULL) { ++ return -1; ++ } ++ int tmpSize = strlen(manufacture) + strlen(model) + strlen(sn) + 1; ++ if (tmpSize <= 1 || tmpSize > DEV_BUF_MAX_LENGTH) { ++ return -1; ++ } ++ char *tmp = (char *)malloc(tmpSize); ++ if (tmp == NULL) { ++ return -1; ++ } ++ ++ (void)memset_s(tmp, tmpSize, 0, tmpSize); ++ if ((strcat_s(tmp, tmpSize, manufacture) != 0) || (strcat_s(tmp, tmpSize, model) != 0) || ++ (strcat_s(tmp, tmpSize, sn) != 0)) { ++ free(tmp); ++ return -1; ++ } ++ ++ ret = GetSha256Value(tmp, udid, size); ++ if (ret == EC_SUCCESS) { ++ SystemSetParameter("persist.product.udid", udid); ++ } + return ret; +-} +\ No newline at end of file ++} ++ ++BEGET_LOCAL_API int GetDeviceName_(char *deviceName, int size) ++{ ++ if (size < 0 || deviceName == NULL) { ++ return EC_FAILURE; ++ } ++ ++ uint32_t len; ++ if (size > PARAM_BUFFER_MAX) { ++ len = PARAM_BUFFER_MAX; ++ } else { ++ len = (uint32_t)size; ++ } ++ ++ int ret = SystemGetParameter("const.device.name", deviceName, &len); ++ BEGET_CHECK(ret == 0, return ret); ++ ++ return ret; ++} ++ ++BEGET_LOCAL_API int GetOsAccount_(int *id) ++{ ++ char account[10] = {0}; ++ int len = sizeof(account); ++ ++ int ret = SystemGetParameter("const.default.account", account, &len); ++ BEGET_CHECK(ret == 0, return ret); ++ ++ *id = atoi(account); ++ return ret; ++} +diff --git a/interfaces/innerkits/syspara/param_comm.h b/interfaces/innerkits/syspara/param_comm.h +index b847c74..d3279cd 100755 +--- a/interfaces/innerkits/syspara/param_comm.h ++++ b/interfaces/innerkits/syspara/param_comm.h +@@ -36,6 +36,8 @@ BEGET_LOCAL_API int GetParameter_(const char *key, const char *def, char *value, + BEGET_LOCAL_API const char *GetManufacture_(void); + BEGET_LOCAL_API const char *GetSerial_(void); + BEGET_LOCAL_API int GetDevUdid_(char *udid, int size); ++BEGET_LOCAL_API int GetDeviceName_(char *devcieName, int size); ++BEGET_LOCAL_API int GetOsAccount_(int *id); + BEGET_LOCAL_API int IsValidParamValue(const char *value, uint32_t len); + BEGET_LOCAL_API int GetSystemError(int err); + #ifdef __cplusplus +diff --git a/interfaces/innerkits/syspara/parameter.c b/interfaces/innerkits/syspara/parameter.c +index 060f8ce..1132d4a 100644 +--- a/interfaces/innerkits/syspara/parameter.c ++++ b/interfaces/innerkits/syspara/parameter.c +@@ -25,8 +25,6 @@ + #include "securec.h" + #include "beget_ext.h" + +-#define SN_LEN 65 +-#define SN_FILE "/etc/SN" + + int WaitParameter(const char *key, const char *value, int timeout) + { +@@ -55,60 +53,28 @@ int SetParameter(const char *key, const char *value) + + const char *GetDeviceType(void) + { +- // static const char *productType = NULL; +- // const char *deviceType = GetProperty("const.product.devicetype", &productType); +- // if (deviceType != NULL) { +- // return deviceType; +- // } +- // return GetProperty("const.build.characteristics", &productType); +- return "UNKNOWN"; ++ static const char *productType = NULL; ++ const char *deviceType = GetProperty("const.product.devicetype", &productType); ++ if (deviceType != NULL) { ++ return deviceType; ++ } ++ return GetProperty("const.build.characteristics", &productType); + } + +-// 暂时使用/etc/SN里面的数字代表udid + int GetDevUdid(char *udid, int size) + { +- FILE *fp; +- char *realPath = NULL; +- char sn[SN_LEN] = {0}; +- // char out[UDID_LEN] = {0}; +- int ret; +- +- realPath = realpath(SN_FILE, NULL); +- if (realPath == NULL) { +- printf("realpath fail.\n"); +- goto err_realpath; +- } +- +- fp = fopen(realPath, "r"); +- if (fp == NULL) { +- printf("open SN fail.\n"); +- goto err_fopen; +- } +- +- ret = fscanf_s(fp, "%s", sn, SN_LEN); +- if (ret < 1) { +- printf("get sn fail.\n"); +- goto err_out; +- } +- +- if (strcpy_s(udid, size, sn) != EOK) { +- return 1; +- } ++ return GetDevUdid_(udid, size); ++} + +- fclose(fp); +- return 0; +-err_out: +- fclose(fp); +-err_fopen: +- free(realPath); +-err_realpath: +- return -1; ++int GetDeviceName(char* deviceName, int size) ++{ ++ return GetDeviceName_(deviceName, size); + } + +-// int GetDevUdid(char *udid, int size) +-// { +-// return GetDevUdid_(udid, size); +-// } ++int GetOsAccount(int *id) ++{ ++ return GetOsAccount_(id); ++} + + int32_t GetIntParameter(const char *key, int32_t def) + { +-- +2.33.0 + diff --git a/0007-modify-default-param-read-path.patch b/0007-modify-default-param-read-path.patch new file mode 100644 index 0000000000000000000000000000000000000000..e3f8f055fe580e4518e94245dd38e863c6cd6e04 --- /dev/null +++ b/0007-modify-default-param-read-path.patch @@ -0,0 +1,32 @@ +From ee5eb1c1a8c3247b26ca5b265528cfa59eb8c9b0 Mon Sep 17 00:00:00 2001 +From: peng_langyuan +Date: Tue, 7 May 2024 16:30:16 +0800 +Subject: [PATCH] modify default param read path + +--- + services/param/include/param_utils.h | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/services/param/include/param_utils.h b/services/param/include/param_utils.h +index e613eee..af86268 100644 +--- a/services/param/include/param_utils.h ++++ b/services/param/include/param_utils.h +@@ -34,7 +34,7 @@ extern "C" { + #define PIPE_PATH "/dev/unix/socket" + #define CLIENT_PIPE_NAME "/dev/unix/socket/paramservice" + #define PIPE_NAME "/dev/unix/socket/paramservice" +-#define SYSTEM_PARAM_PATH "/system/etc/param" ++#define SYSTEM_PARAM_PATH "/etc/param" + #define USER_PARAM_PATH "/data/service/el1/public/param_service/" + #define USER_PARAM_FILE USER_PARAM_PATH "/user.para" + #define CONST_PREFIX "const." +@@ -44,4 +44,4 @@ extern "C" { + } + #endif + #endif +-#endif +\ No newline at end of file ++#endif +-- +2.33.0 + diff --git a/distributed-beget.spec b/distributed-beget.spec index 4432097b6c8bb36c24c6e7ccf5ec7e6624ea0b30..018926a396380b7ff0128f8a3233c7e726ab68a1 100644 --- a/distributed-beget.spec +++ b/distributed-beget.spec @@ -5,7 +5,7 @@ Name: distributed-beget Version: 1.0.0 -Release: 6 +Release: 7 Summary: openEuler embedded softbus capability support License: Apache License 2.0 URL: https://gitee.com/openeuler/distributed-beget.git @@ -17,8 +17,10 @@ Patch2: 0002-feat-for-embedded-fix-compile-errors.patch Patch3: 0003-feat-for-embedded-fix-sysroot-hilog-path.patch Patch4: 0004-refactor-using-the-reactor-framework.patch Patch5: 0005-feat-for-embedded-fix-compile-errors-after-refactor.patch +Patch6: 0006-feat-auto-generated-udid-and-add-new-interfaces.patch +Patch7: 0007-modify-default-param-read-path.patch -BuildRequires: distributed-build, hilog, commonlibrary_c_utils +BuildRequires: distributed-build, hilog, commonlibrary_c_utils,compat-openssl11-devel Requires: commonlibrary_c_utils Requires: hilog @@ -45,6 +47,8 @@ cp -rf %{_builddir}/build/openeuler/compiler_gn/* %{_builddir} %patch -P3 -p1 -d %{_builddir}/base/startup/init %patch -P4 -p1 -d %{_builddir}/base/startup/init %patch -P5 -p1 -d %{_builddir}/base/startup/init +%patch -P6 -p1 -d %{_builddir}/base/startup/init +%patch -P7 -p1 -d %{_builddir}/base/startup/init # exit 0 %build @@ -63,6 +67,7 @@ install -d -m 0755 %{buildroot}/%{_libdir} install -d -m 0755 %{buildroot}/system/lib64/ install -d -m 0755 %{buildroot}/%{_bindir} install -d -m 0755 %{buildroot}%{build_opt}/openeuler/compiler_gn/base/startup/init/interfaces/innerkits +install -d -m 0755 %{buildroot}/%{_sysconfdir}/param %ifarch aarch64 %define module_out_path out/openeuler/linux_clang_arm64 @@ -89,6 +94,8 @@ install -m 0755 %{_builddir}/%{interface_path}/syspara/* %{buildroot}/%{_include install -m 0755 %{_builddir}/%{service_path}/init_utils.h %{buildroot}/%{_includedir}/init install -m 0755 %{_builddir}/%{service_path}/param/* %{buildroot}/%{_includedir}/init/param install -m 0755 %{_builddir}/%{service_path}/param/* %{buildroot}/%{_includedir}/init +# default param file +install -m 0755 %{_builddir}/out/openeuler/packages/phone/system/etc/param/* %{buildroot}/%{_sysconfdir}/param # cp bundle.json mkdir -p %{buildroot}%{init_path} @@ -105,8 +112,12 @@ ln -s /usr/include/init %{buildroot}%{build_opt}/openeuler/compiler_gn/%{interfa %{_includedir}/init/* /system/lib64/* %{build_opt}/* +%{_sysconfdir}/* %changelog +* Tue May 7 2024 peng_langyuan - 1.0.0-7 +- Apply the 6th and 7th patch + * Wed Apr 24 2024 s_c_c - 1.0.0-6 - Apply the 5th patch