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 <stddef.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include <securec.h>
21
22 #include "bus_center_adapter.h"
23 #include "parameter.h"
24 #include "softbus_adapter_log.h"
25 #include "softbus_common.h"
26 #include "softbus_errcode.h"
27
28 #define DEFAULT_DEVICE_NAME "OpenHarmony"
29
GetCommonDevInfo(const CommonDeviceKey key,char * value,uint32_t len)30 int32_t GetCommonDevInfo(const CommonDeviceKey key, char *value, uint32_t len)
31 {
32 if (value == NULL) {
33 HILOG_ERROR(SOFTBUS_HILOG_ID, "fail: para error!");
34 return SOFTBUS_INVALID_PARAM;
35 }
36 char localUdid[UDID_BUF_LEN] = {0};
37 const char *devType = NULL;
38 switch (key) {
39 case COMM_DEVICE_KEY_DEVNAME:
40 if (strncpy_s(value, len, DEFAULT_DEVICE_NAME, strlen(DEFAULT_DEVICE_NAME)) != EOK) {
41 return SOFTBUS_ERR;
42 }
43 break;
44 case COMM_DEVICE_KEY_UDID:
45 if (GetDevUdid(localUdid, UDID_BUF_LEN) != 0) {
46 HILOG_ERROR(SOFTBUS_HILOG_ID, "GetDevUdid failed!");
47 return SOFTBUS_ERR;
48 }
49 if (strncpy_s(value, len, localUdid, UDID_BUF_LEN) != EOK) {
50 return SOFTBUS_ERR;
51 }
52 break;
53 case COMM_DEVICE_KEY_DEVTYPE:
54 devType = GetDeviceType();
55 if (devType == NULL) {
56 HILOG_ERROR(SOFTBUS_HILOG_ID, "GetDeviceType failed!");
57 return SOFTBUS_ERR;
58 }
59 if (strncpy_s(value, len, devType, strlen(devType)) != EOK) {
60 return SOFTBUS_ERR;
61 }
62 break;
63 default:
64 break;
65 }
66 return SOFTBUS_OK;
67 }
68