2020-07-11 12:11:34 +02:00
|
|
|
#ifndef _ena_STORAGE_H_
|
|
|
|
#define _ena_STORAGE_H_
|
|
|
|
|
|
|
|
#include "ena-crypto.h"
|
|
|
|
|
|
|
|
#define ENA_STORAGE_LOG "ESP-ENA-storage" // TAG for Logging
|
|
|
|
#define PARTITION_NAME "ena"
|
2020-07-12 14:14:06 +02:00
|
|
|
#define ENA_STOARGE_TEK_STORE_PERIOD (14) // Period of storing TEKs
|
|
|
|
#define ENA_STORAGE_TEK_COUNT_ADDRESS (0) // starting address for TEK COUNT
|
|
|
|
#define ENA_STORAGE_TEK_START_ADDRESS (ENA_STORAGE_TEK_COUNT_ADDRESS + 1) // starting address for TEKs
|
|
|
|
#define ENA_STORAGE_TEK_LENGTH (ENA_KEY_LENGTH + 4) // length of a stored TEK -> TEK keysize + 4 Bytes for ENIN
|
|
|
|
#define ENA_STORAGE_DETECTION_LENGTH (ENA_KEY_LENGTH + ENA_AEM_METADATA_LENGTH + 4 + sizeof(int)) // length of a stored detection -> RPI keysize + AEM size + 4 Bytes for ENIN + 4 Bytes for RSSI
|
|
|
|
#define ENA_STOARGE_TEMP_DETECTIONS_MAX (1000) // Maximum number of temporary stored detections
|
|
|
|
#define ENA_STORAGE_TEMP_DETECTIONS_COUNT_ADDRESS (ENA_STORAGE_TEK_START_ADDRESS + ENA_STORAGE_TEK_LENGTH * ENA_STOARGE_TEK_STORE_PERIOD) // starting address for temporary detections COUNT (offset from max. stored TEKs)
|
|
|
|
#define ENA_STORAGE_TEMP_DETECTIONS_START_ADDRESS (ENA_STORAGE_TEMP_DETECTIONS_COUNT_ADDRESS + 4) // starting address for temporary detections
|
2020-07-11 12:11:34 +02:00
|
|
|
#define ENA_STORAGE_DETECTIONS_COUNT_ADDRESS (ENA_STORAGE_TEMP_DETECTIONS_COUNT_ADDRESS + ENA_STORAGE_DETECTION_LENGTH * ENA_STOARGE_TEMP_DETECTIONS_MAX) // starting address for detections COUNT (offset from max. stored temporary detections)
|
2020-07-12 14:14:06 +02:00
|
|
|
#define ENA_STORAGE_DETECTIONS_START_ADDRESS (ENA_STORAGE_DETECTIONS_COUNT_ADDRESS + 4) // starting address of detections
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* read bytes at given address
|
|
|
|
*/
|
|
|
|
void ena_storage_read(size_t address, uint8_t *data, size_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* store bytes at given address
|
|
|
|
*/
|
2020-07-12 14:14:06 +02:00
|
|
|
void ena_storage_write(size_t address, uint8_t *data, size_t size);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* deletes bytes at given address and shift other data back
|
|
|
|
*/
|
2020-07-12 14:14:06 +02:00
|
|
|
void ena_storage_shift_delete(size_t address, size_t end_address, size_t size);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* store TEK with ENIN
|
|
|
|
*/
|
2020-07-12 14:14:06 +02:00
|
|
|
void ena_storage_write_tek(uint32_t enin, uint8_t *tek);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get last stored ENIN
|
|
|
|
*/
|
|
|
|
uint32_t ena_storage_read_enin(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get last stored TEK
|
|
|
|
*/
|
2020-07-12 14:14:06 +02:00
|
|
|
void ena_storage_read_tek(uint8_t *tek);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get number of stored temporary detections
|
|
|
|
*/
|
|
|
|
uint32_t ena_storage_temp_detections_count(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* store temporary detection (RPI + AEM + RSSI with UNIX timestamp)
|
|
|
|
*
|
|
|
|
* returns index
|
|
|
|
*/
|
2020-07-12 14:14:06 +02:00
|
|
|
uint32_t ena_storage_write_temp_detection(uint32_t timestamp, uint8_t *rpi, uint8_t *aem, int rssi);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get temporary detection (RPI + AEM + RSSI with UNIX timestamp) at given index
|
|
|
|
*/
|
2020-07-12 14:14:06 +02:00
|
|
|
void ena_storage_read_temp_detection(uint32_t index, uint32_t *timestamp, uint8_t *rpi, uint8_t *aem, int *rssi);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* remove temporary detection at given index
|
|
|
|
*/
|
|
|
|
void ena_storage_remove_temp_detection(uint32_t index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get number of stored detections
|
|
|
|
*/
|
|
|
|
uint32_t ena_storage_detections_count(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* store detection (RPI + AEM + RSSI with ENIN)
|
|
|
|
*/
|
2020-07-12 14:14:06 +02:00
|
|
|
void ena_storage_write_detection(uint32_t timestamp, uint8_t *rpi, uint8_t *aem, int rssi);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get detection (RPI + AEM + RSSI with ENIN) at given index
|
|
|
|
*/
|
2020-07-12 14:14:06 +02:00
|
|
|
void ena_storage_read_detection(uint32_t index, uint32_t *enin, uint8_t *rpi, uint8_t *aem, int *rssi);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
uint8_t ena_storage_read_u8(size_t address);
|
|
|
|
|
|
|
|
uint32_t ena_storage_read_u32(size_t address);
|
|
|
|
|
|
|
|
void ena_storage_write_u8(size_t address, uint8_t byte);
|
|
|
|
|
|
|
|
void ena_storage_write_u32(size_t address, uint32_t value);
|
|
|
|
|
|
|
|
int ena_storage_read_int(size_t address);
|
|
|
|
|
|
|
|
void ena_storage_write_int(size_t address, int value);
|
|
|
|
|
|
|
|
void ena_storage_erase(void);
|
|
|
|
|
|
|
|
void ena_storage_dump_tek(void);
|
|
|
|
|
2020-07-12 14:14:06 +02:00
|
|
|
void ena_storage_dump_temp_detections(void);
|
2020-07-11 12:11:34 +02:00
|
|
|
|
|
|
|
void ena_storage_dump_detections(void);
|
|
|
|
|
|
|
|
#endif
|