1 /*
2 * Copyright (C) 2022 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 "hc_dev_info.h"
17 #include "hal_error.h"
18 #include "hc_log.h"
19 #include "securec.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 static bool g_isClient = true;
26 static char *g_clientDevUdid = "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930";
27 static char *g_serverDevUdid = "52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C749558BD2E6492C";
28
SetDeviceStatus(bool isClient)29 void SetDeviceStatus(bool isClient)
30 {
31 g_isClient = isClient;
32 }
33
HcGetUdid(uint8_t * udid,int32_t udidLen)34 int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
35 {
36 if (udid == NULL || udidLen < INPUT_UDID_LEN || udidLen > MAX_INPUT_UDID_LEN) {
37 return HAL_ERR_INVALID_PARAM;
38 }
39 char *devUdid;
40 if (g_isClient) {
41 devUdid = g_clientDevUdid;
42 LOGI("Use mock client device udid.");
43 } else {
44 devUdid = g_serverDevUdid;
45 LOGI("Use mock server device udid.");
46 }
47 if (memcpy_s(udid, udidLen, devUdid, INPUT_UDID_LEN) != EOK) {
48 LOGE("Failed to copy udid!");
49 return HAL_FAILED;
50 }
51 return HAL_SUCCESS;
52 }
53
GetStoragePath(void)54 const char *GetStoragePath(void)
55 {
56 #ifndef LITE_DEVICE
57 const char *storageFile = "/data/service/el1/public/deviceauth/hcgroup.dat";
58 #else
59 const char *storageFile = "/storage/deviceauth/hcgroup.dat";
60 #endif
61 LOGI("[OS]: storageFile: %s", storageFile);
62 return storageFile;
63 }
64
GetStorageDirPath(void)65 const char *GetStorageDirPath(void)
66 {
67 #ifndef LITE_DEVICE
68 const char *storageFile = "/data/service/el1/public/deviceauth";
69 #else
70 const char *storageFile = "/storage/deviceauth";
71 #endif
72 LOGI("[OS]: storageDirFile: %s", storageFile);
73 return storageFile;
74 }
75
GetAccountStoragePath(void)76 const char *GetAccountStoragePath(void)
77 {
78 #ifndef LITE_DEVICE
79 const char *storageFile = "/data/service/el1/public/deviceauth/account";
80 #else
81 const char *storageFile = "/storage/deviceauth/account";
82 #endif
83 LOGI("[OS]: Account storage dir: %s", storageFile);
84 return storageFile;
85 }
86
87 #ifdef __cplusplus
88 }
89 #endif
90