1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <securec.h>
17 #include "hcs_dm_parser.h"
18 #include "hcs_tree_if.h"
19 #include "hdf_attribute_manager.h"
20 #include "hdf_log.h"
21
22 #define HDF_LOG_TAG attribute_manager
23
24 #ifdef __OHOS_STANDARD_SYS__
25 #define HOST_CONFIG_PATH HDF_CONFIG_DIR
26 #else
27 #define HOST_CONFIG_PATH "/system/etc/hdfconfig"
28 #endif
29 #define PRODUCT_PROPERTY "ro.build.product"
30 #define PRODUCT_NAME_MAX 128
31
GetProductName(char * name,int maxLen)32 static int GetProductName(char *name, int maxLen)
33 {
34 return strcpy_s(name, maxLen, "default");
35 }
36
HdfGetHcsRootNode(void)37 const struct DeviceResourceNode *HdfGetHcsRootNode(void)
38 {
39 char productName[PRODUCT_NAME_MAX] = { 0 };
40 char configPath[PATH_MAX] = { 0 };
41
42 int ret = GetProductName(productName, PRODUCT_NAME_MAX);
43 if (ret != HDF_SUCCESS) {
44 return NULL;
45 }
46
47 ret = sprintf_s(configPath, PATH_MAX - 1, "%s/hdf_%s.hcb", HOST_CONFIG_PATH, productName);
48 if (ret < 0) {
49 HDF_LOGE("config path error");
50 return NULL;
51 }
52
53 const char *configFileName = configPath;
54 SetHcsBlobPath(configFileName);
55 const struct DeviceResourceNode *mgrRoot = HcsGetRootNode();
56 return mgrRoot;
57 }
58