diff --git a/components/ena/Kconfig.projbuild b/components/ena/Kconfig.projbuild index 3d8f642..d788ada 100644 --- a/components/ena/Kconfig.projbuild +++ b/components/ena/Kconfig.projbuild @@ -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 \ No newline at end of file diff --git a/components/ena/ena-storage.c b/components/ena/ena-storage.c index e62a1cc..97dd298 100644 --- a/components/ena/ena-storage.c +++ b/components/ena/ena-storage.c @@ -179,10 +179,17 @@ void ena_storage_write_last_exposure_date(uint32_t timestamp) ena_storage_write(ENA_STORAGE_LAST_EXPOSURE_DATE_ADDRESS, ×tamp, 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; diff --git a/components/ena/ena.c b/components/ena/ena.c index c0806dc..add5803 100644 --- a/components/ena/ena.c +++ b/components/ena/ena.c @@ -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(); diff --git a/components/ena/include/ena-storage.h b/components/ena/include/ena-storage.h index f5f98e1..786cce1 100644 --- a/components/ena/include/ena-storage.h +++ b/components/ena/include/ena-storage.h @@ -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 *