1 /*
2  * Copyright (c) 2023 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 <stdio.h>
17 #include <stdlib.h>
18 
19 #include "parameter.h"
20 #include "devattest_interface.h"
21 
22 const int DEVATTEST_SUESS = 0;
23 const int UDIDSIZE_LEN = 64;
24 
ObtainProductParms()25 void ObtainProductParms()
26 {
27     int sdkApiVersion = GetSdkApiVersion();
28     if (sdkApiVersion != 0) {
29         printf("SdkApiVersion = %d\n", sdkApiVersion);
30     } else {
31         printf("SdkApiVersion = 0\n");
32     }
33 
34     int firstApiVersion = GetFirstApiVersion();
35     if (firstApiVersion != 0) {
36         printf("firstApiVersion = %d\n", firstApiVersion);
37     } else {
38         printf("firstApiVersion = 0\n");
39     }
40 
41     const char *bootloaderVersion = GetBootloaderVersion();
42     if (bootloaderVersion != nullptr) {
43         printf("bootloaderVersion = %s\n", bootloaderVersion);
44     } else {
45         printf("bootloaderVersion = nullptr\n");
46     }
47 
48 
49     const char *incrementalVersion = GetIncrementalVersion();
50     if (incrementalVersion != nullptr) {
51         printf("incrementalVersion = %s\n", incrementalVersion);
52     } else {
53         printf("incrementalVersion = nullptr\n");
54     }
55 
56     const char *buildType = GetBuildType();
57     if (buildType != nullptr) {
58         printf("buildType = %s\n", buildType);
59     } else {
60         printf("buildType = nullptr\n");
61     }
62 
63     const char *buildUser = GetBuildUser();
64     if (buildUser != nullptr) {
65         printf("buildUser = %s\n", buildUser);
66     } else {
67         printf("buildUser = nullptr\n");
68     }
69 
70     const char *buildHost = GetBuildHost();
71     if (buildHost != nullptr) {
72         printf("buildHost = %s\n", buildHost);
73     } else {
74         printf("buildHost = nullptr\n");
75     }
76 
77     const char *buildTime = GetBuildTime();
78     if (buildTime != nullptr) {
79         printf("buildTime = %s\n", buildTime);
80     } else {
81         printf("buildTime = nullptr\n");
82     }
83 
84     const char *abiList = GetAbiList();
85     if (abiList != nullptr) {
86         printf("AbiList = %s\n", abiList);
87     } else {
88         printf("AbiList = nullptr\n");
89     }
90 }
91 
main()92 int main()
93 {
94     printf("******To Obtain Product Params Start******\n");
95     const char *productType = GetDeviceType();
96     if (productType != nullptr) {
97         printf("Device Type = %s\n", productType);
98     } else {
99         printf("Device Type = nullptr\n");
100     }
101 
102     const char *securityPatchTag = GetSecurityPatchTag();
103     if (securityPatchTag != nullptr) {
104         printf("Security Patch = %s\n", securityPatchTag);
105     } else {
106         printf("Security Patch = nullptr\n");
107     }
108 
109     const char *osName = GetOSFullName();
110     if (osName != nullptr) {
111         printf("OsFullName = %s\n", osName);
112     } else {
113         printf("OsFullName = nullptr\n");
114     }
115 
116     const char *displayVersion = GetDisplayVersion();
117     if (displayVersion != nullptr) {
118         printf("DisplayVersion = %s\n", displayVersion);
119     } else {
120         printf("DisplayVersion = nullptr\n");
121     }
122 
123     const char *versionId = GetVersionId();
124     if (versionId != nullptr) {
125         printf("VersionID = %s\n", versionId);
126     } else {
127         printf("VersionID = nullptr\n");
128     }
129 
130     AttestResultInfo attestResultInfo = {0};
131     attestResultInfo.ticket = NULL;
132     int32_t retStatus = GetAttestStatus(&attestResultInfo);
133     if (retStatus != DEVATTEST_SUESS) {
134         printf("[CLIENT MAIN] wrong. retStatus:%d\n", retStatus);
135         printf("authResult = %d\n", attestResultInfo.authResult);
136         printf("softwareResult = %d\n", attestResultInfo.softwareResult);
137     } else {
138         printf("authResult = %d\n", attestResultInfo.authResult);
139         printf("softwareResult = %d\n", attestResultInfo.softwareResult);
140     }
141 
142     char udid[UDIDSIZE_LEN + 1] = {0};
143     int retUdid = GetDevUdid(udid, UDIDSIZE_LEN + 1);
144     if (retUdid == 0) {
145         printf("DevUdid = %s\n", udid);
146     } else {
147         printf("DevUdid = nullptr\n");
148     }
149 
150     const char *manuFacture = GetManufacture();
151     if (manuFacture != nullptr) {
152         printf("manuFacture = %s\n", manuFacture);
153     } else {
154         printf("manuFacture = nullptr\n");
155     }
156 
157     const char *productModel = GetProductModel();
158     if (productModel != nullptr) {
159         printf("productModel = %s\n", productModel);
160     } else {
161         printf("productModel = nullptr\n");
162     }
163 
164     const char *serial = GetSerial();
165     if (serial != nullptr) {
166         printf("serial = %s\n", serial);
167     } else {
168         printf("serial = nullptr\n");
169     }
170 
171     const char *brand = GetBrand();
172     if (brand != nullptr) {
173         printf("brand = %s\n", brand);
174     } else {
175         printf("brand = nullptr\n");
176     }
177 
178     const char *productSeries = GetProductSeries();
179     if (productSeries != nullptr) {
180         printf("productSeries = %s\n", productSeries);
181     } else {
182         printf("productSeries = nullptr\n");
183     }
184 
185     const char *softwareModel = GetSoftwareModel();
186     if (softwareModel != nullptr) {
187         printf("softwareModel = %s\n", softwareModel);
188     } else {
189         printf("softwareModel = nullptr\n");
190     }
191 
192     const char *hardWareModel = GetHardwareModel();
193     if (hardWareModel != nullptr) {
194         printf("HardwareModel = %s\n", hardWareModel);
195     } else {
196         printf("HardwareModel = nullptr\n");
197     }
198 
199     const char *buildRootHash = GetBuildRootHash();
200     if (buildRootHash != nullptr) {
201         printf("BuildRootHash = %s\n", buildRootHash);
202     } else {
203         printf("BuildRootHash = nullptr\n");
204     }
205 
206     const char *marketName = GetMarketName();
207     if (marketName != nullptr) {
208         printf("marketName = %s\n", marketName);
209     } else {
210         printf("marketName = nullptr\n");
211     }
212 
213     ObtainProductParms();
214 
215     printf("******To Obtain Product Params End  ******\n");
216     return 0;
217 }
218