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 #ifndef OHOS_LITE_HOTA_HAL_BOARD_H
17 #define OHOS_LITE_HOTA_HAL_BOARD_H
18 
19 #include "hota_partition.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif /* End of #ifdef __cplusplus */
26 
27 /**
28  * @brief OTA module initialization.
29  *
30  * @return OHOS_SUCCESS: Success,
31  *         Others: Failure.
32  *
33  * @since 1.0
34  * @version 1.0
35  */
36 int HotaHalInit(void);
37 
38 /**
39  * @brief Release OTA module resource.
40  *
41  * @return OHOS_SUCCESS: Success,
42  *         Others: Failure.
43  *
44  * @since 1.0
45  * @version 1.0
46  */
47 int HotaHalDeInit(void);
48 
49 /**
50  * @brief Release OTA module resource.
51  *
52  * @return OHOS_SUCCESS: Success,
53  *         Others: Failure.
54  *
55  * @since 1.0
56  * @version 1.0
57  */
58 int HotaHalGetUpdateIndex(unsigned int *index);
59 
60 /**
61  * @brief Write image to partition.
62  *
63  * @param partition [in] scan result, result array size must larger than WIFI_SCAN_AP_LIMIT.
64  * @param buffer    [in] image buffer.
65  * @param offset    [in] The buffer offset of file.
66  * @param bufLen    [in] The Length of buffer.
67  *
68  * @return OHOS_SUCCESS: Success,
69  *         Others: Failure.
70  *
71  * @since 1.0
72  * @version 1.0
73  */
74 int HotaHalWrite(int partition, unsigned char *buffer, unsigned int offset, unsigned int bufLen);
75 
76 /**
77  * @brief read image of partition.
78  *
79  * @param partition [in]  scan result, result array size must larger than WIFI_SCAN_AP_LIMIT.
80  * @param offset    [in]  The buffer offset of file.
81  * @param bufLen    [in]  The Length of buffer.
82  * @param buffer    [out] image buffer.
83  *
84  * @return OHOS_SUCCESS: Success,
85  *         Others: Failure.
86  *
87  * @since 1.0
88  * @version 1.0
89  */
90 int HotaHalRead(int partition, unsigned int offset, unsigned int bufLen, unsigned char *buffer);
91 
92 /**
93  * @brief Write Boot Settings in order to notify device upgrade success or enter Recovery Part.
94  *
95  * @return OHOS_SUCCESS: Success,
96  *         Others: Failure.
97  *
98  * @since 1.0
99  * @version 1.0
100  */
101 int HotaHalSetBootSettings(void);
102 
103 /**
104  * @brief Restart after upgrade finish or go bootloader to upgrade.
105  *
106  * @return OHOS_SUCCESS: Success,
107  *         Others: Failure.
108  *
109  * @since 1.0
110  * @version 1.0
111  */
112 int HotaHalRestart(void);
113 
114 /**
115  * @brief Rollback if ota failed.
116  *
117  * @return OHOS_SUCCESS: Success,
118  *         Others: Failure.
119  *
120  * @since 1.0
121  * @version 1.0
122  */
123 int HotaHalRollback(void);
124 
125 /**
126  * @brief Get partition info.
127  *
128  * You need to call this funtion in Init function, you need partition info when upgrade. \n
129  *
130  * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
131  *
132  * @since 1.0
133  * @version 1.0
134  */
135 const ComponentTableInfo *HotaHalGetPartitionInfo(void);
136 
137 /**
138  * @brief Get public key.
139  *
140  * You need to call this funtion when verfiy sign data \n
141  *
142  * @param length Indicates  pubkey len.
143  *
144  * @return Returns <b>0</b> if the operation is successful; public key.
145  *
146  * @since 1.0
147  * @version 1.0
148  */
149 unsigned char *HotaHalGetPubKey(unsigned int *length);
150 
151 /**
152  * @brief get update ability.
153  *
154  * You need to call this function when update process init. \n
155  *
156  * @return Returns update abilty.
157  *
158  * @since 1.0
159  * @version 1.0
160  */
161 int HotaHalGetUpdateAbility(void);
162 
163 /**
164  * @brief get ota package update path.
165  *
166  * You need to call this function before update process. \n
167  *
168  * @param path Indicates where ota package you place.
169  * @param len Indicates  path len.
170  *
171  * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
172  *
173  * @since 1.0
174  * @version 1.0
175  */
176 int HotaHalGetOtaPkgPath(char *path, int len);
177 
178 /**
179  * @brief judge device can auto update.
180  *
181  * You need to call this function when update process init.\n
182  *
183  * @return Returns <b>1</b> if device can auto update; returns <b>0</b> if device can not auto update.
184  *
185  * @since 1.0
186  * @version 1.0
187  */
188 int HotaHalIsDeviceCanReboot(void);
189 
190 /**
191  * @brief judge is develop mode now.
192  *
193  * You need to call this function to get develop mode.\n
194  *
195  * @return Returns <b>1</b> if device is develop mode; returns <b>0</b> if device is not develop mode.
196  *
197  * @since 1.0
198  * @version 1.0
199  */
200 int HotaHalIsDevelopMode(void);
201 
202 /**
203  * @brief get update metadata.
204  *
205  * You need to call this function when update process .\n
206  *
207  * @return Returns OtaStatus if the operation is successful; returns <b>-1</b> otherwise.
208  *
209  * @since 1.0
210  * @version 1.0
211  */
212 int HotaHalGetMetaData(UpdateMetaData *metaData);
213 
214 /**
215  * @brief set update metadata.
216  *
217  * You need to call this function when update process.\n
218  *
219  * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
220  *
221  * @since 1.0
222  * @version 1.0
223  */
224 int HotaHalSetMetaData(UpdateMetaData *metaData);
225 
226 /**
227  * @brief reboot and clean userdata.
228  *
229  * You need to call this function when recovery system.\n
230  *
231  * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
232  *
233  * @since 1.0
234  * @version 1.0
235  */
236 int HotaHalRebootAndCleanUserData(void);
237 
238 /**
239  * @brief reboot and clean cache.
240  *
241  * You need to call this function when recovery system.\n
242  *
243  * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
244  *
245  * @since 1.0
246  * @version 1.0
247  */
248 int HotaHalRebootAndCleanCache(void);
249 
250 /**
251  * @brief check whether pkgVersion is valid.
252  *
253  * You need to call this function before update process.\n
254  *
255  * @return Returns <b>1</b> if pkgVersion is valid compared to currentVersion; returns <b>0</b> otherwise.
256  *
257  * @since 1.0
258  * @version 1.0
259  */
260 int HotaHalCheckVersionValid(const char *currentVersion, const char *pkgVersion, unsigned int pkgVersionLength);
261 
262 #ifdef __cplusplus
263 #if __cplusplus
264 }
265 #endif
266 #endif /* End of #ifdef __cplusplus */
267 
268 #endif /* End of #ifndef OHOS_LITE_HOTA_HAL_BOARD_H */
269