HT32SX Monarch Scan
Monarch Scan application for HT32SX
retriever_api.h
Go to the documentation of this file.
1 
24 #ifndef RETRIEVER_API_H
25 #define RETRIEVER_API_H
26 
27 #include <stdint.h>
28 #include "nvm_api.h"
29 
30 /* Retriever error codes definition */
31 typedef uint8_t retr_error_t;
32 
33 typedef enum {
34  KEY_ENC_FIXED = 0x01,
35  KEY_ENC_VARIABLE = 0x02,
36  KEY_ENC_NONE = 0x03
37 } KEY_ENC_MODES;
38 
39 
40 //#define UID_BASE ((uint32_t)0x1FF80050U)
41 
42 
54 #define RETR_OK 0 /* no error */
55 #define RETR_ERR 1 /* error */
56 
60 /*!******************************************************************
61  * \fn retr_error_t enc_utils_retrieve_data(uint32_t *id, uint8_t *pac, uint8_t *rcz)
62  * \brief Retrieve the ID, PAC and RCZ number of the board and returns it to the caller.
63  * The ID should be used when opening the library. The PAC is used to register the node on the backend.
64  * \param[in] id: pointer to the 32bits word variable where the ID of the board must be stored.
65  * \param[in] pac: pointer to the 8bytes array where the PAC of the board must be stored.
66  * \param[in] rcz: pointer to the byte where the RCZ number of this board must be stored.
67  * \retval Error code: RETR_OK (0) or RETR_ERR (1)
68  *******************************************************************/
69 retr_error_t enc_utils_retrieve_data(uint32_t *id, uint8_t *pac, uint8_t *rcz);
70 
71 /*!******************************************************************
72  * \fn retr_error_t enc_utils_retrieve_data_from_flash(NVM_BoardDataType *nvmBoardData)
73  * \brief Retrieve board informations accordint to the NVM_BoardDataType and returns it to the caller.
74  *
75  * \param[out] nvmBoardData: pointer to a struct of the type of NVM_BoardDataType.
76  * \retval Error code: RETR_OK (0) or RETR_ERR (1)
77  *******************************************************************/
79 
80 /*!******************************************************************
81  * \fn retr_error_t enc_utils_encrypt(uint8_t* encrypted_data, uint8_t* data_to_encrypt, uint16_t data_len)
82  * \brief Perform the AES128-CBC encryption using the AES KEY associated to the board.
83  * \param[in] uint8_t* encrypted_data: pointer to the destination buffer where the encrypted data must be stored.
84  * \param[in] uint8_t* data_to_encrypt: pointer to the source buffer where the data to encrypt are stored.
85  * \param[in] uint16_t data_len: length of the data buffer to encrypt.
86  * \retval Error code: RETR_OK (0) or RETR_ERR (1)
87  *******************************************************************/
88 retr_error_t enc_utils_encrypt(uint8_t* encrypted_data, uint8_t* data_to_encrypt, uint16_t data_len, uint8_t* key, uint8_t useExternalKey);
89 
90 /*!******************************************************************
91  * \fn retr_error_t enc_utils_set_public_key(uint8_t en)
92  * \brief Switch the encryption key to the public key: <i>0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF</i>.
93  * \param[in] uint8_t en: if 1 switch to the public key, else restore the one associated with the board.
94  * \retval Error code: RETR_OK (0) or RETR_ERR (1)
95  *******************************************************************/
96 retr_error_t enc_utils_set_public_key(uint8_t en);
97 
98 /*!******************************************************************
99  * \fn retr_error_t enc_utils_set_test_key(uint8_t en)
100  * \brief Switch the to the test KEY <i>0x0123456789ABCDEF0123456789ABCDEF</i>.
101  * \param[in] uint8_t en: if 1 switch to the test KEY, else restore the one associated with the board.
102  * \retval Error code: RETR_OK (0) or RETR_ERR (1)
103  *******************************************************************/
104 retr_error_t enc_utils_set_test_key(uint8_t en);
105 
106 /*!******************************************************************
107  * \fn retr_error_t enc_utils_set_test_id(uint8_t en)
108  * \brief Switch the to the test ID <i>0xFEDCBA98</i>.
109  * \param[in] uint8_t en: if 1 switch to the test ID, else restore the one associated with the board.
110  * \retval Error code: RETR_OK (0) or RETR_ERR (1)
111  *******************************************************************/
112 retr_error_t enc_utils_set_test_id(uint8_t en);
113 
114 /*!******************************************************************
115  * \fn retr_error_t enc_utils_get_id(uint8_t *id)
116  * \brief Gets the ID from the EEPROM on the board.
117  * \param[in] uint8_t *id: pointer to the array where the ID should be stored.
118  * \note: The function \ref enc_utils_retrieve_data should be called in the
119  * initialization phase of the board.
120  * \retval Error code: RETR_OK (0) or RETR_ERR (1)
121  *******************************************************************/
122 retr_error_t enc_utils_get_id(uint8_t *id);
123 
124 /*!******************************************************************
125  * \fn retr_error_t enc_utils_get_initial_pac(uint8_t *pac)
126  * \brief Gets the PAC from the EEPROM on the board.
127  * \param[in] uint8_t *pac: pointer to the array where the PAC should be stored.
128  * \note: The function \ref enc_utils_retrieve_data should be called in the
129  * initialization phase of the board.
130  * \retval Error code: RETR_OK (0) or RETR_ERR (1)
131  *******************************************************************/
132 retr_error_t enc_utils_get_initial_pac(uint8_t *pac);
133 
136 /******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/
137 #endif
enc_utils_get_id
retr_error_t enc_utils_get_id(uint8_t *id)
Gets the ID from the EEPROM on the board.
enc_utils_set_test_id
retr_error_t enc_utils_set_test_id(uint8_t en)
Switch the to the test ID 0xFEDCBA98.
enc_utils_set_test_key
retr_error_t enc_utils_set_test_key(uint8_t en)
Switch the to the test KEY 0x0123456789ABCDEF0123456789ABCDEF.
enc_utils_retrieve_data_from_flash
uint8_t enc_utils_retrieve_data_from_flash(NVM_BoardDataType *nvmBoardData)
Retrieve board informations accordint to the NVM_BoardDataType and returns it to the caller.
enc_utils_set_public_key
retr_error_t enc_utils_set_public_key(uint8_t en)
Switch the encryption key to the public key: 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,...
enc_utils_get_initial_pac
retr_error_t enc_utils_get_initial_pac(uint8_t *pac)
Gets the PAC from the EEPROM on the board.
enc_utils_retrieve_data
retr_error_t enc_utils_retrieve_data(uint32_t *id, uint8_t *pac, uint8_t *rcz)
Retrieve the ID, PAC and RCZ number of the board and returns it to the caller. The ID should be used ...
nvm_api.h
NVM handler.
NVM_BoardDataType
Record for board data.
Definition: nvm_api.h:140