1 /** ----------------------------------------------------------------------
2  *
3  * Copyright (C) 2018 ST Microelectronics S.A.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *
18  ----------------------------------------------------------------------*/
19 
20 #ifndef HAL_FD_H_
21 #define HAL_FD_H_
22 
23 #include "halcore.h"
24 
25 #define STFLASHTOOL_VERSION 0x0503
26 /*
27  *Structure containing fw version info
28  */
29 typedef struct FWInfo {
30   uint32_t patchVersion;
31   uint32_t fwVersion;
32   uint8_t hwVersion;
33   uint32_t loaderVersion;
34   uint16_t custVersion;
35   uint16_t confVersion;
36   uint16_t uwbFwVersion;
37   uint16_t uwbVersion;
38   bool hibernate_exited;
39 } FWInfo;
40 
41 typedef enum {
42   //  HAL_FD_STATE_GET_ATR,
43   HAL_FD_STATE_AUTHENTICATE,
44   HAL_FD_STATE_ERASE_FLASH,
45   HAL_FD_STATE_SEND_RAW_APDU,
46   HAL_FD_STATE_EXIT_APDU,
47 } hal_fd_state_e;
48 
49 #define FT_CLF_MODE_ERROR 0
50 #define FT_CLF_MODE_LOADER 1
51 #define FT_CLF_MODE_ROUTER 2
52 
53 #define FW_TIMER_DURATION 3000
54 
55 #define FW_PATCH_AVAILABLE 1
56 #define FW_CUSTOM_PARAM_AVAILABLE 2
57 #define FW_UWB_PARAM_AVAILABLE 4
58 
59 #define FW_UPDATE_NEEDED 1
60 #define CONF_UPDATE_NEEDED 2
61 #define UWB_CONF_UPDATE_NEEDED 4
62 
63 #define MAX_BUFFER_SIZE 300
64 
65 /* Function declarations */
66 int hal_fd_init();
67 void hal_fd_close();
68 uint8_t ft_cmd_HwReset(uint8_t* pdata, uint8_t* clf_mode);
69 void ExitHibernateHandler(HALHANDLE mHalHandle, uint16_t data_len,
70                           uint8_t* p_data);
71 void UpdateHandler(HALHANDLE mHalHandle, uint16_t data_len, uint8_t* p_data);
72 void ApplyCustomParamHandler(HALHANDLE mHalHandle, uint16_t data_len,
73                              uint8_t* p_data);
74 void ApplyUwbParamHandler(HALHANDLE mHalHandle, uint16_t data_len,
75                              uint8_t* p_data);
76 void resetHandlerState();
77 bool ft_CheckUWBConf() ;
78 #endif /* HAL_FD_H_ */
79