option to reset last check via config, TEK storage functions

This commit is contained in:
Lurkars 2020-10-27 19:59:54 +01:00
parent af3888ec87
commit 8b38bde332
4 changed files with 44 additions and 2 deletions

View File

@ -7,6 +7,12 @@ menu "Exposure Notification API"
help
Dump storage (stored TEKs, temp. beacons and perm. beacons) to serial output after scan.
config ENA_RESET_LAST_CHECK
bool "Reset last exposure check"
default false
help
Resets the last exposure check date on start.
config ENA_STORAGE_TEK_MAX
int "Max. TEKs"
default 14
@ -91,4 +97,5 @@ menu "Exposure Notification API"
Defines the TEK rolling period in 10 minute steps. (Default 144 => 24 hours)
endmenu
endmenu

View File

@ -179,10 +179,17 @@ void ena_storage_write_last_exposure_date(uint32_t timestamp)
ena_storage_write(ENA_STORAGE_LAST_EXPOSURE_DATE_ADDRESS, &timestamp, sizeof(uint32_t));
}
uint32_t ena_storage_tek_count(void)
{
uint32_t count = 0;
ena_storage_read(ENA_STORAGE_TEK_COUNT_ADDRESS, &count, sizeof(uint32_t));
ESP_LOGD(ENA_STORAGE_LOG, "read TEK count: %u", count);
return count;
}
uint32_t ena_storage_read_last_tek(ena_tek_t *tek)
{
uint32_t tek_count = 0;
ena_storage_read(ENA_STORAGE_TEK_COUNT_ADDRESS, &tek_count, sizeof(uint32_t));
uint32_t tek_count = ena_storage_tek_count();
if (tek_count < 1)
{
return 0;
@ -195,6 +202,13 @@ uint32_t ena_storage_read_last_tek(ena_tek_t *tek)
return tek_count;
}
void ena_storage_get_tek(uint32_t index, ena_tek_t *tek)
{
ena_storage_read(ENA_STORAGE_TEK_START_ADDRESS + index * sizeof(ena_tek_t), tek, sizeof(ena_tek_t));
ESP_LOGD(ENA_STORAGE_LOG, "read %d tek %u:", index, tek->enin);
ESP_LOG_BUFFER_HEXDUMP(ENA_STORAGE_LOG, tek->key_data, ENA_KEY_LENGTH, ESP_LOG_DEBUG);
}
void ena_storage_write_tek(ena_tek_t *tek)
{
uint32_t tek_count = 0;

View File

@ -91,6 +91,10 @@ void ena_start(void)
ena_storage_erase_all();
#endif
#ifdef CONFIG_ENA_RESET_LAST_CHECK
ena_storage_write_last_exposure_date(0);
#endif
if (ena_storage_read_last_exposure_date() == 0xFFFFFFFF)
{
ena_storage_erase_all();

View File

@ -113,6 +113,14 @@ uint32_t ena_storage_read_last_exposure_date(void);
*/
void ena_storage_write_last_exposure_date(uint32_t timestamp);
/**
* @brief get number of stored TEKs
*
* @return
* total number of TEKs stored
*/
uint32_t ena_storage_tek_count(void);
/**
* @brief get last stored TEK
*
@ -123,6 +131,15 @@ void ena_storage_write_last_exposure_date(uint32_t timestamp);
*/
uint32_t ena_storage_read_last_tek(ena_tek_t *tek);
/**
* @brief get stored TEK at given index
*
* @param[in] index the index of the TEK to read
* @param[out] tek pointer to write TEK to
*
*/
void ena_storage_get_tek(uint32_t index, ena_tek_t *tek);
/**
* @brief store given TEK
*