1 /* 2 * Copyright (C) 2018-2020 Alibaba Group Holding Limited 3 */ 4 5 #ifndef __GENIE_TRIPLE_H__ 6 #define __GENIE_TRIPLE_H__ 7 8 #define GENIE_TRIPLE_PID_SIZE 4 9 #define GENIE_TRIPLE_KEY_SIZE 16 10 #define GENIE_TRIPLE_MAC_SIZE 6 11 #define GENIE_TRIPLE_CRC_LEN 2 12 #define GENIE_SIZE_TRI_TRUPLE (GENIE_TRIPLE_PID_SIZE + GENIE_TRIPLE_KEY_SIZE + GENIE_TRIPLE_MAC_SIZE + GENIE_TRIPLE_CRC_LEN) 13 14 #define GENIE_TRIPLE_CRC_MAGIC (0xA5A6) 15 16 typedef struct _genie_triple_s 17 { 18 uint32_t pid; 19 uint8_t key[GENIE_TRIPLE_KEY_SIZE]; 20 uint8_t mac[GENIE_TRIPLE_MAC_SIZE]; 21 } genie_triple_t; 22 23 /** 24 * @brief writes the trituple info into flash. 25 * @param[in] p_pid: product ID 26 * @param[in] p_mac: device address 27 * @param[in] p_key: secret key 28 * @return the status of the writing operation, 0 for success. 29 */ 30 genie_storage_status_e genie_triple_write(uint32_t *p_pid, uint8_t *p_mac, uint8_t *p_key); 31 32 /** 33 * @brief get the trituple info from flash. 34 * @param[in] p_pid 35 * @param[in] p_mac 36 * @param[in] p_key 37 * @return the status of the reading operation, 0 for success. 38 */ 39 genie_storage_status_e genie_triple_read(uint32_t *p_pid, uint8_t *p_mac, uint8_t *p_key); 40 41 /** 42 * @brief load the trituple info from flash. 43 * @return 0 for success, otherwise failed. 44 */ 45 int8_t genie_triple_init(void); 46 47 genie_triple_t *genie_triple_get(void); 48 uint8_t *genie_triple_get_mac(void); 49 50 #endif