• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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 #include <stdio.h>
16 #include <stdbool.h>
17 #include <string.h>
18 
19 #include <sys/stat.h>
20 #include <sys/time.h>
21 #include <sys/types.h>
22 #include <emmc_if.h>
23 #include "hal_sys_param.h"
24 
25 #define STR_MAX 65
26 #define CID_LENGTH 16
27 #define EOK 0
28 #define TWO_TIMES 2
29 #define DIGITAL_CID_LENGTH    (CID_LENGTH * TWO_TIMES + 1)
30 #define HEX_OF_BINARY_BITS 4
31 #define LAST_FOUR_BINARY_DIGITS 16
32 #define DIVIDE_NUMBER_AND_LETTERS 10
33 #define CID_ERROR    (-1)
34 #define CID_OK    1
35 
36 static const char OHOS_DEVICE_TYPE[] = {"****"};
37 static const char OHOS_DISPLAY_VERSION[] = {"OpenHarmony 3.0 LTS"};
38 static const char OHOS_MANUFACTURE[] = {"****"};
39 static const char OHOS_BRAND[] = {"****"};
40 static const char OHOS_MARKET_NAME[] = {"****"};
41 static const char OHOS_PRODUCT_SERIES[] = {"****"};
42 static const char OHOS_PRODUCT_MODEL[] = {"****"};
43 static const char OHOS_SOFTWARE_MODEL[] = {"****"};
44 static const char OHOS_HARDWARE_MODEL[] = {"****"};
45 static const char OHOS_HARDWARE_PROFILE[] = {"aout:true,display:true"};
46 static const char OHOS_BOOTLOADER_VERSION[] = {"bootloader"};
47 static const char OHOS_ABI_LIST[] = {"****"};
48 static const char OHOS_SERIAL[] = {"1234567890"};  // provided by OEM.
49 static const int OHOS_FIRST_API_VERSION = 1;
50 static const char EMPTY_STR[] = {""};
51 
HalGetDeviceType(void)52 const char* HalGetDeviceType(void)
53 {
54     return OHOS_DEVICE_TYPE;
55 }
56 
HalGetManufacture(void)57 const char* HalGetManufacture(void)
58 {
59     return OHOS_MANUFACTURE;
60 }
61 
HalGetBrand(void)62 const char* HalGetBrand(void)
63 {
64     return OHOS_BRAND;
65 }
66 
HalGetMarketName(void)67 const char* HalGetMarketName(void)
68 {
69     return OHOS_MARKET_NAME;
70 }
71 
HalGetProductSeries(void)72 const char* HalGetProductSeries(void)
73 {
74     return OHOS_PRODUCT_SERIES;
75 }
76 
HalGetProductModel(void)77 const char* HalGetProductModel(void)
78 {
79     return OHOS_PRODUCT_MODEL;
80 }
81 
HalGetSoftwareModel(void)82 const char* HalGetSoftwareModel(void)
83 {
84     return OHOS_SOFTWARE_MODEL;
85 }
86 
HalGetHardwareModel(void)87 const char* HalGetHardwareModel(void)
88 {
89     return OHOS_HARDWARE_MODEL;
90 }
91 
HalGetHardwareProfile(void)92 const char* HalGetHardwareProfile(void)
93 {
94     return OHOS_HARDWARE_PROFILE;
95 }
96 
GetDigitalCidLocation(int i)97 static int GetDigitalCidLocation(int i)
98 {
99     return ((i / HEX_OF_BINARY_BITS + 1) * HEX_OF_BINARY_BITS - (i % HEX_OF_BINARY_BITS) - 1) * TWO_TIMES;
100 }
101 
TranslateCid(uint8_t * cid,uint32_t cidLen,char * digitalCid,uint32_t digitalCidLen)102 static int32_t TranslateCid(uint8_t *cid, uint32_t cidLen, char *digitalCid, uint32_t digitalCidLen)
103 {
104     if (cid == NULL || digitalCid == NULL || cidLen * TWO_TIMES + 1 != digitalCidLen) {
105         return CID_ERROR;
106     }
107     uint8_t tmp;
108     for (int i = 0; i < cidLen; i++) {
109         tmp = cid[i] / LAST_FOUR_BINARY_DIGITS;
110         if (tmp < DIVIDE_NUMBER_AND_LETTERS) {
111             digitalCid[GetDigitalCidLocation(i)] = tmp + '0';
112         } else {
113             digitalCid[GetDigitalCidLocation(i)] = tmp - DIVIDE_NUMBER_AND_LETTERS + 'a';
114         }
115         tmp = cid[i] % LAST_FOUR_BINARY_DIGITS;
116         if (tmp < DIVIDE_NUMBER_AND_LETTERS) {
117             digitalCid[GetDigitalCidLocation(i) + 1] = tmp + '0';
118         } else {
119             digitalCid[GetDigitalCidLocation(i) + 1] = tmp - DIVIDE_NUMBER_AND_LETTERS + 'a';
120         }
121     }
122     digitalCid[digitalCidLen - 1] = '\0';
123     return CID_OK;
124 }
125 
Getcid(char * str,int strlength)126 static int32_t Getcid(char * str, int strlength)
127 {
128     if (str == NULL) {
129         return CID_ERROR;
130     }
131     uint8_t cid[CID_LENGTH] = {0};
132     EmmcGetHuid(cid, CID_LENGTH);
133     char digitalCid[DIGITAL_CID_LENGTH] = {0};
134     if (TranslateCid(cid, CID_LENGTH, digitalCid, DIGITAL_CID_LENGTH) != CID_OK) {
135         return CID_ERROR;
136     }
137     if (strncpy_s(str, strlength, digitalCid, strlen(digitalCid)) != EOK) {
138         return CID_ERROR;
139     }
140     return CID_OK;
141 }
142 
HalGetSerial(void)143 const char* HalGetSerial(void)
144 {
145     static char str[STR_MAX] = {0};
146     if (strlen(str) > 0) {
147         return str;
148     }
149     if (Getcid(str, STR_MAX) != CID_OK) {
150         return OHOS_SERIAL;
151     }
152     return str;
153 }
154 
HalGetBootloaderVersion(void)155 const char* HalGetBootloaderVersion(void)
156 {
157     return OHOS_BOOTLOADER_VERSION;
158 }
159 
HalGetAbiList(void)160 const char* HalGetAbiList(void)
161 {
162     return OHOS_ABI_LIST;
163 }
164 
HalGetDisplayVersion(void)165 const char* HalGetDisplayVersion(void)
166 {
167     return OHOS_DISPLAY_VERSION;
168 }
169 
HalGetIncrementalVersion(void)170 const char* HalGetIncrementalVersion(void)
171 {
172     return INCREMENTAL_VERSION;
173 }
174 
HalGetBuildType(void)175 const char* HalGetBuildType(void)
176 {
177     return BUILD_TYPE;
178 }
179 
HalGetBuildUser(void)180 const char* HalGetBuildUser(void)
181 {
182     return BUILD_USER;
183 }
184 
HalGetBuildHost(void)185 const char* HalGetBuildHost(void)
186 {
187     return BUILD_HOST;
188 }
189 
HalGetBuildTime(void)190 const char* HalGetBuildTime(void)
191 {
192     return BUILD_TIME;
193 }
194 
HalGetFirstApiVersion(void)195 int HalGetFirstApiVersion(void)
196 {
197     return OHOS_FIRST_API_VERSION;
198 }
199